HardwareBufferSurfaceRenderer


@RequiresApi(value = 26)
@ExperimentalApi
class HardwareBufferSurfaceRenderer : 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 companion functions

HardwareBufferSurfaceRenderer
create(
    context: Context,
    hardwareBufferJniWrapper: HardwareBufferJniWrapper,
    listener: GlTextureFrameRenderer.Listener,
    errorConsumer: Consumer<Exception>
)

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

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

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

Public functions

open suspend Unit

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

open suspend Unit

Releases all resources.

open Unit

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

open Unit

Sets the target for where input frames are rendered to.

Public companion functions

create

fun create(
    context: Context,
    hardwareBufferJniWrapper: HardwareBufferJniWrapper,
    listener: GlTextureFrameRenderer.Listener,
    errorConsumer: Consumer<Exception>
): HardwareBufferSurfaceRenderer

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

fun create(
    context: Context,
    glExecutorService: ListeningExecutorService,
    glObjectsProvider: GlObjectsProvider,
    hardwareBufferJniWrapper: HardwareBufferJniWrapper,
    listener: GlTextureFrameRenderer.Listener,
    errorConsumer: Consumer<Exception>
): HardwareBufferSurfaceRenderer

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

Public functions

queuePacket

open suspend fun queuePacket(packet: PacketConsumer.Packet<HardwareBufferFrame>): Unit

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
packet: PacketConsumer.Packet<HardwareBufferFrame>

The Packet to process.

release

open suspend fun release(): Unit

Releases all resources.

setErrorConsumer

open fun setErrorConsumer(errorConsumer: Consumer<Exception>): Unit

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

setRenderOutput

open fun setRenderOutput(output: SurfaceInfo?): Unit

Sets the target for where input frames are rendered to.