Java 类com.google.android.exoplayer2.source.TrackGroup 实例源码

项目:Exoplayer2Radio    文件:HlsChunkSource.java   
/**
 * @param playlistTracker The {@link HlsPlaylistTracker} from which to obtain media playlists.
 * @param variants The available variants.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} to create {@link DataSource}s for the
 *     chunks.
 * @param timestampAdjusterProvider A provider of {@link TimestampAdjuster} instances. If
 *     multiple {@link HlsChunkSource}s are used for a single playback, they should all share the
 *     same provider.
 * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption
 *     information is available in the master playlist.
 */
public HlsChunkSource(HlsPlaylistTracker playlistTracker, HlsUrl[] variants,
    HlsDataSourceFactory dataSourceFactory, TimestampAdjusterProvider timestampAdjusterProvider,
    List<Format> muxedCaptionFormats) {
  this.playlistTracker = playlistTracker;
  this.variants = variants;
  this.timestampAdjusterProvider = timestampAdjusterProvider;
  this.muxedCaptionFormats = muxedCaptionFormats;
  Format[] variantFormats = new Format[variants.length];
  int[] initialTrackSelection = new int[variants.length];
  for (int i = 0; i < variants.length; i++) {
    variantFormats[i] = variants[i].format;
    initialTrackSelection[i] = i;
  }
  mediaDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_MEDIA);
  encryptionDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_DRM);
  trackGroup = new TrackGroup(variantFormats);
  trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);
}
项目:Exoplayer2Radio    文件:BaseTrackSelection.java   
/**
 * @param group The {@link TrackGroup}. Must not be null.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     null or empty. May be in any order.
 */
public BaseTrackSelection(TrackGroup group, int... tracks) {
  Assertions.checkState(tracks.length > 0);
  this.group = Assertions.checkNotNull(group);
  this.length = tracks.length;
  // Set the formats, sorted in order of decreasing bandwidth.
  formats = new Format[length];
  for (int i = 0; i < tracks.length; i++) {
    formats[i] = group.getFormat(tracks[i]);
  }
  Arrays.sort(formats, new DecreasingBandwidthComparator());
  // Set the format indices in the same order.
  this.tracks = new int[length];
  for (int i = 0; i < length; i++) {
    this.tracks[i] = group.indexOf(formats[i]);
  }
  blacklistUntilTimes = new long[length];
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static TrackSelection selectAdaptiveVideoTrack(RendererCapabilities rendererCapabilities,
    TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
    int maxVideoBitrate, boolean allowNonSeamlessAdaptiveness, boolean allowMixedMimeAdaptiveness,
    int viewportWidth, int viewportHeight, boolean orientationMayChange,
    TrackSelection.Factory adaptiveTrackSelectionFactory) throws ExoPlaybackException {
  int requiredAdaptiveSupport = allowNonSeamlessAdaptiveness
      ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
      : RendererCapabilities.ADAPTIVE_SEAMLESS;
  boolean allowMixedMimeTypes = allowMixedMimeAdaptiveness
      && (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
  for (int i = 0; i < groups.length; i++) {
    TrackGroup group = groups.get(i);
    int[] adaptiveTracks = getAdaptiveVideoTracksForGroup(group, formatSupport[i],
        allowMixedMimeTypes, requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate, viewportWidth, viewportHeight, orientationMayChange);
    if (adaptiveTracks.length > 0) {
      return adaptiveTrackSelectionFactory.createTrackSelection(group, adaptiveTracks);
    }
  }
  return null;
}
项目:Exoplayer2Radio    文件:MappingTrackSelector.java   
/**
 * Finds the renderer to which the provided {@link TrackGroup} should be associated.
 * <p>
 * A {@link TrackGroup} is associated to a renderer that reports
 * {@link RendererCapabilities#FORMAT_HANDLED} support for one or more of the tracks in the group,
 * or {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES} if no such renderer exists, or
 * {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} if again no such renderer exists. In
 * the case that two or more renderers report the same level of support, the renderer with the
 * lowest index is associated.
 * <p>
 * If all renderers report {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} for all of the
 * tracks in the group, then {@code renderers.length} is returned to indicate that no association
 * was made.
 *
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
 * @param group The {@link TrackGroup} whose associated renderer is to be found.
 * @return The index of the associated renderer, or {@code renderers.length} if no
 *     association was made.
 * @throws ExoPlaybackException If an error occurs finding a renderer.
 */
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group)
    throws ExoPlaybackException {
  int bestRendererIndex = rendererCapabilities.length;
  int bestFormatSupportLevel = RendererCapabilities.FORMAT_UNSUPPORTED_TYPE;
  for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
    RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
    for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
      int formatSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex))
          & RendererCapabilities.FORMAT_SUPPORT_MASK;
      if (formatSupportLevel > bestFormatSupportLevel) {
        bestRendererIndex = rendererIndex;
        bestFormatSupportLevel = formatSupportLevel;
        if (bestFormatSupportLevel == RendererCapabilities.FORMAT_HANDLED) {
          // We can't do better.
          return bestRendererIndex;
        }
      }
    }
  }
  return bestRendererIndex;
}
项目:no-player    文件:ExoPlayerSubtitleTrackSelector.java   
public List<PlayerSubtitleTrack> getSubtitleTracks(RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(TEXT, rendererTypeRequester);

    List<PlayerSubtitleTrack> subtitleTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup trackGroup = trackGroups.get(groupIndex);

        for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
            Format format = trackGroup.getFormat(formatIndex);
            PlayerSubtitleTrack playerSubtitleTrack = new PlayerSubtitleTrack(
                    groupIndex,
                    formatIndex,
                    format.id,
                    format.language,
                    format.sampleMimeType,
                    format.channelCount,
                    format.bitrate
            );
            subtitleTracks.add(playerSubtitleTrack);
        }
    }

    return subtitleTracks;
}
项目:K-Sonic    文件:BaseTrackSelection.java   
/**
 * @param group The {@link TrackGroup}. Must not be null.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     null or empty. May be in any order.
 */
public BaseTrackSelection(TrackGroup group, int... tracks) {
  Assertions.checkState(tracks.length > 0);
  this.group = Assertions.checkNotNull(group);
  this.length = tracks.length;
  // Set the formats, sorted in order of decreasing bandwidth.
  formats = new Format[length];
  for (int i = 0; i < tracks.length; i++) {
    formats[i] = group.getFormat(tracks[i]);
  }
  Arrays.sort(formats, new DecreasingBandwidthComparator());
  // Set the format indices in the same order.
  this.tracks = new int[length];
  for (int i = 0; i < length; i++) {
    this.tracks[i] = group.indexOf(formats[i]);
  }
  blacklistUntilTimes = new long[length];
}
项目:K-Sonic    文件:DefaultTrackSelector.java   
private static TrackSelection selectAdaptiveVideoTrack(RendererCapabilities rendererCapabilities,
    TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
    int maxVideoBitrate, boolean allowNonSeamlessAdaptiveness, boolean allowMixedMimeAdaptiveness,
    int viewportWidth, int viewportHeight, boolean orientationMayChange,
    TrackSelection.Factory adaptiveVideoTrackSelectionFactory) throws ExoPlaybackException {
  int requiredAdaptiveSupport = allowNonSeamlessAdaptiveness
      ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
      : RendererCapabilities.ADAPTIVE_SEAMLESS;
  boolean allowMixedMimeTypes = allowMixedMimeAdaptiveness
      && (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
  for (int i = 0; i < groups.length; i++) {
    TrackGroup group = groups.get(i);
    int[] adaptiveTracks = getAdaptiveTracksForGroup(group, formatSupport[i],
        allowMixedMimeTypes, requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate, viewportWidth, viewportHeight, orientationMayChange);
    if (adaptiveTracks.length > 0) {
      return adaptiveVideoTrackSelectionFactory.createTrackSelection(group, adaptiveTracks);
    }
  }
  return null;
}
项目:K-Sonic    文件:MappingTrackSelector.java   
/**
 * Finds the renderer to which the provided {@link TrackGroup} should be associated.
 * <p>
 * A {@link TrackGroup} is associated to a renderer that reports
 * {@link RendererCapabilities#FORMAT_HANDLED} support for one or more of the tracks in the group,
 * or {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES} if no such renderer exists, or
 * {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} if again no such renderer exists. In
 * the case that two or more renderers report the same level of support, the renderer with the
 * lowest index is associated.
 * <p>
 * If all renderers report {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} for all of the
 * tracks in the group, then {@code renderers.length} is returned to indicate that no association
 * was made.
 *
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
 * @param group The {@link TrackGroup} whose associated renderer is to be found.
 * @return The index of the associated renderer, or {@code renderers.length} if no
 *     association was made.
 * @throws ExoPlaybackException If an error occurs finding a renderer.
 */
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group)
    throws ExoPlaybackException {
  int bestRendererIndex = rendererCapabilities.length;
  int bestFormatSupportLevel = RendererCapabilities.FORMAT_UNSUPPORTED_TYPE;
  for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
    RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
    for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
      int formatSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex))
          & RendererCapabilities.FORMAT_SUPPORT_MASK;
      if (formatSupportLevel > bestFormatSupportLevel) {
        bestRendererIndex = rendererIndex;
        bestFormatSupportLevel = formatSupportLevel;
        if (bestFormatSupportLevel == RendererCapabilities.FORMAT_HANDLED) {
          // We can't do better.
          return bestRendererIndex;
        }
      }
    }
  }
  return bestRendererIndex;
}
项目:K-Sonic    文件:HlsChunkSource.java   
/**
 * @param playlistTracker The {@link HlsPlaylistTracker} from which to obtain media playlists.
 * @param variants The available variants.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} to create {@link DataSource}s for the
 *     chunks.
 * @param timestampAdjusterProvider A provider of {@link TimestampAdjuster} instances. If
 *     multiple {@link HlsChunkSource}s are used for a single playback, they should all share the
 *     same provider.
 * @param muxedCaptionFormats List of muxed caption {@link Format}s.
 */
