// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) (2018-2024) 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% // Disable warnings about missing documentation for native interop. #pragma warning disable 1591 namespace UnityEngine.XR.MagicLeap { using System; using System.Runtime.InteropServices; /// /// MLCamera class exposes static functions to query camera related /// functions. Most functions are currently a direct pass through functions to the /// native C-API functions and incur no overhead. /// public partial class MLCameraBase { /// /// This class defines the C# interface to the C functions/structures in "ml_camera.h". /// internal partial class NativeBindings : Native.MagicLeapNativeBindings { /// /// Number of MLCamera image planes. /// public const int MLCameraMaxImagePlanes = 3; /// /// Default distortion vector size. /// private const int MLCameraMaxDistortionCoefficients = 5; /// /// Max No of streams supported by logical camera /// private const int MLCameraMaxStreams = 2; #region V2 [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraInit(ref MLCameraDeviceAvailabilityStatusCallbacks deviceAvailabilityStatusCallback, IntPtr userData); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraDeInit(); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraConnect(ref MLCameraConnectContext inputContext, out ulong handle); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraGetNumSupportedStreams(ulong handle, out uint numSupportedStreams); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraGetStreamCaps(ulong contextHandle, uint streamIndex, ref uint numStreamCaps, IntPtr streamCaps); /// /// Disconnect from camera device. /// /// Capture operation type. /// /// MLResult.Result will be MLResult.Code.Ok if disconnected from camera device successfully. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraDisconnect(ulong contextHandle); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraPreCaptureAEAWB(ulong contextHandle); /// /// Prepare for capture. /// This API prepares capture per specified MLCamera.CaptureType by creating /// a capture request, and a handle to which is returned to the user, who can choose /// to manipulate the request data(metadata) via APIs defined in ml_camera_metadata.h /// before performing the capture. /// Shall be called after MLCameraConnect(). /// /// Context obtained from MLCameraConnect. /// Capture configuration. /// Handle to the capture metadata. Only valid if result is MLResult_Ok. /// /// MLResult.Result will be MLResult.Code.Ok if prepared for capture successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to prepare for capture due to an invalid parameter. /// MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to prepare for capture due to null pointer. /// MLResult.Result will be MLResult.Code.BadType if failed to prepare for capture due to null pointer. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraPrepareCapture(ulong contextHandle, ref MLCameraCaptureConfig config, out ulong metadataHandle); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraUpdateCaptureSettings(ulong contextHandle); /// /// Set the client-implemented callbacks to convey camera device status. /// Client needs to implement the callbacks defined by MLCameraDeviceStatusCallbacks. /// The library passes the camera device status to the client via those callbacks. /// Shall be called before MLCameraConnect(). /// /// Capture status callbacks. /// User metadata. /// /// MLResult.Result will be MLResult.Code.Ok if callbacks were set successfully. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraSetDeviceStatusCallbacks(ulong contextHandle, ref MLCameraDeviceStatusCallbacks deviceStatusCallbacks, IntPtr data); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraSetCaptureCallbacks(ulong handle, ref MLCameraCaptureCallbacks captureCallbacks, IntPtr data); /// /// The output image will be returned in capture callback on_image_buffer_available /// /// Context obtained from MLCameraConnect. /// no of images to capture valid range is 1-10. /// /// MLResult.Result will be MLResult.Code.Ok if image was captured successfully. /// MLResult.Result will be MLResult.Code.MediaGenericInvalidOperation if failed to capture image due to on-going video recording. /// MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to capture image due to null pointer. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to capture image due to an invalid parameter. /// MLResult.Result will be MLResult.Code.Timeout if failed to capture image due to timeout. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern MLResult.Code MLCameraCaptureImage(ulong contextHandle, uint numImages); /// /// Start video capture and save output to a file. /// The captured video and audio streams will be encoded with AVC and AAC codecs /// and packed in mp4 container format and stored into the file specified by the /// file path.The library is responsible for opening and closing the file.The /// current supported video resolution is 1080p. /// If this function is invoked before the camera sensor has locked AE and AWB, /// it will be blocked till AE, AWB is locked and then starts to capture. /// MLCameraCaptureVideoStop() needs to be called to stop the capture. /// /// File path to store the output video. /// /// MLResult.Result will be MLResult.Code.Ok if started video recording successfully. /// MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to start video recording due to null pointer. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to start video recording due to invalid input parameter. /// MLResult.Result will be MLResult.Code.Timeout if failed to start video recording image due to timeout. /// MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern MLResult.Code MLCameraCaptureVideoStart(ulong contextHandle); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraCapturePreviewStart(ulong contextHandle); /// /// Stop video capture. /// User should allow some time, i.e., >500ms, after MLCameraCaptureVideoStart and before /// calling this API, as captured frames are being encoded.Otherwise, MLResult_UnspecifiedFailure /// will be returned. /// /// /// MLResult.Result will be MLResult.Code.Ok if stopped video recording successfully. /// MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to stop video recording due to null pointer. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraCaptureVideoStop(ulong contextHandle); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraCapturePreviewStop(ulong contextHandle); /// /// Poll camera device status. /// Use #MLCamera.DeviceStatusFlag to view specific status bit. /// Call MLCameraGetErrorCode() to obtain the error code if /// MLCamera.DeviceStatusFlag.Error bit is set. /// Note: This API can still be used even if MLCameraSetDeviceStatusCallbacks() has been called. /// /// Context obtained from MLCameraConnect. /// Device status. /// /// MLResult.Result will be MLResult.Code.Ok if obtained device status successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain device status due to invalid input parameter. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraGetDeviceStatus(ulong contextHandle, out uint outDeviceStatus); [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] internal static extern MLResult.Code MLCameraGetDeviceAvailabilityStatus(MLCamera.Identifier camId, [MarshalAs(UnmanagedType.I1)] out bool deviceAvailabilityStatus); /// /// Obtain device error code. /// /// Device error code. /// /// MLResult.Result will be MLResult.Code.Ok if obtained device error code successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain device error code due to invalid input parameter. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraGetErrorCode(ulong contextHandle, out MLCamera.ErrorType outErrorCode); /// /// Obtain handle for retrieving camera characteristics. /// This API provides the handle for retrieving camera characteristics via APIs /// defined in ml_camera_metadata.h. /// /// Handle to access camera characteristic metadata. /// /// MLResult.Result will be MLResult.Code.Ok if obtained camera characteristic handle successfully. /// MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain camera characteristic handle due to invalid input parameter. /// MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to capture raw image due to null pointer. /// MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. /// MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing. /// [DllImport(MLCameraDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLCameraGetCameraCharacteristics(ulong contextHandle, out ulong outMetadataHandle); #endregion } } }