using System;
using System.Linq;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.MagicLeap
{
public sealed partial class MLEyeCamera
{
public readonly struct EyeCameraData
{
public readonly byte FrameCount;
public readonly EyeCameraFrame[] Frames;
internal EyeCameraData(NativeBindings.MLEyeCameraData eyeCameraData)
{
FrameCount = eyeCameraData.FrameCount;
var size = Marshal.SizeOf(typeof(EyeCameraFrame));
Frames = new EyeCameraFrame[FrameCount];
for (int i = 0; i < FrameCount; i++)
{
IntPtr ins = new IntPtr(eyeCameraData.Frames.ToInt64() + i * size);
Frames[i] = Marshal.PtrToStructure<EyeCameraFrame>(ins);
}
}
}
public readonly struct EyeCameraFrameBuffer
{
public readonly uint Width;
public readonly uint Height;
public readonly uint Stride;
public readonly uint BytesPerPixel;
public readonly uint PixelStride;
public readonly uint Size;
public readonly IntPtr Data;
internal EyeCameraFrameBuffer(NativeBindings.MLEyeCameraFrameBuffer eyeCameraFrameBuffer)
{
Width = eyeCameraFrameBuffer.Width;
Height = eyeCameraFrameBuffer.Height;
Stride = eyeCameraFrameBuffer.Stride;
BytesPerPixel = eyeCameraFrameBuffer.BytesPerPixel;
PixelStride = eyeCameraFrameBuffer.PixelStride;
Size = eyeCameraFrameBuffer.Size;
Data = eyeCameraFrameBuffer.Data;
}
}
public readonly struct EyeCameraFrame
{
public readonly MLEyeCameraIdentifier CameraID;
public readonly long FrameNumber;
public readonly long TimeStamp;
public readonly EyeCameraFrameBuffer FrameBuffer;
internal EyeCameraFrame(NativeBindings.MLEyeCameraFrame eyeCameraFrame)
{
CameraID = eyeCameraFrame.CameraID;
FrameNumber = eyeCameraFrame.FrameNumber;
TimeStamp = eyeCameraFrame.TimeStamp;
FrameBuffer = new EyeCameraFrameBuffer(eyeCameraFrame.FrameBuffer);
}
}
}
}