@UnstableApi
interface VideoSink


A sink that consumes decoded video frames from a video .

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
annotation VideoSink.InputType

Specifies how the input frames are made available to the video sink.

Listener for VideoSink events.

Thrown by VideoSink implementations.

Constants

const Int

Input frames come from a Bitmap.

const Int

Input frames come from a surface.

Public functions

Unit

Clears the set output surface info.

Unit

Enables this video sink to render the start of the stream even if the renderer is not started yet.

Unit
flush(resetPosition: Boolean)

Flushes the video sink.

Surface!

Returns the input Surface where the video sink consumes input frames from.

Unit
initialize(sourceFormat: Format!)

Initializes the video sink.

Boolean

Returns whether all queued video frames have been rendered, including the frame marked as last buffer.

Boolean

Returns whether frames could be dropped from the sink's input surface.

Boolean

Returns whether the video sink is initialized.

Boolean

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

Unit

Called when the renderer is disabled.

Unit
onRendererEnabled(mayRenderStartOfStream: Boolean)

Called when the renderer is enabled.

Unit

Called when the renderer is started.

Unit

Called when the renderer is stopped.

Boolean
queueBitmap(inputBitmap: Bitmap!, timestampIterator: TimestampIterator!)

Provides an input Bitmap to the video sink.

Long
registerInputFrame(framePresentationTimeUs: Long, isLastFrame: Boolean)

Informs the video sink that a frame will be queued to its input surface.

Unit

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

Unit

Releases the sink.

Unit
render(positionUs: Long, elapsedRealtimeUs: Long)

Incrementally renders processed video frames.

Unit
setListener(listener: VideoSink.Listener!, executor: Executor!)

Sets a Listener on this sink.

Unit
setOutputSurfaceInfo(outputSurface: Surface!, outputResolution: Size!)

Sets the output surface info.

Unit

Sets video effects to apply after the next stream is registered.

Unit
setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float)

Sets the playback speed.

Unit
setStreamOffsetAndAdjustmentUs(
    streamOffsetUs: Long,
    bufferTimestampAdjustmentUs: Long
)

Sets the stream offset and buffer time adjustment, in microseconds.

Unit
setVideoEffects(videoEffects: (Mutable)List<Effect!>!)

Sets video effects to apply immediately.

Unit
setVideoFrameMetadataListener(
    videoFrameMetadataListener: VideoFrameMetadataListener!
)

Sets the VideoFrameMetadataListener.

Constants

INPUT_TYPE_BITMAP

const val INPUT_TYPE_BITMAP = 2: Int

Input frames come from a Bitmap.

INPUT_TYPE_SURFACE

const val INPUT_TYPE_SURFACE = 1: Int

Input frames come from a surface.

Public functions

clearOutputSurfaceInfo

fun clearOutputSurfaceInfo(): Unit

Clears the set output surface info.

enableMayRenderStartOfStream

fun enableMayRenderStartOfStream(): Unit

Enables this video sink to render the start of the stream even if the renderer is not started yet.

This is used to update the value of mayRenderStartOfStream passed to onRendererEnabled.

flush

fun flush(resetPosition: Boolean): Unit

Flushes the video sink.

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

Parameters
resetPosition: Boolean

Whether to reset the current position.

getInputSurface

fun getInputSurface(): Surface!

Returns the input Surface where the video sink consumes input frames from.

Must be called after the sink is initialized.

initialize

fun initialize(sourceFormat: Format!): Unit

Initializes the video sink.

Parameters
sourceFormat: Format!

The format of the compressed video.

Throws
androidx.media3.exoplayer.video.VideoSink.VideoSinkException

If initializing the sink failed.

isEnded

fun isEnded(): Boolean

Returns whether all queued video frames have been rendered, including the frame marked as last buffer.

isFrameDropAllowedOnInput

fun isFrameDropAllowedOnInput(): Boolean

Returns whether frames could be dropped from the sink's input surface.

isInitialized

fun isInitialized(): Boolean

Returns whether the video sink is initialized.

isReady

fun isReady(): Boolean

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

onRendererDisabled

fun onRendererDisabled(): Unit

Called when the renderer is disabled.

onRendererEnabled

fun onRendererEnabled(mayRenderStartOfStream: Boolean): Unit

Called when the renderer is enabled.

onRendererStarted

fun onRendererStarted(): Unit

Called when the renderer is started.

onRendererStopped

fun onRendererStopped(): Unit

Called when the renderer is stopped.

queueBitmap

fun queueBitmap(inputBitmap: Bitmap!, timestampIterator: TimestampIterator!): Boolean

Provides an input Bitmap to the video sink.

Must be called after the sink is initialized.

Parameters
inputBitmap: Bitmap!

The Bitmap queued to the video sink.

timestampIterator: TimestampIterator!

The 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. A false value indicates the caller must try again later.

registerInputFrame

fun registerInputFrame(framePresentationTimeUs: Long, isLastFrame: Boolean): Long

Informs the video sink that a frame will be queued to its input surface.

Must be called after the sink is initialized.

Parameters
framePresentationTimeUs: Long

The frame's presentation time, in microseconds.

isLastFrame: Boolean

Whether this is the last frame of the video stream.

Returns
Long

A release timestamp, in nanoseconds, that should be associated when releasing this frame, or TIME_UNSET if the sink was not able to register the frame and the caller must try again later.

registerInputStream

fun registerInputStream(@VideoSink.InputType inputType: Int, format: Format!): Unit

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

Must be called after the sink is initialized.

Parameters
@VideoSink.InputType inputType: Int

The InputType of the stream.

format: Format!

The Format of the stream.

release

fun release(): Unit

Releases the sink.

render

fun render(positionUs: Long, elapsedRealtimeUs: Long): Unit

Incrementally renders processed video frames.

Parameters
positionUs: Long

The current playback position, in microseconds.

elapsedRealtimeUs: Long

elapsedRealtime in microseconds, taken approximately at the time the playback position was positionUs.

Throws
androidx.media3.exoplayer.video.VideoSink.VideoSinkException

If an error occurs during rendering.

setListener

fun setListener(listener: VideoSink.Listener!, executor: Executor!): Unit

Sets a Listener on this sink. Callbacks are triggered on the supplied Executor.

Parameters
listener: VideoSink.Listener!

The Listener.

executor: Executor!

The Executor to dispatch the callbacks.

setOutputSurfaceInfo

fun setOutputSurfaceInfo(outputSurface: Surface!, outputResolution: Size!): Unit

Sets the output surface info.

setPendingVideoEffects

fun setPendingVideoEffects(videoEffects: (Mutable)List<Effect!>!): Unit

Sets video effects to apply after the next stream is registered.

setPlaybackSpeed

fun setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float): Unit

Sets the playback speed.

setStreamOffsetAndAdjustmentUs

fun setStreamOffsetAndAdjustmentUs(
    streamOffsetUs: Long,
    bufferTimestampAdjustmentUs: Long
): Unit

Sets the stream offset and buffer time adjustment, in microseconds.

Parameters
streamOffsetUs: Long

The offset that is added to the video frames presentation timestamps from the player.

bufferTimestampAdjustmentUs: Long

The timestamp adjustment to convert the player position to the frame presentation timestamp.

setVideoEffects

fun setVideoEffects(videoEffects: (Mutable)List<Effect!>!): Unit

Sets video effects to apply immediately.

setVideoFrameMetadataListener

fun setVideoFrameMetadataListener(
    videoFrameMetadataListener: VideoFrameMetadataListener!
): Unit

Sets the VideoFrameMetadataListener.