VideoFrameProcessor


@UnstableApi
interface VideoFrameProcessor

Known direct subclasses
DefaultVideoFrameProcessor

A VideoFrameProcessor implementation that applies GlEffect instances using OpenGL on a background thread.


Interface for a video frame processor that applies changes to individual video frames.

The changes are specified by Effect instances passed to registerInputStream.

Manages its input Surface, which can be accessed via getInputSurface. The output Surface must be set by the caller using setOutputSurfaceInfo.

VideoFrameProcessor instances can be created from any thread, but instance methods for each stream must be called from the same thread.

Summary

Nested types

A factory for VideoFrameProcessor instances.

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

Specifies how the input frames are made available to the VideoFrameProcessor.

Listener for asynchronous frame processing events.

Constants

const Long

Indicates the frame should be dropped after renderOutputFrame is invoked.

const Int

Input frames come from a Bitmap.

const Int

Input frames come from a surface.

const Int

Input frames come from a traditional GLES texture.

const Long

Indicates the frame should be rendered immediately after renderOutputFrame is invoked.

Public functions

Unit

Flushes the VideoFrameProcessor.

Surface!

Returns the input Surface, where VideoFrameProcessor consumes input frames from.

Int

Returns the number of input frames that have been made available to the VideoFrameProcessor but have not been processed yet.

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

Provides an input Bitmap to the VideoFrameProcessor.

Boolean
queueInputTexture(textureId: Int, presentationTimeUs: Long)

Provides an input texture ID to the VideoFrameProcessor.

Boolean

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

Unit
registerInputStream(
    @VideoFrameProcessor.InputType inputType: Int,
    effects: (Mutable)List<Effect!>!,
    frameInfo: FrameInfo!
)

Informs the VideoFrameProcessor that a new input stream will be queued with the list of Effects to apply to the new input stream.

Unit

Releases all resources.

Unit
renderOutputFrame(renderTimeNs: Long)

Renders the oldest unrendered output frame that has become available for rendering at the given renderTimeNs.

Unit

Sets the OnInputFrameProcessedListener.

Unit
setOutputSurfaceInfo(outputSurfaceInfo: SurfaceInfo?)

Sets the output surface and supporting information.

Unit

Informs the VideoFrameProcessor that no further input frames should be accepted.

Constants

DROP_OUTPUT_FRAME

const val DROP_OUTPUT_FRAME = -2: Long

Indicates the frame should be dropped after renderOutputFrame is invoked.

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.

When receiving input from a Surface, the caller must register input frames before rendering them to the input Surface.

INPUT_TYPE_TEXTURE_ID

const val INPUT_TYPE_TEXTURE_ID = 3: Int

Input frames come from a traditional GLES texture.

RENDER_OUTPUT_FRAME_IMMEDIATELY

const val RENDER_OUTPUT_FRAME_IMMEDIATELY = -1: Long

Indicates the frame should be rendered immediately after renderOutputFrame is invoked.

Public functions

flush

fun flush(): Unit

Flushes the VideoFrameProcessor.

All the frames that are registered prior to calling this method are no longer considered to be registered when this method returns.

Listener methods invoked prior to calling this method should be ignored.

Throws
java.lang.UnsupportedOperationException

If the VideoFrameProcessor does not accept surface input.

java.lang.IllegalStateException

If registerInputStream is not called before calling this method.

getInputSurface

fun getInputSurface(): Surface!

Returns the input Surface, where VideoFrameProcessor consumes input frames from.

The frames arriving on the Surface will not be consumed by the VideoFrameProcessor until registerInputStream is called with INPUT_TYPE_SURFACE.

Throws
java.lang.UnsupportedOperationException

If the VideoFrameProcessor does not accept surface input.

getPendingInputFrameCount

fun getPendingInputFrameCount(): Int

Returns the number of input frames that have been made available to the VideoFrameProcessor but have not been processed yet.

queueInputBitmap

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

Provides an input Bitmap to the VideoFrameProcessor.

Can be called many times after registering the input stream to put multiple frames in the same input stream.

Parameters
inputBitmap: Bitmap!

The Bitmap queued to the VideoFrameProcessor.

timestampIterator: TimestampIterator!

A TimestampIterator generating the exact timestamps that the bitmap should be shown at.

Returns
Boolean

Whether the Bitmap was successfully queued. A return value of false indicates the VideoFrameProcessor is not ready to accept input.

Throws
java.lang.UnsupportedOperationException

If the VideoFrameProcessor does not accept bitmap input.

queueInputTexture

fun queueInputTexture(textureId: Int, presentationTimeUs: Long): Boolean

Provides an input texture ID to the VideoFrameProcessor.

It must be only called after setOnInputFrameProcessedListener and registerInputStream have been called.

Parameters
textureId: Int

The ID of the texture queued to the VideoFrameProcessor.

presentationTimeUs: Long

The presentation time of the queued texture, in microseconds.

Returns
Boolean

Whether the texture was successfully queued. A return value of false indicates the VideoFrameProcessor is not ready to accept input.

registerInputFrame

fun registerInputFrame(): Boolean

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

Must be called before rendering a frame to the input surface. The caller must not render frames to the input surface when false is returned.

Returns
Boolean

Whether the input frame was successfully registered. If registerInputStream is called, this method returns false until onInputStreamRegistered is called. Otherwise, a return value of false indicates the VideoFrameProcessor is not ready to accept input.

Throws
java.lang.UnsupportedOperationException

If the VideoFrameProcessor does not accept surface input.

java.lang.IllegalStateException

If called after signalEndOfInput or before registerInputStream.

registerInputStream

fun registerInputStream(
    @VideoFrameProcessor.InputType inputType: Int,
    effects: (Mutable)List<Effect!>!,
    frameInfo: FrameInfo!
): Unit

Informs the VideoFrameProcessor that a new input stream will be queued with the list of Effects to apply to the new input stream.

After registering the first input stream, this method must only be called after the last frame of the already-registered input stream has been registered, last bitmap queued or last texture id queued.

This method blocks the calling thread until the previous calls to this method finish, that is when onInputStreamRegistered is called after the underlying processing pipeline has been adapted to the registered input stream.

Parameters
@VideoFrameProcessor.InputType inputType: Int

The InputType of the new input stream.

effects: (Mutable)List<Effect!>!

The list of effects to apply to the new input stream.

frameInfo: FrameInfo!

The FrameInfo of the new input stream.

release

fun release(): Unit

Releases all resources.

If the VideoFrameProcessor is released before it has ended, it will attempt to cancel processing any input frames that have already become available. Input frames that become available after release are ignored.

This method blocks until all resources are released or releasing times out.

This VideoFrameProcessor instance must not be used after this method is called.

renderOutputFrame

fun renderOutputFrame(renderTimeNs: Long): Unit

Renders the oldest unrendered output frame that has become available for rendering at the given renderTimeNs.

This will either render the output frame to the output surface, or drop the frame, per renderTimeNs.

This method must only be called if renderFramesAutomatically was set to false using the Factory and should be called exactly once for each frame that becomes available for rendering.

The renderTimeNs may be passed to eglPresentationTimeANDROID depending on the implementation.

Parameters
renderTimeNs: Long

The render time to use for the frame, in nanoseconds. The render time can be before or after the current system time. Use DROP_OUTPUT_FRAME to drop the frame, or RENDER_OUTPUT_FRAME_IMMEDIATELY to render the frame immediately.

setOnInputFrameProcessedListener

fun setOnInputFrameProcessedListener(
    listener: OnInputFrameProcessedListener!
): Unit

Sets the OnInputFrameProcessedListener.

setOutputSurfaceInfo

fun setOutputSurfaceInfo(outputSurfaceInfo: SurfaceInfo?): Unit

Sets the output surface and supporting information. When output frames are rendered and not dropped, they will be rendered to this output SurfaceInfo.

The new output SurfaceInfo is applied from the next output frame rendered onwards. If the output SurfaceInfo is null, the VideoFrameProcessor will stop rendering pending frames and resume rendering once a non-null SurfaceInfo is set.

If the dimensions given in SurfaceInfo do not match the output size after applying the final effect the frames are resized before rendering to the surface and letter/pillar-boxing is applied.

The caller is responsible for tracking the lifecycle of the surface including calling this method with a new surface if it is destroyed. When this method returns, the previous output surface is no longer being used and can safely be released by the caller.

signalEndOfInput

fun signalEndOfInput(): Unit

Informs the VideoFrameProcessor that no further input frames should be accepted.

Throws
java.lang.IllegalStateException

If called more than once.