Table of Contents

Class YUVToRGBAConverter

The default YUV 4:2:0 to RGBA converter that uses a compute shader to convert the camera texture to RGBA.

public class YUVToRGBAConverter
Inheritance
object
YUVToRGBAConverter

Constructors

YUVToRGBAConverter(Resolution)

public YUVToRGBAConverter(Resolution resolution)

Parameters

resolution Resolution

Fields

_kernelHandle

protected int _kernelHandle

Field Value

int

_threadGroupsX

protected readonly int _threadGroupsX

Field Value

int

_threadGroupsY

protected readonly int _threadGroupsY

Field Value

int

_uComputeBuffer

Buffer containing U (color) data of the frame being processed.

protected readonly ComputeBuffer _uComputeBuffer

Field Value

ComputeBuffer

_uvBufferSize

protected readonly int _uvBufferSize

Field Value

int

_vComputeBuffer

Buffer containing V (color) data of the frame being processed.

protected readonly ComputeBuffer _vComputeBuffer

Field Value

ComputeBuffer

_yBufferSize

protected readonly int _yBufferSize

Field Value

int

_yComputeBuffer

Buffer containing Y (luminance) data of the frame being processed.

protected readonly ComputeBuffer _yComputeBuffer

Field Value

ComputeBuffer

Properties

FrameCaptureTimestamp

The timestamp the last frame processed was captured at in nanoseconds.

public long FrameCaptureTimestamp { get; protected set; }

Property Value

long

FrameRenderTexture

The RenderTexture which will contain the RGBA camera frames.

public RenderTexture FrameRenderTexture { get; protected set; }

Property Value

RenderTexture

Shader

The shader used to convert YUV 4:2:0 to an RGBA RenderTexture. Uses YUVToRGBAComputeShader if not specified here.

public ComputeShader Shader { get; set; }

Property Value

ComputeShader

Methods

Dispose()

Releases the frame RenderTexture and buffers.

public void Dispose()

~YUVToRGBAConverter()

protected ~YUVToRGBAConverter()

GetNextFrameAsync(CancellationToken)

Returns the next frame to be received by this processor.

public Task<(RenderTexture, long)> GetNextFrameAsync(CancellationToken token = default)

Parameters

token CancellationToken

Returns

Task<(RenderTexture, long)>

The frame's RenderTexture and capture timestamp, in nanoseconds..

OnFrameReady(nint, long, nint, nint, long, int, int, int, long)

Processes a frame received from the native capture session.

public virtual void OnFrameReady(nint yBuffer, long yBufferSize, nint uBuffer, nint vBuffer, long uvBufferSize, int yRowStride, int uvRowStride, int uvPixelStride, long timestamp)

Parameters

yBuffer nint

The pointer to this frame's Y (luminance) data.

yBufferSize long

The size of the Y buffer in bytes.

uBuffer nint

The pointer to this frame's U (color) data.

vBuffer nint

The pointer to this frame's V (color) data.

uvBufferSize long

The size of the U and V buffers in bytes.

yRowStride int

The size of each row of the image in yBuffer in bytes.

uvRowStride int

The size of each row of the image in uBuffer and vBuffer in bytes.

uvPixelStride int

The size of a pixel in a row of the image in uBuffer and vBuffer in bytes.

timestamp long

The timestamp the frame was captured at in nanoseconds.

PrepareDataForComputeBuffer(CPUDepthFrame, int, int, int, long)

Copies the given data into the shader's buffers and dispatches it.

protected virtual Task PrepareDataForComputeBuffer(YUVToRGBAConverter.CPUDepthFrame frame, int yRowStride, int uvRowStride, int uvPixelStride, long timestamp)

Parameters

frame YUVToRGBAConverter.CPUDepthFrame

The frame data on the CPU.

yRowStride int

The size of each row of the image in _yComputeBuffer in bytes.

uvRowStride int

The size of each row of the image in _uComputeBuffer and _vComputeBuffer in bytes.

uvPixelStride int

The size of a pixel in a row of the image in _uComputeBuffer and _vComputeBuffer in bytes.

timestamp long

The timestamp the frame was captured at in nanoseconds.

Returns

Task

Events

OnFrameProcessed

Called when a capture is dispatched for conversion to RGBA, with the capture's timestamp in nanoseconds.

public event Action<RenderTexture, long>? OnFrameProcessed

Event Type

Action<RenderTexture, long>