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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> //assert |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 14 | #include <string.h> //memset |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 17 | #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| 18 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 19 | #include "webrtc/system_wrappers/interface/trace.h" |
| 20 | #include "webrtc/system_wrappers/interface/trace_event.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | namespace |
| 23 | { |
| 24 | const float FRAC = 4.294967296E9; |
| 25 | } |
| 26 | |
| 27 | namespace webrtc { |
| 28 | using namespace RTCPUtility; |
| 29 | using namespace RTCPHelp; |
| 30 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 31 | // The number of RTCP time intervals needed to trigger a timeout. |
| 32 | const int kRrTimeoutIntervals = 3; |
| 33 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 34 | RTCPReceiver::RTCPReceiver(const int32_t id, Clock* clock, |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 35 | ModuleRtpRtcpImpl* owner) |
| 36 | : TMMBRHelp(), |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 37 | _id(id), |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 38 | _clock(clock), |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 39 | _method(kRtcpOff), |
| 40 | _lastReceived(0), |
| 41 | _rtpRtcp(*owner), |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 42 | _criticalSectionFeedbacks( |
| 43 | CriticalSectionWrapper::CreateCriticalSection()), |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 44 | _cbRtcpFeedback(NULL), |
| 45 | _cbRtcpBandwidthObserver(NULL), |
| 46 | _cbRtcpIntraFrameObserver(NULL), |
| 47 | _criticalSectionRTCPReceiver( |
| 48 | CriticalSectionWrapper::CreateCriticalSection()), |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 49 | main_ssrc_(0), |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 50 | _remoteSSRC(0), |
| 51 | _remoteSenderInfo(), |
| 52 | _lastReceivedSRNTPsecs(0), |
| 53 | _lastReceivedSRNTPfrac(0), |
| 54 | _receivedInfoMap(), |
| 55 | _packetTimeOutMS(0), |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 56 | _lastReceivedRrMs(0), |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 57 | _lastIncreasedSequenceNumberMs(0), |
| 58 | _rtt(0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
| 60 | WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); |
| 61 | } |
| 62 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 63 | RTCPReceiver::~RTCPReceiver() { |
| 64 | delete _criticalSectionRTCPReceiver; |
| 65 | delete _criticalSectionFeedbacks; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 67 | while (!_receivedReportBlockMap.empty()) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 68 | std::map<uint32_t, RTCPReportBlockInformation*>::iterator first = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 69 | _receivedReportBlockMap.begin(); |
| 70 | delete first->second; |
| 71 | _receivedReportBlockMap.erase(first); |
| 72 | } |
| 73 | while (!_receivedInfoMap.empty()) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 74 | std::map<uint32_t, RTCPReceiveInformation*>::iterator first = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 75 | _receivedInfoMap.begin(); |
| 76 | delete first->second; |
| 77 | _receivedInfoMap.erase(first); |
| 78 | } |
| 79 | while (!_receivedCnameMap.empty()) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 80 | std::map<uint32_t, RTCPCnameInformation*>::iterator first = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 81 | _receivedCnameMap.begin(); |
| 82 | delete first->second; |
| 83 | _receivedCnameMap.erase(first); |
| 84 | } |
| 85 | WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, _id, |
| 86 | "%s deleted", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 90 | RTCPReceiver::ChangeUniqueId(const int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | { |
| 92 | _id = id; |
| 93 | } |
| 94 | |
| 95 | RTCPMethod |
| 96 | RTCPReceiver::Status() const |
| 97 | { |
| 98 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 99 | return _method; |
| 100 | } |
| 101 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 102 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | RTCPReceiver::SetRTCPStatus(const RTCPMethod method) |
| 104 | { |
| 105 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 106 | _method = method; |
| 107 | return 0; |
| 108 | } |
| 109 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 110 | int64_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | RTCPReceiver::LastReceived() |
| 112 | { |
| 113 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 114 | return _lastReceived; |
| 115 | } |
| 116 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 117 | int64_t |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame] | 118 | RTCPReceiver::LastReceivedReceiverReport() const { |
| 119 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 120 | int64_t last_received_rr = -1; |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame] | 121 | for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); |
| 122 | it != _receivedInfoMap.end(); ++it) { |
| 123 | if (it->second->lastTimeReceived > last_received_rr) { |
| 124 | last_received_rr = it->second->lastTimeReceived; |
| 125 | } |
| 126 | } |
| 127 | return last_received_rr; |
| 128 | } |
| 129 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 130 | int32_t |
| 131 | RTCPReceiver::SetRemoteSSRC( const uint32_t ssrc) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | { |
| 133 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 134 | |
| 135 | // new SSRC reset old reports |
| 136 | memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
| 137 | _lastReceivedSRNTPsecs = 0; |
| 138 | _lastReceivedSRNTPfrac = 0; |
| 139 | |
| 140 | _remoteSSRC = ssrc; |
| 141 | return 0; |
| 142 | } |
| 143 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 144 | uint32_t RTCPReceiver::RemoteSSRC() const { |
| 145 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 146 | return _remoteSSRC; |
| 147 | } |
| 148 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 149 | void RTCPReceiver::RegisterRtcpObservers( |
| 150 | RtcpIntraFrameObserver* intra_frame_callback, |
| 151 | RtcpBandwidthObserver* bandwidth_callback, |
| 152 | RtcpFeedback* feedback_callback) { |
| 153 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 154 | _cbRtcpIntraFrameObserver = intra_frame_callback; |
| 155 | _cbRtcpBandwidthObserver = bandwidth_callback; |
| 156 | _cbRtcpFeedback = feedback_callback; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | } |
| 158 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 159 | void RTCPReceiver::SetSsrcs(uint32_t main_ssrc, |
| 160 | const std::set<uint32_t>& registered_ssrcs) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 161 | uint32_t old_ssrc = 0; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 162 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 163 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 164 | old_ssrc = main_ssrc_; |
| 165 | main_ssrc_ = main_ssrc; |
| 166 | registered_ssrcs_ = registered_ssrcs; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 167 | } |
| 168 | { |
| 169 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 170 | if (_cbRtcpIntraFrameObserver && old_ssrc != main_ssrc) { |
| 171 | _cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, main_ssrc); |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | } |
| 175 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 176 | int32_t RTCPReceiver::ResetRTT(const uint32_t remoteSSRC) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 177 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 178 | RTCPReportBlockInformation* reportBlock = |
| 179 | GetReportBlockInformation(remoteSSRC); |
| 180 | if (reportBlock == NULL) { |
| 181 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 182 | "\tfailed to GetReportBlockInformation(%u)", remoteSSRC); |
| 183 | return -1; |
| 184 | } |
| 185 | reportBlock->RTT = 0; |
| 186 | reportBlock->avgRTT = 0; |
| 187 | reportBlock->minRTT = 0; |
| 188 | reportBlock->maxRTT = 0; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 189 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 192 | int32_t RTCPReceiver::RTT(uint32_t remoteSSRC, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 193 | uint16_t* RTT, |
| 194 | uint16_t* avgRTT, |
| 195 | uint16_t* minRTT, |
| 196 | uint16_t* maxRTT) const { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 197 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 199 | RTCPReportBlockInformation* reportBlock = |
| 200 | GetReportBlockInformation(remoteSSRC); |
| 201 | |
| 202 | if (reportBlock == NULL) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 203 | return -1; |
| 204 | } |
| 205 | if (RTT) { |
| 206 | *RTT = reportBlock->RTT; |
| 207 | } |
| 208 | if (avgRTT) { |
| 209 | *avgRTT = reportBlock->avgRTT; |
| 210 | } |
| 211 | if (minRTT) { |
| 212 | *minRTT = reportBlock->minRTT; |
| 213 | } |
| 214 | if (maxRTT) { |
| 215 | *maxRTT = reportBlock->maxRTT; |
| 216 | } |
| 217 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | } |
| 219 | |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 220 | uint16_t RTCPReceiver::RTT() const { |
| 221 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 222 | if (!_receivedReportBlockMap.empty()) { |
| 223 | return 0; |
| 224 | } |
| 225 | return _rtt; |
| 226 | } |
| 227 | |
| 228 | int RTCPReceiver::SetRTT(uint16_t rtt) { |
| 229 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 230 | if (!_receivedReportBlockMap.empty()) { |
| 231 | return -1; |
| 232 | } |
| 233 | _rtt = rtt; |
| 234 | return 0; |
| 235 | } |
| 236 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 237 | int32_t |
| 238 | RTCPReceiver::NTP(uint32_t *ReceivedNTPsecs, |
| 239 | uint32_t *ReceivedNTPfrac, |
| 240 | uint32_t *RTCPArrivalTimeSecs, |
| 241 | uint32_t *RTCPArrivalTimeFrac, |
| 242 | uint32_t *rtcp_timestamp) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 243 | { |
| 244 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 245 | if(ReceivedNTPsecs) |
| 246 | { |
| 247 | *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; // NTP from incoming SendReport |
| 248 | } |
| 249 | if(ReceivedNTPfrac) |
| 250 | { |
| 251 | *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction; |
| 252 | } |
| 253 | if(RTCPArrivalTimeFrac) |
| 254 | { |
| 255 | *RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we received a RTCP packet with a send block |
| 256 | } |
| 257 | if(RTCPArrivalTimeSecs) |
| 258 | { |
| 259 | *RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs; |
| 260 | } |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 261 | if (rtcp_timestamp) { |
| 262 | *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp; |
| 263 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 267 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 268 | RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const |
| 269 | { |
| 270 | if(senderInfo == NULL) |
| 271 | { |
| 272 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, "%s invalid argument", __FUNCTION__); |
| 273 | return -1; |
| 274 | } |
| 275 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 276 | if(_lastReceivedSRNTPsecs == 0) |
| 277 | { |
| 278 | WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, "%s No received SR", __FUNCTION__); |
| 279 | return -1; |
| 280 | } |
| 281 | memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo)); |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | // statistics |
| 286 | // 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] | 287 | int32_t RTCPReceiver::StatisticsReceived( |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 288 | std::vector<RTCPReportBlock>* receiveBlocks) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 289 | assert(receiveBlocks); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 290 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 291 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 292 | std::map<uint32_t, RTCPReportBlockInformation*>::const_iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 293 | _receivedReportBlockMap.begin(); |
| 294 | |
| 295 | while (it != _receivedReportBlockMap.end()) { |
| 296 | receiveBlocks->push_back(it->second->remoteReceiveBlock); |
| 297 | it++; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 298 | } |
| 299 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 300 | } |
| 301 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 302 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | RTCPReceiver::IncomingRTCPPacket(RTCPPacketInformation& rtcpPacketInformation, |
| 304 | RTCPUtility::RTCPParserV2* rtcpParser) |
| 305 | { |
| 306 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 307 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 308 | _lastReceived = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 309 | |
| 310 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin(); |
| 311 | while (pktType != RTCPUtility::kRtcpNotValidCode) |
| 312 | { |
| 313 | // Each "case" is responsible for iterate the parser to the |
| 314 | // next top level packet. |
| 315 | switch (pktType) |
| 316 | { |
| 317 | case RTCPUtility::kRtcpSrCode: |
| 318 | case RTCPUtility::kRtcpRrCode: |
| 319 | HandleSenderReceiverReport(*rtcpParser, rtcpPacketInformation); |
| 320 | break; |
| 321 | case RTCPUtility::kRtcpSdesCode: |
| 322 | HandleSDES(*rtcpParser); |
| 323 | break; |
| 324 | case RTCPUtility::kRtcpXrVoipMetricCode: |
| 325 | HandleXRVOIPMetric(*rtcpParser, rtcpPacketInformation); |
| 326 | break; |
| 327 | case RTCPUtility::kRtcpByeCode: |
| 328 | HandleBYE(*rtcpParser); |
| 329 | break; |
| 330 | case RTCPUtility::kRtcpRtpfbNackCode: |
| 331 | HandleNACK(*rtcpParser, rtcpPacketInformation); |
| 332 | break; |
| 333 | case RTCPUtility::kRtcpRtpfbTmmbrCode: |
| 334 | HandleTMMBR(*rtcpParser, rtcpPacketInformation); |
| 335 | break; |
| 336 | case RTCPUtility::kRtcpRtpfbTmmbnCode: |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 337 | HandleTMMBN(*rtcpParser, rtcpPacketInformation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 338 | break; |
| 339 | case RTCPUtility::kRtcpRtpfbSrReqCode: |
| 340 | HandleSR_REQ(*rtcpParser, rtcpPacketInformation); |
| 341 | break; |
| 342 | case RTCPUtility::kRtcpPsfbPliCode: |
| 343 | HandlePLI(*rtcpParser, rtcpPacketInformation); |
| 344 | break; |
| 345 | case RTCPUtility::kRtcpPsfbSliCode: |
| 346 | HandleSLI(*rtcpParser, rtcpPacketInformation); |
| 347 | break; |
| 348 | case RTCPUtility::kRtcpPsfbRpsiCode: |
| 349 | HandleRPSI(*rtcpParser, rtcpPacketInformation); |
| 350 | break; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 351 | case RTCPUtility::kRtcpExtendedIjCode: |
| 352 | HandleIJ(*rtcpParser, rtcpPacketInformation); |
| 353 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | case RTCPUtility::kRtcpPsfbFirCode: |
| 355 | HandleFIR(*rtcpParser, rtcpPacketInformation); |
| 356 | break; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 357 | case RTCPUtility::kRtcpPsfbAppCode: |
| 358 | HandlePsfbApp(*rtcpParser, rtcpPacketInformation); |
| 359 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 360 | case RTCPUtility::kRtcpAppCode: |
| 361 | // generic application messages |
| 362 | HandleAPP(*rtcpParser, rtcpPacketInformation); |
| 363 | break; |
| 364 | case RTCPUtility::kRtcpAppItemCode: |
| 365 | // generic application messages |
| 366 | HandleAPPItem(*rtcpParser, rtcpPacketInformation); |
| 367 | break; |
| 368 | default: |
| 369 | rtcpParser->Iterate(); |
| 370 | break; |
| 371 | } |
| 372 | pktType = rtcpParser->PacketType(); |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 378 | void |
| 379 | RTCPReceiver::HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser, |
| 380 | RTCPPacketInformation& rtcpPacketInformation) |
| 381 | { |
| 382 | RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); |
| 383 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 384 | |
| 385 | assert((rtcpPacketType == RTCPUtility::kRtcpRrCode) || (rtcpPacketType == RTCPUtility::kRtcpSrCode)); |
| 386 | |
| 387 | // SR.SenderSSRC |
| 388 | // The synchronization source identifier for the originator of this SR packet |
| 389 | |
| 390 | // rtcpPacket.RR.SenderSSRC |
| 391 | // The source of the packet sender, same as of SR? or is this a CE? |
| 392 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 393 | const uint32_t remoteSSRC = (rtcpPacketType == RTCPUtility::kRtcpRrCode) ? rtcpPacket.RR.SenderSSRC:rtcpPacket.SR.SenderSSRC; |
| 394 | const uint8_t numberOfReportBlocks = (rtcpPacketType == RTCPUtility::kRtcpRrCode) ? rtcpPacket.RR.NumberOfReportBlocks:rtcpPacket.SR.NumberOfReportBlocks; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | |
| 396 | rtcpPacketInformation.remoteSSRC = remoteSSRC; |
| 397 | |
| 398 | RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
| 399 | if (!ptrReceiveInfo) |
| 400 | { |
| 401 | rtcpParser.Iterate(); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | if (rtcpPacketType == RTCPUtility::kRtcpSrCode) |
| 406 | { |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame] | 407 | TRACE_EVENT_INSTANT2("webrtc_rtp", "SR", |
| 408 | "remote_ssrc", remoteSSRC, |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 409 | "ssrc", main_ssrc_); |
elham@webrtc.org | b7eda43 | 2013-07-15 21:08:27 +0000 | [diff] [blame] | 410 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 411 | if (_remoteSSRC == remoteSSRC) // have I received RTP packets from this party |
| 412 | { |
| 413 | // only signal that we have received a SR when we accept one |
| 414 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr; |
| 415 | |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 416 | rtcpPacketInformation.ntp_secs = rtcpPacket.SR.NTPMostSignificant; |
| 417 | rtcpPacketInformation.ntp_frac = rtcpPacket.SR.NTPLeastSignificant; |
| 418 | rtcpPacketInformation.rtp_timestamp = rtcpPacket.SR.RTPTimestamp; |
| 419 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 420 | // We will only store the send report from one source, but |
| 421 | // we will store all the receive block |
| 422 | |
| 423 | // Save the NTP time of this report |
| 424 | _remoteSenderInfo.NTPseconds = rtcpPacket.SR.NTPMostSignificant; |
| 425 | _remoteSenderInfo.NTPfraction = rtcpPacket.SR.NTPLeastSignificant; |
| 426 | _remoteSenderInfo.RTPtimeStamp = rtcpPacket.SR.RTPTimestamp; |
| 427 | _remoteSenderInfo.sendPacketCount = rtcpPacket.SR.SenderPacketCount; |
| 428 | _remoteSenderInfo.sendOctetCount = rtcpPacket.SR.SenderOctetCount; |
| 429 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 430 | _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 431 | } |
| 432 | else |
| 433 | { |
| 434 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; |
| 435 | } |
| 436 | } else |
| 437 | { |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame] | 438 | TRACE_EVENT_INSTANT2("webrtc_rtp", "RR", |
| 439 | "remote_ssrc", remoteSSRC, |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 440 | "ssrc", main_ssrc_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | |
| 442 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; |
| 443 | } |
| 444 | UpdateReceiveInformation(*ptrReceiveInfo); |
| 445 | |
| 446 | rtcpPacketType = rtcpParser.Iterate(); |
| 447 | |
| 448 | while (rtcpPacketType == RTCPUtility::kRtcpReportBlockItemCode) |
| 449 | { |
| 450 | HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC, numberOfReportBlocks); |
| 451 | rtcpPacketType = rtcpParser.Iterate(); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 456 | void |
| 457 | RTCPReceiver::HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 458 | RTCPPacketInformation& rtcpPacketInformation, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 459 | const uint32_t remoteSSRC, |
| 460 | const uint8_t numberOfReportBlocks) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 461 | // This will be called once per report block in the RTCP packet. |
| 462 | // We filter out all report blocks that are not for us. |
| 463 | // Each packet has max 31 RR blocks. |
| 464 | // |
| 465 | // 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] | 466 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 467 | // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to |
| 468 | // which the information in this reception report block pertains. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 469 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 470 | // Filter out all report blocks that are not for us. |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 471 | if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) == |
| 472 | registered_ssrcs_.end()) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 473 | // This block is not for us ignore it. |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | // To avoid problem with acquiring _criticalSectionRTCPSender while holding |
| 478 | // _criticalSectionRTCPReceiver. |
| 479 | _criticalSectionRTCPReceiver->Leave(); |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 480 | uint32_t sendTimeMS = |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 481 | _rtpRtcp.SendTimeOfSendReport(rtcpPacket.ReportBlockItem.LastSR); |
| 482 | _criticalSectionRTCPReceiver->Enter(); |
| 483 | |
| 484 | RTCPReportBlockInformation* reportBlock = |
| 485 | CreateReportBlockInformation(remoteSSRC); |
| 486 | if (reportBlock == NULL) { |
| 487 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 488 | "\tfailed to CreateReportBlockInformation(%u)", remoteSSRC); |
| 489 | return; |
| 490 | } |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 491 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 492 | _lastReceivedRrMs = _clock->TimeInMilliseconds(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 493 | const RTCPPacketReportBlockItem& rb = rtcpPacket.ReportBlockItem; |
| 494 | reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC; |
| 495 | reportBlock->remoteReceiveBlock.sourceSSRC = rb.SSRC; |
| 496 | reportBlock->remoteReceiveBlock.fractionLost = rb.FractionLost; |
| 497 | reportBlock->remoteReceiveBlock.cumulativeLost = |
| 498 | rb.CumulativeNumOfPacketsLost; |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 499 | if (rb.ExtendedHighestSequenceNumber > |
| 500 | reportBlock->remoteReceiveBlock.extendedHighSeqNum) { |
| 501 | // We have successfully delivered new RTP packets to the remote side after |
| 502 | // the last RR was sent from the remote side. |
| 503 | _lastIncreasedSequenceNumberMs = _lastReceivedRrMs; |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 504 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 505 | reportBlock->remoteReceiveBlock.extendedHighSeqNum = |
| 506 | rb.ExtendedHighestSequenceNumber; |
| 507 | reportBlock->remoteReceiveBlock.jitter = rb.Jitter; |
| 508 | reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; |
| 509 | reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; |
| 510 | |
| 511 | if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { |
| 512 | reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; |
| 513 | } |
| 514 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 515 | uint32_t delaySinceLastSendReport = |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 516 | rtcpPacket.ReportBlockItem.DelayLastSR; |
| 517 | |
| 518 | // local NTP time when we received this |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 519 | uint32_t lastReceivedRRNTPsecs = 0; |
| 520 | uint32_t lastReceivedRRNTPfrac = 0; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 521 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 522 | _clock->CurrentNtp(lastReceivedRRNTPsecs, lastReceivedRRNTPfrac); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 523 | |
| 524 | // time when we received this in MS |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 525 | uint32_t receiveTimeMS = Clock::NtpToMs(lastReceivedRRNTPsecs, |
| 526 | lastReceivedRRNTPfrac); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 527 | |
| 528 | // Estimate RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 529 | uint32_t d = (delaySinceLastSendReport & 0x0000ffff) * 1000; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 530 | d /= 65536; |
| 531 | d += ((delaySinceLastSendReport & 0xffff0000) >> 16) * 1000; |
| 532 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 533 | int32_t RTT = 0; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 534 | |
| 535 | if (sendTimeMS > 0) { |
| 536 | RTT = receiveTimeMS - d - sendTimeMS; |
| 537 | if (RTT <= 0) { |
| 538 | RTT = 1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 539 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 540 | if (RTT > reportBlock->maxRTT) { |
| 541 | // store max RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 542 | reportBlock->maxRTT = (uint16_t) RTT; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 543 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 544 | if (reportBlock->minRTT == 0) { |
| 545 | // first RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 546 | reportBlock->minRTT = (uint16_t) RTT; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 547 | } else if (RTT < reportBlock->minRTT) { |
| 548 | // Store min RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 549 | reportBlock->minRTT = (uint16_t) RTT; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 550 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 551 | // store last RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 552 | reportBlock->RTT = (uint16_t) RTT; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 553 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 554 | // store average RTT |
| 555 | if (reportBlock->numAverageCalcs != 0) { |
| 556 | float ac = static_cast<float> (reportBlock->numAverageCalcs); |
| 557 | float newAverage = ((ac / (ac + 1)) * reportBlock->avgRTT) |
| 558 | + ((1 / (ac + 1)) * RTT); |
| 559 | reportBlock->avgRTT = static_cast<int> (newAverage + 0.5f); |
| 560 | } else { |
| 561 | // first RTT |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 562 | reportBlock->avgRTT = (uint16_t) RTT; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 563 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 564 | reportBlock->numAverageCalcs++; |
| 565 | } |
| 566 | |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame] | 567 | TRACE_COUNTER_ID1("webrtc_rtp", "RR_RTT", rb.SSRC, RTT); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 568 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 569 | rtcpPacketInformation.AddReportInfo(*reportBlock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | RTCPReportBlockInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 573 | RTCPReceiver::CreateReportBlockInformation(uint32_t remoteSSRC) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 574 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 575 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 576 | std::map<uint32_t, RTCPReportBlockInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 577 | _receivedReportBlockMap.find(remoteSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 578 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 579 | RTCPReportBlockInformation* ptrReportBlockInfo = NULL; |
| 580 | if (it != _receivedReportBlockMap.end()) { |
| 581 | ptrReportBlockInfo = it->second; |
| 582 | } else { |
| 583 | ptrReportBlockInfo = new RTCPReportBlockInformation; |
| 584 | _receivedReportBlockMap[remoteSSRC] = ptrReportBlockInfo; |
| 585 | } |
| 586 | return ptrReportBlockInfo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | RTCPReportBlockInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 590 | RTCPReceiver::GetReportBlockInformation(uint32_t remoteSSRC) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 591 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 593 | std::map<uint32_t, RTCPReportBlockInformation*>::const_iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 594 | _receivedReportBlockMap.find(remoteSSRC); |
| 595 | |
| 596 | if (it == _receivedReportBlockMap.end()) { |
| 597 | return NULL; |
| 598 | } |
| 599 | return it->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | RTCPCnameInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 603 | RTCPReceiver::CreateCnameInformation(uint32_t remoteSSRC) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 604 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 605 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 606 | std::map<uint32_t, RTCPCnameInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 607 | _receivedCnameMap.find(remoteSSRC); |
| 608 | |
| 609 | if (it != _receivedCnameMap.end()) { |
| 610 | return it->second; |
| 611 | } |
| 612 | RTCPCnameInformation* cnameInfo = new RTCPCnameInformation; |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 613 | memset(cnameInfo->name, 0, RTCP_CNAME_SIZE); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 614 | _receivedCnameMap[remoteSSRC] = cnameInfo; |
| 615 | return cnameInfo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | RTCPCnameInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 619 | RTCPReceiver::GetCnameInformation(uint32_t remoteSSRC) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 620 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 621 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 622 | std::map<uint32_t, RTCPCnameInformation*>::const_iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 623 | _receivedCnameMap.find(remoteSSRC); |
| 624 | |
| 625 | if (it == _receivedCnameMap.end()) { |
| 626 | return NULL; |
| 627 | } |
| 628 | return it->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | RTCPReceiveInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 632 | RTCPReceiver::CreateReceiveInformation(uint32_t remoteSSRC) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 633 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 634 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 635 | std::map<uint32_t, RTCPReceiveInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 636 | _receivedInfoMap.find(remoteSSRC); |
| 637 | |
| 638 | if (it != _receivedInfoMap.end()) { |
| 639 | return it->second; |
| 640 | } |
| 641 | RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation; |
| 642 | _receivedInfoMap[remoteSSRC] = receiveInfo; |
| 643 | return receiveInfo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | RTCPReceiveInformation* |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 647 | RTCPReceiver::GetReceiveInformation(uint32_t remoteSSRC) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 648 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 649 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 650 | std::map<uint32_t, RTCPReceiveInformation*>::iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 651 | _receivedInfoMap.find(remoteSSRC); |
| 652 | if (it == _receivedInfoMap.end()) { |
| 653 | return NULL; |
| 654 | } |
| 655 | return it->second; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 658 | void RTCPReceiver::UpdateReceiveInformation( |
| 659 | RTCPReceiveInformation& receiveInformation) { |
| 660 | // Update that this remote is alive |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 661 | receiveInformation.lastTimeReceived = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 662 | } |
| 663 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 664 | bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { |
| 665 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 666 | if (_lastReceivedRrMs == 0) |
| 667 | return false; |
| 668 | |
| 669 | int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 670 | if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 671 | // Reset the timer to only trigger one log. |
| 672 | _lastReceivedRrMs = 0; |
| 673 | return true; |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) { |
| 679 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 680 | if (_lastIncreasedSequenceNumberMs == 0) |
| 681 | return false; |
| 682 | |
| 683 | int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 684 | if (_clock->TimeInMilliseconds() > _lastIncreasedSequenceNumberMs + |
stefan@webrtc.org | 20ed36d | 2013-01-17 14:01:20 +0000 | [diff] [blame] | 685 | time_out_ms) { |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 686 | // Reset the timer to only trigger one log. |
| 687 | _lastIncreasedSequenceNumberMs = 0; |
| 688 | return true; |
| 689 | } |
| 690 | return false; |
| 691 | } |
| 692 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 693 | bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { |
| 694 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 695 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 696 | bool updateBoundingSet = false; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 697 | int64_t timeNow = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 698 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 699 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 700 | _receivedInfoMap.begin(); |
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 | while (receiveInfoIt != _receivedInfoMap.end()) { |
| 703 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 704 | if (receiveInfo == NULL) { |
| 705 | return updateBoundingSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 707 | // time since last received rtcp packet |
| 708 | // when we dont have a lastTimeReceived and the object is marked |
| 709 | // readyForDelete it's removed from the map |
| 710 | if (receiveInfo->lastTimeReceived) { |
| 711 | /// use audio define since we don't know what interval the remote peer is |
| 712 | // using |
| 713 | if ((timeNow - receiveInfo->lastTimeReceived) > |
| 714 | 5 * RTCP_INTERVAL_AUDIO_MS) { |
| 715 | // no rtcp packet for the last five regular intervals, reset limitations |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 716 | receiveInfo->TmmbrSet.clearSet(); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 717 | // prevent that we call this over and over again |
| 718 | receiveInfo->lastTimeReceived = 0; |
| 719 | // send new TMMBN to all channels using the default codec |
| 720 | updateBoundingSet = true; |
| 721 | } |
| 722 | receiveInfoIt++; |
| 723 | } else if (receiveInfo->readyForDelete) { |
| 724 | // store our current receiveInfoItem |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 725 | std::map<uint32_t, RTCPReceiveInformation*>::iterator |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 726 | receiveInfoItemToBeErased = receiveInfoIt; |
| 727 | receiveInfoIt++; |
| 728 | delete receiveInfoItemToBeErased->second; |
| 729 | _receivedInfoMap.erase(receiveInfoItemToBeErased); |
| 730 | } else { |
| 731 | receiveInfoIt++; |
| 732 | } |
| 733 | } |
| 734 | return updateBoundingSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 735 | } |
| 736 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 737 | int32_t RTCPReceiver::BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 738 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 739 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 740 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 741 | _receivedInfoMap.find(_remoteSSRC); |
| 742 | |
| 743 | if (receiveInfoIt == _receivedInfoMap.end()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | return -1; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 745 | } |
| 746 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 747 | if (receiveInfo == NULL) { |
| 748 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 749 | "%s failed to get RTCPReceiveInformation", |
| 750 | __FUNCTION__); |
| 751 | return -1; |
| 752 | } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 753 | if (receiveInfo->TmmbnBoundingSet.lengthOfSet() > 0) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 754 | boundingSetRec->VerifyAndAllocateSet( |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 755 | receiveInfo->TmmbnBoundingSet.lengthOfSet() + 1); |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 756 | for(uint32_t i=0; i< receiveInfo->TmmbnBoundingSet.lengthOfSet(); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 757 | i++) { |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 758 | if(receiveInfo->TmmbnBoundingSet.Ssrc(i) == main_ssrc_) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 759 | // owner of bounding set |
| 760 | tmmbrOwner = true; |
| 761 | } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 762 | boundingSetRec->SetEntry(i, |
| 763 | receiveInfo->TmmbnBoundingSet.Tmmbr(i), |
| 764 | receiveInfo->TmmbnBoundingSet.PacketOH(i), |
| 765 | receiveInfo->TmmbnBoundingSet.Ssrc(i)); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 768 | return receiveInfo->TmmbnBoundingSet.lengthOfSet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 772 | void |
| 773 | RTCPReceiver::HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser) |
| 774 | { |
| 775 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 776 | while (pktType == RTCPUtility::kRtcpSdesChunkCode) |
| 777 | { |
| 778 | HandleSDESChunk(rtcpParser); |
| 779 | pktType = rtcpParser.Iterate(); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 784 | void RTCPReceiver::HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser) { |
| 785 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 786 | RTCPCnameInformation* cnameInfo = |
| 787 | CreateCnameInformation(rtcpPacket.CName.SenderSSRC); |
| 788 | assert(cnameInfo); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 789 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 790 | cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; |
| 791 | strncpy(cnameInfo->name, rtcpPacket.CName.CName, RTCP_CNAME_SIZE - 1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 795 | void |
| 796 | RTCPReceiver::HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser, |
| 797 | RTCPPacketInformation& rtcpPacketInformation) |
| 798 | { |
| 799 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 800 | if (main_ssrc_ != rtcpPacket.NACK.MediaSSRC) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 801 | { |
| 802 | // Not to us. |
| 803 | rtcpParser.Iterate(); |
| 804 | return; |
| 805 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 806 | rtcpPacketInformation.ResetNACKPacketIdArray(); |
| 807 | |
| 808 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 809 | while (pktType == RTCPUtility::kRtcpRtpfbNackItemCode) |
| 810 | { |
| 811 | HandleNACKItem(rtcpPacket, rtcpPacketInformation); |
| 812 | pktType = rtcpParser.Iterate(); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 817 | void |
| 818 | RTCPReceiver::HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 819 | RTCPPacketInformation& rtcpPacketInformation) |
| 820 | { |
| 821 | rtcpPacketInformation.AddNACKPacket(rtcpPacket.NACKItem.PacketID); |
| 822 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 823 | uint16_t bitMask = rtcpPacket.NACKItem.BitMask; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 824 | if(bitMask) |
| 825 | { |
| 826 | for(int i=1; i <= 16; ++i) |
| 827 | { |
| 828 | if(bitMask & 0x01) |
| 829 | { |
| 830 | rtcpPacketInformation.AddNACKPacket(rtcpPacket.NACKItem.PacketID + i); |
| 831 | } |
| 832 | bitMask = bitMask >>1; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpNack; |
| 837 | } |
| 838 | |
| 839 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 840 | void RTCPReceiver::HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser) { |
| 841 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 842 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 843 | // clear our lists |
| 844 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 845 | std::map<uint32_t, RTCPReportBlockInformation*>::iterator |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 846 | reportBlockInfoIt = _receivedReportBlockMap.find( |
| 847 | rtcpPacket.BYE.SenderSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 848 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 849 | if (reportBlockInfoIt != _receivedReportBlockMap.end()) { |
| 850 | delete reportBlockInfoIt->second; |
| 851 | _receivedReportBlockMap.erase(reportBlockInfoIt); |
| 852 | } |
| 853 | // we can't delete it due to TMMBR |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 854 | std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 855 | _receivedInfoMap.find(rtcpPacket.BYE.SenderSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 856 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 857 | if (receiveInfoIt != _receivedInfoMap.end()) { |
| 858 | receiveInfoIt->second->readyForDelete = true; |
| 859 | } |
| 860 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 861 | std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 862 | _receivedCnameMap.find(rtcpPacket.BYE.SenderSSRC); |
| 863 | |
| 864 | if (cnameInfoIt != _receivedCnameMap.end()) { |
| 865 | delete cnameInfoIt->second; |
| 866 | _receivedCnameMap.erase(cnameInfoIt); |
| 867 | } |
| 868 | rtcpParser.Iterate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 872 | void |
| 873 | RTCPReceiver::HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, |
| 874 | RTCPPacketInformation& rtcpPacketInformation) |
| 875 | { |
| 876 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 877 | |
| 878 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 879 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 880 | if(rtcpPacket.XRVOIPMetricItem.SSRC == main_ssrc_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 881 | { |
| 882 | // Store VoIP metrics block if it's about me |
| 883 | // from OriginatorSSRC do we filter it? |
| 884 | // rtcpPacket.XR.OriginatorSSRC; |
| 885 | |
| 886 | RTCPVoIPMetric receivedVoIPMetrics; |
| 887 | receivedVoIPMetrics.burstDensity = rtcpPacket.XRVOIPMetricItem.burstDensity; |
| 888 | receivedVoIPMetrics.burstDuration = rtcpPacket.XRVOIPMetricItem.burstDuration; |
| 889 | receivedVoIPMetrics.discardRate = rtcpPacket.XRVOIPMetricItem.discardRate; |
| 890 | receivedVoIPMetrics.endSystemDelay = rtcpPacket.XRVOIPMetricItem.endSystemDelay; |
| 891 | receivedVoIPMetrics.extRfactor = rtcpPacket.XRVOIPMetricItem.extRfactor; |
| 892 | receivedVoIPMetrics.gapDensity = rtcpPacket.XRVOIPMetricItem.gapDensity; |
| 893 | receivedVoIPMetrics.gapDuration = rtcpPacket.XRVOIPMetricItem.gapDuration; |
| 894 | receivedVoIPMetrics.Gmin = rtcpPacket.XRVOIPMetricItem.Gmin; |
| 895 | receivedVoIPMetrics.JBabsMax = rtcpPacket.XRVOIPMetricItem.JBabsMax; |
| 896 | receivedVoIPMetrics.JBmax = rtcpPacket.XRVOIPMetricItem.JBmax; |
| 897 | receivedVoIPMetrics.JBnominal = rtcpPacket.XRVOIPMetricItem.JBnominal; |
| 898 | receivedVoIPMetrics.lossRate = rtcpPacket.XRVOIPMetricItem.lossRate; |
| 899 | receivedVoIPMetrics.MOSCQ = rtcpPacket.XRVOIPMetricItem.MOSCQ; |
| 900 | receivedVoIPMetrics.MOSLQ = rtcpPacket.XRVOIPMetricItem.MOSLQ; |
| 901 | receivedVoIPMetrics.noiseLevel = rtcpPacket.XRVOIPMetricItem.noiseLevel; |
| 902 | receivedVoIPMetrics.RERL = rtcpPacket.XRVOIPMetricItem.RERL; |
| 903 | receivedVoIPMetrics.Rfactor = rtcpPacket.XRVOIPMetricItem.Rfactor; |
| 904 | receivedVoIPMetrics.roundTripDelay = rtcpPacket.XRVOIPMetricItem.roundTripDelay; |
| 905 | receivedVoIPMetrics.RXconfig = rtcpPacket.XRVOIPMetricItem.RXconfig; |
| 906 | receivedVoIPMetrics.signalLevel = rtcpPacket.XRVOIPMetricItem.signalLevel; |
| 907 | |
| 908 | rtcpPacketInformation.AddVoIPMetric(&receivedVoIPMetrics); |
| 909 | |
| 910 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrVoipMetric; // received signal |
| 911 | } |
| 912 | rtcpParser.Iterate(); |
| 913 | } |
| 914 | |
| 915 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 916 | void RTCPReceiver::HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 917 | RTCPPacketInformation& rtcpPacketInformation) { |
| 918 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 919 | if (main_ssrc_ == rtcpPacket.PLI.MediaSSRC) { |
justinlin@chromium.org | 7bfb3a3 | 2013-05-13 22:59:00 +0000 | [diff] [blame] | 920 | TRACE_EVENT_INSTANT0("webrtc_rtp", "PLI"); |
| 921 | |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 922 | // Received a signal that we need to send a new key frame. |
| 923 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpPli; |
| 924 | } |
| 925 | rtcpParser.Iterate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 929 | void |
| 930 | RTCPReceiver::HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 931 | RTCPPacketInformation& rtcpPacketInformation) |
| 932 | { |
| 933 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 934 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 935 | uint32_t senderSSRC = rtcpPacket.TMMBR.SenderSSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 936 | RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); |
| 937 | if (ptrReceiveInfo == NULL) |
| 938 | { |
| 939 | // This remote SSRC must be saved before. |
| 940 | rtcpParser.Iterate(); |
| 941 | return; |
| 942 | } |
| 943 | if(rtcpPacket.TMMBR.MediaSSRC) |
| 944 | { |
| 945 | // rtcpPacket.TMMBR.MediaSSRC SHOULD be 0 if same as SenderSSRC |
| 946 | // in relay mode this is a valid number |
| 947 | senderSSRC = rtcpPacket.TMMBR.MediaSSRC; |
| 948 | } |
| 949 | |
| 950 | // Use packet length to calc max number of TMMBR blocks |
| 951 | // each TMMBR block is 8 bytes |
| 952 | ptrdiff_t maxNumOfTMMBRBlocks = rtcpParser.LengthLeft() / 8; |
| 953 | |
| 954 | // sanity |
| 955 | if(maxNumOfTMMBRBlocks > 200) // we can't have more than what's in one packet |
| 956 | { |
| 957 | assert(false); |
| 958 | rtcpParser.Iterate(); |
| 959 | return; |
| 960 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 961 | ptrReceiveInfo->VerifyAndAllocateTMMBRSet((uint32_t)maxNumOfTMMBRBlocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 962 | |
| 963 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 964 | while (pktType == RTCPUtility::kRtcpRtpfbTmmbrItemCode) |
| 965 | { |
| 966 | HandleTMMBRItem(*ptrReceiveInfo, rtcpPacket, rtcpPacketInformation, senderSSRC); |
| 967 | pktType = rtcpParser.Iterate(); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 972 | void |
| 973 | RTCPReceiver::HandleTMMBRItem(RTCPReceiveInformation& receiveInfo, |
| 974 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 975 | RTCPPacketInformation& rtcpPacketInformation, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 976 | const uint32_t senderSSRC) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 977 | { |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 978 | if (main_ssrc_ == rtcpPacket.TMMBRItem.SSRC && |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 979 | rtcpPacket.TMMBRItem.MaxTotalMediaBitRate > 0) |
| 980 | { |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 981 | receiveInfo.InsertTMMBRItem(senderSSRC, rtcpPacket.TMMBRItem, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 982 | _clock->TimeInMilliseconds()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 983 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbr; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 988 | void |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 989 | RTCPReceiver::HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser, |
| 990 | RTCPPacketInformation& rtcpPacketInformation) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 991 | { |
| 992 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 993 | RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(rtcpPacket.TMMBN.SenderSSRC); |
| 994 | if (ptrReceiveInfo == NULL) |
| 995 | { |
| 996 | // This remote SSRC must be saved before. |
| 997 | rtcpParser.Iterate(); |
| 998 | return; |
| 999 | } |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 1000 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbn; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1001 | // Use packet length to calc max number of TMMBN blocks |
| 1002 | // each TMMBN block is 8 bytes |
| 1003 | ptrdiff_t maxNumOfTMMBNBlocks = rtcpParser.LengthLeft() / 8; |
| 1004 | |
| 1005 | // sanity |
| 1006 | if(maxNumOfTMMBNBlocks > 200) // we cant have more than what's in one packet |
| 1007 | { |
| 1008 | assert(false); |
| 1009 | rtcpParser.Iterate(); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1013 | ptrReceiveInfo->VerifyAndAllocateBoundingSet((uint32_t)maxNumOfTMMBNBlocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1014 | |
| 1015 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1016 | while (pktType == RTCPUtility::kRtcpRtpfbTmmbnItemCode) |
| 1017 | { |
| 1018 | HandleTMMBNItem(*ptrReceiveInfo, rtcpPacket); |
| 1019 | pktType = rtcpParser.Iterate(); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1024 | void |
| 1025 | RTCPReceiver::HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1026 | RTCPPacketInformation& rtcpPacketInformation) |
| 1027 | { |
| 1028 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq; |
| 1029 | rtcpParser.Iterate(); |
| 1030 | } |
| 1031 | |
| 1032 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1033 | void |
| 1034 | RTCPReceiver::HandleTMMBNItem(RTCPReceiveInformation& receiveInfo, |
| 1035 | const RTCPUtility::RTCPPacket& rtcpPacket) |
| 1036 | { |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1037 | receiveInfo.TmmbnBoundingSet.AddEntry( |
| 1038 | rtcpPacket.TMMBNItem.MaxTotalMediaBitRate, |
| 1039 | rtcpPacket.TMMBNItem.MeasuredOverhead, |
| 1040 | rtcpPacket.TMMBNItem.SSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1044 | void |
| 1045 | RTCPReceiver::HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1046 | RTCPPacketInformation& rtcpPacketInformation) |
| 1047 | { |
| 1048 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1049 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1050 | while (pktType == RTCPUtility::kRtcpPsfbSliItemCode) |
| 1051 | { |
| 1052 | HandleSLIItem(rtcpPacket, rtcpPacketInformation); |
| 1053 | pktType = rtcpParser.Iterate(); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1058 | void |
| 1059 | RTCPReceiver::HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1060 | RTCPPacketInformation& rtcpPacketInformation) |
| 1061 | { |
| 1062 | // in theory there could be multiple slices lost |
| 1063 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSli; // received signal that we need to refresh a slice |
| 1064 | rtcpPacketInformation.sliPictureId = rtcpPacket.SLIItem.PictureId; |
| 1065 | } |
| 1066 | |
| 1067 | void |
| 1068 | RTCPReceiver::HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1069 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation) |
| 1070 | { |
| 1071 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1072 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1073 | if(pktType == RTCPUtility::kRtcpPsfbRpsiCode) |
| 1074 | { |
| 1075 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRpsi; // received signal that we have a confirmed reference picture |
| 1076 | if(rtcpPacket.RPSI.NumberOfValidBits%8 != 0) |
| 1077 | { |
| 1078 | // to us unknown |
| 1079 | // continue |
| 1080 | rtcpParser.Iterate(); |
| 1081 | return; |
| 1082 | } |
| 1083 | rtcpPacketInformation.rpsiPictureId = 0; |
| 1084 | |
| 1085 | // convert NativeBitString to rpsiPictureId |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1086 | uint8_t numberOfBytes = rtcpPacket.RPSI.NumberOfValidBits /8; |
| 1087 | for(uint8_t n = 0; n < (numberOfBytes-1); n++) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1088 | { |
| 1089 | rtcpPacketInformation.rpsiPictureId += (rtcpPacket.RPSI.NativeBitString[n] & 0x7f); |
| 1090 | rtcpPacketInformation.rpsiPictureId <<= 7; // prepare next |
| 1091 | } |
| 1092 | rtcpPacketInformation.rpsiPictureId += (rtcpPacket.RPSI.NativeBitString[numberOfBytes-1] & 0x7f); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1097 | void RTCPReceiver::HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1098 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1099 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1100 | if (pktType == RTCPUtility::kRtcpPsfbRembCode) { |
| 1101 | pktType = rtcpParser.Iterate(); |
| 1102 | if (pktType == RTCPUtility::kRtcpPsfbRembItemCode) { |
| 1103 | HandleREMBItem(rtcpParser, rtcpPacketInformation); |
| 1104 | rtcpParser.Iterate(); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1105 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1106 | } |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 1109 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1110 | void |
| 1111 | RTCPReceiver::HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1112 | RTCPPacketInformation& rtcpPacketInformation) |
| 1113 | { |
| 1114 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1115 | |
| 1116 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1117 | while (pktType == RTCPUtility::kRtcpExtendedIjItemCode) |
| 1118 | { |
| 1119 | HandleIJItem(rtcpPacket, rtcpPacketInformation); |
| 1120 | pktType = rtcpParser.Iterate(); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | void |
| 1125 | RTCPReceiver::HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1126 | RTCPPacketInformation& rtcpPacketInformation) |
| 1127 | { |
| 1128 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTransmissionTimeOffset; |
| 1129 | rtcpPacketInformation.interArrivalJitter = |
| 1130 | rtcpPacket.ExtendedJitterReportItem.Jitter; |
| 1131 | } |
| 1132 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1133 | void RTCPReceiver::HandleREMBItem( |
| 1134 | RTCPUtility::RTCPParserV2& rtcpParser, |
| 1135 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1136 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1137 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRemb; |
| 1138 | rtcpPacketInformation.receiverEstimatedMaxBitrate = |
| 1139 | rtcpPacket.REMBItem.BitRate; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1143 | void RTCPReceiver::HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1144 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1145 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1146 | RTCPReceiveInformation* ptrReceiveInfo = |
| 1147 | GetReceiveInformation(rtcpPacket.FIR.SenderSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1148 | |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1149 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1150 | while (pktType == RTCPUtility::kRtcpPsfbFirItemCode) { |
| 1151 | HandleFIRItem(ptrReceiveInfo, rtcpPacket, rtcpPacketInformation); |
| 1152 | pktType = rtcpParser.Iterate(); |
| 1153 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1157 | void RTCPReceiver::HandleFIRItem(RTCPReceiveInformation* receiveInfo, |
| 1158 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1159 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1160 | // Is it our sender that is requested to generate a new keyframe |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 1161 | if (main_ssrc_ != rtcpPacket.FIRItem.SSRC) { |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1162 | return; |
| 1163 | } |
| 1164 | // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it |
| 1165 | // we don't know who this originate from |
| 1166 | if (receiveInfo) { |
| 1167 | // check if we have reported this FIRSequenceNumber before |
| 1168 | if (rtcpPacket.FIRItem.CommandSequenceNumber != |
| 1169 | receiveInfo->lastFIRSequenceNumber) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1170 | int64_t now = _clock->TimeInMilliseconds(); |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1171 | // sanity; don't go crazy with the callbacks |
| 1172 | if ((now - receiveInfo->lastFIRRequest) > RTCP_MIN_FRAME_LENGTH_MS) { |
| 1173 | receiveInfo->lastFIRRequest = now; |
| 1174 | receiveInfo->lastFIRSequenceNumber = |
| 1175 | rtcpPacket.FIRItem.CommandSequenceNumber; |
| 1176 | // received signal that we need to send a new key frame |
| 1177 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; |
| 1178 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1179 | } |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1180 | } else { |
| 1181 | // received signal that we need to send a new key frame |
| 1182 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; |
| 1183 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void |
| 1187 | RTCPReceiver::HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1188 | RTCPPacketInformation& rtcpPacketInformation) |
| 1189 | { |
| 1190 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1191 | |
| 1192 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpApp; |
| 1193 | rtcpPacketInformation.applicationSubType = rtcpPacket.APP.SubType; |
| 1194 | rtcpPacketInformation.applicationName = rtcpPacket.APP.Name; |
| 1195 | |
| 1196 | rtcpParser.Iterate(); |
| 1197 | } |
| 1198 | |
| 1199 | void |
| 1200 | RTCPReceiver::HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1201 | RTCPPacketInformation& rtcpPacketInformation) |
| 1202 | { |
| 1203 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1204 | |
| 1205 | rtcpPacketInformation.AddApplicationData(rtcpPacket.APP.Data, rtcpPacket.APP.Size); |
| 1206 | |
| 1207 | rtcpParser.Iterate(); |
| 1208 | } |
| 1209 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1210 | int32_t RTCPReceiver::UpdateTMMBR() { |
| 1211 | int32_t numBoundingSet = 0; |
| 1212 | uint32_t bitrate = 0; |
| 1213 | uint32_t accNumCandidates = 0; |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1214 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1215 | int32_t size = TMMBRReceived(0, 0, NULL); |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1216 | if (size > 0) { |
| 1217 | TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size); |
| 1218 | // Get candidate set from receiver. |
| 1219 | accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet); |
| 1220 | } else { |
| 1221 | // Candidate set empty. |
| 1222 | VerifyAndAllocateCandidateSet(0); // resets candidate set |
| 1223 | } |
| 1224 | // Find bounding set |
| 1225 | TMMBRSet* boundingSet = NULL; |
| 1226 | numBoundingSet = FindTMMBRBoundingSet(boundingSet); |
| 1227 | if (numBoundingSet == -1) { |
| 1228 | WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, |
| 1229 | "Failed to find TMMBR bounding set."); |
| 1230 | return -1; |
| 1231 | } |
| 1232 | // Set bounding set |
| 1233 | // Inform remote clients about the new bandwidth |
| 1234 | // inform the remote client |
| 1235 | _rtpRtcp.SetTMMBN(boundingSet); |
| 1236 | |
| 1237 | // might trigger a TMMBN |
| 1238 | if (numBoundingSet == 0) { |
| 1239 | // owner of max bitrate request has timed out |
| 1240 | // empty bounding set has been sent |
| 1241 | return 0; |
| 1242 | } |
| 1243 | // Get net bitrate from bounding set depending on sent packet rate |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1244 | if (CalcMinBitRate(&bitrate)) { |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1245 | // we have a new bandwidth estimate on this channel |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1246 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 1247 | if (_cbRtcpBandwidthObserver) { |
| 1248 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000); |
| 1249 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
| 1250 | "Set TMMBR request:%d kbps", bitrate); |
| 1251 | } |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1252 | } |
| 1253 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | // Holding no Critical section |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1257 | void RTCPReceiver::TriggerCallbacksFromRTCPPacket( |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1258 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1259 | // Process TMMBR and REMB first to avoid multiple callbacks |
| 1260 | // to OnNetworkChanged. |
| 1261 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTmmbr) { |
| 1262 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1263 | "SIG [RTCP] Incoming TMMBR to id:%d", _id); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1264 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1265 | // Might trigger a OnReceivedBandwidthEstimateUpdate. |
| 1266 | UpdateTMMBR(); |
| 1267 | } |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1268 | unsigned int local_ssrc = 0; |
| 1269 | { |
| 1270 | // We don't want to hold this critsect when triggering the callbacks below. |
| 1271 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 1272 | local_ssrc = main_ssrc_; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1273 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1274 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq) { |
| 1275 | _rtpRtcp.OnRequestSendReport(); |
| 1276 | } |
| 1277 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) { |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 1278 | if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1279 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1280 | "SIG [RTCP] Incoming NACK length:%d", |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 1281 | rtcpPacketInformation.nackSequenceNumbers.size()); |
| 1282 | _rtpRtcp.OnReceivedNACK(rtcpPacketInformation.nackSequenceNumbers); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1283 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1284 | } |
| 1285 | { |
| 1286 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1287 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1288 | // We need feedback that we have received a report block(s) so that we |
| 1289 | // can generate a new packet in a conference relay scenario, one received |
| 1290 | // report can generate several RTCP packets, based on number relayed/mixed |
| 1291 | // a send report block should go out to all receivers. |
| 1292 | if (_cbRtcpIntraFrameObserver) { |
| 1293 | if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) || |
| 1294 | (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpFir)) { |
| 1295 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) { |
| 1296 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1297 | "SIG [RTCP] Incoming PLI from SSRC:0x%x", |
| 1298 | rtcpPacketInformation.remoteSSRC); |
| 1299 | } else { |
| 1300 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1301 | "SIG [RTCP] Incoming FIR from SSRC:0x%x", |
| 1302 | rtcpPacketInformation.remoteSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1303 | } |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1304 | _cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1305 | } |
| 1306 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSli) { |
| 1307 | _cbRtcpIntraFrameObserver->OnReceivedSLI( |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1308 | local_ssrc, rtcpPacketInformation.sliPictureId); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1309 | } |
| 1310 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRpsi) { |
| 1311 | _cbRtcpIntraFrameObserver->OnReceivedRPSI( |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1312 | local_ssrc, rtcpPacketInformation.rpsiPictureId); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1313 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1314 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1315 | if (_cbRtcpBandwidthObserver) { |
| 1316 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb) { |
| 1317 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1318 | "SIG [RTCP] Incoming REMB:%d", |
| 1319 | rtcpPacketInformation.receiverEstimatedMaxBitrate); |
| 1320 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate( |
| 1321 | rtcpPacketInformation.receiverEstimatedMaxBitrate); |
| 1322 | } |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 1323 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr || |
| 1324 | rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1325 | int64_t now = _clock->TimeInMilliseconds(); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1326 | _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame^] | 1327 | rtcpPacketInformation.report_blocks, |
| 1328 | rtcpPacketInformation.rtt, |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1329 | now); |
| 1330 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1331 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1332 | if(_cbRtcpFeedback) { |
solenberg@webrtc.org | 91811e2 | 2013-06-25 20:36:14 +0000 | [diff] [blame] | 1333 | if(!(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr)) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1334 | _cbRtcpFeedback->OnReceiveReportReceived(_id, |
| 1335 | rtcpPacketInformation.remoteSSRC); |
| 1336 | } |
| 1337 | if(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpXrVoipMetric) { |
| 1338 | _cbRtcpFeedback->OnXRVoIPMetricReceived(_id, |
| 1339 | rtcpPacketInformation.VoIPMetric); |
| 1340 | } |
| 1341 | if(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpApp) { |
| 1342 | _cbRtcpFeedback->OnApplicationDataReceived(_id, |
| 1343 | rtcpPacketInformation.applicationSubType, |
| 1344 | rtcpPacketInformation.applicationName, |
| 1345 | rtcpPacketInformation.applicationLength, |
| 1346 | rtcpPacketInformation.applicationData); |
| 1347 | } |
| 1348 | } |
| 1349 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1352 | int32_t RTCPReceiver::CNAME(const uint32_t remoteSSRC, |
| 1353 | char cName[RTCP_CNAME_SIZE]) const { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1354 | assert(cName); |
| 1355 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1356 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 1357 | RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1358 | if (cnameInfo == NULL) { |
| 1359 | return -1; |
| 1360 | } |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1361 | cName[RTCP_CNAME_SIZE - 1] = 0; |
| 1362 | strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); |
| 1363 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | // no callbacks allowed inside this function |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1367 | int32_t RTCPReceiver::TMMBRReceived(const uint32_t size, |
| 1368 | const uint32_t accNumCandidates, |
| 1369 | TMMBRSet* candidateSet) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1370 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1371 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1372 | std::map<uint32_t, RTCPReceiveInformation*>::const_iterator |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1373 | receiveInfoIt = _receivedInfoMap.begin(); |
| 1374 | if (receiveInfoIt == _receivedInfoMap.end()) { |
| 1375 | return -1; |
| 1376 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1377 | uint32_t num = accNumCandidates; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1378 | if (candidateSet) { |
| 1379 | while( num < size && receiveInfoIt != _receivedInfoMap.end()) { |
| 1380 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 1381 | if (receiveInfo == NULL) { |
| 1382 | return 0; |
| 1383 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1384 | for (uint32_t i = 0; |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1385 | (num < size) && (i < receiveInfo->TmmbrSet.lengthOfSet()); i++) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1386 | if (receiveInfo->GetTMMBRSet(i, num, candidateSet, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 1387 | _clock->TimeInMilliseconds()) == 0) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1388 | num++; |
| 1389 | } |
| 1390 | } |
| 1391 | receiveInfoIt++; |
| 1392 | } |
| 1393 | } else { |
| 1394 | while (receiveInfoIt != _receivedInfoMap.end()) { |
| 1395 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 1396 | if(receiveInfo == NULL) { |
| 1397 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 1398 | "%s failed to get RTCPReceiveInformation", |
| 1399 | __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1400 | return -1; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1401 | } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1402 | num += receiveInfo->TmmbrSet.lengthOfSet(); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1403 | receiveInfoIt++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1404 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1405 | } |
| 1406 | return num; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 1409 | } // namespace webrtc |