Commit eb8c174b by ibaker Committed by Oliver Woodman

Update WebVttCueParser to parse position alignment values

Currently we assume these are "start", "center", "middle" or "end",
which was correct in a previous draft of the spec:
https://www.w3.org/TR/2014/WD-webvtt1-20141111/#dfn-webvtt-text-position-cue-setting

The released spec uses "line-left", "center" and "line-right":
https://www.w3.org/TR/webvtt1/#webvtt-position-cue-setting

PiperOrigin-RevId: 307371066
parent ad3fb3d0
......@@ -89,6 +89,12 @@
[issue #6581](https://github.com/google/ExoPlayer/issues/6581)).
* Parse `tts:ruby` and `tts:rubyPosition` properties in TTML subtitles
(rendering is coming later).
* Update WebVTT position alignment parsing to recognise `line-left`,
`center` and `line-right` as per the
[released spec](https://www.w3.org/TR/webvtt1/#webvtt-position-cue-setting)
(a
[previous draft](https://www.w3.org/TR/2014/WD-webvtt1-20141111/#dfn-webvtt-text-position-cue-setting)
used `start`, `middle` and `end`).
* DRM:
* Add support for attaching DRM sessions to clear content in the demo app.
* Remove `DrmSessionManager` references from all renderers.
......
......@@ -387,7 +387,7 @@ public final class WebvttCueParser {
private static void parseLineAttribute(String s, WebvttCueInfoBuilder builder) {
int commaIndex = s.indexOf(',');
if (commaIndex != -1) {
builder.lineAnchor = parsePositionAnchor(s.substring(commaIndex + 1));
builder.lineAnchor = parseLineAnchor(s.substring(commaIndex + 1));
s = s.substring(0, commaIndex);
}
if (s.endsWith("%")) {
......@@ -405,6 +405,22 @@ public final class WebvttCueParser {
}
}
@Cue.AnchorType
private static int parseLineAnchor(String s) {
switch (s) {
case "start":
return Cue.ANCHOR_TYPE_START;
case "center":
case "middle":
return Cue.ANCHOR_TYPE_MIDDLE;
case "end":
return Cue.ANCHOR_TYPE_END;
default:
Log.w(TAG, "Invalid anchor value: " + s);
return Cue.TYPE_UNSET;
}
}
private static void parsePositionAttribute(String s, WebvttCueInfoBuilder builder) {
int commaIndex = s.indexOf(',');
if (commaIndex != -1) {
......@@ -417,11 +433,13 @@ public final class WebvttCueParser {
@Cue.AnchorType
private static int parsePositionAnchor(String s) {
switch (s) {
case "line-left":
case "start":
return Cue.ANCHOR_TYPE_START;
case "center":
case "middle":
return Cue.ANCHOR_TYPE_MIDDLE;
case "line-right":
case "end":
return Cue.ANCHOR_TYPE_END;
default:
......
......@@ -184,14 +184,14 @@ public class WebvttDecoderTest {
public void decodeWithPositioning() throws Exception {
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_POSITIONING_FILE);
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
assertThat(subtitle.getEventTimeCount()).isEqualTo(16);
assertThat(subtitle.getEventTime(0)).isEqualTo(0L);
assertThat(subtitle.getEventTime(1)).isEqualTo(1_234_000L);
Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
assertThat(firstCue.text.toString()).isEqualTo("This is the first subtitle.");
assertThat(firstCue.position).isEqualTo(0.1f);
assertThat(firstCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
assertThat(firstCue.position).isEqualTo(0.6f);
assertThat(firstCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_END);
assertThat(firstCue.textAlignment).isEqualTo(Alignment.ALIGN_NORMAL);
assertThat(firstCue.size).isEqualTo(0.35f);
// Unspecified values should use WebVTT defaults
......@@ -246,6 +246,18 @@ public class WebvttDecoderTest {
// Derived from `align:center`:
assertThat(sixthCue.position).isEqualTo(0.5f);
assertThat(sixthCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
assertThat(subtitle.getEventTime(12)).isEqualTo(12_000_000L);
assertThat(subtitle.getEventTime(13)).isEqualTo(13_000_000L);
Cue seventhCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(12)));
assertThat(seventhCue.text.toString()).isEqualTo("This is the seventh subtitle.");
assertThat(seventhCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
assertThat(subtitle.getEventTime(14)).isEqualTo(14_000_000L);
assertThat(subtitle.getEventTime(15)).isEqualTo(15_000_000L);
Cue eighthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(14)));
assertThat(eighthCue.text.toString()).isEqualTo("This is the eighth subtitle.");
assertThat(eighthCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_END);
}
@Test
......
......@@ -2,7 +2,7 @@ WEBVTT
NOTE Position with percentage and position alignment
00:00:00.000 --> 00:00:01.234 position:10%,start align:start size:35%
00:00:00.000 --> 00:00:01.234 position:60%,end align:start size:35%
This is the first subtitle.
NOTE Wrong position provided. It should be provided as
......@@ -30,3 +30,13 @@ NOTE In newer drafts, align:middle has been replaced by align:center
00:10.000 --> 00:11.000 align:center
This is the sixth subtitle.
NOTE In older drafts position alignment could be start,middle,end
00:12.000 --> 00:13.000 position:20%,start
This is the seventh subtitle.
NOTE In the released spec position alignment can be line-left,center,line-right
00:14.000 --> 00:15.000 position:70%,line-right
This is the eighth subtitle.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment