Java Code Examples for com.google.android.exoplayer2.C#SELECTION_REASON_INITIAL

The following examples show how to use com.google.android.exoplayer2.C#SELECTION_REASON_INITIAL . 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: BufferSizeAdaptationBuilder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  updateFormatBitrates(/* nowMs= */ clock.elapsedRealtime());

  // Make initial selection
  if (selectionReason == C.SELECTION_REASON_UNKNOWN) {
    selectionReason = C.SELECTION_REASON_INITIAL;
    selectedIndex = selectIdealIndexUsingBandwidth(/* isInitialSelection= */ true);
    return;
  }

  long bufferUs = getCurrentPeriodBufferedDurationUs(playbackPositionUs, bufferedDurationUs);
  int oldSelectedIndex = selectedIndex;
  if (isInSteadyState) {
    selectIndexSteadyState(bufferUs);
  } else {
    selectIndexStartUpPhase(bufferUs);
  }
  if (selectedIndex != oldSelectedIndex) {
    selectionReason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 2
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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.
 * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
 *     selected track to switch to one of higher quality.
 * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
 *     selected track to switch to one of lower quality.
 * @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
 *     quality, the selection may indicate that media already buffered at the lower quality can be
 *     discarded to speed up the switch. This is the minimum duration of media that must be
 *     retained at the lower quality.
 * @param bandwidthFraction The fraction of the available bandwidth that the selection should
 *     consider available for use. Setting to a value less than 1 is recommended to account for
 *     inaccuracies in the bandwidth estimator.
 * @param bufferedFractionToLiveEdgeForQualityIncrease For live streaming, the fraction of the
 *     duration from current playback position to the live edge that has to be buffered before the
 *     selected track can be switched to one of higher quality. This parameter is only applied
 *     when the playback position is closer to the live edge than {@code
 *     minDurationForQualityIncreaseMs}, which would otherwise prevent switching to a higher
 *     quality from happening.
 * @param minTimeBetweenBufferReevaluationMs The track selection may periodically reevaluate its
 *     buffer and discard some chunks of lower quality to improve the playback quality if network
 *     condition has changed. This is the minimum duration between 2 consecutive buffer
 *     reevaluation calls.
 */
public AdaptiveTrackSelection(
    TrackGroup group,
    int[] tracks,
    BandwidthMeter bandwidthMeter,
    long minDurationForQualityIncreaseMs,
    long maxDurationForQualityDecreaseMs,
    long minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  super(group, tracks);
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
  this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
  this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  playbackSpeed = 1f;
  reason = C.SELECTION_REASON_INITIAL;
  lastBufferEvaluationMs = C.TIME_UNSET;
  @SuppressWarnings("nullness:method.invocation.invalid")
  int selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
  this.selectedIndex = selectedIndex;
}
 
Example 3
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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.
 * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
 *     selected track to switch to one of higher quality.
 * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
 *     selected track to switch to one of lower quality.
 * @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
 *     quality, the selection may indicate that media already buffered at the lower quality can be
 *     discarded to speed up the switch. This is the minimum duration of media that must be
 *     retained at the lower quality.
 * @param bandwidthFraction The fraction of the available bandwidth that the selection should
 *     consider available for use. Setting to a value less than 1 is recommended to account for
 *     inaccuracies in the bandwidth estimator.
 * @param bufferedFractionToLiveEdgeForQualityIncrease For live streaming, the fraction of the
 *     duration from current playback position to the live edge that has to be buffered before the
 *     selected track can be switched to one of higher quality. This parameter is only applied
 *     when the playback position is closer to the live edge than {@code
 *     minDurationForQualityIncreaseMs}, which would otherwise prevent switching to a higher
 *     quality from happening.
 * @param minTimeBetweenBufferReevaluationMs The track selection may periodically reevaluate its
 *     buffer and discard some chunks of lower quality to improve the playback quality if network
 *     condition has changed. This is the minimum duration between 2 consecutive buffer
 *     reevaluation calls.
 */
public AdaptiveTrackSelection(
    TrackGroup group,
    int[] tracks,
    BandwidthMeter bandwidthMeter,
    long minDurationForQualityIncreaseMs,
    long maxDurationForQualityDecreaseMs,
    long minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  super(group, tracks);
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
  this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
  this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  playbackSpeed = 1f;
  reason = C.SELECTION_REASON_INITIAL;
  lastBufferEvaluationMs = C.TIME_UNSET;
  @SuppressWarnings("nullness:method.invocation.invalid")
  int selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
  this.selectedIndex = selectedIndex;
}
 
Example 4
Source File: BufferSizeAdaptationBuilder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  updateFormatBitrates(/* nowMs= */ clock.elapsedRealtime());

  // Make initial selection
  if (selectionReason == C.SELECTION_REASON_UNKNOWN) {
    selectionReason = C.SELECTION_REASON_INITIAL;
    selectedIndex = selectIdealIndexUsingBandwidth(/* isInitialSelection= */ true);
    return;
  }

  long bufferUs = getCurrentPeriodBufferedDurationUs(playbackPositionUs, bufferedDurationUs);
  int oldSelectedIndex = selectedIndex;
  if (isInSteadyState) {
    selectIndexSteadyState(bufferUs);
  } else {
    selectIndexStartUpPhase(bufferUs);
  }
  if (selectedIndex != oldSelectedIndex) {
    selectionReason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 5
Source File: BufferSizeAdaptationBuilder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  updateFormatBitrates(/* nowMs= */ clock.elapsedRealtime());

  // Make initial selection
  if (selectionReason == C.SELECTION_REASON_UNKNOWN) {
    selectionReason = C.SELECTION_REASON_INITIAL;
    selectedIndex = selectIdealIndexUsingBandwidth(/* isInitialSelection= */ true);
    return;
  }

  long bufferUs = getCurrentPeriodBufferedDurationUs(playbackPositionUs, bufferedDurationUs);
  int oldSelectedIndex = selectedIndex;
  if (isInSteadyState) {
    selectIndexSteadyState(bufferUs);
  } else {
    selectIndexStartUpPhase(bufferUs);
  }
  if (selectedIndex != oldSelectedIndex) {
    selectionReason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 6
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  long nowMs = clock.elapsedRealtime();

  // Make initial selection
  if (reason == C.SELECTION_REASON_UNKNOWN) {
    reason = C.SELECTION_REASON_INITIAL;
    selectedIndex = determineIdealSelectedIndex(nowMs);
    return;
  }

  // Stash the current selection, then make a new one.
  int currentSelectedIndex = selectedIndex;
  selectedIndex = determineIdealSelectedIndex(nowMs);
  if (selectedIndex == currentSelectedIndex) {
    return;
  }

  if (!isBlacklisted(currentSelectedIndex, nowMs)) {
    // Revert back to the current selection if conditions are not suitable for switching.
    Format currentFormat = getFormat(currentSelectedIndex);
    Format selectedFormat = getFormat(selectedIndex);
    if (selectedFormat.bitrate > currentFormat.bitrate
        && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) {
      // The selected track is a higher quality, but we have insufficient buffer to safely switch
      // up. Defer switching up for now.
      selectedIndex = currentSelectedIndex;
    } else if (selectedFormat.bitrate < currentFormat.bitrate
        && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
      // The selected track is a lower quality, but we have sufficient buffer to defer switching
      // down for now.
      selectedIndex = currentSelectedIndex;
    }
  }
  // If we adapted, update the trigger.
  if (selectedIndex != currentSelectedIndex) {
    reason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 7
Source File: AdaptiveTrackSelection.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  long nowMs = clock.elapsedRealtime();

  // Update the estimated track bitrates.
  trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates);

  // Make initial selection
  if (reason == C.SELECTION_REASON_UNKNOWN) {
    reason = C.SELECTION_REASON_INITIAL;
    selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates);
    return;
  }

  // Stash the current selection, then make a new one.
  int currentSelectedIndex = selectedIndex;
  selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates);
  if (selectedIndex == currentSelectedIndex) {
    return;
  }

  if (!isBlacklisted(currentSelectedIndex, nowMs)) {
    // Revert back to the current selection if conditions are not suitable for switching.
    Format currentFormat = getFormat(currentSelectedIndex);
    Format selectedFormat = getFormat(selectedIndex);
    if (selectedFormat.bitrate > currentFormat.bitrate
        && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) {
      // The selected track is a higher quality, but we have insufficient buffer to safely switch
      // up. Defer switching up for now.
      selectedIndex = currentSelectedIndex;
    } else if (selectedFormat.bitrate < currentFormat.bitrate
        && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
      // The selected track is a lower quality, but we have sufficient buffer to defer switching
      // down for now.
      selectedIndex = currentSelectedIndex;
    }
  }
  // If we adapted, update the trigger.
  if (selectedIndex != currentSelectedIndex) {
    reason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 8
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<? extends MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators) {
  long nowMs = clock.elapsedRealtime();

  // Update the estimated track bitrates.
  trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates);

  // Make initial selection
  if (reason == C.SELECTION_REASON_UNKNOWN) {
    reason = C.SELECTION_REASON_INITIAL;
    selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates);
    return;
  }

  // Stash the current selection, then make a new one.
  int currentSelectedIndex = selectedIndex;
  selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates);
  if (selectedIndex == currentSelectedIndex) {
    return;
  }

  if (!isBlacklisted(currentSelectedIndex, nowMs)) {
    // Revert back to the current selection if conditions are not suitable for switching.
    Format currentFormat = getFormat(currentSelectedIndex);
    Format selectedFormat = getFormat(selectedIndex);
    if (selectedFormat.bitrate > currentFormat.bitrate
        && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) {
      // The selected track is a higher quality, but we have insufficient buffer to safely switch
      // up. Defer switching up for now.
      selectedIndex = currentSelectedIndex;
    } else if (selectedFormat.bitrate < currentFormat.bitrate
        && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
      // The selected track is a lower quality, but we have sufficient buffer to defer switching
      // down for now.
      selectedIndex = currentSelectedIndex;
    }
  }
  // If we adapted, update the trigger.
  if (selectedIndex != currentSelectedIndex) {
    reason = C.SELECTION_REASON_ADAPTIVE;
  }
}
 
