GlTextureFrameRenderer


@ExperimentalApi
public final class GlTextureFrameRenderer implements RenderingPacketConsumer, GlShaderProgram.InputListener, FinalShaderProgramWrapper.Listener


A PacketConsumer implementation that renders GlTextureFrames to an output android.view.Surface.

Summary

Public methods

static final @NonNull GlTextureFrameRenderer
create(
    @NonNull Context context,
    @NonNull ListeningExecutorService glExecutorService,
    @NonNull GlObjectsProvider glObjectsProvider,
    @NonNull Consumer<@NonNull VideoFrameProcessingException> errorHandler,
    @NonNull GlTextureFrameRenderer.Listener listener
)

Creates a new instance of GlTextureFrameRenderer.

void
onFrameRendered(long presentationTimeUs)

Called when a frame is rendered to the output surface.

void

Called when the GlShaderProgram has processed an input frame.

void

Called when one input stream is fully processed following signalEndOfCurrentInputStream.

void

Called when the GlShaderProgram is ready to accept another input frame.

void

Consumes a single GlTextureFrame, first configuring the renderer if required and queuing the frame to the shader program.

void

Releases all resources associated with this renderer.

void

Updates the output surface information with new SurfaceInfo, or null if the surface is no longer available.

Inherited methods

From androidx.media3.effect.GlShaderProgram.InputListener
void

Called when the GlShaderProgram has been flushed.

Public methods

create

public static final @NonNull GlTextureFrameRenderer create(
    @NonNull Context context,
    @NonNull ListeningExecutorService glExecutorService,
    @NonNull GlObjectsProvider glObjectsProvider,
    @NonNull Consumer<@NonNull VideoFrameProcessingException> errorHandler,
    @NonNull GlTextureFrameRenderer.Listener listener
)

Creates a new instance of GlTextureFrameRenderer.

Parameters
@NonNull Context context

The application context.

@NonNull ListeningExecutorService glExecutorService

The executor service to be used for GL operations.

@NonNull GlObjectsProvider glObjectsProvider

Provider for GL objects (textures, buffers, etc.).

@NonNull Consumer<@NonNull VideoFrameProcessingException> errorHandler

A consumer to handle any VideoFrameProcessingExceptions that occur.

@NonNull GlTextureFrameRenderer.Listener listener

A Listener to be notified of events from the renderer.

onFrameRendered

public void onFrameRendered(long presentationTimeUs)

Called when a frame is rendered to the output surface.

onInputFrameProcessed

public void onInputFrameProcessed(@NonNull GlTextureInfo inputTexture)

Called when the GlShaderProgram has processed an input frame.

The implementation shall not assume the GlShaderProgram is ready to accept another input frame when this method is called.

Parameters
@NonNull GlTextureInfo inputTexture

The GlTextureInfo that was used to queue the input frame.

onInputStreamProcessed

public void onInputStreamProcessed()

Called when one input stream is fully processed following signalEndOfCurrentInputStream.

onReadyToAcceptInputFrame

public void onReadyToAcceptInputFrame()

Called when the GlShaderProgram is ready to accept another input frame.

For each time this method is called, queueInputFrame can be called once.

queuePacket

public void queuePacket(
    @NonNull PacketConsumer.Packet<@NonNull GlTextureFrame> packet
)

Consumes a single GlTextureFrame, first configuring the renderer if required and queuing the frame to the shader program.

This method suspends until the frame is fully rendered. If the renderer is released while waiting, it gracefully exits.

release

public void release()

Releases all resources associated with this renderer.

This method cancels any pending render operations, releases the inputConsumer, and destroys the underlying GL shader program. It ensures that no further frames are processed after being called.

setRenderOutput

public void setRenderOutput(SurfaceInfo output)

Updates the output surface information with new SurfaceInfo, or null if the surface is no longer available.