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.

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

Signals that no more frames will be queued.

Public constructors

PacketConsumerHardwareBufferFrameQueue

public PacketConsumerHardwareBufferFrameQueue(
    Executor releaseFrameExecutor,
    RenderingPacketConsumer<HardwareBufferFrameSurfaceInfo> packetRenderer,
    PacketConsumerHardwareBufferFrameQueue.Listener listener
)

Creates a new instance.

Parameters
Executor releaseFrameExecutor

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

RenderingPacketConsumer<HardwareBufferFrameSurfaceInfo> packetRenderer

The downstream RenderingPacketConsumer that will receive the frames.

PacketConsumerHardwareBufferFrameQueue.Listener listener

The Listener.

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.

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

public void queue(HardwareBufferFrame frame)

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

The frame to be queued.

release

public void release()

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

public void signalEndOfStream()

Signals that no more frames will be queued.

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