# GlShaderProgram

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/GlShaderProgram.java+class:androidx.media3.effect.GlShaderProgram)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/media3/effect/GlShaderProgram "View this page in Java")


```
@UnstableApi
interface GlShaderProgram
```

<br />

Known direct subclasses [BaseGlShaderProgram](https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram), [DebugViewShaderProgram](https://developer.android.com/reference/kotlin/androidx/media3/effect/DebugViewShaderProgram), [PassthroughShaderProgram](https://developer.android.com/reference/kotlin/androidx/media3/effect/PassthroughShaderProgram), [SeparableConvolutionShaderProgram](https://developer.android.com/reference/kotlin/androidx/media3/effect/SeparableConvolutionShaderProgram), [TimestampAdjustmentShaderProgram](https://developer.android.com/reference/kotlin/androidx/media3/effect/TimestampAdjustmentShaderProgram)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram` | A base implementation of `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/DebugViewShaderProgram` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram` that renders to a `https://developer.android.com/reference/android/view/SurfaceView.html` provided by `https://developer.android.com/reference/kotlin/androidx/media3/common/DebugViewProvider`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/PassthroughShaderProgram` | A `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram` that passes a frame from the input to the output listener without copying. |
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/SeparableConvolutionShaderProgram` | A `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram` for performing separable convolutions. |
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/TimestampAdjustmentShaderProgram` | **This class is deprecated.** Use `EditedMediaItem.Builder#setSpeed(SpeedProvider)` instead. <br /> |

*** ** * ** ***

Processes frames from one OpenGL 2D texture to another.

The `GlShaderProgram` consumes input frames it accepts via `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#queueInputFrame(androidx.media3.common.GlObjectsProvider,androidx.media3.common.GlTextureInfo,long)` and surrenders each texture back to the caller via its `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onInputFrameProcessed(androidx.media3.common.GlTextureInfo)` once the texture's contents have been processed.

The `GlShaderProgram` produces output frames asynchronously and notifies its owner when they are available via its `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener#onOutputFrameAvailable(androidx.media3.common.GlTextureInfo,long)`. The `GlShaderProgram` instance's owner must surrender the texture back to the `GlShaderProgram` via `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#releaseOutputFrame(androidx.media3.common.GlTextureInfo)` when it has finished processing it.

`GlShaderProgram` implementations can choose to produce output frames before receiving input frames or process several input frames before producing an output frame. However, `
GlShaderProgram` implementations cannot assume that they will receive more than one input frame at a time, so they must process each input frame they accept even if they cannot produce output yet.

The methods in this interface must be called on the thread that owns the parent OpenGL context. If the implementation uses another OpenGL context, e.g., on another thread, it must configure it to share data with the context of thread the interface methods are called on.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener` Listener for video frame processing errors. |
| `interface https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener` Listener for input-related video frame processing events. |
| `interface https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener` Listener for output-related video frame processing events. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#flush()()` Flushes the `GlShaderProgram`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#queueInputFrame(androidx.media3.common.GlObjectsProvider,androidx.media3.common.GlTextureInfo,long)( glObjectsProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider!, inputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Processes an input frame if possible. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#release()()` Releases all resources. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#releaseOutputFrame(androidx.media3.common.GlTextureInfo)(outputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!)` Notifies the `GlShaderProgram` that the frame on the given output texture is no longer used and can be overwritten. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#setErrorListener(java.util.concurrent.Executor,androidx.media3.effect.GlShaderProgram.ErrorListener)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, errorListener: https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener! )` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#setInputListener(androidx.media3.effect.GlShaderProgram.InputListener)(inputListener: https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener!)` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#setOutputListener(androidx.media3.effect.GlShaderProgram.OutputListener)(outputListener: https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener!)` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram#signalEndOfCurrentInputStream()()` Notifies the `GlShaderProgram` that no further input frames belonging to the current input stream will be queued. |

## Public functions

### flush

```
fun flush(): Unit
```

Flushes the `GlShaderProgram`.

The `GlShaderProgram` should reclaim the ownership of its allocated textures, `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onFlush()` its `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener` about the flush event, and `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onReadyToAcceptInputFrame()` if necessary.

The implementation must not `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener#onOutputFrameAvailable(androidx.media3.common.GlTextureInfo,long)` until after this method returns.

### queueInputFrame

```
fun queueInputFrame(
    glObjectsProvider: GlObjectsProvider!,
    inputTexture: GlTextureInfo!,
    presentationTimeUs: Long
): Unit
```

Processes an input frame if possible.

The `GlShaderProgram` owns the accepted frame until it calls `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onInputFrameProcessed(androidx.media3.common.GlTextureInfo)`. The caller should not overwrite or release the texture before the `GlShaderProgram` has finished processing it.

This method must only be called when the `GlShaderProgram` can `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onReadyToAcceptInputFrame()`.

| Parameters |
|---|---|
| `glObjectsProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider` for using EGL and GLES. |
| `inputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo` describing the texture containing the input frame. |
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp of the input frame, in microseconds. |

### release

```
fun release(): Unit
```

Releases all resources.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while releasing resources. |

### releaseOutputFrame

```
fun releaseOutputFrame(outputTexture: GlTextureInfo!): Unit
```

Notifies the `GlShaderProgram` that the frame on the given output texture is no longer used and can be overwritten.

### setErrorListener

```
fun setErrorListener(
    executor: Executor!,
    errorListener: GlShaderProgram.ErrorListener!
): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener`.

The `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener` is invoked on the provided `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

### setInputListener

```
fun setInputListener(inputListener: GlShaderProgram.InputListener!): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener`.

The `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener` should be invoked on the thread that owns the parent OpenGL context. For example, `https://developer.android.com/reference/kotlin/androidx/media3/effect/DefaultVideoFrameProcessor` invokes the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener` methods on its internal thread.

### setOutputListener

```
fun setOutputListener(outputListener: GlShaderProgram.OutputListener!): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener`.

The `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener` should be invoked on the thread that owns the parent OpenGL context. For example, `https://developer.android.com/reference/kotlin/androidx/media3/effect/DefaultVideoFrameProcessor` invokes the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener` methods on its internal thread.

### signalEndOfCurrentInputStream

```
fun signalEndOfCurrentInputStream(): Unit
```

Notifies the `GlShaderProgram` that no further input frames belonging to the current input stream will be queued.

Input frames that are queued after this method is called belong to a different input stream.