# DecoderInputBuffer

Artifact: [androidx.media3:media3-decoder](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/decoder/DecoderInputBuffer.java+class:androidx.media3.decoder.DecoderInputBuffer)

*** ** * ** ***


```
@UnstableApi
public class DecoderInputBuffer extends Buffer
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.decoder.Buffer](https://developer.android.com/reference/androidx/media3/decoder/Buffer) ||
|   | ↳ | [androidx.media3.decoder.DecoderInputBuffer](https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer) |

Known direct subclasses [MetadataInputBuffer](https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataInputBuffer), [SubtitleInputBuffer](https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer)

|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataInputBuffer` | A `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` for a `https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataDecoder`. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer` | A `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` for a `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoder`. |

*** ** * ** ***

Holds input for a decoder.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode` The buffer replacement mode. |
| `public final class https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.InsufficientCapacityException extends https://developer.android.com/reference/java/lang/IllegalStateException.html` Thrown when an attempt is made to write into a `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` whose `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#bufferReplacementMode()` is `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#BUFFER_REPLACEMENT_MODE_DISABLED()` and who `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` capacity is smaller than required. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#BUFFER_REPLACEMENT_MODE_DIRECT() = 2` Allows buffer replacement using `https://developer.android.com/reference/java/nio/ByteBuffer.html#allocateDirect(int)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#BUFFER_REPLACEMENT_MODE_DISABLED() = 0` Disallows buffer replacement. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#BUFFER_REPLACEMENT_MODE_NORMAL() = 1` Allows buffer replacement using `https://developer.android.com/reference/java/nio/ByteBuffer.html#allocate(int)`. |

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/androidx/media3/decoder/CryptoInfo` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#cryptoInfo()` `https://developer.android.com/reference/androidx/media3/decoder/CryptoInfo` for encrypted data. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` The buffer's data, or `null` if no data has been set. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#format()` The `https://developer.android.com/reference/androidx/media3/common/Format`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` Supplemental data related to the buffer, if `https://developer.android.com/reference/androidx/media3/decoder/Buffer#hasSupplementalData()` returns true. |
| `long` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#timeUs()` The time at which the sample should be presented. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#waitingForKeys()` Whether the last attempt to read a sample into this buffer failed due to not yet having the DRM keys associated with the next sample. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#DecoderInputBuffer(int)( @https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode )` Creates a new instance. |
| `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#DecoderInputBuffer(int,int)( @https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode, int paddingSize )` Creates a new instance. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#clear()()` Clears the buffer. |
| `void` | `@https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/EnsuresNonNull.html(value = "data") https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#ensureSpaceForWrite(int)(int length)` Ensures that `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` is large enough to accommodate a write of a given length at its current position. |
| `final void` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#flip()()` Flips `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` and `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` in preparation for being queued to a decoder. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#isEncrypted()()` Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_ENCRYPTED()` flag is set. |
| `static https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` | `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#newNoDataInstance()()` Returns a new instance that's not able to hold any data. |
| `void` | `@https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/EnsuresNonNull.html(value = "supplementalData") https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#resetSupplementalData(int)(int length)` Clears `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` and ensures that it's large enough to accommodate ` length` bytes. |

### Inherited methods

