SsManifest implements FilterableManifest<SsManifest> { @Override public final SsManifest copy(List<StreamKey> streamKeys) { ArrayList<StreamKey> sortedKeys = new ArrayList<>(streamKeys); Collections.sort(sortedKeys); StreamElement currentStreamElement = null; List<StreamElement> copiedStreamElements = new ArrayList<>(); List<Format> copiedFormats = new ArrayList<>(); for (int i = 0; i < sortedKeys.size(); i++) { StreamKey key = sortedKeys.get(i); StreamElement streamElement = streamElements[key.groupIndex]; if (streamElement != currentStreamElement && currentStreamElement != null) { copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0]))); copiedFormats.clear(); } currentStreamElement = streamElement; copiedFormats.add(streamElement.formats[key.trackIndex]); } if (currentStreamElement != null) { copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0]))); } StreamElement[] copiedStreamElementsArray = copiedStreamElements.toArray(new StreamElement[0]); return new SsManifest( majorVersion, minorVersion, durationUs, dvrWindowLengthUs, lookAheadCount, isLive, protectionElement, copiedStreamElementsArray); } SsManifest(
      int majorVersion,
      int minorVersion,
      long timescale,
      long duration,
      long dvrWindowLength,
      int lookAheadCount,
      boolean isLive,
      @Nullable ProtectionElement protectionElement,
      StreamElement[] streamElements); private  SsManifest(
      int majorVersion,
      int minorVersion,
      long durationUs,
      long dvrWindowLengthUs,
      int lookAheadCount,
      boolean isLive,
      @Nullable ProtectionElement protectionElement,
      StreamElement[] streamElements); @Override final SsManifest copy(List<StreamKey> streamKeys); static final int UNSET_LOOKAHEAD; final int majorVersion; final int minorVersion; final int lookAheadCount; final boolean isLive; @Nullable final ProtectionElement protectionElement; final StreamElement[] streamElements; final long durationUs; final long dvrWindowLengthUs; }
@Test public void testCopy() throws Exception { Format[][] formats = newFormats(2, 3); SsManifest sourceManifest = createSsManifest( createStreamElement("1", formats[0]), createStreamElement("2", formats[1])); List<StreamKey> keys = Arrays.asList(new StreamKey(0, 0), new StreamKey(0, 2), new StreamKey(1, 0)); Collections.shuffle(keys, new Random(0)); SsManifest copyManifest = sourceManifest.copy(keys); SsManifest expectedManifest = createSsManifest( createStreamElement("1", formats[0][0], formats[0][2]), createStreamElement("2", formats[1][0])); assertManifestEquals(expectedManifest, copyManifest); }
@Test public void testCopyRemoveStreamElement() throws Exception { Format[][] formats = newFormats(2, 3); SsManifest sourceManifest = createSsManifest( createStreamElement("1", formats[0]), createStreamElement("2", formats[1])); List<StreamKey> keys = Collections.singletonList(new StreamKey(1, 0)); SsManifest copyManifest = sourceManifest.copy(keys); SsManifest expectedManifest = createSsManifest(createStreamElement("2", formats[1][0])); assertManifestEquals(expectedManifest, copyManifest); }