BitmapToHardwareBufferProcessor


@RequiresApi(value = 26)
@ExperimentalApi
public class BitmapToHardwareBufferProcessor implements AutoCloseable


A HardwareBufferFrameProcessor that converts Bitmap-backed HardwareBufferFrame instances into android.hardware.HardwareBuffer-backed ones.

This processor caches the underlying android.hardware.HardwareBuffer as long as the input Bitmap remains the same (verified via getGenerationId). It uses JNI to copy pixels from the bitmap to the hardware buffer.

The processor manages the lifecycle of the hardware buffer using reference counting, ensuring it is only closed once all consumer frames and the processor itself have released their references.

Summary

Public constructors

BitmapToHardwareBufferProcessor(
    HardwareBufferJniWrapper hardwareBufferJniWrapper,
    ExecutorService internalExecutor,
    Executor errorExecutor,
    Consumer<VideoFrameProcessingException> errorCallback
)

Creates an instance.

Public methods

void
HardwareBufferFrame

Converts the inputFrame to a new HardwareBufferFrame.

Public constructors

BitmapToHardwareBufferProcessor

public BitmapToHardwareBufferProcessor(
    HardwareBufferJniWrapper hardwareBufferJniWrapper,
    ExecutorService internalExecutor,
    Executor errorExecutor,
    Consumer<VideoFrameProcessingException> errorCallback
)

Creates an instance.

Parameters
HardwareBufferJniWrapper hardwareBufferJniWrapper

The HardwareBufferJniWrapper that supplies the native helpers needed by this class.

ExecutorService internalExecutor

The ExecutorService that waits for the release fence to signal before closing created HardwareBuffers. Will be shutdown when this class is closed.

Executor errorExecutor

The Executor on which the errorCallback will be called.

Consumer<VideoFrameProcessingException> errorCallback

The Consumer called when waiting or closing the created HardwareBuffers fails.

Public methods

close

public void close()

process

public HardwareBufferFrame process(HardwareBufferFrame inputFrame)

Converts the inputFrame to a new HardwareBufferFrame.

The implementation may return the inputFrame itself if no conversion is needed, or a new frame backed by a android.hardware.HardwareBuffer.

Parameters
HardwareBufferFrame inputFrame

The input HardwareBufferFrame.

Returns
HardwareBufferFrame

The processed HardwareBufferFrame.