示例#1
0
            private void _read()
            {
                _version = m_io.ReadBitsIntBe(2);
                _padding = m_io.ReadBitsIntBe(1) != 0;
                _subtype = m_io.ReadBitsIntBe(5);
                m_io.AlignToByte();
                _payloadType = ((RtcpPayload.PayloadType)m_io.ReadU1());
                _length      = m_io.ReadU2be();
                switch (PayloadType)
                {
                case RtcpPayload.PayloadType.Sr: {
                    __raw_body = m_io.ReadBytes((4 * Length));
                    var io___raw_body = new KaitaiStream(__raw_body);
                    _body = new SrPacket(io___raw_body, this, m_root);
                    break;
                }

                case RtcpPayload.PayloadType.Psfb: {
                    __raw_body = m_io.ReadBytes((4 * Length));
                    var io___raw_body = new KaitaiStream(__raw_body);
                    _body = new PsfbPacket(io___raw_body, this, m_root);
                    break;
                }

                case RtcpPayload.PayloadType.Rr: {
                    __raw_body = m_io.ReadBytes((4 * Length));
                    var io___raw_body = new KaitaiStream(__raw_body);
                    _body = new RrPacket(io___raw_body, this, m_root);
                    break;
                }

                case RtcpPayload.PayloadType.Rtpfb: {
                    __raw_body = m_io.ReadBytes((4 * Length));
                    var io___raw_body = new KaitaiStream(__raw_body);
                    _body = new RtpfbPacket(io___raw_body, this, m_root);
                    break;
                }

                case RtcpPayload.PayloadType.Sdes: {
                    __raw_body = m_io.ReadBytes((4 * Length));
                    var io___raw_body = new KaitaiStream(__raw_body);
                    _body = new SdesPacket(io___raw_body, this, m_root);
                    break;
                }

                default: {
                    _body = m_io.ReadBytes((4 * Length));
                    break;
                }
                }
            }
示例#2
0
        private void Start()
        {
            //BufferChunk chunk = new BufferChunk(2048);
            CompoundPacket compoundPacket = new CompoundPacket();
            EndPoint       endPoint       = null;

            while (isRunning)
            {
                try
                {
                    compoundPacket.Reset();
                    udpListener.ReceiveFrom(compoundPacket.Buffer, out endPoint);

                    compoundPacket.ParseBuffer();
                    //IPAddress ipAddress = ((IPEndPoint)endPoint).Address;
                    IPEndPoint ipEndpoint = (IPEndPoint)endPoint;

                    // The compound packet enumerator destroys its list during enumeration,
                    // so we keep track of packets that have yet to be processed
                    IList <RtcpPacket> yetToBeProcessed = new List <RtcpPacket>();


                    String venueName = null;
                    //uint ssrc = 0;
                    long when = 0; // in units of "ticks"

                    // scan through the compound packet, looking for key pieces of meta-data
                    // first, look for the app packet that specifies the venue
                    // also, obtain the ssrc and the time stamp

                    foreach (RtcpPacket packet in compoundPacket)
                    {
                        if (packet.PacketType == (byte)Rtcp.PacketType.APP)
                        {
                            AppPacket appPacket = new AppPacket(packet);
                            if (appPacket.Name.Equals(Rtcp.APP_PACKET_NAME) &&
                                appPacket.Subtype == Rtcp.VENUE_APP_PACKET_SUBTYPE)
                            {
                                BufferChunk chunk = new BufferChunk(appPacket.Data);
                                when      = chunk.NextInt64();
                                venueName = chunk.NextUtf8String(chunk.Length);
                                int padIndex = venueName.IndexOf((char)0);
                                if (padIndex > 0)
                                {
                                    venueName = venueName.Substring(0, padIndex);
                                }
                            }
                        }
                        else
                        {
                            yetToBeProcessed.Add(packet);
                        }
                    }

                    if (venueName == null)
                    {
                        continue; // can't do anything if we don't know the venue for this packet
                    }
                    if (when == 0)
                    {
                        continue; // need a timestamp
                    }
                    VenueState venueState = null;

                    // compound operations must always be locked...
                    lock (venueStateMap)
                    {
                        if (!venueStateMap.ContainsKey(venueName))
                        {
                            venueState = new VenueState(venueName);
                        }
                        else
                        {
                            venueState = venueStateMap[venueName];
                        }
                    }


                    // scan again, this time processing the RTCP packets
                    foreach (RtcpPacket packet in yetToBeProcessed)
                    {
                        switch (packet.PacketType)
                        {
                        case (byte)Rtcp.PacketType.SR:
                        {
                            SrPacket sr = new SrPacket(packet);

                            SenderData senderData = venueState.GetSenderState(sr.SSRC);
                            senderData.Source = ipEndpoint;

                            senderData.updateSenderState(sr.SenderReport, when);

                            // this "refreshes" the host state (so that it won't expire)
                            venueState.SenderData[sr.SSRC] = senderData;
                            break;
                        }

                        case (byte)Rtcp.PacketType.RR:
                        {
                            RrPacket     rr           = new RrPacket(packet);
                            ReceiverData receiverData = venueState.GetReceiverData(ipEndpoint);

                            // currently, we replace all receiver summaries with the data
                            // from a single RR packet
                            receiverData.updateReceiverState(rr.ReceiverReports, when, venueState);


                            // this "refreshes" the host state (so that it won't expire)
                            venueState.ReceiverData[ipEndpoint] = receiverData;
                            break;
                        }

                        case (byte)Rtcp.PacketType.SDES:
                        {
                            SdesPacket sdp = new SdesPacket(packet);

                            foreach (SdesReport report in sdp.Reports())
                            {
                                SenderData senderData = venueState.GetSenderState(report.SSRC);
                                senderData.CName  = report.SdesData.CName;
                                senderData.Source = ipEndpoint;

                                // this "refreshes" the host state (so that it won't expire)
                                venueState.SenderData[report.SSRC] = senderData;

                                ReceiverData receiverData =
                                    venueState.GetReceiverDataWithoutCreating(ipEndpoint);

                                if (receiverData != null)
                                {
                                    receiverData.CName = report.SdesData.CName;
                                }
                            }
                            break;
                        }

                        case (byte)Rtcp.PacketType.BYE:
                        {
                            //BYE packets occur when capabilities stop.  Clean out sender data only for the
                            //ssrc's affected.  We leave receiver reports alone for now.
                            ByePacket byePacket = new ByePacket(packet);
                            foreach (uint ssrc in byePacket.SSRCs)
                            {
                                venueState.SenderData.Remove(ssrc);
                            }
                            //Set a flag to cause the matrix for this venue to be rebuilt on the next request.
                            venueState.ParticipantChange = true;
                            continue;
                        }

                        case (byte)Rtcp.PacketType.APP:
                        {
                            // ignored

                            break;
                        }
                        }
                    }   // foreach packet...

                    // refresh the venue state
                    venueStateMap[venueName] = venueState;
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine("Exception : " + e.ToString());

                    writeEventLog("Exception in receive thread: " + e.ToString(), EventLogEntryType.Warning);
                }
            } // loop forever...
        }
