Example #1
0
 private void RtcpListenerThread()
 {
     try
     {               
         bool receivedGoodBye = false;                
         try
         {
             _udpClient.Client.ReceiveTimeout = 400;
             IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, 0);
             while (!receivedGoodBye && !_rtcpListenerThreadStopEvent.WaitOne(1))
             {
                 byte[] packets = _udpClient.Receive(ref serverEndPoint);
                 if (packets == null)
                 {
                     continue;
                 }
                 
                 int offset = 0;
                 while (offset < packets.Length)
                 {
                     switch (packets[offset + 1])
                     {
                         case 200: //sr
                             var sr = new RtcpSenderReportPacket();
                             sr.Parse(packets, offset);                                    
                             offset += sr.Length;
                             break;
                         case 201: //rr
                             var rr = new RtcpReceiverReportPacket();
                             rr.Parse(packets, offset);                                    
                             offset += rr.Length;
                             break;
                         case 202: //sd
                             var sd = new RtcpSourceDescriptionPacket();
                             sd.Parse(packets, offset);                                    
                             offset += sd.Length;
                             break;
                         case 203: // bye
                             var bye = new RtcpByePacket();
                             bye.Parse(packets, offset);                                    
                             receivedGoodBye = true;
                             OnPacketReceived(new RtcpPacketReceivedArgs(bye));
                             offset += bye.Length;                                    
                             break;
                         case 204: // app
                             var app = new RtcpAppPacket();
                             app.Parse(packets, offset);                                    
                             OnPacketReceived(new RtcpPacketReceivedArgs(app));
                             offset += app.Length;
                             break;
                     }                           
                 }
                 
             }
         }
         finally
         {
             switch (_transmissionMode)
             {
                 case TransmissionMode.Multicast:
                     _udpClient.DropMulticastGroup(_multicastEndPoint.Address);
                     _udpClient.Close();
                     break;
                 case TransmissionMode.Unicast:
                     _udpClient.Close();
                     break;
             }   
         }
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception ex)
     {
         _logger.Info(string.Format("SAT>IP : RTCP listener thread exception"), ex);
         return;
     }
     _logger.Info("SAT>IP : RTCP listener thread stopping");
 }
        private void RtcpListenerThread()
        {
            try
            {
                bool receivedGoodBye = false;
                try
                {
                    _udpClient.Client.ReceiveTimeout = 400;
                    IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    while (!receivedGoodBye && !_rtcpListenerThreadStopEvent.WaitOne(1))
                    {
                        byte[] packets = _udpClient.Receive(ref serverEndPoint);
                        if (packets == null)
                        {
                            continue;
                        }

                        int offset = 0;
                        while (offset < packets.Length)
                        {
                            switch (packets[offset + 1])
                            {
                            case 200:     //sr
                                var sr = new RtcpSenderReportPacket();
                                sr.Parse(packets, offset);
                                offset += sr.Length;
                                break;

                            case 201:     //rr
                                var rr = new RtcpReceiverReportPacket();
                                rr.Parse(packets, offset);
                                offset += rr.Length;
                                break;

                            case 202:     //sd
                                var sd = new RtcpSourceDescriptionPacket();
                                sd.Parse(packets, offset);
                                offset += sd.Length;
                                break;

                            case 203:     // bye
                                var bye = new RtcpByePacket();
                                bye.Parse(packets, offset);
                                receivedGoodBye = true;
                                OnPacketReceived(new RtcpPacketReceivedArgs(bye));
                                offset += bye.Length;
                                break;

                            case 204:     // app
                                var app = new RtcpAppPacket();
                                app.Parse(packets, offset);
                                OnPacketReceived(new RtcpPacketReceivedArgs(app));
                                offset += app.Length;
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    switch (_transmissionMode)
                    {
                    case TransmissionMode.Multicast:
                        _udpClient.DropMulticastGroup(_multicastEndPoint.Address);
                        _udpClient.Close();
                        break;

                    case TransmissionMode.Unicast:
                        _udpClient.Close();
                        break;
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _logger.Info(string.Format("SAT>IP : RTCP listener thread exception"), ex);
                return;
            }
            _logger.Info("SAT>IP : RTCP listener thread stopping");
        }