Added in API level 30

LinearBlock


class LinearBlock
kotlin.Any
   ↳ android.media.MediaCodec.LinearBlock

Section of memory that represents a linear block. Applications may acquire a block via LinearBlock#obtain and queue all or part of the block as an input buffer to a codec, or get a block allocated by codec as an output buffer from OutputFrame. {@see QueueRequest#setLinearBlock} {@see QueueRequest#setEncryptedLinearBlock} {@see OutputFrame#getLinearBlock}

Summary

Public methods
static Boolean

Returns true if it is possible to allocate a linear block that can be passed to all listed codecs as input buffers without copying the content.

Boolean

Returns true if the buffer is mappable.

ByteBuffer
map()

Map the memory and return the mapped region.

static MediaCodec.LinearBlock?
obtain(capacity: Int, codecNames: Array<String!>)

Obtain a linear block object no smaller than capacity.

Unit

Mark this block as ready to be recycled by the framework once it is no longer in use.

Protected methods
Unit

Public methods

isCodecCopyFreeCompatible

Added in API level 30
static fun isCodecCopyFreeCompatible(codecNames: Array<String!>): Boolean

Returns true if it is possible to allocate a linear block that can be passed to all listed codecs as input buffers without copying the content.

Note that even if this function returns true, obtain may still throw due to invalid arguments or allocation failure.

Parameters
codecNames Array<String!>: list of codecs that the client wants to use a linear block without copying. Null entries are ignored. This value cannot be null.

isMappable

Added in API level 30
fun isMappable(): Boolean

Returns true if the buffer is mappable.

Exceptions
java.lang.IllegalStateException if invalid

map

Added in API level 30
fun map(): ByteBuffer

Map the memory and return the mapped region.

The returned memory region becomes inaccessible after recycle, or the buffer is queued to the codecs and not returned to the client yet.

Return
ByteBuffer mapped memory region as ByteBuffer object This value cannot be null.
Exceptions
java.lang.IllegalStateException if not mappable or invalid

obtain

Added in API level 30
static fun obtain(
    capacity: Int,
    codecNames: Array<String!>
): MediaCodec.LinearBlock?

Obtain a linear block object no smaller than capacity. If isCodecCopyFreeCompatible with the same codecNames returned true, the returned LinearBlock object can be queued to the listed codecs without copying. The returned LinearBlock object is always read/write mappable.

Parameters
capacity Int: requested capacity of the linear block in bytes
codecNames Array<String!>: list of codecs that the client wants to use this linear block without copying. Null entries are ignored. This value cannot be null.
Return
MediaCodec.LinearBlock? a linear block object. This value may be null.
Exceptions
java.lang.IllegalArgumentException if the capacity is invalid or codecNames contains invalid name
java.io.IOException if an error occurred while allocating a buffer

recycle

Added in API level 30
fun recycle(): Unit

Mark this block as ready to be recycled by the framework once it is no longer in use. All operations to this object after this call will cause exceptions, as well as attempt to access the previously mapped memory region. Caller should clear all references to this object after this call.

To avoid excessive memory consumption, it is recommended that callers recycle buffers as soon as they no longer need the buffers

Exceptions
java.lang.IllegalStateException if invalid

Protected methods

finalize

Added in API level 30
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method