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

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) {
åsapersson 2016/03/09 09:00:13 should xr_rrtr_status_ be GUARDED_BY(_criticalSect
danilchap 2016/03/09 09:52:53 Done. Do not think it should, but it doesn't hurt
194 xr_rrtr_status_ = enable;
195 }
196
194 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { 197 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) {
195 assert(rtt_ms); 198 assert(rtt_ms);
196 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 199 CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
197 if (xr_rr_rtt_ms_ == 0) { 200 if (xr_rr_rtt_ms_ == 0) {
198 return false; 201 return false;
199 } 202 }
200 *rtt_ms = xr_rr_rtt_ms_; 203 *rtt_ms = xr_rr_rtt_ms_;
201 xr_rr_rtt_ms_ = 0; 204 xr_rr_rtt_ms_ = 0;
202 return true; 205 return true;
203 } 206 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 uint32_t remoteSSRC) 476 uint32_t remoteSSRC)
474 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { 477 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) {
475 // This will be called once per report block in the RTCP packet. 478 // This will be called once per report block in the RTCP packet.
476 // We filter out all report blocks that are not for us. 479 // We filter out all report blocks that are not for us.
477 // Each packet has max 31 RR blocks. 480 // Each packet has max 31 RR blocks.
478 // 481 //
479 // We can calc RTT if we send a send report and get a report block back. 482 // We can calc RTT if we send a send report and get a report block back.
480 483
481 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to 484 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to
482 // which the information in this reception report block pertains. 485 // which the information in this reception report block pertains.
483 486
åsapersson 2016/03/09 09:00:13 maybe we should move the check earlier and not sto
danilchap 2016/03/09 09:52:53 May be, but not in this CL. (I have CL that change
åsapersson 2016/03/09 10:06:46 Acknowledged.
484 // Filter out all report blocks that are not for us. 487 // Filter out all report blocks that are not for us.
485 if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) == 488 if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) ==
486 registered_ssrcs_.end()) { 489 registered_ssrcs_.end()) {
487 // This block is not for us ignore it. 490 // This block is not for us ignore it.
488 return; 491 return;
489 } 492 }
490 493
491 RTCPReportBlockInformation* reportBlock = 494 RTCPReportBlockInformation* reportBlock =
492 CreateOrGetReportBlockInformation(remoteSSRC, 495 CreateOrGetReportBlockInformation(remoteSSRC,
493 rtcpPacket.ReportBlockItem.SSRC); 496 rtcpPacket.ReportBlockItem.SSRC);
(...skipping 19 matching lines...) Expand all
513 reportBlock->remoteReceiveBlock.extendedHighSeqNum = 516 reportBlock->remoteReceiveBlock.extendedHighSeqNum =
514 rb.ExtendedHighestSequenceNumber; 517 rb.ExtendedHighestSequenceNumber;
515 reportBlock->remoteReceiveBlock.jitter = rb.Jitter; 518 reportBlock->remoteReceiveBlock.jitter = rb.Jitter;
516 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; 519 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR;
517 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; 520 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR;
518 521
519 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { 522 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) {
520 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; 523 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter;
521 } 524 }
522 525
526 int64_t rtt = 0;
523 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR; 527 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR;
524 uint32_t rtt = 0; 528 // RFC3550, section 6.4.1, LSR field discription states:
525 529 // If no SR has been received yet, the field is set to zero.
526 if (send_time > 0) { 530 // Receiver rtp_rtcp module is not expected to calculate rtt using
531 // Sender Reports even if it accidentely can.
åsapersson 2016/03/09 09:00:13 nit: accidentally
danilchap 2016/03/09 09:52:53 Done.
532 if (!receiver_only_ && send_time != 0) {
527 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR; 533 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR;
528 // Local NTP time. 534 // Local NTP time.
529 uint32_t receive_time = CompactNtp(NtpTime(*_clock)); 535 uint32_t receive_time = CompactNtp(NtpTime(*_clock));
530 536
531 // RTT in 1/(2^16) seconds. 537 // RTT in 1/(2^16) seconds.
532 uint32_t rtt_ntp = receive_time - delay - send_time; 538 uint32_t rtt_ntp = receive_time - delay - send_time;
533 // Convert to 1/1000 seconds (milliseconds). 539 // Convert to 1/1000 seconds (milliseconds).
534 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); 540 rtt = CompactNtpRttToMs(rtt_ntp);
535 rtt = std::max<uint32_t>(rtt_ms, 1);
536 if (rtt > reportBlock->maxRTT) { 541 if (rtt > reportBlock->maxRTT) {
537 // Store max RTT. 542 // Store max RTT.
538 reportBlock->maxRTT = rtt; 543 reportBlock->maxRTT = rtt;
539 } 544 }
540 if (reportBlock->minRTT == 0) { 545 if (reportBlock->minRTT == 0) {
541 // First RTT. 546 // First RTT.
542 reportBlock->minRTT = rtt; 547 reportBlock->minRTT = rtt;
543 } else if (rtt < reportBlock->minRTT) { 548 } else if (rtt < reportBlock->minRTT) {
544 // Store min RTT. 549 // Store min RTT.
545 reportBlock->minRTT = rtt; 550 reportBlock->minRTT = rtt;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 RTCPPacketInformation& rtcpPacketInformation) 914 RTCPPacketInformation& rtcpPacketInformation)
910 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { 915 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) {
911 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) == 916 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) ==
912 registered_ssrcs_.end()) { 917 registered_ssrcs_.end()) {
913 // Not to us. 918 // Not to us.
914 return; 919 return;
915 } 920 }
916 921
917 rtcpPacketInformation.xr_dlrr_item = true; 922 rtcpPacketInformation.xr_dlrr_item = true;
918 923
924 // Caller should explicetely enable rtt calculation using extended reports.
åsapersson 2016/03/09 09:00:13 nit: explicitly
danilchap 2016/03/09 09:52:53 Done.
925 if (!xr_rrtr_status_)
åsapersson 2016/03/09 09:00:13 move check to line 921
danilchap 2016/03/09 09:52:53 Would rather not in this CL: xr_dlrr_item flag is
926 return;
927
919 // The send_time and delay_rr fields are in units of 1/2^16 sec. 928 // The send_time and delay_rr fields are in units of 1/2^16 sec.
920 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR; 929 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR;
921 // RFC3411, section 4.5, LRR field discription states: 930 // RFC3611, section 4.5, LRR field discription states:
922 // If no such block has been received, the field is set to zero. 931 // If no such block has been received, the field is set to zero.
923 if (send_time == 0) 932 if (send_time == 0)
924 return; 933 return;
925 934
926 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR; 935 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR;
927 uint32_t now = CompactNtp(NtpTime(*_clock)); 936 uint32_t now = CompactNtp(NtpTime(*_clock));
928 937
929 uint32_t rtt_ntp = now - delay_rr - send_time; 938 uint32_t rtt_ntp = now - delay_rr - send_time;
930 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); 939 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
931 xr_rr_rtt_ms_ = std::max<uint32_t>(rtt_ms, 1);
932 940
933 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; 941 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock;
934 } 942 }
935 943
936 void 944 void
937 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, 945 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
938 RTCPPacketInformation& rtcpPacketInformation) 946 RTCPPacketInformation& rtcpPacketInformation)
939 { 947 {
940 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 948 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
941 949
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 return -1; 1453 return -1;
1446 } 1454 }
1447 num += receiveInfo->TmmbrSet.lengthOfSet(); 1455 num += receiveInfo->TmmbrSet.lengthOfSet();
1448 receiveInfoIt++; 1456 receiveInfoIt++;
1449 } 1457 }
1450 } 1458 }
1451 return num; 1459 return num;
1452 } 1460 }
1453 1461
1454 } // namespace webrtc 1462 } // 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