com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.Rendition Java Examples

The following examples show how to use com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.Rendition. 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: HlsMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void buildAndPrepareAudioSampleStreamWrappers(
    long positionUs,
    List<Rendition> audioRenditions,
    List<HlsSampleStreamWrapper> sampleStreamWrappers,
    List<int[]> manifestUrlsIndicesPerWrapper,
    Map<String, DrmInitData> overridingDrmInitData) {
  ArrayList<Uri> scratchPlaylistUrls =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Format> scratchPlaylistFormats =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Integer> scratchIndicesList =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  HashSet<String> alreadyGroupedNames = new HashSet<>();
  for (int renditionByNameIndex = 0;
      renditionByNameIndex < audioRenditions.size();
      renditionByNameIndex++) {
    String name = audioRenditions.get(renditionByNameIndex).name;
    if (!alreadyGroupedNames.add(name)) {
      // This name already has a corresponding group.
      continue;
    }

    boolean renditionsHaveCodecs = true;
    scratchPlaylistUrls.clear();
    scratchPlaylistFormats.clear();
    scratchIndicesList.clear();
    // Group all renditions with matching name.
    for (int renditionIndex = 0; renditionIndex < audioRenditions.size(); renditionIndex++) {
      if (Util.areEqual(name, audioRenditions.get(renditionIndex).name)) {
        Rendition rendition = audioRenditions.get(renditionIndex);
        scratchIndicesList.add(renditionIndex);
        scratchPlaylistUrls.add(rendition.url);
        scratchPlaylistFormats.add(rendition.format);
        renditionsHaveCodecs &= rendition.format.codecs != null;
      }
    }

    HlsSampleStreamWrapper sampleStreamWrapper =
        buildSampleStreamWrapper(
            C.TRACK_TYPE_AUDIO,
            scratchPlaylistUrls.toArray(Util.castNonNullTypeArray(new Uri[0])),
            scratchPlaylistFormats.toArray(new Format[0]),
            /* muxedAudioFormat= */ null,
            /* muxedCaptionFormats= */ Collections.emptyList(),
            overridingDrmInitData,
            positionUs);
    manifestUrlsIndicesPerWrapper.add(Util.toArray(scratchIndicesList));
    sampleStreamWrappers.add(sampleStreamWrapper);

    if (allowChunklessPreparation && renditionsHaveCodecs) {
      Format[] renditionFormats = scratchPlaylistFormats.toArray(new Format[0]);
      sampleStreamWrapper.prepareWithMasterPlaylistInfo(
          new TrackGroup[] {new TrackGroup(renditionFormats)}, /* primaryTrackGroupIndex= */ 0);
    }
  }
}
 