public HlsChunkSource(HlsPlaylistTracker playlistTracker, HlsUrl[] variants,
    HlsDataSourceFactory dataSourceFactory, TimestampAdjusterProvider timestampAdjusterProvider,
    List<Format> muxedCaptionFormats) {
  this.playlistTracker = playlistTracker;
  this.variants = variants;
  this.timestampAdjusterProvider = timestampAdjusterProvider;
  this.muxedCaptionFormats = muxedCaptionFormats;
  Format[] variantFormats = new Format[variants.length];
  int[] initialTrackSelection = new int[variants.length];
  for (int i = 0; i < variants.length; i++) {
    variantFormats[i] = variants[i].format;
    initialTrackSelection[i] = i;
  }
  mediaDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_MEDIA);
  encryptionDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_DRM);
  trackGroup = new TrackGroup(variantFormats);
  trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);
}
项目:videoPickPlayer    文件:BaseTrackSelection.java   
/**
 * @param group The {@link TrackGroup}. Must not be null.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     null or empty. May be in any order.
 */
public BaseTrackSelection(TrackGroup group, int... tracks) {
  Assertions.checkState(tracks.length > 0);
  this.group = Assertions.checkNotNull(group);
  this.length = tracks.length;
  // Set the formats, sorted in order of decreasing bandwidth.
  formats = new Format[length];
  for (int i = 0; i < tracks.length; i++) {
    formats[i] = group.getFormat(tracks[i]);
  }
  Arrays.sort(formats, new DecreasingBandwidthComparator());
  // Set the format indices in the same order.
  this.tracks = new int[length];
  for (int i = 0; i < length; i++) {
    this.tracks[i] = group.indexOf(formats[i]);
  }
  blacklistUntilTimes = new long[length];
}
项目:videoPickPlayer    文件:DefaultTrackSelector.java   
private static TrackSelection selectAdaptiveVideoTrack(RendererCapabilities rendererCapabilities,
    TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
    boolean allowNonSeamlessAdaptiveness, boolean allowMixedMimeAdaptiveness, int viewportWidth,
    int viewportHeight, boolean orientationMayChange,
    TrackSelection.Factory adaptiveVideoTrackSelectionFactory) throws ExoPlaybackException {
  int requiredAdaptiveSupport = allowNonSeamlessAdaptiveness
      ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
      : RendererCapabilities.ADAPTIVE_SEAMLESS;
  boolean allowMixedMimeTypes = allowMixedMimeAdaptiveness
      && (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
  for (int i = 0; i < groups.length; i++) {
    TrackGroup group = groups.get(i);
    int[] adaptiveTracks = getAdaptiveTracksForGroup(group, formatSupport[i],
        allowMixedMimeTypes, requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        viewportWidth, viewportHeight, orientationMayChange);
    if (adaptiveTracks.length > 0) {
      return adaptiveVideoTrackSelectionFactory.createTrackSelection(group, adaptiveTracks);
    }
  }
  return null;
}
项目:videoPickPlayer    文件:DefaultTrackSelector.java   
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups,
    int[][] formatSupport) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex])) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
