Exemple #1
0
    public VoicePacketInfo Receive(GamePacket packet)
    {
        CSteamID id;
        uint     packSize;

        if (SteamNetworking.IsP2PPacketAvailable(out packSize))
        {
            if (packSize > packet.MaxCapacity)
            {
                return(VoicePacketInfo.InvalidPacket);
            }

            uint b;

            SteamNetworking.ReadP2PPacket(temp1024.Data, packSize, out b, out id);

            VoicePacketInfo info = new VoicePacketInfo();
            info.NetId           = temp1024.ReadUInt(0);
            info.Frequency       = temp1024.ReadUShort();
            info.Channels        = temp1024.ReadByte();
            info.Format          = (AudioDataTypeFlag)temp1024.ReadByte();
            info.ValidPacketInfo = true;

            packet.WriteByteData(temp1024.Data, FirstPacketByteAvailable, (int)b);

            return(info);
        }

        return(VoicePacketInfo.InvalidPacket);
    }
    public void FromPacketToAudioDataInt16(GamePacket packet, ref VoicePacketInfo info, byte[] out_audioData, int out_audioDataOffset, out int dataCount)
    {
        //reads audio data length
        int count = packet.ReadInt();

        //Restarts packet buffer to use
        decompressBuffer.ResetSeekLength();

        //fills buffer with only audio data from given packet
        decompressBuffer.WriteByteData(packet.Data, packet.CurrentSeek, count);

        EVoiceResult res = EVoiceResult.k_EVoiceResultUnsupportedCodec;

        //number of bytes written
        uint b = 0;

        //audio data is decompressed
        res = SteamUser.DecompressVoice(decompressBuffer.Data, (uint)decompressBuffer.CurrentLength, out_audioData, (uint)out_audioData.Length, out b, info.Frequency);

        dataCount = (int)b;

        //if an error occurred packet is invalid
        if (res != EVoiceResult.k_EVoiceResultOK)
        {
            info.ValidPacketInfo = false;
        }
    }
 public void FromPacketToAudioData(GamePacket packet, ref VoicePacketInfo info, float[] out_audioData, int out_audioDataOffset, out int dataCount)
 {
     //this method is not supported
     info.ValidPacketInfo = false;
     dataCount            = -1;
     return;
 }
    public override int FromPacketToAudioData(BytePacket packet, ref VoicePacketInfo info, float[] out_audioData, int out_audioDataOffset)
    {
        int length    = packet.ReadInt();
        int frameSize = packet.ReadInt();

        return(decoder.Decode(packet.Data, packet.CurrentSeek, length, out_audioData, out_audioDataOffset, frameSize) * decoder.NumChannels);
    }
 public override void SendToAll(BytePacket data, VoicePacketInfo info, List <ulong> receiversIds)
 {
     SentArray = new byte[data.Data.Length];
     ByteManipulator.Write <byte>(data.Data, 0, SentArray, 0, SentArray.Length);
     DataSent = data.CurrentLength;
     for (int i = 0; i < receiversIds.Count; i++)
     {
         DataSentTo.Add(receiversIds[i]);
     }
 }
    public void TestSendToAllOthersCorrectFormatRedLight()
    {
        VoicePacketInfo info = new VoicePacketInfo();

        info.Format = AudioDataTypeFlag.Single;
        transport.SendToAll(new BytePacket(1), info, new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadByte(workflow.receivedData, 3), Is.Not.EqualTo((byte)AudioDataTypeFlag.Int16));
    }
    public void TestSendToAllOthersCorrectChannelsRedLight()
    {
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels = 1;
        transport.SendToAll(new BytePacket(1), info, new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadByte(workflow.receivedData, 2), Is.Not.EqualTo(7));
    }
    public void TestSendToAllOthersCorrectFrequencyRedLight()
    {
        VoicePacketInfo info = new VoicePacketInfo();

        info.Frequency = 5666;
        transport.SendToAll(new BytePacket(1), info, new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadUInt16(workflow.receivedData, 0), Is.Not.EqualTo(17898));
    }
