com.google.android.exoplayer2.offline.StreamKey Java Examples

The following examples show how to use com.google.android.exoplayer2.offline.StreamKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HlsMasterPlaylist.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public HlsMasterPlaylist copy(List<StreamKey> streamKeys) {
  return new HlsMasterPlaylist(
      baseUri,
      tags,
      copyStreams(variants, GROUP_INDEX_VARIANT, streamKeys),
      // TODO: Allow stream keys to specify video renditions to be retained.
      /* videos= */ Collections.emptyList(),
      copyStreams(audios, GROUP_INDEX_AUDIO, streamKeys),
      copyStreams(subtitles, GROUP_INDEX_SUBTITLE, streamKeys),
      // TODO: Update to retain all closed captions.
      /* closedCaptions= */ Collections.emptyList(),
      muxedAudioFormat,
      muxedCaptionFormats,
      hasIndependentSegments,
      variableDefinitions,
      sessionKeyDrmInitData);
}
 
Example #2
Source File: HlsMasterPlaylist.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static <T> List<T> copyStreams(
    List<T> streams, int groupIndex, List<StreamKey> streamKeys) {
  List<T> copiedStreams = new ArrayList<>(streamKeys.size());
  // TODO:
  // 1. When variants with the same URL are not de-duplicated, duplicates must not increment
  //    trackIndex so as to avoid breaking stream keys that have been persisted for offline. All
  //    duplicates should be copied if the first variant is copied, or discarded otherwise.
  // 2. When renditions with null URLs are permitted, they must not increment trackIndex so as to
  //    avoid breaking stream keys that have been persisted for offline. All renitions with null
  //    URLs should be copied. They may become unreachable if all variants that reference them are
  //    removed, but this is OK.
  // 3. Renditions with URLs matching copied variants should always themselves be copied, even if
  //    the corresponding stream key is omitted. Else we're throwing away information for no gain.
  for (int i = 0; i < streams.size(); i++) {
    T stream = streams.get(i);
    for (int j = 0; j < streamKeys.size(); j++) {
      StreamKey streamKey = streamKeys.get(j);
      if (streamKey.groupIndex == groupIndex && streamKey.trackIndex == i) {
        copiedStreams.add(stream);
        break;
      }
    }
  }
  return copiedStreams;
}
 
Example #3
Source File: HlsMasterPlaylist.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static <T> List<T> copyStreams(
    List<T> streams, int groupIndex, List<StreamKey> streamKeys) {
  List<T> copiedStreams = new ArrayList<>(streamKeys.size());
  // TODO:
  // 1. When variants with the same URL are not de-duplicated, duplicates must not increment
  //    trackIndex so as to avoid breaking stream keys that have been persisted for offline. All
  //    duplicates should be copied if the first variant is copied, or discarded otherwise.
  // 2. When renditions with null URLs are permitted, they must not increment trackIndex so as to
  //    avoid breaking stream keys that have been persisted for offline. All renitions with null
  //    URLs should be copied. They may become unreachable if all variants that reference them are
  //    removed, but this is OK.
  // 3. Renditions with URLs matching copied variants should always themselves be copied, even if
  //    the corresponding stream key is omitted. Else we're throwing away information for no gain.
  for (int i = 0; i < streams.size(); i++) {
    T stream = streams.get(i);
    for (int j = 0; j < streamKeys.size(); j++) {
      StreamKey streamKey = streamKeys.get(j);
      if (streamKey.groupIndex == groupIndex && streamKey.trackIndex == i) {
        copiedStreams.add(stream);
        break;
      }
    }
  }
  return copiedStreams;
}
 
Example #4
Source File: HlsMasterPlaylist.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public HlsMasterPlaylist copy(List<StreamKey> streamKeys) {
  return new HlsMasterPlaylist(
      baseUri,
      tags,
      copyStreams(variants, GROUP_INDEX_VARIANT, streamKeys),
      // TODO: Allow stream keys to specify video renditions to be retained.
      /* videos= */ Collections.emptyList(),
      copyStreams(audios, GROUP_INDEX_AUDIO, streamKeys),
      copyStreams(subtitles, GROUP_INDEX_SUBTITLE, streamKeys),
      // TODO: Update to retain all closed captions.
      /* closedCaptions= */ Collections.emptyList(),
      muxedAudioFormat,
      muxedCaptionFormats,
      hasIndependentSegments,
      variableDefinitions,
      sessionKeyDrmInitData);
}
 
Example #5
Source File: SsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  List<StreamKey> streamKeys = new ArrayList<>();
  for (int selectionIndex = 0; selectionIndex < trackSelections.size(); selectionIndex++) {
    TrackSelection trackSelection = trackSelections.get(selectionIndex);
    int streamElementIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
    for (int i = 0; i < trackSelection.length(); i++) {
      streamKeys.add(new StreamKey(streamElementIndex, trackSelection.getIndexInTrackGroup(i)));
    }
  }
  return streamKeys;
}
 
