Ejemplo n.º 1
0
        public bool ParseReport(RTCPPacket packet, RTPStream stream, IPEndPoint fromAddress)
        {
            uint reportBlocksSize = (uint)(packet.ReportCount * (6 * 4));
            int  length           = (int)packet.Reader.BaseStream.Length - (int)packet.Reader.BaseStream.Position;

            if (length < reportBlocksSize)
            {
                return(false);
            }

            for (int i = 0; i < packet.ReportCount; ++i)
            {
                uint senderSSRC = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32()));
                if (_logger.IsTraceEnabled)
                {
                    _logger.Trace("\tSSRC/CSRC: {0:x8}", packet.SenderSSRC);
                }

                // We care only about reports about our own transmission, not others'
                if (senderSSRC == stream.SSRC())
                {
                    var RR = new RTCPRRRecord()
                    {
                        SenderSSRC      = senderSSRC,
                        LossStats       = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32())),
                        HighestReceived = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32())),
                        Jitter          = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32())),
                        TimeLastSR      = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32())),
                        TimeSinceLastSR = unchecked ((uint)IPAddress.NetworkToHostOrder(packet.Reader.ReadInt32()))
                    };
                    stream.Transsmitions.noteIncomingRR(RR.SenderSSRC, fromAddress,
                                                        RR.LossStats,
                                                        RR.HighestReceived,
                                                        RR.Jitter,
                                                        RR.TimeLastSR,
                                                        RR.TimeSinceLastSR);

                    RRRecords.Add(RR);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool ParseReport(RTCPPacket packet)
        {
            int length = (int)packet.Reader.BaseStream.Length - (int)packet.Reader.BaseStream.Position;

            if (_logger.IsTraceEnabled)
            {
                _logger.Trace("\tSSRC/CSRC: {0:x8}", packet.SenderSSRC);
            }


            // 'Handle' SDES packets only in debugging code, by printing out the 'SDES items':
            // Process each 'chunk':
            bool chunkOK = false;

            while (length >= 8)
            {
                // A valid chunk must be at least 8 bytes long
                chunkOK = false;                 // until we learn otherwise

                // Process each 'SDES item' in the chunk:
                byte itemType = packet.Reader.ReadByte();
                //ADVANCE(1);
                --length;
                while (itemType != 0)
                {
                    int itemLen = packet.Reader.ReadByte();

                    --length;

                    // Make sure "itemLen" allows for at least 1 zero byte at the end of the chunk:
                    if (itemLen + 1 > length /*|| received[br.BaseStream.Position + itemLen] != 0*/)
                    {
                        return(false);
                    }
                    var str = Encoding.ASCII.GetString(packet.Reader.ReadBytes(itemLen));
                    if (_logger.IsTraceEnabled)
                    {
                        _logger.Trace("\t\t{0}:{1}", itemType == 1 ? "CNAME" :
                                      itemType == 2 ? "NAME" :
                                      itemType == 3 ? "EMAIL" :
                                      itemType == 4 ? "PHONE" :
                                      itemType == 5 ? "LOC" :
                                      itemType == 6 ? "TOOL" :
                                      itemType == 7 ? "NOTE" :
                                      itemType == 8 ? "PRIV" :
                                      "(unknown)",
                                      itemType < 8 ? str : "???");                   // hack, because we know it's '\0'-terminated
                    }
                    //: "???"/* don't try to print out PRIV or unknown items */);
                    /*ADVANCE(itemLen); */
                    length -= itemLen;

                    itemType = packet.Reader.ReadByte();
                    --length;
                }
                if (itemType != 0)
                {
                    return(false);                    // bad 'SDES item'
                }
                // Thus, itemType == 0.  This zero 'type' marks the end of the list of SDES items.
                // Skip over remaining zero padding bytes, so that this chunk ends on a 4-byte boundary:
                while (length % 4 > 0 && packet.Reader.ReadByte() == 0)
                {
                    //ADVANCE(1);
                    --length;
                }
                if (length % 4 > 0)
                {
                    return(false);                    // Bad (non-zero) padding byte
                }
                chunkOK = true;
            }
            if (!chunkOK || length > 0)
            {
                return(false);                // bad chunk, or not enough bytes for the last chunk
            }
            return(true);
        }