123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
-
- namespace NRKernal
- {
- using System;
- using System.Runtime.InteropServices;
-
- internal partial class NativeCamera : ICameraDataProvider
- {
-
- private UInt64 m_NativeCameraHandle;
- private bool _IsErrorState = false;
-
-
- public bool Create()
- {
- _IsErrorState = false;
- var result = NativeApi.NRRGBCameraCreate(ref m_NativeCameraHandle);
- NativeErrorListener.Check(result, this, "Create", true);
- return result == NativeResult.Success;
- }
-
-
-
-
-
-
- public bool GetRawData(UInt64 imageHandle, int eye, ref IntPtr ptr, ref int size)
- {
- if (_IsErrorState)
- {
- return false;
- }
- uint data_size = 0;
- var result = NativeApi.NRRGBCameraImageGetRawData(m_NativeCameraHandle, imageHandle, ref ptr, ref data_size);
- size = (int)data_size;
- NativeErrorListener.Check(result, this, "GetRawData");
- return result == NativeResult.Success;
- }
-
-
-
-
- public NativeResolution GetResolution(UInt64 imageHandle, int eye)
- {
- NativeResolution resolution = new NativeResolution(0, 0);
- var result = NativeApi.NRRGBCameraImageGetResolution(m_NativeCameraHandle, imageHandle, ref resolution);
- NativeErrorListener.Check(result, this, "GetResolution");
- return resolution;
- }
-
-
-
-
- public UInt64 GetHMDTimeNanos(UInt64 imageHandle, int eye)
- {
- UInt64 time = 0;
- NativeApi.NRRGBCameraImageGetHMDTimeNanos(m_NativeCameraHandle, imageHandle, ref time);
- return time;
- }
-
-
-
-
- public UInt32 GetExposureTime(UInt64 imageHandle, int eye)
- {
- UInt32 exposureTime = 0;
- return exposureTime;
- }
-
-
-
-
- public UInt32 GetGain(UInt64 imageHandle, int eye)
- {
- UInt32 gain = 0;
- return gain;
- }
-
-
-
-
- public bool SetCaptureCallback(CameraImageCallback callback, UInt64 userdata = 0)
- {
- if (_IsErrorState)
- {
- return false;
- }
- var result = NativeApi.NRRGBCameraSetCaptureCallback(m_NativeCameraHandle, callback, userdata);
- NativeErrorListener.Check(result, this, "SetCaptureCallback");
- return result == NativeResult.Success;
- }
-
-
-
- public bool SetImageFormat(CameraImageFormat format)
- {
- if (_IsErrorState)
- {
- return false;
- }
- var result = NativeApi.NRRGBCameraSetImageFormat(m_NativeCameraHandle, format);
- NativeErrorListener.Check(result, this, "SetImageFormat");
- return result == NativeResult.Success;
- }
-
-
- public bool StartCapture()
- {
- if (_IsErrorState)
- {
- NativeErrorListener.Check(NativeResult.RGBCameraDeviceNotFind, this, "StartCapture", true);
- return false;
- }
- var result = NativeApi.NRRGBCameraStartCapture(m_NativeCameraHandle);
- _IsErrorState = (result != NativeResult.Success);
- NativeErrorListener.Check(result, this, "StartCapture", true);
- return result == NativeResult.Success;
- }
-
-
- public bool StopCapture()
- {
- if (_IsErrorState)
- {
- return false;
- }
- var result = NativeApi.NRRGBCameraStopCapture(m_NativeCameraHandle);
- NativeErrorListener.Check(result, this, "StopCapture", true);
- return result == NativeResult.Success;
- }
-
-
-
- public bool DestroyImage(UInt64 imageHandle)
- {
- if (_IsErrorState)
- {
- return false;
- }
- var result = NativeApi.NRRGBCameraImageDestroy(m_NativeCameraHandle, imageHandle);
- NativeErrorListener.Check(result, this, "DestroyImage");
- return result == NativeResult.Success;
- }
-
-
- public bool Release()
- {
- _IsErrorState = false;
- var result = NativeApi.NRRGBCameraDestroy(m_NativeCameraHandle);
- NativeErrorListener.Check(result, this, "Release");
- return result == NativeResult.Success;
- }
-
- private struct NativeApi
- {
-
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraImageGetRawData(UInt64 rgb_camera_handle,
- UInt64 rgb_camera_image_handle, ref IntPtr out_image_raw_data, ref UInt32 out_image_raw_data_size);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraImageGetResolution(UInt64 rgb_camera_handle,
- UInt64 rgb_camera_image_handle, ref NativeResolution out_image_resolution);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraImageGetHMDTimeNanos(
- UInt64 rgb_camera_handle, UInt64 rgb_camera_image_handle,
- ref UInt64 out_image_hmd_time_nanos);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraCreate(ref UInt64 out_rgb_camera_handle);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraDestroy(UInt64 rgb_camera_handle);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- public static extern NativeResult NRRGBCameraSetCaptureCallback(
- UInt64 rgb_camera_handle, CameraImageCallback image_callback, UInt64 userdata);
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraSetImageFormat(
- UInt64 rgb_camera_handle, CameraImageFormat format);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraStartCapture(UInt64 rgb_camera_handle);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraStopCapture(UInt64 rgb_camera_handle);
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRRGBCameraImageDestroy(UInt64 rgb_camera_handle,
- UInt64 rgb_camera_image_handle);
- };
- }
- }
|