using System; using System.Runtime.InteropServices; using AOT; using Rokid.UXR.Module; using UnityEngine; using Rokid.UXR.Utility; namespace Rokid.UXR.Native { public partial class NativeInterface { /// /// The update of camera preview data. /// width, height, result, timestamp /// [Obsolete("Use NativeInterface.NativeAPI.OnCameraDataUpdate instead")] public static event Action OnCameraDataUpdate; public static partial class NativeAPI { /// /// The update of camera preview data. /// width, height, result, timestamp /// public static event Action OnCameraDataUpdate; /// /// Start camera preview /// public static void StartCameraPreview() { if (Utils.IsAndroidPlatfrom()) startCameraPreview(); } /// /// Sets the type of camera preview data type /// /// 1-ARGB,2-NV21 public static void SetCameraPreviewDataType(int dataType) { if (Utils.IsAndroidPlatfrom()) setOnCameraDataUpdate(OnCameraDataUpdateCallByC, dataType); } /// /// Stop camera preview /// public static void StopCameraPreview() { if (Utils.IsAndroidPlatfrom()) stopCameraPreview(); } /// /// Clean up camera data updates /// public static void ClearCameraDataUpdate() { if (Utils.IsAndroidPlatfrom()) clearOnCameraDataUpdate(); } /// /// Whether the glasses support the camera /// /// public static bool IsSupportCamera() { return FuncDeviceCheck.CheckCameraFunc(); } /// /// Preview or not /// /// public static bool IsPreviewing() { if (Application.platform == RuntimePlatform.Android) return Api.isPreviewing(); return false; } /// /// Get preview width /// /// public static int GetPreviewWidth() { if (Utils.IsAndroidPlatfrom()) { int[] dimen = new int[2]; Api.getPreviewDimen(dimen); return dimen[0]; } return 0; } /// /// Get preview height /// /// public static int GetPreivewHeight() { if (Utils.IsAndroidPlatfrom()) { int[] dimen = new int[2]; Api.getPreviewDimen(dimen); return dimen[1]; } return 0; } /// /// Get fx,fy /// /// public static void GetFocalLength(float[] data) { if (Utils.IsAndroidPlatfrom()) getFocalLength(data); } /// /// Get cx,cy /// /// public static void GetPrincipalPoint(float[] data) { if (Utils.IsAndroidPlatfrom()) getPrincipalPoint(data); } /// /// Get width,height /// /// public static void GetImageDimensions(int[] data) { if (Utils.IsAndroidPlatfrom()) getImageDimensions(data); } /// /// pinhole:k1,k2,k3,p1,p2 /// fisheye:alpha,k1,k2,k3,k4; /// /// public static void GetDistortion(float[] data) { if (Utils.IsAndroidPlatfrom()) getDistortion(data); } /// /// Get the YPR angles of the camera, /// represented as an array of length 3 in the order [yaw, pitch, roll]. /// /// public static void GetCameraYPR(float[] data) { if (Utils.IsAndroidPlatfrom()) getCameraYPR(data); } #region NativeInterface [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void startCameraPreview(); delegate void OnCameraDataUpdateC(IntPtr ptr, int size, ushort width, ushort height, long timestamp); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void setOnCameraDataUpdate(OnCameraDataUpdateC cb, int type); [MonoPInvokeCallback(typeof(OnCameraDataUpdateC))] static void OnCameraDataUpdateCallByC(IntPtr ptr, int size, ushort width, ushort height, long timestamp) { byte[] result = new byte[size]; Marshal.Copy(ptr, result, 0, size); NativeAPI.OnCameraDataUpdate?.Invoke(width, height, result, timestamp); OnCameraDataUpdate?.Invoke(width, height, result, timestamp); } [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void stopCameraPreview(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void clearOnCameraDataUpdate(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getFocalLength(float[] data); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getPrincipalPoint(float[] data); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getImageDimensions(int[] data); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getDistortion(float[] data); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getCameraYPR(float[] data); #endregion } } }