示例#3
0
        /// <summary>
        /// An SdesPacket can contain multiple Sdes reports (ssrc, SdesData) which we process here
        /// 
        /// Due to our architecture with 1 RtpSession / RtpParticipant and multiple RtpSenders / 
        /// RtpStreams (each of which get their own ssrc and SdesData) it is difficult to properly 
        /// map the SdesData to the participant, because they all share the same CName.
        ///  
        /// The participant properties will have a CName, Name, Email, Phone, etc plus any private 
        /// extensions for the participant.  In order to conserve Rtcp bandwidth, the streams will 
        /// only send out CName, Name and any private extensions for the stream. And the stream's 
        /// Name may be completely different from the participant's name.  
        /// 
        /// The problem is that we don't want the participant to be updated from the stream's 
        /// properties due to sharing a CName.  So we use the private extension "Source" to 
        /// distinguish between a participant's SdesData and a Stream's SdesData
        /// 
        /// The last complication is that AccessGrid doesn't have this private extension, probably
        /// because they have a 1:1 mapping between a sender and receiver.  In order to not break
        /// interop, we allow for the case of the private extension not being there, in which case
        /// the participant data will be updated from any and all SdesData that share that CName
        /// </summary>
        /// <param name="packet">Rtcp packet to process</param>
        /// <param name="ipAddress">Originating IP address of the packet</param>
        private void ProcessSDESPacket(SdesPacket packet, IPAddress ipAddress)
        {
            foreach(SdesReport report in packet.Reports())
            {
                uint ssrc = report.ssrc;
                SdesData sdes = report.sdes;

                // Check for SSRC conflict
                AddSsrcToIp(ssrc, ipAddress);

                // Find out what source generated this data
                string role = sdes.GetPrivateExtension(Rtcp.PEP_SOURCE);

                if(role != null)
                {
                    // Update the participant's properties
                    if(role == Rtcp.PED_PARTICIPANT)
                    {
                        AddOrUpdateParticipant(ssrc, sdes, ipAddress);
                    }
                    else if(role == Rtcp.PED_STREAM)
                    {
                        if(RtpTraffic)
                        {
                            AddOrUpdateStream(ssrc, sdes);
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, 
                            Strings.UnsupportedRole, role));
                    }
                }
                else // Doesn't have CXP specific extensions
                {
                    // This code is not currently guaranteed to work
                    Debug.Assert(false);
                }
            }
        }