Exemple #9
0
    public override int FromPacketToAudioDataInt16(BytePacket packet, ref VoicePacketInfo info, byte[] out_audioData, int out_audioDataOffset)
    {
        int dataCount = Mathf.Min(packet.CurrentLength - packet.CurrentSeek, out_audioData.Length - out_audioDataOffset);

        packet.ReadByteData(out_audioData, out_audioDataOffset, dataCount);
        FromPacketToAudioInt16 = true;
        if (UseInfo)
        {
            info = this.Info;
        }
        return(dataCount);
    }
    public void TestProcessReceivedDataChann()
    {
        BytePacket buffer = new BytePacket(20);

        byte[] receivedData = new byte[20];
        ByteManipulator.Write(receivedData, 0, (ushort)4588);
        ByteManipulator.Write(receivedData, 2, (byte)5);
        ByteManipulator.Write(receivedData, 3, (byte)99);
        ulong           netId = 5;
        VoicePacketInfo info  = transport.ProcessReceivedData(buffer, receivedData, 0, 20, netId);

        Assert.That(info.Channels, Is.EqualTo(5));
    }
    public void TestProcessReceivedDataValidPacketRedLight()
    {
        BytePacket buffer = new BytePacket(20);

        byte[] receivedData = new byte[20];
        ByteManipulator.Write(receivedData, 0, (ushort)4588);
        ByteManipulator.Write(receivedData, 2, (byte)5);
        ByteManipulator.Write(receivedData, 3, (byte)99);
        ulong           netId = 6;
        VoicePacketInfo info  = transport.ProcessReceivedData(buffer, receivedData, 0, 20, netId);

        Assert.That(info.ValidPacketInfo, Is.Not.False);
    }
    public void TestProcessReceivedDataFormatRedLight()
    {
        BytePacket buffer = new BytePacket(20);

        byte[] receivedData = new byte[20];
        ByteManipulator.Write(receivedData, 0, (ushort)4588);
        ByteManipulator.Write(receivedData, 2, (byte)5);
        ByteManipulator.Write(receivedData, 3, (byte)199);
        ulong           netId = 6;
        VoicePacketInfo info  = transport.ProcessReceivedData(buffer, receivedData, 0, 20, netId);

        Assert.That((byte)info.Format, Is.Not.EqualTo(99));
    }
Exemple #13
0
    public void SendToAllOthers(GamePacket data, VoicePacketInfo info)
    {
        //Debug.Log("packet sent to all others");
        GamePacket toSend = GamePacket.CreatePacket(pLength);

        toSend.Write(ReceiverId, 0);
        toSend.Write(info.Frequency);
        toSend.Write(info.Channels);
        toSend.Write((byte)info.Format);

        toSend.WriteByteData(data.Data, 0, data.CurrentLength);

        packets.Enqueue(toSend);
    }
    public VoicePacketInfo GetMicDataInt16(byte[] buffer, int bufferOffset, int micDataCount, out uint effectiveMicAudioData)
    {
        effectiveMicAudioData = 0;
        //Gets mic data from recorder if not disabled
        if (Recorder.IsDisabled)
        {
            return(VoicePacketInfo.InvalidPacket);
        }

        VoicePacketInfo info = Recorder.GetMicData(buffer, bufferOffset, micDataCount, out effectiveMicAudioData);

        info.NetId = Identity.NetworkId;

        return(info);
    }
Exemple #15
0
    public override int FromPacketToAudioData(BytePacket packet, ref VoicePacketInfo info, float[] out_audioData, int out_audioDataOffset)
    {
        int dataCount = Mathf.Min(packet.CurrentLength - packet.CurrentSeek, out_audioData.Length - out_audioDataOffset);

        for (int i = 0; i < dataCount / sizeof(float); i++)
        {
            out_audioData[i + out_audioDataOffset] = packet.ReadFloat();
        }
        FromPacketToAudio = true;
        if (UseInfo)
        {
            info = this.Info;
        }
        return(dataCount);
    }
Exemple #16
0
        /// <summary>
        /// Sends a packet to a list of clients
        /// </summary>
        /// <param name="data">GamePacket that stores the data to send</param>
        /// <param name="info">data info</param>
        /// <param name="receiversIds">list of receivers ids that will receive the audio packet</param>
        public override void SendToAll(BytePacket data, VoicePacketInfo info, List <ulong> receiversIds)
        {
            toSend.CurrentSeek   = 0;
            toSend.CurrentLength = 0;

            toSend.Write(info.Frequency);
            toSend.Write(info.Channels);
            toSend.Write((byte)info.Format);

            int count = Mathf.Min(data.CurrentLength - data.CurrentSeek, toSend.Data.Length - toSend.CurrentSeek);

            toSend.WriteByteData(data.Data, data.CurrentSeek, count);

            SendToAllAction?.Invoke(toSend.Data, 0, toSend.CurrentLength, receiversIds);
        }
