diff --git a/library/dash/src/test/assets/sample_mpd_1 b/library/dash/src/test/assets/sample_mpd similarity index 99% rename from library/dash/src/test/assets/sample_mpd_1 rename to library/dash/src/test/assets/sample_mpd index ccd3ab4dd6..8417d2f7c4 100644 --- a/library/dash/src/test/assets/sample_mpd_1 +++ b/library/dash/src/test/assets/sample_mpd @@ -102,4 +102,3 @@ http://www.test.com/vtt - diff --git a/library/dash/src/test/assets/sample_mpd_4_event_stream b/library/dash/src/test/assets/sample_mpd_event_stream similarity index 99% rename from library/dash/src/test/assets/sample_mpd_4_event_stream rename to library/dash/src/test/assets/sample_mpd_event_stream index e4c927260d..4148b420f1 100644 --- a/library/dash/src/test/assets/sample_mpd_4_event_stream +++ b/library/dash/src/test/assets/sample_mpd_event_stream @@ -44,4 +44,3 @@ - diff --git a/library/dash/src/test/assets/sample_mpd_3_segment_template b/library/dash/src/test/assets/sample_mpd_segment_template similarity index 99% rename from library/dash/src/test/assets/sample_mpd_3_segment_template rename to library/dash/src/test/assets/sample_mpd_segment_template index a9147b54df..d45ab14f52 100644 --- a/library/dash/src/test/assets/sample_mpd_3_segment_template +++ b/library/dash/src/test/assets/sample_mpd_segment_template @@ -35,4 +35,3 @@ - diff --git a/library/dash/src/test/assets/sample_mpd_2_unknown_mime_type b/library/dash/src/test/assets/sample_mpd_unknown_mime_type similarity index 99% rename from library/dash/src/test/assets/sample_mpd_2_unknown_mime_type rename to library/dash/src/test/assets/sample_mpd_unknown_mime_type index c6f00965e3..4645e3c859 100644 --- a/library/dash/src/test/assets/sample_mpd_2_unknown_mime_type +++ b/library/dash/src/test/assets/sample_mpd_unknown_mime_type @@ -115,4 +115,3 @@ http://www.test.com/vtt - 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 6f5bc5c83d..d2a4f1cd6f 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 @@ -40,32 +40,35 @@ import org.xmlpull.v1.XmlPullParserFactory; @RunWith(AndroidJUnit4.class) public class DashManifestParserTest { - private static final String SAMPLE_MPD_1 = "sample_mpd_1"; - private static final String SAMPLE_MPD_2_UNKNOWN_MIME_TYPE = "sample_mpd_2_unknown_mime_type"; - private static final String SAMPLE_MPD_3_SEGMENT_TEMPLATE = "sample_mpd_3_segment_template"; - private static final String SAMPLE_MPD_4_EVENT_STREAM = "sample_mpd_4_event_stream"; + private static final String SAMPLE_MPD = "sample_mpd"; + 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 NEXT_TAG_NAME = "Next"; + private static final String NEXT_TAG = "<" + NEXT_TAG_NAME + "/>"; /** Simple test to ensure the sample manifests parse without any exceptions being thrown. */ @Test - public void testParseMediaPresentationDescription() throws IOException { + public void parseMediaPresentationDescription() throws IOException { DashManifestParser parser = new DashManifestParser(); parser.parse( Uri.parse("https://example.com/test.mpd"), - TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_1)); + TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD)); parser.parse( Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream( - ApplicationProvider.getApplicationContext(), SAMPLE_MPD_2_UNKNOWN_MIME_TYPE)); + ApplicationProvider.getApplicationContext(), SAMPLE_MPD_UNKNOWN_MIME_TYPE)); } @Test - public void testParseMediaPresentationDescriptionWithSegmentTemplate() throws IOException { + public void parseMediaPresentationDescription_segmentTemplate() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream( - ApplicationProvider.getApplicationContext(), SAMPLE_MPD_3_SEGMENT_TEMPLATE)); + ApplicationProvider.getApplicationContext(), SAMPLE_MPD_SEGMENT_TEMPLATE)); assertThat(mpd.getPeriodCount()).isEqualTo(1); @@ -91,13 +94,13 @@ public class DashManifestParserTest { } @Test - public void testParseMediaPresentationDescriptionCanParseEventStream() throws IOException { + public void parseMediaPresentationDescription_eventStream() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream( - ApplicationProvider.getApplicationContext(), SAMPLE_MPD_4_EVENT_STREAM)); + ApplicationProvider.getApplicationContext(), SAMPLE_MPD_EVENT_STREAM)); Period period = mpd.getPeriod(0); assertThat(period.eventStreams).hasSize(3); @@ -161,12 +164,12 @@ public class DashManifestParserTest { } @Test - public void testParseMediaPresentationDescriptionCanParseProgramInformation() throws IOException { + public void parseMediaPresentationDescription_programInformation() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("Https://example.com/test.mpd"), - TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_1)); + TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD)); ProgramInformation expectedProgramInformation = new ProgramInformation( "MediaTitle", "MediaSource", "MediaCopyright", "www.example.com", "enUs"); @@ -174,7 +177,82 @@ public class DashManifestParserTest { } @Test - public void testParseCea608AccessibilityChannel() { + public void parseSegmentTimeline_repeatCount() throws Exception { + DashManifestParser parser = new DashManifestParser(); + XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); + xpp.setInput( + new StringReader( + "" + + NEXT_TAG)); + xpp.next(); + + List elements = + parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); + + assertThat(elements) + .containsExactly( + new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 48000)) + .inOrder(); + assertNextTag(xpp); + } + + @Test + public void parseSegmentTimeline_singleUndefinedRepeatCount() throws Exception { + DashManifestParser parser = new DashManifestParser(); + XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); + xpp.setInput( + new StringReader( + "" + NEXT_TAG)); + xpp.next(); + + List elements = + parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); + + assertThat(elements) + .containsExactly( + new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 384000, /* duration= */ 96000)) + .inOrder(); + assertNextTag(xpp); + } + + @Test + public void parseSegmentTimeline_timeOffsetsAndUndefinedRepeatCount() throws Exception { + DashManifestParser parser = new DashManifestParser(); + XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); + xpp.setInput( + new StringReader( + "" + + "" + + NEXT_TAG)); + xpp.next(); + + List elements = + parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); + + assertThat(elements) + .containsExactly( + new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), + new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 48000), + new SegmentTimelineElement(/* startTime= */ 240000, /* duration= */ 48000), + new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 48000), + new SegmentTimelineElement(/* startTime= */ 336000, /* duration= */ 48000), + new SegmentTimelineElement(/* startTime= */ 384000, /* duration= */ 48000), + new SegmentTimelineElement(/* startTime= */ 432000, /* duration= */ 48000)) + .inOrder(); + assertNextTag(xpp); + } + + @Test + public void parseCea608AccessibilityChannel() { assertThat( DashManifestParser.parseCea608AccessibilityChannel( buildCea608AccessibilityDescriptors("CC1=eng"))) @@ -215,7 +293,7 @@ public class DashManifestParserTest { } @Test - public void testParseCea708AccessibilityChannel() { + public void parseCea708AccessibilityChannel() { assertThat( DashManifestParser.parseCea708AccessibilityChannel( buildCea708AccessibilityDescriptors("1=lang:eng"))) @@ -259,74 +337,6 @@ public class DashManifestParserTest { .isEqualTo(Format.NO_VALUE); } - @Test - public void parseSegmentTimeline_withRepeatCount() throws Exception { - DashManifestParser parser = new DashManifestParser(); - XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); - xpp.setInput( - new StringReader( - "")); - xpp.next(); - - List elements = - parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); - - assertThat(elements) - .containsExactly( - new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 48000)) - .inOrder(); - } - - @Test - public void parseSegmentTimeline_withSingleUndefinedRepeatCount() throws Exception { - DashManifestParser parser = new DashManifestParser(); - XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); - xpp.setInput(new StringReader("")); - xpp.next(); - - List elements = - parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); - - assertThat(elements) - .containsExactly( - new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 384000, /* duration= */ 96000)) - .inOrder(); - } - - @Test - public void parseSegmentTimeline_withTimeOffsetsAndUndefinedRepeatCount() throws Exception { - DashManifestParser parser = new DashManifestParser(); - XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); - xpp.setInput( - new StringReader( - "" - + "")); - xpp.next(); - - List elements = - parser.parseSegmentTimeline(xpp, /* timescale= */ 48000, /* periodDurationMs= */ 10000); - - assertThat(elements) - .containsExactly( - new SegmentTimelineElement(/* startTime= */ 0, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 96000, /* duration= */ 96000), - new SegmentTimelineElement(/* startTime= */ 192000, /* duration= */ 48000), - new SegmentTimelineElement(/* startTime= */ 240000, /* duration= */ 48000), - new SegmentTimelineElement(/* startTime= */ 288000, /* duration= */ 48000), - new SegmentTimelineElement(/* startTime= */ 336000, /* duration= */ 48000), - new SegmentTimelineElement(/* startTime= */ 384000, /* duration= */ 48000), - new SegmentTimelineElement(/* startTime= */ 432000, /* duration= */ 48000)) - .inOrder(); - } - private static List buildCea608AccessibilityDescriptors(String value) { return Collections.singletonList(new Descriptor("urn:scte:dash:cc:cea-608:2015", value, null)); } @@ -334,4 +344,10 @@ public class DashManifestParserTest { private static List buildCea708AccessibilityDescriptors(String value) { return Collections.singletonList(new Descriptor("urn:scte:dash:cc:cea-708:2015", value, null)); } + + private static void assertNextTag(XmlPullParser xpp) throws Exception { + xpp.next(); + assertThat(xpp.getEventType()).isEqualTo(XmlPullParser.START_TAG); + assertThat(xpp.getName()).isEqualTo(NEXT_TAG_NAME); + } }