# FrameProcessorUtils

Artifact: [androidx.media3:media3-effect](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/effect/FrameProcessorUtils.java+class:androidx.media3.effect.FrameProcessorUtils)

*** ** * ** ***


```
@ExperimentalApi
public final class FrameProcessorUtils
```

<br />

*** ** * ** ***

Utility methods for FrameProcessor implementations.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils.EglImageTextureWrapper` Data class holding handles to `EglImage`, texture ID and frame buffer object ID. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#OPEN_GL_VERSION_2() = 2` OpenGL ES 2.0 context created. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#OPEN_GL_VERSION_3() = 3` 10-bit HDR-capable OpenGL ES 3.0 context created. |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils.EglImageTextureWrapper` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#createAndBindEglImage(android.opengl.EGLDisplay,android.hardware.HardwareBuffer,androidx.media3.effect.HardwareBufferJniWrapper,int,boolean)( https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, https://developer.android.com/reference/android/hardware/HardwareBuffer.html buffer, https://developer.android.com/reference/androidx/media3/effect/HardwareBufferJniWrapper jniWrapper, int target, boolean writesToBoundImage )` Creates an EGL image from a `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` and binds it to a newly generated texture. |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#releaseEglImageTexture(androidx.media3.effect.FrameProcessorUtils.EglImageTextureWrapper,androidx.media3.effect.HardwareBufferJniWrapper)( https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils.EglImageTextureWrapper eglImageTextureWrapper, https://developer.android.com/reference/androidx/media3/effect/HardwareBufferJniWrapper jniWrapper )` Releases the EGL image, focused frame buffer object, and texture. |
| `static void` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#releaseOpenGl(androidx.media3.common.GlObjectsProvider)(https://developer.android.com/reference/androidx/media3/common/GlObjectsProvider glObjectsProvider)` Releases the OpenGL resources. |
| `static void` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#runAllAndAccumulateExceptions(androidx.media3.common.util.ThrowingRunnable<?>...)(ThrowingRunnable[] actions)` Executes multiple throwing actions sequentially, ensuring all are run even if some fail. |
| `static void` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#runAllAndAccumulateExceptions(java.util.function.Consumer<androidx.media3.common.VideoFrameProcessingException>,androidx.media3.common.util.ThrowingRunnable<?>...)( https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException> errorConsumer, ThrowingRunnable[] actions )` Executes multiple throwing actions sequentially, ensuring all are run even if some fail. |
| `static int` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#setupOpenGl(androidx.media3.common.GlObjectsProvider)(https://developer.android.com/reference/androidx/media3/common/GlObjectsProvider glObjectsProvider)` Sets up the OpenGL context on the current thread. |
| `static void` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#shutdownGlExecutorService(java.util.concurrent.ExecutorService)(https://developer.android.com/reference/java/util/concurrent/ExecutorService.html glExecutorService)` Shuts down the passed in `https://developer.android.com/reference/java/util/concurrent/ExecutorService.html` with a timeout. |
| `static void` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#submitToGlExecutor(java.util.concurrent.Callable<java.lang.Void>,com.google.common.util.concurrent.ListeningExecutorService,java.util.function.Consumer<androidx.media3.common.VideoFrameProcessingException>)( https://developer.android.com/reference/java/util/concurrent/Callable.html<https://developer.android.com/reference/java/lang/Void.html> operation, https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListeningExecutorService.html glExecutorService, https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException> errorConsumer )` Submits an `https://developer.android.com/reference/java/util/concurrent/Callable.html` to the passed in `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListeningExecutorService.html`. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#useHighPrecisionColorComponents(androidx.media3.common.ColorInfo)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/ColorInfo colorInfo)` Returns whether the color space requires high precision (16-bit floating-point) color components. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#waitAndCloseFence(androidx.media3.common.video.AsyncFrame)(https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame asyncFrame)` Awaits the acquire fence on the `https://developer.android.com/reference/androidx/media3/common/video/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 `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` and binds it to a newly generated texture.

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

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### releaseEglImageTexture

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

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

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### releaseOpenGl

```
public static void releaseOpenGl(GlObjectsProvider glObjectsProvider)
```

Releases the OpenGL resources.

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

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### 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 `https://developer.android.com/reference/java/lang/Throwable.html#addSuppressed(java.lang.Throwable)`.

| Parameters |
|---|---|
| `ThrowingRunnable[] actions` | The throwing actions to execute. |

| Throws |
|---|---|
| `https://developer.android.com/reference/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 `https://developer.android.com/reference/java/lang/Throwable.html#addSuppressed(java.lang.Throwable)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException> errorConsumer` | The `https://developer.android.com/reference/java/util/function/Consumer.html` to which the accumulated `https://developer.android.com/reference/androidx/media3/common/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 (`https://developer.android.com/reference/androidx/media3/common/util/GlUtil#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 `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_8888()` if surfaceless contexts are unsupported (e.g., on emulators) or if ES 3.0 context creation fails.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/GlObjectsProvider glObjectsProvider` | The `https://developer.android.com/reference/androidx/media3/common/GlObjectsProvider`. |

| Returns |
|---|---|
| `int` | The created OpenGL version (`https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#OPEN_GL_VERSION_3()` or `https://developer.android.com/reference/androidx/media3/effect/FrameProcessorUtils#OPEN_GL_VERSION_2()`). |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### shutdownGlExecutorService

```
public static void shutdownGlExecutorService(ExecutorService glExecutorService)
```

Shuts down the passed in `https://developer.android.com/reference/java/util/concurrent/ExecutorService.html` with a timeout.

### submitToGlExecutor

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

Submits an `https://developer.android.com/reference/java/util/concurrent/Callable.html` to the passed in `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListeningExecutorService.html`.

The passed in `https://developer.android.com/reference/java/util/function/Consumer.html` 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 `https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame`. Returns `true` if the fence was signaled before the timeout, `false` otherwise.