DecoderInputBuffer


@UnstableApi
public class DecoderInputBuffer extends Buffer


Holds input for a decoder.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation DecoderInputBuffer.BufferReplacementMode

The buffer replacement mode.

Thrown when an attempt is made to write into a DecoderInputBuffer whose bufferReplacementMode is BUFFER_REPLACEMENT_MODE_DISABLED and who data capacity is smaller than required.

Constants

static final int

Allows buffer replacement using allocateDirect.

static final int

Disallows buffer replacement.

static final int

Allows buffer replacement using allocate.

Public fields

final CryptoInfo

CryptoInfo for encrypted data.

@Nullable ByteBuffer

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

@Nullable Format

The Format.

@Nullable ByteBuffer

Supplemental data related to the buffer, if hasSupplementalData returns true.

long

The time at which the sample should be presented.

boolean

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

Creates a new instance.

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

Creates a new instance.

Public methods

void

Clears the buffer.

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

Ensures that data is large enough to accommodate a write of a given length at its current position.

final void

Flips data and supplementalData in preparation for being queued to a decoder.

final boolean

Returns whether the BUFFER_FLAG_ENCRYPTED flag is set.

static DecoderInputBuffer

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

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

Clears supplementalData and ensures that it's large enough to accommodate length bytes.

Inherited methods

From androidx.media3.decoder.Buffer
final void

Adds the flag to this buffer's flags.

final void

Removes the flag from this buffer's flags, if it is set.

final boolean

Returns whether the specified flag has been set on this buffer.

final boolean

Returns whether the BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA flag is set.

final boolean

Returns whether the BUFFER_FLAG_END_OF_STREAM flag is set.

final boolean

Returns whether the BUFFER_FLAG_FIRST_SAMPLE flag is set.

final boolean

Returns whether the BUFFER_FLAG_KEY_FRAME flag is set.

final boolean

Returns whether the BUFFER_FLAG_LAST_SAMPLE flag is set.

final boolean

Returns whether the BUFFER_FLAG_NOT_DEPENDED_ON flag is set.

final void
setFlags(@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 allocateDirect.

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 allocate.

Public fields

cryptoInfo

public final CryptoInfo cryptoInfo

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 Format.

supplementalData

public @Nullable ByteBuffer supplementalData

Supplemental data related to the buffer, if 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
@DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode

The BufferReplacementMode replacement mode.

DecoderInputBuffer

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

Creates a new instance.

Parameters
@DecoderInputBuffer.BufferReplacementMode int bufferReplacementMode

The BufferReplacementMode replacement mode.

int paddingSize

If non-zero, ensureSpaceForWrite 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 data is large enough to accommodate a write of a given length at its current position.

If the capacity of data is sufficient this method does nothing. If the capacity is insufficient then an attempt is made to replace data with a new ByteBuffer 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.

flip

public final void flip()

Flips data and supplementalData in preparation for being queued to a decoder.

See also
flip

isEncrypted

public final boolean isEncrypted()

Returns whether the 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 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.