Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc |
| index d65b04c8ab00405aeee884a646baa075375cabdb..ff5c9a4660f3a01b1875fc409fc92d6e29900870 100644 |
| --- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc |
| @@ -21,6 +21,8 @@ |
| #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| +#include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| +#include "webrtc/system_wrappers/include/ntp_time.h" |
| namespace webrtc { |
| using RTCPHelp::RTCPPacketInformation; |
| @@ -487,13 +489,6 @@ void RTCPReceiver::HandleReportBlock( |
| return; |
| } |
| - // To avoid problem with acquiring _criticalSectionRTCPSender while holding |
| - // _criticalSectionRTCPReceiver. |
| - _criticalSectionRTCPReceiver->Leave(); |
| - int64_t sendTimeMS = |
| - _rtpRtcp.SendTimeOfSendReport(rtcpPacket.ReportBlockItem.LastSR); |
| - _criticalSectionRTCPReceiver->Enter(); |
| - |
| RTCPReportBlockInformation* reportBlock = |
| CreateOrGetReportBlockInformation(remoteSSRC, |
| rtcpPacket.ReportBlockItem.SSRC); |
| @@ -526,43 +521,31 @@ void RTCPReceiver::HandleReportBlock( |
| reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; |
| } |
| - uint32_t delaySinceLastSendReport = |
| - rtcpPacket.ReportBlockItem.DelayLastSR; |
| - |
| - // local NTP time when we received this |
| - uint32_t lastReceivedRRNTPsecs = 0; |
| - uint32_t lastReceivedRRNTPfrac = 0; |
| - |
| - _clock->CurrentNtp(lastReceivedRRNTPsecs, lastReceivedRRNTPfrac); |
| + uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR; |
| + uint32_t RTT = 0; |
|
stefan-webrtc
2016/02/03 10:03:10
rtt
danilchap
2016/02/03 13:27:11
Done.
|
| - // time when we received this in MS |
| - int64_t receiveTimeMS = Clock::NtpToMs(lastReceivedRRNTPsecs, |
| - lastReceivedRRNTPfrac); |
| + if (send_time > 0) { |
| + uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR; |
| + // Local NTP time. |
| + uint32_t receive_time = CompactNtp(NtpTime(*_clock)); |
| - // Estimate RTT |
| - uint32_t d = (delaySinceLastSendReport & 0x0000ffff) * 1000; |
| - d /= 65536; |
| - d += ((delaySinceLastSendReport & 0xffff0000) >> 16) * 1000; |
| - |
| - int64_t RTT = 0; |
| - |
| - if (sendTimeMS > 0) { |
| - RTT = receiveTimeMS - d - sendTimeMS; |
| - if (RTT <= 0) { |
| - RTT = 1; |
| - } |
| + // RTT in 1/(2^16) seconds. |
| + uint32_t rtt_ntp = receive_time - delay - send_time; |
| + // Convert to 1/1000 seconds (milliseconds). |
| + uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); |
| + RTT = std::max<uint32_t>(rtt_ms, 1); |
| if (RTT > reportBlock->maxRTT) { |
| - // store max RTT |
| + // Store max RTT. |
| reportBlock->maxRTT = RTT; |
| } |
| if (reportBlock->minRTT == 0) { |
| - // first RTT |
| + // First RTT. |
| reportBlock->minRTT = RTT; |
| } else if (RTT < reportBlock->minRTT) { |
| - // Store min RTT |
| + // Store min RTT. |
| reportBlock->minRTT = RTT; |
| } |
| - // store last RTT |
| + // Store last RTT. |
| reportBlock->RTT = RTT; |
| // store average RTT |
| @@ -572,7 +555,7 @@ void RTCPReceiver::HandleReportBlock( |
| ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * RTT); |
| reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f); |
| } else { |
| - // first RTT |
| + // First RTT. |
| reportBlock->avgRTT = RTT; |
| } |
| reportBlock->numAverageCalcs++; |
| @@ -934,28 +917,19 @@ void RTCPReceiver::HandleXrDlrrReportBlockItem( |
| rtcpPacketInformation.xr_dlrr_item = true; |
| - // To avoid problem with acquiring _criticalSectionRTCPSender while holding |
| - // _criticalSectionRTCPReceiver. |
| - _criticalSectionRTCPReceiver->Leave(); |
| - |
| - int64_t send_time_ms; |
| - bool found = _rtpRtcp.SendTimeOfXrRrReport( |
| - packet.XRDLRRReportBlockItem.LastRR, &send_time_ms); |
| - |
| - _criticalSectionRTCPReceiver->Enter(); |
| - |
| - if (!found) { |
| + // The send_time and delay_rr fields are in units of 1/65536 sec. |
|
stefan-webrtc
2016/02/03 10:03:10
1/2^16 as above?
danilchap
2016/02/03 13:27:11
Done.
|
| + uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR; |
| + // RFC3411, section 4.5, LRR field discription states: |
| + // If no such block has been received, the field is set to zero. |
| + if (send_time == 0) |
| return; |
| - } |
| - |
| - // The DelayLastRR field is in units of 1/65536 sec. |
| - uint32_t delay_rr_ms = |
| - (((packet.XRDLRRReportBlockItem.DelayLastRR & 0x0000ffff) * 1000) >> 16) + |
| - (((packet.XRDLRRReportBlockItem.DelayLastRR & 0xffff0000) >> 16) * 1000); |
| - int64_t rtt = _clock->CurrentNtpInMilliseconds() - delay_rr_ms - send_time_ms; |
| + uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR; |
| + uint32_t now = CompactNtp(NtpTime(*_clock)); |
| - xr_rr_rtt_ms_ = std::max<int64_t>(rtt, 1); |
| + uint32_t rtt_ntp = now - delay_rr - send_time; |
| + uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); |
| + xr_rr_rtt_ms_ = std::max<uint32_t>(rtt_ms, 1); |
|
stefan-webrtc
2016/02/03 10:03:10
Maybe we should break this out into a method and r
danilchap
2016/02/03 13:27:11
I would like to move one of this blocks (the other
|
| rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; |
| } |