Java Code Examples for com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist#GROUP_INDEX_SUBTITLE

The following examples show how to use com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist#GROUP_INDEX_SUBTITLE . 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: HlsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public TrackGroupArray getTrackGroups(int periodIndex) {
  Assertions.checkNotNull(playlist);
  if (playlist instanceof HlsMediaPlaylist) {
    renditionGroups = new int[0];
    return TrackGroupArray.EMPTY;
  }
  // TODO: Generate track groups as in playback. Reverse the mapping in getDownloadAction.
  HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist;
  TrackGroup[] trackGroups = new TrackGroup[3];
  renditionGroups = new int[3];
  int trackGroupIndex = 0;
  if (!masterPlaylist.variants.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_VARIANT;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.variants));
  }
  if (!masterPlaylist.audios.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_AUDIO;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.audios));
  }
  if (!masterPlaylist.subtitles.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.subtitles));
  }
  return new TrackGroupArray(Arrays.copyOf(trackGroups, trackGroupIndex));
}
 
Example 2
Source File: HlsDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public TrackGroupArray getTrackGroups(int periodIndex) {
  Assertions.checkNotNull(playlist);
  if (playlist instanceof HlsMediaPlaylist) {
    renditionGroups = new int[0];
    return TrackGroupArray.EMPTY;
  }
  // TODO: Generate track groups as in playback. Reverse the mapping in getDownloadAction.
  HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist;
  TrackGroup[] trackGroups = new TrackGroup[3];
  renditionGroups = new int[3];
  int trackGroupIndex = 0;
  if (!masterPlaylist.variants.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_VARIANT;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.variants));
  }
  if (!masterPlaylist.audios.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_AUDIO;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.audios));
  }
  if (!masterPlaylist.subtitles.isEmpty()) {
    renditionGroups[trackGroupIndex] = HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
    trackGroups[trackGroupIndex++] = new TrackGroup(toFormats(masterPlaylist.subtitles));
  }
  return new TrackGroupArray(Arrays.copyOf(trackGroups, trackGroupIndex));
}
 
Example 3
Source File: HlsMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  // See HlsMasterPlaylist.copy for interpretation of StreamKeys.
  HlsMasterPlaylist masterPlaylist = Assertions.checkNotNull(playlistTracker.getMasterPlaylist());
  boolean hasVariants = !masterPlaylist.variants.isEmpty();
  int audioWrapperOffset = hasVariants ? 1 : 0;
  // Subtitle sample stream wrappers are held last.
  int subtitleWrapperOffset = sampleStreamWrappers.length - masterPlaylist.subtitles.size();

  TrackGroupArray mainWrapperTrackGroups;
  int mainWrapperPrimaryGroupIndex;
  int[] mainWrapperVariantIndices;
  if (hasVariants) {
    HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
    mainWrapperVariantIndices = manifestUrlIndicesPerWrapper[0];
    mainWrapperTrackGroups = mainWrapper.getTrackGroups();
    mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
  } else {
    mainWrapperVariantIndices = new int[0];
    mainWrapperTrackGroups = TrackGroupArray.EMPTY;
    mainWrapperPrimaryGroupIndex = 0;
  }

  List<StreamKey> streamKeys = new ArrayList<>();
  boolean needsPrimaryTrackGroupSelection = false;
  boolean hasPrimaryTrackGroupSelection = false;
  for (TrackSelection trackSelection : trackSelections) {
    TrackGroup trackSelectionGroup = trackSelection.getTrackGroup();
    int mainWrapperTrackGroupIndex = mainWrapperTrackGroups.indexOf(trackSelectionGroup);
    if (mainWrapperTrackGroupIndex != C.INDEX_UNSET) {
      if (mainWrapperTrackGroupIndex == mainWrapperPrimaryGroupIndex) {
        // Primary group in main wrapper.
        hasPrimaryTrackGroupSelection = true;
        for (int i = 0; i < trackSelection.length(); i++) {
          int variantIndex = mainWrapperVariantIndices[trackSelection.getIndexInTrackGroup(i)];
          streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, variantIndex));
        }
      } else {
        // Embedded group in main wrapper.
        needsPrimaryTrackGroupSelection = true;
      }
    } else {
      // Audio or subtitle group.
      for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
        TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
        int selectedTrackGroupIndex = wrapperTrackGroups.indexOf(trackSelectionGroup);
        if (selectedTrackGroupIndex != C.INDEX_UNSET) {
          int groupIndexType =
              i < subtitleWrapperOffset
                  ? HlsMasterPlaylist.GROUP_INDEX_AUDIO
                  : HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
          int[] selectedWrapperUrlIndices = manifestUrlIndicesPerWrapper[i];
          for (int trackIndex = 0; trackIndex < trackSelection.length(); trackIndex++) {
            int renditionIndex =
                selectedWrapperUrlIndices[trackSelection.getIndexInTrackGroup(trackIndex)];
            streamKeys.add(new StreamKey(groupIndexType, renditionIndex));
          }
          break;
        }
      }
    }
  }
  if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
    // A track selection includes a variant-embedded track, but no variant is added yet. We use
    // the valid variant with the lowest bitrate to reduce overhead.
    int lowestBitrateIndex = mainWrapperVariantIndices[0];
    int lowestBitrate = masterPlaylist.variants.get(mainWrapperVariantIndices[0]).format.bitrate;
    for (int i = 1; i < mainWrapperVariantIndices.length; i++) {
      int variantBitrate =
          masterPlaylist.variants.get(mainWrapperVariantIndices[i]).format.bitrate;
      if (variantBitrate < lowestBitrate) {
        lowestBitrate = variantBitrate;
        lowestBitrateIndex = mainWrapperVariantIndices[i];
      }
    }
    streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
  }
  return streamKeys;
}
 
