// %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% namespace UnityEngine.XR.MagicLeap { /// /// APIs for accessing Camera Device and to do Camera Capture. /// public partial class MLCameraBase { #region Events /// /// Camera status callback, device available. /// public static event MLCamera.OnDeviceAvailabilityStatusDelegate OnDeviceAvailable { add { internalOnDeviceAvailable += value; if (GetDeviceAvailabilitySubscriberCount() > 0) { InternalInitialize(); } } remove { internalOnDeviceAvailable -= value; if (GetDeviceAvailabilitySubscriberCount() == 0) { InternalUninitialize(); } } } /// /// Camera status callback, device unavailable. /// public static event MLCamera.OnDeviceAvailabilityStatusDelegate OnDeviceUnavailable { add { internalOnDeviceUnavailable += value; if (GetDeviceAvailabilitySubscriberCount() > 0) { InternalInitialize(); } } remove { internalOnDeviceUnavailable -= value; if (GetDeviceAvailabilitySubscriberCount() == 0) { InternalUninitialize(); } } } /// /// Callback is invoked when the camera stops streaming. /// public event MLCamera.OnDeviceStatusDelegate OnDeviceIdle; /// /// Callback is invoked when the camera is streaming. /// public event MLCamera.OnDeviceStatusDelegate OnDeviceStreaming; /// /// Callback is invoked when the camera is disconnected. /// public event MLCamera.OnDeviceDisconnectedDelegate OnDeviceDisconnected; /// /// Camera status callback, device error. /// public event MLCamera.OnDeviceErrorDelegate OnDeviceError; /// /// Callback is invoked when a capture has failed when the camera device /// failed to produce a capture result for the request. /// public event MLCamera.OnCaptureFailedDelegate OnCaptureFailed; /// /// Callback is invoked when an ongoing video or preview capture or both /// are aborteddue to an error. /// public event MLCamera.OnCaptureAbortedDelegate OnCaptureAborted; /// /// Callback is invoked when capturing single frame is completed and result is available. /// public event MLCamera.OnCaptureCompletedDelegate OnCaptureCompleted; /// /// Callback is invoked when a preview video frame buffer is available with MLCamera.CaptureType.Preview. /// Not valid for MR/VR Capture since it does not have preview support. /// #pragma warning disable CS0067 public event MLCamera.OnPreviewCaptureCompletedDelegate OnPreviewCaptureCompleted; #pragma warning restore CS0067 /// /// Callback is invoked when a captured image buffer is available. /// public event MLCamera.OnCapturedFrameAvailableDelegate OnRawImageAvailable; /// /// Callback is invoked when a captured raw/compressed video frame buffer is available, invoked on the main thread. /// public event MLCamera.OnCapturedFrameAvailableDelegate OnRawVideoFrameAvailable; /// /// Camera capture callback, capture raw video frame, invoked on the same thread as the native callback, /// allowing the use of the unmanaged native pointer to the frame data memory. /// public event MLCamera.OnCapturedFrameAvailableDelegate OnRawVideoFrameAvailable_NativeCallbackThread; /// /// Callback is invoked when a captured preview frame buffer is available, invoked on the main thread. /// public event MLCamera.OnPreviewBufferAvailableDelegate OnPreviewBufferAvailable; public delegate void OnDeviceAvailabilityStatusDelegate(Identifier camId); /// /// Delegate to notify the app about camera device status (idle or streaming) /// public delegate void OnDeviceStatusDelegate(); /// /// Delegate to notify the app about camera device error /// /// Error code public delegate void OnDeviceErrorDelegate(ErrorType error); /// /// Delegate to notify the app when the camera device disconnects. /// /// Disconnect reason public delegate void OnDeviceDisconnectedDelegate(DisconnectReason reason); /// /// Delegate to notify the app when a capture request fails. /// /// Carries capture result information of current captured frame. public delegate void OnCaptureFailedDelegate(ResultExtras extra); /// /// Delegate to notify the app when a capture request is aborted. /// public delegate void OnCaptureAbortedDelegate(); /// /// Delegate to notify the app when a capture request is completed. /// /// Handle to metadata of captured frame. /// Carries capture result information of current captured frame. public delegate void OnCaptureCompletedDelegate(Metadata metadataHandle, ResultExtras extra); /// /// Delegate to notify the app when the result of a preview capture is available. /// /// Result reporting whether the preview capture completed or not. public delegate void OnPreviewCaptureCompletedDelegate(MLResult result); /// /// Delegate to notify the app when the frame data of a capture is available. /// /// Frame data /// Carries capture result information of current captured frame. public delegate void OnCapturedFrameAvailableDelegate(CameraOutput frameInfo, ResultExtras resultExtras, Metadata metadataHandle); /// /// Delegate to notify the app when the frame data of a preview is available. /// /// Handle to metadata of captured frame. /// Carries capture result information of current captured frame. public delegate void OnPreviewBufferAvailableDelegate(Metadata metadataHandle, ResultExtras extra); protected static MLCamera.OnDeviceAvailabilityStatusDelegate internalOnDeviceAvailable; protected static MLCamera.OnDeviceAvailabilityStatusDelegate internalOnDeviceUnavailable; private static int GetDeviceAvailabilitySubscriberCount() { int deviceAvailableListeners = (internalOnDeviceAvailable != null) ? internalOnDeviceAvailable.GetInvocationList().Length : 0; int deviceUnavailableListeners = (internalOnDeviceUnavailable != null) ? internalOnDeviceUnavailable.GetInvocationList().Length : 0; return deviceAvailableListeners + deviceUnavailableListeners; } #endregion } }