# SurfaceHolderFrameWriter

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

*** ** * ** ***


```
@ExperimentalApi
class SurfaceHolderFrameWriter : FrameWriter, SurfaceHolder.Callback
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter` that outputs frames to a `https://developer.android.com/reference/android/view/SurfaceHolder.html`.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener` A listener for `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter` events. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#close()()` Blocks until all resources are released. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#configure(androidx.media3.common.Format,long)(format: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!, @https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame.Usage usage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Format and usage support can be Info#isSupported(Format, long) checked on the before configuring. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 33) https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#create(android.view.SurfaceHolder,java.util.concurrent.Executor,androidx.media3.common.video.SurfaceHolderFrameWriter.Listener,java.util.concurrent.Executor)( surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?, surfaceHolderExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, listener: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener!, listenerExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html! )` Creates a new instance that returns `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferFrame`s that are directly dequeued from an `https://developer.android.com/reference/android/media/ImageWriter.html` linked to the output `https://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#create(android.view.SurfaceHolder,java.util.concurrent.Executor,androidx.media3.common.video.SurfaceHolderFrameWriter.Listener,java.util.concurrent.Executor,androidx.media3.common.video.HardwareBufferNativeHelpers)( surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?, surfaceHolderExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, listener: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener!, listenerExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, hardwareBufferNativeHelpers: https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferNativeHelpers! )` Creates a new instance that returns video frames that will be written to the output `https://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame?` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)(wakeupExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, wakeupListener: https://developer.android.com/reference/java/lang/Runnable.html!)` Dequeues an `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame` storing a `https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame` of the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` format and usage, and a `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SyncFenceWrapper` that must be waited on before filling the frame. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter.Info!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#getInfo()()` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter.Info` for this FrameWriter. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#queueInputFrame(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)(frame: https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame!, writeCompleteFence: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SyncFenceWrapper?)` Queues a filled frame for further processing. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#setSurfaceHolder(android.view.SurfaceHolder)(surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?)` Sets the `https://developer.android.com/reference/android/view/SurfaceHolder.html` to which frames will be written. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#signalEndOfStream()()` Notifies this `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter` that the current stream has ended. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#surfaceChanged(android.view.SurfaceHolder,int,int,int)(holder: https://developer.android.com/reference/android/view/SurfaceHolder.html!, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#surfaceCreated(android.view.SurfaceHolder)(holder: https://developer.android.com/reference/android/view/SurfaceHolder.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#surfaceDestroyed(android.view.SurfaceHolder)(holder: https://developer.android.com/reference/android/view/SurfaceHolder.html!)` |

### Inherited functions

From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.html) `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/lang/AutoCloseable.html#close()()`

## Public functions

### close

```
fun close(): Unit
```

Blocks until all resources are released.

### configure

```
fun configure(format: Format!, @Frame.Usage usage: Long): Unit
```

Format and usage support can be Info#isSupported(Format, long) checked on the before configuring.

Must be called before #dequeueInputFrame.

If `https://developer.android.com/reference/kotlin/androidx/media3/common/Format#pixelFormat()` is unset (i.e. `https://developer.android.com/reference/kotlin/androidx/media3/common/Format#NO_VALUE()`), it defaults to `https://developer.android.com/reference/android/graphics/ImageFormat.html#YV12` below API 28, `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_1010102` for HDR on API 28+, or `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_8888` for SDR on API 28+.

### create

```
@RequiresApi(value = 33)
java-static fun create(
    surfaceHolder: SurfaceHolder?,
    surfaceHolderExecutor: Executor!,
    listener: SurfaceHolderFrameWriter.Listener!,
    listenerExecutor: Executor!
): SurfaceHolderFrameWriter!
```

Creates a new instance that returns `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferFrame`s that are directly dequeued from an `https://developer.android.com/reference/android/media/ImageWriter.html` linked to the output `https://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()`.

| Parameters |
|---|---|
| `surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?` | The `https://developer.android.com/reference/android/view/SurfaceHolder.html` to which frames will be written, or `null` if not yet available. |
| `surfaceHolderExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the surface holder methods will be called. |
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener`. |
| `listenerExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the listener methods will be called. |

### create

```
java-static fun create(
    surfaceHolder: SurfaceHolder?,
    surfaceHolderExecutor: Executor!,
    listener: SurfaceHolderFrameWriter.Listener!,
    listenerExecutor: Executor!,
    hardwareBufferNativeHelpers: HardwareBufferNativeHelpers!
): SurfaceHolderFrameWriter!
```

Creates a new instance that returns video frames that will be written to the output `https://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()`.

