Add DASH text representation parsing tests

PiperOrigin-RevId: 305140826
This commit is contained in:
olly 2020-04-07 00:17:10 +01:00 committed by Oliver Woodman
parent 2b44ff3c71
commit d87fc72378
2 changed files with 66 additions and 10 deletions

View File

@ -26,6 +26,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.metadata.emsg.EventMessage;
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentTimelineElement;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.io.StringReader;
@ -47,6 +48,7 @@ public class DashManifestParserTest {
private static final String SAMPLE_MPD_EVENT_STREAM = "mpd/sample_mpd_event_stream";
private static final String SAMPLE_MPD_LABELS = "mpd/sample_mpd_labels";
private static final String SAMPLE_MPD_ASSET_IDENTIFIER = "mpd/sample_mpd_asset_identifier";
private static final String SAMPLE_MPD_TEXT = "mpd/sample_mpd_text";
private static final String NEXT_TAG_NAME = "Next";
private static final String NEXT_TAG = "<" + NEXT_TAG_NAME + "/>";
@ -67,15 +69,15 @@ public class DashManifestParserTest {
@Test
public void parseMediaPresentationDescription_segmentTemplate() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest mpd =
DashManifest manifest =
parser.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_SEGMENT_TEMPLATE));
assertThat(mpd.getPeriodCount()).isEqualTo(1);
assertThat(manifest.getPeriodCount()).isEqualTo(1);
Period period = mpd.getPeriod(0);
Period period = manifest.getPeriod(0);
assertThat(period).isNotNull();
assertThat(period.adaptationSets).hasSize(2);
@ -99,13 +101,13 @@ public class DashManifestParserTest {
@Test
public void parseMediaPresentationDescription_eventStream() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest mpd =
DashManifest manifest =
parser.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_EVENT_STREAM));
Period period = mpd.getPeriod(0);
Period period = manifest.getPeriod(0);
assertThat(period.eventStreams).hasSize(3);
// assert text-only event stream
@ -169,14 +171,14 @@ public class DashManifestParserTest {
@Test
public void parseMediaPresentationDescription_programInformation() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest mpd =
DashManifest manifest =
parser.parse(
Uri.parse("Https://example.com/test.mpd"),
TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD));
ProgramInformation expectedProgramInformation =
new ProgramInformation(
"MediaTitle", "MediaSource", "MediaCopyright", "www.example.com", "enUs");
assertThat(mpd.programInformation).isEqualTo(expectedProgramInformation);
assertThat(manifest.programInformation).isEqualTo(expectedProgramInformation);
}
@Test
@ -194,6 +196,35 @@ public class DashManifestParserTest {
assertThat(adaptationSets.get(1).representations.get(0).format.label).isEqualTo("video label");
}
@Test
public void parseMediaPresentationDescription_text() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest manifest =
parser.parse(
Uri.parse("Https://example.com/test.mpd"),
TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_TEXT));
List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;
Format format = adaptationSets.get(0).representations.get(0).format;
assertThat(format.containerMimeType).isEqualTo(MimeTypes.APPLICATION_RAWCC);
assertThat(format.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA608);
assertThat(format.codecs).isEqualTo("cea608");
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(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(adaptationSets.get(2).type).isEqualTo(C.TRACK_TYPE_TEXT);
}
@Test
public void parseSegmentTimeline_repeatCount() throws Exception {
DashManifestParser parser = new DashManifestParser();
@ -382,15 +413,15 @@ public class DashManifestParserTest {
@Test
public void parsePeriodAssetIdentifier() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest mpd =
DashManifest manifest =
parser.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_ASSET_IDENTIFIER));
assertThat(mpd.getPeriodCount()).isEqualTo(1);
assertThat(manifest.getPeriodCount()).isEqualTo(1);
Period period = mpd.getPeriod(0);
Period period = manifest.getPeriod(0);
assertThat(period).isNotNull();
@Nullable Descriptor assetIdentifier = period.assetIdentifier;
assertThat(assetIdentifier).isNotNull();

View File

@ -0,0 +1,25 @@
<?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="application/x-rawcc" subsegmentAlignment="true">
<Representation id="0" codecs="cea608" bandwidth="16">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
</AdaptationSet>
<AdaptationSet id="0" mimeType="application/mp4" subsegmentAlignment="true">
<Representation id="0" codecs="stpp.ttml.im1t" bandwidth="16">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
</AdaptationSet>
<AdaptationSet id="0" mimeType="application/ttml+xml" subsegmentAlignment="true">
<Representation id="0" bandwidth="16">
<BaseURL>https://test.com/0</BaseURL>
</Representation>
</AdaptationSet>
</Period>
</MPD>