FrameProcessorUtils


@ExperimentalApi
class FrameProcessorUtils


Utility methods for FrameProcessor implementations.

Summary

Nested types

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

Constants

const Int

OpenGL ES 2.0 context created.

const Int

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

Public functions

java-static FrameProcessorUtils.EglImageTextureWrapper!
@RequiresApi(value = 26)
createAndBindEglImage(
    eglDisplay: EGLDisplay!,
    buffer: HardwareBuffer!,
    jniWrapper: HardwareBufferJniWrapper!,
    target: Int,
    writesToBoundImage: Boolean
)

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

java-static Unit
@RequiresApi(value = 26)
releaseEglImageTexture(
    eglImageTextureWrapper: FrameProcessorUtils.EglImageTextureWrapper!,
    jniWrapper: HardwareBufferJniWrapper!
)

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

java-static Unit
releaseOpenGl(glObjectsProvider: GlObjectsProvider!)

Releases the OpenGL resources.

java-static Unit

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

java-static Unit

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

java-static Int
setupOpenGl(glObjectsProvider: GlObjectsProvider!)

Sets up the OpenGL context on the current thread.

java-static Unit

Shuts down the passed in ExecutorService with a timeout.

java-static Unit
submitToGlExecutor(
    operation: Callable<Void!>!,
    glExecutorService: ListeningExecutorService!,
    errorConsumer: Consumer<VideoFrameProcessingException!>!
)

Submits an operation to the passed in ListeningExecutorService.

java-static Boolean

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

java-static Boolean

Awaits the acquire fence on the AsyncFrame.

Constants

OPEN_GL_VERSION_2

const val OPEN_GL_VERSION_2 = 2: Int

OpenGL ES 2.0 context created.

OPEN_GL_VERSION_3

const val OPEN_GL_VERSION_3 = 3: Int

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

Public functions

createAndBindEglImage

@RequiresApi(value = 26)
java-static fun createAndBindEglImage(
    eglDisplay: EGLDisplay!,
    buffer: HardwareBuffer!,
    jniWrapper: HardwareBufferJniWrapper!,
    target: Int,
    writesToBoundImage: Boolean
): FrameProcessorUtils.EglImageTextureWrapper!

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)
java-static fun releaseEglImageTexture(
    eglImageTextureWrapper: FrameProcessorUtils.EglImageTextureWrapper!,
    jniWrapper: HardwareBufferJniWrapper!
): Unit

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

releaseOpenGl

java-static fun releaseOpenGl(glObjectsProvider: GlObjectsProvider!): Unit

Releases the OpenGL resources.

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

runAllAndAccumulateExceptions

java-static fun runAllAndAccumulateExceptions(actions: Array<ThrowingRunnable<*>!>!): Unit

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

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

Parameters
actions: Array<ThrowingRunnable<*>!>!

The throwing actions to execute.

Throws
androidx.media3.common.VideoFrameProcessingException

If any of the actions fail.

runAllAndAccumulateExceptions

java-static fun runAllAndAccumulateExceptions(
    errorConsumer: Consumer<VideoFrameProcessingException!>!,
    actions: Array<ThrowingRunnable<*>!>!
): Unit

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

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

Parameters
errorConsumer: Consumer<VideoFrameProcessingException!>!

The Consumer to which the accumulated VideoFrameProcessingException is routed.

actions: Array<ThrowingRunnable<*>!>!

The throwing actions to execute.

setupOpenGl

java-static fun setupOpenGl(glObjectsProvider: GlObjectsProvider!): Int

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

java-static fun shutdownGlExecutorService(glExecutorService: ExecutorService!): Unit

Shuts down the passed in ExecutorService with a timeout.

submitToGlExecutor

java-static fun submitToGlExecutor(
    operation: Callable<Void!>!,
    glExecutorService: ListeningExecutorService!,
    errorConsumer: Consumer<VideoFrameProcessingException!>!
): Unit

Submits an operation to the passed in ListeningExecutorService.

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

useHighPrecisionColorComponents

java-static fun useHighPrecisionColorComponents(colorInfo: ColorInfo?): Boolean

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

waitAndCloseFence

java-static fun waitAndCloseFence(asyncFrame: AsyncFrame!): Boolean

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