# VideoSink

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

*** ** * ** ***

<br />

```
@UnstableApi
public interface VideoSink
```

<br />

*** ** * ** ***

A sink that consumes decoded video frames and images.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.FirstFrameReleaseInstruction` The instruction provided when the stream changes for releasing the first frame. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.InputType` Specifies how the input frames are made available to the video sink. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener` Listener for `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink` events. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoFrameHandler` Handler for a video frame. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoSinkException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown by `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink` implementations. |

| ### Constants |
|---|---|
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#INPUT_TYPE_BITMAP() = 2` Input frames come from a `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#INPUT_TYPE_SURFACE() = 1` Input frames come from a `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#getInputSurface()`. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#RELEASE_FIRST_FRAME_IMMEDIATELY() = 0` Instructs to release the first frame as soon as possible. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED() = 2` Instructs to release the first frame when the playback position reaches the stream start position. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#RELEASE_FIRST_FRAME_WHEN_STARTED() = 1` Instructs to release the first frame when rendering starts. |

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#allowReleaseFirstFrameBeforeStarted()()` Allows the sink to release the first frame even if rendering is not `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#startRendering()`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#clearOutputSurfaceInfo()()` Clears the set output surface info. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#flush(boolean)(boolean resetPosition)` Flushes the video sink. |
| `abstract https://developer.android.com/reference/android/view/Surface.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#getInputSurface()()` Returns the input `https://developer.android.com/reference/android/view/Surface.html` where the video sink consumes input frames from. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#handleInputBitmap(android.graphics.Bitmap,androidx.media3.common.util.TimestampIterator)( https://developer.android.com/reference/android/graphics/Bitmap.html inputBitmap, https://developer.android.com/reference/androidx/media3/common/util/TimestampIterator bufferTimestampIterator )` Handles an input `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#handleInputFrame(long,androidx.media3.exoplayer.video.VideoSink.VideoFrameHandler)( long bufferPresentationTimeUs, https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoFrameHandler videoFrameHandler )` Handles a video input frame. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#initialize(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format sourceFormat)` Initializes the video sink. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#isEnded()()` Returns whether all the data has been rendered to the output surface. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#isInitialized()()` Returns whether the video sink is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#initialize(androidx.media3.common.Format)`. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#isReady(boolean)(boolean otherwiseReady)` Returns whether the video sink is able to immediately render media to its output surface from the current position. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#join(boolean)(boolean renderNextFrameImmediately)` Joins the video sink to a new stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#onInputStreamChanged(int,androidx.media3.common.Format,long,int,java.util.List<androidx.media3.common.Effect>)( @https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.InputType int inputType, https://developer.android.com/reference/androidx/media3/common/Format format, long startPositionUs, @https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.FirstFrameReleaseInstruction int firstFrameReleaseInstruction, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Effect> videoEffects )` Informs the video sink that a new input stream will be queued with the given effects. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#redraw()()` Redraws the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setVideoEffects(java.util.List<androidx.media3.common.Effect>)` immediately. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#release()()` Releases the sink. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#render(long,long)(long positionUs, long elapsedRealtimeUs)` Incrementally renders processed video frames to the output surface. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setBufferTimestampAdjustmentUs(long)(long bufferTimestampAdjustmentUs)` Sets the buffer timestamp adjustment. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setChangeFrameRateStrategy(int)( @https://developer.android.com/reference/androidx/media3/common/C.VideoChangeFrameRateStrategy int changeFrameRateStrategy )` Changes the `https://developer.android.com/reference/androidx/media3/common/C.VideoChangeFrameRateStrategy` used when calling `https://developer.android.com/reference/android/view/Surface.html#setFrameRate(float, int)`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setListener(androidx.media3.exoplayer.video.VideoSink.Listener,java.util.concurrent.Executor)(https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener listener, https://developer.android.com/reference/java/util/concurrent/Executor.html executor)` Sets a `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener` on this sink. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setOutputSurfaceInfo(android.view.Surface,androidx.media3.common.util.Size)(https://developer.android.com/reference/android/view/Surface.html outputSurface, https://developer.android.com/reference/androidx/media3/common/util/Size outputResolution)` Sets the output surface info. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setPlaybackSpeed(float)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0, fromInclusive = false) float speed)` Sets the playback speed. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setVideoEffects(java.util.List<androidx.media3.common.Effect>)(https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Effect> videoEffects)` Sets `https://developer.android.com/reference/androidx/media3/common/Effect` to apply immediately. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setVideoFrameMetadataListener(androidx.media3.exoplayer.video.VideoFrameMetadataListener)( https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoFrameMetadataListener videoFrameMetadataListener )` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoFrameMetadataListener`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#signalEndOfCurrentInputStream()()` Signals the end of the current input stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#signalEndOfInput()()` Signals the end of the last input stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#startRendering()()` Starts rendering to the output surface. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#stopRendering()()` Stops rendering to the output surface. |