Exemple #17
0
        /// <summary>
        /// Processes a Gamepacket into audio data in format Int16
        /// </summary>
        /// <param name="packet">GamePacket to process</param>
        /// <param name="info">data info</param>
        /// <param name="out_audioData">output array on which data will be written</param>
        /// <param name="out_audioDataOffset">output array start index</param>
        /// <returns>total number of bytes written</returns>
        public override int FromPacketToAudioDataInt16(BytePacket packet, ref VoicePacketInfo info, byte[] out_audioData, int out_audioDataOffset)
        {
            int maxP      = packet.CurrentLength - packet.CurrentSeek - sizeof(int);
            int dataCount = Mathf.Min(Mathf.Min(packet.ReadInt(), out_audioData.Length - out_audioDataOffset), maxP);

            if (dataCount <= 0)
            {
                info.ValidPacketInfo = false;
                return(dataCount);
            }

            packet.ReadByteData(out_audioData, out_audioDataOffset, dataCount);

            return(dataCount);
        }
Exemple #18
0
    public void TestFromAudioSingleToPacketValid()
    {
        float[]    audiodata = new float[200];
        BytePacket output    = new BytePacket(404);

        output.CurrentSeek   = 0;
        output.CurrentLength = 0;
        VoicePacketInfo info = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        manipulator.FromAudioDataToPacket(audiodata, 0, audiodata.Length, ref info, output);
        Assert.That(info.ValidPacketInfo, Is.True);
    }
Exemple #19
0
        /// <summary>
        /// Process packet data
        /// </summary>
        /// <param name="buffer">GamePacket of which data will be stored</param>
        /// <param name="dataReceived">Raw data received from network</param>
        /// <param name="startIndex">Raw data start index</param>
        /// <param name="length">Raw data length</param>
        /// <param name="netId">Sender net id</param>
        /// <returns>data info</returns>
        public override VoicePacketInfo ProcessReceivedData(BytePacket buffer, byte[] dataReceived, int startIndex, int length, ulong netId)
        {
            VoicePacketInfo info = new VoicePacketInfo();

            info.Frequency       = ByteManipulator.ReadUInt16(dataReceived, startIndex);
            startIndex          += sizeof(ushort);
            info.Channels        = ByteManipulator.ReadByte(dataReceived, startIndex);
            startIndex          += sizeof(byte);
            info.Format          = (AudioDataTypeFlag)ByteManipulator.ReadByte(dataReceived, startIndex);
            startIndex          += sizeof(byte);
            info.ValidPacketInfo = true;

            buffer.WriteByteData(dataReceived, startIndex, length - sizeof(ushort) - sizeof(byte) - sizeof(byte));

            return(info);
        }
Exemple #20
0
    public void TestFromAudioInt16ToPacketInvalid4()
    {
        byte[]     audiodata = new byte[200];
        BytePacket output    = new BytePacket(404);

        output.CurrentSeek   = 500;
        output.CurrentLength = 0;
        VoicePacketInfo info = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        manipulator.FromAudioDataToPacketInt16(audiodata, 0, audiodata.Length, ref info, output);
        Assert.That(info.ValidPacketInfo, Is.False);
    }
Exemple #21
0
    public void TestFromAudioInt16ToPacketHeaderValue3()
    {
        byte[]     audiodata = new byte[800];
        BytePacket output    = new BytePacket(404);

        output.CurrentSeek   = 0;
        output.CurrentLength = 0;
        VoicePacketInfo info = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        manipulator.FromAudioDataToPacketInt16(audiodata, 0, audiodata.Length, ref info, output);
        Assert.That(output.ReadInt(0), Is.EqualTo(400));
    }
Exemple #22
0
    public void TestReceiveAudioDataInt16BufferInit()
    {
        byte[] data = new byte[10];
        for (int i = 0; i < 10; i++)
        {
            data[i] = (byte)i;
        }
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        info.ValidPacketInfo = true;
        info.Frequency       = 48000;

        receiver.ReceiveAudioData(data, 0, 10, info);
        Assert.That(recBuffer.GetValue(receiver), Is.Not.Null);
    }