Example 4
Source File: HlsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  // See HlsMasterPlaylist.copy for interpretation of StreamKeys.
  HlsMasterPlaylist masterPlaylist = Assertions.checkNotNull(playlistTracker.getMasterPlaylist());
  boolean hasVariants = !masterPlaylist.variants.isEmpty();
  int audioWrapperOffset = hasVariants ? 1 : 0;
  // Subtitle sample stream wrappers are held last.
  int subtitleWrapperOffset = sampleStreamWrappers.length - masterPlaylist.subtitles.size();

  TrackGroupArray mainWrapperTrackGroups;
  int mainWrapperPrimaryGroupIndex;
  int[] mainWrapperVariantIndices;
  if (hasVariants) {
    HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
    mainWrapperVariantIndices = manifestUrlIndicesPerWrapper[0];
    mainWrapperTrackGroups = mainWrapper.getTrackGroups();
    mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
  } else {
    mainWrapperVariantIndices = new int[0];
    mainWrapperTrackGroups = TrackGroupArray.EMPTY;
    mainWrapperPrimaryGroupIndex = 0;
  }

  List<StreamKey> streamKeys = new ArrayList<>();
  boolean needsPrimaryTrackGroupSelection = false;
  boolean hasPrimaryTrackGroupSelection = false;
  for (TrackSelection trackSelection : trackSelections) {
    TrackGroup trackSelectionGroup = trackSelection.getTrackGroup();
    int mainWrapperTrackGroupIndex = mainWrapperTrackGroups.indexOf(trackSelectionGroup);
    if (mainWrapperTrackGroupIndex != C.INDEX_UNSET) {
      if (mainWrapperTrackGroupIndex == mainWrapperPrimaryGroupIndex) {
        // Primary group in main wrapper.
        hasPrimaryTrackGroupSelection = true;
        for (int i = 0; i < trackSelection.length(); i++) {
          int variantIndex = mainWrapperVariantIndices[trackSelection.getIndexInTrackGroup(i)];
          streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, variantIndex));
        }
      } else {
        // Embedded group in main wrapper.
        needsPrimaryTrackGroupSelection = true;
      }
    } else {
      // Audio or subtitle group.
      for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
        TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
        int selectedTrackGroupIndex = wrapperTrackGroups.indexOf(trackSelectionGroup);
        if (selectedTrackGroupIndex != C.INDEX_UNSET) {
          int groupIndexType =
              i < subtitleWrapperOffset
                  ? HlsMasterPlaylist.GROUP_INDEX_AUDIO
                  : HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
          int[] selectedWrapperUrlIndices = manifestUrlIndicesPerWrapper[i];
          for (int trackIndex = 0; trackIndex < trackSelection.length(); trackIndex++) {
            int renditionIndex =
                selectedWrapperUrlIndices[trackSelection.getIndexInTrackGroup(trackIndex)];
            streamKeys.add(new StreamKey(groupIndexType, renditionIndex));
          }
          break;
        }
      }
    }
  }
  if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
    // A track selection includes a variant-embedded track, but no variant is added yet. We use
    // the valid variant with the lowest bitrate to reduce overhead.
    int lowestBitrateIndex = mainWrapperVariantIndices[0];
    int lowestBitrate = masterPlaylist.variants.get(mainWrapperVariantIndices[0]).format.bitrate;
    for (int i = 1; i < mainWrapperVariantIndices.length; i++) {
      int variantBitrate =
          masterPlaylist.variants.get(mainWrapperVariantIndices[i]).format.bitrate;
      if (variantBitrate < lowestBitrate) {
        lowestBitrate = variantBitrate;
        lowestBitrateIndex = mainWrapperVariantIndices[i];
      }
    }
    streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
  }
  return streamKeys;
}
 
