Class NonAllocatingAudioFrameBuffer
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.track.playback.AbstractAudioFrameBuffer
-
- com.sedmelluq.discord.lavaplayer.track.playback.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.
-
-
Field Summary
-
Fields inherited from class com.sedmelluq.discord.lavaplayer.track.playback.AbstractAudioFrameBuffer
clearOnInsert, format, locked, receivedFrames, synchronizer, terminated, terminateOnEmpty
-
-
Constructor Summary
Constructors Constructor Description NonAllocatingAudioFrameBuffer(int bufferDuration, AudioDataFormat format, java.util.concurrent.atomic.AtomicBoolean stopping)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the buffer.voidconsume(AudioFrame frame)Consumes the frame, may blockintgetFullCapacity()java.lang.LonggetLastInputTimecode()intgetRemainingCapacity()AudioFrameprovide()AudioFrameprovide(long timeout, java.util.concurrent.TimeUnit unit)booleanprovide(MutableAudioFrame targetFrame)booleanprovide(MutableAudioFrame targetFrame, long timeout, java.util.concurrent.TimeUnit unit)voidrebuild(AudioFrameRebuilder rebuilder)Rebuild all caches framesprotected voidsignalWaiters()-
Methods inherited from class com.sedmelluq.discord.lavaplayer.track.playback.AbstractAudioFrameBuffer
hasClearOnInsert, hasReceivedFrames, lockBuffer, setClearOnInsert, setTerminateOnEmpty, waitForTermination
-
-
-
-
Constructor Detail
-
NonAllocatingAudioFrameBuffer
public NonAllocatingAudioFrameBuffer(int bufferDuration, AudioDataFormat format, java.util.concurrent.atomic.AtomicBoolean stopping)- Parameters:
bufferDuration- The length of the internal buffer in millisecondsformat- The format of the frames held in this bufferstopping- 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:AudioFrameConsumerConsumes 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:
trueif 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:
trueif 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:AudioFrameBufferClear the buffer.
-
rebuild
public void rebuild(AudioFrameRebuilder rebuilder)
Description copied from interface:AudioFrameConsumerRebuild 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.
-
signalWaiters
protected void signalWaiters()
- Specified by:
signalWaitersin classAbstractAudioFrameBuffer
-
-