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.

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

Signals that no more frames will be queued.

Public constructors

PacketConsumerHardwareBufferFrameQueue

PacketConsumerHardwareBufferFrameQueue(
    releaseFrameExecutor: Executor!,
    packetRenderer: RenderingPacketConsumer<HardwareBufferFrame!, SurfaceInfo!>!,
    listener: PacketConsumerHardwareBufferFrameQueue.Listener!
)

Creates a new instance.

Parameters
releaseFrameExecutor: Executor!

The executor that frames will be used to release frames back to the pool.

packetRenderer: RenderingPacketConsumer<HardwareBufferFrame!, SurfaceInfo!>!

The downstream RenderingPacketConsumer that will receive the frames.

listener: PacketConsumerHardwareBufferFrameQueue.Listener!

The Listener.

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.

If this method is called multiple times without returning a frame, only the most recent wakeupListener} is guaranteed to be invoked.

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 Frame#release(SyncFenceCompat) 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.

Must be called on the same thread as the releaseFrameExecutor.

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

signalEndOfStream

fun signalEndOfStream(): Unit

Signals that no more frames will be queued.

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