Example 9
Source File: AdaptiveTrackSelection.java    From K-Sonic with MIT License 3 votes vote down vote up
/**
 * @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.
 * @param maxInitialBitrate The maximum bitrate in bits per second that should be assumed when a
 *     bandwidth estimate is unavailable.
 * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
 *     selected track to switch to one of higher quality.
 * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
 *     selected track to switch to one of lower quality.
 * @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
 *     quality, the selection may indicate that media already buffered at the lower quality can
 *     be discarded to speed up the switch. This is the minimum duration of media that must be
 *     retained at the lower quality.
 * @param bandwidthFraction The fraction of the available bandwidth that the selection should
 *     consider available for use. Setting to a value less than 1 is recommended to account
 *     for inaccuracies in the bandwidth estimator.
 */
public AdaptiveTrackSelection(TrackGroup group, int[] tracks, BandwidthMeter bandwidthMeter,
    int maxInitialBitrate, long minDurationForQualityIncreaseMs,
    long maxDurationForQualityDecreaseMs, long minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  super(group, tracks);
  this.bandwidthMeter = bandwidthMeter;
  this.maxInitialBitrate = maxInitialBitrate;
  this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
  this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
  this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
  this.bandwidthFraction = bandwidthFraction;
  selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
  reason = C.SELECTION_REASON_INITIAL;
}