FrameProcessorUtils


@ExperimentalApi
public final class FrameProcessorUtils


Utility methods for FrameProcessor implementations.

Summary

Nested types

Data class holding handles to EglImage, texture ID and frame buffer object ID.

Constants

static final int

OpenGL ES 2.0 context created.

static final int

10-bit HDR-capable OpenGL ES 3.0 context created.

Public methods

static FrameProcessorUtils.EglImageTextureWrapper
@RequiresApi(value = 26)
createAndBindEglImage(
    EGLDisplay eglDisplay,
    HardwareBuffer buffer,
    HardwareBufferJniWrapper jniWrapper,
    int target,
    boolean writesToBoundImage
)

Creates an EGL image from a HardwareBuffer and binds it to a newly generated texture.

static void
@RequiresApi(value = 26)
releaseEglImageTexture(
    FrameProcessorUtils.EglImageTextureWrapper eglImageTextureWrapper,
    HardwareBufferJniWrapper jniWrapper
)

Releases the EGL image, focused frame buffer object, and texture.

static void
releaseOpenGl(GlObjectsProvider glObjectsProvider)

Releases the OpenGL resources.

static void
runAllAndAccumulateExceptions(ThrowingRunnable[] actions)

Executes multiple throwing actions sequentially, ensuring all are run even if some fail.

static void
runAllAndAccumulateExceptions(
    Consumer<VideoFrameProcessingException> errorConsumer,
    ThrowingRunnable[] actions
)

Executes multiple throwing actions sequentially, ensuring all are run even if some fail.

static int
setupOpenGl(GlObjectsProvider glObjectsProvider)

Sets up the OpenGL context on the current thread.

static void

Shuts down the passed in ExecutorService with a timeout.

static void
submitToGlExecutor(
    Callable<Void> operation,
    ListeningExecutorService glExecutorService,
    Consumer<VideoFrameProcessingException> errorConsumer
)

Submits an operation to the passed in ListeningExecutorService.

static boolean

Returns whether the color space requires high precision (16-bit floating-point) color components.

static boolean

Awaits the acquire fence on the AsyncFrame.

Constants

OPEN_GL_VERSION_2

public static final int OPEN_GL_VERSION_2 = 2

OpenGL ES 2.0 context created.

OPEN_GL_VERSION_3

public static final int OPEN_GL_VERSION_3 = 3

10-bit HDR-capable OpenGL ES 3.0 context created.

Public methods

createAndBindEglImage

@RequiresApi(value = 26)
public static FrameProcessorUtils.EglImageTextureWrapper createAndBindEglImage(
    EGLDisplay eglDisplay,
    HardwareBuffer buffer,
    HardwareBufferJniWrapper jniWrapper,
    int target,
    boolean writesToBoundImage
)

Creates an EGL image from a HardwareBuffer and binds it to a newly generated texture.

This method should only be called on the thread that owns the OpenGL context.

releaseEglImageTexture

@RequiresApi(value = 26)
public static void releaseEglImageTexture(
    FrameProcessorUtils.EglImageTextureWrapper eglImageTextureWrapper,
    HardwareBufferJniWrapper jniWrapper
)

Releases the EGL image, focused frame buffer object, and texture.

releaseOpenGl

public static void releaseOpenGl(GlObjectsProvider glObjectsProvider)

Releases the OpenGL resources.

This method must run on the thread that owns the OpenGL context.

runAllAndAccumulateExceptions

public static void runAllAndAccumulateExceptions(ThrowingRunnable[] actions)

Executes multiple throwing actions sequentially, ensuring all are run even if some fail.

If multiple exceptions are thrown, they are accumulated using addSuppressed.

Parameters
ThrowingRunnable[] actions

The throwing actions to execute.

Throws
androidx.media3.common.VideoFrameProcessingException

If any of the actions fail.

runAllAndAccumulateExceptions

public static void runAllAndAccumulateExceptions(
    Consumer<VideoFrameProcessingException> errorConsumer,
    ThrowingRunnable[] actions
)

Executes multiple throwing actions sequentially, ensuring all are run even if some fail.

If multiple exceptions are thrown, they are accumulated using addSuppressed.

Parameters
Consumer<VideoFrameProcessingException> errorConsumer

The Consumer to which the accumulated VideoFrameProcessingException is routed.

ThrowingRunnable[] actions

The throwing actions to execute.

setupOpenGl

public static int setupOpenGl(GlObjectsProvider glObjectsProvider)

Sets up the OpenGL context on the current thread.

Attempts to create an OpenGL ES 3.0 context with 10-bit HDR configuration (EGL_CONFIG_ATTRIBUTES_RGBA_1010102) if surfaceless contexts are supported. This allows the pipeline to handle SDR and HDR contents without recreating the context.

Falls back to OpenGL ES 2.0 with EGL_CONFIG_ATTRIBUTES_RGBA_8888 if surfaceless contexts are unsupported (e.g., on emulators) or if ES 3.0 context creation fails.

Parameters
GlObjectsProvider glObjectsProvider

The GlObjectsProvider.

Returns
int

The created OpenGL version (OPEN_GL_VERSION_3 or OPEN_GL_VERSION_2).

shutdownGlExecutorService

public static void shutdownGlExecutorService(ExecutorService glExecutorService)

Shuts down the passed in ExecutorService with a timeout.

submitToGlExecutor

public static void submitToGlExecutor(
    Callable<Void> operation,
    ListeningExecutorService glExecutorService,
    Consumer<VideoFrameProcessingException> errorConsumer
)

Submits an operation to the passed in ListeningExecutorService.

The passed in errorConsumer will be invoked if the operation fails.

useHighPrecisionColorComponents

public static boolean useHighPrecisionColorComponents(@Nullable ColorInfo colorInfo)

Returns whether the color space requires high precision (16-bit floating-point) color components.

waitAndCloseFence

public static boolean waitAndCloseFence(AsyncFrame asyncFrame)

Awaits the acquire fence on the AsyncFrame. Returns true if the fence was signaled before the timeout, false otherwise.