# MediaCodec.LinearBlock

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# LinearBlock

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/MediaCodec.LinearBlock "View this page in Java")  

```
class LinearBlock
```

|---|------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                               ||
| ↳ | [android.media.MediaCodec.LinearBlock](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#) |

Section of memory that represents a linear block. Applications may acquire a block via[LinearBlock.obtain](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#obtain(kotlin.Int,%20kotlin.Array))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](https://developer.android.com/reference/kotlin/android/media/MediaCodec.OutputFrame). {@see QueueRequest#setLinearBlock} {@see QueueRequest#setEncryptedLinearBlock} {@see OutputFrame#getLinearBlock}

## Summary

|                                                                                                                                                                                                                                                                                                    Public methods                                                                                                                                                                                                                                                                                                    ||
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                              | [isCodecCopyFreeCompatible](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#isCodecCopyFreeCompatible(kotlin.Array))`(`codecNames:` `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!>`)` 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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                    | [isMappable](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#isMappable())`()` Returns true if the buffer is mappable.                                                                                                                                                                                                                                                                                                                                    |
| [ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)                                | [map](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#map())`()` Map the memory and return the mapped region.                                                                                                                                                                                                                                                                                                                                             |
| static[MediaCodec.LinearBlock](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#)? | [obtain](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#obtain(kotlin.Int,%20kotlin.Array))`(`capacity:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `codecNames:` `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!>`)` Obtain a linear block object no smaller than`capacity`.                       |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                                          | [recycle](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#recycle())`()` Mark this block as ready to be recycled by the framework once it is no longer in use.                                                                                                                                                                                                                                                                                            |

|                                                                                          Protected methods                                                                                          ||
|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [finalize](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#finalize())`()` <br /> |

## Public methods

### isCodecCopyFreeCompatible

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#obtain(kotlin.Int,%20kotlin.Array))may still throw due to invalid arguments or allocation failure.

|                                                                                                                                                     Parameters                                                                                                                                                      ||
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `codecNames` | [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)\<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!\>: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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun isMappable(): Boolean
```

Returns true if the buffer is mappable.

|                  Exceptions                   ||
|-----------------------------------|------------|
| `java.lang.IllegalStateException` | if invalid |

### map

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun map(): ByteBuffer
```

Map the memory and return the mapped region.

The returned memory region becomes inaccessible after[recycle](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#recycle()), or the buffer is queued to the codecs and not returned to the client yet.

|                                                                                                                 Return                                                                                                                  ||
|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| [ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#) | mapped memory region as[ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)object This value cannot be`null`. |

|                          Exceptions                           ||
|-----------------------------------|----------------------------|
| `java.lang.IllegalStateException` | if not mappable or invalid |

### obtain

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

Obtain a linear block object no smaller than`capacity`. If[isCodecCopyFreeCompatible](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#isCodecCopyFreeCompatible(kotlin.Array))with the same`codecNames`returned true, the returned[LinearBlock](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#)object can be queued to the listed codecs without copying. The returned[LinearBlock](https://developer.android.com/reference/kotlin/android/media/MediaCodec.LinearBlock#)object is always read/write mappable.

|                                                                                                                                                       Parameters                                                                                                                                                       ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `capacity`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):requested capacity of the linear block in bytes                                                                                                                                                                               |
| `codecNames` | [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)\<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!\>: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](https://developer.android.com/reference/kotlin/android/media/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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
protected fun finalize(): Unit
```

|                         Exceptions                         ||
|-----------------------|-------------------------------------|
| `java.lang.Throwable` | the`Exception`raised by this method |