DashManifestParser extends DefaultHandler implements ParsingLoadable.Parser<DashManifest> { @Override public DashManifest parse(Uri uri, InputStream inputStream) throws IOException { try { XmlPullParser xpp = xmlParserFactory.newPullParser(); xpp.setInput(inputStream, null); int eventType = xpp.next(); if (eventType != XmlPullParser.START_TAG || !"MPD".equals(xpp.getName())) { throw new ParserException( "inputStream does not contain a valid media presentation description"); } return parseMediaPresentationDescription(xpp, uri.toString()); } catch (XmlPullParserException e) { throw new ParserException(e); } } DashManifestParser(); @Override DashManifest parse(Uri uri, InputStream inputStream); static void maybeSkipTag(XmlPullParser xpp);  }
@Test public void parseMediaPresentationDescription_segmentTemplate() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("https: TestUtil.getInputStream( ApplicationProvider.getApplicationContext(), SAMPLE_MPD_SEGMENT_TEMPLATE)); assertThat(mpd.getPeriodCount()).isEqualTo(1); Period period = mpd.getPeriod(0); assertThat(period).isNotNull(); assertThat(period.adaptationSets).hasSize(2); for (AdaptationSet adaptationSet : period.adaptationSets) { assertThat(adaptationSet).isNotNull(); for (Representation representation : adaptationSet.representations) { if (representation instanceof Representation.MultiSegmentRepresentation) { Representation.MultiSegmentRepresentation multiSegmentRepresentation = (Representation.MultiSegmentRepresentation) representation; long firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum(); RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex); assertThat( uri.resolveUriString(representation.baseUrl) .contains("redirector.googlevideo.com")) .isTrue(); } } } }
@Test public void parseMediaPresentationDescription_eventStream() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("https: TestUtil.getInputStream( ApplicationProvider.getApplicationContext(), SAMPLE_MPD_EVENT_STREAM)); Period period = mpd.getPeriod(0); assertThat(period.eventStreams).hasSize(3); EventStream eventStream1 = period.eventStreams.get(0); assertThat(eventStream1.events.length).isEqualTo(1); EventMessage expectedEvent1 = new EventMessage( "urn:uuid:XYZY", "call", 10000, 0, "+ 1 800 10101010".getBytes(Charset.forName(C.UTF8_NAME))); assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1); assertThat(eventStream1.presentationTimesUs[0]).isEqualTo(0); EventStream eventStream2 = period.eventStreams.get(1); assertThat(eventStream2.events.length).isEqualTo(1); EventMessage expectedEvent2 = new EventMessage( "urn:dvb:iptv:cpm:2014", "", 1500000, 1, Util.getUtf8Bytes( "<![CDATA[<BroadcastEvent>\n" + " <Program crid=\"crid: + " <InstanceDescription>\n" + " <Title xml:lang=\"en\">The title</Title>\n" + " <Synopsis xml:lang=\"en\" length=\"medium\">" + "The description</Synopsis>\n" + " <ParentalGuidance>\n" + " <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n" + " <mpeg7:Region>GB</mpeg7:Region>\n" + " </ParentalGuidance>\n" + " </InstanceDescription>\n" + " </BroadcastEvent>]]>")); assertThat(eventStream2.events[0]).isEqualTo(expectedEvent2); assertThat(eventStream2.presentationTimesUs[0]).isEqualTo(300000000); EventStream eventStream3 = period.eventStreams.get(2); assertThat(eventStream3.events.length).isEqualTo(1); EventMessage expectedEvent3 = new EventMessage( "urn:scte:scte35:2014:xml+bin", "", 1000000, 2, Util.getUtf8Bytes( "<scte35:Signal>\n" + " <scte35:Binary>\n" + " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n" + " </scte35:Binary>\n" + " </scte35:Signal>")); assertThat(eventStream3.events[0]).isEqualTo(expectedEvent3); assertThat(eventStream3.presentationTimesUs[0]).isEqualTo(1000000000); }
@Test public void parseMediaPresentationDescription_programInformation() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse( Uri.parse("Https: TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD)); ProgramInformation expectedProgramInformation = new ProgramInformation( "MediaTitle", "MediaSource", "MediaCopyright", "www.example.com", "enUs"); assertThat(mpd.programInformation).isEqualTo(expectedProgramInformation); }
@Test public void parseMediaPresentationDescription_labels() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest manifest = parser.parse( Uri.parse("https: 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"); }