Example #6
Source File: HlsDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected StreamKey readKey(int version, DataInputStream input) throws IOException {
  if (version > 0) {
    return super.readKey(version, input);
  }
  int renditionGroup = input.readInt();
  int trackIndex = input.readInt();
  return new StreamKey(renditionGroup, trackIndex);
}
 
Example #7
Source File: SsManifest.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@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) {
      // We're advancing to a new stream element. Add the current one.
      copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
      copiedFormats.clear();
    }
    currentStreamElement = streamElement;
    copiedFormats.add(streamElement.formats[key.trackIndex]);
  }
  if (currentStreamElement != null) {
    // Add the last stream element.
    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);
}
 
Example #8
Source File: HlsMasterPlaylist.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public HlsMasterPlaylist copy(List<StreamKey> streamKeys) {
  return new HlsMasterPlaylist(
      baseUri,
      tags,
      copyRenditionsList(variants, GROUP_INDEX_VARIANT, streamKeys),
      copyRenditionsList(audios, GROUP_INDEX_AUDIO, streamKeys),
      copyRenditionsList(subtitles, GROUP_INDEX_SUBTITLE, streamKeys),
      muxedAudioFormat,
      muxedCaptionFormats,
      hasIndependentSegments);
}
 
Example #9
Source File: HlsMasterPlaylist.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<HlsUrl> copyRenditionsList(
    List<HlsUrl> renditions, int groupIndex, List<StreamKey> streamKeys) {
  List<HlsUrl> copiedRenditions = new ArrayList<>(streamKeys.size());
  for (int i = 0; i < renditions.size(); i++) {
    HlsUrl rendition = renditions.get(i);
    for (int j = 0; j < streamKeys.size(); j++) {
      StreamKey streamKey = streamKeys.get(j);
      if (streamKey.groupIndex == groupIndex && streamKey.trackIndex == i) {
        copiedRenditions.add(rendition);
        break;
      }
    }
  }
  return copiedRenditions;
}
 
Example #10
Source File: DashManifest.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      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);
}
 
Example #11
Source File: HlsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys, int[] groups) {
  List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    representationKeys.add(new StreamKey(groups[trackKey.groupIndex], trackKey.trackIndex));
  }
  return representationKeys;
}
 
Example #12
Source File: SsMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  List<StreamKey> streamKeys = new ArrayList<>();
  for (int selectionIndex = 0; selectionIndex < trackSelections.size(); selectionIndex++) {
    TrackSelection trackSelection = trackSelections.get(selectionIndex);
    int streamElementIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
    for (int i = 0; i < trackSelection.length(); i++) {
      streamKeys.add(new StreamKey(streamElementIndex, trackSelection.getIndexInTrackGroup(i)));
    }
  }
  return streamKeys;
}
 
Example #13
Source File: DashDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
  List<StreamKey> streamKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    streamKeys.add(new StreamKey(trackKey.periodIndex, trackKey.groupIndex, trackKey.trackIndex));
  }
  return streamKeys;
}
 
Example #14
Source File: DashManifest.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      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);
}
 
Example #15
Source File: SsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
  List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    representationKeys.add(new StreamKey(trackKey.groupIndex, trackKey.trackIndex));
  }
  return representationKeys;
}
 
Example #16
Source File: SsDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected StreamKey readKey(int version, DataInputStream input) throws IOException {
  if (version > 0) {
    return super.readKey(version, input);
  }
  int groupIndex = input.readInt();
  int trackIndex = input.readInt();
  return new StreamKey(groupIndex, trackIndex);
}
 
Example #17
Source File: HlsMasterPlaylist.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<HlsUrl> copyRenditionsList(
    List<HlsUrl> renditions, int groupIndex, List<StreamKey> streamKeys) {
  List<HlsUrl> copiedRenditions = new ArrayList<>(streamKeys.size());
  for (int i = 0; i < renditions.size(); i++) {
    HlsUrl rendition = renditions.get(i);
    for (int j = 0; j < streamKeys.size(); j++) {
      StreamKey streamKey = streamKeys.get(j);
      if (streamKey.groupIndex == groupIndex && streamKey.trackIndex == i) {
        copiedRenditions.add(rendition);
        break;
      }
    }
  }
  return copiedRenditions;
}
 
Example #18
Source File: HlsMasterPlaylist.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public HlsMasterPlaylist copy(List<StreamKey> streamKeys) {
  return new HlsMasterPlaylist(
      baseUri,
      tags,
      copyRenditionsList(variants, GROUP_INDEX_VARIANT, streamKeys),
      copyRenditionsList(audios, GROUP_INDEX_AUDIO, streamKeys),
      copyRenditionsList(subtitles, GROUP_INDEX_SUBTITLE, streamKeys),
      muxedAudioFormat,
      muxedCaptionFormats,
      hasIndependentSegments);
}
 
