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