项目:videoPickPlayer    文件:MappingTrackSelector.java   
/**
 * Finds the renderer to which the provided {@link TrackGroup} should be associated.
 * <p>
 * A {@link TrackGroup} is associated to a renderer that reports
 * {@link RendererCapabilities#FORMAT_HANDLED} support for one or more of the tracks in the group,
 * or {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES} if no such renderer exists, or
 * {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} if again no such renderer exists. In
 * the case that two or more renderers report the same level of support, the renderer with the
 * lowest index is associated.
 * <p>
 * If all renderers report {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} for all of the
 * tracks in the group, then {@code renderers.length} is returned to indicate that no association
 * was made.
 *
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
 * @param group The {@link TrackGroup} whose associated renderer is to be found.
 * @return The index of the associated renderer, or {@code renderers.length} if no
 *     association was made.
 * @throws ExoPlaybackException If an error occurs finding a renderer.
 */
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group)
    throws ExoPlaybackException {
  int bestRendererIndex = rendererCapabilities.length;
  int bestSupportLevel = RendererCapabilities.FORMAT_UNSUPPORTED_TYPE;
  for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
    RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
    for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
      int trackSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex));
      if (trackSupportLevel > bestSupportLevel) {
        bestRendererIndex = rendererIndex;
        bestSupportLevel = trackSupportLevel;
        if (bestSupportLevel == RendererCapabilities.FORMAT_HANDLED) {
          // We can't do better.
          return bestRendererIndex;
        }
      }
    }
  }
  return bestRendererIndex;
}
项目:videoPickPlayer    文件:HlsChunkSource.java   
/**
 * @param baseUri The playlist's base uri.
 * @param variants The available variants.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param timestampAdjusterProvider A provider of {@link TimestampAdjuster} instances. If
 *     multiple {@link HlsChunkSource}s are used for a single playback, they should all share the
 *     same provider.
 */
public HlsChunkSource(String baseUri, HlsMasterPlaylist.HlsUrl[] variants, DataSource dataSource,
    TimestampAdjusterProvider timestampAdjusterProvider) {
  this.baseUri = baseUri;
  this.variants = variants;
  this.dataSource = dataSource;
  this.timestampAdjusterProvider = timestampAdjusterProvider;
  playlistParser = new HlsPlaylistParser();
  variantPlaylists = new HlsMediaPlaylist[variants.length];
  variantLastPlaylistLoadTimesMs = new long[variants.length];

  Format[] variantFormats = new Format[variants.length];
  int[] initialTrackSelection = new int[variants.length];
  for (int i = 0; i < variants.length; i++) {
    variantFormats[i] = variants[i].format;
    initialTrackSelection[i] = i;
  }
  trackGroup = new TrackGroup(variantFormats);
  trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);
}
项目:transistor    文件:FakeMediaPeriod.java   
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  Assert.assertTrue(preparedPeriod);
  int rendererCount = selections.length;
  for (int i = 0; i < rendererCount; i++) {
    if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
      streams[i] = null;
    }
    if (streams[i] == null && selections[i] != null) {
      TrackSelection selection = selections[i];
      Assert.assertTrue(1 <= selection.length());
      TrackGroup trackGroup = selection.getTrackGroup();
      Assert.assertTrue(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET);
      int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
      Assert.assertTrue(0 <= indexInTrackGroup);
      Assert.assertTrue(indexInTrackGroup < trackGroup.length);
      streams[i] = createSampleStream(selection);
      streamResetFlags[i] = true;
    }
  }
  return positionUs;
}
项目:transistor    文件:FakeTrackSelector.java   
@NonNull
private FakeTrackSelection reuseOrCreateTrackSelection(TrackGroup trackGroup) {
  FakeTrackSelection trackSelectionForRenderer = null;
  if (mayReuseTrackSelection) {
    for (FakeTrackSelection selectedTrackSelection : selectedTrackSelections) {
      if (selectedTrackSelection.getTrackGroup().equals(trackGroup)) {
        trackSelectionForRenderer = selectedTrackSelection;
      }
    }
  }
  if (trackSelectionForRenderer == null) {
    trackSelectionForRenderer = new FakeTrackSelection(trackGroup);
    selectedTrackSelections.add(trackSelectionForRenderer);
  }
  return trackSelectionForRenderer;
}
项目:transistor    文件:HlsChunkSource.java   
/**
 * @param extractorFactory An {@link HlsExtractorFactory} from which to obtain the extractors for
 *     media chunks.
 * @param playlistTracker The {@link HlsPlaylistTracker} from which to obtain media playlists.
 * @param variants The available variants.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} to create {@link DataSource}s for the
 *     chunks.
 * @param timestampAdjusterProvider A provider of {@link TimestampAdjuster} instances. If
 *     multiple {@link HlsChunkSource}s are used for a single playback, they should all share the
 *     same provider.
 * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption
 *     information is available in the master playlist.
 */
