// %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.Runtime.InteropServices; namespace UnityEngine.XR.MagicLeap { public sealed partial class MLEyeCamera : MLAutoAPISingleton { /// /// The maximum number of eye camera frames. /// public const int MaxFrameCount = 4; /// /// The enumerated value representing which eye cameras are currently active. /// /// public static MLEyeCameraIdentifier ActiveCameras => (MLEyeCameraIdentifier)Instance.settings.Cameras; /// /// The number of active eye cameras. /// /// public static int ActiveCamerasCount { get { int count = 0; if (ActiveCameras.HasFlag(MLEyeCameraIdentifier.LeftTemple)) count++; if (ActiveCameras.HasFlag(MLEyeCameraIdentifier.LeftNasal)) count++; if (ActiveCameras.HasFlag(MLEyeCameraIdentifier.RightNasal)) count++; if (ActiveCameras.HasFlag(MLEyeCameraIdentifier.RightTemple)) count++; return count; } } /// /// Converts an image frame data pointer into a byte array. /// /// The associated eye camera frame buffer for an eye camera. /// The image data from the native eye camera data as a byte array. public static void CopyImageFrameDataToByteArray(EyeCameraFrameBuffer imageFrame, ref byte[] byteArray) => Marshal.Copy(imageFrame.Data, byteArray, 0, byteArray.Length); /// /// Polls for Frames. Returns EyeCameraData with this latest data when available. /// If there are no new camera frames within the timeout_ms duration then the API will return MLResult_Timeout. /// /// Eye camera data to be output. /// Timeout in milliseconds. /// /// MLResult.Result will be MLResult.Code.Ok if succesfully fetched the camera frames and released the native data. /// 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. /// public static MLResult GetLatestCameraData(out EyeCameraData outData, UInt64 timeoutMS) => Instance.InternalMLEyeCameraGetLatestCameraData(out outData, timeoutMS); /// /// Update the eye camera settings. /// /// The specific eye cameras that will be active with the updated settings. /// /// 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. /// public static MLResult UpdateSettings(MLEyeCameraIdentifier cameras) => Instance.InternalMLEyeCameraUpdateSettings(cameras); } }