Example #1
0
        public virtual void SendAudioPacket(short[] audioBuffer, int length, AudioCodecType codecTypeType, bool isSilent, int localProcessorLoad)
        {
            if (++_audioPacketsSent % 200 == 0)
            {
                ClientLogger.Debug("{0} audio packets sent through the LoopbackMediaConnection", _audioPacketsSent);
            }

            if (!isSilent && length == 0)
            {
                ClientLogger.Debug("Entry has zero datalength!");
            }

            var packet = new LoopbackMediaPacket
            {
                Payload        = audioBuffer,
                PayloadLength  = (ushort)(length * sizeof(short)),
                SsrcId         = _localSsrcId,
                ProcessorLoad  = 10,
                AudioCodecType = codecTypeType,
                IsSilent       = isSilent,
                SequenceNumber = _sequenceNumber++
            };

            AudioPacketHandler(packet);
        }
 public override void SendAudioPacket(short[] audioBuffer, int length, AudioCodecType codecTypeType, bool isSilent, int localProcessorLoad)
 {
     if (_packets++ == 0)
     {
         var data = new short[length];
         Buffer.BlockCopy(audioBuffer, 0, data, 0, length * sizeof(short));
         OnFirstPacketReceived(new EventArgs <short[]>(data));
     }
     base.SendAudioPacket(audioBuffer, length, codecTypeType, isSilent, localProcessorLoad);
 }
Example #3
0
 /// <summary>
 /// Returns a filter that specifies the given codec
 /// </summary>
 /// <param name="audioCodec">an Audio Codec to find a filter for</param>
 /// <param name="type">The type of Filter, such as AudioDecoder, Encoder, etc</param>
 /// <returns>The first filter encountered that deals with the given audio codec. Returns null if not found.</returns>
 public Filter GetFilterForCodec(AudioCodecType audioCodec, FilterType type)
 {
     foreach (Filter f in this.Filter)
     {
         if ((f.AudioCodec == audioCodec) && (f.Type == type))
         {
             return(f);
         }
     }
     return(null);
 }
        public void SendAudioPacket(short[] audioBuffer, int length, AudioCodecType codecTypeType, bool isSilent, int localProcessorLoad)
        {
            if (++_audioPacketsSent % 200 == 0)
            {
                ClientLogger.Debug("{0} audio packets sent through the TimingMediaConnection", _audioPacketsSent);
            }

            if (!isSilent && length == 0)
            {
                ClientLogger.Debug("Entry has zero datalength!");
            }

            // Buffer 100 frames.
            if (RecordedFrames.Count < packetsToBuffer)
            {
                var packet = new TimingMediaPacket
                {
                    Payload        = audioBuffer,
                    PayloadLength  = (ushort)(length * sizeof(short)),
                    SsrcId         = _localSsrcId,
                    ProcessorLoad  = 10,
                    AudioCodecType = codecTypeType,
                    IsSilent       = isSilent
                };
                RecordedFrames.Add(packet);
            }
            else
            {
                // Start playing them
                int index = _sequenceNumber % packetsToBuffer;
                if (AudioPacketHandler != null)
                {
                    var packet = RecordedFrames[index];
                    var copy   = new TimingMediaPacket
                    {
                        Payload        = new short[packet.Payload.Length],
                        PayloadLength  = packet.PayloadLength,
                        SsrcId         = packet.SsrcId,
                        SequenceNumber = _sequenceNumber++,
                        ProcessorLoad  = packet.ProcessorLoad,
                        AudioCodecType = packet.AudioCodecType,
                        IsSilent       = packet.IsSilent
                    };
                    Buffer.BlockCopy(packet.Payload, 0, copy.Payload, 0, copy.Payload.Length * sizeof(short));
                    if (!copy.IsSilent && copy.PayloadLength == 0)
                    {
                        ClientLogger.Debug("Entry has zero datalength!");
                    }

                    AudioPacketHandler(copy);
                }
            }
        }
