Class NonAllocatingAudioFrameBuffer

  • All Implemented Interfaces:
    AudioFrameBuffer, AudioFrameConsumer, AudioFrameProvider

    public class NonAllocatingAudioFrameBuffer
    extends AbstractAudioFrameBuffer
    Audio frame buffer implementation which never allocates any new objects after creation. All instances of mutable frames are preallocated, and for the data there is one byte buffer which is used as a ring buffer for the frame data.
    • Constructor Detail

      • NonAllocatingAudioFrameBuffer

        public NonAllocatingAudioFrameBuffer​(int bufferDuration,
                                             AudioDataFormat format,
                                             java.util.concurrent.atomic.AtomicBoolean stopping)
        Parameters:
        bufferDuration - The length of the internal buffer in milliseconds
        format - The format of the frames held in this buffer
        stopping - Atomic boolean which has true value when the track is in a state of pending stop.
    • Method Detail

      • getRemainingCapacity

        public int getRemainingCapacity()
        Returns:
        Number of frames that can be added to the buffer without blocking.
      • getFullCapacity

        public int getFullCapacity()
        Returns:
        Total number of frames that the buffer can hold.
      • consume

        public void consume​(AudioFrame frame)
                     throws java.lang.InterruptedException
        Description copied from interface: AudioFrameConsumer
        Consumes the frame, may block
        Parameters:
        frame - The frame to consume
        Throws:
        java.lang.InterruptedException - When interrupted externally (or for seek/stop).
      • provide

        public AudioFrame provide()
        Returns:
        Provided frame, or null if none available
      • provide

        public AudioFrame provide​(long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.util.concurrent.TimeoutException,
                                  java.lang.InterruptedException
        Parameters:
        timeout - Specifies the maximum time to wait for data. Pass 0 for non-blocking mode.
        unit - Specifies the time unit of the maximum wait time.
        Returns:
        Provided frame. In case wait time is above zero, null indicates that no data is not available at the current moment, otherwise null means the end of the track.
        Throws:
        java.util.concurrent.TimeoutException - When wait time is above zero, but no track info is found in that time.
        java.lang.InterruptedException - When interrupted externally (or for seek/stop).
      • provide

        public boolean provide​(MutableAudioFrame targetFrame)
        Parameters:
        targetFrame - Frame to update with the details and data of the provided frame.
        Returns:
        true if a frame was provided.
      • provide

        public boolean provide​(MutableAudioFrame targetFrame,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.util.concurrent.TimeoutException,
                               java.lang.InterruptedException
        Parameters:
        targetFrame - Frame to update with the details and data of the provided frame.
        timeout - Timeout.
        unit - Time unit for the timeout value.
        Returns:
        true if a frame was provided.
        Throws:
        java.util.concurrent.TimeoutException - If no frame became available within the timeout.
        java.lang.InterruptedException - When interrupted externally (or for seek/stop).
      • clear

        public void clear()
        Description copied from interface: AudioFrameBuffer
        Clear the buffer.
      • rebuild

        public void rebuild​(AudioFrameRebuilder rebuilder)
        Description copied from interface: AudioFrameConsumer
        Rebuild all caches frames
        Parameters:
        rebuilder - The rebuilder to use
      • getLastInputTimecode

        public java.lang.Long getLastInputTimecode()
        Returns:
        The timecode of the last frame in the buffer, null if the buffer is empty or is marked to be cleared upon receiving the next frame.