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 <limits> | 16 #include <limits> |
17 #include <map> | |
17 #include <memory> | 18 #include <memory> |
18 #include <utility> | 19 #include <utility> |
20 #include <vector> | |
19 | 21 |
20 #include "webrtc/base/checks.h" | 22 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/logging.h" | 23 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/trace_event.h" | 24 #include "webrtc/base/trace_event.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
40 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 42 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
41 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 43 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
42 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" | 44 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" |
43 #include "webrtc/system_wrappers/include/ntp_time.h" | 45 #include "webrtc/system_wrappers/include/ntp_time.h" |
44 | 46 |
45 namespace webrtc { | 47 namespace webrtc { |
46 namespace { | 48 namespace { |
47 | 49 |
48 using rtcp::CommonHeader; | 50 using rtcp::CommonHeader; |
49 using rtcp::ReportBlock; | 51 using rtcp::ReportBlock; |
50 using RTCPHelp::RTCPReceiveInformation; | |
51 using RTCPHelp::RTCPReportBlockInformation; | 52 using RTCPHelp::RTCPReportBlockInformation; |
52 | 53 |
53 // The number of RTCP time intervals needed to trigger a timeout. | 54 // The number of RTCP time intervals needed to trigger a timeout. |
54 const int kRrTimeoutIntervals = 3; | 55 const int kRrTimeoutIntervals = 3; |
55 | 56 |
56 const int64_t kMaxWarningLogIntervalMs = 10000; | 57 const int64_t kMaxWarningLogIntervalMs = 10000; |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 struct RTCPReceiver::PacketInformation { | 61 struct RTCPReceiver::PacketInformation { |
61 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. | 62 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. |
62 | 63 |
63 uint32_t remote_ssrc = 0; | 64 uint32_t remote_ssrc = 0; |
64 std::vector<uint16_t> nack_sequence_numbers; | 65 std::vector<uint16_t> nack_sequence_numbers; |
65 ReportBlockList report_blocks; | 66 ReportBlockList report_blocks; |
66 int64_t rtt_ms = 0; | 67 int64_t rtt_ms = 0; |
67 uint8_t sli_picture_id = 0; | 68 uint8_t sli_picture_id = 0; |
68 uint64_t rpsi_picture_id = 0; | 69 uint64_t rpsi_picture_id = 0; |
69 uint32_t receiver_estimated_max_bitrate_bps = 0; | 70 uint32_t receiver_estimated_max_bitrate_bps = 0; |
70 std::unique_ptr<rtcp::TransportFeedback> transport_feedback; | 71 std::unique_ptr<rtcp::TransportFeedback> transport_feedback; |
71 }; | 72 }; |
72 | 73 |
74 struct RTCPReceiver::ReceiveInformation { | |
75 struct TimedTmmbrItem { | |
76 rtcp::TmmbItem tmmbr_item; | |
77 int64_t last_updated_ms; | |
78 }; | |
79 | |
80 int64_t last_time_received_ms = 0; | |
81 | |
82 int64_t last_fir_request_ms = 0; | |
83 int32_t last_fir_sequence_number = -1; | |
84 | |
85 bool ready_for_delete = false; | |
86 | |
87 std::vector<rtcp::TmmbItem> tmmbn; | |
88 std::map<uint32_t, TimedTmmbrItem> tmmbr; | |
89 }; | |
90 | |
73 RTCPReceiver::RTCPReceiver( | 91 RTCPReceiver::RTCPReceiver( |
74 Clock* clock, | 92 Clock* clock, |
75 bool receiver_only, | 93 bool receiver_only, |
76 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 94 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
77 RtcpBandwidthObserver* rtcp_bandwidth_observer, | 95 RtcpBandwidthObserver* rtcp_bandwidth_observer, |
78 RtcpIntraFrameObserver* rtcp_intra_frame_observer, | 96 RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
79 TransportFeedbackObserver* transport_feedback_observer, | 97 TransportFeedbackObserver* transport_feedback_observer, |
80 ModuleRtpRtcp* owner) | 98 ModuleRtpRtcp* owner) |
81 : _clock(clock), | 99 : _clock(clock), |
82 receiver_only_(receiver_only), | 100 receiver_only_(receiver_only), |
83 _rtpRtcp(*owner), | 101 _rtpRtcp(*owner), |
84 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), | 102 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), |
85 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), | 103 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), |
86 _cbTransportFeedbackObserver(transport_feedback_observer), | 104 _cbTransportFeedbackObserver(transport_feedback_observer), |
87 main_ssrc_(0), | 105 main_ssrc_(0), |
88 _remoteSSRC(0), | 106 _remoteSSRC(0), |
89 _remoteSenderInfo(), | 107 _remoteSenderInfo(), |
90 _lastReceivedSRNTPsecs(0), | 108 _lastReceivedSRNTPsecs(0), |
91 _lastReceivedSRNTPfrac(0), | 109 _lastReceivedSRNTPfrac(0), |
92 _lastReceivedXRNTPsecs(0), | 110 _lastReceivedXRNTPsecs(0), |
93 _lastReceivedXRNTPfrac(0), | 111 _lastReceivedXRNTPfrac(0), |
94 xr_rrtr_status_(false), | 112 xr_rrtr_status_(false), |
95 xr_rr_rtt_ms_(0), | 113 xr_rr_rtt_ms_(0), |
96 _receivedInfoMap(), | |
97 _lastReceivedRrMs(0), | 114 _lastReceivedRrMs(0), |
98 _lastIncreasedSequenceNumberMs(0), | 115 _lastIncreasedSequenceNumberMs(0), |
99 stats_callback_(NULL), | 116 stats_callback_(NULL), |
100 packet_type_counter_observer_(packet_type_counter_observer), | 117 packet_type_counter_observer_(packet_type_counter_observer), |
101 num_skipped_packets_(0), | 118 num_skipped_packets_(0), |
102 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { | 119 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { |
103 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); | 120 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
104 } | 121 } |
105 | 122 |
106 RTCPReceiver::~RTCPReceiver() { | 123 RTCPReceiver::~RTCPReceiver() { |
107 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); | 124 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); |
108 for (; it != _receivedReportBlockMap.end(); ++it) { | 125 for (; it != _receivedReportBlockMap.end(); ++it) { |
109 ReportBlockInfoMap* info_map = &(it->second); | 126 ReportBlockInfoMap* info_map = &(it->second); |
110 while (!info_map->empty()) { | 127 while (!info_map->empty()) { |
111 ReportBlockInfoMap::iterator it_info = info_map->begin(); | 128 ReportBlockInfoMap::iterator it_info = info_map->begin(); |
112 delete it_info->second; | 129 delete it_info->second; |
113 info_map->erase(it_info); | 130 info_map->erase(it_info); |
114 } | 131 } |
115 } | 132 } |
116 while (!_receivedInfoMap.empty()) { | |
117 std::map<uint32_t, RTCPReceiveInformation*>::iterator first = | |
118 _receivedInfoMap.begin(); | |
119 delete first->second; | |
120 _receivedInfoMap.erase(first); | |
121 } | |
122 } | 133 } |
123 | 134 |
124 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { | 135 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { |
125 if (packet_size == 0) { | 136 if (packet_size == 0) { |
126 LOG(LS_WARNING) << "Incoming empty RTCP packet"; | 137 LOG(LS_WARNING) << "Incoming empty RTCP packet"; |
127 return false; | 138 return false; |
128 } | 139 } |
129 | 140 |
130 PacketInformation packet_information; | 141 PacketInformation packet_information; |
131 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) | 142 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) |
132 return false; | 143 return false; |
133 TriggerCallbacksFromRTCPPacket(packet_information); | 144 TriggerCallbacksFromRTCPPacket(packet_information); |
134 return true; | 145 return true; |
135 } | 146 } |
136 | 147 |
137 int64_t RTCPReceiver::LastReceivedReceiverReport() const { | 148 int64_t RTCPReceiver::LastReceivedReceiverReport() const { |
138 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 149 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
139 int64_t last_received_rr = -1; | 150 int64_t last_received_rr = -1; |
philipel
2016/09/29 11:39:21
Maybe make |last_received_rr| a member variable an
danilchap
2016/09/29 13:00:58
It totaly make sense, thank you, but it turn out t
philipel
2016/09/29 14:43:38
Lets do it in another CL then.
| |
140 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); | 151 for (const auto& kv : received_infos_) |
141 it != _receivedInfoMap.end(); ++it) { | 152 if (kv.second.last_time_received_ms > last_received_rr) |
142 if (it->second->last_time_received_ms > last_received_rr) { | 153 last_received_rr = kv.second.last_time_received_ms; |
143 last_received_rr = it->second->last_time_received_ms; | |
144 } | |
145 } | |
146 return last_received_rr; | 154 return last_received_rr; |
147 } | 155 } |
148 | 156 |
149 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { | 157 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { |
150 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 158 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
151 | 159 |
152 // new SSRC reset old reports | 160 // new SSRC reset old reports |
153 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); | 161 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
154 _lastReceivedSRNTPsecs = 0; | 162 _lastReceivedSRNTPsecs = 0; |
155 _lastReceivedSRNTPfrac = 0; | 163 _lastReceivedSRNTPfrac = 0; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 rtcp::SenderReport sender_report; | 421 rtcp::SenderReport sender_report; |
414 if (!sender_report.Parse(rtcp_block)) { | 422 if (!sender_report.Parse(rtcp_block)) { |
415 ++num_skipped_packets_; | 423 ++num_skipped_packets_; |
416 return; | 424 return; |
417 } | 425 } |
418 | 426 |
419 const uint32_t remoteSSRC = sender_report.sender_ssrc(); | 427 const uint32_t remoteSSRC = sender_report.sender_ssrc(); |
420 | 428 |
421 packet_information->remote_ssrc = remoteSSRC; | 429 packet_information->remote_ssrc = remoteSSRC; |
422 | 430 |
423 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); | 431 CreateReceiveInformation(remoteSSRC); |
424 if (!ptrReceiveInfo) | |
425 return; | |
426 | 432 |
427 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", | 433 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", |
428 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 434 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
429 | 435 |
430 // Have I received RTP packets from this party? | 436 // Have I received RTP packets from this party? |
431 if (_remoteSSRC == remoteSSRC) { | 437 if (_remoteSSRC == remoteSSRC) { |
432 // Only signal that we have received a SR when we accept one. | 438 // Only signal that we have received a SR when we accept one. |
433 packet_information->packet_type_flags |= kRtcpSr; | 439 packet_information->packet_type_flags |= kRtcpSr; |
434 | 440 |
435 // Save the NTP time of this report. | 441 // Save the NTP time of this report. |
436 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); | 442 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); |
437 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); | 443 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); |
438 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); | 444 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); |
439 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); | 445 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); |
440 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); | 446 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); |
441 | 447 |
442 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); | 448 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); |
443 } else { | 449 } else { |
444 // We will only store the send report from one source, but | 450 // We will only store the send report from one source, but |
445 // we will store all the receive blocks. | 451 // we will store all the receive blocks. |
446 packet_information->packet_type_flags |= kRtcpRr; | 452 packet_information->packet_type_flags |= kRtcpRr; |
447 } | 453 } |
448 // Update that this remote is alive. | |
449 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); | |
450 | 454 |
451 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) | 455 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) |
452 HandleReportBlock(report_block, packet_information, remoteSSRC); | 456 HandleReportBlock(report_block, packet_information, remoteSSRC); |
453 } | 457 } |
454 | 458 |
455 void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, | 459 void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, |
456 PacketInformation* packet_information) { | 460 PacketInformation* packet_information) { |
457 rtcp::ReceiverReport receiver_report; | 461 rtcp::ReceiverReport receiver_report; |
458 if (!receiver_report.Parse(rtcp_block)) { | 462 if (!receiver_report.Parse(rtcp_block)) { |
459 ++num_skipped_packets_; | 463 ++num_skipped_packets_; |
460 return; | 464 return; |
461 } | 465 } |
462 | 466 |
463 const uint32_t remoteSSRC = receiver_report.sender_ssrc(); | 467 const uint32_t remoteSSRC = receiver_report.sender_ssrc(); |
464 | 468 |
465 packet_information->remote_ssrc = remoteSSRC; | 469 packet_information->remote_ssrc = remoteSSRC; |
466 | 470 |
467 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); | 471 CreateReceiveInformation(remoteSSRC); |
468 if (!ptrReceiveInfo) | |
469 return; | |
470 | 472 |
471 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", | 473 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", |
472 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 474 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
473 | 475 |
474 packet_information->packet_type_flags |= kRtcpRr; | 476 packet_information->packet_type_flags |= kRtcpRr; |
475 | 477 |
476 // Update that this remote is alive. | |
477 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); | |
478 | |
479 for (const ReportBlock& report_block : receiver_report.report_blocks()) | 478 for (const ReportBlock& report_block : receiver_report.report_blocks()) |
480 HandleReportBlock(report_block, packet_information, remoteSSRC); | 479 HandleReportBlock(report_block, packet_information, remoteSSRC); |
481 } | 480 } |
482 | 481 |
483 void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, | 482 void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, |
484 PacketInformation* packet_information, | 483 PacketInformation* packet_information, |
485 uint32_t remoteSSRC) { | 484 uint32_t remoteSSRC) { |
486 // This will be called once per report block in the RTCP packet. | 485 // This will be called once per report block in the RTCP packet. |
487 // We filter out all report blocks that are not for us. | 486 // We filter out all report blocks that are not for us. |
488 // Each packet has max 31 RR blocks. | 487 // Each packet has max 31 RR blocks. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 return NULL; | 594 return NULL; |
596 } | 595 } |
597 const ReportBlockInfoMap* info_map = &(it->second); | 596 const ReportBlockInfoMap* info_map = &(it->second); |
598 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc); | 597 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc); |
599 if (it_info == info_map->end()) { | 598 if (it_info == info_map->end()) { |
600 return NULL; | 599 return NULL; |
601 } | 600 } |
602 return it_info->second; | 601 return it_info->second; |
603 } | 602 } |
604 | 603 |
605 RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation( | 604 void RTCPReceiver::CreateReceiveInformation(uint32_t remote_ssrc) { |
606 uint32_t remoteSSRC) { | 605 // Create or find receive information. |
607 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 606 ReceiveInformation* receive_info = &received_infos_[remote_ssrc]; |
608 | 607 // Update that this remote is alive. |
609 std::map<uint32_t, RTCPReceiveInformation*>::iterator it = | 608 receive_info->last_time_received_ms = _clock->TimeInMilliseconds(); |
610 _receivedInfoMap.find(remoteSSRC); | |
611 | |
612 if (it != _receivedInfoMap.end()) { | |
613 return it->second; | |
614 } | |
615 RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation; | |
616 _receivedInfoMap[remoteSSRC] = receiveInfo; | |
617 return receiveInfo; | |
618 } | 609 } |
619 | 610 |
620 RTCPReceiveInformation* RTCPReceiver::GetReceiveInformation( | 611 RTCPReceiver::ReceiveInformation* RTCPReceiver::GetReceiveInformation( |
621 uint32_t remoteSSRC) { | 612 uint32_t remote_ssrc) { |
622 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 613 auto it = received_infos_.find(remote_ssrc); |
623 | 614 if (it == received_infos_.end()) |
624 std::map<uint32_t, RTCPReceiveInformation*>::iterator it = | 615 return nullptr; |
625 _receivedInfoMap.find(remoteSSRC); | 616 return &it->second; |
626 if (it == _receivedInfoMap.end()) { | |
627 return NULL; | |
628 } | |
629 return it->second; | |
630 } | 617 } |
631 | 618 |
632 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { | 619 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { |
633 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 620 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
634 if (_lastReceivedRrMs == 0) | 621 if (_lastReceivedRrMs == 0) |
635 return false; | 622 return false; |
636 | 623 |
637 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; | 624 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
638 if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { | 625 if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { |
639 // Reset the timer to only trigger one log. | 626 // Reset the timer to only trigger one log. |
(...skipping 14 matching lines...) Expand all Loading... | |
654 // Reset the timer to only trigger one log. | 641 // Reset the timer to only trigger one log. |
655 _lastIncreasedSequenceNumberMs = 0; | 642 _lastIncreasedSequenceNumberMs = 0; |
656 return true; | 643 return true; |
657 } | 644 } |
658 return false; | 645 return false; |
659 } | 646 } |
660 | 647 |
661 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { | 648 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { |
662 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 649 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
663 | 650 |
664 bool updateBoundingSet = false; | 651 bool update_bounding_set = false; |
665 int64_t timeNow = _clock->TimeInMilliseconds(); | 652 int64_t now_ms = _clock->TimeInMilliseconds(); |
653 // Use audio define since we don't know what interval the remote peer use. | |
654 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; | |
666 | 655 |
667 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = | 656 for (auto receive_info_it = received_infos_.begin(); |
668 _receivedInfoMap.begin(); | 657 receive_info_it != received_infos_.end();) { |
669 | 658 ReceiveInformation* receive_info = &receive_info_it->second; |
670 while (receiveInfoIt != _receivedInfoMap.end()) { | 659 if (receive_info->last_time_received_ms > 0) { |
671 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; | 660 if (receive_info->last_time_received_ms < timeouted_ms) { |
672 if (receiveInfo == NULL) { | 661 // No rtcp packet for the last 5 regular intervals, reset limitations. |
673 return updateBoundingSet; | 662 receive_info->tmmbr.clear(); |
674 } | 663 // Prevent that we call this over and over again. |
675 // time since last received rtcp packet | 664 receive_info->last_time_received_ms = 0; |
676 // when we dont have a lastTimeReceived and the object is marked | 665 // Send new TMMBN to all channels using the default codec. |
677 // readyForDelete it's removed from the map | 666 update_bounding_set = true; |
678 if (receiveInfo->last_time_received_ms > 0) { | |
679 /// use audio define since we don't know what interval the remote peer is | |
680 // using | |
681 if ((timeNow - receiveInfo->last_time_received_ms) > | |
682 5 * RTCP_INTERVAL_AUDIO_MS) { | |
683 // no rtcp packet for the last five regular intervals, reset limitations | |
684 receiveInfo->ClearTmmbr(); | |
685 // prevent that we call this over and over again | |
686 receiveInfo->last_time_received_ms = 0; | |
687 // send new TMMBN to all channels using the default codec | |
688 updateBoundingSet = true; | |
689 } | 667 } |
690 receiveInfoIt++; | 668 ++receive_info_it; |
691 } else if (receiveInfo->ready_for_delete) { | 669 } else if (receive_info->ready_for_delete) { |
philipel
2016/09/29 11:39:21
Should a ReceiveInfo that is ready for deletion ev
danilchap
2016/09/29 13:00:58
Comment (not mine, I just moved it) explicitly say
philipel
2016/09/29 14:43:38
Oops, missed that comment :)
| |
692 // store our current receiveInfoItem | 670 // When we dont have a last_time_received_ms and the object is marked |
693 std::map<uint32_t, RTCPReceiveInformation*>::iterator | 671 // ready_for_delete it's removed from the map. |
694 receiveInfoItemToBeErased = receiveInfoIt; | 672 receive_info_it = received_infos_.erase(receive_info_it); |
695 receiveInfoIt++; | |
696 delete receiveInfoItemToBeErased->second; | |
697 _receivedInfoMap.erase(receiveInfoItemToBeErased); | |
698 } else { | 673 } else { |
699 receiveInfoIt++; | 674 ++receive_info_it; |
700 } | 675 } |
701 } | 676 } |
702 return updateBoundingSet; | 677 return update_bounding_set; |
703 } | 678 } |
704 | 679 |
705 std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) { | 680 std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) { |
706 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 681 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
682 ReceiveInformation* receive_info = GetReceiveInformation(_remoteSSRC); | |
683 if (!receive_info) | |
684 return std::vector<rtcp::TmmbItem>(); | |
707 | 685 |
708 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = | 686 *tmmbr_owner = TMMBRHelp::IsOwner(receive_info->tmmbn, main_ssrc_); |
709 _receivedInfoMap.find(_remoteSSRC); | 687 return receive_info->tmmbn; |
710 | |
711 if (receiveInfoIt == _receivedInfoMap.end()) { | |
712 return std::vector<rtcp::TmmbItem>(); | |
713 } | |
714 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; | |
715 RTC_DCHECK(receiveInfo); | |
716 | |
717 *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_); | |
718 return receiveInfo->tmmbn; | |
719 } | 688 } |
720 | 689 |
721 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, | 690 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, |
722 PacketInformation* packet_information) { | 691 PacketInformation* packet_information) { |
723 rtcp::Sdes sdes; | 692 rtcp::Sdes sdes; |
724 if (!sdes.Parse(rtcp_block)) { | 693 if (!sdes.Parse(rtcp_block)) { |
725 ++num_skipped_packets_; | 694 ++num_skipped_packets_; |
726 return; | 695 return; |
727 } | 696 } |
728 | 697 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); | 740 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); |
772 for (; it != _receivedReportBlockMap.end(); ++it) { | 741 for (; it != _receivedReportBlockMap.end(); ++it) { |
773 ReportBlockInfoMap* info_map = &(it->second); | 742 ReportBlockInfoMap* info_map = &(it->second); |
774 ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc()); | 743 ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc()); |
775 if (it_info != info_map->end()) { | 744 if (it_info != info_map->end()) { |
776 delete it_info->second; | 745 delete it_info->second; |
777 info_map->erase(it_info); | 746 info_map->erase(it_info); |
778 } | 747 } |
779 } | 748 } |
780 | 749 |
781 // we can't delete it due to TMMBR | 750 // We can't delete it due to TMMBR. |
782 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = | 751 ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc()); |
783 _receivedInfoMap.find(bye.sender_ssrc()); | 752 if (receive_info) |
784 | 753 receive_info->ready_for_delete = true; |
785 if (receiveInfoIt != _receivedInfoMap.end()) | |
786 receiveInfoIt->second->ready_for_delete = true; | |
787 | 754 |
788 received_cnames_.erase(bye.sender_ssrc()); | 755 received_cnames_.erase(bye.sender_ssrc()); |
789 xr_rr_rtt_ms_ = 0; | 756 xr_rr_rtt_ms_ = 0; |
790 } | 757 } |
791 | 758 |
792 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, | 759 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, |
793 PacketInformation* packet_information) { | 760 PacketInformation* packet_information) { |
794 rtcp::ExtendedReports xr; | 761 rtcp::ExtendedReports xr; |
795 if (!xr.Parse(rtcp_block)) { | 762 if (!xr.Parse(rtcp_block)) { |
796 ++num_skipped_packets_; | 763 ++num_skipped_packets_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 } | 821 } |
855 | 822 |
856 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, | 823 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, |
857 PacketInformation* packet_information) { | 824 PacketInformation* packet_information) { |
858 rtcp::Tmmbr tmmbr; | 825 rtcp::Tmmbr tmmbr; |
859 if (!tmmbr.Parse(rtcp_block)) { | 826 if (!tmmbr.Parse(rtcp_block)) { |
860 ++num_skipped_packets_; | 827 ++num_skipped_packets_; |
861 return; | 828 return; |
862 } | 829 } |
863 | 830 |
864 uint32_t senderSSRC = tmmbr.sender_ssrc(); | 831 uint32_t sender_ssrc = tmmbr.sender_ssrc(); |
865 RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); | 832 ReceiveInformation* receive_info = GetReceiveInformation(sender_ssrc); |
866 if (!ptrReceiveInfo) // This remote SSRC must be saved before. | 833 if (!receive_info) // This remote SSRC must be saved before. |
867 return; | 834 return; |
868 | 835 |
869 if (tmmbr.media_ssrc()) { | 836 if (tmmbr.media_ssrc()) { |
870 // media_ssrc() SHOULD be 0 if same as SenderSSRC. | 837 // media_ssrc() SHOULD be 0 if same as SenderSSRC. |
871 // In relay mode this is a valid number. | 838 // In relay mode this is a valid number. |
872 senderSSRC = tmmbr.media_ssrc(); | 839 sender_ssrc = tmmbr.media_ssrc(); |
873 } | 840 } |
874 | 841 |
875 for (const rtcp::TmmbItem& request : tmmbr.requests()) { | 842 for (const rtcp::TmmbItem& request : tmmbr.requests()) { |
876 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { | 843 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { |
877 ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request, | 844 auto* entry = &receive_info->tmmbr[sender_ssrc]; |
878 _clock->TimeInMilliseconds()); | 845 entry->tmmbr_item = rtcp::TmmbItem(sender_ssrc, |
846 request.bitrate_bps(), | |
847 request.packet_overhead()); | |
848 entry->last_updated_ms = _clock->TimeInMilliseconds(); | |
849 | |
879 packet_information->packet_type_flags |= kRtcpTmmbr; | 850 packet_information->packet_type_flags |= kRtcpTmmbr; |
880 } | 851 } |
881 } | 852 } |
882 } | 853 } |
883 | 854 |
884 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, | 855 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, |
885 PacketInformation* packet_information) { | 856 PacketInformation* packet_information) { |
886 rtcp::Tmmbn tmmbn; | 857 rtcp::Tmmbn tmmbn; |
887 if (!tmmbn.Parse(rtcp_block)) { | 858 if (!tmmbn.Parse(rtcp_block)) { |
888 ++num_skipped_packets_; | 859 ++num_skipped_packets_; |
889 return; | 860 return; |
890 } | 861 } |
891 | 862 |
892 RTCPReceiveInformation* ptrReceiveInfo = | 863 ReceiveInformation* receive_info = GetReceiveInformation(tmmbn.sender_ssrc()); |
893 GetReceiveInformation(tmmbn.sender_ssrc()); | 864 if (!receive_info) // This remote SSRC must be saved before. |
894 if (!ptrReceiveInfo) // This remote SSRC must be saved before. | |
895 return; | 865 return; |
896 | 866 |
897 packet_information->packet_type_flags |= kRtcpTmmbn; | 867 packet_information->packet_type_flags |= kRtcpTmmbn; |
898 | 868 |
899 for (const auto& item : tmmbn.items()) | 869 for (const auto& item : tmmbn.items()) |
900 ptrReceiveInfo->tmmbn.push_back(item); | 870 receive_info->tmmbn.push_back(item); |
901 } | 871 } |
902 | 872 |
903 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, | 873 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, |
904 PacketInformation* packet_information) { | 874 PacketInformation* packet_information) { |
905 rtcp::RapidResyncRequest sr_req; | 875 rtcp::RapidResyncRequest sr_req; |
906 if (!sr_req.Parse(rtcp_block)) { | 876 if (!sr_req.Parse(rtcp_block)) { |
907 ++num_skipped_packets_; | 877 ++num_skipped_packets_; |
908 return; | 878 return; |
909 } | 879 } |
910 | 880 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 } | 923 } |
954 | 924 |
955 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, | 925 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, |
956 PacketInformation* packet_information) { | 926 PacketInformation* packet_information) { |
957 rtcp::Fir fir; | 927 rtcp::Fir fir; |
958 if (!fir.Parse(rtcp_block)) { | 928 if (!fir.Parse(rtcp_block)) { |
959 ++num_skipped_packets_; | 929 ++num_skipped_packets_; |
960 return; | 930 return; |
961 } | 931 } |
962 | 932 |
963 RTCPReceiveInformation* ptrReceiveInfo = | 933 ReceiveInformation* receive_info = GetReceiveInformation(fir.sender_ssrc()); |
964 GetReceiveInformation(fir.sender_ssrc()); | |
965 | 934 |
966 for (const rtcp::Fir::Request& fir_request : fir.requests()) { | 935 for (const rtcp::Fir::Request& fir_request : fir.requests()) { |
967 // Is it our sender that is requested to generate a new keyframe | 936 // Is it our sender that is requested to generate a new keyframe |
968 if (main_ssrc_ != fir_request.ssrc) | 937 if (main_ssrc_ != fir_request.ssrc) |
969 continue; | 938 continue; |
970 | 939 |
971 ++packet_type_counter_.fir_packets; | 940 ++packet_type_counter_.fir_packets; |
972 | 941 |
973 // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it | 942 if (receive_info) { |
974 // we don't know who this originate from | 943 // Check if we have reported this FIRSequenceNumber before. |
975 if (ptrReceiveInfo) { | 944 if (fir_request.seq_nr == receive_info->last_fir_sequence_number) |
976 // check if we have reported this FIRSequenceNumber before | 945 continue; |
977 if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) { | 946 |
978 int64_t now = _clock->TimeInMilliseconds(); | 947 int64_t now_ms = _clock->TimeInMilliseconds(); |
979 // sanity; don't go crazy with the callbacks | 948 // Sanity: don't go crazy with the callbacks. |
980 if ((now - ptrReceiveInfo->last_fir_request_ms) > | 949 if (now_ms - receive_info->last_fir_request_ms < RTCP_MIN_FRAME_LENGTH_MS) |
981 RTCP_MIN_FRAME_LENGTH_MS) { | 950 continue; |
982 ptrReceiveInfo->last_fir_request_ms = now; | 951 |
983 ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr; | 952 receive_info->last_fir_request_ms = now_ms; |
984 // received signal that we need to send a new key frame | 953 receive_info->last_fir_sequence_number = fir_request.seq_nr; |
985 packet_information->packet_type_flags |= kRtcpFir; | |
986 } | |
987 } | |
988 } else { | |
989 // received signal that we need to send a new key frame | |
990 packet_information->packet_type_flags |= kRtcpFir; | |
991 } | 954 } |
955 // Received signal that we need to send a new key frame. | |
956 packet_information->packet_type_flags |= kRtcpFir; | |
992 } | 957 } |
993 } | 958 } |
994 | 959 |
995 void RTCPReceiver::HandleTransportFeedback( | 960 void RTCPReceiver::HandleTransportFeedback( |
996 const CommonHeader& rtcp_block, | 961 const CommonHeader& rtcp_block, |
997 PacketInformation* packet_information) { | 962 PacketInformation* packet_information) { |
998 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( | 963 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( |
999 new rtcp::TransportFeedback()); | 964 new rtcp::TransportFeedback()); |
1000 if (!transport_feedback->Parse(rtcp_block)) { | 965 if (!transport_feedback->Parse(rtcp_block)) { |
1001 ++num_skipped_packets_; | 966 ++num_skipped_packets_; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1108 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
1144 auto received_cname_it = received_cnames_.find(remoteSSRC); | 1109 auto received_cname_it = received_cnames_.find(remoteSSRC); |
1145 if (received_cname_it == received_cnames_.end()) | 1110 if (received_cname_it == received_cnames_.end()) |
1146 return -1; | 1111 return -1; |
1147 | 1112 |
1148 size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1); | 1113 size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1); |
1149 cName[length] = 0; | 1114 cName[length] = 0; |
1150 return 0; | 1115 return 0; |
1151 } | 1116 } |
1152 | 1117 |
1153 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() const { | 1118 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() { |
1154 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1119 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
1155 std::vector<rtcp::TmmbItem> candidates; | 1120 std::vector<rtcp::TmmbItem> candidates; |
1156 | 1121 |
1157 int64_t now_ms = _clock->TimeInMilliseconds(); | 1122 int64_t now_ms = _clock->TimeInMilliseconds(); |
1123 // Use audio define since we don't know what interval the remote peer use. | |
1124 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; | |
1158 | 1125 |
1159 for (const auto& kv : _receivedInfoMap) { | 1126 for (auto& kv : received_infos_) { |
1160 RTCPReceiveInformation* receive_info = kv.second; | 1127 for (auto it = kv.second.tmmbr.begin(); it != kv.second.tmmbr.end();) { |
1161 RTC_DCHECK(receive_info); | 1128 if (it->second.last_updated_ms < timeouted_ms) { |
1162 receive_info->GetTmmbrSet(now_ms, &candidates); | 1129 // Erase timeout entries. |
1130 it = kv.second.tmmbr.erase(it); | |
1131 } else { | |
1132 candidates.push_back(it->second.tmmbr_item); | |
1133 ++it; | |
1134 } | |
1135 } | |
1163 } | 1136 } |
1164 return candidates; | 1137 return candidates; |
1165 } | 1138 } |
1166 | 1139 |
1167 } // namespace webrtc | 1140 } // namespace webrtc |
OLD | NEW |