Example #2
Source File: HlsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void buildAndPrepareAudioSampleStreamWrappers(
    long positionUs,
    List<Rendition> audioRenditions,
    List<HlsSampleStreamWrapper> sampleStreamWrappers,
    List<int[]> manifestUrlsIndicesPerWrapper,
    Map<String, DrmInitData> overridingDrmInitData) {
  ArrayList<Uri> scratchPlaylistUrls =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Format> scratchPlaylistFormats =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Integer> scratchIndicesList =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  HashSet<String> alreadyGroupedNames = new HashSet<>();
  for (int renditionByNameIndex = 0;
      renditionByNameIndex < audioRenditions.size();
      renditionByNameIndex++) {
    String name = audioRenditions.get(renditionByNameIndex).name;
    if (!alreadyGroupedNames.add(name)) {
      // This name already has a corresponding group.
      continue;
    }

    boolean renditionsHaveCodecs = true;
    scratchPlaylistUrls.clear();
    scratchPlaylistFormats.clear();
    scratchIndicesList.clear();
    // Group all renditions with matching name.
    for (int renditionIndex = 0; renditionIndex < audioRenditions.size(); renditionIndex++) {
      if (Util.areEqual(name, audioRenditions.get(renditionIndex).name)) {
        Rendition rendition = audioRenditions.get(renditionIndex);
        scratchIndicesList.add(renditionIndex);
        scratchPlaylistUrls.add(rendition.url);
        scratchPlaylistFormats.add(rendition.format);
        renditionsHaveCodecs &= rendition.format.codecs != null;
      }
    }

    HlsSampleStreamWrapper sampleStreamWrapper =
        buildSampleStreamWrapper(
            C.TRACK_TYPE_AUDIO,
            scratchPlaylistUrls.toArray(new Uri[0]),
            scratchPlaylistFormats.toArray(new Format[0]),
            /* muxedAudioFormat= */ null,
            /* muxedCaptionFormats= */ Collections.emptyList(),
            overridingDrmInitData,
            positionUs);
    manifestUrlsIndicesPerWrapper.add(Util.toArray(scratchIndicesList));
    sampleStreamWrappers.add(sampleStreamWrapper);

    if (allowChunklessPreparation && renditionsHaveCodecs) {
      Format[] renditionFormats = scratchPlaylistFormats.toArray(new Format[0]);
      sampleStreamWrapper.prepareWithMasterPlaylistInfo(
          new TrackGroupArray(new TrackGroup(renditionFormats)), 0, TrackGroupArray.EMPTY);
    }
  }
}
 
Example #3
Source File: HlsMediaPeriod.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void buildAndPrepareAudioSampleStreamWrappers(
    long positionUs,
    List<Rendition> audioRenditions,
    List<HlsSampleStreamWrapper> sampleStreamWrappers,
    List<int[]> manifestUrlsIndicesPerWrapper,
    Map<String, DrmInitData> overridingDrmInitData) {
  ArrayList<Uri> scratchPlaylistUrls =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Format> scratchPlaylistFormats =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Integer> scratchIndicesList =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  HashSet<String> alreadyGroupedNames = new HashSet<>();
  for (int renditionByNameIndex = 0;
      renditionByNameIndex < audioRenditions.size();
      renditionByNameIndex++) {
    String name = audioRenditions.get(renditionByNameIndex).name;
    if (!alreadyGroupedNames.add(name)) {
      // This name already has a corresponding group.
      continue;
    }

    boolean renditionsHaveCodecs = true;
    scratchPlaylistUrls.clear();
    scratchPlaylistFormats.clear();
    scratchIndicesList.clear();
    // Group all renditions with matching name.
    for (int renditionIndex = 0; renditionIndex < audioRenditions.size(); renditionIndex++) {
      if (Util.areEqual(name, audioRenditions.get(renditionIndex).name)) {
        Rendition rendition = audioRenditions.get(renditionIndex);
        scratchIndicesList.add(renditionIndex);
        scratchPlaylistUrls.add(rendition.url);
        scratchPlaylistFormats.add(rendition.format);
        renditionsHaveCodecs &= rendition.format.codecs != null;
      }
    }

    HlsSampleStreamWrapper sampleStreamWrapper =
        buildSampleStreamWrapper(
            C.TRACK_TYPE_AUDIO,
            scratchPlaylistUrls.toArray(new Uri[0]),
            scratchPlaylistFormats.toArray(new Format[0]),
            /* muxedAudioFormat= */ null,
            /* muxedCaptionFormats= */ Collections.emptyList(),
            overridingDrmInitData,
            positionUs);
    manifestUrlsIndicesPerWrapper.add(Util.toArray(scratchIndicesList));
    sampleStreamWrappers.add(sampleStreamWrapper);

    if (allowChunklessPreparation && renditionsHaveCodecs) {
      Format[] renditionFormats = scratchPlaylistFormats.toArray(new Format[0]);
      sampleStreamWrapper.prepareWithMasterPlaylistInfo(
          new TrackGroupArray(new TrackGroup(renditionFormats)), 0, TrackGroupArray.EMPTY);
    }
  }
}