Below API 28, `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)` returns an `https://developer.android.com/reference/kotlin/androidx/media3/common/video/ImagePlanesFrame` wrapping an `https://developer.android.com/reference/android/media/ImageWriter.html` buffer without intermediate copying, and `
hardwareBufferNativeHelpers` is ignored.

On API 28 to 32 (inclusive), `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)` returns a pre-allocated `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferFrame`. It is copied to the `https://developer.android.com/reference/android/media/ImageWriter.html` (via `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferNativeHelpers`) after the caller fills and `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#queueInputFrame(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)` it.

On API 33 and above, `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)` returns a `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferFrame` directly dequeued from the `https://developer.android.com/reference/android/media/ImageWriter.html` without intermediate copying, and `
hardwareBufferNativeHelpers` is ignored.

| Parameters |
|---|---|
| `surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?` | The `https://developer.android.com/reference/android/view/SurfaceHolder.html` to which frames will be written, or `null` if not yet available. |
| `surfaceHolderExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the surface holder methods will be called. |
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SurfaceHolderFrameWriter.Listener`. |
| `listenerExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the listener methods will be called. |
| `hardwareBufferNativeHelpers: https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferNativeHelpers!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/video/HardwareBufferNativeHelpers` used to copy intermediate `https://developer.android.com/reference/android/hardware/HardwareBuffer.html`s to `https://developer.android.com/reference/android/hardware/HardwareBuffer.html`s dequeued from `https://developer.android.com/reference/android/media/ImageWriter.html` on API 28 to 32; ignored on other API levels. |

### dequeueInputFrame

```
fun dequeueInputFrame(wakeupExecutor: Executor!, wakeupListener: Runnable!): AsyncFrame?
```

Dequeues an `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame` storing a `https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame` of the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` format and usage, and a `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SyncFenceWrapper` that must be waited on before filling the frame.

The returned frame must be filled and `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter#queueInputFrame(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)` back for processing.

If the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter` is at capacity, this method returns null and will notify the listener when capacity is available, and it can be called again.

Only the most recent `wakeupListener` will be notified when capacity is available.

| Parameters |
|---|---|
| `wakeupExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the `wakeupListener` is invoked. |
| `wakeupListener: https://developer.android.com/reference/java/lang/Runnable.html!` | A `https://developer.android.com/reference/java/lang/Runnable.html` to be invoked when capacity becomes available. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame?` | The dequeued frame, or null if the writer is at capacity. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` has not been called. |

### getInfo

```
fun getInfo(): FrameWriter.Info!
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter.Info` for this FrameWriter.

### queueInputFrame

```
fun queueInputFrame(frame: Frame!, writeCompleteFence: SyncFenceWrapper?): Unit
```

Queues a filled frame for further processing.

The queued frame must have been previously `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)` from this writer.

| Parameters |
|---|---|
| `frame: https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame!` | The filled frame to queue. |
| `writeCompleteFence: https://developer.android.com/reference/kotlin/androidx/media3/common/video/SyncFenceWrapper?` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/video/SyncFenceWrapper` that will signal when the caller has finished writing to the frame, or `null` if the write was synchronous. |

### setSurfaceHolder

```
fun setSurfaceHolder(surfaceHolder: SurfaceHolder?): Unit
```

Sets the `https://developer.android.com/reference/android/view/SurfaceHolder.html` to which frames will be written.

| Parameters |
|---|---|
| `surfaceHolder: https://developer.android.com/reference/android/view/SurfaceHolder.html?` | The `https://developer.android.com/reference/android/view/SurfaceHolder.html`, or `null` to clear the output. |

### signalEndOfStream

```
fun signalEndOfStream(): Unit
```

Notifies this `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameWriter` that the current stream has ended.

More frames may be queued after calling this method, if the current stream changes.

### surfaceChanged

```
fun surfaceChanged(holder: SurfaceHolder!, format: Int, width: Int, height: Int): Unit
```

### surfaceCreated

```
fun surfaceCreated(holder: SurfaceHolder!): Unit
```

### surfaceDestroyed

```
fun surfaceDestroyed(holder: SurfaceHolder!): Unit
```