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