Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc

Issue 1763823003: rtt calculation handles time go backwards (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <algorithm>
17
18 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 18 #include "webrtc/base/trace_event.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
23 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" 21 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
24 #include "webrtc/modules/rtp_rtcp/source/time_util.h" 22 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
25 #include "webrtc/system_wrappers/include/ntp_time.h" 23 #include "webrtc/system_wrappers/include/ntp_time.h"
26 24
27 namespace webrtc { 25 namespace webrtc {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 _cbTransportFeedbackObserver(transport_feedback_observer), 57 _cbTransportFeedbackObserver(transport_feedback_observer),
60 _criticalSectionRTCPReceiver( 58 _criticalSectionRTCPReceiver(
61 CriticalSectionWrapper::CreateCriticalSection()), 59 CriticalSectionWrapper::CreateCriticalSection()),
62 main_ssrc_(0), 60 main_ssrc_(0),
63 _remoteSSRC(0), 61 _remoteSSRC(0),
64 _remoteSenderInfo(), 62 _remoteSenderInfo(),
65 _lastReceivedSRNTPsecs(0), 63 _lastReceivedSRNTPsecs(0),
66 _lastReceivedSRNTPfrac(0), 64 _lastReceivedSRNTPfrac(0),
67 _lastReceivedXRNTPsecs(0), 65 _lastReceivedXRNTPsecs(0),
68 _lastReceivedXRNTPfrac(0), 66 _lastReceivedXRNTPfrac(0),
67 xr_rrtr_status_(false),
69 xr_rr_rtt_ms_(0), 68 xr_rr_rtt_ms_(0),
70 _receivedInfoMap(), 69 _receivedInfoMap(),
71 _lastReceivedRrMs(0), 70 _lastReceivedRrMs(0),
72 _lastIncreasedSequenceNumberMs(0), 71 _lastIncreasedSequenceNumberMs(0),
73 stats_callback_(NULL), 72 stats_callback_(NULL),
74 packet_type_counter_observer_(packet_type_counter_observer), 73 packet_type_counter_observer_(packet_type_counter_observer),
75 num_skipped_packets_(0), 74 num_skipped_packets_(0),
76 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { 75 last_skipped_packets_warning_(clock->TimeInMilliseconds()) {
77 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); 76 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
78 } 77 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 183 }
185 if (minRTT) { 184 if (minRTT) {
186 *minRTT = reportBlock->minRTT; 185 *minRTT = reportBlock->minRTT;
187 } 186 }
188 if (maxRTT) { 187 if (maxRTT) {
189 *maxRTT = reportBlock->maxRTT; 188 *maxRTT = reportBlock->maxRTT;
190 } 189 }
191 return 0; 190 return 0;
192 } 191 }
193 192
193 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) {
194 CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
195 xr_rrtr_status_ = enable;
196 }
197
194 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { 198 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) {
195 assert(rtt_ms); 199 assert(rtt_ms);
196 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 200 CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
197 if (xr_rr_rtt_ms_ == 0) { 201 if (xr_rr_rtt_ms_ == 0) {
198 return false; 202 return false;
199 } 203 }
200 *rtt_ms = xr_rr_rtt_ms_; 204 *rtt_ms = xr_rr_rtt_ms_;
201 xr_rr_rtt_ms_ = 0; 205 xr_rr_rtt_ms_ = 0;
202 return true; 206 return true;
203 } 207 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 reportBlock->remoteReceiveBlock.extendedHighSeqNum = 517 reportBlock->remoteReceiveBlock.extendedHighSeqNum =
514 rb.ExtendedHighestSequenceNumber; 518 rb.ExtendedHighestSequenceNumber;
515 reportBlock->remoteReceiveBlock.jitter = rb.Jitter; 519 reportBlock->remoteReceiveBlock.jitter = rb.Jitter;
516 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; 520 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR;
517 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; 521 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR;
518 522
519 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { 523 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) {
520 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; 524 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter;
521 } 525 }
522 526
527 int64_t rtt = 0;
523 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR; 528 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR;
524 uint32_t rtt = 0; 529 // RFC3550, section 6.4.1, LSR field discription states:
525 530 // If no SR has been received yet, the field is set to zero.
526 if (send_time > 0) { 531 // Receiver rtp_rtcp module is not expected to calculate rtt using
532 // Sender Reports even if it accidentally can.
533 if (!receiver_only_ && send_time != 0) {
527 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR; 534 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR;
528 // Local NTP time. 535 // Local NTP time.
529 uint32_t receive_time = CompactNtp(NtpTime(*_clock)); 536 uint32_t receive_time = CompactNtp(NtpTime(*_clock));
530 537
531 // RTT in 1/(2^16) seconds. 538 // RTT in 1/(2^16) seconds.
532 uint32_t rtt_ntp = receive_time - delay - send_time; 539 uint32_t rtt_ntp = receive_time - delay - send_time;
533 // Convert to 1/1000 seconds (milliseconds). 540 // Convert to 1/1000 seconds (milliseconds).
534 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); 541 rtt = CompactNtpRttToMs(rtt_ntp);
535 rtt = std::max<uint32_t>(rtt_ms, 1);
536 if (rtt > reportBlock->maxRTT) { 542 if (rtt > reportBlock->maxRTT) {
537 // Store max RTT. 543 // Store max RTT.
538 reportBlock->maxRTT = rtt; 544 reportBlock->maxRTT = rtt;
539 } 545 }
540 if (reportBlock->minRTT == 0) { 546 if (reportBlock->minRTT == 0) {
541 // First RTT. 547 // First RTT.
542 reportBlock->minRTT = rtt; 548 reportBlock->minRTT = rtt;
543 } else if (rtt < reportBlock->minRTT) { 549 } else if (rtt < reportBlock->minRTT) {
544 // Store min RTT. 550 // Store min RTT.
545 reportBlock->minRTT = rtt; 551 reportBlock->minRTT = rtt;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 RTCPPacketInformation& rtcpPacketInformation) 915 RTCPPacketInformation& rtcpPacketInformation)
910 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { 916 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) {
911 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) == 917 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) ==
912 registered_ssrcs_.end()) { 918 registered_ssrcs_.end()) {
913 // Not to us. 919 // Not to us.
914 return; 920 return;
915 } 921 }
916 922
917 rtcpPacketInformation.xr_dlrr_item = true; 923 rtcpPacketInformation.xr_dlrr_item = true;
918 924
925 // Caller should explicitly enable rtt calculation using extended reports.
926 if (!xr_rrtr_status_)
927 return;
928
919 // The send_time and delay_rr fields are in units of 1/2^16 sec. 929 // The send_time and delay_rr fields are in units of 1/2^16 sec.
920 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR; 930 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR;
921 // RFC3411, section 4.5, LRR field discription states: 931 // RFC3611, section 4.5, LRR field discription states:
922 // If no such block has been received, the field is set to zero. 932 // If no such block has been received, the field is set to zero.
923 if (send_time == 0) 933 if (send_time == 0)
924 return; 934 return;
925 935
926 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR; 936 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR;
927 uint32_t now = CompactNtp(NtpTime(*_clock)); 937 uint32_t now = CompactNtp(NtpTime(*_clock));
928 938
929 uint32_t rtt_ntp = now - delay_rr - send_time; 939 uint32_t rtt_ntp = now - delay_rr - send_time;
930 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); 940 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
931 xr_rr_rtt_ms_ = std::max<uint32_t>(rtt_ms, 1);
932 941
933 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; 942 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock;
934 } 943 }
935 944
936 void 945 void
937 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, 946 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
938 RTCPPacketInformation& rtcpPacketInformation) 947 RTCPPacketInformation& rtcpPacketInformation)
939 { 948 {
940 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 949 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
941 950
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 return -1; 1454 return -1;
1446 } 1455 }
1447 num += receiveInfo->TmmbrSet.lengthOfSet(); 1456 num += receiveInfo->TmmbrSet.lengthOfSet();
1448 receiveInfoIt++; 1457 receiveInfoIt++;
1449 } 1458 }
1450 } 1459 }
1451 return num; 1460 return num;
1452 } 1461 }
1453 1462
1454 } // namespace webrtc 1463 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698