private void UninitializeStreams() { Debug.Log("AstraController: Uninitializing streams"); if (_reader1 != null) { _reader1.FrameReady -= FrameReady; _reader2.FrameReady -= FrameReady; _reader3.FrameReady -= FrameReady; _reader4.FrameReady -= FrameReady; _reader5.FrameReady -= FrameReady; _reader1.Dispose(); _reader2.Dispose(); _reader3.Dispose(); _reader4.Dispose(); _reader5.Dispose(); _reader1 = null; _reader2 = null; _reader3 = null; _reader4 = null; _reader5 = null; } if (_streamSet != null) { _streamSet.Dispose(); _streamSet = null; } }
private void UninitializeStreams() { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); Debug.Log("AstraController: Uninitializing streams"); if (_readerDepth != null) { _readerDepth.Dispose(); _readerColor.Dispose(); _readerBody.Dispose(); _readerMaskedColor.Dispose(); _readerColorizedBody.Dispose(); _readerPoint.Dispose(); _readerDepth = null; _readerColor = null; _readerBody = null; _readerMaskedColor = null; _readerColorizedBody = null; _readerPoint = null; } if (_streamSet != null) { _streamSet.Dispose(); _streamSet = null; } }
private void InitializeStreams() { try { _streamSet = Astra.StreamSet.Open(); _reader1 = _streamSet.CreateReader(); _reader1.FrameReady += FrameReady; _reader2 = _streamSet.CreateReader(); _reader2.FrameReady += FrameReady; _reader3 = _streamSet.CreateReader(); _reader3.FrameReady += FrameReady; _reader4 = _streamSet.CreateReader(); _reader4.FrameReady += FrameReady; _reader5 = _streamSet.CreateReader(); _reader5.FrameReady += FrameReady; _depthStream = _reader1.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 60; #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _reader2.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 60; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); _bodyStream = _reader3.GetStream <BodyStream>(); _maskedColorStream = _reader4.GetStream <MaskedColorStream>(); _colorizedBodyStream = _reader5.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
private void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _readerPoint = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 30; #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _pointStream = _readerPoint.GetStream <PointStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
public void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerNV21Color = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; int targetDepthWidth, targetDepthHeight, targetDepthFps; #if ASTRA_UNITY_ANDROID_NATIVE //Deeyea and Dabai doesn't support qqvga and qvga resolution. //use 640*400. if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x60e || _depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x617) { targetDepthWidth = 640; targetDepthHeight = 400; targetDepthFps = 30; } else { targetDepthWidth = 160; targetDepthHeight = 120; targetDepthFps = 30; } #else if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x60e || _depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x617) { targetDepthWidth = 640; targetDepthHeight = 400; targetDepthFps = 30; } else { targetDepthWidth = 320; targetDepthHeight = 240; targetDepthFps = 30; } #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x617) { //for deeyea, set mirror to false to match depth. _colorStream.IsMirroring = false; } #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth, targetColorHeight, targetColorFps; if (_depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x60f || _depthStream.usbInfo.Pid == 0x617) { targetColorWidth = 640; targetColorHeight = 480; targetColorFps = 30; } else { targetColorWidth = 320; targetColorHeight = 240; targetColorFps = 30; } #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); #if ASTRA_UNITY_ANDROID_NATIVE _nv21ColorStream = _readerNV21Color.GetStream <ColorStream>(Astra.Core.StreamSubType.COLOR_NV21_SUBTYPE); if (_nv21ColorStream.IsAvailable) { //COLOR_NV21_SUBTYPE is only available when using astra pro and astra pro plus. colorModes = _nv21ColorStream.AvailableModes; selectedColorMode = colorModes[0]; foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _nv21ColorStream.SetMode(selectedColorMode); if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x617) { //for deeyea, set mirror to false to match depth. _nv21ColorStream.IsMirroring = false; } } else { _readerNV21Color.Dispose(); _readerNV21Color = null; _nv21ColorStream = null; } #endif _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
private void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); _depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = _depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 30; #endif foreach (var m in _depthModes) { Debug.Log("Depth mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond); if (m.Width == targetDepthWidth && m.Height == targetDepthHeight) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); try { _colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = _colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in _colorModes) { Debug.Log("Color mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond); if (m.Width == targetColorWidth && m.Height == targetColorHeight) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); } catch (System.Exception e) { Debug.Log("Couldn't initialize color stream: " + e.ToString()); } _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; Debug.Log("Stream initialize success"); OnInitializeSuccess.Invoke(); } catch (System.Exception e) { Debug.Log("Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); if (_initializeCount > 0) { _initializeCount--; } else { Debug.Log("Initialize failed"); OnInitializeFailed.Invoke(); } } }