From d87fc72378399d2a61a3c9065b56a41382efb951 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 7 Apr 2020 00:17:10 +0100 Subject: [PATCH] Add DASH text representation parsing tests PiperOrigin-RevId: 305140826 --- .../dash/manifest/DashManifestParserTest.java | 51 +++++++++++++++---- testdata/src/test/assets/mpd/sample_mpd_text | 25 +++++++++ 2 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 testdata/src/test/assets/mpd/sample_mpd_text diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java index 55b3f971f5..37b3046a54 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java @@ -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 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(); diff --git a/testdata/src/test/assets/mpd/sample_mpd_text b/testdata/src/test/assets/mpd/sample_mpd_text new file mode 100644 index 0000000000..d3235d5ed0 --- /dev/null +++ b/testdata/src/test/assets/mpd/sample_mpd_text @@ -0,0 +1,25 @@ + + + + + + + + + + + https://test.com/0 + + + + + https://test.com/0 + + + + + https://test.com/0 + + + +