com.google.android.exoplayer2.upstream.BandwidthMeter Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.BandwidthMeter. 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: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #2
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in {@link SimpleExoPlayer.Builder}.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #3
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in {@link
 *     SimpleExoPlayer.Builder}.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
}
 
Example #4
Source File: ExoPlayerFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  return new SimpleExoPlayer(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      looper);
}
 
Example #5
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      looper);
}
 
Example #6
Source File: VideoPlayer.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay)
    throws IOException
{
  BandwidthMeter         bandwidthMeter             = new DefaultBandwidthMeter();
  TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
  TrackSelector          trackSelector              = new DefaultTrackSelector(videoTrackSelectionFactory);
  LoadControl            loadControl                = new DefaultLoadControl();

  exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
  exoPlayer.addListener(new ExoPlayerListener(window));
  //noinspection ConstantConditions
  exoView.setPlayer(exoPlayer);

  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory();

  MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);

  exoPlayer.prepare(mediaSource);
  exoPlayer.setPlayWhenReady(autoplay);
}
 
Example #7
Source File: ExoPlayerFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 */
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      Util.getLooper());
}
 
Example #8
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in {@link ExoPlayerFactory}.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #9
Source File: AdaptiveTrackSelection.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in {@link ExoPlayerFactory}.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  trackBitrateEstimator = TrackBitrateEstimator.DEFAULT;
}
 
Example #10
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      Util.getLooper());
}
 
Example #11
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a single adaptive selection for the given group, bandwidth meter and tracks.
 *
 * @param group The {@link TrackGroup}.
 * @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
 * @param tracks The indices of the selected tracks in the track group.
 * @param totalFixedTrackBandwidth The total bandwidth used by all non-adaptive tracks, in bits
 *     per second.
 * @return An {@link AdaptiveTrackSelection} for the specified tracks.
 */
protected AdaptiveTrackSelection createAdaptiveTrackSelection(
    TrackGroup group,
    BandwidthMeter bandwidthMeter,
    int[] tracks,
    int totalFixedTrackBandwidth) {
  return new AdaptiveTrackSelection(
      group,
      tracks,
      new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction, totalFixedTrackBandwidth),
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bufferedFractionToLiveEdgeForQualityIncrease,
      minTimeBetweenBufferReevaluationMs,
      clock);
}
 
Example #12
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    Looper looper) {
  this(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      looper);
}
 
Example #13
Source File: ExoPlayerFactory.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  return new SimpleExoPlayer(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      looper);
}
 
Example #14
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AdaptiveTrackSelection createTrackSelection(
    TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks) {
  if (this.bandwidthMeter != null) {
    bandwidthMeter = this.bandwidthMeter;
  }
  return new AdaptiveTrackSelection(
      group,
      tracks,
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      bufferedFractionToLiveEdgeForQualityIncrease,
      minTimeBetweenBufferReevaluationMs,
      clock);
}
 
Example #15
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in ExoPlayerFactory.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
}
 
Example #16
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in ExoPlayerFactory.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
}
 
Example #17
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in ExoPlayerFactory.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #18
Source File: ExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a builder with the specified custom components.
 *
 * <p>Note that this constructor is only useful if you try to ensure that ExoPlayer's default
 * components can be removed by ProGuard or R8. For most components except renderers, there is
 * only a marginal benefit of doing that.
 *
 * @param renderers The {@link Renderer Renderers} to be used by the player.
 * @param trackSelector A {@link TrackSelector}.
 * @param loadControl A {@link LoadControl}.
 * @param bandwidthMeter A {@link BandwidthMeter}.
 * @param looper A {@link Looper} that must be used for all calls to the player.
 * @param analyticsCollector An {@link AnalyticsCollector}.
 * @param useLazyPreparation Whether media sources should be initialized lazily.
 * @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
 */
public Builder(
    Renderer[] renderers,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    Looper looper,
    AnalyticsCollector analyticsCollector,
    boolean useLazyPreparation,
    Clock clock) {
  Assertions.checkArgument(renderers.length > 0);
  this.renderers = renderers;
  this.trackSelector = trackSelector;
  this.loadControl = loadControl;
  this.bandwidthMeter = bandwidthMeter;
  this.looper = looper;
  this.analyticsCollector = analyticsCollector;
  this.useLazyPreparation = useLazyPreparation;
  this.clock = clock;
}
 