Example #19
Source File: HlsDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected StreamKey readKey(int version, DataInputStream input) throws IOException {
  if (version > 0) {
    return super.readKey(version, input);
  }
  int renditionGroup = input.readInt();
  int trackIndex = input.readInt();
  return new StreamKey(renditionGroup, trackIndex);
}
 
Example #20
Source File: HlsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys, int[] groups) {
  List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    representationKeys.add(new StreamKey(groups[trackKey.groupIndex], trackKey.trackIndex));
  }
  return representationKeys;
}
 
Example #21
Source File: DashManifest.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      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,
      utcTiming, location, copyPeriods);
}
 
Example #22
Source File: DashDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
  List<StreamKey> streamKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    streamKeys.add(new StreamKey(trackKey.periodIndex, trackKey.groupIndex, trackKey.trackIndex));
  }
  return streamKeys;
}
 
Example #23
Source File: SsManifest.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@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) {
      // We're advancing to a new stream element. Add the current one.
      copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
      copiedFormats.clear();
    }
    currentStreamElement = streamElement;
    copiedFormats.add(streamElement.formats[key.trackIndex]);
  }
  if (currentStreamElement != null) {
    // Add the last stream element.
    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);
}
 
Example #24
Source File: SsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
  List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
  for (int i = 0; i < trackKeys.size(); i++) {
    TrackKey trackKey = trackKeys.get(i);
    representationKeys.add(new StreamKey(trackKey.groupIndex, trackKey.trackIndex));
  }
  return representationKeys;
}
 
Example #25
Source File: SsDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected StreamKey readKey(int version, DataInputStream input) throws IOException {
  if (version > 0) {
    return super.readKey(version, input);
  }
  int groupIndex = input.readInt();
  int trackIndex = input.readInt();
  return new StreamKey(groupIndex, trackIndex);
}
 
Example #26
Source File: SsManifest.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@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) {
      // We're advancing to a new stream element. Add the current one.
      copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
      copiedFormats.clear();
    }
    currentStreamElement = streamElement;
    copiedFormats.add(streamElement.formats[key.trackIndex]);
  }
  if (currentStreamElement != null) {
    // Add the last stream element.
    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);
}
 
Example #27
Source File: DashManifest.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      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);
}
 
Example #28
Source File: SsManifest.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@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) {
      // We're advancing to a new stream element. Add the current one.
      copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
      copiedFormats.clear();
    }
    currentStreamElement = streamElement;
    copiedFormats.add(streamElement.formats[key.trackIndex]);
  }
  if (currentStreamElement != null) {
    // Add the last stream element.
    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);
}
 
Example #29
Source File: FilteringHlsPlaylistParserFactory.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * @param hlsPlaylistParserFactory A factory for the parsers of the playlists which will be
 *     filtered.
 * @param streamKeys The stream keys. If null or empty then filtering will not occur.
 */
public FilteringHlsPlaylistParserFactory(
    HlsPlaylistParserFactory hlsPlaylistParserFactory, List<StreamKey> streamKeys) {
  this.hlsPlaylistParserFactory = hlsPlaylistParserFactory;
  this.streamKeys = streamKeys;
}
 
Example #30
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  List<StreamKey> streamKeys = new ArrayList<>();
  for (TrackSelection trackSelection : trackSelections) {
    int trackGroupIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
    TrackGroupInfo trackGroupInfo = trackGroupInfos[trackGroupIndex];
    if (trackGroupInfo.trackGroupCategory != TrackGroupInfo.CATEGORY_PRIMARY) {
      // Ignore non-primary tracks.
      continue;
    }
    int[] adaptationSetIndices = trackGroupInfo.adaptationSetIndices;
    int[] trackIndices = new int[trackSelection.length()];
    for (int i = 0; i < trackSelection.length(); i++) {
      trackIndices[i] = trackSelection.getIndexInTrackGroup(i);
    }
    Arrays.sort(trackIndices);

    int currentAdaptationSetIndex = 0;
    int totalTracksInPreviousAdaptationSets = 0;
    int tracksInCurrentAdaptationSet =
        manifestAdaptationSets.get(adaptationSetIndices[0]).representations.size();
    for (int trackIndex : trackIndices) {
      while (trackIndex >= totalTracksInPreviousAdaptationSets + tracksInCurrentAdaptationSet) {
        currentAdaptationSetIndex++;
        totalTracksInPreviousAdaptationSets += tracksInCurrentAdaptationSet;
        tracksInCurrentAdaptationSet =
            manifestAdaptationSets
                .get(adaptationSetIndices[currentAdaptationSetIndex])
                .representations
                .size();
      }
      streamKeys.add(
          new StreamKey(
              periodIndex,
              adaptationSetIndices[currentAdaptationSetIndex],
              trackIndex - totalTracksInPreviousAdaptationSets));
    }
  }
  return streamKeys;
}