Stay organized with collections Save and categorize content based on your preferences.

SingleFrameGlTextureProcessor

@UnstableApi
public abstract class SingleFrameGlTextureProcessor implements GlTextureProcessor


Manages a GLSL shader program for processing a frame. Implementations generally copy input pixels into an output frame, with changes to pixels specific to the implementation.

SingleFrameGlTextureProcessor implementations must produce exactly one output frame per input frame with the same presentation timestamp. For more flexibility, implement directly.

All methods in this class must be called on the thread that owns the OpenGL context.

Summary

Public constructors

Creates a SingleFrameGlTextureProcessor instance.

Public methods

abstract Pair<IntegerInteger>
configure(int inputWidth, int inputHeight)

Configures the texture processor based on the input dimensions.

abstract void
drawFrame(int inputTexId, long presentationTimeUs)

Draws one frame.

final void
queueInputFrame(TextureInfo inputTexture, long presentationTimeUs)

Processes an input frame if possible.

void

Releases all resources.

final void

Notifies the texture processor that the frame on the given output texture is no longer used and can be overwritten.

final void

Sets the ErrorListener.

final void

Sets the InputListener.

final void

Sets the OutputListener.

final void

Notifies the GlTextureProcessor that no further input frames belonging to the current input stream will be queued.

Public constructors

SingleFrameGlTextureProcessor

public SingleFrameGlTextureProcessor(boolean useHdr)

Creates a SingleFrameGlTextureProcessor instance.

Parameters
boolean useHdr

Whether input textures come from an HDR source. If true, colors will be in linear RGB BT.2020. If false, colors will be in linear RGB BT.709.

Public methods

configure

public abstract Pair<IntegerIntegerconfigure(int inputWidth, int inputHeight)

Configures the texture processor based on the input dimensions.

This method must be called before drawing the first frame and before drawing subsequent frames with different input dimensions.

Parameters
int inputWidth

The input width, in pixels.

int inputHeight

The input height, in pixels.

Returns
Pair<IntegerInteger>

The output width and height of frames processed through drawFrame.

drawFrame

public abstract void drawFrame(int inputTexId, long presentationTimeUs)

Draws one frame.

This method may only be called after the texture processor has been configured. The caller is responsible for focussing the correct render target before calling this method.

A minimal implementation should tell OpenGL to use its shader program, bind the shader program's vertex attributes and uniforms, and issue a drawing command.

Parameters
int inputTexId

Identifier of a 2D OpenGL texture containing the input frame.

long presentationTimeUs

The presentation timestamp of the current frame, in microseconds.

Throws
androidx.media3.common.FrameProcessingException androidx.media3.common.FrameProcessingException

If an error occurs while processing or drawing the frame.

queueInputFrame

public final void queueInputFrame(TextureInfo inputTexture, long presentationTimeUs)

Processes an input frame if possible.

The GlTextureProcessor owns the accepted frame until it calls onInputFrameProcessed. The caller should not overwrite or release the texture before the GlTextureProcessor has finished processing it.

This method must only be called when the GlTextureProcessor can accept an input frame.

Parameters
TextureInfo inputTexture

A TextureInfo describing the texture containing the input frame.

long presentationTimeUs

The presentation timestamp of the input frame, in microseconds.

release

@CallSuper
public void release()

Releases all resources.

Throws
androidx.media3.common.FrameProcessingException androidx.media3.common.FrameProcessingException

If an error occurs while releasing resources.

releaseOutputFrame

public final void releaseOutputFrame(TextureInfo outputTexture)

Notifies the texture processor that the frame on the given output texture is no longer used and can be overwritten.

setErrorListener

public final void setErrorListener(GlTextureProcessor.ErrorListener errorListener)

Sets the ErrorListener.

setInputListener

public final void setInputListener(GlTextureProcessor.InputListener inputListener)

Sets the InputListener.

setOutputListener

public final void setOutputListener(GlTextureProcessor.OutputListener outputListener)

Sets the OutputListener.

signalEndOfCurrentInputStream

public final void signalEndOfCurrentInputStream()

Notifies the GlTextureProcessor that no further input frames belonging to the current input stream will be queued.

Input frames that are queued after this method is called belong to a different input stream, so presentation timestamps may reset to start from a smaller presentation timestamp than the last frame of the previous input stream.