Java Code Examples for com.google.android.exoplayer2.source.TrackGroupArray#indexOf()

The following examples show how to use com.google.android.exoplayer2.source.TrackGroupArray#indexOf() . 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: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupports The {@link Capabilities} for each track, indexed by group index and track
 *     index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(
    @Capabilities int[][] formatSupports, TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    @Capabilities
    int trackFormatSupport = formatSupports[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if (RendererCapabilities.getTunnelingSupport(trackFormatSupport)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 2
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupports The result of {@link RendererCapabilities#supportsFormat} for each track,
 *     indexed by group index and track index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(
    int[][] formatSupports, TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    int trackFormatSupport = formatSupports[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if ((trackFormatSupport & RendererCapabilities.TUNNELING_SUPPORT_MASK)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 3
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupports The result of {@link RendererCapabilities#supportsFormat} for each track,
 *     indexed by group index and track index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(
    int[][] formatSupports, TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    int trackFormatSupport = formatSupports[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if ((trackFormatSupport & RendererCapabilities.TUNNELING_SUPPORT_MASK)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 4
Source File: MappingTrackSelector.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each
 *     track, indexed by group index and track index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(int[][] formatSupport,
    TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    int trackFormatSupport = formatSupport[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if ((trackFormatSupport & RendererCapabilities.TUNNELING_SUPPORT_MASK)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 5
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupports The result of {@link RendererCapabilities#supportsFormat} for each track,
 *     indexed by group index and track index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(
    int[][] formatSupports, TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    int trackFormatSupport = formatSupports[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if ((trackFormatSupport & RendererCapabilities.TUNNELING_SUPPORT_MASK)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 6
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether a renderer supports tunneling for a {@link TrackSelection}.
 *
 * @param formatSupports The result of {@link RendererCapabilities#supportsFormat} for each track,
 *     indexed by group index and track index (in that order).
 * @param trackGroups The {@link TrackGroupArray}s for the renderer.
 * @param selection The track selection.
 * @return Whether the renderer supports tunneling for the {@link TrackSelection}.
 */
private static boolean rendererSupportsTunneling(
    int[][] formatSupports, TrackGroupArray trackGroups, TrackSelection selection) {
  if (selection == null) {
    return false;
  }
  int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
  for (int i = 0; i < selection.length(); i++) {
    int trackFormatSupport = formatSupports[trackGroupIndex][selection.getIndexInTrackGroup(i)];
    if ((trackFormatSupport & RendererCapabilities.TUNNELING_SUPPORT_MASK)
        != RendererCapabilities.TUNNELING_SUPPORTED) {
      return false;
    }
  }
  return true;
}
 
Example 7
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 8
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 9
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;
}