Example 5
Source File: HlsMediaPeriod.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  // See HlsMasterPlaylist.copy for interpretation of StreamKeys.
  HlsMasterPlaylist masterPlaylist = Assertions.checkNotNull(playlistTracker.getMasterPlaylist());
  boolean hasVariants = !masterPlaylist.variants.isEmpty();
  int audioWrapperOffset = hasVariants ? 1 : 0;
  // Subtitle sample stream wrappers are held last.
  int subtitleWrapperOffset = sampleStreamWrappers.length - masterPlaylist.subtitles.size();

  TrackGroupArray mainWrapperTrackGroups;
  int mainWrapperPrimaryGroupIndex;
  int[] mainWrapperVariantIndices;
  if (hasVariants) {
    HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
    mainWrapperVariantIndices = manifestUrlIndicesPerWrapper[0];
    mainWrapperTrackGroups = mainWrapper.getTrackGroups();
    mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
  } else {
    mainWrapperVariantIndices = new int[0];
    mainWrapperTrackGroups = TrackGroupArray.EMPTY;
    mainWrapperPrimaryGroupIndex = 0;
  }

  List<StreamKey> streamKeys = new ArrayList<>();
  boolean needsPrimaryTrackGroupSelection = false;
  boolean hasPrimaryTrackGroupSelection = false;
  for (TrackSelection trackSelection : trackSelections) {
    TrackGroup trackSelectionGroup = trackSelection.getTrackGroup();
    int mainWrapperTrackGroupIndex = mainWrapperTrackGroups.indexOf(trackSelectionGroup);
    if (mainWrapperTrackGroupIndex != C.INDEX_UNSET) {
      if (mainWrapperTrackGroupIndex == mainWrapperPrimaryGroupIndex) {
        // Primary group in main wrapper.
        hasPrimaryTrackGroupSelection = true;
        for (int i = 0; i < trackSelection.length(); i++) {
          int variantIndex = mainWrapperVariantIndices[trackSelection.getIndexInTrackGroup(i)];
          streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, variantIndex));
        }
      } else {
        // Embedded group in main wrapper.
        needsPrimaryTrackGroupSelection = true;
      }
    } else {
      // Audio or subtitle group.
      for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
        TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
        int selectedTrackGroupIndex = wrapperTrackGroups.indexOf(trackSelectionGroup);
        if (selectedTrackGroupIndex != C.INDEX_UNSET) {
          int groupIndexType =
              i < subtitleWrapperOffset
                  ? HlsMasterPlaylist.GROUP_INDEX_AUDIO
                  : HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
          int[] selectedWrapperUrlIndices = manifestUrlIndicesPerWrapper[i];
          for (int trackIndex = 0; trackIndex < trackSelection.length(); trackIndex++) {
            int renditionIndex =
                selectedWrapperUrlIndices[trackSelection.getIndexInTrackGroup(trackIndex)];
            streamKeys.add(new StreamKey(groupIndexType, renditionIndex));
          }
          break;
        }
      }
    }
  }
  if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
    // A track selection includes a variant-embedded track, but no variant is added yet. We use
    // the valid variant with the lowest bitrate to reduce overhead.
    int lowestBitrateIndex = mainWrapperVariantIndices[0];
    int lowestBitrate = masterPlaylist.variants.get(mainWrapperVariantIndices[0]).format.bitrate;
    for (int i = 1; i < mainWrapperVariantIndices.length; i++) {
      int variantBitrate =
          masterPlaylist.variants.get(mainWrapperVariantIndices[i]).format.bitrate;
      if (variantBitrate < lowestBitrate) {
        lowestBitrate = variantBitrate;
        lowestBitrateIndex = mainWrapperVariantIndices[i];
      }
    }
    streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
  }
  return streamKeys;
}