OLD | NEW |
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> | 16 #include <algorithm> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/trace_event.h" | 20 #include "webrtc/base/trace_event.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| 24 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| 25 #include "webrtc/system_wrappers/include/ntp_time.h" |
24 | 26 |
25 namespace webrtc { | 27 namespace webrtc { |
26 using RTCPHelp::RTCPPacketInformation; | 28 using RTCPHelp::RTCPPacketInformation; |
27 using RTCPHelp::RTCPReceiveInformation; | 29 using RTCPHelp::RTCPReceiveInformation; |
28 using RTCPHelp::RTCPReportBlockInformation; | 30 using RTCPHelp::RTCPReportBlockInformation; |
29 using RTCPUtility::kBtVoipMetric; | 31 using RTCPUtility::kBtVoipMetric; |
30 using RTCPUtility::RTCPCnameInformation; | 32 using RTCPUtility::RTCPCnameInformation; |
31 using RTCPUtility::RTCPPacketReportBlockItem; | 33 using RTCPUtility::RTCPPacketReportBlockItem; |
32 using RTCPUtility::RTCPPacketTypes; | 34 using RTCPUtility::RTCPPacketTypes; |
33 | 35 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to | 482 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to |
481 // which the information in this reception report block pertains. | 483 // which the information in this reception report block pertains. |
482 | 484 |
483 // Filter out all report blocks that are not for us. | 485 // Filter out all report blocks that are not for us. |
484 if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) == | 486 if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) == |
485 registered_ssrcs_.end()) { | 487 registered_ssrcs_.end()) { |
486 // This block is not for us ignore it. | 488 // This block is not for us ignore it. |
487 return; | 489 return; |
488 } | 490 } |
489 | 491 |
490 // To avoid problem with acquiring _criticalSectionRTCPSender while holding | |
491 // _criticalSectionRTCPReceiver. | |
492 _criticalSectionRTCPReceiver->Leave(); | |
493 int64_t sendTimeMS = | |
494 _rtpRtcp.SendTimeOfSendReport(rtcpPacket.ReportBlockItem.LastSR); | |
495 _criticalSectionRTCPReceiver->Enter(); | |
496 | |
497 RTCPReportBlockInformation* reportBlock = | 492 RTCPReportBlockInformation* reportBlock = |
498 CreateOrGetReportBlockInformation(remoteSSRC, | 493 CreateOrGetReportBlockInformation(remoteSSRC, |
499 rtcpPacket.ReportBlockItem.SSRC); | 494 rtcpPacket.ReportBlockItem.SSRC); |
500 if (reportBlock == NULL) { | 495 if (reportBlock == NULL) { |
501 LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" | 496 LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" |
502 << remoteSSRC << ")"; | 497 << remoteSSRC << ")"; |
503 return; | 498 return; |
504 } | 499 } |
505 | 500 |
506 _lastReceivedRrMs = _clock->TimeInMilliseconds(); | 501 _lastReceivedRrMs = _clock->TimeInMilliseconds(); |
(...skipping 12 matching lines...) Expand all Loading... |
519 reportBlock->remoteReceiveBlock.extendedHighSeqNum = | 514 reportBlock->remoteReceiveBlock.extendedHighSeqNum = |
520 rb.ExtendedHighestSequenceNumber; | 515 rb.ExtendedHighestSequenceNumber; |
521 reportBlock->remoteReceiveBlock.jitter = rb.Jitter; | 516 reportBlock->remoteReceiveBlock.jitter = rb.Jitter; |
522 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; | 517 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; |
523 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; | 518 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; |
524 | 519 |
525 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { | 520 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { |
526 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; | 521 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; |
527 } | 522 } |
528 | 523 |
529 uint32_t delaySinceLastSendReport = | 524 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR; |
530 rtcpPacket.ReportBlockItem.DelayLastSR; | 525 uint32_t rtt = 0; |
531 | 526 |
532 // local NTP time when we received this | 527 if (send_time > 0) { |
533 uint32_t lastReceivedRRNTPsecs = 0; | 528 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR; |
534 uint32_t lastReceivedRRNTPfrac = 0; | 529 // Local NTP time. |
| 530 uint32_t receive_time = CompactNtp(NtpTime(*_clock)); |
535 | 531 |
536 _clock->CurrentNtp(lastReceivedRRNTPsecs, lastReceivedRRNTPfrac); | 532 // RTT in 1/(2^16) seconds. |
537 | 533 uint32_t rtt_ntp = receive_time - delay - send_time; |
538 // time when we received this in MS | 534 // Convert to 1/1000 seconds (milliseconds). |
539 int64_t receiveTimeMS = Clock::NtpToMs(lastReceivedRRNTPsecs, | 535 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); |
540 lastReceivedRRNTPfrac); | 536 rtt = std::max<uint32_t>(rtt_ms, 1); |
541 | 537 if (rtt > reportBlock->maxRTT) { |
542 // Estimate RTT | 538 // Store max RTT. |
543 uint32_t d = (delaySinceLastSendReport & 0x0000ffff) * 1000; | 539 reportBlock->maxRTT = rtt; |
544 d /= 65536; | |
545 d += ((delaySinceLastSendReport & 0xffff0000) >> 16) * 1000; | |
546 | |
547 int64_t RTT = 0; | |
548 | |
549 if (sendTimeMS > 0) { | |
550 RTT = receiveTimeMS - d - sendTimeMS; | |
551 if (RTT <= 0) { | |
552 RTT = 1; | |
553 } | |
554 if (RTT > reportBlock->maxRTT) { | |
555 // store max RTT | |
556 reportBlock->maxRTT = RTT; | |
557 } | 540 } |
558 if (reportBlock->minRTT == 0) { | 541 if (reportBlock->minRTT == 0) { |
559 // first RTT | 542 // First RTT. |
560 reportBlock->minRTT = RTT; | 543 reportBlock->minRTT = rtt; |
561 } else if (RTT < reportBlock->minRTT) { | 544 } else if (rtt < reportBlock->minRTT) { |
562 // Store min RTT | 545 // Store min RTT. |
563 reportBlock->minRTT = RTT; | 546 reportBlock->minRTT = rtt; |
564 } | 547 } |
565 // store last RTT | 548 // Store last RTT. |
566 reportBlock->RTT = RTT; | 549 reportBlock->RTT = rtt; |
567 | 550 |
568 // store average RTT | 551 // store average RTT |
569 if (reportBlock->numAverageCalcs != 0) { | 552 if (reportBlock->numAverageCalcs != 0) { |
570 float ac = static_cast<float>(reportBlock->numAverageCalcs); | 553 float ac = static_cast<float>(reportBlock->numAverageCalcs); |
571 float newAverage = | 554 float newAverage = |
572 ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * RTT); | 555 ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt); |
573 reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f); | 556 reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f); |
574 } else { | 557 } else { |
575 // first RTT | 558 // First RTT. |
576 reportBlock->avgRTT = RTT; | 559 reportBlock->avgRTT = rtt; |
577 } | 560 } |
578 reportBlock->numAverageCalcs++; | 561 reportBlock->numAverageCalcs++; |
579 } | 562 } |
580 | 563 |
581 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", rb.SSRC, | 564 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", rb.SSRC, |
582 RTT); | 565 rtt); |
583 | 566 |
584 rtcpPacketInformation.AddReportInfo(*reportBlock); | 567 rtcpPacketInformation.AddReportInfo(*reportBlock); |
585 } | 568 } |
586 | 569 |
587 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( | 570 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( |
588 uint32_t remote_ssrc, | 571 uint32_t remote_ssrc, |
589 uint32_t source_ssrc) { | 572 uint32_t source_ssrc) { |
590 RTCPReportBlockInformation* info = | 573 RTCPReportBlockInformation* info = |
591 GetReportBlockInformation(remote_ssrc, source_ssrc); | 574 GetReportBlockInformation(remote_ssrc, source_ssrc); |
592 if (info == NULL) { | 575 if (info == NULL) { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 RTCPPacketInformation& rtcpPacketInformation) | 910 RTCPPacketInformation& rtcpPacketInformation) |
928 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { | 911 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { |
929 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) == | 912 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) == |
930 registered_ssrcs_.end()) { | 913 registered_ssrcs_.end()) { |
931 // Not to us. | 914 // Not to us. |
932 return; | 915 return; |
933 } | 916 } |
934 | 917 |
935 rtcpPacketInformation.xr_dlrr_item = true; | 918 rtcpPacketInformation.xr_dlrr_item = true; |
936 | 919 |
937 // To avoid problem with acquiring _criticalSectionRTCPSender while holding | 920 // The send_time and delay_rr fields are in units of 1/2^16 sec. |
938 // _criticalSectionRTCPReceiver. | 921 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR; |
939 _criticalSectionRTCPReceiver->Leave(); | 922 // RFC3411, section 4.5, LRR field discription states: |
| 923 // If no such block has been received, the field is set to zero. |
| 924 if (send_time == 0) |
| 925 return; |
940 | 926 |
941 int64_t send_time_ms; | 927 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR; |
942 bool found = _rtpRtcp.SendTimeOfXrRrReport( | 928 uint32_t now = CompactNtp(NtpTime(*_clock)); |
943 packet.XRDLRRReportBlockItem.LastRR, &send_time_ms); | |
944 | 929 |
945 _criticalSectionRTCPReceiver->Enter(); | 930 uint32_t rtt_ntp = now - delay_rr - send_time; |
946 | 931 uint32_t rtt_ms = CompactNtpIntervalToMs(rtt_ntp); |
947 if (!found) { | 932 xr_rr_rtt_ms_ = std::max<uint32_t>(rtt_ms, 1); |
948 return; | |
949 } | |
950 | |
951 // The DelayLastRR field is in units of 1/65536 sec. | |
952 uint32_t delay_rr_ms = | |
953 (((packet.XRDLRRReportBlockItem.DelayLastRR & 0x0000ffff) * 1000) >> 16) + | |
954 (((packet.XRDLRRReportBlockItem.DelayLastRR & 0xffff0000) >> 16) * 1000); | |
955 | |
956 int64_t rtt = _clock->CurrentNtpInMilliseconds() - delay_rr_ms - send_time_ms; | |
957 | |
958 xr_rr_rtt_ms_ = std::max<int64_t>(rtt, 1); | |
959 | 933 |
960 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; | 934 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; |
961 } | 935 } |
962 | 936 |
963 void | 937 void |
964 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, | 938 RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, |
965 RTCPPacketInformation& rtcpPacketInformation) | 939 RTCPPacketInformation& rtcpPacketInformation) |
966 { | 940 { |
967 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); | 941 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
968 | 942 |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 return -1; | 1446 return -1; |
1473 } | 1447 } |
1474 num += receiveInfo->TmmbrSet.lengthOfSet(); | 1448 num += receiveInfo->TmmbrSet.lengthOfSet(); |
1475 receiveInfoIt++; | 1449 receiveInfoIt++; |
1476 } | 1450 } |
1477 } | 1451 } |
1478 return num; | 1452 return num; |
1479 } | 1453 } |
1480 | 1454 |
1481 } // namespace webrtc | 1455 } // namespace webrtc |
OLD | NEW |