public override int FromPacketToAudioDataInt16(BytePacket packet, ref VoicePacketInfo info, byte[] out_audioData, int out_audioDataOffset)
    {
        //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);

        //if an error occurred packet is invalid
        if (res != EVoiceResult.k_EVoiceResultOK)
        {
            info.ValidPacketInfo = false;
        }

        return((int)b);
    }
Esempio n. 2
0
 public override void FromAudioDataToPacketInt16(byte[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
 {
     FromAudioToPacketInt16 = true;
     output.WriteByteData(audioData, audioDataOffset, audioDataCount);
     if (UseInfo)
     {
         info = this.Info;
     }
 }
    public override void FromAudioDataToPacketInt16(byte[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
    {
        //writes audio data length
        output.Write(audioDataCount);

        //data is written on the output.
        int n = audioDataCount > output.MaxCapacity - output.CurrentSeek ? output.MaxCapacity - output.CurrentSeek : audioDataCount;

        output.WriteByteData(audioData, audioDataOffset, n);
    }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// Processes audio data in format Int16 into a GamePacket
        /// </summary>
        /// <param name="audioData">audio data to process</param>
        /// <param name="audioDataOffset">audio data startIndex</param>
        /// <param name="audioDataCount">number of bytes to process</param>
        /// <param name="info">data info</param>
        /// <param name="output">gamepacket on which data will be written</param>
        public override void FromAudioDataToPacketInt16(byte[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
        {
            int outputAvailableSpace = output.Data.Length - output.CurrentSeek;

            if (outputAvailableSpace < audioDataCount + sizeof(int))
            {
                audioDataCount = outputAvailableSpace - sizeof(int);
            }

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

            output.Write(audioDataCount);
            output.WriteByteData(audioData, audioDataOffset, audioDataCount);
        }
Esempio n. 7
0
 public override VoicePacketInfo ProcessReceivedData(BytePacket buffer, byte[] dataReceived, int startIndex, int length, ulong netId)
 {
     DataReceived = length;
     buffer.WriteByteData(dataReceived, startIndex, length);
     return(Info);
 }