コード例 #1
0
        void AcquireData(byte[] buffer, BvhDataHeader header)
        {
            int requiredSize = (int)header.DataCount * sizeof(float);

            if (pinnedHeader == IntPtr.Zero || dataSize < requiredSize)
            {
                ReleaseData();
                pinnedData = Marshal.AllocHGlobal(requiredSize);
                dataSize   = requiredSize;
            }

            Marshal.Copy(buffer, 64, pinnedData, requiredSize);
        }
コード例 #2
0
        public void DoReceive()
        {
            while (!exitFlag)
            {
                int recvSize = 0;
                try
                {
                    Receive(recvBuffer, recvBufferSize, out recvSize, 0);
                }
                catch (Exception ex)
                {
                    Debug.Log("thread will stop in next fame: \r\n" + ex.StackTrace);
                }

                if (reserveBuffer == null)
                {
                    reserveBuffer = new byte[reserveBufferSize];
                }

                Buffer.BlockCopy(recvBuffer, 0, reserveBuffer, reserveSize, recvSize);
                reserveSize += recvSize;

                if (reserveSize >= headerSize)
                {
                    BvhDataHeader header = AcquireHeader(reserveBuffer);
                    if (ValidateHeader(header))
                    {
                        // check complete packet
                        int packetSize = headerSize + (int)header.DataCount * sizeof(float);
                        //Debug.LogFormat( "reserveSize {0} >= {1} packetSize", reserveSize, packetSize );
                        if (reserveSize >= packetSize)
                        {
                            //Debug.LogWarningFormat( "received packet received size = {0}", reserveSize );
                            if (NeuronDataReader.frameDataReceivedCallback != null)
                            {
                                AcquireData(reserveBuffer, header);
                                NeuronDataReader.frameDataReceivedCallback(IntPtr.Zero, GetHashValue(), pinnedHeader, pinnedData);
                            }

                            // clean reserveBuffer
                            Buffer.BlockCopy(reserveBuffer, packetSize, reserveBuffer, 0, reserveSize - packetSize);
                            reserveSize -= packetSize;
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("Invalid packet HeadToken = {0} TailToken = {1} received size = {2}", header.Token1.ToString("X4"), header.Token2.ToString("X4"), recvSize);
                    }
                }
            }
        }
コード例 #3
0
 bool ValidateHeader(BvhDataHeader header)
 {
     return(header.Token1 == 0xDDFF && header.Token2 == 0xEEFF);
 }