Class YUVToRGBAConverter
- Namespace
- Uralstech.UXR.QuestCamera
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
-
objectYUVToRGBAConverter
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
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
ComputeBufferThe buffer to copy to.
nativeBufferPtr
nintThe memory to copy from.
nativeBufferSize
intThe 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
nintPointer to the buffer containing Y (luminance) data of the frame.
uBuffer
nintPointer to the buffer containing U (color) data of the frame.
vBuffer
nintPointer to the buffer containing V (color) data of the frame.
ySize
intThe size of
yBuffer
.uSize
intThe size of
uBuffer
.vSize
intThe size of
vBuffer
.yRowStride
intThe size of each row of the image in
yBuffer
in bytes.uvRowStride
intThe size of each row of the image in
uBuffer
andvBuffer
in bytes.uvPixelStride
intThe size of a pixel in a row of the image in
uBuffer
andvBuffer
in bytes.timestamp
longThe 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
intThe size of each row of the image in _yComputeBuffer in bytes.
uvRowStride
intThe size of each row of the image in _uComputeBuffer and _vComputeBuffer in bytes.
uvPixelStride
intThe size of a pixel in a row of the image in _uComputeBuffer and _vComputeBuffer in bytes.
timestampNs
longThe 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
CameraFrameForwardertextureResolution
Resolution