TTML: Ignore regions that don't declare origin and extent

Issue: #2953

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159218386
This commit is contained in:
olly 2017-05-07 05:37:26 +01:00 committed by Oliver Woodman
parent 023c9d56a9
commit c7948f2f7a
2 changed files with 22 additions and 10 deletions

View File

@ -179,9 +179,13 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
assertEquals(1, output.size());
ttmlCue = output.get(0);
assertEquals("dolor", ttmlCue.text.toString());
assertEquals(10f / 100f, ttmlCue.position);
assertEquals(80f / 100f, ttmlCue.line);
assertEquals(1f, ttmlCue.size);
assertEquals(Cue.DIMEN_UNSET, ttmlCue.position);
assertEquals(Cue.DIMEN_UNSET, ttmlCue.line);
assertEquals(Cue.DIMEN_UNSET, ttmlCue.size);
// TODO: Should be as below, once https://github.com/google/ExoPlayer/issues/2953 is fixed.
// assertEquals(10f / 100f, ttmlCue.position);
// assertEquals(80f / 100f, ttmlCue.line);
// assertEquals(1f, ttmlCue.size);
output = subtitle.getCues(21000000);
assertEquals(1, output.size());

View File

@ -222,9 +222,9 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
/**
* Parses a region declaration.
* <p>
* If the region defines an origin and/or extent, it is required that they're defined as
* percentages of the viewport. Region declarations that define origin and/or extent in other
* formats are unsupported, and null is returned.
* If the region defines an origin and extent, it is required that they're defined as percentages
* of the viewport. Region declarations that define origin and extent in other formats are
* unsupported, and null is returned.
*/
private TtmlRegion parseRegionAttributes(XmlPullParser xmlParser) {
String regionId = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_ID);
@ -250,9 +250,13 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
return null;
}
} else {
Log.w(TAG, "Ignoring region without an origin");
return null;
// TODO: Should default to top left as below in this case, but need to fix
// https://github.com/google/ExoPlayer/issues/2953 first.
// Origin is omitted. Default to top left.
position = 0;
line = 0;
// position = 0;
// line = 0;
}
float width;
@ -273,9 +277,13 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
return null;
}
} else {
Log.w(TAG, "Ignoring region without an extent");
return null;
// TODO: Should default to extent of parent as below in this case, but need to fix
// https://github.com/google/ExoPlayer/issues/2953 first.
// Extent is omitted. Default to extent of parent.
width = 1;
height = 1;
// width = 1;
// height = 1;
}
@Cue.AnchorType int lineAnchor = Cue.ANCHOR_TYPE_START;