DashManifest implements FilterableManifest<DashManifest> { @Override public final DashManifest copy(List<StreamKey> streamKeys) { LinkedList<StreamKey> keys = new LinkedList<>(streamKeys); Collections.sort(keys); keys.add(new StreamKey(-1, -1, -1)); ArrayList<Period> copyPeriods = new ArrayList<>(); long shiftMs = 0; for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) { if (keys.peek().periodIndex != periodIndex) { long periodDurationMs = getPeriodDurationMs(periodIndex); if (periodDurationMs != C.TIME_UNSET) { shiftMs += periodDurationMs; } } else { Period period = getPeriod(periodIndex); ArrayList<AdaptationSet> copyAdaptationSets = copyAdaptationSets(period.adaptationSets, keys); Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets, period.eventStreams); copyPeriods.add(copiedPeriod); } } long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET; return new DashManifest( availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic, minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs, programInformation, utcTiming, location, copyPeriods); } @Deprecated  DashManifest(
      long availabilityStartTimeMs,
      long durationMs,
      long minBufferTimeMs,
      boolean dynamic,
      long minUpdatePeriodMs,
      long timeShiftBufferDepthMs,
      long suggestedPresentationDelayMs,
      long publishTimeMs,
      @Nullable UtcTimingElement utcTiming,
      @Nullable Uri location,
      List<Period> periods);  DashManifest(
      long availabilityStartTimeMs,
      long durationMs,
      long minBufferTimeMs,
      boolean dynamic,
      long minUpdatePeriodMs,
      long timeShiftBufferDepthMs,
      long suggestedPresentationDelayMs,
      long publishTimeMs,
      @Nullable ProgramInformation programInformation,
      @Nullable UtcTimingElement utcTiming,
      @Nullable Uri location,
      List<Period> periods); final int getPeriodCount(); final Period getPeriod(int index); final long getPeriodDurationMs(int index); final long getPeriodDurationUs(int index); @Override final DashManifest copy(List<StreamKey> streamKeys); final long availabilityStartTimeMs; final long durationMs; final long minBufferTimeMs; final boolean dynamic; final long minUpdatePeriodMs; final long timeShiftBufferDepthMs; final long suggestedPresentationDelayMs; final long publishTimeMs; @Nullable final UtcTimingElement utcTiming; @Nullable final Uri location; @Nullable final ProgramInformation programInformation; }
@Test public void testCopy() throws Exception { Representation[][][] representations = newRepresentations(3, 2, 3); DashManifest sourceManifest = newDashManifest( 10, newPeriod( "1", 1, newAdaptationSet(2, representations[0][0]), newAdaptationSet(3, representations[0][1])), newPeriod( "4", 4, newAdaptationSet(5, representations[1][0]), newAdaptationSet(6, representations[1][1])), newPeriod( "7", 7, newAdaptationSet(8, representations[2][0]), newAdaptationSet(9, representations[2][1]))); List<StreamKey> keys = Arrays.asList( new StreamKey(0, 0, 0), new StreamKey(0, 0, 1), new StreamKey(0, 1, 2), new StreamKey(1, 0, 1), new StreamKey(1, 1, 0), new StreamKey(1, 1, 2), new StreamKey(2, 0, 1), new StreamKey(2, 0, 2), new StreamKey(2, 1, 0)); Collections.shuffle(keys, new Random(0)); DashManifest copyManifest = sourceManifest.copy(keys); DashManifest expectedManifest = newDashManifest( 10, newPeriod( "1", 1, newAdaptationSet(2, representations[0][0][0], representations[0][0][1]), newAdaptationSet(3, representations[0][1][2])), newPeriod( "4", 4, newAdaptationSet(5, representations[1][0][1]), newAdaptationSet(6, representations[1][1][0], representations[1][1][2])), newPeriod( "7", 7, newAdaptationSet(8, representations[2][0][1], representations[2][0][2]), newAdaptationSet(9, representations[2][1][0]))); assertManifestEquals(expectedManifest, copyManifest); }
@Test public void testCopySameAdaptationIndexButDifferentPeriod() throws Exception { Representation[][][] representations = newRepresentations(2, 1, 1); DashManifest sourceManifest = newDashManifest( 10, newPeriod("1", 1, newAdaptationSet(2, representations[0][0])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0]))); DashManifest copyManifest = sourceManifest.copy(Arrays.asList(new StreamKey(0, 0, 0), new StreamKey(1, 0, 0))); DashManifest expectedManifest = newDashManifest( 10, newPeriod("1", 1, newAdaptationSet(2, representations[0][0])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0]))); assertManifestEquals(expectedManifest, copyManifest); }
@Test public void testCopySkipPeriod() throws Exception { Representation[][][] representations = newRepresentations(3, 2, 3); DashManifest sourceManifest = newDashManifest( 10, newPeriod( "1", 1, newAdaptationSet(2, representations[0][0]), newAdaptationSet(3, representations[0][1])), newPeriod( "4", 4, newAdaptationSet(5, representations[1][0]), newAdaptationSet(6, representations[1][1])), newPeriod( "7", 7, newAdaptationSet(8, representations[2][0]), newAdaptationSet(9, representations[2][1]))); DashManifest copyManifest = sourceManifest.copy( Arrays.asList( new StreamKey(0, 0, 0), new StreamKey(0, 0, 1), new StreamKey(0, 1, 2), new StreamKey(2, 0, 1), new StreamKey(2, 0, 2), new StreamKey(2, 1, 0))); DashManifest expectedManifest = newDashManifest( 7, newPeriod( "1", 1, newAdaptationSet(2, representations[0][0][0], representations[0][0][1]), newAdaptationSet(3, representations[0][1][2])), newPeriod( "7", 4, newAdaptationSet(8, representations[2][0][1], representations[2][0][2]), newAdaptationSet(9, representations[2][1][0]))); assertManifestEquals(expectedManifest, copyManifest); }