public HlsChunkSource(HlsExtractorFactory extractorFactory, HlsPlaylistTracker playlistTracker,
    HlsUrl[] variants, HlsDataSourceFactory dataSourceFactory,
    TimestampAdjusterProvider timestampAdjusterProvider, List<Format> muxedCaptionFormats) {
  this.extractorFactory = extractorFactory;
  this.playlistTracker = playlistTracker;
  this.variants = variants;
  this.timestampAdjusterProvider = timestampAdjusterProvider;
  this.muxedCaptionFormats = muxedCaptionFormats;
  liveEdgeTimeUs = C.TIME_UNSET;
  Format[] variantFormats = new Format[variants.length];
  int[] initialTrackSelection = new int[variants.length];
  for (int i = 0; i < variants.length; i++) {
    variantFormats[i] = variants[i].format;
    initialTrackSelection[i] = i;
  }
  mediaDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_MEDIA);
  encryptionDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_DRM);
  trackGroup = new TrackGroup(variantFormats);
  trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);
}
项目:transistor    文件:BaseTrackSelection.java   
/**
 * @param group The {@link TrackGroup}. Must not be null.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     null or empty. May be in any order.
 */
public BaseTrackSelection(TrackGroup group, int... tracks) {
  Assertions.checkState(tracks.length > 0);
  this.group = Assertions.checkNotNull(group);
  this.length = tracks.length;
  // Set the formats, sorted in order of decreasing bandwidth.
  formats = new Format[length];
  for (int i = 0; i < tracks.length; i++) {
    formats[i] = group.getFormat(tracks[i]);
  }
  Arrays.sort(formats, new DecreasingBandwidthComparator());
  // Set the format indices in the same order.
  this.tracks = new int[length];
  for (int i = 0; i < length; i++) {
    this.tracks[i] = group.indexOf(formats[i]);
  }
  blacklistUntilTimes = new long[length];
}
项目:transistor    文件:DefaultTrackSelector.java   
private static TrackSelection selectAdaptiveVideoTrack(RendererCapabilities rendererCapabilities,
    TrackGroupArray groups, int[][] formatSupport, Parameters params,
    TrackSelection.Factory adaptiveTrackSelectionFactory) throws ExoPlaybackException {
  int requiredAdaptiveSupport = params.allowNonSeamlessAdaptiveness
      ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
      : RendererCapabilities.ADAPTIVE_SEAMLESS;
  boolean allowMixedMimeTypes = params.allowMixedMimeAdaptiveness
      && (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
  for (int i = 0; i < groups.length; i++) {
    TrackGroup group = groups.get(i);
    int[] adaptiveTracks = getAdaptiveVideoTracksForGroup(group, formatSupport[i],
        allowMixedMimeTypes, requiredAdaptiveSupport, params.maxVideoWidth, params.maxVideoHeight,
        params.maxVideoBitrate, params.viewportWidth, params.viewportHeight,
        params.viewportOrientationMayChange);
    if (adaptiveTracks.length > 0) {
      return adaptiveTrackSelectionFactory.createTrackSelection(group, adaptiveTracks);
    }
  }
  return null;
}
项目:transistor    文件:MappingTrackSelector.java   
/**
 * Finds the renderer to which the provided {@link TrackGroup} should be mapped.
 * <p>
 * A {@link TrackGroup} is mapped to the renderer that reports the highest of (listed in
 * decreasing order of support) {@link RendererCapabilities#FORMAT_HANDLED},
 * {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES},
 * {@link RendererCapabilities#FORMAT_UNSUPPORTED_DRM} and
 * {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE}. In the case that two or more renderers
 * report the same level of support, the renderer with the lowest index is associated.
 * <p>
 * If all renderers report {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} for all of the
 * tracks in the group, then {@code renderers.length} is returned to indicate that the group was
 * not mapped to any renderer.
 *
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
 * @param group The track group to map to a renderer.
 * @return The index of the renderer to which the track group was mapped, or
 *     {@code renderers.length} if it was not mapped to any renderer.
 * @throws ExoPlaybackException If an error occurs finding a renderer.
 */
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group)
    throws ExoPlaybackException {
  int bestRendererIndex = rendererCapabilities.length;
  int bestFormatSupportLevel = RendererCapabilities.FORMAT_UNSUPPORTED_TYPE;
  for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
    RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
    for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
      int formatSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex))
          & RendererCapabilities.FORMAT_SUPPORT_MASK;
      if (formatSupportLevel > bestFormatSupportLevel) {
        bestRendererIndex = rendererIndex;
        bestFormatSupportLevel = formatSupportLevel;
        if (bestFormatSupportLevel == RendererCapabilities.FORMAT_HANDLED) {
          // We can't do better.
          return bestRendererIndex;
        }
      }
    }
  }
  return bestRendererIndex;
}
项目:transistor    文件:ExoPlayerTest.java   
/**
 * Tests playback of a source that exposes a single period.
 */
