@UnstableApi
public 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 = )
public annotation VideoSink.InputType

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

public interface VideoSink.Listener

Listener for VideoSink events.

public final class VideoSink.VideoSinkException extends Exception

Thrown by VideoSink implementations.

Constants

default static final int

Input frames come from a Bitmap.

default static final int

Input frames come from a surface.

Public methods

abstract void

Clears the set output surface info.

abstract void

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

abstract void
flush(boolean resetPosition)

Flushes the video sink.

abstract Surface

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

abstract void
initialize(Format sourceFormat)

Initializes the video sink.

abstract boolean

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

abstract boolean

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

abstract boolean

Returns whether the video sink is initialized.

abstract boolean

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

abstract void

Called when the renderer is disabled.

abstract void
onRendererEnabled(boolean mayRenderStartOfStream)

Called when the renderer is enabled.

abstract void

Called when the renderer is started.

abstract void

Called when the renderer is stopped.

abstract boolean
queueBitmap(Bitmap inputBitmap, TimestampIterator timestampIterator)

Provides an input Bitmap to the video sink.

abstract long
registerInputFrame(long framePresentationTimeUs, boolean isLastFrame)

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

abstract void

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

abstract void

Releases the sink.

abstract void
render(long positionUs, long elapsedRealtimeUs)

Incrementally renders processed video frames.

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

Sets a Listener on this sink.

abstract void
setOutputSurfaceInfo(Surface outputSurface, Size outputResolution)

Sets the output surface info.

abstract void

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

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

Sets the playback speed.

abstract void
setStreamOffsetAndAdjustmentUs(
    long streamOffsetUs,
    long bufferTimestampAdjustmentUs
)

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

abstract void
setVideoEffects(List<Effect> videoEffects)

Sets video effects to apply immediately.

abstract void
setVideoFrameMetadataListener(
    VideoFrameMetadataListener videoFrameMetadataListener
)

Sets the VideoFrameMetadataListener.

Constants

INPUT_TYPE_BITMAP

default static final int INPUT_TYPE_BITMAP = 2

Input frames come from a Bitmap.

INPUT_TYPE_SURFACE

default static final int INPUT_TYPE_SURFACE = 1

Input frames come from a surface.

Public methods

clearOutputSurfaceInfo

abstract void clearOutputSurfaceInfo()

Clears the set output surface info.

enableMayRenderStartOfStream

abstract void enableMayRenderStartOfStream()

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

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 Surface where the video sink consumes input frames from.

Must be called after the sink is initialized.

initialize

abstract void initialize(Format sourceFormat)

Initializes the video sink.

Parameters
Format sourceFormat

The format of the compressed video.

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

If initializing the sink failed.

isEnded

abstract boolean isEnded()

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

isFrameDropAllowedOnInput

abstract boolean isFrameDropAllowedOnInput()

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

isInitialized

abstract boolean isInitialized()

Returns whether the video sink is initialized.

isReady

abstract boolean isReady()

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

onRendererDisabled

abstract void onRendererDisabled()

Called when the renderer is disabled.

onRendererEnabled

abstract void onRendererEnabled(boolean mayRenderStartOfStream)

Called when the renderer is enabled.

onRendererStarted

abstract void onRendererStarted()

Called when the renderer is started.

onRendererStopped

abstract void onRendererStopped()

Called when the renderer is stopped.

queueBitmap

abstract boolean queueBitmap(Bitmap inputBitmap, TimestampIterator timestampIterator)

Provides an input Bitmap to the video sink.

Must be called after the sink is initialized.

Parameters
Bitmap inputBitmap

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

abstract long registerInputFrame(long framePresentationTimeUs, boolean isLastFrame)

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

Must be called after the sink is initialized.

Parameters
long framePresentationTimeUs

The frame's presentation time, in microseconds.

boolean isLastFrame

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

abstract void registerInputStream(@VideoSink.InputType int inputType, Format format)

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

Must be called after the sink is initialized.

Parameters
@VideoSink.InputType int inputType

The InputType of the stream.

Format format

The Format of the stream.

release

abstract void release()

Releases the sink.

render

abstract void render(long positionUs, long elapsedRealtimeUs)

Incrementally renders processed video frames.

Parameters
long positionUs

The current playback position, in microseconds.

long elapsedRealtimeUs

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

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

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

Parameters
VideoSink.Listener listener

The Listener.

Executor executor

The Executor to dispatch the callbacks.

setOutputSurfaceInfo

abstract void setOutputSurfaceInfo(Surface outputSurface, Size outputResolution)

Sets the output surface info.

setPendingVideoEffects

abstract void setPendingVideoEffects(List<Effect> videoEffects)

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

setPlaybackSpeed

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

Sets the playback speed.

setStreamOffsetAndAdjustmentUs

abstract void setStreamOffsetAndAdjustmentUs(
    long streamOffsetUs,
    long bufferTimestampAdjustmentUs
)

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

Parameters
long streamOffsetUs

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

long bufferTimestampAdjustmentUs

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

setVideoEffects

abstract void setVideoEffects(List<Effect> videoEffects)

Sets video effects to apply immediately.

setVideoFrameMetadataListener

abstract void setVideoFrameMetadataListener(
    VideoFrameMetadataListener videoFrameMetadataListener
)

Sets the VideoFrameMetadataListener.