# EnhancementSessionDecorator

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

*** ** * ** ***


```
@ExperimentalApi
@RequiresApi(value = 33)
class EnhancementSessionDecorator : FrameProcessor
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameProcessor` decorator that routes video frames through Google Play services EnhancementSession.

Timestamp handling across the surface bridge:

1. `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/FrameToSurfaceFrameWriter` receives an upstream `https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame` with `
   presentationTimeUs`, stamps the `https://developer.android.com/reference/android/media/Image.html` with a synthetic strictly increasing nanosecond timestamp from `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/MonotonicTimestampGenerator` (required because the underlying MediaPipe graph rejects non-increasing timestamps on seeks), and notifies `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/FrameToSurfaceFrameWriter.Listener#onFrameQueued(long)` with the original `
   presentationTimeUs`.
2. `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator` forwards `presentationTimeUs` from `
   onFrameQueued` to `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/SurfaceToFrameWriterAdapter#onInputFrameQueued(long)`.
3. `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/SurfaceToFrameWriterAdapter` stores `presentationTimeUs` in a FIFO queue and restores it onto the output `https://developer.android.com/reference/kotlin/androidx/media3/common/video/Frame` when the processed image arrives on the output `https://developer.android.com/reference/android/view/Surface.html`. A 1:1 FIFO queue is guaranteed to match because `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/FrameToSurfaceFrameWriter` enforces at most one frame in flight (`
   MAX_IN_FLIGHT_FRAMES = 1`), waiting for `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/SurfaceToFrameWriterAdapter.Listener#onFrameReleased()` before queuing the next frame.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator.Builder` Builder for `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator` factories. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator.Factory : https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameProcessor.Factory` Factory for `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator#close()()` Blocks until all resources are released. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator#queue(java.util.List<androidx.media3.common.video.AsyncFrame>)(frames: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame!>!)` Attempts to queue a `https://developer.android.com/reference/java/util/List.html` of `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame` for processing. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/playservices/EnhancementSessionDecorator#signalEndOfStream()()` Notifies this processor that the current stream has ended. |

### 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.

May be called from any thread.

### queue

```
fun queue(frames: (Mutable)List<AsyncFrame!>!): Boolean
```

Attempts to queue a `https://developer.android.com/reference/java/util/List.html` of `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame` for processing.

All frames provided in a single invocation of this method represent the exact same point in time.

If this consumer is at capacity, this method returns `false` and the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameProcessor.Listener#onWakeup()` will be invoked when capacity becomes available.

If this method returns `true`, `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameProcessor.Listener#onFrameProcessed(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)` must be called once with every input `https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame#frame()` instance queued, once the `https://developer.android.com/reference/kotlin/androidx/media3/common/video/FrameProcessor` has finished processing the `frames`.

| Parameters |
|---|---|
| `frames: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/common/video/AsyncFrame!>!` | The frames to queue. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the frames were queued, `false` if the consumer is at capacity. |

### signalEndOfStream

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

Notifies this processor that the current stream has ended.

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