123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- 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
- {
- /// <summary>
- /// The update of camera preview data.
- /// width, height, result, timestamp
- /// </summary>
- [Obsolete("Use NativeInterface.NativeAPI.OnCameraDataUpdate instead")]
- public static event Action<int, int, byte[], long> OnCameraDataUpdate;
- public static partial class NativeAPI
- {
- /// <summary>
- /// The update of camera preview data.
- /// width, height, result, timestamp
- /// </summary>
- public static event Action<int, int, byte[], long> OnCameraDataUpdate;
- /// <summary>
- /// Start camera preview
- /// </summary>
- public static void StartCameraPreview()
- {
- if (Utils.IsAndroidPlatfrom())
- startCameraPreview();
- }
- /// <summary>
- /// Sets the type of camera preview data type
- /// </summary>
- /// <param name="dataType">1-ARGB,2-NV21</param>
- public static void SetCameraPreviewDataType(int dataType)
- {
- if (Utils.IsAndroidPlatfrom())
- setOnCameraDataUpdate(OnCameraDataUpdateCallByC, dataType);
- }
- /// <summary>
- /// Stop camera preview
- /// </summary>
- public static void StopCameraPreview()
- {
- if (Utils.IsAndroidPlatfrom())
- stopCameraPreview();
- }
- /// <summary>
- /// Clean up camera data updates
- /// </summary>
- public static void ClearCameraDataUpdate()
- {
- if (Utils.IsAndroidPlatfrom())
- clearOnCameraDataUpdate();
- }
- /// <summary>
- /// Whether the glasses support the camera
- /// </summary>
- /// <returns></returns>
- public static bool IsSupportCamera()
- {
- return FuncDeviceCheck.CheckCameraFunc();
- }
- /// <summary>
- /// Preview or not
- /// </summary>
- /// <returns></returns>
- public static bool IsPreviewing()
- {
- if (Application.platform == RuntimePlatform.Android)
- return Api.isPreviewing();
- return false;
- }
- /// <summary>
- /// Get preview width
- /// </summary>
- /// <returns></returns>
- public static int GetPreviewWidth()
- {
- if (Utils.IsAndroidPlatfrom())
- {
- int[] dimen = new int[2];
- Api.getPreviewDimen(dimen);
- return dimen[0];
- }
- return 0;
- }
- /// <summary>
- /// Get preview height
- /// </summary>
- /// <returns></returns>
- public static int GetPreivewHeight()
- {
- if (Utils.IsAndroidPlatfrom())
- {
- int[] dimen = new int[2];
- Api.getPreviewDimen(dimen);
- return dimen[1];
- }
- return 0;
- }
- /// <summary>
- /// Get fx,fy
- /// </summary>
- /// <param name="data"></param>
- public static void GetFocalLength(float[] data)
- {
- if (Utils.IsAndroidPlatfrom())
- getFocalLength(data);
- }
- /// <summary>
- /// Get cx,cy
- /// </summary>
- /// <param name="data"></param>
- public static void GetPrincipalPoint(float[] data)
- {
- if (Utils.IsAndroidPlatfrom())
- getPrincipalPoint(data);
- }
- /// <summary>
- /// Get width,height
- /// </summary>
- /// <param name="data"></param>
- public static void GetImageDimensions(int[] data)
- {
- if (Utils.IsAndroidPlatfrom())
- getImageDimensions(data);
- }
- /// <summary>
- /// pinhole:k1,k2,k3,p1,p2
- /// fisheye:alpha,k1,k2,k3,k4;
- /// </summary>
- /// <param name="data"></param>
- public static void GetDistortion(float[] data)
- {
- if (Utils.IsAndroidPlatfrom())
- getDistortion(data);
- }
- /// <summary>
- /// Get the YPR angles of the camera,
- /// represented as an array of length 3 in the order [yaw, pitch, roll].
- /// </summary>
- /// <param name="data"></param>
- 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
- }
- }
- }
|