SurfaceHolderHardwareBufferFrameQueue


@RequiresApi(value = 33)
@ExperimentalApi
public final class SurfaceHolderHardwareBufferFrameQueue implements HardwareBufferFrameQueue, SurfaceHolder.Callback


A HardwareBufferFrameQueue that outputs frames to a SurfaceHolder.

Summary

Nested types

A listener for SurfaceHolderHardwareBufferFrameQueue events.

Public constructors

SurfaceHolderHardwareBufferFrameQueue(
    SurfaceHolder surfaceHolder,
    Executor surfaceHolderExecutor,
    SurfaceHolderHardwareBufferFrameQueue.Listener listener,
    Executor listenerExecutor
)

Creates a new instance.

Public methods

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

Attempts to dequeue a HardwareBufferFrame matching the specified format.

void

Queues a HardwareBufferFrame for consumption by the downstream component.

void

Releases the queue.

void

Signals that no more frames will be queued.

void
surfaceChanged(SurfaceHolder holder, int format, int width, int height)
void
void

Public constructors

SurfaceHolderHardwareBufferFrameQueue

public SurfaceHolderHardwareBufferFrameQueue(
    SurfaceHolder surfaceHolder,
    Executor surfaceHolderExecutor,
    SurfaceHolderHardwareBufferFrameQueue.Listener listener,
    Executor listenerExecutor
)

Creates a new instance.

Parameters
SurfaceHolder surfaceHolder

The SurfaceHolder to which frames will be written.

Executor surfaceHolderExecutor

The Executor on which the surface holder methods will be called.

SurfaceHolderHardwareBufferFrameQueue.Listener listener

The Listener.

Executor listenerExecutor

The Executor on which the listener methods will be called.

Public methods

dequeue

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

Attempts to dequeue a HardwareBufferFrame 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.

Parameters
HardwareBufferFrameQueue.FrameFormat format

The required format for the dequeued buffer.

Runnable wakeupListener

A callback to notify the caller when a buffer becomes available.

Returns
@Nullable HardwareBufferFrame

A HardwareBufferFrame, or null if the queue is currently full.

queue

public void queue(HardwareBufferFrame frame)

Queues a HardwareBufferFrame for consumption by the downstream component.

Implementations may override 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.

Parameters
HardwareBufferFrame frame

The frame to be processed.

release

public void release()

Releases the queue.

This method should be called when the queue is no longer needed to unregister callbacks and release resources.

signalEndOfStream

public void signalEndOfStream()

Signals that no more frames will be queued.

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

surfaceChanged

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)

surfaceCreated

public void surfaceCreated(SurfaceHolder holder)

surfaceDestroyed

public void surfaceDestroyed(SurfaceHolder holder)