Added in API level 30

MediaCodec.QueueRequest


public final class MediaCodec.QueueRequest
extends Object

java.lang.Object
   ↳ android.media.MediaCodec.QueueRequest


Builder-like class for queue requests. Use this class to prepare a queue request and send it.

Summary

Public methods

void queue()

Finish building a queue request and queue the buffers with tunings.

MediaCodec.QueueRequest setByteBufferParameter(String key, ByteBuffer value)

Add a ByteBuffer parameter.

MediaCodec.QueueRequest setEncryptedLinearBlock(MediaCodec.LinearBlock block, int offset, int size, MediaCodec.CryptoInfo cryptoInfo)

Set an encrypted linear block to this queue request.

MediaCodec.QueueRequest setFlags(int flags)

Set flags to this queue request.

MediaCodec.QueueRequest setFloatParameter(String key, float value)

Add a float parameter.

MediaCodec.QueueRequest setHardwareBuffer(HardwareBuffer buffer)

Set a hardware graphic buffer to this queue request.

MediaCodec.QueueRequest setIntegerParameter(String key, int value)

Add an integer parameter.

MediaCodec.QueueRequest setLinearBlock(MediaCodec.LinearBlock block, int offset, int size)

Set a linear block to this queue request.

MediaCodec.QueueRequest setLongParameter(String key, long value)

Add a long parameter.

MediaCodec.QueueRequest setMultiFrameEncryptedLinearBlock(MediaCodec.LinearBlock block, ArrayDeque<MediaCodec.BufferInfo> bufferInfos, ArrayDeque<MediaCodec.CryptoInfo> cryptoInfos)

Set an encrypted linear block to this queue request.

MediaCodec.QueueRequest setMultiFrameLinearBlock(MediaCodec.LinearBlock block, ArrayDeque<MediaCodec.BufferInfo> infos)

Set a linear block that contain multiple non-encrypted access unit to this queue request.

MediaCodec.QueueRequest setPresentationTimeUs(long presentationTimeUs)

Set timestamp to this queue request.

MediaCodec.QueueRequest setStringParameter(String key, String value)

Add a string parameter.

Inherited methods

Public methods

queue

Added in API level 30
public void queue ()

Finish building a queue request and queue the buffers with tunings.

setByteBufferParameter

Added in API level 30
public MediaCodec.QueueRequest setByteBufferParameter (String key, 
                ByteBuffer value)

Add a ByteBuffer parameter. See MediaFormat for an exhaustive list of supported keys with values of byte buffer, that can also be set with MediaFormat#setByteBuffer. If there was MediaCodec#setParameters call with the same key which is not processed by the codec yet, the value set from this method will override the unprocessed value.

Parameters
key String: This value cannot be null.

value ByteBuffer: This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setEncryptedLinearBlock

Added in API level 30
public MediaCodec.QueueRequest setEncryptedLinearBlock (MediaCodec.LinearBlock block, 
                int offset, 
                int size, 
                MediaCodec.CryptoInfo cryptoInfo)

Set an encrypted linear block to this queue request. Exactly one buffer must be set for a queue request before calling queue(). It is possible to use the same LinearBlock object for multiple queue requests. The behavior is undefined if the range of the buffer overlaps for multiple requests, or the application writes into the region being processed by the codec.

Parameters
block MediaCodec.LinearBlock: The linear block object This value cannot be null.

offset int: The byte offset into the input buffer at which the data starts.

size int: The number of bytes of valid input data.

cryptoInfo MediaCodec.CryptoInfo: Metadata describing the structure of the encrypted input sample. This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

Throws
IllegalStateException if a buffer is already set

setFlags

Added in API level 30
public MediaCodec.QueueRequest setFlags (int flags)

Set flags to this queue request.

Parameters
flags int: A bitmask of flags MediaCodec.BUFFER_FLAG_CODEC_CONFIG and MediaCodec.BUFFER_FLAG_END_OF_STREAM. While not prohibited, most codecs do not use the MediaCodec.BUFFER_FLAG_KEY_FRAME flag for input buffers. Value is either 0 or a combination of MediaCodec.BUFFER_FLAG_SYNC_FRAME, MediaCodec.BUFFER_FLAG_KEY_FRAME, MediaCodec.BUFFER_FLAG_CODEC_CONFIG, MediaCodec.BUFFER_FLAG_END_OF_STREAM, MediaCodec.BUFFER_FLAG_PARTIAL_FRAME, android.media.MediaCodec.BUFFER_FLAG_MUXER_DATA, and MediaCodec.BUFFER_FLAG_DECODE_ONLY

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setFloatParameter

Added in API level 30
public MediaCodec.QueueRequest setFloatParameter (String key, 
                float value)

Add a float parameter. See MediaFormat for an exhaustive list of supported keys with values of type float, that can also be set with MediaFormat#setFloat. If there was MediaCodec#setParameters call with the same key which is not processed by the codec yet, the value set from this method will override the unprocessed value.

Parameters
key String: This value cannot be null.

value float

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setHardwareBuffer

Added in API level 30
public MediaCodec.QueueRequest setHardwareBuffer (HardwareBuffer buffer)

