예제 #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 RTPTransmissionStat(RTPStream stream, uint ssrc)
        {
            _stream = stream;
            SSRC    = ssrc;
            fLastPacketNumReceived = 0;
            fPacketLossRatio       = 0;
            fTotNumPacketsLost     = 0;
            fJitter        = 0;
            fLastSRTime    = 0;
            fDiffSR_RRTime = 0;
            fAtLeastTwoRRsHaveBeenReceived = false;
            fFirstPacket         = true;
            fTotalOctetCount_hi  = 0;
            fTotalOctetCount_lo  = 0;
            fTotalPacketCount_hi = 0;
            fTotalPacketCount_lo = 0;
            fTimeCreated         = new TimeVal();

            RTPTime.GetTimestamp(ref fTimeCreated);

            fLastOctetCount  = _stream.OctetCount();
            fLastPacketCount = _stream.PacketCount();
        }
        public void noteIncomingRR(IPEndPoint lastFromAddress, uint lossStats, uint lastPacketNumReceived, uint jitter, uint lastSRTime, uint diffSR_RRTime)
        {
            if (fFirstPacket)
            {
                fFirstPacket            = false;
                fFirstPacketNumReported = lastPacketNumReceived;
            }
            else
            {
                fAtLeastTwoRRsHaveBeenReceived = true;
                fOldLastPacketNumReceived      = fLastPacketNumReceived;
                fOldTotNumPacketsLost          = fTotNumPacketsLost;
            }

            RTPTime.GetTimestamp(ref fTimeReceived);

            fLastFromAddress       = lastFromAddress;
            fPacketLossRatio       = (byte)(lossStats >> 24);
            fTotNumPacketsLost     = lossStats & 0xFFFFFF;
            fLastPacketNumReceived = lastPacketNumReceived;
            fJitter        = jitter;
            fLastSRTime    = lastSRTime;
            fDiffSR_RRTime = diffSR_RRTime;

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("RTCP RR data (received at {0}.{1}): lossStats {2:x8}, TotNumLost {3} lastPacketNumReceived {4}, jitter {5}, lastSRTime {6}, diffSR_RRTime {7} from SSRC {0}",
                              fTimeReceived.tv_sec, fTimeReceived.tv_usec, lossStats, fTotNumPacketsLost, lastPacketNumReceived, jitter, lastSRTime, diffSR_RRTime, SSRC);
            }

            if (_logger.IsDebugEnabled)
            {
                uint rtd = roundTripDelay();
                _logger.Debug("=> round-trip delay: {0:x4} (== {1} seconds)", rtd, rtd / 65536.0);
            }

            // Update our counts of the total number of octets and packets sent towards
            // this receiver:
            uint newOctetCount  = _stream.OctetCount();
            uint octetCountDiff = newOctetCount - fLastOctetCount;

            fLastOctetCount = newOctetCount;
            uint prevTotalOctetCount_lo = fTotalOctetCount_lo;

            fTotalOctetCount_lo += octetCountDiff;
            if (fTotalOctetCount_lo < prevTotalOctetCount_lo)
            {             // wrap around
                ++fTotalOctetCount_hi;
            }

            uint newPacketCount  = _stream.PacketCount();
            uint packetCountDiff = newPacketCount - fLastPacketCount;

            fLastPacketCount = newPacketCount;
            uint prevTotalPacketCount_lo = fTotalPacketCount_lo;

            fTotalPacketCount_lo += packetCountDiff;
            if (fTotalPacketCount_lo < prevTotalPacketCount_lo)
            {             // wrap around
                ++fTotalPacketCount_hi;
            }
        }