MediaCodecAdapter
@UnstableApi
public interface MediaCodecAdapter
ForwardingMediaCodecAdapter |
A |
SynchronousMediaCodecAdapter |
A |
Abstracts MediaCodec operations.
MediaCodecAdapter offers a common interface to interact with a MediaCodec regardless of the mode the MediaCodec is operating in.
Summary
Nested types |
|---|
public final class MediaCodecAdapter.ConfigurationConfiguration parameters for a |
public interface MediaCodecAdapter.FactoryA factory for |
public interface MediaCodecAdapter.OnBufferAvailableListenerListener to be called when an input or output buffer becomes available. |
public interface MediaCodecAdapter.OnFrameRenderedListenerListener to be called when an output frame has rendered on the output surface. |
Public methods |
|
|---|---|
abstract int |
Returns the next available input buffer index from the underlying |
abstract int |
dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)Returns the next available output buffer index from the underlying |
abstract void |
@RequiresApi(value = 35)Detaches the current output surface. |
abstract void |
flush()Flushes the adapter and the underlying |
abstract @Nullable ByteBuffer |
getInputBuffer(int index)Returns a writable ByteBuffer object for a dequeued input buffer index. |
abstract PersistableBundle |
@RequiresApi(value = 26)Returns metrics data about the current codec instance. |
abstract @Nullable ByteBuffer |
getOutputBuffer(int index)Returns a read-only ByteBuffer for a dequeued output buffer index. |
abstract MediaFormat |
Gets the |
abstract boolean |
Whether the adapter needs to be reconfigured before it is used. |
abstract void |
queueInputBuffer(Submit an input buffer for decoding. |
abstract void |
queueSecureInputBuffer(Submit an input buffer that is potentially encrypted for decoding. |
default boolean |
Registers a listener that will be called when an input or output buffer becomes available. |
abstract void |
release()Releases the adapter and the underlying |
abstract void |
releaseOutputBuffer(int index, boolean render)Returns the buffer to the |
abstract void |
releaseOutputBuffer(int index, long renderTimeStampNs)Updates the output buffer's surface timestamp and sends it to the |
abstract void |
setOnFrameRenderedListener(Registers a callback to be invoked when an output frame is rendered on the output surface. |
abstract void |
setOutputSurface(Surface surface)Dynamically sets the output surface of a |
abstract void |
setParameters(Bundle params)Communicate additional parameter changes to the |
abstract void |
setVideoScalingMode(@C.VideoScalingMode int scalingMode)Specifies the scaling mode to use, if a surface was specified when the codec was created. |
abstract void |
@RequiresApi(value = 31)Subscribe to vendor parameters, so that these parameters will be present in |
abstract void |
@RequiresApi(value = 31)Unsubscribe from vendor parameters, so that these parameters will not be present in |
default void |
useInputBuffer(Runnable runnable)Uses an acquired input buffer (e.g. to write data to it). |
Public methods
dequeueInputBufferIndex
abstract int dequeueInputBufferIndex()
Returns the next available input buffer index from the underlying MediaCodec or INFO_TRY_AGAIN_LATER if no such buffer exists.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the underlying |
dequeueOutputBufferIndex
abstract int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
Returns the next available output buffer index from the underlying MediaCodec. If the next available output is a MediaFormat change, it will return INFO_OUTPUT_FORMAT_CHANGED and you should call getOutputFormat to get the format. If there is no available output, this method will return INFO_TRY_AGAIN_LATER.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the underlying |
detachOutputSurface
@RequiresApi(value = 35)
abstract void detachOutputSurface()
Detaches the current output surface.
| See also | |
|---|---|
detachOutputSurface |
getInputBuffer
abstract @Nullable ByteBuffer getInputBuffer(int index)
Returns a writable ByteBuffer object for a dequeued input buffer index.
| See also | |
|---|---|
getInputBuffer |
getMetrics
@RequiresApi(value = 26)
abstract PersistableBundle getMetrics()
Returns metrics data about the current codec instance.
| See also | |
|---|---|
getMetrics |
getOutputBuffer
abstract @Nullable ByteBuffer getOutputBuffer(int index)
Returns a read-only ByteBuffer for a dequeued output buffer index.
| See also | |
|---|---|
getOutputBuffer |
getOutputFormat
abstract MediaFormat getOutputFormat()
Gets the MediaFormat that was output from the MediaCodec.
Call this method if a previous call to dequeueOutputBufferIndex returned INFO_OUTPUT_FORMAT_CHANGED.
needsReconfiguration
abstract boolean needsReconfiguration()
Whether the adapter needs to be reconfigured before it is used.
queueInputBuffer
abstract void queueInputBuffer(
int index,
int offset,
int size,
long presentationTimeUs,
int flags
)
Submit an input buffer for decoding.
The index must be an input buffer index that has been obtained from a previous call to dequeueInputBufferIndex.
| See also | |
|---|---|
queueInputBuffer |
queueSecureInputBuffer
abstract void queueSecureInputBuffer(
int index,
int offset,
CryptoInfo info,
long presentationTimeUs,
int flags
)
Submit an input buffer that is potentially encrypted for decoding.
The index must be an input buffer index that has been obtained from a previous call to dequeueInputBufferIndex.
This method behaves like queueSecureInputBuffer, with the difference that info is of type CryptoInfo and not android.media.MediaCodec.CryptoInfo.
| See also | |
|---|---|
queueSecureInputBuffer |
registerOnBufferAvailableListener
default boolean registerOnBufferAvailableListener(
MediaCodecAdapter.OnBufferAvailableListener listener
)
Registers a listener that will be called when an input or output buffer becomes available.
Returns false if listener was not successfully registered for callbacks.
| Returns | |
|---|---|
boolean |
Whether listener was successfully registered. |
releaseOutputBuffer
abstract void releaseOutputBuffer(int index, boolean render)
Returns the buffer to the 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.
| See also | |
|---|---|
releaseOutputBuffer |
releaseOutputBuffer
abstract 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. If the MediaCodec is not configured with an output surface, this call will simply return the buffer to the MediaCodec.
| See also | |
|---|---|
releaseOutputBuffer |
setOnFrameRenderedListener
abstract void setOnFrameRenderedListener(
MediaCodecAdapter.OnFrameRenderedListener listener,
Handler handler
)
Registers a callback to be invoked when an output frame is rendered on the output surface.
| See also | |
|---|---|
setOnFrameRenderedListener |
setOutputSurface
abstract void setOutputSurface(Surface surface)
Dynamically sets the output surface of a MediaCodec.
| See also | |
|---|---|
setOutputSurface |
setParameters
abstract void setParameters(Bundle params)
Communicate additional parameter changes to the MediaCodec instance.
| See also | |
|---|---|
setParameters |
setVideoScalingMode
abstract void setVideoScalingMode(@C.VideoScalingMode int scalingMode)
Specifies the scaling mode to use, if a surface was specified when the codec was created.
| See also | |
|---|---|
setVideoScalingMode |
subscribeToVendorParameters
@RequiresApi(value = 31)
abstract void subscribeToVendorParameters(List<String> names)
Subscribe to vendor parameters, so that these parameters will be present in getOutputFormat and changes to these parameters generate output format change event.
| See also | |
|---|---|
subscribeToVendorParameters |
unsubscribeFromVendorParameters
@RequiresApi(value = 31)
abstract void unsubscribeFromVendorParameters(List<String> names)
Unsubscribe from vendor parameters, so that these parameters will not be present in getOutputFormat and changes to these parameters no longer generate output format change event.
| See also | |
|---|---|
unsubscribeFromVendorParameters |
useInputBuffer
default void useInputBuffer(Runnable runnable)
Uses an acquired input buffer (e.g. to write data to it).
This can be used for error handling, e.g. to guarantee no operation can invalidate the buffer while it's being used.