public class MediaCodecVideoRenderer extends MediaCodecRenderer
MediaCodec
.MediaCodecRenderer.DecoderInitializationException
decoderCounters
STATE_DISABLED, STATE_ENABLED, STATE_STARTED
ADAPTIVE_NOT_SEAMLESS, ADAPTIVE_NOT_SUPPORTED, ADAPTIVE_SEAMLESS, ADAPTIVE_SUPPORT_MASK, FORMAT_EXCEEDS_CAPABILITIES, FORMAT_HANDLED, FORMAT_SUPPORT_MASK, FORMAT_UNSUPPORTED_SUBTYPE, FORMAT_UNSUPPORTED_TYPE
Constructor and Description |
---|
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode) |
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs) |
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
boolean playClearSamplesWithoutKeys,
Handler eventHandler,
VideoRendererEventListener eventListener,
int maxDroppedFramesToNotify) |
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs,
Handler eventHandler,
VideoRendererEventListener eventListener,
int maxDroppedFrameCountToNotify) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canReconfigureCodec(MediaCodec codec,
boolean codecIsAdaptive,
Format oldFormat,
Format newFormat)
Determines whether the existing
MediaCodec should be reconfigured for a new format by
sending codec specific initialization data at the start of the next input buffer. |
protected void |
configureCodec(MediaCodec codec,
Format format,
MediaCrypto crypto)
Configures a newly created
MediaCodec . |
void |
handleMessage(int messageType,
Object message)
Handles a message delivered to the component.
|
boolean |
isReady()
Whether the renderer is able to immediately render media from the current position.
|
protected void |
onCodecInitialized(String name,
long initializedTimestampMs,
long initializationDurationMs)
Called when a
MediaCodec has been created and configured. |
protected void |
onDisabled()
Called when the renderer is disabled.
|
protected void |
onEnabled(boolean joining)
Called when the renderer is enabled.
|
protected void |
onInputFormatChanged(Format newFormat)
Called when a new format is read from the upstream
MediaPeriod . |
protected void |
onOutputFormatChanged(MediaCodec codec,
MediaFormat outputFormat)
Called when the output format of the
MediaCodec changes. |
protected void |
onPositionReset(long positionUs,
boolean joining)
Called when the position is reset.
|
protected void |
onStarted()
Called when the renderer is started.
|
protected void |
onStopped()
Called when the renderer is stopped.
|
protected void |
onStreamChanged(Format[] formats)
Called when the renderer's stream has changed.
|
protected boolean |
processOutputBuffer(long positionUs,
long elapsedRealtimeUs,
MediaCodec codec,
ByteBuffer buffer,
int bufferIndex,
int bufferFlags,
long bufferPresentationTimeUs,
boolean shouldSkip)
Processes an output media buffer.
|
protected boolean |
shouldInitCodec() |
protected int |
supportsFormat(MediaCodecSelector mediaCodecSelector,
Format format)
Returns the extent to which the renderer is capable of supporting a given format.
|
flushCodec, getDecoderInfo, getDequeueOutputBufferTimeoutUs, isEnded, maybeInitCodec, onOutputStreamEnded, onProcessedOutputBuffer, onQueueInputBuffer, releaseCodec, render, supportsFormat, supportsMixedMimeTypeAdaptation
disable, enable, getCapabilities, getIndex, getMediaClock, getState, getStream, getTrackType, hasReadStreamToEnd, isSourceReady, maybeThrowStreamError, readSource, replaceStream, resetPosition, setCurrentStreamIsFinal, setIndex, skipToKeyframeBefore, start, stop
public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, int videoScalingMode)
context
- A context.mediaCodecSelector
- A decoder selector.videoScalingMode
- The scaling mode to pass to
MediaCodec.setVideoScalingMode(int)
.public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs)
context
- A context.mediaCodecSelector
- A decoder selector.videoScalingMode
- The scaling mode to pass to
MediaCodec.setVideoScalingMode(int)
.allowedJoiningTimeMs
- The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs, Handler eventHandler, VideoRendererEventListener eventListener, int maxDroppedFrameCountToNotify)
context
- A context.mediaCodecSelector
- A decoder selector.videoScalingMode
- The scaling mode to pass to
MediaCodec.setVideoScalingMode(int)
.allowedJoiningTimeMs
- The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.maxDroppedFrameCountToNotify
- The maximum number of frames that can be dropped between
invocations of VideoRendererEventListener.onDroppedFrames(int, long)
.public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, Handler eventHandler, VideoRendererEventListener eventListener, int maxDroppedFramesToNotify)
context
- A context.mediaCodecSelector
- A decoder selector.videoScalingMode
- The scaling mode to pass to
MediaCodec.setVideoScalingMode(int)
.allowedJoiningTimeMs
- The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.drmSessionManager
- For use with encrypted content. May be null if support for encrypted
content is not required.playClearSamplesWithoutKeys
- Encrypted media may contain clear (un-encrypted) regions.
For example a media file may start with a short clear region so as to allow playback to
begin in parallel with key acquisition. This parameter specifies whether the renderer is
permitted to play clear regions of encrypted media files before drmSessionManager
has obtained the keys necessary to decrypt encrypted regions of the media.eventHandler
- A handler to use when delivering events to eventListener
. May be
null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.maxDroppedFramesToNotify
- The maximum number of frames that can be dropped between
invocations of VideoRendererEventListener.onDroppedFrames(int, long)
.protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format) throws MediaCodecUtil.DecoderQueryException
MediaCodecRenderer
supportsFormat
in class MediaCodecRenderer
mediaCodecSelector
- The decoder selector.format
- The format.MediaCodecRenderer.supportsFormat(Format)
for more detail.MediaCodecUtil.DecoderQueryException
- If there was an error querying decoders.protected void onEnabled(boolean joining) throws ExoPlaybackException
BaseRenderer
The default implementation is a no-op.
onEnabled
in class MediaCodecRenderer
joining
- Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException
- If an error occurs.protected void onStreamChanged(Format[] formats) throws ExoPlaybackException
BaseRenderer
BaseRenderer.onEnabled(boolean)
has been called, and also when the stream has been replaced whilst
the renderer is enabled or started.
The default implementation is a no-op.
onStreamChanged
in class BaseRenderer
formats
- The enabled formats.ExoPlaybackException
- If an error occurs.protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
BaseRenderer
BaseRenderer.onStreamChanged(Format[])
has been called, and also when a position discontinuity
is encountered.
After a position reset, the renderer's SampleStream
is guaranteed to provide samples
starting from a key frame.
The default implementation is a no-op.
onPositionReset
in class MediaCodecRenderer
positionUs
- The new playback position in microseconds.joining
- Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException
- If an error occurs.public boolean isReady()
Renderer
If the renderer is in the Renderer.STATE_STARTED
state then returning true indicates that the
renderer has everything that it needs to continue playback. Returning false indicates that
the player should pause until the renderer is ready.
If the renderer is in the Renderer.STATE_ENABLED
state then returning true indicates that the
renderer is ready for playback to be started. Returning false indicates that it is not.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
isReady
in interface Renderer
isReady
in class MediaCodecRenderer
protected void onStarted()
BaseRenderer
The default implementation is a no-op.
onStarted
in class MediaCodecRenderer
protected void onStopped()
BaseRenderer
The default implementation is a no-op.
onStopped
in class MediaCodecRenderer
protected void onDisabled()
BaseRenderer
The default implementation is a no-op.
onDisabled
in class MediaCodecRenderer
public void handleMessage(int messageType, Object message) throws ExoPlaybackException
ExoPlayer.ExoPlayerComponent
handleMessage
in interface ExoPlayer.ExoPlayerComponent
handleMessage
in class BaseRenderer
messageType
- The message type.message
- The message.ExoPlaybackException
- If an error occurred whilst handling the message.protected boolean shouldInitCodec()
shouldInitCodec
in class MediaCodecRenderer
protected void configureCodec(MediaCodec codec, Format format, MediaCrypto crypto)
MediaCodecRenderer
MediaCodec
.configureCodec
in class MediaCodecRenderer
codec
- The MediaCodec
to configure.format
- The format for which the codec is being configured.crypto
- For drm protected playbacks, a MediaCrypto
to use for decryption.protected void onCodecInitialized(String name, long initializedTimestampMs, long initializationDurationMs)
MediaCodecRenderer
MediaCodec
has been created and configured.
The default implementation is a no-op.
onCodecInitialized
in class MediaCodecRenderer
name
- The name of the codec that was initialized.initializedTimestampMs
- SystemClock.elapsedRealtime()
when initialization
finished.initializationDurationMs
- The time taken to initialize the codec in milliseconds.protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException
MediaCodecRenderer
MediaPeriod
.onInputFormatChanged
in class MediaCodecRenderer
newFormat
- The new format.ExoPlaybackException
- If an error occurs reinitializing the MediaCodec
.protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat)
MediaCodecRenderer
MediaCodec
changes.
The default implementation is a no-op.
onOutputFormatChanged
in class MediaCodecRenderer
codec
- The MediaCodec
instance.outputFormat
- The new output format.protected boolean canReconfigureCodec(MediaCodec codec, boolean codecIsAdaptive, Format oldFormat, Format newFormat)
MediaCodecRenderer
MediaCodec
should be reconfigured for a new format by
sending codec specific initialization data at the start of the next input buffer. If true is
returned then the MediaCodec
instance will be reconfigured in this way. If false is
returned then the instance will be released, and a new instance will be created for the new
format.
The default implementation returns false.
canReconfigureCodec
in class MediaCodecRenderer
codec
- The existing MediaCodec
instance.codecIsAdaptive
- Whether the codec is adaptive.oldFormat
- The format for which the existing instance is configured.newFormat
- The new format.protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, MediaCodec codec, ByteBuffer buffer, int bufferIndex, int bufferFlags, long bufferPresentationTimeUs, boolean shouldSkip)
MediaCodecRenderer
When a new ByteBuffer
is passed to this method its position and limit delineate the
data to be processed. The return value indicates whether the buffer was processed in full. If
true is returned then the next call to this method will receive a new buffer to be processed.
If false is returned then the same buffer will be passed to the next call. An implementation of
this method is free to modify the buffer and can assume that the buffer will not be externally
modified between successive calls. Hence an implementation can, for example, modify the
buffer's position to keep track of how much of the data it has processed.
Note that the first call to this method following a call to
MediaCodecRenderer.onPositionReset(long, boolean)
will always receive a new ByteBuffer
to be
processed.
processOutputBuffer
in class MediaCodecRenderer
positionUs
- The current media time in microseconds, measured at the start of the
current iteration of the rendering loop.elapsedRealtimeUs
- SystemClock.elapsedRealtime()
in microseconds,
measured at the start of the current iteration of the rendering loop.codec
- The MediaCodec
instance.buffer
- The output buffer to process.bufferIndex
- The index of the output buffer.bufferFlags
- The flags attached to the output buffer.bufferPresentationTimeUs
- The presentation time of the output buffer in microseconds.shouldSkip
- Whether the buffer should be skipped (i.e. not rendered).