示例#1
0
        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
        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
        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));
        }
示例#4
0
        void  RTPUDPClient_OnReceiveMessage(byte[] bData, int nLength, IPEndPoint epfrom, IPEndPoint epthis, DateTime dtReceived)
        {
            /// if we are an performing ICE, see if this is an ICE packet instead of an RTP one
            if (nLength >= 8)
            {
                //0x2112A442
                if ((bData[4] == 0x21) && (bData[5] == 0x12) && (bData[6] == 0xA4) && (bData[7] == 0x42))
                {
                    /// STUN message
                    STUNMessage smsg  = new STUN2Message();
                    byte[]      bStun = new byte[nLength];
                    Array.Copy(bData, 0, bStun, 0, nLength);
                    try
                    {
                        smsg.Bytes = bStun;
                    }
                    catch (Exception ex)
                    {
                        smsg       = new STUNMessage();
                        smsg.Bytes = bStun;
                    }

                    STUNRequestResponse foundreq = null;
                    lock (StunLock)
                    {
                        foreach (STUNRequestResponse queuedreq in StunRequestResponses)
                        {
                            if (queuedreq.IsThisYourResponseSetIfItIs(smsg) == true)
                            {
                                foundreq = queuedreq;
                                break;
                            }
                        }

                        if (foundreq != null)
                        {
                            StunRequestResponses.Remove(foundreq);
                            return;
                        }
                    }

                    if (OnUnhandleSTUNMessage != null)
                    {
                        OnUnhandleSTUNMessage(smsg, epfrom);
                    }
                    return;
                }
            }

            RTPPacket packet = RTPPacket.BuildPacket(bData, 0, nLength);

            if (packet != null) /// Seems we get some TURN channel data messages from google talk
            {
                if (ReceiveSSRC == 0)
                {
                    ReceiveSSRC = packet.SSRC;
                }
                if ((packet.PayloadType == this.Payload) && (packet.SSRC == this.ReceiveSSRC))
                {
                    IncomingRTPPacketBuffer.AddPacket(packet);
                }
            }
        }