// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022-2023 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using System; using System.Linq; using System.Runtime.InteropServices; namespace UnityEngine.XR.MagicLeap { public sealed partial class MLEyeCamera { public readonly struct EyeCameraData { /// /// Number of camera frames. /// public readonly byte FrameCount; /// /// Camera frame data. The number of frames is specified by FrameCount. /// public readonly EyeCameraFrame[] Frames; internal EyeCameraData(NativeBindings.MLEyeCameraData eyeCameraData) { FrameCount = eyeCameraData.FrameCount; // marshal unmanaged array to struct array 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(ins); } } } public readonly struct EyeCameraFrameBuffer { /// /// Width of the output image in pixels. /// public readonly uint Width; /// /// Height of the output image in pixels. /// public readonly uint Height; /// /// Stride of the output image in bytes. /// public readonly uint Stride; /// /// Number of bytes used to represent a pixel. /// public readonly uint BytesPerPixel; /// /// Distance between 2 consecutive pixels in bytes. /// public readonly uint PixelStride; /// /// Number of bytes in the image output data. /// public readonly uint Size; /// /// Image data. /// 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 { /// /// Camera Identifier specifies which camera is associated with this frame. /// public readonly MLEyeCameraIdentifier CameraID; /// /// A 64bit integer to index the frame number associated with this frame. /// public readonly long FrameNumber; /// /// Frame timestamp specifies the time at which the frame was captured. /// public readonly long TimeStamp; /// /// Frame buffer data. /// public readonly EyeCameraFrameBuffer FrameBuffer; internal EyeCameraFrame(NativeBindings.MLEyeCameraFrame eyeCameraFrame) { CameraID = eyeCameraFrame.CameraID; FrameNumber = eyeCameraFrame.FrameNumber; TimeStamp = eyeCameraFrame.TimeStamp; FrameBuffer = new EyeCameraFrameBuffer(eyeCameraFrame.FrameBuffer); } } } }