PacketConsumerHardwareBufferFrameQueue


@RequiresApi(value = 26)
@ExperimentalApi
public class PacketConsumerHardwareBufferFrameQueue implements HardwareBufferFrameQueue


An implementation of HardwareBufferFrameQueue that manages a fixed-capacity pool of HardwareBuffers, that are forwarded to a downstream PacketConsumer.

This class maintains an internal pool (default capacity of 5) of buffers.

Thread Safety: This class is not thread-safe.

Summary

Public constructors

Creates a new instance.

Public methods

@Nullable HardwareBufferFrame
dequeue(
    HardwareBufferFrameQueue.FrameFormat format,
    Runnable wakeupListener
)

Attempts to dequeue a matching the specified format}.

void

Queues a for consumption by the downstream component.

void

Releases the queue and the downstream caller.

void

Sets the downstream PacketConsumer that will receive the frames.

void

Signals that no more frames will be queued.

Public constructors

PacketConsumerHardwareBufferFrameQueue

public PacketConsumerHardwareBufferFrameQueue(
    Consumer<Exception> errorConsumer
)

Creates a new instance.

Parameters
Consumer<Exception> errorConsumer

A consumer for reporting asynchronous errors.

Public methods

dequeue

public @Nullable HardwareBufferFrame dequeue(
    HardwareBufferFrameQueue.FrameFormat format,
    Runnable wakeupListener
)

Attempts to dequeue a matching the specified format}.

If the queue has reached its capacity and no buffers are available for reuse, this method returns null}. In this case, the wakeupListener} will be invoked when a buffer is eventually returned to the pool.

Returns a buffer from the pool if one exists with matching FrameFormat. If the pool is empty but capacity is available, a new buffer is created. If the queue is at capacity, returns null and the most recent wakeupListener will be notified when capacity is available.

queue

public void queue(HardwareBufferFrame frame)

Queues a for consumption by the downstream component.

Implementations may override HardwareBufferFrame#release() of the queued frame.

The implementation is responsible for ensuring the buffer is correctly reused or released once the downstream component has finished processing it.

Overrides the callback called in release to return the queued frame to the internal pool.

Parameters
HardwareBufferFrame frame

The frame to be queued.

release

public void release()

Releases the queue and the downstream caller.

This should be called when the pipeline is being shut down to ensure all asynchronous resources are cleaned up.

setOutput

public void setOutput(PacketConsumer<HardwareBufferFrame> output)

Sets the downstream PacketConsumer that will receive the frames.

This method must be called before calling queue.

Parameters
PacketConsumer<HardwareBufferFrame> output

The downstream consumer.

Throws
java.lang.IllegalStateException

If an output has already been set.

signalEndOfStream

public void signalEndOfStream()

Signals that no more frames will be queued.

This propagates an end-of-stream signal to the downstream consumer.