From [androidx.media3.decoder.Buffer](https://developer.android.com/reference/androidx/media3/decoder/Buffer) `final void` `https://developer.android.com/reference/androidx/media3/decoder/Buffer#addFlag(int)(@https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flag)`

Adds the `flag` to this buffer's flags.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/Buffer#clearFlag(int)(@https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flag)`

Removes the `flag` from this buffer's flags, if it is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#getFlag(int)(@https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flag)`

Returns whether the specified flag has been set on this buffer.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#hasSupplementalData()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA()` flag is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#isEndOfStream()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#isFirstSample()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_FIRST_SAMPLE()` flag is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#isKeyFrame()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_KEY_FRAME()` flag is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#isLastSample()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_LAST_SAMPLE()` flag is set.
`final boolean` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html
https://developer.android.com/reference/androidx/media3/decoder/Buffer#notDependedOn()()`

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_NOT_DEPENDED_ON()` flag is set.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/Buffer#setFlags(int)(@https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flags)`

Replaces this buffer's flags with `flags`.

## Constants

### BUFFER_REPLACEMENT_MODE_DIRECT

```
public static final int BUFFER_REPLACEMENT_MODE_DIRECT = 2
```

Allows buffer replacement using `https://developer.android.com/reference/java/nio/ByteBuffer.html#allocateDirect(int)`.

### BUFFER_REPLACEMENT_MODE_DISABLED

```
public static final int BUFFER_REPLACEMENT_MODE_DISABLED = 0
```

Disallows buffer replacement.

### BUFFER_REPLACEMENT_MODE_NORMAL

```
public static final int BUFFER_REPLACEMENT_MODE_NORMAL = 1
```

Allows buffer replacement using `https://developer.android.com/reference/java/nio/ByteBuffer.html#allocate(int)`.

## Public fields

### cryptoInfo

```
public final CryptoInfo cryptoInfo
```

`https://developer.android.com/reference/androidx/media3/decoder/CryptoInfo` for encrypted data.

### data

```
public @Nullable ByteBuffer data
```

The buffer's data, or `null` if no data has been set.

### format

```
public @Nullable Format format
```

The `https://developer.android.com/reference/androidx/media3/common/Format`.

### supplementalData

```
public @Nullable ByteBuffer supplementalData
```

Supplemental data related to the buffer, if `https://developer.android.com/reference/androidx/media3/decoder/Buffer#hasSupplementalData()` returns true. If present, the buffer is populated with supplemental data from position 0 to its limit.

### timeUs

```
public long timeUs
```

The time at which the sample should be presented.

### waitingForKeys

```
public boolean waitingForKeys
```

Whether the last attempt to read a sample into this buffer failed due to not yet having the DRM keys associated with the next sample.

## Public constructors

### DecoderInputBuffer

```
public DecoderInputBuffer(
    @DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode
)
```

Creates a new instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode` | The `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode` replacement mode. |

### DecoderInputBuffer

```
public DecoderInputBuffer(
    @DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode,
    int paddingSize
)
```

Creates a new instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode` | The `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.BufferReplacementMode` replacement mode. |
| `int paddingSize` | If non-zero, `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#ensureSpaceForWrite(int)` will ensure that the buffer is this number of bytes larger than the requested length. This can be useful for decoders that consume data in fixed size blocks, for efficiency. Setting the padding size to the decoder's fixed read size is necessary to prevent such a decoder from trying to read beyond the end of the buffer. |

## Public methods

### clear

```
public void clear()
```

Clears the buffer.

### ensureSpaceForWrite

```
@EnsuresNonNull(value = "data")
public void ensureSpaceForWrite(int length)
```

Ensures that `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` is large enough to accommodate a write of a given length at its current position.

If the capacity of `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` is sufficient this method does nothing. If the capacity is insufficient then an attempt is made to replace `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` with a new `https://developer.android.com/reference/java/nio/ByteBuffer.html` whose capacity is sufficient. Data up to the current position is copied to the new buffer.

| Parameters |
|---|---|
| `int length` | The length of the write that must be accommodated, in bytes. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.InsufficientCapacityException` | If there is insufficient capacity to accommodate the write and `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#bufferReplacementMode()` is `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#BUFFER_REPLACEMENT_MODE_DISABLED()`. |

### flip

```
public final void flip()
```

Flips `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` and `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` in preparation for being queued to a decoder.

| See also |
|---|---|
| `https://developer.android.com/reference/java/nio/Buffer.html#flip()` |   |

### isEncrypted

```
public final boolean isEncrypted()
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_ENCRYPTED()` flag is set.

### newNoDataInstance

```
public static DecoderInputBuffer newNoDataInstance()
```

Returns a new instance that's not able to hold any data.

### resetSupplementalData

```
@EnsuresNonNull(value = "supplementalData")
public void resetSupplementalData(int length)
```

Clears `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` and ensures that it's large enough to accommodate `
length` bytes.

| Parameters |
|---|---|
| `int length` | The length of the supplemental data that must be accommodated, in bytes. |