Skip to content

Commit

Permalink
Parse Label elements for adaptation sets
Browse files Browse the repository at this point in the history
Issue: #6297
PiperOrigin-RevId: 273297284
  • Loading branch information
ojw28 committed Oct 13, 2019
1 parent 904e3f8 commit 0249058
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 13 deletions.
4 changes: 3 additions & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Add `Player.onPlaybackSuppressionReasonChanged` to allow listeners to
detect playbacks suppressions (e.g. audio focus loss) directly
([#6203](https://github.com/google/ExoPlayer/issues/6203)).
* Expose the raw ICY metadata through `IcyInfo`
* DASH: Support `Label` elements
([#6297](https://github.com/google/ExoPlayer/issues/6297)).
* Metadata: Expose the raw ICY metadata through `IcyInfo`
([#6476](https://github.com/google/ExoPlayer/issues/6476)).
* UI
* Setting `app:played_color` on `PlayerView` and `PlayerControlView` no longer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,38 @@ public Format copyWithSubsampleOffsetUs(long subsampleOffsetUs) {
accessibilityChannel);
}

public Format copyWithLabel(@Nullable String label) {
return new Format(
id,
label,
selectionFlags,
roleFlags,
bitrate,
codecs,
metadata,
containerMimeType,
sampleMimeType,
maxInputSize,
initializationData,
drmInitData,
subsampleOffsetUs,
width,
height,
frameRate,
rotationDegrees,
pixelWidthHeightRatio,
projectionData,
stereoMode,
colorInfo,
channelCount,
sampleRate,
pcmEncoding,
encoderDelay,
encoderPadding,
language,
accessibilityChannel);
}

public Format copyWithContainerInfo(
@Nullable String id,
@Nullable String label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
parseRepresentation(
xpp,
baseUrl,
label,
mimeType,
codecs,
width,
Expand All @@ -338,6 +337,8 @@ protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
parseSegmentTemplate(xpp, (SegmentTemplate) segmentBase, supplementalProperties);
} else if (XmlPullParserUtil.isStartTag(xpp, "InbandEventStream")) {
inbandEventStreams.add(parseDescriptor(xpp, "InbandEventStream"));
} else if (XmlPullParserUtil.isStartTag(xpp, "Label")) {
label = parseLabel(xpp);
} else if (XmlPullParserUtil.isStartTag(xpp)) {
parseAdaptationSetChild(xpp);
}
Expand All @@ -348,7 +349,11 @@ protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
for (int i = 0; i < representationInfos.size(); i++) {
representations.add(
buildRepresentation(
representationInfos.get(i), drmSchemeType, drmSchemeDatas, inbandEventStreams));
representationInfos.get(i),
label,
drmSchemeType,
drmSchemeDatas,
inbandEventStreams));
}

return buildAdaptationSet(id, contentType, representations, accessibilityDescriptors,
Expand Down Expand Up @@ -484,7 +489,6 @@ protected void parseAdaptationSetChild(XmlPullParser xpp)
protected RepresentationInfo parseRepresentation(
XmlPullParser xpp,
String baseUrl,
String label,
String adaptationSetMimeType,
String adaptationSetCodecs,
int adaptationSetWidth,
Expand Down Expand Up @@ -551,7 +555,6 @@ protected RepresentationInfo parseRepresentation(
Format format =
buildFormat(
id,
label,
mimeType,
width,
height,
Expand All @@ -572,7 +575,6 @@ protected RepresentationInfo parseRepresentation(

protected Format buildFormat(
String id,
String label,
String containerMimeType,
int width,
int height,
Expand All @@ -596,7 +598,7 @@ protected Format buildFormat(
if (MimeTypes.isVideo(sampleMimeType)) {
return Format.createVideoContainerFormat(
id,
label,
/* label= */ null,
containerMimeType,
sampleMimeType,
codecs,
Expand All @@ -611,7 +613,7 @@ protected Format buildFormat(
} else if (MimeTypes.isAudio(sampleMimeType)) {
return Format.createAudioContainerFormat(
id,
label,
/* label= */ null,
containerMimeType,
sampleMimeType,
codecs,
Expand All @@ -634,7 +636,7 @@ protected Format buildFormat(
}
return Format.createTextContainerFormat(
id,
label,
/* label= */ null,
containerMimeType,
sampleMimeType,
codecs,
Expand All @@ -647,7 +649,7 @@ protected Format buildFormat(
}
return Format.createContainerFormat(
id,
label,
/* label= */ null,
containerMimeType,
sampleMimeType,
codecs,
Expand All @@ -659,10 +661,14 @@ protected Format buildFormat(

protected Representation buildRepresentation(
RepresentationInfo representationInfo,
String label,
String extraDrmSchemeType,
ArrayList<SchemeData> extraDrmSchemeDatas,
ArrayList<Descriptor> extraInbandEventStreams) {
Format format = representationInfo.format;
if (label != null) {
format = format.copyWithLabel(label);
}
String drmSchemeType = representationInfo.drmSchemeType != null
? representationInfo.drmSchemeType : extraDrmSchemeType;
ArrayList<SchemeData> drmSchemeDatas = representationInfo.drmSchemeDatas;
Expand Down Expand Up @@ -1076,6 +1082,32 @@ protected ProgramInformation parseProgramInformation(XmlPullParser xpp)
return new ProgramInformation(title, source, copyright, moreInformationURL, lang);
}

/**
* Parses a Label element.
*
* @param xpp The parser from which to read.
* @throws XmlPullParserException If an error occurs parsing the element.
* @throws IOException If an error occurs reading the element.
* @return The parsed label.
*/
protected String parseLabel(XmlPullParser xpp) throws XmlPullParserException, IOException {
return parseText(xpp, "Label");
}

/**
* Parses a BaseURL element.
*
* @param xpp The parser from which to read.
* @param parentBaseUrl A base URL for resolving the parsed URL.
* @throws XmlPullParserException If an error occurs parsing the element.
* @throws IOException If an error occurs reading the element.
* @return The parsed and resolved URL.
*/
protected String parseBaseUrl(XmlPullParser xpp, String parentBaseUrl)
throws XmlPullParserException, IOException {
return UriUtil.resolve(parentBaseUrl, parseText(xpp, "BaseURL"));
}

// AudioChannelConfiguration parsing.

protected int parseAudioChannelConfiguration(XmlPullParser xpp)
Expand Down Expand Up @@ -1427,10 +1459,18 @@ protected static long parseDateTime(XmlPullParser xpp, String name, long default
}
}

protected static String parseBaseUrl(XmlPullParser xpp, String parentBaseUrl)
protected static String parseText(XmlPullParser xpp, String label)
throws XmlPullParserException, IOException {
xpp.next();
return UriUtil.resolve(parentBaseUrl, xpp.getText());
String text = "";
do {
xpp.next();
if (xpp.getEventType() == XmlPullParser.TEXT) {
text = xpp.getText();
} else {
maybeSkipTag(xpp);
}
} while (!XmlPullParserUtil.isEndTag(xpp, label));
return text;
}

protected static int parseInt(XmlPullParser xpp, String name, int defaultValue) {
Expand Down
21 changes: 21 additions & 0 deletions library/dash/src/test/assets/sample_mpd_labels
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD type="static" duration="1s" mediaPresentationDuration="PT1S">
<Period>
<SegmentTemplate startNumber="0" timescale="1000" media="sq/$Number$">
<SegmentTimeline>
<S d="1000"/>
</SegmentTimeline>
</SegmentTemplate>
<AdaptationSet id="0" mimeType="audio/mp4" subsegmentAlignment="true" label="audio label">
<Representation id="0" codecs="mp4a.40.2" audioSamplingRate="48000" bandwidth="144000">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" mimeType="video/mp4" subsegmentAlignment="true" label="ignored label">
<Representation id="1" codecs="avc1.4d4015" width="426" height="240" bandwidth="258000">
<BaseURL>https://test.com/1</BaseURL>
</Representation>
<Label>video label</Label>
</AdaptationSet>
</Period>
</MPD>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class DashManifestParserTest {
private static final String SAMPLE_MPD_UNKNOWN_MIME_TYPE = "sample_mpd_unknown_mime_type";
private static final String SAMPLE_MPD_SEGMENT_TEMPLATE = "sample_mpd_segment_template";
private static final String SAMPLE_MPD_EVENT_STREAM = "sample_mpd_event_stream";
private static final String SAMPLE_MPD_LABELS = "sample_mpd_labels";

private static final String NEXT_TAG_NAME = "Next";
private static final String NEXT_TAG = "<" + NEXT_TAG_NAME + "/>";
Expand Down Expand Up @@ -172,6 +173,21 @@ public void parseMediaPresentationDescription_programInformation() throws IOExce
assertThat(mpd.programInformation).isEqualTo(expectedProgramInformation);
}

@Test
public void parseMediaPresentationDescription_labels() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest manifest =
parser.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_LABELS));

List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;

assertThat(adaptationSets.get(0).representations.get(0).format.label).isEqualTo("audio label");
assertThat(adaptationSets.get(1).representations.get(0).format.label).isEqualTo("video label");
}

@Test
public void parseSegmentTimeline_repeatCount() throws Exception {
DashManifestParser parser = new DashManifestParser();
Expand Down Expand Up @@ -247,6 +263,30 @@ public void parseSegmentTimeline_timeOffsetsAndUndefinedRepeatCount() throws Exc
assertNextTag(xpp);
}

@Test
public void parseLabel() throws Exception {
DashManifestParser parser = new DashManifestParser();
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
xpp.setInput(new StringReader("<Label>test label</Label>" + NEXT_TAG));
xpp.next();

String label = parser.parseLabel(xpp);
assertThat(label).isEqualTo("test label");
assertNextTag(xpp);
}

@Test
public void parseLabel_noText() throws Exception {
DashManifestParser parser = new DashManifestParser();
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
xpp.setInput(new StringReader("<Label/>" + NEXT_TAG));
xpp.next();

String label = parser.parseLabel(xpp);
assertThat(label).isEqualTo("");
assertNextTag(xpp);
}

@Test
public void parseCea608AccessibilityChannel() {
assertThat(
Expand Down

0 comments on commit 0249058

Please sign in to comment.