Exemple #23
0
    public void TestReceiveAudioDataSingleBufferInit2()
    {
        float[] data = new float[10];
        for (int i = 0; i < 10; i++)
        {
            data[i] = (float)i;
        }
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        info.ValidPacketInfo = true;
        info.Frequency       = 48000;

        receiver.ReceiveAudioData(data, 0, 10, info);
        Assert.That((recBuffer.GetValue(receiver) as float[]).Length, Is.EqualTo(12000));
    }
Exemple #24
0
    public void TestReceiveAudioDataSingleDataIntegrity7()
    {
        float[] data = new float[10];
        for (int i = 0; i < 10; i++)
        {
            data[i] = (float)i;
        }
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;
        info.ValidPacketInfo = true;
        info.Frequency       = 12000;
        recWriteIndex.SetValue(receiver, 0);

        receiver.ReceiveAudioData(data, 0, 10, info);
        Assert.That((recBuffer.GetValue(receiver) as float[])[8], Is.EqualTo(1).Within(0.0001));
    }
Exemple #25
0
    public void TestReceiveAudioDataSingleWriteIndexUpdate9()
    {
        float[] data = new float[10];
        for (int i = 0; i < 10; i++)
        {
            data[i] = (float)i;
        }
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels        = 5;
        info.Format          = AudioDataTypeFlag.Both;
        info.ValidPacketInfo = true;
        info.Frequency       = 12000;
        recWriteIndex.SetValue(receiver, 11999);

        receiver.ReceiveAudioData(data, 0, 10, info);
        Assert.That(recWriteIndex.GetValue(receiver), Is.EqualTo(15));
    }
Exemple #26
0
    public void SendToAllOthers(GamePacket data, VoicePacketInfo info)
    {
        int l = data.CurrentLength + FirstPacketByteAvailable;

        GamePacket toUse = l <= temp256.MaxCapacity ? temp256 : (l <= temp512.MaxCapacity ? temp512 : (l <= temp768.MaxCapacity ? temp768 : temp1024));

        toUse.Write(info.NetId, 0);
        toUse.Write(info.Frequency);
        toUse.Write(info.Channels);
        toUse.Write((byte)info.Format);

        toUse.WriteByteData(data.Data, data.CurrentSeek, data.CurrentLength - data.CurrentSeek);

        foreach (KeyValuePair <ulong, CSteamID> item in others)
        {
            SteamNetworking.SendP2PPacket(item.Value, toUse.Data, (uint)toUse.MaxCapacity, EP2PSend.k_EP2PSendReliable);
        }
    }
Exemple #27
0
    public void TestReceiveAudioDataInt16WriteIndexUpdate8()
    {
        byte[] data = new byte[10];
        for (int i = 0; i < 10; i++)
        {
            data[i] = (byte)i;
        }
        VoicePacketInfo info = new VoicePacketInfo();

        info.Channels        = 2;
        info.Format          = AudioDataTypeFlag.Both;
        info.ValidPacketInfo = true;
        info.Frequency       = 12000;
        recWriteIndex.SetValue(receiver, 0);

        receiver.ReceiveAudioData(data, 0, 10, info);
        Assert.That(recWriteIndex.GetValue(receiver), Is.EqualTo(20));
    }
Exemple #28
0
    public void TestFromPacketToAudioDataInt16Count2()
    {
        BytePacket packet = new BytePacket(404);

        packet.Write(100);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 104;
        byte[]          output = new byte[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        int count = manipulator.FromPacketToAudioDataInt16(packet, ref info, output, 0);

        Assert.That(count, Is.EqualTo(100));
    }
Exemple #29
0
    public void TestFromPacketToAudioDataSingleInvalidPacket2()
    {
        BytePacket packet = new BytePacket(4);

        packet.Write(25);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 4;
        float[]         output = new float[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        manipulator.FromPacketToAudioData(packet, ref info, output, 0);

        Assert.That(info.ValidPacketInfo, Is.False);
    }
Exemple #30
0
    public void TestFromPacketToAudioDataInt16InvalidPacket3()
    {
        BytePacket packet = new BytePacket(104);

        packet.Write(-1);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 104;
        byte[]          output = new byte[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        manipulator.FromPacketToAudioDataInt16(packet, ref info, output, 0);

        Assert.That(info.ValidPacketInfo, Is.False);
    }