VideoSink
@UnstableApi
interface VideoSink
A sink that consumes decoded video frames and images.
Summary
Nested types |
|---|
@DocumentedThe instruction provided when the stream changes for releasing the first frame. |
@DocumentedSpecifies how the input frames are made available to the video sink. |
interface VideoSink.ListenerListener for |
interface VideoSink.VideoFrameHandlerHandler for a video frame. |
|
Thrown by |
Constants |
|
|---|---|
const Int |
Input frames come from a |
const Int |
Input frames come from a |
const Int |
Instructs to release the first frame as soon as possible. |
const Int |
Instructs to release the first frame when the playback position reaches the stream start position. |
const Int |
Instructs to release the first frame when rendering starts. |
Public functions |
|
|---|---|
Unit |
Allows the sink to release the first frame even if rendering is not |
Unit |
Clears the set output surface info. |
Unit |
Flushes the video sink. |
Surface! |
Returns the input |
Boolean |
handleInputBitmap(Handles an input |
Boolean |
handleInputFrame(Handles a video input frame. |
Boolean |
initialize(sourceFormat: Format!)Initializes the video sink. |
Boolean |
isEnded()Returns whether all the data has been rendered to the output surface. |
Boolean |
Returns whether the video sink is |
Boolean |
Returns whether the video sink is able to immediately render media to its output surface from the current position. |
Unit |
Joins the video sink to a new stream. |
Unit |
onInputStreamChanged(Informs the video sink that a new input stream will be queued with the given effects. |
Unit |
redraw()Redraws the |
Unit |
release()Releases the sink. |
Unit |
Incrementally renders processed video frames to the output surface. |
Unit |
setBufferTimestampAdjustmentUs(bufferTimestampAdjustmentUs: Long)Sets the buffer timestamp adjustment. |
Unit |
setChangeFrameRateStrategy(Changes the |
Unit |
setListener(listener: VideoSink.Listener!, executor: Executor!)Sets a |
Unit |
setOutputSurfaceInfo(outputSurface: Surface!, outputResolution: Size!)Sets the output surface info. |
Unit |
setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float)Sets the playback speed. |
Unit |
setVideoEffects(videoEffects: (Mutable)List<Effect!>!)Sets |
Unit |
setVideoFrameMetadataListener(Sets the |
Unit |
Signals the end of the current input stream. |
Unit |
Signals the end of the last input stream. |
Unit |
Starts rendering to the output surface. |
Unit |
Stops rendering to the output surface. |
Constants
RELEASE_FIRST_FRAME_IMMEDIATELY
const val RELEASE_FIRST_FRAME_IMMEDIATELY = 0: Int
Instructs to release the first frame as soon as possible.
RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED
const val RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED = 2: Int
Instructs to release the first frame when the playback position reaches the stream start position.
RELEASE_FIRST_FRAME_WHEN_STARTED
const val RELEASE_FIRST_FRAME_WHEN_STARTED = 1: Int
Instructs to release the first frame when rendering starts.
Public functions
allowReleaseFirstFrameBeforeStarted
fun allowReleaseFirstFrameBeforeStarted(): Unit
Allows the sink to release the first frame even if rendering is not started.
This is used to update the FirstFrameReleaseInstruction of the stream that is currently being processed.
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.
handleInputBitmap
fun handleInputBitmap(
inputBitmap: Bitmap!,
bufferTimestampIterator: TimestampIterator!
): Boolean
Handles an input Bitmap.
Must be called after the corresponding stream is signaled.
| Parameters | |
|---|---|
inputBitmap: Bitmap! |
The |
bufferTimestampIterator: TimestampIterator! |
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 |
handleInputFrame
fun handleInputFrame(
bufferPresentationTimeUs: Long,
videoFrameHandler: VideoSink.VideoFrameHandler!
): Boolean
Handles a video input frame.
Must be called after the corresponding stream is signaled.
| Parameters | |
|---|---|
bufferPresentationTimeUs: Long |
The buffer presentation time, in microseconds. |
videoFrameHandler: VideoSink.VideoFrameHandler! |
The |
| Returns | |
|---|---|
Boolean |
Whether the frame was handled successfully. If |
initialize
fun initialize(sourceFormat: Format!): Boolean
Initializes the video sink.
| Parameters | |
|---|---|
sourceFormat: Format! |
The format of the first input video or image. |
| Returns | |
|---|---|
Boolean |
Whether initialization succeeded. If |
| Throws | |
|---|---|
androidx.media3.exoplayer.video.VideoSink.VideoSinkException |
If initializing the sink failed. |
isEnded
fun isEnded(): Boolean
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 signaled and all the input frames have been rendered. Note that a new input stream can be signaled even when this method returns true (in which case the sink will not be ended anymore).
isReady
fun isReady(otherwiseReady: Boolean): Boolean
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 | |
|---|---|
otherwiseReady: Boolean |
Whether the caller is ready except for the video sink. |
join
fun join(renderNextFrameImmediately: Boolean): Unit
Joins the video sink to a new stream.
The sink will mask isReady 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 | |
|---|---|
renderNextFrameImmediately: Boolean |
Whether the next frame should be rendered as soon as possible or only at its preferred scheduled release time. |
onInputStreamChanged
fun onInputStreamChanged(
@VideoSink.InputType inputType: Int,
format: Format!,
startPositionUs: Long,
@VideoSink.FirstFrameReleaseInstruction firstFrameReleaseInstruction: Int,
videoEffects: (Mutable)List<Effect!>!
): Unit
Informs the video sink that a new input stream will be queued with the given effects.
Must be called after the sink is initialized.
| Parameters | |
|---|---|
@VideoSink.InputType inputType: Int |
The |
format: Format! |
The |
startPositionUs: Long |
The start position of the buffer presentation timestamps of the stream, in microseconds. |
@VideoSink.FirstFrameReleaseInstruction firstFrameReleaseInstruction: Int |
The |
videoEffects: (Mutable)List<Effect!>! |
The |
render
fun render(positionUs: Long, elapsedRealtimeUs: Long): Unit
Incrementally renders processed video frames to the output surface.
| Parameters | |
|---|---|
positionUs: Long |
The current playback position, in microseconds. |
elapsedRealtimeUs: Long |
|
| Throws | |
|---|---|
androidx.media3.exoplayer.video.VideoSink.VideoSinkException |
If an error occurs during rendering. |
setBufferTimestampAdjustmentUs
fun setBufferTimestampAdjustmentUs(bufferTimestampAdjustmentUs: Long): Unit
Sets the buffer timestamp adjustment.
| Parameters | |
|---|---|
bufferTimestampAdjustmentUs: Long |
The timestamp adjustment to add to the buffer presentation timestamps to convert them to frame presentation timestamps, in microseconds. |
setChangeFrameRateStrategy
fun setChangeFrameRateStrategy(
@C.VideoChangeFrameRateStrategy changeFrameRateStrategy: Int
): Unit
Changes the C.VideoChangeFrameRateStrategy used when calling setFrameRate.
The default value is VIDEO_CHANGE_FRAME_RATE_STRATEGY_ONLY_IF_SEAMLESS.
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 |
executor: Executor! |
The |
setOutputSurfaceInfo
fun setOutputSurfaceInfo(outputSurface: Surface!, outputResolution: Size!): Unit
Sets the output surface info.
setPlaybackSpeed
fun setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float): Unit
Sets the playback speed.
setVideoEffects
fun setVideoEffects(videoEffects: (Mutable)List<Effect!>!): Unit
Sets video effects to apply immediately.
setVideoFrameMetadataListener
fun setVideoFrameMetadataListener(
videoFrameMetadataListener: VideoFrameMetadataListener!
): Unit
Sets the VideoFrameMetadataListener.
signalEndOfCurrentInputStream
fun signalEndOfCurrentInputStream(): Unit
Signals the end of the current input stream.