## Constants

### INPUT_TYPE_BITMAP

```
default static final int INPUT_TYPE_BITMAP = 2
```

Input frames come from a `https://developer.android.com/reference/android/graphics/Bitmap.html`.

### INPUT_TYPE_SURFACE

```
default static final int INPUT_TYPE_SURFACE = 1
```

Input frames come from a `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#getInputSurface()`.

### RELEASE_FIRST_FRAME_IMMEDIATELY

```
default static final int RELEASE_FIRST_FRAME_IMMEDIATELY = 0
```

Instructs to release the first frame as soon as possible.

### RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED

```
default static final int RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED = 2
```

Instructs to release the first frame when the playback position reaches the stream start position.

### RELEASE_FIRST_FRAME_WHEN_STARTED

```
default static final int RELEASE_FIRST_FRAME_WHEN_STARTED = 1
```

Instructs to release the first frame when rendering starts.

## Public methods

### allowReleaseFirstFrameBeforeStarted

```
abstract void allowReleaseFirstFrameBeforeStarted()
```

Allows the sink to release the first frame even if rendering is not `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#startRendering()`.

This is used to update the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.FirstFrameReleaseInstruction` of the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#onInputStreamChanged(int,androidx.media3.common.Format,long,int,java.util.List<androidx.media3.common.Effect>)` that is currently being processed.

### clearOutputSurfaceInfo

```
abstract void clearOutputSurfaceInfo()
```

Clears the set output surface info.

### flush

```
abstract void flush(boolean resetPosition)
```

Flushes the video sink.

After calling this method, any frames stored inside the video sink are discarded.

| Parameters |
|---|---|
| `boolean resetPosition` | Whether to reset the current position. |

### getInputSurface

```
abstract Surface getInputSurface()
```

Returns the input `https://developer.android.com/reference/android/view/Surface.html` where the video sink consumes input frames from.

Must be called after the sink is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#initialize(androidx.media3.common.Format)`.

### handleInputBitmap

```
abstract boolean handleInputBitmap(
    Bitmap inputBitmap,
    TimestampIterator bufferTimestampIterator
)
```

Handles an input `https://developer.android.com/reference/android/graphics/Bitmap.html`.

Must be called after the corresponding stream is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#onInputStreamChanged(int,androidx.media3.common.Format,long,int,java.util.List<androidx.media3.common.Effect>)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html inputBitmap` | The `https://developer.android.com/reference/android/graphics/Bitmap.html` to queue to the video sink. |
| `https://developer.android.com/reference/androidx/media3/common/util/TimestampIterator bufferTimestampIterator` | The buffer presentation times within the current stream that the bitmap should be shown at. The timestamps should be monotonically increasing. |

| Returns |
|---|---|
| `boolean` | Whether the bitmap was queued successfully. If `false`, the caller can try again later. |

### handleInputFrame

```
abstract boolean handleInputFrame(
    long bufferPresentationTimeUs,
    VideoSink.VideoFrameHandler videoFrameHandler
)
```

Handles a video input frame.

Must be called after the corresponding stream is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#onInputStreamChanged(int,androidx.media3.common.Format,long,int,java.util.List<androidx.media3.common.Effect>)`.

| Parameters |
|---|---|
| `long bufferPresentationTimeUs` | The buffer presentation time, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoFrameHandler videoFrameHandler` | The `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoFrameHandler` used to handle the input frame. |

| Returns |
|---|---|
| `boolean` | Whether the frame was handled successfully. If `false`, the caller can try again later. |

### initialize

```
abstract boolean initialize(Format sourceFormat)
```

Initializes the video sink.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format sourceFormat` | The format of the first input video or image. |

| Returns |
|---|---|
| `boolean` | Whether initialization succeeded. If `false`, the caller should try again later. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoSinkException` | If initializing the sink failed. |

### isEnded

```
abstract boolean isEnded()
```

Returns whether all the data has been rendered to the output surface.

This method returns `true` if the end of the last input stream has been `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#signalEndOfCurrentInputStream()` and all the input frames have been rendered. Note that a new input stream can be `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#onInputStreamChanged(int,androidx.media3.common.Format,long,int,java.util.List<androidx.media3.common.Effect>)` even when this method returns true (in which case the sink will not be ended anymore).

### isInitialized

```
abstract boolean isInitialized()
```

