Package com.castlabs.sdk.base.subtitles.buffer

# Class DecoderInputBuffer

java.lang.Object
com.castlabs.sdk.base.subtitles.buffer.Buffer
com.castlabs.sdk.base.subtitles.buffer.DecoderInputBuffer

Direct Known Subclasses:
  `BaseSubtitleInputBuffer`

public class DecoderInputBuffer extends Buffer
Holds input for a decoder.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static @interface`
  `DecoderInputBuffer.BufferReplacementMode`
  The buffer replacement mode, which may disable replacement.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `BUFFER_REPLACEMENT_MODE_DIRECT`
  Allows buffer replacement using `ByteBuffer.allocateDirect(int)`.
  `static final int`
  `BUFFER_REPLACEMENT_MODE_DISABLED`
  Disallows buffer replacement.
  `static final int`
  `BUFFER_REPLACEMENT_MODE_NORMAL`
  Allows buffer replacement using `ByteBuffer.allocate(int)`.
  `static final int`
  `BUFFER_REPLACEMENT_MODE_SHARED`
  Allows buffer replacement using Android Shared Memory.
  `CryptoInfo`
  `cryptoInfo`
  `CryptoInfo` for encrypted data.
  `ByteBuffer`
  `data`
  The buffer's data, or `null` if no data has been set.
  `SharedMemory`
  `shmemRegion`
  `int[]`
  `subsamples`
  Subsamples contained in the buffer.
  `ByteBuffer`
  `supplementalData`
  Supplemental data related to the buffer, if `Buffer.hasSupplementalData()` returns true.
  `long`
  `timeUs`
  The time at which the sample should be presented.
  `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.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DecoderInputBuffer(int bufferReplacementMode)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Clears the buffer.
  `void`
  `ensureSpaceForWrite(int length)`
  Ensures that `data` is large enough to accommodate a write of a given length at its current position.
  `final void`
  `flip()`
  Flips `data` and `supplementalData` in preparation for being queued to a decoder.
  `final boolean`
  `isEncrypted()`
  Returns whether the `Constants.BUFFER_FLAG_ENCRYPTED` flag is set.
  `final boolean`
  `isFlagsOnly()`
  Returns whether the buffer is only able to hold flags, meaning `data` is null and its replacement mode is `BUFFER_REPLACEMENT_MODE_DISABLED`.
  `final boolean`
  `isSharedMemoryBuffer()`
  `static DecoderInputBuffer`
  `newFlagsOnlyInstance()`
  Creates a new instance for which `isFlagsOnly()` will return true.
  `static DecoderInputBuffer`
  `newSharedMemoryInstance(String debugName, int regionSize)`
  Creates a new instance for which `isSharedMemoryBuffer()` will return true.
  `void`
  `releaseSharedMemoryBuffer()`
  `void`
  `resetSupplementalData(int length)`
  Clears `supplementalData` and ensures that it's large enough to accommodate `length` bytes.
  `void`
  `unmapByteBuffer()`

  ### Methods inherited from class com.castlabs.sdk.base.subtitles.buffer.Buffer

  `addFlag, clearFlag, getFlag, hasSupplementalData, isDecodeOnly, isEndOfStream, isKeyFrame, setFlags`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### BUFFER_REPLACEMENT_MODE_DISABLED

    public static final int BUFFER_REPLACEMENT_MODE_DISABLED
    Disallows buffer replacement.
    See Also:
      - Constant Field Values

  - ### BUFFER_REPLACEMENT_MODE_NORMAL

    public static final int BUFFER_REPLACEMENT_MODE_NORMAL
    Allows buffer replacement using `ByteBuffer.allocate(int)`.
    See Also:
      - Constant Field Values

  - ### BUFFER_REPLACEMENT_MODE_DIRECT

    public static final int BUFFER_REPLACEMENT_MODE_DIRECT
    Allows buffer replacement using `ByteBuffer.allocateDirect(int)`.
    See Also:
      - Constant Field Values

  - ### BUFFER_REPLACEMENT_MODE_SHARED

    public static final int BUFFER_REPLACEMENT_MODE_SHARED
    Allows buffer replacement using Android Shared Memory.
    See Also:
      - Constant Field Values

  - ### cryptoInfo

    public CryptoInfo cryptoInfo
    `CryptoInfo` for encrypted data.

  - ### shmemRegion

    @Nullable public SharedMemory shmemRegion

  - ### data

    @Nullable public ByteBuffer data
    The buffer's data, or `null` if no data has been set.

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

  - ### timeUs

    public long timeUs
    The time at which the sample should be presented.

  - ### subsamples

    @Nullable public int[] subsamples
    Subsamples contained in the buffer. This corresponds to the 'subs' MP4 box. May be null if such box was not present in the sample.

  - ### supplementalData

    @Nullable public ByteBuffer supplementalData
    Supplemental data related to the buffer, if `Buffer.hasSupplementalData()` returns true. If present, the buffer is populated with supplemental data from position 0 to its limit.

- ## Constructor Details

  - ### DecoderInputBuffer

    public DecoderInputBuffer(@BufferReplacementMode int bufferReplacementMode)
    Parameters:
      `bufferReplacementMode` - Determines the behavior of `ensureSpaceForWrite(int)`. One of `BUFFER_REPLACEMENT_MODE_DISABLED`, `BUFFER_REPLACEMENT_MODE_NORMAL` and `BUFFER_REPLACEMENT_MODE_DIRECT`.

- ## Method Details

  - ### newFlagsOnlyInstance

    public static DecoderInputBuffer newFlagsOnlyInstance()
    Creates a new instance for which `isFlagsOnly()` will return true.
    Returns:
      A new flags only input buffer.

  - ### newSharedMemoryInstance

    public static DecoderInputBuffer newSharedMemoryInstance(String debugName, int regionSize)
    Creates a new instance for which `isSharedMemoryBuffer()` will return true.
    Parameters:
      `debugName` - The debug name on the Android system of this piece of shared memory that is allocated.
      `regionSize` - Size of the Shared memory region to be allocated in bytes.
    Returns:
      A new shared memory based input buffer.

  - ### resetSupplementalData

    @EnsuresNonNull("supplementalData") public void resetSupplementalData(int length)
    Clears `supplementalData` and ensures that it's large enough to accommodate `length` bytes.
    Parameters:
      `length` - The length of the supplemental data that must be accommodated, in bytes.

  - ### ensureSpaceForWrite

    @EnsuresNonNull("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:
      `length` - The length of the write that must be accommodated, in bytes.
    Throws:
      `IllegalStateException` - If there is insufficient capacity to accommodate the write and the buffer replacement mode of the holder is `BUFFER_REPLACEMENT_MODE_DISABLED`.

  - ### isFlagsOnly

    public final boolean isFlagsOnly()
    Returns whether the buffer is only able to hold flags, meaning `data` is null and its replacement mode is `BUFFER_REPLACEMENT_MODE_DISABLED`.

  - ### isSharedMemoryBuffer

    public final boolean isSharedMemoryBuffer()

  - ### isEncrypted

    public final boolean isEncrypted()
    Returns whether the `Constants.BUFFER_FLAG_ENCRYPTED` flag is set.

  - ### flip

    public final void flip()
    Flips `data` and `supplementalData` in preparation for being queued to a decoder.
    See Also:
      - `Buffer.flip()`

  - ### clear

    public void clear()
    Description copied from class: `Buffer`
    Clears the buffer.
    Overrides:
      `clear` in class `Buffer`

  - ### unmapByteBuffer

    public void unmapByteBuffer()

  - ### releaseSharedMemoryBuffer

    public void releaseSharedMemoryBuffer()