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 : MonoBehaviour
Inheritance
object
YUVToRGBAConverter

Fields

OnFrameProcessed

Called when a frame has been converted from YUV 4:2:0 to RGBA.

public UnityEvent<RenderTexture> OnFrameProcessed

Field Value

UnityEvent<RenderTexture>

OnFrameProcessedWithTimestamp

Called when a frame has been converted from YUV 4:2:0 to RGBA. Also includes the timestamp the frame was captured at in nanoseconds.

public UnityEvent<RenderTexture, long> OnFrameProcessedWithTimestamp

Field Value

UnityEvent<RenderTexture, long>

Shader

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

public ComputeShader Shader

Field Value

ComputeShader

_uComputeBuffer

Pointer to the buffer containing U (color) data of the frame being processed.

protected ComputeBuffer _uComputeBuffer

Field Value

ComputeBuffer

_vComputeBuffer

Pointer to the buffer containing V (color) data of the frame being processed.

protected ComputeBuffer _vComputeBuffer

Field Value

ComputeBuffer

_yComputeBuffer

Pointer to the buffer containing Y (luminance) data of the frame being processed.

protected ComputeBuffer _yComputeBuffer

Field Value

ComputeBuffer

Properties

CameraFrameForwarder

The native camera frame forwarder.

public CameraFrameForwarder CameraFrameForwarder { get; protected set; }

Property Value

CameraFrameForwarder

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

_isReleased

Have the converter's resources been released?

protected bool _isReleased { get; }

Property Value

bool

Methods

Awake()

protected void Awake()

CopyNativeDataToComputeBuffer(ref ComputeBuffer, nint, int)

Copies native (unmanaged) byte data to a compute buffer.

protected static void CopyNativeDataToComputeBuffer(ref ComputeBuffer computeBuffer, nint nativeBufferPtr, int nativeBufferSize)

Parameters

computeBuffer ComputeBuffer

The buffer to copy to.

nativeBufferPtr nint

The memory to copy from.

nativeBufferSize int

The number of bytes to copy.

OnDestroy()

protected void OnDestroy()

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

Callback for CameraFrameForwarder.

protected virtual Task OnFrameReady(nint yBuffer, nint uBuffer, nint vBuffer, int ySize, int uSize, int vSize, int yRowStride, int uvRowStride, int uvPixelStride, long timestamp)

Parameters

yBuffer nint

Pointer to the buffer containing Y (luminance) data of the frame.

uBuffer nint

Pointer to the buffer containing U (color) data of the frame.

vBuffer nint

Pointer to the buffer containing V (color) data of the frame.

ySize int

The size of yBuffer.

uSize int

The size of uBuffer.

vSize int

The size of vBuffer.

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.

Returns

Task

Release()

Releases the ComputeBuffers and RenderTextures associated with this converter.

public void Release()

SendFrameToComputeBuffer(int, int, int, long)

Sends the camera frame stored in the compute buffers to the compute shader and dispatches it.

protected virtual void SendFrameToComputeBuffer(int yRowStride, int uvRowStride, int uvPixelStride, long timestampNs)

Parameters

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.

timestampNs long

The timestamp the frame was captured at in nanoseconds.

SetupCameraFrameForwarder(CameraFrameForwarder, Resolution)

Sets the camera frame forwarder.

public virtual void SetupCameraFrameForwarder(CameraFrameForwarder cameraFrameForwarder, Resolution textureResolution)

Parameters

cameraFrameForwarder CameraFrameForwarder
textureResolution Resolution