/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using AOT; using System; using UnityEngine; /// Manage the life cycle of the entire rgb camera. internal class NRRgbCamera : NativeCameraProxy { /// The identifier. public new static string ID = "NRRgbCamera"; /// Gets the resolution. /// The resolution. public override NativeResolution Resolution { get { #if !UNITY_EDITOR NativeResolution resolution = NRFrame.GetDeviceResolution(NativeDevice.RGB_CAMERA); #else NativeResolution resolution = new NativeResolution(1280, 720); #endif return resolution; } } #if !UNITY_EDITOR public NRRgbCamera() : base(new NativeCamera()) { } #else /// Default constructor. public NRRgbCamera() : base(new EditorCameraDataProvider()) { } #endif /// Initializes this object. public override void Initialize() { base.Initialize(); RegistCaptureCallback(RGBCameraCapture); } /// /// RGB camera capture callback for native layer. Note: Here must be static to avoid function /// pointer lost in native layer. /// . /// . /// . [MonoPInvokeCallback(typeof(CameraImageCallback))] public static void RGBCameraCapture(UInt64 camera_handle, UInt64 camera_image_handle, UInt64 userdata) { var controller = CameraProxyFactory.GetInstance(NRRgbCamera.ID); if (controller == null) { NRDebugger.Error("[NRRgbCamera] get controller instance faild."); return; } controller.UpdateFrame(camera_handle, camera_image_handle, userdata); } /// Updates the frame. /// Handle of the camera. /// Handle of the camera image. /// The userdata. public override void UpdateFrame(UInt64 camera_handle, UInt64 camera_image_handle, UInt64 userdata) { int RawDataSize = 0; this.CameraDataProvider.GetRawData(camera_image_handle, (int)NativeDevice.RGB_CAMERA, ref this.m_TexturePtr, ref RawDataSize); var timestamp = this.CameraDataProvider.GetHMDTimeNanos(camera_image_handle, (int)NativeDevice.RGB_CAMERA); this.QueueFrame(this.m_TexturePtr, RawDataSize, timestamp); this.CameraDataProvider.DestroyImage(camera_image_handle); } } }