Example #19
Source File: PlaybackFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
Example #20
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in {@link ExoPlayerFactory}.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  trackBitrateEstimator = TrackBitrateEstimator.DEFAULT;
}
 
Example #21
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      Util.getLooper());
}
 
Example #22
Source File: AdaptiveTrackSelection.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Computes the ideal selected index ignoring buffer health.
 *
 * @param nowMs The current time in the timebase of {@link SystemClock#elapsedRealtime()}, or
 *     {@link Long#MIN_VALUE} to ignore blacklisting.
 */
private int determineIdealSelectedIndex(long nowMs) {
  long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
  long effectiveBitrate = bitrateEstimate == BandwidthMeter.NO_ESTIMATE
      ? maxInitialBitrate : (long) (bitrateEstimate * bandwidthFraction);
  int lowestBitrateNonBlacklistedIndex = 0;
  for (int i = 0; i < length; i++) {
    if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
      Format format = getFormat(i);
      if (format.bitrate <= effectiveBitrate) {
        return i;
      } else {
        lowestBitrateNonBlacklistedIndex = i;
      }
    }
  }
  return lowestBitrateNonBlacklistedIndex;
}
 
Example #23
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  return new SimpleExoPlayer(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      looper);
}
 
Example #24
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.
 */
public AdaptiveTrackSelection(TrackGroup group, int[] tracks,
    BandwidthMeter bandwidthMeter) {
  this(
      group,
      tracks,
      bandwidthMeter,
      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,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #25
Source File: ExoPlayerFactory.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an {@link ExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderers The {@link Renderer}s that will be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
@SuppressWarnings("unused")
public static ExoPlayer newInstance(
    Context context,
    Renderer[] renderers,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    Looper looper) {
  return new ExoPlayerImpl(
      renderers, trackSelector, loadControl, bandwidthMeter, Clock.DEFAULT, looper);
}
 
Example #26
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #Factory()} instead. Custom bandwidth meter should be directly passed
 *     to the player in ExoPlayerFactory.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(BandwidthMeter bandwidthMeter) {
  this(
      bandwidthMeter,
      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,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #27
Source File: RandomTrackSelection.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public @NullableType TrackSelection[] createTrackSelections(
    @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
  return TrackSelectionUtil.createTrackSelectionsForDefinitions(
      definitions,
      definition -> new RandomTrackSelection(definition.group, definition.tracks, random));
}
 
Example #28
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #Factory()} instead. Custom bandwidth meter should be directly passed
 *     to the player in ExoPlayerFactory.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(BandwidthMeter bandwidthMeter) {
  this(
      bandwidthMeter,
      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,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #29
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 5 votes vote down vote up
public DefaultPlayer(@NonNull Context context,
                     @NonNull RenderersFactory renderersFactory,
                     @NonNull TrackSelector trackSelector,
                     @NonNull LoadControl loadControl,
                     @Nullable BandwidthMeter bandwidthMeter) {
    this(
        context,
        renderersFactory,
        trackSelector,
        loadControl,
        bandwidthMeter,
        null
    );
}
 
Example #30
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable TrackSelection selectAdaptiveVideoTrack(
    TrackGroupArray groups,
    int[][] formatSupport,
    int mixedMimeTypeAdaptationSupports,
    Parameters params,
    TrackSelection.Factory adaptiveTrackSelectionFactory,
    BandwidthMeter bandwidthMeter)
    throws ExoPlaybackException {
  int requiredAdaptiveSupport = params.allowNonSeamlessAdaptiveness
      ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
      : RendererCapabilities.ADAPTIVE_SEAMLESS;
  boolean allowMixedMimeTypes =
      params.allowMixedMimeAdaptiveness
          && (mixedMimeTypeAdaptationSupports & 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 Assertions.checkNotNull(adaptiveTrackSelectionFactory)
          .createTrackSelection(group, bandwidthMeter, adaptiveTracks);
    }
  }
  return null;
}