Skip to content

Commit

Permalink
Parse DASH forced_subtitle role
Browse files Browse the repository at this point in the history
#minor-release

Issue: google#8781
PiperOrigin-RevId: 368212289
  • Loading branch information
icbaker authored and roblav96 committed Apr 17, 2021
1 parent 2886a77 commit 9e4401a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
* Metadata:
* Ensure that timed metadata near the end of a period is not dropped
([#8710](https:/google/ExoPlayer/issues/8710)).
* DASH:
* Parse `forced_subtitle` role from DASH manifests
([#8781](https:/google/ExoPlayer/issues/8781)).
* MediaSession extension: Remove dependency to core module and rely on common
only. The `TimelineQueueEditor` uses a new `MediaDescriptionConverter` for
this purpose and does not rely on the `ConcatenatingMediaSource` anymore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,15 +1391,31 @@ protected int parseAudioChannelConfiguration(XmlPullParser xpp)

// Selection flag parsing.

@C.SelectionFlags
protected int parseSelectionFlagsFromRoleDescriptors(List<Descriptor> roleDescriptors) {
@C.SelectionFlags int result = 0;
for (int i = 0; i < roleDescriptors.size(); i++) {
Descriptor descriptor = roleDescriptors.get(i);
if (Ascii.equalsIgnoreCase("urn:mpeg:dash:role:2011", descriptor.schemeIdUri)
&& "main".equals(descriptor.value)) {
return C.SELECTION_FLAG_DEFAULT;
if (Ascii.equalsIgnoreCase("urn:mpeg:dash:role:2011", descriptor.schemeIdUri)) {
result |= parseSelectionFlagsFromDashRoleScheme(descriptor.value);
}
}
return 0;
return result;
}

@C.SelectionFlags
protected int parseSelectionFlagsFromDashRoleScheme(@Nullable String value) {
if (value == null) {
return 0;
}
switch (value) {
case "main":
return C.SELECTION_FLAG_DEFAULT;
case "forced_subtitle":
return C.SELECTION_FLAG_FORCED;
default:
return 0;
}
}

// Role and Accessibility parsing.
Expand All @@ -1410,7 +1426,7 @@ protected int parseRoleFlagsFromRoleDescriptors(List<Descriptor> roleDescriptors
for (int i = 0; i < roleDescriptors.size(); i++) {
Descriptor descriptor = roleDescriptors.get(i);
if (Ascii.equalsIgnoreCase("urn:mpeg:dash:role:2011", descriptor.schemeIdUri)) {
result |= parseDashRoleSchemeValue(descriptor.value);
result |= parseRoleFlagsFromDashRoleScheme(descriptor.value);
}
}
return result;
Expand All @@ -1423,7 +1439,7 @@ protected int parseRoleFlagsFromAccessibilityDescriptors(
for (int i = 0; i < accessibilityDescriptors.size(); i++) {
Descriptor descriptor = accessibilityDescriptors.get(i);
if (Ascii.equalsIgnoreCase("urn:mpeg:dash:role:2011", descriptor.schemeIdUri)) {
result |= parseDashRoleSchemeValue(descriptor.value);
result |= parseRoleFlagsFromDashRoleScheme(descriptor.value);
} else if (Ascii.equalsIgnoreCase(
"urn:tva:metadata:cs:AudioPurposeCS:2007", descriptor.schemeIdUri)) {
result |= parseTvaAudioPurposeCsValue(descriptor.value);
Expand All @@ -1446,7 +1462,7 @@ protected int parseRoleFlagsFromProperties(List<Descriptor> accessibilityDescrip
}

@C.RoleFlags
protected int parseDashRoleSchemeValue(@Nullable String value) {
protected int parseRoleFlagsFromDashRoleScheme(@Nullable String value) {
if (value == null) {
return 0;
}
Expand All @@ -1465,6 +1481,7 @@ protected int parseDashRoleSchemeValue(@Nullable String value) {
return C.ROLE_FLAG_EMERGENCY;
case "caption":
return C.ROLE_FLAG_CAPTION;
case "forced_subtitle":
case "subtitle":
return C.ROLE_FLAG_SUBTITLE;
case "sign":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,22 @@ public void parseMediaPresentationDescription_text() throws IOException {
assertThat(format.containerMimeType).isEqualTo(MimeTypes.APPLICATION_RAWCC);
assertThat(format.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA608);
assertThat(format.codecs).isEqualTo("cea608");
assertThat(format.roleFlags).isEqualTo(C.ROLE_FLAG_SUBTITLE);
assertThat(adaptationSets.get(0).type).isEqualTo(C.TRACK_TYPE_TEXT);

format = adaptationSets.get(1).representations.get(0).format;
assertThat(format.containerMimeType).isEqualTo(MimeTypes.APPLICATION_MP4);
assertThat(format.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_TTML);
assertThat(format.codecs).isEqualTo("stpp.ttml.im1t");
assertThat(format.roleFlags).isEqualTo(C.ROLE_FLAG_SUBTITLE);
assertThat(format.selectionFlags).isEqualTo(C.SELECTION_FLAG_FORCED);
assertThat(adaptationSets.get(1).type).isEqualTo(C.TRACK_TYPE_TEXT);

format = adaptationSets.get(2).representations.get(0).format;
assertThat(format.containerMimeType).isEqualTo(MimeTypes.APPLICATION_TTML);
assertThat(format.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_TTML);
assertThat(format.codecs).isNull();
assertThat(format.roleFlags).isEqualTo(0);
assertThat(adaptationSets.get(2).type).isEqualTo(C.TRACK_TYPE_TEXT);
}

Expand Down
2 changes: 2 additions & 0 deletions testdata/src/test/assets/media/mpd/sample_mpd_text
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
</SegmentTimeline>
</SegmentTemplate>
<AdaptationSet id="0" mimeType="application/x-rawcc" subsegmentAlignment="true">
<Role schemeIdUri="urn:mpeg:DASH:role:2011" value="subtitle"/>
<Representation id="0" codecs="cea608" bandwidth="16">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
</AdaptationSet>
<AdaptationSet id="0" mimeType="application/mp4" subsegmentAlignment="true">
<Role schemeIdUri="urn:mpeg:DASH:role:2011" value="forced_subtitle"/>
<Representation id="0" codecs="stpp.ttml.im1t" bandwidth="16">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
Expand Down

0 comments on commit 9e4401a

Please sign in to comment.