PacketConsumerHardwareBufferFrameQueue


@RequiresApi(value = 26)
@ExperimentalApi
class PacketConsumerHardwareBufferFrameQueue : 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 functions

HardwareBufferFrame?
dequeue(
    format: HardwareBufferFrameQueue.FrameFormat!,
    wakeupListener: Runnable!
)

Attempts to dequeue a matching the specified format}.

Unit

Queues a for consumption by the downstream component.

Unit

Releases the queue and the downstream caller.

Unit

Sets the downstream PacketConsumer that will receive the frames.

Unit

Signals that no more frames will be queued.

Public constructors

PacketConsumerHardwareBufferFrameQueue

PacketConsumerHardwareBufferFrameQueue(
    errorConsumer: Consumer<Exception!>!
)

Creates a new instance.

Parameters
errorConsumer: Consumer<Exception!>!

A consumer for reporting asynchronous errors.

Public functions

dequeue

fun dequeue(
    format: HardwareBufferFrameQueue.FrameFormat!,
    wakeupListener: Runnable!
): HardwareBufferFrame?

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

fun queue(frame: HardwareBufferFrame!): Unit

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
frame: HardwareBufferFrame!

The frame to be queued.

release

fun release(): Unit

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

fun setOutput(output: PacketConsumer<HardwareBufferFrame!>!): Unit

Sets the downstream PacketConsumer that will receive the frames.

This method must be called before calling queue.

Parameters
output: PacketConsumer<HardwareBufferFrame!>!

The downstream consumer.

Throws
java.lang.IllegalStateException

If an output has already been set.

signalEndOfStream

fun signalEndOfStream(): Unit

Signals that no more frames will be queued.

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