Exemplo n.º 1
0
        internal void UnpackOpusVoicePacket(byte[] plainTextMessage)
        {
            NumPacketsRecv++;
            byte typeByte = plainTextMessage[0];

            //int target = typeByte & 31;
            //Debug.Log("len = " + plainTextMessage.Length + " typeByte = " + typeByte);

            using (var reader = new UdpPacketReader(new MemoryStream(plainTextMessage, 1, plainTextMessage.Length - 1)))
            {
                UInt32 session = 0;
                if (!_mumbleClient.UseLocalLoopBack)
                {
                    session = (uint)reader.ReadVarInt64();
                }
                else
                {
                    session = _mumbleClient.OurUserState.session;
                }

                Int64 sequence = reader.ReadVarInt64();


                //We assume we mean OPUS
                int size = (int)reader.ReadVarInt64();
                //Debug.Log("Seq = " + sequence + " Ses: " + session + " Size " + size + " type= " + typeByte + " tar= " + target);
                bool isLast = (size & 8192) == 8192;
                if (isLast)
                {
                    Debug.Log("Found last byte in seq");
                }

                //Apply a bitmask to remove the bit that marks if this is the last packet
                size &= 0x1fff;

                //Debug.Log("Received sess: " + session);
                //Debug.Log(" seq: " + sequence + " size = " + size + " packetLen: " + plainTextMessage.Length);

                if (size == 0)
                {
                    return;
                }

                byte[] data = reader.ReadBytes(size);

                if (data == null || data.Length != size)
                {
                    Debug.LogError("empty or wrong sized packet");
                    return;
                }

                long remaining = reader.GetRemainingBytes();
                if (remaining != 0)
                {
                    Debug.LogWarning("We have " + remaining + " bytes!");
                }
                _mumbleClient.ReceiveEncodedVoice(session, data, sequence);
            }
        }
Exemplo n.º 2
0
        internal void UnpackOpusVoicePacket(byte[] plainTextMessage, bool isLoopback)
        {
            NumPacketsRecv++;
            //byte typeByte = plainTextMessage[0];
            //int target = typeByte & 31;
            //Debug.Log("len = " + plainTextMessage.Length + " typeByte = " + typeByte);

            using (var reader = new UdpPacketReader(new MemoryStream(plainTextMessage, 1, plainTextMessage.Length - 1)))
            {
                UInt32 session = 0;
                if (!isLoopback)
                {
                    session = (uint)reader.ReadVarInt64();
                }
                else
                {
                    session = _mumbleClient.OurUserState.Session;
                }

                Int64 sequence = reader.ReadVarInt64();

                //We assume we mean OPUS
                int size = (int)reader.ReadVarInt64();
                //Debug.Log("Seq = " + sequence + " Ses: " + session + " Size " + size + " type= " + typeByte + " tar= " + target);
                bool isLast = (size & 8192) == 8192;
                if (isLast)
                {
                    Debug.Log("Found last byte in seq");
                }

                //Apply a bitmask to remove the bit that marks if this is the last packet
                size &= 0x1fff;

                //Debug.Log("Received sess: " + session);
                //Debug.Log(" seq: " + sequence + " size = " + size + " packetLen: " + plainTextMessage.Length);

                byte[] data = (size != 0) ? reader.ReadBytes(size) : new byte[0];

                if (data == null || data.Length != size)
                {
                    Debug.LogError("empty or wrong sized packet. Recv: " + (data != null ? data.Length.ToString() : "null")
                                   + " expected: " + size + " plain len: " + plainTextMessage.Length
                                   + " seq: " + sequence + " isLoop: " + isLoopback);
                    return;
                }

                // All remaining bytes are assumed to be positional data
                byte[] posData   = null;
                long   remaining = reader.GetRemainingBytes();
                if (remaining != 0)
                {
                    //Debug.LogWarning("We have " + remaining + " bytes!");
                    posData = reader.ReadBytes((int)remaining);
                }
                //_mumbleClient.ReceiveEncodedVoice(session, data, sequence, isLast);
                _audioDecodeThread.AddCompressedAudio(session, data, posData, sequence, isLast);
            }
        }