public void testPlaySinglePeriodTimeline() throws Exception {
  Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
  Object manifest = new Object();
  FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
  ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
      .setTimeline(timeline).setManifest(manifest).setRenderers(renderer)
      .build().start().blockUntilEnded(TIMEOUT_MS);
  testRunner.assertPositionDiscontinuityCount(0);
  testRunner.assertTimelinesEqual(timeline);
  testRunner.assertManifestsEqual(manifest);
  testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
  assertEquals(1, renderer.formatReadCount);
  assertEquals(1, renderer.bufferReadCount);
  assertTrue(renderer.isEnded);
}
项目:TubiPlayer    文件:TubiQualityDialogView.java   
/**
 * Builds the quality selection list based on the media tracks
 *
 * @param selector      The selector to get all the available tracks
 * @param rendererIndex The render index
 * @return The selection view
 */
public View buildQualityDialog(@NonNull MappingTrackSelector selector, int rendererIndex) {
    setRendererIndex(rendererIndex);
    setSelector(selector);


    // View for clearing the override to allow the selector to use its default selection logic.
    qualityAutoView = new TubiRadioButton(getContext());
    qualityAutoView.setText(R.string.track_selector_alert_auto);
    qualityAutoView.setFocusable(true);
    qualityAutoView.setOnClickListener(this);
    mBinding.viewTubiQualityDialogLl.addView(qualityAutoView);

    // Per-track views.
    trackViews = new TubiRadioButton[trackGroups.length][];
    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup group = trackGroups.get(groupIndex);
        trackViews[groupIndex] = new TubiRadioButton[group.length];
        for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
            TubiRadioButton trackView = new TubiRadioButton(getContext());
            trackView.setText(buildTrackName(group.getFormat(trackIndex)));
            if (trackInfo.getTrackFormatSupport(rendererIndex, groupIndex, trackIndex)
                    == RendererCapabilities.FORMAT_HANDLED) {
                trackView.setFocusable(true);
                trackView.setTag(Pair.create(groupIndex, trackIndex));
            } else {
                trackView.setFocusable(false);
                trackView.setEnabled(false);
            }
            trackView.setOnClickListener(this);
            trackViews[groupIndex][trackIndex] = trackView;
            mBinding.viewTubiQualityDialogLl.addView(trackView);
        }
    }

    updateViews();
    return this;
}
项目:ExoPlayer-Offline    文件:DashTest.java   
private static int[] getVideoTrackIndices(TrackGroup trackGroup, int[] formatSupport,
    String[] formatIds, boolean canIncludeAdditionalFormats) {
  List<Integer> trackIndices = new ArrayList<>();

  // Always select explicitly listed representations.
  for (String formatId : formatIds) {
    int trackIndex = getTrackIndex(trackGroup, formatId);
    Log.d(TAG, "Adding base video format: "
        + Format.toLogString(trackGroup.getFormat(trackIndex)));
    trackIndices.add(trackIndex);
  }

  // Select additional video representations, if supported by the device.
  if (canIncludeAdditionalFormats) {
    for (int i = 0; i < trackGroup.length; i++) {
      if (!trackIndices.contains(i) && isFormatHandled(formatSupport[i])) {
        Log.d(TAG, "Adding extra video format: "
            + Format.toLogString(trackGroup.getFormat(i)));
        trackIndices.add(i);
      }
    }
  }

  int[] trackIndicesArray = Util.toArray(trackIndices);
  Arrays.sort(trackIndicesArray);
  return trackIndicesArray;
}
项目:ExoPlayer-Offline    文件:DashTest.java   
private static int getTrackIndex(TrackGroup trackGroup, String formatId) {
  for (int i = 0; i < trackGroup.length; i++) {
    if (trackGroup.getFormat(i).id.equals(formatId)) {
      return i;
    }
  }
  throw new IllegalStateException("Format " + formatId + " not found.");
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType = getAdaptiveVideoTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            maxVideoBitrate, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

  // Filter by the selected mime type.
  filterAdaptiveVideoTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
      selectedMimeType, maxVideoWidth, maxVideoHeight, maxVideoBitrate, selectedTrackIndices);

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static int getAdaptiveVideoTrackCountForMimeType(TrackGroup group, int[] formatSupport,
    int requiredAdaptiveSupport, String mimeType, int maxVideoWidth, int maxVideoHeight,
    int maxVideoBitrate, List<Integer> selectedTrackIndices) {
  int adaptiveTrackCount = 0;
  for (int i = 0; i < selectedTrackIndices.size(); i++) {
    int trackIndex = selectedTrackIndices.get(i);
    if (isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
        formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate)) {
      adaptiveTrackCount++;
    }
  }
  return adaptiveTrackCount;
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static void filterAdaptiveVideoTrackCountForMimeType(TrackGroup group,
    int[] formatSupport, int requiredAdaptiveSupport, String mimeType, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, List<Integer> selectedTrackIndices) {
  for (int i = selectedTrackIndices.size() - 1; i >= 0; i--) {
    int trackIndex = selectedTrackIndices.get(i);
    if (!isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
        formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate)) {
      selectedTrackIndices.remove(i);
    }
  }
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary,
    boolean allowMixedMimeAdaptiveness, TrackSelection.Factory adaptiveTrackSelectionFactory) {
  int selectedGroupIndex = C.INDEX_UNSET;
  int selectedTrackIndex = C.INDEX_UNSET;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        int trackScore = getAudioTrackScore(trackFormatSupport[trackIndex],
            preferredAudioLanguage, format);
        if (trackScore > selectedTrackScore) {
          selectedGroupIndex = groupIndex;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }

  if (selectedGroupIndex == C.INDEX_UNSET) {
    return null;
  }

  TrackGroup selectedGroup = groups.get(selectedGroupIndex);
  if (adaptiveTrackSelectionFactory != null) {
    // If the group of the track with the highest score allows it, try to enable adaptation.
    int[] adaptiveTracks = getAdaptiveAudioTracks(selectedGroup,
        formatSupport[selectedGroupIndex], allowMixedMimeAdaptiveness);
    if (adaptiveTracks.length > 0) {
      return adaptiveTrackSelectionFactory.createTrackSelection(selectedGroup,
          adaptiveTracks);
    }
  }
  return new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static int[] getAdaptiveAudioTracks(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes) {
  int selectedConfigurationTrackCount = 0;
  AudioConfigurationTuple selectedConfiguration = null;
  HashSet<AudioConfigurationTuple> seenConfigurationTuples = new HashSet<>();
  for (int i = 0; i < group.length; i++) {
    Format format = group.getFormat(i);
    AudioConfigurationTuple configuration = new AudioConfigurationTuple(
        format.channelCount, format.sampleRate,
        allowMixedMimeTypes ? null : format.sampleMimeType);
    if (seenConfigurationTuples.add(configuration)) {
      int configurationCount = getAdaptiveAudioTrackCount(group, formatSupport, configuration);
      if (configurationCount > selectedConfigurationTrackCount) {
        selectedConfiguration = configuration;
        selectedConfigurationTrackCount = configurationCount;
      }
    }
  }

  if (selectedConfigurationTrackCount > 1) {
    int[] adaptiveIndices = new int[selectedConfigurationTrackCount];
    int index = 0;
    for (int i = 0; i < group.length; i++) {
      if (isSupportedAdaptiveAudioTrack(group.getFormat(i), formatSupport[i],
          selectedConfiguration)) {
        adaptiveIndices[index++] = i;
      }
    }
    return adaptiveIndices;
  }
  return NO_TRACKS;
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
private static int getAdaptiveAudioTrackCount(TrackGroup group, int[] formatSupport,
    AudioConfigurationTuple configuration) {
  int count = 0;
  for (int i = 0; i < group.length; i++) {
    if (isSupportedAdaptiveAudioTrack(group.getFormat(i), formatSupport[i], configuration)) {
      count++;
    }
  }
  return count;
}
项目:Exoplayer2Radio    文件:DefaultTrackSelector.java   
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups,
    int[][] formatSupport, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
项目:Exoplayer2Radio    文件:AdaptiveTrackSelection.java   
/**
 * @param group The {@link TrackGroup}.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     empty. May be in any order.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth.
 */
public AdaptiveTrackSelection(TrackGroup group, int[] tracks,
    BandwidthMeter bandwidthMeter) {
  this (group, tracks, bandwidthMeter, DEFAULT_MAX_INITIAL_BITRATE,
      DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
      DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
      DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS, DEFAULT_BANDWIDTH_FRACTION);
}
项目:no-player    文件:ExoPlayerAudioTrackSelector.java   
public AudioTracks getAudioTracks(RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(AUDIO, rendererTypeRequester);

    List<PlayerAudioTrack> audioTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        if (trackSelector.supportsTrackSwitching(AUDIO, rendererTypeRequester, trackGroups, groupIndex)) {
            TrackGroup trackGroup = trackGroups.get(groupIndex);

            for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
                Format format = trackGroup.getFormat(formatIndex);

                PlayerAudioTrack playerAudioTrack = new PlayerAudioTrack(
                        groupIndex,
                        formatIndex,
                        format.id,
                        format.language,
                        format.sampleMimeType,
                        format.channelCount,
                        format.bitrate,
                        AudioTrackType.from(format.selectionFlags)
                );
                audioTracks.add(playerAudioTrack);
            }
        }
    }

    return AudioTracks.from(audioTracks);
}
项目:no-player    文件:ExoPlayerVideoTrackSelector.java   
public List<PlayerVideoTrack> getVideoTracks(RendererTypeRequester rendererTypeRequester, ContentType contentType) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(VIDEO, rendererTypeRequester);

    List<PlayerVideoTrack> videoTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup trackGroup = trackGroups.get(groupIndex);

        for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
            Format format = trackGroup.getFormat(formatIndex);

            PlayerVideoTrack playerVideoTrack = new PlayerVideoTrack(
                    groupIndex,
                    formatIndex,
                    format.id,
                    contentType,
                    format.width,
                    format.height,
                    (int) format.frameRate,
                    format.bitrate
            );

            videoTracks.add(playerVideoTrack);
        }
    }

    return videoTracks;
}
项目:no-player    文件:ExoPlayerAudioTrackSelectorTest.java   
private TrackGroupArray givenTrackSelectorContainsTracks() {
    TrackGroupArray trackGroups = new TrackGroupArray(
            new TrackGroup(AudioFormatFixture.anAudioFormat().build()),
            new TrackGroup(
                    AudioFormatFixture.anAudioFormat().build(),
                    AudioFormatFixture.anAudioFormat().build(),
                    AudioFormatFixture.anAudioFormat().build()
            )
    );
    given(trackSelector.trackGroups(TrackType.AUDIO, rendererTypeRequester)).willReturn(trackGroups);

    return trackGroups;
}
项目:no-player    文件:ExoPlayerAudioTrackSelectorTest.java   
private void givenTrackSelectorContainsUnsupportedTracks() {
    TrackGroupArray trackGroups = new TrackGroupArray(
            new TrackGroup(AUDIO_FORMAT),
            new TrackGroup(
                    AudioFormatFixture.anAudioFormat().build(),
                    AudioFormatFixture.anAudioFormat().build(),
                    AudioFormatFixture.anAudioFormat().build()
            )
    );
    given(trackSelector.trackGroups(TrackType.AUDIO, rendererTypeRequester)).willReturn(trackGroups);
    given(trackSelector.supportsTrackSwitching(eq(TrackType.AUDIO), any(RendererTypeRequester.class), any(TrackGroupArray.class), anyInt()))
            .willReturn(true)
            .willReturn(false);
}
项目:K-Sonic    文件:DefaultTrackSelector.java   
private static int[] getAdaptiveTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType = getAdaptiveTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            maxVideoBitrate, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

  // Filter by the selected mime type.
  filterAdaptiveTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
      selectedMimeType, maxVideoWidth, maxVideoHeight, maxVideoBitrate, selectedTrackIndices);

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
项目:K-Sonic    文件:DefaultTrackSelector.java   
private static int getAdaptiveTrackCountForMimeType(TrackGroup group, int[] formatSupport,
    int requiredAdaptiveSupport, String mimeType, int maxVideoWidth, int maxVideoHeight,
    int maxVideoBitrate, List<Integer> selectedTrackIndices) {
  int adaptiveTrackCount = 0;
  for (int i = 0; i < selectedTrackIndices.size(); i++) {
    int trackIndex = selectedTrackIndices.get(i);
    if (isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
        formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate)) {
      adaptiveTrackCount++;
    }
  }
  return adaptiveTrackCount;
}
项目:K-Sonic    文件:DefaultTrackSelector.java   
private static void filterAdaptiveTrackCountForMimeType(TrackGroup group, int[] formatSupport,
    int requiredAdaptiveSupport, String mimeType, int maxVideoWidth, int maxVideoHeight,
    int maxVideoBitrate, List<Integer> selectedTrackIndices) {
  for (int i = selectedTrackIndices.size() - 1; i >= 0; i--) {
    int trackIndex = selectedTrackIndices.get(i);
    if (!isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
        formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
        maxVideoBitrate)) {
      selectedTrackIndices.remove(i);
    }
  }
}
项目:K-Sonic    文件:DefaultTrackSelector.java   
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore;
        if (formatHasLanguage(format, preferredAudioLanguage)) {
          if (isDefault) {
            trackScore = 4;
          } else {
            trackScore = 3;
          }
        } else if (isDefault) {
          trackScore = 2;
        } else {
          trackScore = 1;
        }
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}