コード例 #1
0
ファイル: RTPAudioStream.cs プロジェクト: quangfox/Voip
        protected override void PushNextPacket()
        {
            if (AudioCodec == null)
            {
                return;
            }

            RTPPacket packet = IncomingRTPPacketBuffer.GetPacket();

            if (packet == null)
            {
                return;
            }

            byte[] bNewAudioData = AudioCodec.DecodeToBytes(packet);

            if (bNewAudioData != null)
            {
                ReceiveAudioQueue.AppendData(bNewAudioData);
                if (ReceiveAudioQueue.Size > m_nPacketBytes * MaxAudioPacketsQueue)                // someone isn't taking our packets (either directly our through IAudioSource), so let's not get too big
                {
                    ReceiveAudioQueue.GetNSamples(ReceiveAudioQueue.Size - m_nPacketBytes * MaxAudioPacketsQueue);
                }

                if (RenderSink != null)
                {
                    MediaSample samp = new MediaSample(bNewAudioData, AudioCodec.AudioFormat);
                    RenderSink.PushSample(samp, this);
                }
            }
        }
コード例 #2
0
ファイル: RTPAudioStream.cs プロジェクト: quangfox/Voip
        public override byte[] GetNextPacketSample(bool bReturnArrayOnNA)
        {
            if (AudioCodec == null)
            {
                return(null);
            }

            int nSamples   = AudioCodec.AudioFormat.CalculateNumberOfSamplesForDuration(TimeSpan.FromMilliseconds(AudioCodec.ReceivePTime));
            int nSizeBytes = nSamples * AudioCodec.AudioFormat.BytesPerSample;

            RTPPacket packet = IncomingRTPPacketBuffer.GetPacket();

            if ((packet == null) && (bReturnArrayOnNA == true))
            {
                return(new byte[nSizeBytes]);
            }

            return(AudioCodec.DecodeToBytes(packet));
        }
コード例 #3
0
ファイル: RTPAudioStream.cs プロジェクト: quangfox/Voip
        public byte[] WaitNextPacketSample(bool bReturnArrayOnNA, int nTimeOut, out int nMsTook)
        {
            nMsTook = 0;
            if (AudioCodec == null)
            {
                return(null);
            }

            int nSamples   = AudioCodec.AudioFormat.CalculateNumberOfSamplesForDuration(TimeSpan.FromMilliseconds(AudioCodec.ReceivePTime));
            int nSizeBytes = nSamples * AudioCodec.AudioFormat.BytesPerSample;

            RTPPacket packet = IncomingRTPPacketBuffer.WaitPacket(nTimeOut, out nMsTook);

            if ((packet == null) && (bReturnArrayOnNA == true))
            {
                return(new byte[nSizeBytes]);
            }

            return(AudioCodec.DecodeToBytes(packet));
        }