Exemple #1
0
        public void TextCompressBodyFrame()
        {
            DepthFrameData frame = FakeImageData.RandomDepthFrame();

            SnappyFrameCompressor compressor = new SnappyFrameCompressor(KinectFrameInformation.DepthFrame);

            compressor.Compress(frame.DataPointer);

            SnappyFrameDecompressor decompressor = new SnappyFrameDecompressor(KinectFrameInformation.DepthFrame);

            var barray = compressor.CompressedFrameData;

            fixed(byte *bptr = &barray[0])
            {
                decompressor.UnCompress(new IntPtr(bptr), compressor.CompressedSize);
            }

            var decomparray = decompressor.UnCompressedFrameData;

            fixed(byte *bptr = &barray[0])
            {
                FakeImageData.ByteCheck(frame.DataPointer, new IntPtr(bptr), decompressor.UnCompressedSize);
            }

            frame.Dispose();
        }
        private unsafe void ReceiveThread()
        {
            while (this.isRunning)
            {
                if (this.clientStream.DataAvailable)
                {
                    if (this.readHeader)
                    {
                        int p            = this.clientStream.Read(this.header, 0, 5);
                        int packetLength = BitConverter.ToInt32(this.header, 0);
                        this.isDepth = this.header[4] == 0;

                        this.remaining  = packetLength;
                        this.readHeader = false;
                        this.bytesRead  = 0;
                    }

                    try
                    {
                        int totalRead = this.clientStream.Read(this.temporaryData, this.bytesRead, this.remaining);

                        this.bytesRead += totalRead;
                        this.remaining -= totalRead;

                        //Case where we have all the data we need
                        if (totalRead == this.remaining)
                        {
                            fixed(byte *bptr = &this.temporaryData[0])
                            {
                                if (isDepth)
                                {
                                    SnappyFrameDecompressor.Uncompress(new IntPtr(bptr), bytesRead, this.depthData.DataPointer, this.depthData.SizeInBytes);

                                    if (this.depthReceived != null)
                                    {
                                        this.depthReceived(this, new DepthFrameDataEventArgs(this.depthData));
                                    }
                                }
                                else
                                {
                                    SnappyFrameDecompressor.Uncompress(new IntPtr(bptr), bytesRead, this.bodyIndexData.DataPointer, this.bodyIndexData.SizeInBytes);

                                    if (this.bodyIndexReceived != null)
                                    {
                                        this.bodyIndexReceived(this, new BodyIndexFrameDataEventArgs(this.bodyIndexData));
                                    }
                                }
                            }

                            //Wait for next header
                            this.readHeader = true;
                        }
                    }
                    catch
                    {
                        if (this.OnError != null)
                        {
                            this.OnError(this, new EventArgs());
                        }
                    }
                }
                Thread.Sleep(5);
            }
        }