DashManifestParser extends DefaultHandler implements ParsingLoadable.Parser<DashManifest> { protected List<SegmentTimelineElement> parseSegmentTimeline( XmlPullParser xpp, long timescale, long periodDurationMs) throws XmlPullParserException, IOException { List<SegmentTimelineElement> segmentTimeline = new ArrayList<>(); long startTime = 0; long elementDuration = C.TIME_UNSET; int elementRepeatCount = 0; boolean havePreviousTimelineElement = false; do { xpp.next(); if (XmlPullParserUtil.isStartTag(xpp, "S")) { long newStartTime = parseLong(xpp, "t", C.TIME_UNSET); if (havePreviousTimelineElement) { startTime = addSegmentTimelineElementsToList( segmentTimeline, startTime, elementDuration, elementRepeatCount, newStartTime); } if (newStartTime != C.TIME_UNSET) { startTime = newStartTime; } elementDuration = parseLong(xpp, "d", C.TIME_UNSET); elementRepeatCount = parseInt(xpp, "r", 0); havePreviousTimelineElement = true; } else { maybeSkipTag(xpp); } } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTimeline")); if (havePreviousTimelineElement) { long periodDuration = Util.scaleLargeTimestamp(periodDurationMs, timescale, 1000); addSegmentTimelineElementsToList( segmentTimeline, startTime, elementDuration, elementRepeatCount, periodDuration); } return segmentTimeline; } DashManifestParser(); @Override DashManifest parse(Uri uri, InputStream inputStream); static void maybeSkipTag(XmlPullParser xpp);  }
@Test public void parseSegmentTimeline_repeatCount() throws Exception { DashManifestParser parser = new DashManifestParser(); XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); xpp.setInput( new StringReader( "<SegmentTimeline><S d=\"96000\" r=\"2\"/><S d=\"48000\" r=\"0\"/></SegmentTimeline>" + NEXT_TAG)); xpp.next(); List<SegmentTimelineElement> elements = parser.parseSegmentTimeline(xpp, 48000, 10000); assertThat(elements) .containsExactly( new SegmentTimelineElement( 0, 96000), new SegmentTimelineElement( 96000, 96000), new SegmentTimelineElement( 192000, 96000), new SegmentTimelineElement( 288000, 48000)) .inOrder(); assertNextTag(xpp); }
@Test public void parseSegmentTimeline_singleUndefinedRepeatCount() throws Exception { DashManifestParser parser = new DashManifestParser(); XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); xpp.setInput( new StringReader( "<SegmentTimeline><S d=\"96000\" r=\"-1\"/></SegmentTimeline>" + NEXT_TAG)); xpp.next(); List<SegmentTimelineElement> elements = parser.parseSegmentTimeline(xpp, 48000, 10000); assertThat(elements) .containsExactly( new SegmentTimelineElement( 0, 96000), new SegmentTimelineElement( 96000, 96000), new SegmentTimelineElement( 192000, 96000), new SegmentTimelineElement( 288000, 96000), new SegmentTimelineElement( 384000, 96000)) .inOrder(); assertNextTag(xpp); }
@Test public void parseSegmentTimeline_timeOffsetsAndUndefinedRepeatCount() throws Exception { DashManifestParser parser = new DashManifestParser(); XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); xpp.setInput( new StringReader( "<SegmentTimeline><S t=\"0\" " + "d=\"96000\" r=\"-1\"/><S t=\"192000\" d=\"48000\" r=\"-1\"/>" + "</SegmentTimeline>" + NEXT_TAG)); xpp.next(); List<SegmentTimelineElement> elements = parser.parseSegmentTimeline(xpp, 48000, 10000); assertThat(elements) .containsExactly( new SegmentTimelineElement( 0, 96000), new SegmentTimelineElement( 96000, 96000), new SegmentTimelineElement( 192000, 48000), new SegmentTimelineElement( 240000, 48000), new SegmentTimelineElement( 288000, 48000), new SegmentTimelineElement( 336000, 48000), new SegmentTimelineElement( 384000, 48000), new SegmentTimelineElement( 432000, 48000)) .inOrder(); assertNextTag(xpp); }