Esempio n. 1
0
        /// <summary>
        /// This method is called when new RTP packets recieved.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Eevent data.</param>
        private void m_pStream_PacketReceived(object sender,RTP_PacketEventArgs e)
        {
            String s1;
            try{
                AudioCodec codec = null;
                m_RtpMap.TryGetValue(e.Packet.PayloadType,out codec);
                if(codec != null){
                    byte[] decodedData = codec.Decode(e.Packet.Data,0,e.Packet.Data.Length);
                    m_pPlayer.Write(decodedData,0,decodedData.Length);
                }
                // Unknown RTP payload.
                //else{

                // Record if recording enabled.
                // if(m_pRecordStream != null){
                //       m_pRecordStream.Write(decodedData,0,decodedData.Length);
                //}

                //this.BeginInvoke(new MethodInvoker(delegate(){
                //    m_pCodec.Text = codec != null ? codec.Name : "unknown";
                //    m_pPacketsReceived.Text = m_pStream.PacketsReceived.ToString();
                //    m_pKBReceived.Text = (m_pStream.BytesReceived / 1000).ToString("n2");
                //}));

                Codec = codec != null ? codec.Name : "unknown";
                PacketsReceived = m_pStream.PacketsReceived.ToString();
                KBReceived = (m_pStream.BytesReceived / 1000).ToString("n2");
                s1 = KBReceived.ToString();

                m_pMainUI.Invoke(m_pMainUI.m_DelegateAddString1, new Object[] { s1 });
            }
            catch{
                // Decoding or player error, skip it.
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method is called when new RTP packet received.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event data.</param>
        private void m_pRTP_Stream_PacketReceived(object sender,RTP_PacketEventArgs e)
        {
            if(m_IsDisposed){
                return;
            }

            try{
                AudioCodec codec = null;
                if(!m_pAudioCodecs.TryGetValue(e.Packet.PayloadType,out codec)){
                    // Unknown codec(payload value), skip it.

                    return;
                }
                m_pActiveCodec = codec;

                // Audio-out not created yet, create it.
                if(m_pAudioOut == null){
                    m_pAudioOut = new AudioOut(m_pAudioOutDevice,codec.AudioFormat);
                }
                // Audio-out audio format not compatible to codec, recreate it.
                else if(!m_pAudioOut.AudioFormat.Equals(codec.AudioFormat)){
                    m_pAudioOut.Dispose();
                    m_pAudioOut = new AudioOut(m_pAudioOutDevice,codec.AudioFormat);
                }

                // Decode RTP audio frame and queue it for play out.
                byte[] decodedData = codec.Decode(e.Packet.Data,0,e.Packet.Data.Length);
                m_pAudioOut.Write(decodedData,0,decodedData.Length);
            }
            catch(Exception x){
                if(!this.IsDisposed){
                    // Raise error event(We can't throw expection directly, we are on threadpool thread).
                    OnError(x);
                }
            }
        }