// %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% namespace UnityEngine.XR.MagicLeap { using System; using System.Runtime.InteropServices; /// /// MLEyeCamera class exposes static functions to query eye camera related /// functions. Most functions are currently a direct pass through functions to the /// native C-API functions and incur no overhead. /// public sealed partial class MLEyeCamera { /// /// See ml_eye_camera.h for additional comments. /// internal partial class NativeBindings : Native.MagicLeapNativeBindings { /// /// A structure to encapsulate the camera settings. /// [StructLayout(LayoutKind.Sequential)] public readonly struct MLEyeCameraSettings { /// /// Version of this structure. /// public readonly uint Version; /// /// Eye cameras that need to be enabled. /// See MLEyeCameraIdentifier for more details. /// If you want to request frames from different eye camera then "OR" the cameras of interest to the app. /// public readonly uint Cameras; internal MLEyeCameraSettings(uint version, MLEyeCameraIdentifier cameras) { Version = version; Cameras = (uint)cameras; } } /// /// A structure to encapsulate per plane info for each camera frame. /// [StructLayout(LayoutKind.Sequential)] public readonly struct MLEyeCameraFrameBuffer { /// /// 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; } /// /// A structure to encapsulate all the eye camera data. /// [StructLayout(LayoutKind.Sequential)] public readonly struct MLEyeCameraData { /// /// version contains the version number for this structure. /// public readonly uint Version; /// /// Number of camera frames. /// public readonly byte FrameCount; /// /// Camera frame data. The number of frames is specified by FrameCount. /// public readonly IntPtr Frames; internal MLEyeCameraData(uint version) { Version = version; FrameCount = 0; Frames = IntPtr.Zero; } } /// /// A structure to encapsulate output data for each camera sensor. /// [StructLayout(LayoutKind.Sequential)] public readonly struct MLEyeCameraFrame { /// /// 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 MLEyeCameraFrameBuffer FrameBuffer; } /// /// Brief connect to eye camera(s). /// /// A pointer to MLEyeCameraSettings structure. /// A pointer to camera handle to be used in later APIs. /// /// MLResult.Result will be MLResult.Code.Ok if connected to camera device(s) successfully. /// MLResult.Result will be MLResult.Code.LicenseError if necessary license is missing. /// MLResult.Result will be MLResult.Code.InvalidParam if one of the parameters is invalid. /// MLResult.Result will be MLResult.Code.PermissionDenied if the necessary permission is missing. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed with an unspecified error. /// /// apilevel 26. permissions android.permission.EYE_CAMERA (protection level: dangerous) [DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLEyeCameraConnect(ref MLEyeCameraSettings setting, ref ulong outHandle); /// /// Update the eye camera settings. /// /// Camera handle obtained from MLEyeCameraConnect. /// Pointer to MLEyeCameraSettings. /// /// MLResult.Result will be MLResult.Code.Ok if the settings updated successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if one of the parameters is invalid. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed due to an internal error. /// [DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLEyeCameraUpdateSettings(ulong handle, ref MLEyeCameraSettings settings); /// /// Poll for Frames. Returns MLEyeCameraData with this latest data when available. /// The memory is owned by the system. /// Application should copy the data it needs to cache and release the memory by calling MLEyeCameraReleaseCameraData. /// This is a blocking call. API is not thread safe. /// If there are no new camera frames within the timeout_ms duration then the API will return MLResult_Timeout. /// /// Camera handle obtained from MLEyeCameraConnect. /// Timeout in milliseconds. /// Eye camera data. Will be set to NULL if no valid data is available at this time. /// /// MLResult.Result will be MLResult.Code.Ok if camera frames fetched successfully. /// MLResult.Result will be MLResult.Code.Timeout returned because no new frame available at this time. /// MLResult.Result will be MLResult.Code.InvalidParam if one of the parameters is invalid. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed due to an internal error. /// /// apilevel 26. permissions None. [DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLEyeCameraGetLatestCameraData(ulong handle, UInt64 timeoutMS, ref MLEyeCameraData outData); /// /// Releases specified #MLEyeCameraData object. /// This function should be called exactly once for each call to #MLEyeCameraGetLatestCameraData. /// MLEyeCameraData will be over-written when new data is available. /// /// Camera handle obtained from MLEyeCameraConnect. /// Pointer to a valid MLEyeCameraData object. /// /// MLResult.Result will be MLResult.Code.Ok if successfully released eye camera data. /// MLResult.Result will be MLResult.Code.InvalidParam if eyeCameraData parameter was not valid (NULL). /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed due to an internal error. /// /// permissions None. [DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLEyeCameraReleaseCameraData(ulong handle, ref MLEyeCameraData eyeCameraData); /// /// Disconnect from eye camera(s). This will disconnect from all the eye camera(s) currently connected. /// /// Camera handle obtained from MLEyeCameraConnect. /// /// MLResult.Result will be MLResult.Code.Ok if disconnected camera(s) successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if invalid context. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed to disconnect camera(s). /// /// apilevel 26. permissions None. [DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLEyeCameraDisconnect(ulong handle); } } }