SynchronousMediaCodecAdapter


@UnstableApi
public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter


A MediaCodecAdapter that operates the underlying MediaCodec in synchronous mode.

Summary

Nested types

A factory for SynchronousMediaCodecAdapter instances.

Public methods

int

Returns the next available input buffer index from the underlying MediaCodec or INFO_TRY_AGAIN_LATER if no such buffer exists.

int

Returns the next available output buffer index from the underlying MediaCodec.

void

Detaches the current output surface.

void

Flushes the adapter and the underlying MediaCodec.

@Nullable ByteBuffer
getInputBuffer(int index)

Returns a writable ByteBuffer object for a dequeued input buffer index.

PersistableBundle
@RequiresApi(value = 26)
getMetrics()

Returns metrics data about the current codec instance.

@Nullable ByteBuffer
getOutputBuffer(int index)

Returns a read-only ByteBuffer for a dequeued output buffer index.

MediaFormat

Gets the MediaFormat that was output from the MediaCodec.

boolean

Whether the adapter needs to be reconfigured before it is used.

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

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

Registers a callback to be invoked when an output frame is rendered on the output surface.

void
@RequiresApi(value = 23)
setOutputSurface(Surface surface)

Dynamically sets the output surface of a MediaCodec.

void

Communicate additional parameter changes to the MediaCodec instance.

void

Specifies the scaling mode to use, if a surface was specified when the codec was created.

Inherited methods

From androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
boolean

Registers a listener that will be called when an input or output buffer becomes available.

Public methods

dequeueInputBufferIndex

public 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 MediaCodec raised an error.

dequeueOutputBufferIndex

public 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 MediaCodec raised an error.

detachOutputSurface

@RequiresApi(value = 35)
public void detachOutputSurface()

Detaches the current output surface.

See also
MediaCodec

flush

public void flush()

Flushes the adapter and the underlying MediaCodec.

getInputBuffer

public @Nullable ByteBuffer getInputBuffer(int index)

Returns a writable ByteBuffer object for a dequeued input buffer index.

See also
getInputBuffer

getMetrics

@RequiresApi(value = 26)
public PersistableBundle getMetrics()

Returns metrics data about the current codec instance.

See also
getMetrics

getOutputBuffer

public @Nullable ByteBuffer getOutputBuffer(int index)

Returns a read-only ByteBuffer for a dequeued output buffer index.

See also
getOutputBuffer

getOutputFormat

public 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

public boolean needsReconfiguration()

Whether the adapter needs to be reconfigured before it is used.

queueInputBuffer

public 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

public 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.

release

public void release()

Releases the adapter and the underlying MediaCodec.

releaseOutputBuffer

public 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.

releaseOutputBuffer

public 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.

setOnFrameRenderedListener

@RequiresApi(value = 23)
public void setOnFrameRenderedListener(
    MediaCodecAdapter.OnFrameRenderedListener listener,
    Handler handler
)

Registers a callback to be invoked when an output frame is rendered on the output surface.

setOutputSurface

@RequiresApi(value = 23)
public void setOutputSurface(Surface surface)

Dynamically sets the output surface of a MediaCodec.

See also
setOutputSurface

setParameters

public void setParameters(Bundle params)

Communicate additional parameter changes to the MediaCodec instance.

See also
setParameters

setVideoScalingMode

public void setVideoScalingMode(@C.VideoScalingMode int scalingMode)

Specifies the scaling mode to use, if a surface was specified when the codec was created.