Example #1
0
        public void addSR()
        {
            enqueueCommonReportPrefix(RTCPConstants.RTCP_PT_SR, _stream.SSRC(),
                                      5 /* extra words in a SR */);

            // Now, add the 'sender info' for our sink

            // Insert the NTP and RTP timestamps for the 'wallclock time':
            TimeVal timeNow = new TimeVal();

            RTPTime.GetTimestamp(ref timeNow);
            _fOutBuf.WriteWord((uint)(timeNow.tv_sec + 0x83AA7E80));
            // NTP timestamp most-significant word (1970 epoch -> 1900 epoch)
            double fractionalPart = (timeNow.tv_usec / 15625.0) * 0x04000000;             // 2^32/10^6

            _fOutBuf.WriteWord((uint)(fractionalPart + 0.5));
            // NTP timestamp least-significant word
            uint rtpTimestamp = _stream.ConvertToRTPTimestamp(timeNow);

            _fOutBuf.WriteWord(rtpTimestamp);             // RTP ts

            // Insert the packet and byte counts:
            uint packetCount = _stream.PacketCount() - _session.PacketsCount;
            uint octetCount  = _stream.OctetCount() - _session.OctetCount;

            _fOutBuf.WriteWord(packetCount);
            _fOutBuf.WriteWord(octetCount);
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Sending report : {0}.{1} packet {2} octet {3} Sequence {4}", timeNow.tv_sec + 0x83AA7E80,
                              (uint)(fractionalPart + 0.5), packetCount, octetCount, _stream.CurrentSeqNo());
            }
        }
        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);
        }