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