niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <string.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
danilchap | 2f69ce9 | 2016-08-16 03:21:38 -0700 | [diff] [blame] | 16 | #include <limits> |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 17 | #include <memory> |
| 18 | #include <utility> |
danilchap | 2f69ce9 | 2016-08-16 03:21:38 -0700 | [diff] [blame] | 19 | |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 20 | #include "webrtc/base/checks.h" |
Peter Boström | ebc0b4e | 2015-10-28 16:39:33 +0100 | [diff] [blame] | 21 | #include "webrtc/base/logging.h" |
tommi | e4f9650 | 2015-10-20 23:00:48 -0700 | [diff] [blame] | 22 | #include "webrtc/base/trace_event.h" |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 23 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 24 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 25 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
| 26 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
| 27 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
| 28 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
| 29 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
| 30 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
| 31 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 32 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" |
| 33 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h" |
| 34 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h" |
| 35 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 36 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" |
| 37 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h" |
| 38 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h" |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 39 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
tommi | e4f9650 | 2015-10-20 23:00:48 -0700 | [diff] [blame] | 40 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 41 | #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
danilchap | 13deaad | 2016-05-24 13:25:27 -0700 | [diff] [blame] | 42 | #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 43 | #include "webrtc/system_wrappers/include/ntp_time.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | namespace webrtc { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 46 | namespace { |
| 47 | |
| 48 | using rtcp::CommonHeader; |
| 49 | using rtcp::ReportBlock; |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 50 | using RTCPHelp::RTCPReceiveInformation; |
| 51 | using RTCPHelp::RTCPReportBlockInformation; |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 52 | using RTCPUtility::RTCPCnameInformation; |
| 53 | using RTCPUtility::RTCPPacketReportBlockItem; |
| 54 | using RTCPUtility::RTCPPacketTypes; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 56 | // The number of RTCP time intervals needed to trigger a timeout. |
| 57 | const int kRrTimeoutIntervals = 3; |
| 58 | |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 59 | const int64_t kMaxWarningLogIntervalMs = 10000; |
| 60 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 61 | } // namespace |
| 62 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 63 | struct RTCPReceiver::PacketInformation { |
| 64 | uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. |
| 65 | |
| 66 | uint32_t remote_ssrc = 0; |
| 67 | std::vector<uint16_t> nack_sequence_numbers; |
| 68 | ReportBlockList report_blocks; |
| 69 | int64_t rtt_ms = 0; |
| 70 | uint8_t sli_picture_id = 0; |
| 71 | uint64_t rpsi_picture_id = 0; |
| 72 | uint32_t receiver_estimated_max_bitrate_bps = 0; |
| 73 | std::unique_ptr<rtcp::TransportFeedback> transport_feedback; |
| 74 | }; |
| 75 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 76 | RTCPReceiver::RTCPReceiver( |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 77 | Clock* clock, |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 78 | bool receiver_only, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 79 | RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
mflodman@webrtc.org | 96abda0 | 2015-02-25 13:50:10 +0000 | [diff] [blame] | 80 | RtcpBandwidthObserver* rtcp_bandwidth_observer, |
| 81 | RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 82 | TransportFeedbackObserver* transport_feedback_observer, |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 83 | ModuleRtpRtcp* owner) |
danilchap | 13deaad | 2016-05-24 13:25:27 -0700 | [diff] [blame] | 84 | : _clock(clock), |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 85 | receiver_only_(receiver_only), |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 86 | _rtpRtcp(*owner), |
mflodman@webrtc.org | 96abda0 | 2015-02-25 13:50:10 +0000 | [diff] [blame] | 87 | _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), |
| 88 | _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 89 | _cbTransportFeedbackObserver(transport_feedback_observer), |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 90 | main_ssrc_(0), |
| 91 | _remoteSSRC(0), |
| 92 | _remoteSenderInfo(), |
| 93 | _lastReceivedSRNTPsecs(0), |
| 94 | _lastReceivedSRNTPfrac(0), |
| 95 | _lastReceivedXRNTPsecs(0), |
| 96 | _lastReceivedXRNTPfrac(0), |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 97 | xr_rrtr_status_(false), |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 98 | xr_rr_rtt_ms_(0), |
| 99 | _receivedInfoMap(), |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 100 | _lastReceivedRrMs(0), |
| 101 | _lastIncreasedSequenceNumberMs(0), |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 102 | stats_callback_(NULL), |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 103 | packet_type_counter_observer_(packet_type_counter_observer), |
| 104 | num_skipped_packets_(0), |
| 105 | last_skipped_packets_warning_(clock->TimeInMilliseconds()) { |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 106 | memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | } |
| 108 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 109 | RTCPReceiver::~RTCPReceiver() { |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 110 | ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); |
| 111 | for (; it != _receivedReportBlockMap.end(); ++it) { |
| 112 | ReportBlockInfoMap* info_map = &(it->second); |
| 113 | while (!info_map->empty()) { |
| 114 | ReportBlockInfoMap::iterator it_info = info_map->begin(); |
| 115 | delete it_info->second; |
| 116 | info_map->erase(it_info); |
| 117 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 118 | } |
| 119 | while (!_receivedInfoMap.empty()) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 120 | std::map<uint32_t, RTCPReceiveInformation*>::iterator first = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 121 | _receivedInfoMap.begin(); |
| 122 | delete first->second; |
| 123 | _receivedInfoMap.erase(first); |
| 124 | } |
| 125 | while (!_receivedCnameMap.empty()) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 126 | std::map<uint32_t, RTCPCnameInformation*>::iterator first = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 127 | _receivedCnameMap.begin(); |
| 128 | delete first->second; |
| 129 | _receivedCnameMap.erase(first); |
| 130 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | } |
| 132 | |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 133 | bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 134 | if (packet_size == 0) { |
| 135 | LOG(LS_WARNING) << "Incoming empty RTCP packet"; |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 136 | return false; |
| 137 | } |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 138 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 139 | PacketInformation packet_information; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 140 | if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) |
| 141 | return false; |
| 142 | TriggerCallbacksFromRTCPPacket(packet_information); |
| 143 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | } |
| 145 | |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 146 | int64_t RTCPReceiver::LastReceivedReceiverReport() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 147 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 148 | int64_t last_received_rr = -1; |
| 149 | for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); |
| 150 | it != _receivedInfoMap.end(); ++it) { |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 151 | if (it->second->last_time_received_ms > last_received_rr) { |
| 152 | last_received_rr = it->second->last_time_received_ms; |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame] | 153 | } |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 154 | } |
| 155 | return last_received_rr; |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame] | 156 | } |
| 157 | |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 158 | void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 159 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 161 | // new SSRC reset old reports |
| 162 | memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
| 163 | _lastReceivedSRNTPsecs = 0; |
| 164 | _lastReceivedSRNTPfrac = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 166 | _remoteSSRC = ssrc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | } |
| 168 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 169 | uint32_t RTCPReceiver::RemoteSSRC() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 170 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 171 | return _remoteSSRC; |
| 172 | } |
| 173 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 174 | void RTCPReceiver::SetSsrcs(uint32_t main_ssrc, |
| 175 | const std::set<uint32_t>& registered_ssrcs) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 176 | uint32_t old_ssrc = 0; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 177 | { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 178 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 179 | old_ssrc = main_ssrc_; |
| 180 | main_ssrc_ = main_ssrc; |
| 181 | registered_ssrcs_ = registered_ssrcs; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 182 | } |
| 183 | { |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 184 | if (_cbRtcpIntraFrameObserver && old_ssrc != main_ssrc) { |
| 185 | _cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, main_ssrc); |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | } |
| 189 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 190 | int32_t RTCPReceiver::RTT(uint32_t remoteSSRC, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 191 | int64_t* RTT, |
| 192 | int64_t* avgRTT, |
| 193 | int64_t* minRTT, |
| 194 | int64_t* maxRTT) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 195 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 197 | RTCPReportBlockInformation* reportBlock = |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 198 | GetReportBlockInformation(remoteSSRC, main_ssrc_); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 199 | |
| 200 | if (reportBlock == NULL) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 201 | return -1; |
| 202 | } |
| 203 | if (RTT) { |
| 204 | *RTT = reportBlock->RTT; |
| 205 | } |
| 206 | if (avgRTT) { |
| 207 | *avgRTT = reportBlock->avgRTT; |
| 208 | } |
| 209 | if (minRTT) { |
| 210 | *minRTT = reportBlock->minRTT; |
| 211 | } |
| 212 | if (maxRTT) { |
| 213 | *maxRTT = reportBlock->maxRTT; |
| 214 | } |
| 215 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 218 | void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 219 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 220 | xr_rrtr_status_ = enable; |
| 221 | } |
| 222 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 223 | bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 224 | assert(rtt_ms); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 225 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 226 | if (xr_rr_rtt_ms_ == 0) { |
| 227 | return false; |
| 228 | } |
| 229 | *rtt_ms = xr_rr_rtt_ms_; |
| 230 | xr_rr_rtt_ms_ = 0; |
| 231 | return true; |
| 232 | } |
| 233 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 234 | // TODO(pbos): Make this fail when we haven't received NTP. |
| 235 | bool RTCPReceiver::NTP(uint32_t* ReceivedNTPsecs, |
| 236 | uint32_t* ReceivedNTPfrac, |
| 237 | uint32_t* RTCPArrivalTimeSecs, |
| 238 | uint32_t* RTCPArrivalTimeFrac, |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 239 | uint32_t* rtcp_timestamp) const { |
| 240 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
| 241 | if (ReceivedNTPsecs) { |
| 242 | *ReceivedNTPsecs = |
| 243 | _remoteSenderInfo.NTPseconds; // NTP from incoming SendReport |
| 244 | } |
| 245 | if (ReceivedNTPfrac) { |
| 246 | *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction; |
| 247 | } |
| 248 | if (RTCPArrivalTimeFrac) { |
| 249 | *RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we |
| 250 | // received a RTCP packet |
| 251 | // with a send block |
| 252 | } |
| 253 | if (RTCPArrivalTimeSecs) { |
| 254 | *RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs; |
| 255 | } |
| 256 | if (rtcp_timestamp) { |
| 257 | *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp; |
| 258 | } |
| 259 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 260 | } |
| 261 | |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 262 | bool RTCPReceiver::LastReceivedXrReferenceTimeInfo( |
| 263 | RtcpReceiveTimeInfo* info) const { |
| 264 | assert(info); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 265 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 266 | if (_lastReceivedXRNTPsecs == 0 && _lastReceivedXRNTPfrac == 0) { |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | info->sourceSSRC = _remoteXRReceiveTimeInfo.sourceSSRC; |
| 271 | info->lastRR = _remoteXRReceiveTimeInfo.lastRR; |
| 272 | |
| 273 | // Get the delay since last received report (RFC 3611). |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 274 | uint32_t receive_time = |
| 275 | RTCPUtility::MidNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 276 | |
| 277 | uint32_t ntp_sec = 0; |
| 278 | uint32_t ntp_frac = 0; |
| 279 | _clock->CurrentNtp(ntp_sec, ntp_frac); |
| 280 | uint32_t now = RTCPUtility::MidNtp(ntp_sec, ntp_frac); |
| 281 | |
| 282 | info->delaySinceLastRR = now - receive_time; |
| 283 | return true; |
| 284 | } |
| 285 | |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 286 | int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const { |
| 287 | assert(senderInfo); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 288 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 289 | if (_lastReceivedSRNTPsecs == 0) { |
| 290 | return -1; |
| 291 | } |
| 292 | memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo)); |
| 293 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // statistics |
| 297 | // we can get multiple receive reports when we receive the report from a CE |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 298 | int32_t RTCPReceiver::StatisticsReceived( |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 299 | std::vector<RTCPReportBlock>* receiveBlocks) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 300 | assert(receiveBlocks); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 301 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 302 | ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin(); |
| 303 | for (; it != _receivedReportBlockMap.end(); ++it) { |
| 304 | const ReportBlockInfoMap* info_map = &(it->second); |
| 305 | ReportBlockInfoMap::const_iterator it_info = info_map->begin(); |
| 306 | for (; it_info != info_map->end(); ++it_info) { |
| 307 | receiveBlocks->push_back(it_info->second->remoteReceiveBlock); |
| 308 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 309 | } |
| 310 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | } |
| 312 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 313 | bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin, |
| 314 | const uint8_t* packet_end, |
| 315 | PacketInformation* packet_information) { |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 316 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 317 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 318 | CommonHeader rtcp_block; |
| 319 | for (const uint8_t* next_block = packet_begin; next_block != packet_end; |
| 320 | next_block = rtcp_block.NextPacket()) { |
| 321 | ptrdiff_t remaining_blocks_size = packet_end - next_block; |
| 322 | RTC_DCHECK_GT(remaining_blocks_size, 0); |
| 323 | if (!rtcp_block.Parse(next_block, remaining_blocks_size)) { |
| 324 | if (next_block == packet_begin) { |
| 325 | // Failed to parse 1st header, nothing was extracted from this packet. |
| 326 | LOG(LS_WARNING) << "Incoming invalid RTCP packet"; |
| 327 | return false; |
| 328 | } |
| 329 | ++num_skipped_packets_; |
| 330 | break; |
| 331 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 333 | if (packet_type_counter_.first_packet_time_ms == -1) |
| 334 | packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds(); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 335 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 336 | switch (rtcp_block.type()) { |
| 337 | case rtcp::SenderReport::kPacketType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 338 | HandleSenderReport(rtcp_block, packet_information); |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 339 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 340 | case rtcp::ReceiverReport::kPacketType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 341 | HandleReceiverReport(rtcp_block, packet_information); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 342 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 343 | case rtcp::Sdes::kPacketType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 344 | HandleSDES(rtcp_block, packet_information); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 345 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 346 | case rtcp::ExtendedReports::kPacketType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 347 | HandleXr(rtcp_block, packet_information); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 348 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 349 | case rtcp::Bye::kPacketType: |
| 350 | HandleBYE(rtcp_block); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 351 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 352 | case rtcp::Rtpfb::kPacketType: |
| 353 | switch (rtcp_block.fmt()) { |
| 354 | case rtcp::Nack::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 355 | HandleNACK(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 356 | break; |
| 357 | case rtcp::Tmmbr::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 358 | HandleTMMBR(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 359 | break; |
| 360 | case rtcp::Tmmbn::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 361 | HandleTMMBN(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 362 | break; |
| 363 | case rtcp::RapidResyncRequest::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 364 | HandleSR_REQ(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 365 | break; |
| 366 | case rtcp::TransportFeedback::kFeedbackMessageType: |
| 367 | HandleTransportFeedback(rtcp_block, packet_information); |
| 368 | break; |
| 369 | default: |
| 370 | ++num_skipped_packets_; |
| 371 | break; |
| 372 | } |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 373 | break; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 374 | case rtcp::Psfb::kPacketType: |
| 375 | switch (rtcp_block.fmt()) { |
| 376 | case rtcp::Pli::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 377 | HandlePLI(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 378 | break; |
| 379 | case rtcp::Sli::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 380 | HandleSLI(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 381 | break; |
| 382 | case rtcp::Rpsi::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 383 | HandleRPSI(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 384 | break; |
| 385 | case rtcp::Fir::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 386 | HandleFIR(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 387 | break; |
| 388 | case rtcp::Remb::kFeedbackMessageType: |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 389 | HandlePsfbApp(rtcp_block, packet_information); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 390 | break; |
| 391 | default: |
| 392 | ++num_skipped_packets_; |
| 393 | break; |
| 394 | } |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 395 | break; |
| 396 | default: |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 397 | ++num_skipped_packets_; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 398 | break; |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 399 | } |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 400 | } |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 401 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 402 | if (packet_type_counter_observer_ != NULL) { |
| 403 | packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( |
| 404 | main_ssrc_, packet_type_counter_); |
| 405 | } |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 406 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 407 | int64_t now = _clock->TimeInMilliseconds(); |
| 408 | if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs && |
| 409 | num_skipped_packets_ > 0) { |
| 410 | last_skipped_packets_warning_ = now; |
| 411 | LOG(LS_WARNING) << num_skipped_packets_ |
| 412 | << " RTCP blocks were skipped due to being malformed or of " |
| 413 | "unrecognized/unsupported type, during the past " |
| 414 | << (kMaxWarningLogIntervalMs / 1000) << " second period."; |
| 415 | } |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 416 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 417 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 418 | } |
| 419 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 420 | void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block, |
| 421 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 422 | rtcp::SenderReport sender_report; |
| 423 | if (!sender_report.Parse(rtcp_block)) { |
| 424 | ++num_skipped_packets_; |
| 425 | return; |
| 426 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 427 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 428 | const uint32_t remoteSSRC = sender_report.sender_ssrc(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 429 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 430 | packet_information->remote_ssrc = remoteSSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 431 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 432 | RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 433 | if (!ptrReceiveInfo) |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 434 | return; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 435 | |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 436 | TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", |
| 437 | "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 438 | |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 439 | // Have I received RTP packets from this party? |
| 440 | if (_remoteSSRC == remoteSSRC) { |
| 441 | // Only signal that we have received a SR when we accept one. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 442 | packet_information->packet_type_flags |= kRtcpSr; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 443 | |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 444 | // Save the NTP time of this report. |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 445 | _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); |
| 446 | _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); |
| 447 | _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); |
| 448 | _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); |
| 449 | _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 450 | |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 451 | _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 452 | } else { |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 453 | // We will only store the send report from one source, but |
| 454 | // we will store all the receive blocks. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 455 | packet_information->packet_type_flags |= kRtcpRr; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 456 | } |
| 457 | // Update that this remote is alive. |
| 458 | ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); |
elham@webrtc.org | b7eda43 | 2013-07-15 21:08:27 +0000 | [diff] [blame] | 459 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 460 | for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 461 | HandleReportBlock(report_block, packet_information, remoteSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 462 | } |
| 463 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 464 | void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, |
| 465 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 466 | rtcp::ReceiverReport receiver_report; |
| 467 | if (!receiver_report.Parse(rtcp_block)) { |
| 468 | ++num_skipped_packets_; |
| 469 | return; |
| 470 | } |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 471 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 472 | const uint32_t remoteSSRC = receiver_report.sender_ssrc(); |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 473 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 474 | packet_information->remote_ssrc = remoteSSRC; |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 475 | |
| 476 | RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 477 | if (!ptrReceiveInfo) |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 478 | return; |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 479 | |
| 480 | TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", |
| 481 | "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
| 482 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 483 | packet_information->packet_type_flags |= kRtcpRr; |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 484 | |
| 485 | // Update that this remote is alive. |
| 486 | ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); |
| 487 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 488 | for (const ReportBlock& report_block : receiver_report.report_blocks()) |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 489 | HandleReportBlock(report_block, packet_information, remoteSSRC); |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 490 | } |
| 491 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 492 | void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, |
| 493 | PacketInformation* packet_information, |
| 494 | uint32_t remoteSSRC) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 495 | // This will be called once per report block in the RTCP packet. |
| 496 | // We filter out all report blocks that are not for us. |
| 497 | // Each packet has max 31 RR blocks. |
| 498 | // |
| 499 | // We can calc RTT if we send a send report and get a report block back. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 500 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 501 | // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to |
| 502 | // which the information in this reception report block pertains. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 503 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 504 | // Filter out all report blocks that are not for us. |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 505 | if (registered_ssrcs_.count(report_block.source_ssrc()) == 0) |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 506 | return; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 507 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 508 | RTCPReportBlockInformation* reportBlock = |
| 509 | CreateOrGetReportBlockInformation(remoteSSRC, report_block.source_ssrc()); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 510 | if (reportBlock == NULL) { |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 511 | LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" << remoteSSRC |
| 512 | << ")"; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 513 | return; |
| 514 | } |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 515 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 516 | _lastReceivedRrMs = _clock->TimeInMilliseconds(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 517 | reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 518 | reportBlock->remoteReceiveBlock.sourceSSRC = report_block.source_ssrc(); |
| 519 | reportBlock->remoteReceiveBlock.fractionLost = report_block.fraction_lost(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 520 | reportBlock->remoteReceiveBlock.cumulativeLost = |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 521 | report_block.cumulative_lost(); |
| 522 | if (report_block.extended_high_seq_num() > |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 523 | reportBlock->remoteReceiveBlock.extendedHighSeqNum) { |
| 524 | // We have successfully delivered new RTP packets to the remote side after |
| 525 | // the last RR was sent from the remote side. |
| 526 | _lastIncreasedSequenceNumberMs = _lastReceivedRrMs; |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 527 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 528 | reportBlock->remoteReceiveBlock.extendedHighSeqNum = |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 529 | report_block.extended_high_seq_num(); |
| 530 | reportBlock->remoteReceiveBlock.jitter = report_block.jitter(); |
| 531 | reportBlock->remoteReceiveBlock.delaySinceLastSR = |
| 532 | report_block.delay_since_last_sr(); |
| 533 | reportBlock->remoteReceiveBlock.lastSR = report_block.last_sr(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 534 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 535 | if (report_block.jitter() > reportBlock->remoteMaxJitter) |
| 536 | reportBlock->remoteMaxJitter = report_block.jitter(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 537 | |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 538 | int64_t rtt = 0; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 539 | uint32_t send_time = report_block.last_sr(); |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 540 | // RFC3550, section 6.4.1, LSR field discription states: |
| 541 | // If no SR has been received yet, the field is set to zero. |
| 542 | // Receiver rtp_rtcp module is not expected to calculate rtt using |
| 543 | // Sender Reports even if it accidentally can. |
| 544 | if (!receiver_only_ && send_time != 0) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 545 | uint32_t delay = report_block.delay_since_last_sr(); |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 546 | // Local NTP time. |
| 547 | uint32_t receive_time = CompactNtp(NtpTime(*_clock)); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 548 | |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 549 | // RTT in 1/(2^16) seconds. |
| 550 | uint32_t rtt_ntp = receive_time - delay - send_time; |
| 551 | // Convert to 1/1000 seconds (milliseconds). |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 552 | rtt = CompactNtpRttToMs(rtt_ntp); |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 553 | if (rtt > reportBlock->maxRTT) { |
| 554 | // Store max RTT. |
| 555 | reportBlock->maxRTT = rtt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 556 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 557 | if (reportBlock->minRTT == 0) { |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 558 | // First RTT. |
| 559 | reportBlock->minRTT = rtt; |
| 560 | } else if (rtt < reportBlock->minRTT) { |
| 561 | // Store min RTT. |
| 562 | reportBlock->minRTT = rtt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 563 | } |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 564 | // Store last RTT. |
| 565 | reportBlock->RTT = rtt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 566 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 567 | // store average RTT |
| 568 | if (reportBlock->numAverageCalcs != 0) { |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 569 | float ac = static_cast<float>(reportBlock->numAverageCalcs); |
| 570 | float newAverage = |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 571 | ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt); |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 572 | reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 573 | } else { |
Danil Chapovalov | a094fd1 | 2016-02-22 18:59:36 +0100 | [diff] [blame] | 574 | // First RTT. |
| 575 | reportBlock->avgRTT = rtt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 576 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 577 | reportBlock->numAverageCalcs++; |
| 578 | } |
| 579 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 580 | TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", |
| 581 | report_block.source_ssrc(), rtt); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 582 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 583 | packet_information->rtt_ms = rtt; |
| 584 | packet_information->report_blocks.push_back(reportBlock->remoteReceiveBlock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | } |
| 586 | |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 587 | RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( |
| 588 | uint32_t remote_ssrc, |
| 589 | uint32_t source_ssrc) { |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 590 | RTCPReportBlockInformation* info = |
| 591 | GetReportBlockInformation(remote_ssrc, source_ssrc); |
| 592 | if (info == NULL) { |
| 593 | info = new RTCPReportBlockInformation; |
| 594 | _receivedReportBlockMap[source_ssrc][remote_ssrc] = info; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 595 | } |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 596 | return info; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 597 | } |
| 598 | |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 599 | RTCPReportBlockInformation* RTCPReceiver::GetReportBlockInformation( |
| 600 | uint32_t remote_ssrc, |
| 601 | uint32_t source_ssrc) const { |
| 602 | ReportBlockMap::const_iterator it = _receivedReportBlockMap.find(source_ssrc); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 603 | if (it == _receivedReportBlockMap.end()) { |
| 604 | return NULL; |
| 605 | } |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 606 | const ReportBlockInfoMap* info_map = &(it->second); |
| 607 | ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc); |
| 608 | if (it_info == info_map->end()) { |
| 609 | return NULL; |
| 610 | } |
| 611 | return it_info->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 612 | } |
| 613 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 614 | RTCPCnameInformation* RTCPReceiver::CreateCnameInformation( |
| 615 | uint32_t remoteSSRC) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 616 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 617 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 618 | std::map<uint32_t, RTCPCnameInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 619 | _receivedCnameMap.find(remoteSSRC); |
| 620 | |
| 621 | if (it != _receivedCnameMap.end()) { |
| 622 | return it->second; |
| 623 | } |
| 624 | RTCPCnameInformation* cnameInfo = new RTCPCnameInformation; |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 625 | memset(cnameInfo->name, 0, RTCP_CNAME_SIZE); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 626 | _receivedCnameMap[remoteSSRC] = cnameInfo; |
| 627 | return cnameInfo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 628 | } |
| 629 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 630 | RTCPCnameInformation* RTCPReceiver::GetCnameInformation( |
| 631 | uint32_t remoteSSRC) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 632 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 633 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 634 | std::map<uint32_t, RTCPCnameInformation*>::const_iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 635 | _receivedCnameMap.find(remoteSSRC); |
| 636 | |
| 637 | if (it == _receivedCnameMap.end()) { |
| 638 | return NULL; |
| 639 | } |
| 640 | return it->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 641 | } |
| 642 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 643 | RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation( |
| 644 | uint32_t remoteSSRC) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 645 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 646 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 647 | std::map<uint32_t, RTCPReceiveInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 648 | _receivedInfoMap.find(remoteSSRC); |
| 649 | |
| 650 | if (it != _receivedInfoMap.end()) { |
| 651 | return it->second; |
| 652 | } |
| 653 | RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation; |
| 654 | _receivedInfoMap[remoteSSRC] = receiveInfo; |
| 655 | return receiveInfo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 658 | RTCPReceiveInformation* RTCPReceiver::GetReceiveInformation( |
| 659 | uint32_t remoteSSRC) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 660 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 661 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 662 | std::map<uint32_t, RTCPReceiveInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 663 | _receivedInfoMap.find(remoteSSRC); |
| 664 | if (it == _receivedInfoMap.end()) { |
| 665 | return NULL; |
| 666 | } |
| 667 | return it->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 668 | } |
| 669 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 670 | bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 671 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 672 | if (_lastReceivedRrMs == 0) |
| 673 | return false; |
| 674 | |
| 675 | int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 676 | if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 677 | // Reset the timer to only trigger one log. |
| 678 | _lastReceivedRrMs = 0; |
| 679 | return true; |
| 680 | } |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 685 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 686 | if (_lastIncreasedSequenceNumberMs == 0) |
| 687 | return false; |
| 688 | |
| 689 | int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 690 | if (_clock->TimeInMilliseconds() > |
| 691 | _lastIncreasedSequenceNumberMs + time_out_ms) { |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 692 | // Reset the timer to only trigger one log. |
| 693 | _lastIncreasedSequenceNumberMs = 0; |
| 694 | return true; |
| 695 | } |
| 696 | return false; |
| 697 | } |
| 698 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 699 | bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 700 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 701 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 702 | bool updateBoundingSet = false; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 703 | int64_t timeNow = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 704 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 705 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 706 | _receivedInfoMap.begin(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 707 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 708 | while (receiveInfoIt != _receivedInfoMap.end()) { |
| 709 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 710 | if (receiveInfo == NULL) { |
| 711 | return updateBoundingSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 712 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 713 | // time since last received rtcp packet |
| 714 | // when we dont have a lastTimeReceived and the object is marked |
| 715 | // readyForDelete it's removed from the map |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 716 | if (receiveInfo->last_time_received_ms > 0) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 717 | /// use audio define since we don't know what interval the remote peer is |
| 718 | // using |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 719 | if ((timeNow - receiveInfo->last_time_received_ms) > |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 720 | 5 * RTCP_INTERVAL_AUDIO_MS) { |
| 721 | // no rtcp packet for the last five regular intervals, reset limitations |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 722 | receiveInfo->ClearTmmbr(); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 723 | // prevent that we call this over and over again |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 724 | receiveInfo->last_time_received_ms = 0; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 725 | // send new TMMBN to all channels using the default codec |
| 726 | updateBoundingSet = true; |
| 727 | } |
| 728 | receiveInfoIt++; |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 729 | } else if (receiveInfo->ready_for_delete) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 730 | // store our current receiveInfoItem |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 731 | std::map<uint32_t, RTCPReceiveInformation*>::iterator |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 732 | receiveInfoItemToBeErased = receiveInfoIt; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 733 | receiveInfoIt++; |
| 734 | delete receiveInfoItemToBeErased->second; |
| 735 | _receivedInfoMap.erase(receiveInfoItemToBeErased); |
| 736 | } else { |
| 737 | receiveInfoIt++; |
| 738 | } |
| 739 | } |
| 740 | return updateBoundingSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 741 | } |
| 742 | |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 743 | std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 744 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 745 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 746 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 747 | _receivedInfoMap.find(_remoteSSRC); |
| 748 | |
| 749 | if (receiveInfoIt == _receivedInfoMap.end()) { |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 750 | return std::vector<rtcp::TmmbItem>(); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 751 | } |
| 752 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 753 | RTC_DCHECK(receiveInfo); |
| 754 | |
| 755 | *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_); |
| 756 | return receiveInfo->tmmbn; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 757 | } |
| 758 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 759 | void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 760 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 761 | rtcp::Sdes sdes; |
| 762 | if (!sdes.Parse(rtcp_block)) { |
| 763 | ++num_skipped_packets_; |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { |
| 768 | RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc); |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 769 | RTC_DCHECK(cnameInfo); |
| 770 | |
| 771 | cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 772 | strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1); |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 773 | { |
| 774 | rtc::CritScope lock(&_criticalSectionFeedbacks); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 775 | if (stats_callback_) |
| 776 | stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 777 | } |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 778 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 779 | packet_information->packet_type_flags |= kRtcpSdes; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | } |
| 781 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 782 | void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 783 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 784 | rtcp::Nack nack; |
| 785 | if (!nack.Parse(rtcp_block)) { |
| 786 | ++num_skipped_packets_; |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 787 | return; |
| 788 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 789 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 790 | if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us. |
| 791 | return; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 792 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 793 | packet_information->nack_sequence_numbers = nack.packet_ids(); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 794 | for (uint16_t packet_id : nack.packet_ids()) |
| 795 | nack_stats_.ReportRequest(packet_id); |
| 796 | |
| 797 | if (!nack.packet_ids().empty()) { |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 798 | packet_information->packet_type_flags |= kRtcpNack; |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 799 | ++packet_type_counter_.nack_packets; |
| 800 | packet_type_counter_.nack_requests = nack_stats_.requests(); |
| 801 | packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); |
| 802 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 803 | } |
| 804 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 805 | void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) { |
| 806 | rtcp::Bye bye; |
| 807 | if (!bye.Parse(rtcp_block)) { |
| 808 | ++num_skipped_packets_; |
| 809 | return; |
| 810 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 811 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 812 | // clear our lists |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 813 | ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); |
| 814 | for (; it != _receivedReportBlockMap.end(); ++it) { |
| 815 | ReportBlockInfoMap* info_map = &(it->second); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 816 | ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc()); |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 817 | if (it_info != info_map->end()) { |
| 818 | delete it_info->second; |
| 819 | info_map->erase(it_info); |
| 820 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 821 | } |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 822 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 823 | // we can't delete it due to TMMBR |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 824 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 825 | _receivedInfoMap.find(bye.sender_ssrc()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 826 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 827 | if (receiveInfoIt != _receivedInfoMap.end()) |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 828 | receiveInfoIt->second->ready_for_delete = true; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 829 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 830 | std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt = |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 831 | _receivedCnameMap.find(bye.sender_ssrc()); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 832 | |
| 833 | if (cnameInfoIt != _receivedCnameMap.end()) { |
| 834 | delete cnameInfoIt->second; |
| 835 | _receivedCnameMap.erase(cnameInfoIt); |
| 836 | } |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 837 | xr_rr_rtt_ms_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 838 | } |
| 839 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 840 | void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 841 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 842 | rtcp::ExtendedReports xr; |
| 843 | if (!xr.Parse(rtcp_block)) { |
| 844 | ++num_skipped_packets_; |
| 845 | return; |
| 846 | } |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 847 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 848 | for (const rtcp::Rrtr& rrtr : xr.rrtrs()) |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 849 | HandleXrReceiveReferenceTime(xr.sender_ssrc(), rrtr); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 850 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 851 | for (const rtcp::Dlrr& dlrr : xr.dlrrs()) { |
| 852 | for (const rtcp::ReceiveTimeInfo& time_info : dlrr.sub_blocks()) |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 853 | HandleXrDlrrReportBlock(time_info); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 854 | } |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | void RTCPReceiver::HandleXrReceiveReferenceTime( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 858 | uint32_t sender_ssrc, |
| 859 | const rtcp::Rrtr& rrtr) { |
| 860 | _remoteXRReceiveTimeInfo.sourceSSRC = sender_ssrc; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 861 | _remoteXRReceiveTimeInfo.lastRR = CompactNtp(rrtr.ntp()); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 862 | _clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 863 | } |
| 864 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 865 | void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 866 | if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us. |
| 867 | return; |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 868 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 869 | // Caller should explicitly enable rtt calculation using extended reports. |
| 870 | if (!xr_rrtr_status_) |
| 871 | return; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 872 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 873 | // The send_time and delay_rr fields are in units of 1/2^16 sec. |
| 874 | uint32_t send_time = rti.last_rr; |
| 875 | // RFC3611, section 4.5, LRR field discription states: |
| 876 | // If no such block has been received, the field is set to zero. |
| 877 | if (send_time == 0) |
| 878 | return; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 879 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 880 | uint32_t delay_rr = rti.delay_since_last_rr; |
| 881 | uint32_t now = CompactNtp(NtpTime(*_clock)); |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 882 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 883 | uint32_t rtt_ntp = now - delay_rr - send_time; |
| 884 | xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 885 | } |
| 886 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 887 | void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 888 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 889 | rtcp::Pli pli; |
| 890 | if (!pli.Parse(rtcp_block)) { |
| 891 | ++num_skipped_packets_; |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | if (main_ssrc_ == pli.media_ssrc()) { |
sprang@webrtc.org | 0200f70 | 2015-02-16 12:06:00 +0000 | [diff] [blame] | 896 | TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); |
justinlin@chromium.org | 7bfb3a3 | 2013-05-13 22:59:00 +0000 | [diff] [blame] | 897 | |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 898 | ++packet_type_counter_.pli_packets; |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 899 | // Received a signal that we need to send a new key frame. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 900 | packet_information->packet_type_flags |= kRtcpPli; |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 901 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 902 | } |
| 903 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 904 | void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 905 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 906 | rtcp::Tmmbr tmmbr; |
| 907 | if (!tmmbr.Parse(rtcp_block)) { |
| 908 | ++num_skipped_packets_; |
| 909 | return; |
| 910 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 912 | uint32_t senderSSRC = tmmbr.sender_ssrc(); |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 913 | RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 914 | if (!ptrReceiveInfo) // This remote SSRC must be saved before. |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 915 | return; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 916 | |
| 917 | if (tmmbr.media_ssrc()) { |
| 918 | // media_ssrc() SHOULD be 0 if same as SenderSSRC. |
| 919 | // In relay mode this is a valid number. |
| 920 | senderSSRC = tmmbr.media_ssrc(); |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 921 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 922 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 923 | for (const rtcp::TmmbItem& request : tmmbr.requests()) { |
| 924 | if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { |
| 925 | ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request, |
| 926 | _clock->TimeInMilliseconds()); |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 927 | packet_information->packet_type_flags |= kRtcpTmmbr; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 928 | } |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 929 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 930 | } |
| 931 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 932 | void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 933 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 934 | rtcp::Tmmbn tmmbn; |
| 935 | if (!tmmbn.Parse(rtcp_block)) { |
| 936 | ++num_skipped_packets_; |
| 937 | return; |
| 938 | } |
| 939 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 940 | RTCPReceiveInformation* ptrReceiveInfo = |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 941 | GetReceiveInformation(tmmbn.sender_ssrc()); |
| 942 | if (!ptrReceiveInfo) // This remote SSRC must be saved before. |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 943 | return; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 944 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 945 | packet_information->packet_type_flags |= kRtcpTmmbn; |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 946 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 947 | for (const auto& item : tmmbn.items()) |
| 948 | ptrReceiveInfo->tmmbn.push_back(item); |
| 949 | } |
| 950 | |
| 951 | void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 952 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 953 | rtcp::RapidResyncRequest sr_req; |
| 954 | if (!sr_req.Parse(rtcp_block)) { |
| 955 | ++num_skipped_packets_; |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 956 | return; |
| 957 | } |
| 958 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 959 | packet_information->packet_type_flags |= kRtcpSrReq; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 960 | } |
| 961 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 962 | void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 963 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 964 | rtcp::Sli sli; |
| 965 | if (!sli.Parse(rtcp_block)) { |
| 966 | ++num_skipped_packets_; |
| 967 | return; |
| 968 | } |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 969 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 970 | for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) { |
| 971 | // In theory there could be multiple slices lost. |
| 972 | // Received signal that we need to refresh a slice. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 973 | packet_information->packet_type_flags |= kRtcpSli; |
| 974 | packet_information->sli_picture_id = item.picture_id(); |
asapersson@webrtc.org | df7b65b | 2015-01-21 13:07:04 +0000 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 978 | void RTCPReceiver::HandleRPSI(const CommonHeader& rtcp_block, |
| 979 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 980 | rtcp::Rpsi rpsi; |
| 981 | if (!rpsi.Parse(rtcp_block)) { |
| 982 | ++num_skipped_packets_; |
| 983 | return; |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 984 | } |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 985 | |
| 986 | // Received signal that we have a confirmed reference picture. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 987 | packet_information->packet_type_flags |= kRtcpRpsi; |
| 988 | packet_information->rpsi_picture_id = rpsi.picture_id(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 989 | } |
| 990 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 991 | void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 992 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 993 | rtcp::Remb remb; |
| 994 | if (remb.Parse(rtcp_block)) { |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 995 | packet_information->packet_type_flags |= kRtcpRemb; |
| 996 | packet_information->receiver_estimated_max_bitrate_bps = remb.bitrate_bps(); |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 997 | return; |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 998 | } |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 999 | |
| 1000 | ++num_skipped_packets_; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1003 | void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1004 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1005 | rtcp::Fir fir; |
| 1006 | if (!fir.Parse(rtcp_block)) { |
| 1007 | ++num_skipped_packets_; |
| 1008 | return; |
| 1009 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1010 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1011 | RTCPReceiveInformation* ptrReceiveInfo = |
| 1012 | GetReceiveInformation(fir.sender_ssrc()); |
| 1013 | |
| 1014 | for (const rtcp::Fir::Request& fir_request : fir.requests()) { |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1015 | // Is it our sender that is requested to generate a new keyframe |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1016 | if (main_ssrc_ != fir_request.ssrc) |
| 1017 | continue; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1018 | |
| 1019 | ++packet_type_counter_.fir_packets; |
| 1020 | |
| 1021 | // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it |
| 1022 | // we don't know who this originate from |
| 1023 | if (ptrReceiveInfo) { |
| 1024 | // check if we have reported this FIRSequenceNumber before |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1025 | if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) { |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1026 | int64_t now = _clock->TimeInMilliseconds(); |
| 1027 | // sanity; don't go crazy with the callbacks |
| 1028 | if ((now - ptrReceiveInfo->last_fir_request_ms) > |
| 1029 | RTCP_MIN_FRAME_LENGTH_MS) { |
| 1030 | ptrReceiveInfo->last_fir_request_ms = now; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1031 | ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1032 | // received signal that we need to send a new key frame |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1033 | packet_information->packet_type_flags |= kRtcpFir; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | } else { |
| 1037 | // received signal that we need to send a new key frame |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1038 | packet_information->packet_type_flags |= kRtcpFir; |
Danil Chapovalov | 530b3f5 | 2016-09-15 18:41:02 +0200 | [diff] [blame] | 1039 | } |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1040 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1043 | void RTCPReceiver::HandleTransportFeedback( |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1044 | const CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1045 | PacketInformation* packet_information) { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 1046 | std::unique_ptr<rtcp::TransportFeedback> transport_feedback( |
| 1047 | new rtcp::TransportFeedback()); |
| 1048 | if (!transport_feedback->Parse(rtcp_block)) { |
| 1049 | ++num_skipped_packets_; |
| 1050 | return; |
| 1051 | } |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1052 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1053 | packet_information->packet_type_flags |= kRtcpTransportFeedback; |
| 1054 | packet_information->transport_feedback = std::move(transport_feedback); |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1055 | } |
danilchap | 287e548 | 2016-08-16 15:15:39 -0700 | [diff] [blame] | 1056 | |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1057 | void RTCPReceiver::UpdateTmmbr() { |
| 1058 | // Find bounding set. |
danilchap | 2f69ce9 | 2016-08-16 03:21:38 -0700 | [diff] [blame] | 1059 | std::vector<rtcp::TmmbItem> bounding = |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1060 | TMMBRHelp::FindBoundingSet(TmmbrReceived()); |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1061 | |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1062 | if (!bounding.empty() && _cbRtcpBandwidthObserver) { |
| 1063 | // We have a new bandwidth estimate on this channel. |
danilchap | 2f69ce9 | 2016-08-16 03:21:38 -0700 | [diff] [blame] | 1064 | uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); |
| 1065 | if (bitrate_bps <= std::numeric_limits<uint32_t>::max()) |
| 1066 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate_bps); |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1067 | } |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1068 | |
| 1069 | // Set bounding set: inform remote clients about the new bandwidth. |
| 1070 | _rtpRtcp.SetTmmbn(std::move(bounding)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1073 | void RTCPReceiver::RegisterRtcpStatisticsCallback( |
| 1074 | RtcpStatisticsCallback* callback) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1075 | rtc::CritScope cs(&_criticalSectionFeedbacks); |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1076 | stats_callback_ = callback; |
| 1077 | } |
| 1078 | |
| 1079 | RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1080 | rtc::CritScope cs(&_criticalSectionFeedbacks); |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1081 | return stats_callback_; |
| 1082 | } |
| 1083 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1084 | // Holding no Critical section |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1085 | void RTCPReceiver::TriggerCallbacksFromRTCPPacket( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1086 | const PacketInformation& packet_information) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1087 | // Process TMMBR and REMB first to avoid multiple callbacks |
| 1088 | // to OnNetworkChanged. |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1089 | if (packet_information.packet_type_flags & kRtcpTmmbr) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1090 | // Might trigger a OnReceivedBandwidthEstimateUpdate. |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1091 | UpdateTmmbr(); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1092 | } |
sprang | 7dc39f3 | 2015-10-13 09:17:48 -0700 | [diff] [blame] | 1093 | uint32_t local_ssrc; |
| 1094 | std::set<uint32_t> registered_ssrcs; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1095 | { |
| 1096 | // We don't want to hold this critsect when triggering the callbacks below. |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1097 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 1098 | local_ssrc = main_ssrc_; |
sprang | 7dc39f3 | 2015-10-13 09:17:48 -0700 | [diff] [blame] | 1099 | registered_ssrcs = registered_ssrcs_; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1100 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1101 | if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1102 | _rtpRtcp.OnRequestSendReport(); |
| 1103 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1104 | if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpNack)) { |
| 1105 | if (!packet_information.nack_sequence_numbers.empty()) { |
andresp@webrtc.org | 4436b44 | 2014-06-04 09:05:30 +0000 | [diff] [blame] | 1106 | LOG(LS_VERBOSE) << "Incoming NACK length: " |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1107 | << packet_information.nack_sequence_numbers.size(); |
| 1108 | _rtpRtcp.OnReceivedNack(packet_information.nack_sequence_numbers); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1109 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1110 | } |
| 1111 | { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1112 | // We need feedback that we have received a report block(s) so that we |
| 1113 | // can generate a new packet in a conference relay scenario, one received |
| 1114 | // report can generate several RTCP packets, based on number relayed/mixed |
| 1115 | // a send report block should go out to all receivers. |
| 1116 | if (_cbRtcpIntraFrameObserver) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1117 | RTC_DCHECK(!receiver_only_); |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1118 | if ((packet_information.packet_type_flags & kRtcpPli) || |
| 1119 | (packet_information.packet_type_flags & kRtcpFir)) { |
| 1120 | if (packet_information.packet_type_flags & kRtcpPli) { |
andresp@webrtc.org | 4436b44 | 2014-06-04 09:05:30 +0000 | [diff] [blame] | 1121 | LOG(LS_VERBOSE) << "Incoming PLI from SSRC " |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1122 | << packet_information.remote_ssrc; |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1123 | } else { |
andresp@webrtc.org | 4436b44 | 2014-06-04 09:05:30 +0000 | [diff] [blame] | 1124 | LOG(LS_VERBOSE) << "Incoming FIR from SSRC " |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1125 | << packet_information.remote_ssrc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1126 | } |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1127 | _cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1128 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1129 | if (packet_information.packet_type_flags & kRtcpSli) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1130 | _cbRtcpIntraFrameObserver->OnReceivedSLI( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1131 | local_ssrc, packet_information.sli_picture_id); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1132 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1133 | if (packet_information.packet_type_flags & kRtcpRpsi) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1134 | _cbRtcpIntraFrameObserver->OnReceivedRPSI( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1135 | local_ssrc, packet_information.rpsi_picture_id); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1136 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1137 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1138 | if (_cbRtcpBandwidthObserver) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1139 | RTC_DCHECK(!receiver_only_); |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1140 | if (packet_information.packet_type_flags & kRtcpRemb) { |
| 1141 | LOG(LS_VERBOSE) |
| 1142 | << "Incoming REMB: " |
| 1143 | << packet_information.receiver_estimated_max_bitrate_bps; |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1144 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1145 | packet_information.receiver_estimated_max_bitrate_bps); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1146 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1147 | if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1148 | (packet_information.packet_type_flags & kRtcpRr)) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1149 | int64_t now = _clock->TimeInMilliseconds(); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1150 | _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1151 | packet_information.report_blocks, packet_information.rtt_ms, now); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1152 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1153 | } |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1154 | if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1155 | (packet_information.packet_type_flags & kRtcpRr)) { |
| 1156 | _rtpRtcp.OnReceivedRtcpReportBlocks(packet_information.report_blocks); |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1159 | if (_cbTransportFeedbackObserver && |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1160 | (packet_information.packet_type_flags & kRtcpTransportFeedback)) { |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1161 | uint32_t media_source_ssrc = |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1162 | packet_information.transport_feedback->media_ssrc(); |
sprang | 7dc39f3 | 2015-10-13 09:17:48 -0700 | [diff] [blame] | 1163 | if (media_source_ssrc == local_ssrc || |
| 1164 | registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1165 | _cbTransportFeedbackObserver->OnTransportFeedback( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1166 | *packet_information.transport_feedback); |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1167 | } |
| 1168 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1169 | } |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1170 | |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 1171 | if (!receiver_only_) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1172 | rtc::CritScope cs(&_criticalSectionFeedbacks); |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1173 | if (stats_callback_) { |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1174 | for (const auto& report_block : packet_information.report_blocks) { |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1175 | RtcpStatistics stats; |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1176 | stats.cumulative_lost = report_block.cumulativeLost; |
| 1177 | stats.extended_max_sequence_number = report_block.extendedHighSeqNum; |
| 1178 | stats.fraction_lost = report_block.fractionLost; |
| 1179 | stats.jitter = report_block.jitter; |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1180 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 1181 | stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC); |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 1187 | int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1188 | char cName[RTCP_CNAME_SIZE]) const { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1189 | assert(cName); |
| 1190 | |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1191 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1192 | RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1193 | if (cnameInfo == NULL) { |
| 1194 | return -1; |
| 1195 | } |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1196 | cName[RTCP_CNAME_SIZE - 1] = 0; |
| 1197 | strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); |
| 1198 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 1201 | std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 1202 | rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
danilchap | 287e548 | 2016-08-16 15:15:39 -0700 | [diff] [blame] | 1203 | std::vector<rtcp::TmmbItem> candidates; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1204 | |
danilchap | 287e548 | 2016-08-16 15:15:39 -0700 | [diff] [blame] | 1205 | int64_t now_ms = _clock->TimeInMilliseconds(); |
| 1206 | |
| 1207 | for (const auto& kv : _receivedInfoMap) { |
| 1208 | RTCPReceiveInformation* receive_info = kv.second; |
| 1209 | RTC_DCHECK(receive_info); |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 1210 | receive_info->GetTmmbrSet(now_ms, &candidates); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1211 | } |
danilchap | 287e548 | 2016-08-16 15:15:39 -0700 | [diff] [blame] | 1212 | return candidates; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 1215 | } // namespace webrtc |