HardwareBufferSurfaceRenderer


@RequiresApi(value = 26)
@ExperimentalApi
public final class HardwareBufferSurfaceRenderer implements RenderingPacketConsumer


A androidx.media3.effect.PacketConsumer that renders a Packet of HardwareBufferFrames to an output android.view.Surface by first converting to a GL texture, using a HardwareBufferToGlTextureFrameProcessor and GlTextureFrameRenderer.

Summary

Public methods

static final @NonNull HardwareBufferSurfaceRenderer
create(
    @NonNull Context context,
    @NonNull HardwareBufferJniWrapper hardwareBufferJniWrapper,
    @NonNull GlTextureFrameRenderer.Listener listener,
    @NonNull Consumer<@NonNull Exception> errorConsumer
)

Creates a HardwareBufferSurfaceRenderer instance, that uses OpenGL to render HardwareBufferFrame to an output android.view.Surface.

static final @NonNull HardwareBufferSurfaceRenderer
create(
    @NonNull Context context,
    @NonNull ListeningExecutorService glExecutorService,
    @NonNull GlObjectsProvider glObjectsProvider,
    @NonNull HardwareBufferJniWrapper hardwareBufferJniWrapper,
    @NonNull GlTextureFrameRenderer.Listener listener,
    @NonNull Consumer<@NonNull Exception> errorConsumer
)

Creates a HardwareBufferSurfaceRenderer instance, that uses OpenGL to render HardwareBufferFrame to an output android.view.Surface, on the given glThread.

void

Queues a Packet for processing, suspending the caller if the consumer is at capacity.

void

Releases all resources.

void

Sets a Consumer to handle any Exceptions that occur during rendering.

void

Sets the target for where input frames are rendered to.

Public methods

create

public static final @NonNull HardwareBufferSurfaceRenderer create(
    @NonNull Context context,
    @NonNull HardwareBufferJniWrapper hardwareBufferJniWrapper,
    @NonNull GlTextureFrameRenderer.Listener listener,
    @NonNull Consumer<@NonNull Exception> errorConsumer
)

Creates a HardwareBufferSurfaceRenderer instance, that uses OpenGL to render HardwareBufferFrame to an output android.view.Surface.

Internally creates a single threaded java.util.concurrent.ExecutorService to run GL commands, and a SingleContextGlObjectsProvider.

create

public static final @NonNull HardwareBufferSurfaceRenderer create(
    @NonNull Context context,
    @NonNull ListeningExecutorService glExecutorService,
    @NonNull GlObjectsProvider glObjectsProvider,
    @NonNull HardwareBufferJniWrapper hardwareBufferJniWrapper,
    @NonNull GlTextureFrameRenderer.Listener listener,
    @NonNull Consumer<@NonNull Exception> errorConsumer
)

Creates a HardwareBufferSurfaceRenderer instance, that uses OpenGL to render HardwareBufferFrame to an output android.view.Surface, on the given glThread.

queuePacket

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

Queues a Packet for processing, suspending the caller if the consumer is at capacity.

Once this method returns, the ownership of the packet is transferred to this PacketConsumer, and the caller should not modify the packet.

Parameters
@NonNull PacketConsumer.Packet<@NonNull HardwareBufferFrame> packet

The Packet to process.

release

public void release()

Releases all resources.

setErrorConsumer

public void setErrorConsumer(@NonNull Consumer<@NonNull Exception> errorConsumer)

Sets a Consumer to handle any Exceptions that occur during rendering.

setRenderOutput

public void setRenderOutput(SurfaceInfo output)

Sets the target for where input frames are rendered to.