Partager via


MediaCodec.QueueInputBuffer Method

Definition

After filling a range of the input buffer at the specified index submit it to the component.

[Android.Runtime.Register("queueInputBuffer", "(IIIJI)V", "")]
public void QueueInputBuffer (int index, int offset, int size, long presentationTimeUs, Android.Media.MediaCodecBufferFlags flags);
[<Android.Runtime.Register("queueInputBuffer", "(IIIJI)V", "")>]
member this.QueueInputBuffer : int * int * int * int64 * Android.Media.MediaCodecBufferFlags -> unit

Parameters

index
Int32

The index of a client-owned input buffer previously returned in a call to #dequeueInputBuffer.

offset
Int32

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

size
Int32

The number of bytes of valid input data.

presentationTimeUs
Int64

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 SurfaceTexture#getTimestamp timestamp for the frame (after conversion to nanoseconds).

flags
MediaCodecBufferFlags

A bitmask of flags #BUFFER_FLAG_CODEC_CONFIG and #BUFFER_FLAG_END_OF_STREAM. While not prohibited, most codecs do not use the #BUFFER_FLAG_KEY_FRAME flag for input buffers.

Attributes

Exceptions

if not in the Executing state.

upon codec error.

Remarks

After filling a range of the input buffer at the specified index submit it to the component. Once an input buffer is queued to the codec, it MUST NOT be used until it is later retrieved by #getInputBuffer in response to a #dequeueInputBuffer return value or a Callback#onInputBufferAvailable callback.

Many decoders require the actual compressed data stream to be preceded by "codec specific data", i.e. setup data used to initialize the codec such as PPS/SPS in the case of AVC video or code tables in the case of vorbis audio. The class android.media.MediaExtractor provides codec specific data as part of the returned track format in entries named "csd-0", "csd-1" ...

These buffers can be submitted directly after #start or #flush by specifying the flag #BUFFER_FLAG_CODEC_CONFIG. However, if you configure the codec with a MediaFormat containing these keys, they will be automatically submitted by MediaCodec directly after start. Therefore, the use of #BUFFER_FLAG_CODEC_CONFIG flag is discouraged and is recommended only for advanced users.

To indicate that this is the final piece of input data (or rather that no more input data follows unless the decoder is subsequently flushed) specify the flag #BUFFER_FLAG_END_OF_STREAM. <p class=note> <strong>Note:</strong> Prior to android.os.Build.VERSION_CODES#M, presentationTimeUs was not propagated to the frame timestamp of (rendered) Surface output buffers, and the resulting frame timestamp was undefined. Use #releaseOutputBuffer(int, long) to ensure a specific frame timestamp is set. Similarly, since frame timestamps can be used by the destination surface for rendering synchronization, <strong>care must be taken to normalize presentationTimeUs so as to not be mistaken for a system time. (See #releaseOutputBuffer(int, long) SurfaceView specifics).</strong>

Java documentation for android.media.MediaCodec.queueInputBuffer(int, int, int, long, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to