Example #1
0
		void DepthClient_FrameReady(object sender, FrameReadyEventArgs e)
		{
			DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
			DepthFrameData dfd = new DepthFrameData();

			MemoryStream ms = new MemoryStream(e.Data);
			BinaryReader br = new BinaryReader(ms);

			dfd.PlayerIndexBitmask = br.ReadInt32();
			dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

			DepthImageFrame frame = br.ReadDepthImageFrame();
			dfd.ImageFrame = frame;

			int dataLength = (int)(ms.Length - ms.Position);

			if(_depthShort == null || _depthShort.Length != dataLength / 2)
				_depthShort = new short[dataLength / 2];

			Buffer.BlockCopy(e.Data, (int)br.BaseStream.Position, _depthShort, 0, dataLength);

			dfd.DepthData = _depthShort;

			DepthFrame = dfd;
			args.DepthFrame = dfd;

			if(DepthFrameReady != null)
				DepthFrameReady(this, args);
		}
Example #2
0
        private async void DepthThread()
        {
            try {
                short[] depthShort = null;

                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
                    BinaryReader br = new BinaryReader( ms );

                    DepthFrameData dfd = new DepthFrameData();
                    dfd.PlayerIndexBitmask = br.ReadInt32();
                    dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

                    DepthImageFrame frame = br.ReadDepthImageFrame();
                    dfd.ImageFrame = frame;

                    int dataLength = (int)(ms.Length - ms.Position);

                    if ( depthShort == null || depthShort.Length != dataLength / 2 )
                        depthShort = new short[dataLength / 2];

                    Buffer.BlockCopy( bytes, (int)br.BaseStream.Position, depthShort, 0, dataLength );

                    dfd.DepthData = depthShort;

                    DepthFrame = dfd;

                    DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
                    args.DepthFrame = dfd;

                    Context.Send( delegate
                    {
                        if ( DepthFrameReady != null )
                            DepthFrameReady( this, args );
                    }, null );
                }
            }
            catch ( IOException ) {
                Disconnect();
            }
        }
Example #3
0
		private void DepthThread()
		{
			try
			{
				NetworkStream ns = Client.GetStream();
				BinaryReader networkReader = new BinaryReader(ns);
				short[] depthShort = null;

				while(Client.Connected)
				{
					DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
					DepthFrameData dfd = new DepthFrameData();

					int size = networkReader.ReadInt32();
					byte[] data = networkReader.ReadBytes(size);

					MemoryStream ms = new MemoryStream(data);
					BinaryReader br = new BinaryReader(ms);

					dfd.PlayerIndexBitmask = br.ReadInt32();
					dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

					DepthImageFrame frame = br.ReadDepthImageFrame();
					dfd.ImageFrame = frame;

					int dataLength = (int)(ms.Length - ms.Position);

					if(depthShort == null || depthShort.Length != dataLength / 2)
						depthShort = new short[dataLength / 2];

					Buffer.BlockCopy(data, (int)br.BaseStream.Position, depthShort, 0, dataLength);

					dfd.DepthData = depthShort;

					DepthFrame = dfd;
					args.DepthFrame = dfd;

					Context.Send(delegate
					{
						if(DepthFrameReady != null)
							DepthFrameReady(this, args);
					}, null);
				}
			}
			catch(IOException)
			{
				Client.Close();
			}
		}