public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer
MediaCodec.| Modifier and Type | Class and Description |
|---|---|
static interface |
MediaCodecVideoTrackRenderer.EventListener
Interface definition for a callback to be notified of
MediaCodecVideoTrackRenderer
events. |
MediaCodecTrackRenderer.DecoderInitializationException| Modifier and Type | Field and Description |
|---|---|
static int |
MSG_SET_SURFACE
The type of a message that can be passed to an instance of this class via
ExoPlayer.sendMessage(com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent, int, java.lang.Object) or ExoPlayer.blockingSendMessage(com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent, int, java.lang.Object). |
codecCounters, eventHandler, SOURCE_STATE_NOT_READY, SOURCE_STATE_READY, SOURCE_STATE_READY_READ_MAY_FAILEND_OF_TRACK_US, MATCH_LONGEST_US, STATE_ENABLED, STATE_PREPARED, STATE_RELEASED, STATE_STARTED, STATE_UNPREPARED, UNKNOWN_TIME_US| Constructor and Description |
|---|
MediaCodecVideoTrackRenderer(Context context,
SampleSource source,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode) |
MediaCodecVideoTrackRenderer(Context context,
SampleSource source,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs) |
MediaCodecVideoTrackRenderer(Context context,
SampleSource source,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
boolean playClearSamplesWithoutKeys,
Handler eventHandler,
MediaCodecVideoTrackRenderer.EventListener eventListener,
int maxDroppedFrameCountToNotify) |
MediaCodecVideoTrackRenderer(Context context,
SampleSource source,
MediaCodecSelector mediaCodecSelector,
int videoScalingMode,
long allowedJoiningTimeMs,
Handler eventHandler,
MediaCodecVideoTrackRenderer.EventListener eventListener,
int maxDroppedFrameCountToNotify) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
canReconfigureCodec(MediaCodec codec,
boolean codecIsAdaptive,
MediaFormat oldFormat,
MediaFormat 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,
boolean codecIsAdaptive,
MediaFormat format,
MediaCrypto crypto)
Configures a newly created
MediaCodec. |
protected void |
dropOutputBuffer(MediaCodec codec,
int bufferIndex) |
void |
handleMessage(int messageType,
Object message)
Handles a message delivered to the component.
|
protected boolean |
handlesTrack(MediaCodecSelector mediaCodecSelector,
MediaFormat mediaFormat)
Returns whether this renderer is capable of handling the provided track.
|
protected boolean |
haveRenderedFirstFrame() |
protected boolean |
isReady()
Whether the renderer is able to immediately render media from the current position.
|
protected void |
onDisabled()
Called when the renderer is disabled.
|
protected void |
onDiscontinuity(long positionUs)
Invoked when a discontinuity is encountered.
|
protected void |
onEnabled(int track,
long positionUs,
boolean joining)
Called when the renderer is enabled.
|
protected void |
onInputFormatChanged(MediaFormatHolder holder)
Invoked when a new format is read from the upstream
SampleSource. |
protected void |
onOutputFormatChanged(MediaCodec codec,
MediaFormat outputFormat)
Invoked when the output format of the
MediaCodec changes. |
protected void |
onStarted()
Called when the renderer is started.
|
protected void |
onStopped()
Called when the renderer is stopped.
|
protected boolean |
processOutputBuffer(long positionUs,
long elapsedRealtimeUs,
MediaCodec codec,
ByteBuffer buffer,
MediaCodec.BufferInfo bufferInfo,
int bufferIndex,
boolean shouldSkip)
Processes the provided output buffer.
|
protected void |
renderOutputBuffer(MediaCodec codec,
int bufferIndex) |
protected void |
renderOutputBufferV21(MediaCodec codec,
int bufferIndex,
long releaseTimeNs) |
protected boolean |
shouldInitCodec() |
protected void |
skipOutputBuffer(MediaCodec codec,
int bufferIndex) |
codecInitialized, doSomeWork, flushCodec, getDecoderInfo, getDequeueOutputBufferTimeoutUs, getSourceState, handlesTrack, haveFormat, isEnded, maybeInitCodec, onOutputStreamEnded, onProcessedOutputBuffer, onQueuedInputBuffer, releaseCodecdoPrepare, doSomeWork, getBufferedPositionUs, getDurationUs, getFormat, getTrackCount, maybeThrowError, onReleased, readSource, seekTo, shiftInputPositiongetMediaClock, getStatepublic static final int MSG_SET_SURFACE
ExoPlayer.sendMessage(com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent, int, java.lang.Object) or ExoPlayer.blockingSendMessage(com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent, int, java.lang.Object). The message object
should be the target Surface, or null.public MediaCodecVideoTrackRenderer(Context context, SampleSource source, MediaCodecSelector mediaCodecSelector, int videoScalingMode)
context - A context.source - The upstream source from which the renderer obtains samples.mediaCodecSelector - A decoder selector.videoScalingMode - The scaling mode to pass to
MediaCodec.setVideoScalingMode(int).public MediaCodecVideoTrackRenderer(Context context, SampleSource source, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs)
context - A context.source - The upstream source from which the renderer obtains samples.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 MediaCodecVideoTrackRenderer(Context context, SampleSource source, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs, Handler eventHandler, MediaCodecVideoTrackRenderer.EventListener eventListener, int maxDroppedFrameCountToNotify)
context - A context.source - The upstream source from which the renderer obtains samples.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 MediaCodecVideoTrackRenderer.EventListener.onDroppedFrames(int, long).public MediaCodecVideoTrackRenderer(Context context, SampleSource source, MediaCodecSelector mediaCodecSelector, int videoScalingMode, long allowedJoiningTimeMs, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, Handler eventHandler, MediaCodecVideoTrackRenderer.EventListener eventListener, int maxDroppedFrameCountToNotify)
context - A context.source - The upstream source from which the renderer obtains samples.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 acquisision. 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.maxDroppedFrameCountToNotify - The maximum number of frames that can be dropped between
invocations of MediaCodecVideoTrackRenderer.EventListener.onDroppedFrames(int, long).protected boolean handlesTrack(MediaCodecSelector mediaCodecSelector, MediaFormat mediaFormat) throws MediaCodecUtil.DecoderQueryException
MediaCodecTrackRendererhandlesTrack in class MediaCodecTrackRenderermediaCodecSelector - The decoder selector.mediaFormat - The format of the track.MediaCodecUtil.DecoderQueryException - Thrown if there was an error querying decoders.protected void onEnabled(int track,
long positionUs,
boolean joining)
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onEnabled in class SampleSourceTrackRenderertrack - The track for which the renderer is being enabled.positionUs - The player's current position.joining - Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException - If an error occurs.protected void onDiscontinuity(long positionUs)
throws ExoPlaybackException
SampleSourceTrackRendereronDiscontinuity in class MediaCodecTrackRendererpositionUs - The playback position after the discontinuity, or the position at which
the renderer is being enabled.ExoPlaybackException - If an error occurs handling the discontinuity.protected boolean isReady()
TrackRenderer
If the renderer is in the TrackRenderer.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 TrackRenderer.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:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
isReady in class MediaCodecTrackRendererprotected void onStarted()
TrackRendererThe default implementation is a no-op.
onStarted in class MediaCodecTrackRendererprotected void onStopped()
TrackRendererThe default implementation is a no-op.
onStopped in class MediaCodecTrackRendererprotected void onDisabled()
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onDisabled in class MediaCodecTrackRendererExoPlaybackException - If an error occurs.public void handleMessage(int messageType,
Object message)
throws ExoPlaybackException
ExoPlayer.ExoPlayerComponenthandleMessage in interface ExoPlayer.ExoPlayerComponenthandleMessage in class TrackRenderermessageType - An integer identifying the type of message.message - The message object.ExoPlaybackException - If an error occurred whilst handling the message.protected boolean shouldInitCodec()
shouldInitCodec in class MediaCodecTrackRendererprotected void configureCodec(MediaCodec codec, boolean codecIsAdaptive, MediaFormat format, MediaCrypto crypto)
MediaCodecTrackRendererMediaCodec.configureCodec in class MediaCodecTrackRenderercodec - The MediaCodec to configure.codecIsAdaptive - Whether the codec is adaptive.format - The format for which the codec is being configured.crypto - For drm protected playbacks, a MediaCrypto to use for decryption.protected void onInputFormatChanged(MediaFormatHolder holder) throws ExoPlaybackException
MediaCodecTrackRendererSampleSource.onInputFormatChanged in class MediaCodecTrackRendererholder - Holds the new format.ExoPlaybackException - If an error occurs reinitializing the MediaCodec.protected final boolean haveRenderedFirstFrame()
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat)
MediaCodecTrackRendererMediaCodec changes.
The default implementation is a no-op.
onOutputFormatChanged in class MediaCodecTrackRenderercodec - The MediaCodec instance.outputFormat - The new output format.protected boolean canReconfigureCodec(MediaCodec codec, boolean codecIsAdaptive, MediaFormat oldFormat, MediaFormat newFormat)
MediaCodecTrackRendererMediaCodec 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 MediaCodecTrackRenderercodec - 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,
MediaCodec.BufferInfo bufferInfo,
int bufferIndex,
boolean shouldSkip)
MediaCodecTrackRendererprocessOutputBuffer in class MediaCodecTrackRendererprotected void skipOutputBuffer(MediaCodec codec, int bufferIndex)
protected void dropOutputBuffer(MediaCodec codec, int bufferIndex)
protected void renderOutputBuffer(MediaCodec codec, int bufferIndex)
protected void renderOutputBufferV21(MediaCodec codec, int bufferIndex, long releaseTimeNs)