Class DefaultLivePlaybackSpeedControl
- java.lang.Object
-
- com.google.android.exoplayer2.DefaultLivePlaybackSpeedControl
-
- All Implemented Interfaces:
LivePlaybackSpeedControl
public final class DefaultLivePlaybackSpeedControl extends Object implements LivePlaybackSpeedControl
ALivePlaybackSpeedControlthat adjusts the playback speed using a proportional controller.The control mechanism calculates the adjusted speed as
1.0 + proportionalControlFactor x (currentLiveOffsetSec - targetLiveOffsetSec). Unit speed (1.0f) is used, if thecurrentLiveOffsetSecis closer totargetLiveOffsetSecthan the value set withDefaultLivePlaybackSpeedControl.Builder.setMaxLiveOffsetErrorMsForUnitSpeed(long).The resulting speed is clamped to a minimum and maximum speed defined by the media, the fallback values set with
DefaultLivePlaybackSpeedControl.Builder.setFallbackMinPlaybackSpeed(float)andDefaultLivePlaybackSpeedControl.Builder.setFallbackMaxPlaybackSpeed(float)or theminimumandmaximumfallback default values.When the player rebuffers, the target live offset
is increasedto adjust to the reduced network capabilities. The live playback speed control alsokeeps trackof the minimum possible live offset to decrease the target live offset again if conditions improve. The minimum possible live offset is derived from the current offset and the duration of buffered media.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultLivePlaybackSpeedControl.BuilderBuilder for aDefaultLivePlaybackSpeedControl.
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_FALLBACK_MAX_PLAYBACK_SPEEDThe default maximum factor by which playback can be sped up that should be used if no maximum playback speed is defined by the media.static floatDEFAULT_FALLBACK_MIN_PLAYBACK_SPEEDThe default minimum factor by which playback can be sped up that should be used if no minimum playback speed is defined by the media.static longDEFAULT_MAX_LIVE_OFFSET_ERROR_MS_FOR_UNIT_SPEEDThe default maximum difference between the current live offset and the target live offset, in milliseconds, for which unit speed (1.0f) is used.static floatDEFAULT_MIN_POSSIBLE_LIVE_OFFSET_SMOOTHING_FACTORThe default smoothing factor when smoothing the minimum possible live offset that can be achieved during playback.static longDEFAULT_MIN_UPDATE_INTERVAL_MSThe defaultminimum intervalbetween playback speed changes, in milliseconds.static floatDEFAULT_PROPORTIONAL_CONTROL_FACTORThe defaultproportional control factorused to adjust the playback speed.static longDEFAULT_TARGET_LIVE_OFFSET_INCREMENT_ON_REBUFFER_MSThe default increment applied to the target live offset each time the player is rebuffering, in milliseconds
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetAdjustedPlaybackSpeed(long liveOffsetUs, long bufferedDurationUs)Returns the adjusted playback speed in order get closer towards thetarget live offset.longgetTargetLiveOffsetUs()Returns the current target live offset, in microseconds, orC.TIME_UNSETif no target live offset is defined for the current media.voidnotifyRebuffer()Notifies the live playback speed control that a rebuffer occurred.voidsetLiveConfiguration(MediaItem.LiveConfiguration liveConfiguration)Sets the live configuration defined by the media.voidsetTargetLiveOffsetOverrideUs(long liveOffsetUs)Sets the target live offset in microseconds that overrides the live offsetconfiguredby the media.
-
-
-
Field Detail
-
DEFAULT_FALLBACK_MIN_PLAYBACK_SPEED
public static final float DEFAULT_FALLBACK_MIN_PLAYBACK_SPEED
The default minimum factor by which playback can be sped up that should be used if no minimum playback speed is defined by the media.- See Also:
- Constant Field Values
-
DEFAULT_FALLBACK_MAX_PLAYBACK_SPEED
public static final float DEFAULT_FALLBACK_MAX_PLAYBACK_SPEED
The default maximum factor by which playback can be sped up that should be used if no maximum playback speed is defined by the media.- See Also:
- Constant Field Values
-
DEFAULT_MIN_UPDATE_INTERVAL_MS
public static final long DEFAULT_MIN_UPDATE_INTERVAL_MS
The defaultminimum intervalbetween playback speed changes, in milliseconds.- See Also:
- Constant Field Values
-
DEFAULT_PROPORTIONAL_CONTROL_FACTOR
public static final float DEFAULT_PROPORTIONAL_CONTROL_FACTOR
The defaultproportional control factorused to adjust the playback speed.- See Also:
- Constant Field Values
-
DEFAULT_TARGET_LIVE_OFFSET_INCREMENT_ON_REBUFFER_MS
public static final long DEFAULT_TARGET_LIVE_OFFSET_INCREMENT_ON_REBUFFER_MS
The default increment applied to the target live offset each time the player is rebuffering, in milliseconds- See Also:
- Constant Field Values
-
DEFAULT_MIN_POSSIBLE_LIVE_OFFSET_SMOOTHING_FACTOR
public static final float DEFAULT_MIN_POSSIBLE_LIVE_OFFSET_SMOOTHING_FACTOR
The default smoothing factor when smoothing the minimum possible live offset that can be achieved during playback.- See Also:
- Constant Field Values
-
DEFAULT_MAX_LIVE_OFFSET_ERROR_MS_FOR_UNIT_SPEED
public static final long DEFAULT_MAX_LIVE_OFFSET_ERROR_MS_FOR_UNIT_SPEED
The default maximum difference between the current live offset and the target live offset, in milliseconds, for which unit speed (1.0f) is used.- See Also:
- Constant Field Values
-
-
Method Detail
-
setLiveConfiguration
public void setLiveConfiguration(MediaItem.LiveConfiguration liveConfiguration)
Description copied from interface:LivePlaybackSpeedControlSets the live configuration defined by the media.- Specified by:
setLiveConfigurationin interfaceLivePlaybackSpeedControl- Parameters:
liveConfiguration- TheMediaItem.LiveConfigurationas defined by the media.
-
setTargetLiveOffsetOverrideUs
public void setTargetLiveOffsetOverrideUs(long liveOffsetUs)
Description copied from interface:LivePlaybackSpeedControlSets the target live offset in microseconds that overrides the live offsetconfiguredby the media. PassingC.TIME_UNSETdeletes a previous override.If no target live offset is configured by
LivePlaybackSpeedControl.setLiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration), this override has no effect.- Specified by:
setTargetLiveOffsetOverrideUsin interfaceLivePlaybackSpeedControl
-
notifyRebuffer
public void notifyRebuffer()
Description copied from interface:LivePlaybackSpeedControlNotifies the live playback speed control that a rebuffer occurred.A rebuffer is defined to be caused by buffer depletion rather than a user action. Hence this method is not called during initial buffering or when buffering as a result of a seek operation.
- Specified by:
notifyRebufferin interfaceLivePlaybackSpeedControl
-
getAdjustedPlaybackSpeed
public float getAdjustedPlaybackSpeed(long liveOffsetUs, long bufferedDurationUs)Description copied from interface:LivePlaybackSpeedControlReturns the adjusted playback speed in order get closer towards thetarget live offset.- Specified by:
getAdjustedPlaybackSpeedin interfaceLivePlaybackSpeedControl- Parameters:
liveOffsetUs- The current live offset, in microseconds.bufferedDurationUs- The duration of media that's currently buffered, in microseconds.- Returns:
- The adjusted factor by which playback should be sped up.
-
getTargetLiveOffsetUs
public long getTargetLiveOffsetUs()
Description copied from interface:LivePlaybackSpeedControlReturns the current target live offset, in microseconds, orC.TIME_UNSETif no target live offset is defined for the current media.- Specified by:
getTargetLiveOffsetUsin interfaceLivePlaybackSpeedControl
-
-