Returns whether the video sink is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#initialize(androidx.media3.common.Format)`.

### isReady

```
abstract boolean isReady(boolean otherwiseReady)
```

Returns whether the video sink is able to immediately render media to its output surface from the current position.

The caller should be ready if and only if the video sink is ready.

| Parameters |
|---|---|
| `boolean otherwiseReady` | Whether the caller is ready except for the video sink. |

### join

```
abstract void join(boolean renderNextFrameImmediately)
```

Joins the video sink to a new stream.

The sink will mask `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#isReady(boolean)` as `true` for a short time to avoid interrupting an ongoing playback, even if the first frame hasn't yet been rendered to the output surface.

| Parameters |
|---|---|
| `boolean renderNextFrameImmediately` | Whether the next frame should be rendered as soon as possible or only at its preferred scheduled release time. |

### onInputStreamChanged

```
abstract void onInputStreamChanged(
    @VideoSink.InputType int inputType,
    Format format,
    long startPositionUs,
    @VideoSink.FirstFrameReleaseInstruction int firstFrameReleaseInstruction,
    List<Effect> videoEffects
)
```

Informs the video sink that a new input stream will be queued with the given effects.

Must be called after the sink is `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#initialize(androidx.media3.common.Format)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.InputType int inputType` | The `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.InputType` of the stream. |
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` of the stream. |
| `long startPositionUs` | The start position of the buffer presentation timestamps of the stream, in microseconds. |
| `@https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.FirstFrameReleaseInstruction int firstFrameReleaseInstruction` | The `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.FirstFrameReleaseInstruction` indicating when to release the stream's first frame. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Effect> videoEffects` | The `https://developer.android.com/reference/java/util/List.html` to apply to the new stream. |

### redraw

```
abstract void redraw()
```

Redraws the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink#setVideoEffects(java.util.List<androidx.media3.common.Effect>)` immediately.

### release

```
abstract void release()
```

Releases the sink.

### render

```
abstract void render(long positionUs, long elapsedRealtimeUs)
```

Incrementally renders processed video frames to the output surface.

| Parameters |
|---|---|
| `long positionUs` | The current playback position, in microseconds. |
| `long elapsedRealtimeUs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` in microseconds, taken approximately at the time the playback position was `positionUs`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.VideoSinkException` | If an error occurs during rendering. |

### setBufferTimestampAdjustmentUs

```
abstract void setBufferTimestampAdjustmentUs(long bufferTimestampAdjustmentUs)
```

Sets the buffer timestamp adjustment.

| Parameters |
|---|---|
| `long bufferTimestampAdjustmentUs` | The timestamp adjustment to add to the buffer presentation timestamps to convert them to frame presentation timestamps, in microseconds. |

### setChangeFrameRateStrategy

```
abstract void setChangeFrameRateStrategy(
    @C.VideoChangeFrameRateStrategy int changeFrameRateStrategy
)
```

Changes the `https://developer.android.com/reference/androidx/media3/common/C.VideoChangeFrameRateStrategy` used when calling `https://developer.android.com/reference/android/view/Surface.html#setFrameRate(float, int)`.

The default value is `https://developer.android.com/reference/androidx/media3/common/C#VIDEO_CHANGE_FRAME_RATE_STRATEGY_ONLY_IF_SEAMLESS()`.

### setListener

```
abstract void setListener(VideoSink.Listener listener, Executor executor)
```

Sets a `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener` on this sink. Callbacks are triggered on the supplied `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener listener` | The `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoSink.Listener`. |
| `https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` to dispatch the callbacks. |

### setOutputSurfaceInfo

```
abstract void setOutputSurfaceInfo(Surface outputSurface, Size outputResolution)
```

Sets the output surface info.

### setPlaybackSpeed

```
abstract void setPlaybackSpeed(@FloatRange(from = 0, fromInclusive = false) float speed)
```

Sets the playback speed.

### setVideoEffects

```
abstract void setVideoEffects(List<Effect> videoEffects)
```

Sets `https://developer.android.com/reference/androidx/media3/common/Effect` to apply immediately.

### setVideoFrameMetadataListener

```
abstract void setVideoFrameMetadataListener(
    VideoFrameMetadataListener videoFrameMetadataListener
)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/video/VideoFrameMetadataListener`.

### signalEndOfCurrentInputStream

```
abstract void signalEndOfCurrentInputStream()
```

Signals the end of the current input stream.

### signalEndOfInput

```
abstract void signalEndOfInput()
```

Signals the end of the last input stream.

### startRendering

```
abstract void startRendering()
```

Starts rendering to the output surface.

### stopRendering

```
abstract void stopRendering()
```

Stops rendering to the output surface.