123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
-
- namespace NRKernal.Experimental.StreammingCast
- {
- using UnityEngine;
- using NRKernal.Record;
- using System.Collections.Generic;
- using System;
-
- public class NRObserverViewCapture : IDisposable
- {
-
- public NRObserverViewCapture()
- {
- IsRecording = false;
- }
-
- ~NRObserverViewCapture()
- {
- }
-
-
- public static IEnumerable<Resolution> SupportedResolutions
- {
- get
- {
- NativeResolution rgbResolution = new NativeResolution(1280, 720);
- if (NRDevice.Subsystem.IsFeatureSupported(NRSupportedFeature.NR_FEATURE_RGB_CAMERA))
- rgbResolution = NRFrame.GetDeviceResolution(NativeDevice.RGB_CAMERA);
- Resolution stand_resolution = new Resolution()
- {
- width = rgbResolution.width,
- height = rgbResolution.height,
- refreshRate = NativeConstants.RECORD_FPS_DEFAULT,
- };
- yield return stand_resolution;
- Resolution low_resolution = new Resolution()
- {
- width = stand_resolution.width / 2,
- height = stand_resolution.height / 2,
- refreshRate = NativeConstants.RECORD_FPS_DEFAULT,
- };
- yield return low_resolution;
- Resolution high_resolution = new Resolution()
- {
- width = stand_resolution.width * 3 / 2,
- height = stand_resolution.height * 3 / 2,
- refreshRate = NativeConstants.RECORD_FPS_DEFAULT,
- };
- yield return high_resolution;
- }
- }
-
-
-
- public bool IsRecording { get; private set; }
-
- private ObserverViewFrameCaptureContext m_CaptureContext;
-
-
- public ObserverViewFrameCaptureContext GetContext()
- {
- return m_CaptureContext;
- }
-
-
- public Texture PreviewTexture
- {
- get
- {
- return m_CaptureContext?.PreviewTexture;
- }
- }
-
-
-
- public static void CreateAsync(bool showHolograms, OnObserverViewResourceCreatedCallback onCreatedCallback)
- {
- NRObserverViewCapture capture = new NRObserverViewCapture();
- capture.m_CaptureContext = new ObserverViewFrameCaptureContext();
- onCreatedCallback?.Invoke(capture);
- }
-
-
-
-
- public static IEnumerable<int> GetSupportedFrameRatesForResolution(Resolution resolution)
- {
- yield return NativeConstants.RECORD_FPS_DEFAULT;
- }
-
- public void Dispose()
- {
- if (m_CaptureContext != null)
- {
- m_CaptureContext.Release();
- m_CaptureContext = null;
- }
- }
-
-
-
-
- public void StartObserverViewModeAsync(CameraParameters setupParams, AudioState audioState, OnObserverViewModeStartedCallback onVideoModeStartedCallback, bool autoAdaptBlendMode = false)
- {
- setupParams.camMode = CamMode.VideoMode;
-
- if (autoAdaptBlendMode)
- {
- var blendMode = m_CaptureContext.AutoAdaptBlendMode(setupParams.blendMode);
- if (blendMode != setupParams.blendMode)
- {
- NRDebugger.Warning("[VideoCapture] AutoAdaptBlendMode : {0} => {1}", setupParams.blendMode, blendMode);
- setupParams.blendMode = blendMode;
- }
- }
- m_CaptureContext.StartCaptureMode(setupParams);
- var result = new ObserverViewCaptureResult();
- result.resultType = CaptureResultType.Success;
- onVideoModeStartedCallback?.Invoke(result);
- }
-
-
-
- public void StartObserverViewAsync(string ip, OnStartedObserverViewCallback onStartedRecordingVideoCallback)
- {
- var captureResult = new ObserverViewCaptureResult();
- if (IsRecording)
- {
- captureResult.resultType = CaptureResultType.UnknownError;
- onStartedRecordingVideoCallback?.Invoke(captureResult);
- }
- else
- {
- m_CaptureContext.StartCapture(ip, (result) =>
- {
- if (result)
- {
- IsRecording = true;
- captureResult.resultType = CaptureResultType.Success;
- onStartedRecordingVideoCallback?.Invoke(captureResult);
- }
- else
- {
- IsRecording = false;
- captureResult.resultType = CaptureResultType.ServiceIsNotAvailable;
- onStartedRecordingVideoCallback?.Invoke(captureResult);
- }
- });
- }
- }
-
-
- public void StopObserverViewAsync(OnStoppedObserverViewCallback onStoppedRecordingVideoCallback)
- {
- var result = new ObserverViewCaptureResult();
- if (!IsRecording)
- {
- result.resultType = CaptureResultType.UnknownError;
- onStoppedRecordingVideoCallback?.Invoke(result);
- }
- else
- {
- try
- {
- m_CaptureContext.StopCapture();
- }
- catch (Exception e)
- {
- NRDebugger.Info("Stop recording error :" + e.ToString());
- throw;
- }
- IsRecording = false;
- result.resultType = CaptureResultType.Success;
- onStoppedRecordingVideoCallback?.Invoke(result);
- }
- }
-
-
- public void StopObserverViewModeAsync(OnObserverViewModeStoppedCallback onVideoModeStoppedCallback)
- {
- m_CaptureContext.StopCaptureMode();
- var result = new ObserverViewCaptureResult();
- result.resultType = CaptureResultType.Success;
- onVideoModeStoppedCallback?.Invoke(result);
- }
-
- public enum CaptureResultType
- {
-
-
-
- Success,
-
-
-
- ServiceIsNotAvailable,
-
-
-
- UnknownError
- }
-
-
- public enum AudioState
- {
-
-
-
- MicAudio = 0,
-
-
-
- ApplicationAudio = 1,
-
-
-
- ApplicationAndMicAudio = 2,
-
-
-
- None = 3
- }
-
-
- public struct ObserverViewCaptureResult
- {
-
-
- public CaptureResultType resultType;
-
- public long hResult;
-
-
- public bool success
- {
- get
- {
- return resultType == CaptureResultType.Success;
- }
- }
- }
-
-
- public delegate void OnStartedObserverViewCallback(ObserverViewCaptureResult result);
-
-
- public delegate void OnObserverViewResourceCreatedCallback(NRObserverViewCapture captureObject);
-
-
- public delegate void OnObserverViewModeStartedCallback(ObserverViewCaptureResult result);
-
-
- public delegate void OnObserverViewModeStoppedCallback(ObserverViewCaptureResult result);
-
-
-
- public delegate void OnStoppedObserverViewCallback(ObserverViewCaptureResult result);
- }
- }
|