Set a hardware graphic buffer to this queue request. Exactly one buffer must be set for a queue request before calling queue().

Note: buffers should have format HardwareBuffer#YCBCR_420_888, a single layer, and an appropriate usage (HardwareBuffer#USAGE_CPU_READ_OFTEN for software codecs and HardwareBuffer#USAGE_VIDEO_ENCODE for hardware) for codecs to recognize. Format ImageFormat#PRIVATE together with usage HardwareBuffer#USAGE_VIDEO_ENCODE will also work for hardware codecs. Codecs may throw exception if the buffer is not recognizable.

Parameters
buffer HardwareBuffer: The hardware graphic buffer object This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

Throws
IllegalStateException if a buffer is already set

setIntegerParameter

Added in API level 30
public MediaCodec.QueueRequest setIntegerParameter (String key, 
                int value)

Add an integer parameter. See MediaFormat for an exhaustive list of supported keys with values of type int, that can also be set with MediaFormat#setInteger. If there was MediaCodec#setParameters call with the same key which is not processed by the codec yet, the value set from this method will override the unprocessed value.

Parameters
key String: This value cannot be null.

value int

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setLinearBlock

Added in API level 30
public MediaCodec.QueueRequest setLinearBlock (MediaCodec.LinearBlock block, 
                int offset, 
                int size)

Set a linear block to this queue request. Exactly one buffer must be set for a queue request before calling queue(). It is possible to use the same LinearBlock object for multiple queue requests. The behavior is undefined if the range of the buffer overlaps for multiple requests, or the application writes into the region being processed by the codec.

Parameters
block MediaCodec.LinearBlock: The linear block object This value cannot be null.

offset int: The byte offset into the input buffer at which the data starts.

size int: The number of bytes of valid input data.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

Throws
IllegalStateException if a buffer is already set

setLongParameter

Added in API level 30
public MediaCodec.QueueRequest setLongParameter (String key, 
                long value)

Add a long parameter. See MediaFormat for an exhaustive list of supported keys with values of type long, that can also be set with MediaFormat#setLong. If there was MediaCodec#setParameters call with the same key which is not processed by the codec yet, the value set from this method will override the unprocessed value.

Parameters
key String: This value cannot be null.

value long

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setMultiFrameEncryptedLinearBlock

Added in API level 35
public MediaCodec.QueueRequest setMultiFrameEncryptedLinearBlock (MediaCodec.LinearBlock block, 
                ArrayDeque<MediaCodec.BufferInfo> bufferInfos, 
                ArrayDeque<MediaCodec.CryptoInfo> cryptoInfos)

Set an encrypted linear block to this queue request. Exactly one buffer must be set for a queue request before calling queue(). The block can contain multiple access units and if present should be laid out contiguously and without gaps.

Parameters
block MediaCodec.LinearBlock: The linear block object This value cannot be null.

bufferInfos ArrayDeque: ArrayDeque of MediaCodec.BufferInfo that describes the contents in the buffer. The ArrayDeque and the BufferInfo objects provided can be recycled by the caller for re-use. This value cannot be null.

cryptoInfos ArrayDeque: ArrayDeque of MediaCodec.CryptoInfo that describes the structure of the encrypted input samples. The ArrayDeque and the BufferInfo objects provided can be recycled by the caller for re-use. This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

Throws
IllegalStateException if a buffer is already set
IllegalArgumentException upon if bufferInfos is empty, contains null, or if the access units are not contiguous.

setMultiFrameLinearBlock

Added in API level 35
public MediaCodec.QueueRequest setMultiFrameLinearBlock (MediaCodec.LinearBlock block, 
                ArrayDeque<MediaCodec.BufferInfo> infos)

Set a linear block that contain multiple non-encrypted access unit to this queue request. Exactly one buffer must be set for a queue request before calling queue(). Multiple access units if present must be laid out contiguously and without gaps and in order. An IllegalArgumentException will be thrown during queue() if access units are not laid out contiguously.

Parameters
block MediaCodec.LinearBlock: The linear block object This value cannot be null.

infos ArrayDeque: Represents MediaCodec.BufferInfo objects to mark individual access-unit boundaries and the timestamps associated with it. This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.

Throws
IllegalStateException if a buffer is already set

setPresentationTimeUs

Added in API level 30
public MediaCodec.QueueRequest setPresentationTimeUs (long presentationTimeUs)

Set timestamp to this queue request.

Parameters
presentationTimeUs long: The presentation timestamp in microseconds for this buffer. This is normally the media time at which this buffer should be presented (rendered). When using an output surface, this will be propagated as the timestamp for the frame (after conversion to nanoseconds).

Returns
MediaCodec.QueueRequest this object This value cannot be null.

setStringParameter

Added in API level 30
public MediaCodec.QueueRequest setStringParameter (String key, 
                String value)

Add a string parameter. See MediaFormat for an exhaustive list of supported keys with values of type string, that can also be set with MediaFormat#setString. If there was MediaCodec#setParameters call with the same key which is not processed by the codec yet, the value set from this method will override the unprocessed value.

Parameters
key String: This value cannot be null.

value String: This value cannot be null.

Returns
MediaCodec.QueueRequest this object This value cannot be null.