Example #5
0
        public override void SetAudioCodecs(AudioCodecInformation[] codecs)
        {
            ipClient.AudioCodecs.DisableAllCodecs();

            foreach (AudioCodecInformation acInfo in codecs)
            {
                AudioCodecType codecType = WOSI.Utilities.EnumUtils <AudioCodecType> .Parse(acInfo.Name);

                ipClient.AudioCodecs.SetToLowestPriority(codecType);
                ipClient.AudioCodecs.SetEnabled(codecType, acInfo.Enabled);
            }
        }
        public void SendAudioPacket(short[] audioBuffer, int length, AudioCodecType codecTypeType, bool isSilent, int localProcessorLoad)
        {
            ByteStream packetBuffer = null;

            try
            {
                bool packetBuilt;
                lock (_rtpData)
                {
                    _rtpData.SequenceNumber++;
                    _rtpData.PayloadType    = RtpPayloadType.Audio;
                    _rtpData.AudioCodecType = codecTypeType;
                    _rtpData.IsSilent       = isSilent;
                    _rtpData.Payload        = audioBuffer;
                    _rtpData.PayloadLength  = (ushort)(length * sizeof(short));
                    _rtpData.ProcessorLoad  = (byte)localProcessorLoad;
                    packetBuffer            = _packetBufferPool.GetNext();
                    packetBuilt             = _rtpData.TryBuildPacket(packetBuffer);
                }
                if (packetBuilt)
                {
                    if (_rtpClient != null)
                    {
                        _rtpClient.Send(packetBuffer.Data, packetBuffer.DataOffset, packetBuffer.DataLength);
                    }
                }
                else
                {
                    ClientLogger.Debug("Error building audio packetBuffer.");
                }
            }
            finally
            {
                _packetBufferPool.Recycle(packetBuffer);
            }
        }
Example #7
0
 public CodecAudio(AudioCodecType codec)
     : base(FormattingUtility.Library(codec.ToString()))
 {
 }
 public TestAudioContextFactory(MediaConfig mediaConfig, AudioFormat rawAudioFormat, AudioFormat transmittedAudioFormat, SpeechEnhancementStack enhancementStack, AudioCodecType codecType)
 {
     this.mediaConfig            = mediaConfig;
     this.rawAudioFormat         = rawAudioFormat;
     this.transmittedAudioFormat = transmittedAudioFormat;
     this.enhancementStack       = enhancementStack;
     this.codecType = codecType;
 }
Example #9
0
 public IAudioDecoder GetAudioDecoder(AudioCodecType codecTypeType, MediaStatistics mediaStatistics = null)
 {
     return(decoders[codecTypeType]);
 }
Example #10
0
 public CodecAudio(AudioCodecType codec)
     : base(Suffix, Formats.Library(codec))
 {
 }
Example #11
0
 public CodecAudio(AudioCodecType codec)
     : base(FormattingUtility.Library(codec.ToString()))
 {
 }
Example #12
0
 public static string Library(AudioCodecType codec)
 {
     return(Library(codec.ToString()));
 }
Example #13
0
        public void WriteSamples(Array samples, int start, int dataLength, ushort sequenceNumber, AudioCodecType audioCodecType, bool isSilent)
        {
            // Only write the frame to the queue if it's newer than the most recently played frame.
            // This particular way of checking will miss some out-of-order packets if they occur right when a wrap-around
            // is happening, but not many.

            if (sequenceNumber > _lastSequenceNumberRead ||
                _lastSequenceNumberRead < lowEndWrapAround ||
                _lastSequenceNumberRead > highEndWrapAround ||
                sequenceNumber < lowEndWrapAround ||
                sequenceNumber > highEndWrapAround)
            {
                var entry = _entryPool.GetNext();
                Buffer.BlockCopy(samples, start, entry.Frame, 0, dataLength);
                entry.DataLength     = dataLength / sizeof(short);
                entry.SequenceNumber = sequenceNumber;
                entry.AudioCodecType = audioCodecType;
                entry.IsSilent       = isSilent;
                lock (_queue)
                {
                    _queue.Enqueue(entry);
                }
                _logger.LogWrite();
            }
            else
            {
                _logger.LogWriteOutOfOrder();
            }
        }
Example #14
0
 public void WriteSamples(ByteStream samples, ushort sequenceNumber, AudioCodecType audioCodecType, bool isSilent)
 {
     WriteSamples(samples.Data, samples.DataOffset, samples.DataLength, sequenceNumber, audioCodecType, isSilent);
 }
        public IAudioDecoder GetAudioDecoder(AudioCodecType codecTypeType, MediaStatistics mediaStatistics = null)
        {
            var audioFormat = new AudioFormat();

            return(new SpeexDecoder(audioFormat));
        }
Example #16
0
 public CodecAudio(AudioCodecType codec)
     : base(Suffix, Formats.Library(codec))
 {
 }