コード例 #1
0
 /// <summary>
 /// Appends to the body stream
 /// </summary>
 /// <returns>The total amount of bytes added</returns>
 public int AppendBody(byte[] value, int offset, int count)
 {
     if (Header == null)
     {
         throw new DriverInternalError("To add a response body you must specify the header");
     }
     if (BodyStream == null)
     {
         if (Header.BodyLength <= count)
         {
             //There is no need to copy the buffer: Use the inner buffer
             BodyStream = new MemoryStream(value, offset, this.Header.BodyLength, false, false);
             return(this.Header.BodyLength);
         }
         BodyStream = new ListBackedStream();
     }
     if (BodyStream.Position + count > Header.BodyLength)
     {
         count = Header.BodyLength - (int)BodyStream.Position;
     }
     BodyStream.Write(value, offset, count);
     return(count);
 }
コード例 #2
0
 /// <summary>
 /// Write a section of a byte array into the message body, without encoding or interpretation.
 /// </summary>
 public IMessageBuilder RawWrite(byte[] bytes, int offset, int length)
 {
     BodyStream.Write(bytes, offset, length);
     return(this);
 }
コード例 #3
0
 /// <summary>
 /// Write a single byte into the message body, without encoding or interpretation.
 /// </summary>
 public IMessageBuilder RawWrite(byte value)
 {
     BodyStream.WriteByte(value);
     return(this);
 }
コード例 #4
0
    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();
        }
    }
コード例 #5
0
    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();
        }
    }
コード例 #6
0
 /// <summary>
 /// Read bytes from the body stream into a section of
 /// an existing byte array, without encoding or
 /// interpretation. Returns the number of bytes read from the
 /// body and written into the target array, which may be less
 /// than the number requested if the end-of-stream is reached.
 /// </summary>
 public int RawRead(byte[] target, int offset, int length)
 {
     return(BodyStream.Read(target, offset, length));
 }
コード例 #7
0
 /// <summary>
 /// Read a single byte from the body stream, without encoding or interpretation.
 /// Returns -1 for end-of-stream.
 /// </summary>
 public int RawRead()
 {
     return(BodyStream.ReadByte());
 }
コード例 #8
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();
        }
    }
 public override void Write(byte[] buffer, int offset, int count)
 {
     BodyStream.Write(buffer, offset, count);
 }
 public override void SetLength(long value)
 {
     BodyStream.SetLength(value);
 }
 public override long Seek(long offset, SeekOrigin origin)
 {
     return(BodyStream.Seek(offset, origin));
 }
 public override int Read(byte[] buffer, int offset, int count)
 {
     return(BodyStream.Read(buffer, offset, count));
 }
 public override void Flush()
 {
     FlusIndex++;
     BodyStream.Flush();
 }
コード例 #14
0
 public void Dispose()
 {
     BodyStream?.Dispose();
 }
コード例 #15
0
ファイル: AstraManager.cs プロジェクト: GabrielCruzT/Teste
    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();
            }
        }
    }
コード例 #16
0
 public byte[] ReadBodyToEnd()
 {
     return(BodyStream.ReadAllBytes());
 }