Exemplo n.º 1
0
    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;
        }
    }
Exemplo n.º 2
0
    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;
        }
    }
Exemplo n.º 3
0
    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();
        }
    }