SynchronousMediaCodecAdapterpublic interface MediaCodecAdapter
MediaCodec operations.
MediaCodecAdapter offers a common interface to interact with a MediaCodec
regardless of the mode the MediaCodec is operating in.
| Modifier and Type | Interface | Description |
|---|---|---|
static interface |
MediaCodecAdapter.Factory |
A factory for
MediaCodecAdapter instances. |
static interface |
MediaCodecAdapter.OnFrameRenderedListener |
Listener to be called when an output frame has rendered on the output surface.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
configure(MediaFormat mediaFormat,
Surface surface,
MediaCrypto crypto,
int flags) |
Configures this adapter and the underlying
MediaCodec. |
int |
dequeueInputBufferIndex() |
Returns the next available input buffer index from the underlying
MediaCodec or MediaCodec.INFO_TRY_AGAIN_LATER if no such buffer exists. |
int |
dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) |
Returns the next available output buffer index from the underlying
MediaCodec. |
void |
flush() |
Flushes the adapter and the underlying
MediaCodec. |
ByteBuffer |
getInputBuffer(int index) |
Returns a writable ByteBuffer object for a dequeued input buffer index.
|
ByteBuffer |
getOutputBuffer(int index) |
Returns a read-only ByteBuffer for a dequeued output buffer index.
|
MediaFormat |
getOutputFormat() |
Gets the
MediaFormat that was output from the MediaCodec. |
void |
queueInputBuffer(int index,
int offset,
int size,
long presentationTimeUs,
int flags) |
Submit an input buffer for decoding.
|
void |
queueSecureInputBuffer(int index,
int offset,
CryptoInfo info,
long presentationTimeUs,
int flags) |
Submit an input buffer that is potentially encrypted for decoding.
|
void |
release() |
Releases the adapter and the underlying
MediaCodec. |
void |
releaseOutputBuffer(int index,
boolean render) |
Returns the buffer to the
MediaCodec. |
void |
releaseOutputBuffer(int index,
long renderTimeStampNs) |
Updates the output buffer's surface timestamp and sends it to the
MediaCodec to render
it on the output surface. |
void |
setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener,
Handler handler) |
Registers a callback to be invoked when an output frame is rendered on the output surface.
|
void |
setOutputSurface(Surface surface) |
Dynamically sets the output surface of a
MediaCodec. |
void |
setParameters(Bundle params) |
Communicate additional parameter changes to the
MediaCodec instance. |
void |
setVideoScalingMode(int scalingMode) |
Specifies the scaling mode to use, if a surface has been specified in a previous call to
configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int). |
void |
start() |
Starts this instance.
|
void configure(@Nullable
MediaFormat mediaFormat,
@Nullable
Surface surface,
@Nullable
MediaCrypto crypto,
int flags)
MediaCodec. Needs to be called before start().void start()
configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).MediaCodec.start()int dequeueInputBufferIndex()
MediaCodec or MediaCodec.INFO_TRY_AGAIN_LATER if no such buffer exists.IllegalStateException - If the underlying MediaCodec raised an error.int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
MediaCodec. If the
next available output is a MediaFormat change, it will return MediaCodec.INFO_OUTPUT_FORMAT_CHANGED and you should call getOutputFormat() to get
the format. If there is no available output, this method will return MediaCodec.INFO_TRY_AGAIN_LATER.IllegalStateException - If the underlying MediaCodec raised an error.MediaFormat getOutputFormat()
MediaFormat that was output from the MediaCodec.
Call this method if a previous call to dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo) returned MediaCodec.INFO_OUTPUT_FORMAT_CHANGED.
@Nullable ByteBuffer getInputBuffer(int index)
MediaCodec.getInputBuffer(int)@Nullable ByteBuffer getOutputBuffer(int index)
MediaCodec.getOutputBuffer(int)void queueInputBuffer(int index,
int offset,
int size,
long presentationTimeUs,
int flags)
The index must be an input buffer index that has been obtained from a previous call
to dequeueInputBufferIndex().
void queueSecureInputBuffer(int index,
int offset,
CryptoInfo info,
long presentationTimeUs,
int flags)
The index must be an input buffer index that has been obtained from a previous call
to dequeueInputBufferIndex().
This method behaves like MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int), with the difference that
info is of type CryptoInfo and not MediaCodec.CryptoInfo.
void releaseOutputBuffer(int index,
boolean render)
MediaCodec. If the MediaCodec was configured with an
output surface, setting render to true will first send the buffer to the output
surface. The surface will release the buffer back to the codec once it is no longer
used/displayed.void releaseOutputBuffer(int index,
long renderTimeStampNs)
MediaCodec to render
it on the output surface. If the MediaCodec is not configured with an output surface,
this call will simply return the buffer to the MediaCodec.void flush()
MediaCodec.void release()
MediaCodec.void setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)
void setOutputSurface(Surface surface)
MediaCodec.MediaCodec.setOutputSurface(Surface)void setParameters(Bundle params)
MediaCodec instance.MediaCodec.setParameters(Bundle)void setVideoScalingMode(@VideoScalingMode int scalingMode)
configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).MediaCodec.setVideoScalingMode(int)