Class DefaultRenderersFactory
- java.lang.Object
-
- com.google.android.exoplayer2.DefaultRenderersFactory
-
- All Implemented Interfaces:
RenderersFactory
public class DefaultRenderersFactory extends Object implements RenderersFactory
DefaultRenderersFactoryimplementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDefaultRenderersFactory.ExtensionRendererModeModes for using extension renderers.
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_ALLOWED_VIDEO_JOINING_TIME_MSThe default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.static intEXTENSION_RENDERER_MODE_OFFDo not allow use of extension renderers.static intEXTENSION_RENDERER_MODE_ONAllow use of extension renderers.static intEXTENSION_RENDERER_MODE_PREFERAllow use of extension renderers.static intMAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFYThe maximum number of frames that can be dropped between invocations ofVideoRendererEventListener.onDroppedFrames(int, long).
-
Constructor Summary
Constructors Constructor Description DefaultRenderersFactory(Context context)DefaultRenderersFactory(Context context, int extensionRendererMode)Deprecated.DefaultRenderersFactory(Context context, int extensionRendererMode, long allowedVideoJoiningTimeMs)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, AudioSink audioSink, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out)Builds audio renderers for use by the player.protected AudioSinkbuildAudioSink(Context context, boolean enableFloatOutput, boolean enableAudioTrackPlaybackParams, boolean enableOffload)Builds anAudioSinkto which the audio renderers will output.protected voidbuildCameraMotionRenderers(Context context, int extensionRendererMode, ArrayList<Renderer> out)Builds camera motion renderers for use by the player.protected voidbuildMetadataRenderers(Context context, MetadataOutput output, Looper outputLooper, int extensionRendererMode, ArrayList<Renderer> out)Builds metadata renderers for use by the player.protected voidbuildMiscellaneousRenderers(Context context, Handler eventHandler, int extensionRendererMode, ArrayList<Renderer> out)Builds any miscellaneous renderers used by the player.protected voidbuildTextRenderers(Context context, TextOutput output, Looper outputLooper, int extensionRendererMode, ArrayList<Renderer> out)Builds text renderers for use by the player.protected voidbuildVideoRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out)Builds video renderers for use by the player.Renderer[]createRenderers(Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput)DefaultRenderersFactoryexperimentalSetImmediateCodecStartAfterFlushEnabled(boolean enabled)Enable callingMediaCodec.start()immediately afterMediaCodec.flush()on the playback thread, when operating the codec in asynchronous mode.DefaultRenderersFactoryexperimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(boolean enabled)Enable synchronizing codec interactions with asynchronous buffer queueing.DefaultRenderersFactoryforceDisableMediaCodecAsynchronousQueueing()DisablesMediaCodecRendererinstances from operating theirMediaCodecin asynchronous mode and perform asynchronous queueing.DefaultRenderersFactoryforceEnableMediaCodecAsynchronousQueueing()EnablesMediaCodecRendererinstances to operate theirMediaCodecin asynchronous mode and perform asynchronous queueing.protected MediaCodecAdapter.FactorygetCodecAdapterFactory()Returns theMediaCodecAdapter.Factorythat will be used when creatingMediaCodecRendererinstances.DefaultRenderersFactorysetAllowedVideoJoiningTimeMs(long allowedVideoJoiningTimeMs)Sets the maximum duration for which video renderers can attempt to seamlessly join an ongoing playback.DefaultRenderersFactorysetEnableAudioFloatOutput(boolean enableFloatOutput)Sets whether floating point audio should be output when possible.DefaultRenderersFactorysetEnableAudioOffload(boolean enableOffload)Sets whether audio should be played using the offload path.DefaultRenderersFactorysetEnableAudioTrackPlaybackParams(boolean enableAudioTrackPlaybackParams)Sets whether to enable setting playback speed usingAudioTrack.setPlaybackParams(PlaybackParams), which is supported from API level 23, rather than using application-level audio speed adjustment.DefaultRenderersFactorysetEnableDecoderFallback(boolean enableDecoderFallback)Sets whether to enable fallback to lower-priority decoders if decoder initialization fails.DefaultRenderersFactorysetExtensionRendererMode(int extensionRendererMode)Sets the extension renderer mode, which determines if and how available extension renderers are used.DefaultRenderersFactorysetMediaCodecSelector(MediaCodecSelector mediaCodecSelector)Sets aMediaCodecSelectorfor use byMediaCodecbased renderers.
-
-
-
Field Detail
-
DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS
public static final long DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS
The default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.- See Also:
- Constant Field Values
-
EXTENSION_RENDERER_MODE_OFF
public static final int EXTENSION_RENDERER_MODE_OFF
Do not allow use of extension renderers.- See Also:
- Constant Field Values
-
EXTENSION_RENDERER_MODE_ON
public static final int EXTENSION_RENDERER_MODE_ON
Allow use of extension renderers. Extension renderers are indexed after core renderers of the same type. ATrackSelectorthat prefers the first suitable renderer will therefore prefer to use a core renderer to an extension renderer in the case that both are able to play a given track.- See Also:
- Constant Field Values
-
EXTENSION_RENDERER_MODE_PREFER
public static final int EXTENSION_RENDERER_MODE_PREFER
Allow use of extension renderers. Extension renderers are indexed before core renderers of the same type. ATrackSelectorthat prefers the first suitable renderer will therefore prefer to use an extension renderer to a core renderer in the case that both are able to play a given track.- See Also:
- Constant Field Values
-
MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY
public static final int MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY
The maximum number of frames that can be dropped between invocations ofVideoRendererEventListener.onDroppedFrames(int, long).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultRenderersFactory
public DefaultRenderersFactory(Context context)
- Parameters:
context- AContext.
-
DefaultRenderersFactory
@Deprecated public DefaultRenderersFactory(Context context, @ExtensionRendererMode int extensionRendererMode)
Deprecated.
-
DefaultRenderersFactory
@Deprecated public DefaultRenderersFactory(Context context, @ExtensionRendererMode int extensionRendererMode, long allowedVideoJoiningTimeMs)
Deprecated.
-
-
Method Detail
-
setExtensionRendererMode
public DefaultRenderersFactory setExtensionRendererMode(@ExtensionRendererMode int extensionRendererMode)
Sets the extension renderer mode, which determines if and how available extension renderers are used. Note that extensions must be included in the application build for them to be considered available.The default value is
EXTENSION_RENDERER_MODE_OFF.- Parameters:
extensionRendererMode- The extension renderer mode.- Returns:
- This factory, for convenience.
-
forceEnableMediaCodecAsynchronousQueueing
public DefaultRenderersFactory forceEnableMediaCodecAsynchronousQueueing()
EnablesMediaCodecRendererinstances to operate theirMediaCodecin asynchronous mode and perform asynchronous queueing.This feature can be enabled only on devices with API versions >= 23. For devices with older API versions, this method is a no-op.
- Returns:
- This factory, for convenience.
-
forceDisableMediaCodecAsynchronousQueueing
public DefaultRenderersFactory forceDisableMediaCodecAsynchronousQueueing()
DisablesMediaCodecRendererinstances from operating theirMediaCodecin asynchronous mode and perform asynchronous queueing.MediaCodecinstances will be operated synchronous mode.- Returns:
- This factory, for convenience.
-
experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled
public DefaultRenderersFactory experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(boolean enabled)
Enable synchronizing codec interactions with asynchronous buffer queueing.This method is experimental, and will be renamed or removed in a future release.
- Parameters:
enabled- Whether codec interactions will be synchronized with asynchronous buffer queueing.- Returns:
- This factory, for convenience.
-
experimentalSetImmediateCodecStartAfterFlushEnabled
public DefaultRenderersFactory experimentalSetImmediateCodecStartAfterFlushEnabled(boolean enabled)
Enable callingMediaCodec.start()immediately afterMediaCodec.flush()on the playback thread, when operating the codec in asynchronous mode. If disabled,MediaCodec.start()will be called by the callback thread after pending callbacks are handled.By default, this feature is disabled.
This method is experimental, and will be renamed or removed in a future release.
- Parameters:
enabled- WhetherMediaCodec.start()will be called on the playback thread immediately afterMediaCodec.flush().- Returns:
- This factory, for convenience.
-
setEnableDecoderFallback
public DefaultRenderersFactory setEnableDecoderFallback(boolean enableDecoderFallback)
Sets whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is less efficient or slower than the primary decoder.- Parameters:
enableDecoderFallback- Whether to enable fallback to lower-priority decoders if decoder initialization fails.- Returns:
- This factory, for convenience.
-
setMediaCodecSelector
public DefaultRenderersFactory setMediaCodecSelector(MediaCodecSelector mediaCodecSelector)
Sets aMediaCodecSelectorfor use byMediaCodecbased renderers.The default value is
MediaCodecSelector.DEFAULT.- Parameters:
mediaCodecSelector- TheMediaCodecSelector.- Returns:
- This factory, for convenience.
-
setEnableAudioFloatOutput
public DefaultRenderersFactory setEnableAudioFloatOutput(boolean enableFloatOutput)
Sets whether floating point audio should be output when possible.Enabling floating point output disables audio processing, but may allow for higher quality audio output.
The default value is
false.- Parameters:
enableFloatOutput- Whether to enable use of floating point audio output, if available.- Returns:
- This factory, for convenience.
-
setEnableAudioOffload
public DefaultRenderersFactory setEnableAudioOffload(boolean enableOffload)
Sets whether audio should be played using the offload path.Audio offload disables ExoPlayer audio processing, but significantly reduces the energy consumption of the playback when
offload schedulingis enabled.Most Android devices can only support one offload
AudioTrackat a time and can invalidate it at any time. Thus an app can never be guaranteed that it will be able to play in offload.The default value is
false.- Parameters:
enableOffload- Whether to enable use of audio offload for supported formats, if available.- Returns:
- This factory, for convenience.
-
setEnableAudioTrackPlaybackParams
public DefaultRenderersFactory setEnableAudioTrackPlaybackParams(boolean enableAudioTrackPlaybackParams)
Sets whether to enable setting playback speed usingAudioTrack.setPlaybackParams(PlaybackParams), which is supported from API level 23, rather than using application-level audio speed adjustment. This setting has no effect on builds before API level 23 (application-level speed adjustment will be used in all cases).If enabled and supported, new playback speed settings will take effect more quickly because they are applied at the audio mixer, rather than at the point of writing data to the track.
When using this mode, the maximum supported playback speed is limited by the size of the audio track's buffer. If the requested speed is not supported the player's event listener will be notified twice on setting playback speed, once with the requested speed, then again with the old playback speed reflecting the fact that the requested speed was not supported.
- Parameters:
enableAudioTrackPlaybackParams- Whether to enable setting playback speed usingAudioTrack.setPlaybackParams(PlaybackParams).- Returns:
- This factory, for convenience.
-
setAllowedVideoJoiningTimeMs
public DefaultRenderersFactory setAllowedVideoJoiningTimeMs(long allowedVideoJoiningTimeMs)
Sets the maximum duration for which video renderers can attempt to seamlessly join an ongoing playback.The default value is
DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS.- Parameters:
allowedVideoJoiningTimeMs- The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.- Returns:
- This factory, for convenience.
-
createRenderers
public Renderer[] createRenderers(Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput)
Description copied from interface:RenderersFactory- Specified by:
createRenderersin interfaceRenderersFactory- Parameters:
eventHandler- A handler to use when invoking event listeners and outputs.videoRendererEventListener- An event listener for video renderers.audioRendererEventListener- An event listener for audio renderers.textRendererOutput- An output for text renderers.metadataRendererOutput- An output for metadata renderers.- Returns:
- The
instances.
-
buildVideoRenderers
protected void buildVideoRenderers(Context context, @ExtensionRendererMode int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out)
Builds video renderers for use by the player.- Parameters:
context- TheContextassociated with the player.extensionRendererMode- The extension renderer mode.mediaCodecSelector- A decoder selector.enableDecoderFallback- Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is slower/less efficient than the primary decoder.eventHandler- A handler associated with the main thread's looper.eventListener- An event listener.allowedVideoJoiningTimeMs- The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.out- An array to which the built renderers should be appended.
-
buildAudioRenderers
protected void buildAudioRenderers(Context context, @ExtensionRendererMode int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, AudioSink audioSink, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out)
Builds audio renderers for use by the player.- Parameters:
context- TheContextassociated with the player.extensionRendererMode- The extension renderer mode.mediaCodecSelector- A decoder selector.enableDecoderFallback- Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is slower/less efficient than the primary decoder.audioSink- A sink to which the renderers will output.eventHandler- A handler to use when invoking event listeners and outputs.eventListener- An event listener.out- An array to which the built renderers should be appended.
-
buildTextRenderers
protected void buildTextRenderers(Context context, TextOutput output, Looper outputLooper, @ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)
Builds text renderers for use by the player.- Parameters:
context- TheContextassociated with the player.output- An output for the renderers.outputLooper- The looper associated with the thread on which the output should be called.extensionRendererMode- The extension renderer mode.out- An array to which the built renderers should be appended.
-
buildMetadataRenderers
protected void buildMetadataRenderers(Context context, MetadataOutput output, Looper outputLooper, @ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)
Builds metadata renderers for use by the player.- Parameters:
context- TheContextassociated with the player.output- An output for the renderers.outputLooper- The looper associated with the thread on which the output should be called.extensionRendererMode- The extension renderer mode.out- An array to which the built renderers should be appended.
-
buildCameraMotionRenderers
protected void buildCameraMotionRenderers(Context context, @ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)
Builds camera motion renderers for use by the player.- Parameters:
context- TheContextassociated with the player.extensionRendererMode- The extension renderer mode.out- An array to which the built renderers should be appended.
-
buildMiscellaneousRenderers
protected void buildMiscellaneousRenderers(Context context, Handler eventHandler, @ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)
Builds any miscellaneous renderers used by the player.- Parameters:
context- TheContextassociated with the player.eventHandler- A handler to use when invoking event listeners and outputs.extensionRendererMode- The extension renderer mode.out- An array to which the built renderers should be appended.
-
buildAudioSink
@Nullable protected AudioSink buildAudioSink(Context context, boolean enableFloatOutput, boolean enableAudioTrackPlaybackParams, boolean enableOffload)
Builds anAudioSinkto which the audio renderers will output.- Parameters:
context- TheContextassociated with the player.enableFloatOutput- Whether to enable use of floating point audio output, if available.enableAudioTrackPlaybackParams- Whether to enable setting playback speed usingAudioTrack.setPlaybackParams(PlaybackParams), if supported.enableOffload- Whether to enable use of audio offload for supported formats, if available.- Returns:
- The
AudioSinkto which the audio renderers will output. May benullif no audio renderers are required. Ifnullis returned thenbuildAudioRenderers(android.content.Context, int, com.google.android.exoplayer2.mediacodec.MediaCodecSelector, boolean, com.google.android.exoplayer2.audio.AudioSink, android.os.Handler, com.google.android.exoplayer2.audio.AudioRendererEventListener, java.util.ArrayList<com.google.android.exoplayer2.Renderer>)will not be called.
-
getCodecAdapterFactory
protected MediaCodecAdapter.Factory getCodecAdapterFactory()
Returns theMediaCodecAdapter.Factorythat will be used when creatingMediaCodecRendererinstances.
-
-