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" |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame^] | 17 | #include "trace_event.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include "critical_section_wrapper.h" |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 19 | #include "rtcp_utility.h" |
| 20 | #include "rtp_rtcp_impl.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), |
| 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 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 144 | void RTCPReceiver::RegisterRtcpObservers( |
| 145 | RtcpIntraFrameObserver* intra_frame_callback, |
| 146 | RtcpBandwidthObserver* bandwidth_callback, |
| 147 | RtcpFeedback* feedback_callback) { |
| 148 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 149 | _cbRtcpIntraFrameObserver = intra_frame_callback; |
| 150 | _cbRtcpBandwidthObserver = bandwidth_callback; |
| 151 | _cbRtcpFeedback = feedback_callback; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | } |
| 153 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 155 | void RTCPReceiver::SetSSRC(const uint32_t ssrc) { |
| 156 | uint32_t old_ssrc = 0; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 157 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 159 | old_ssrc = _SSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | _SSRC = ssrc; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 161 | } |
| 162 | { |
| 163 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 164 | if (_cbRtcpIntraFrameObserver && old_ssrc != ssrc) { |
| 165 | _cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, ssrc); |
| 166 | } |
| 167 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | } |
| 169 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 170 | int32_t RTCPReceiver::ResetRTT(const uint32_t remoteSSRC) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 171 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 172 | RTCPReportBlockInformation* reportBlock = |
| 173 | GetReportBlockInformation(remoteSSRC); |
| 174 | if (reportBlock == NULL) { |
| 175 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 176 | "\tfailed to GetReportBlockInformation(%u)", remoteSSRC); |
| 177 | return -1; |
| 178 | } |
| 179 | reportBlock->RTT = 0; |
| 180 | reportBlock->avgRTT = 0; |
| 181 | reportBlock->minRTT = 0; |
| 182 | reportBlock->maxRTT = 0; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 183 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | } |
| 185 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 186 | int32_t RTCPReceiver::RTT(const uint32_t remoteSSRC, |
| 187 | uint16_t* RTT, |
| 188 | uint16_t* avgRTT, |
| 189 | uint16_t* minRTT, |
| 190 | uint16_t* maxRTT) const { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 191 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 193 | RTCPReportBlockInformation* reportBlock = |
| 194 | GetReportBlockInformation(remoteSSRC); |
| 195 | |
| 196 | if (reportBlock == NULL) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 197 | return -1; |
| 198 | } |
| 199 | if (RTT) { |
| 200 | *RTT = reportBlock->RTT; |
| 201 | } |
| 202 | if (avgRTT) { |
| 203 | *avgRTT = reportBlock->avgRTT; |
| 204 | } |
| 205 | if (minRTT) { |
| 206 | *minRTT = reportBlock->minRTT; |
| 207 | } |
| 208 | if (maxRTT) { |
| 209 | *maxRTT = reportBlock->maxRTT; |
| 210 | } |
| 211 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | } |
| 213 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 214 | uint16_t RTCPReceiver::RTT() const { |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 215 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 216 | if (!_receivedReportBlockMap.empty()) { |
| 217 | return 0; |
| 218 | } |
| 219 | return _rtt; |
| 220 | } |
| 221 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 222 | int RTCPReceiver::SetRTT(uint16_t rtt) { |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 223 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 224 | if (!_receivedReportBlockMap.empty()) { |
| 225 | return -1; |
| 226 | } |
| 227 | _rtt = rtt; |
| 228 | return 0; |
| 229 | } |
| 230 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 231 | int32_t |
| 232 | RTCPReceiver::NTP(uint32_t *ReceivedNTPsecs, |
| 233 | uint32_t *ReceivedNTPfrac, |
| 234 | uint32_t *RTCPArrivalTimeSecs, |
| 235 | uint32_t *RTCPArrivalTimeFrac, |
| 236 | uint32_t *rtcp_timestamp) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | { |
| 238 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 239 | if(ReceivedNTPsecs) |
| 240 | { |
| 241 | *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; // NTP from incoming SendReport |
| 242 | } |
| 243 | if(ReceivedNTPfrac) |
| 244 | { |
| 245 | *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction; |
| 246 | } |
| 247 | if(RTCPArrivalTimeFrac) |
| 248 | { |
| 249 | *RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we received a RTCP packet with a send block |
| 250 | } |
| 251 | if(RTCPArrivalTimeSecs) |
| 252 | { |
| 253 | *RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs; |
| 254 | } |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 255 | if (rtcp_timestamp) { |
| 256 | *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp; |
| 257 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 261 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const |
| 263 | { |
| 264 | if(senderInfo == NULL) |
| 265 | { |
| 266 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, "%s invalid argument", __FUNCTION__); |
| 267 | return -1; |
| 268 | } |
| 269 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 270 | if(_lastReceivedSRNTPsecs == 0) |
| 271 | { |
| 272 | WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, "%s No received SR", __FUNCTION__); |
| 273 | return -1; |
| 274 | } |
| 275 | memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo)); |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | // statistics |
| 280 | // 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] | 281 | int32_t RTCPReceiver::StatisticsReceived( |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 282 | std::vector<RTCPReportBlock>* receiveBlocks) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 283 | assert(receiveBlocks); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 284 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 285 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 286 | std::map<uint32_t, RTCPReportBlockInformation*>::const_iterator it = |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 287 | _receivedReportBlockMap.begin(); |
| 288 | |
| 289 | while (it != _receivedReportBlockMap.end()) { |
| 290 | receiveBlocks->push_back(it->second->remoteReceiveBlock); |
| 291 | it++; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 292 | } |
| 293 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | } |
| 295 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 296 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | RTCPReceiver::IncomingRTCPPacket(RTCPPacketInformation& rtcpPacketInformation, |
| 298 | RTCPUtility::RTCPParserV2* rtcpParser) |
| 299 | { |
| 300 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 301 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 302 | _lastReceived = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | |
| 304 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin(); |
| 305 | while (pktType != RTCPUtility::kRtcpNotValidCode) |
| 306 | { |
| 307 | // Each "case" is responsible for iterate the parser to the |
| 308 | // next top level packet. |
| 309 | switch (pktType) |
| 310 | { |
| 311 | case RTCPUtility::kRtcpSrCode: |
| 312 | case RTCPUtility::kRtcpRrCode: |
| 313 | HandleSenderReceiverReport(*rtcpParser, rtcpPacketInformation); |
| 314 | break; |
| 315 | case RTCPUtility::kRtcpSdesCode: |
| 316 | HandleSDES(*rtcpParser); |
| 317 | break; |
| 318 | case RTCPUtility::kRtcpXrVoipMetricCode: |
| 319 | HandleXRVOIPMetric(*rtcpParser, rtcpPacketInformation); |
| 320 | break; |
| 321 | case RTCPUtility::kRtcpByeCode: |
| 322 | HandleBYE(*rtcpParser); |
| 323 | break; |
| 324 | case RTCPUtility::kRtcpRtpfbNackCode: |
| 325 | HandleNACK(*rtcpParser, rtcpPacketInformation); |
| 326 | break; |
| 327 | case RTCPUtility::kRtcpRtpfbTmmbrCode: |
| 328 | HandleTMMBR(*rtcpParser, rtcpPacketInformation); |
| 329 | break; |
| 330 | case RTCPUtility::kRtcpRtpfbTmmbnCode: |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 331 | HandleTMMBN(*rtcpParser, rtcpPacketInformation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | break; |
| 333 | case RTCPUtility::kRtcpRtpfbSrReqCode: |
| 334 | HandleSR_REQ(*rtcpParser, rtcpPacketInformation); |
| 335 | break; |
| 336 | case RTCPUtility::kRtcpPsfbPliCode: |
| 337 | HandlePLI(*rtcpParser, rtcpPacketInformation); |
| 338 | break; |
| 339 | case RTCPUtility::kRtcpPsfbSliCode: |
| 340 | HandleSLI(*rtcpParser, rtcpPacketInformation); |
| 341 | break; |
| 342 | case RTCPUtility::kRtcpPsfbRpsiCode: |
| 343 | HandleRPSI(*rtcpParser, rtcpPacketInformation); |
| 344 | break; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 345 | case RTCPUtility::kRtcpExtendedIjCode: |
| 346 | HandleIJ(*rtcpParser, rtcpPacketInformation); |
| 347 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | case RTCPUtility::kRtcpPsfbFirCode: |
| 349 | HandleFIR(*rtcpParser, rtcpPacketInformation); |
| 350 | break; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 351 | case RTCPUtility::kRtcpPsfbAppCode: |
| 352 | HandlePsfbApp(*rtcpParser, rtcpPacketInformation); |
| 353 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | case RTCPUtility::kRtcpAppCode: |
| 355 | // generic application messages |
| 356 | HandleAPP(*rtcpParser, rtcpPacketInformation); |
| 357 | break; |
| 358 | case RTCPUtility::kRtcpAppItemCode: |
| 359 | // generic application messages |
| 360 | HandleAPPItem(*rtcpParser, rtcpPacketInformation); |
| 361 | break; |
| 362 | default: |
| 363 | rtcpParser->Iterate(); |
| 364 | break; |
| 365 | } |
| 366 | pktType = rtcpParser->PacketType(); |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 372 | void |
| 373 | RTCPReceiver::HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser, |
| 374 | RTCPPacketInformation& rtcpPacketInformation) |
| 375 | { |
| 376 | RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); |
| 377 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 378 | |
| 379 | assert((rtcpPacketType == RTCPUtility::kRtcpRrCode) || (rtcpPacketType == RTCPUtility::kRtcpSrCode)); |
| 380 | |
| 381 | // SR.SenderSSRC |
| 382 | // The synchronization source identifier for the originator of this SR packet |
| 383 | |
| 384 | // rtcpPacket.RR.SenderSSRC |
| 385 | // The source of the packet sender, same as of SR? or is this a CE? |
| 386 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 387 | const uint32_t remoteSSRC = (rtcpPacketType == RTCPUtility::kRtcpRrCode) ? rtcpPacket.RR.SenderSSRC:rtcpPacket.SR.SenderSSRC; |
| 388 | 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] | 389 | |
| 390 | rtcpPacketInformation.remoteSSRC = remoteSSRC; |
| 391 | |
| 392 | RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
| 393 | if (!ptrReceiveInfo) |
| 394 | { |
| 395 | rtcpParser.Iterate(); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | if (rtcpPacketType == RTCPUtility::kRtcpSrCode) |
| 400 | { |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame^] | 401 | TRACE_EVENT_INSTANT2("webrtc_rtp", "SR", |
| 402 | "remote_ssrc", remoteSSRC, |
| 403 | "ssrc", _SSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | |
| 405 | if (_remoteSSRC == remoteSSRC) // have I received RTP packets from this party |
| 406 | { |
| 407 | // only signal that we have received a SR when we accept one |
| 408 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr; |
| 409 | |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 410 | rtcpPacketInformation.ntp_secs = rtcpPacket.SR.NTPMostSignificant; |
| 411 | rtcpPacketInformation.ntp_frac = rtcpPacket.SR.NTPLeastSignificant; |
| 412 | rtcpPacketInformation.rtp_timestamp = rtcpPacket.SR.RTPTimestamp; |
| 413 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 414 | // We will only store the send report from one source, but |
| 415 | // we will store all the receive block |
| 416 | |
| 417 | // Save the NTP time of this report |
| 418 | _remoteSenderInfo.NTPseconds = rtcpPacket.SR.NTPMostSignificant; |
| 419 | _remoteSenderInfo.NTPfraction = rtcpPacket.SR.NTPLeastSignificant; |
| 420 | _remoteSenderInfo.RTPtimeStamp = rtcpPacket.SR.RTPTimestamp; |
| 421 | _remoteSenderInfo.sendPacketCount = rtcpPacket.SR.SenderPacketCount; |
| 422 | _remoteSenderInfo.sendOctetCount = rtcpPacket.SR.SenderOctetCount; |
| 423 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 424 | _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 425 | } |
| 426 | else |
| 427 | { |
| 428 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; |
| 429 | } |
| 430 | } else |
| 431 | { |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame^] | 432 | TRACE_EVENT_INSTANT2("webrtc_rtp", "RR", |
| 433 | "remote_ssrc", remoteSSRC, |
| 434 | "ssrc", _SSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 435 | |
| 436 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; |
| 437 | } |
| 438 | UpdateReceiveInformation(*ptrReceiveInfo); |
| 439 | |
| 440 | rtcpPacketType = rtcpParser.Iterate(); |
| 441 | |
| 442 | while (rtcpPacketType == RTCPUtility::kRtcpReportBlockItemCode) |
| 443 | { |
| 444 | HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC, numberOfReportBlocks); |
| 445 | rtcpPacketType = rtcpParser.Iterate(); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 450 | void |
| 451 | RTCPReceiver::HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 452 | RTCPPacketInformation& rtcpPacketInformation, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 453 | const uint32_t remoteSSRC, |
| 454 | const uint8_t numberOfReportBlocks) { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 455 | // This will be called once per report block in the RTCP packet. |
| 456 | // We filter out all report blocks that are not for us. |
| 457 | // Each packet has max 31 RR blocks. |
| 458 | // |
| 459 | // 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] | 460 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 461 | // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to |
| 462 | // which the information in this reception report block pertains. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 463 | |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 464 | // Filter out all report blocks that are not for us. |
| 465 | if (rtcpPacket.ReportBlockItem.SSRC != _SSRC) { |
| 466 | // This block is not for us ignore it. |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | // To avoid problem with acquiring _criticalSectionRTCPSender while holding |
| 471 | // _criticalSectionRTCPReceiver. |
| 472 | _criticalSectionRTCPReceiver->Leave(); |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 473 | uint32_t sendTimeMS = |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 474 | _rtpRtcp.SendTimeOfSendReport(rtcpPacket.ReportBlockItem.LastSR); |
| 475 | _criticalSectionRTCPReceiver->Enter(); |
| 476 | |
| 477 | RTCPReportBlockInformation* reportBlock = |
| 478 | CreateReportBlockInformation(remoteSSRC); |
| 479 | if (reportBlock == NULL) { |
| 480 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 481 | "\tfailed to CreateReportBlockInformation(%u)", remoteSSRC); |
| 482 | return; |
| 483 | } |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 484 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 485 | _lastReceivedRrMs = _clock->TimeInMilliseconds(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 486 | const RTCPPacketReportBlockItem& rb = rtcpPacket.ReportBlockItem; |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame^] | 487 | TRACE_COUNTER_ID1("webrtc_rtp", "RRFractionLost", rb.SSRC, rb.FractionLost); |
| 488 | TRACE_COUNTER_ID1("webrtc_rtp", "RRCumulativeNumOfPacketLost", |
| 489 | rb.SSRC, rb.CumulativeNumOfPacketsLost); |
| 490 | TRACE_COUNTER_ID1("webrtc_rtp", "RRJitter", rb.SSRC, rb.Jitter); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 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 | 7da3459 | 2013-04-09 14:56:29 +0000 | [diff] [blame] | 522 | uint32_t receiveTimeMS = ModuleRTPUtility::ConvertNTPTimeToMS( |
| 523 | lastReceivedRRNTPsecs, 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) { |
| 921 | // Received a signal that we need to send a new key frame. |
| 922 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpPli; |
| 923 | } |
| 924 | rtcpParser.Iterate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 928 | void |
| 929 | RTCPReceiver::HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 930 | RTCPPacketInformation& rtcpPacketInformation) |
| 931 | { |
| 932 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 933 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 934 | uint32_t senderSSRC = rtcpPacket.TMMBR.SenderSSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 935 | RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); |
| 936 | if (ptrReceiveInfo == NULL) |
| 937 | { |
| 938 | // This remote SSRC must be saved before. |
| 939 | rtcpParser.Iterate(); |
| 940 | return; |
| 941 | } |
| 942 | if(rtcpPacket.TMMBR.MediaSSRC) |
| 943 | { |
| 944 | // rtcpPacket.TMMBR.MediaSSRC SHOULD be 0 if same as SenderSSRC |
| 945 | // in relay mode this is a valid number |
| 946 | senderSSRC = rtcpPacket.TMMBR.MediaSSRC; |
| 947 | } |
| 948 | |
| 949 | // Use packet length to calc max number of TMMBR blocks |
| 950 | // each TMMBR block is 8 bytes |
| 951 | ptrdiff_t maxNumOfTMMBRBlocks = rtcpParser.LengthLeft() / 8; |
| 952 | |
| 953 | // sanity |
| 954 | if(maxNumOfTMMBRBlocks > 200) // we can't have more than what's in one packet |
| 955 | { |
| 956 | assert(false); |
| 957 | rtcpParser.Iterate(); |
| 958 | return; |
| 959 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 960 | ptrReceiveInfo->VerifyAndAllocateTMMBRSet((uint32_t)maxNumOfTMMBRBlocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 961 | |
| 962 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 963 | while (pktType == RTCPUtility::kRtcpRtpfbTmmbrItemCode) |
| 964 | { |
| 965 | HandleTMMBRItem(*ptrReceiveInfo, rtcpPacket, rtcpPacketInformation, senderSSRC); |
| 966 | pktType = rtcpParser.Iterate(); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 971 | void |
| 972 | RTCPReceiver::HandleTMMBRItem(RTCPReceiveInformation& receiveInfo, |
| 973 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 974 | RTCPPacketInformation& rtcpPacketInformation, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 975 | const uint32_t senderSSRC) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 976 | { |
| 977 | if (_SSRC == rtcpPacket.TMMBRItem.SSRC && |
| 978 | rtcpPacket.TMMBRItem.MaxTotalMediaBitRate > 0) |
| 979 | { |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 980 | receiveInfo.InsertTMMBRItem(senderSSRC, rtcpPacket.TMMBRItem, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 981 | _clock->TimeInMilliseconds()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 982 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbr; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 987 | void |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 988 | RTCPReceiver::HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser, |
| 989 | RTCPPacketInformation& rtcpPacketInformation) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 990 | { |
| 991 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 992 | RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(rtcpPacket.TMMBN.SenderSSRC); |
| 993 | if (ptrReceiveInfo == NULL) |
| 994 | { |
| 995 | // This remote SSRC must be saved before. |
| 996 | rtcpParser.Iterate(); |
| 997 | return; |
| 998 | } |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 999 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbn; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1000 | // Use packet length to calc max number of TMMBN blocks |
| 1001 | // each TMMBN block is 8 bytes |
| 1002 | ptrdiff_t maxNumOfTMMBNBlocks = rtcpParser.LengthLeft() / 8; |
| 1003 | |
| 1004 | // sanity |
| 1005 | if(maxNumOfTMMBNBlocks > 200) // we cant have more than what's in one packet |
| 1006 | { |
| 1007 | assert(false); |
| 1008 | rtcpParser.Iterate(); |
| 1009 | return; |
| 1010 | } |
| 1011 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1012 | ptrReceiveInfo->VerifyAndAllocateBoundingSet((uint32_t)maxNumOfTMMBNBlocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1013 | |
| 1014 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1015 | while (pktType == RTCPUtility::kRtcpRtpfbTmmbnItemCode) |
| 1016 | { |
| 1017 | HandleTMMBNItem(*ptrReceiveInfo, rtcpPacket); |
| 1018 | pktType = rtcpParser.Iterate(); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1023 | void |
| 1024 | RTCPReceiver::HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1025 | RTCPPacketInformation& rtcpPacketInformation) |
| 1026 | { |
| 1027 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq; |
| 1028 | rtcpParser.Iterate(); |
| 1029 | } |
| 1030 | |
| 1031 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1032 | void |
| 1033 | RTCPReceiver::HandleTMMBNItem(RTCPReceiveInformation& receiveInfo, |
| 1034 | const RTCPUtility::RTCPPacket& rtcpPacket) |
| 1035 | { |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1036 | receiveInfo.TmmbnBoundingSet.AddEntry( |
| 1037 | rtcpPacket.TMMBNItem.MaxTotalMediaBitRate, |
| 1038 | rtcpPacket.TMMBNItem.MeasuredOverhead, |
| 1039 | rtcpPacket.TMMBNItem.SSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1043 | void |
| 1044 | RTCPReceiver::HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1045 | RTCPPacketInformation& rtcpPacketInformation) |
| 1046 | { |
| 1047 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1048 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1049 | while (pktType == RTCPUtility::kRtcpPsfbSliItemCode) |
| 1050 | { |
| 1051 | HandleSLIItem(rtcpPacket, rtcpPacketInformation); |
| 1052 | pktType = rtcpParser.Iterate(); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1057 | void |
| 1058 | RTCPReceiver::HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1059 | RTCPPacketInformation& rtcpPacketInformation) |
| 1060 | { |
| 1061 | // in theory there could be multiple slices lost |
| 1062 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSli; // received signal that we need to refresh a slice |
| 1063 | rtcpPacketInformation.sliPictureId = rtcpPacket.SLIItem.PictureId; |
| 1064 | } |
| 1065 | |
| 1066 | void |
| 1067 | RTCPReceiver::HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1068 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation) |
| 1069 | { |
| 1070 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1072 | if(pktType == RTCPUtility::kRtcpPsfbRpsiCode) |
| 1073 | { |
| 1074 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRpsi; // received signal that we have a confirmed reference picture |
| 1075 | if(rtcpPacket.RPSI.NumberOfValidBits%8 != 0) |
| 1076 | { |
| 1077 | // to us unknown |
| 1078 | // continue |
| 1079 | rtcpParser.Iterate(); |
| 1080 | return; |
| 1081 | } |
| 1082 | rtcpPacketInformation.rpsiPictureId = 0; |
| 1083 | |
| 1084 | // convert NativeBitString to rpsiPictureId |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1085 | uint8_t numberOfBytes = rtcpPacket.RPSI.NumberOfValidBits /8; |
| 1086 | for(uint8_t n = 0; n < (numberOfBytes-1); n++) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1087 | { |
| 1088 | rtcpPacketInformation.rpsiPictureId += (rtcpPacket.RPSI.NativeBitString[n] & 0x7f); |
| 1089 | rtcpPacketInformation.rpsiPictureId <<= 7; // prepare next |
| 1090 | } |
| 1091 | rtcpPacketInformation.rpsiPictureId += (rtcpPacket.RPSI.NativeBitString[numberOfBytes-1] & 0x7f); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1096 | void RTCPReceiver::HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1097 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1098 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1099 | if (pktType == RTCPUtility::kRtcpPsfbRembCode) { |
| 1100 | pktType = rtcpParser.Iterate(); |
| 1101 | if (pktType == RTCPUtility::kRtcpPsfbRembItemCode) { |
| 1102 | HandleREMBItem(rtcpParser, rtcpPacketInformation); |
| 1103 | rtcpParser.Iterate(); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1104 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1105 | } |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 1108 | // no need for critsect we have _criticalSectionRTCPReceiver |
| 1109 | void |
| 1110 | RTCPReceiver::HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1111 | RTCPPacketInformation& rtcpPacketInformation) |
| 1112 | { |
| 1113 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1114 | |
| 1115 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1116 | while (pktType == RTCPUtility::kRtcpExtendedIjItemCode) |
| 1117 | { |
| 1118 | HandleIJItem(rtcpPacket, rtcpPacketInformation); |
| 1119 | pktType = rtcpParser.Iterate(); |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | void |
| 1124 | RTCPReceiver::HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1125 | RTCPPacketInformation& rtcpPacketInformation) |
| 1126 | { |
| 1127 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTransmissionTimeOffset; |
| 1128 | rtcpPacketInformation.interArrivalJitter = |
| 1129 | rtcpPacket.ExtendedJitterReportItem.Jitter; |
| 1130 | } |
| 1131 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1132 | void RTCPReceiver::HandleREMBItem( |
| 1133 | RTCPUtility::RTCPParserV2& rtcpParser, |
| 1134 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1135 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1136 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRemb; |
| 1137 | rtcpPacketInformation.receiverEstimatedMaxBitrate = |
| 1138 | rtcpPacket.REMBItem.BitRate; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1142 | void RTCPReceiver::HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1143 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1144 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1145 | RTCPReceiveInformation* ptrReceiveInfo = |
| 1146 | GetReceiveInformation(rtcpPacket.FIR.SenderSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1147 | |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1148 | RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); |
| 1149 | while (pktType == RTCPUtility::kRtcpPsfbFirItemCode) { |
| 1150 | HandleFIRItem(ptrReceiveInfo, rtcpPacket, rtcpPacketInformation); |
| 1151 | pktType = rtcpParser.Iterate(); |
| 1152 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | // no need for critsect we have _criticalSectionRTCPReceiver |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1156 | void RTCPReceiver::HandleFIRItem(RTCPReceiveInformation* receiveInfo, |
| 1157 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 1158 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1159 | // Is it our sender that is requested to generate a new keyframe |
| 1160 | if (_SSRC != rtcpPacket.FIRItem.SSRC) { |
| 1161 | return; |
| 1162 | } |
| 1163 | // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it |
| 1164 | // we don't know who this originate from |
| 1165 | if (receiveInfo) { |
| 1166 | // check if we have reported this FIRSequenceNumber before |
| 1167 | if (rtcpPacket.FIRItem.CommandSequenceNumber != |
| 1168 | receiveInfo->lastFIRSequenceNumber) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1169 | int64_t now = _clock->TimeInMilliseconds(); |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1170 | // sanity; don't go crazy with the callbacks |
| 1171 | if ((now - receiveInfo->lastFIRRequest) > RTCP_MIN_FRAME_LENGTH_MS) { |
| 1172 | receiveInfo->lastFIRRequest = now; |
| 1173 | receiveInfo->lastFIRSequenceNumber = |
| 1174 | rtcpPacket.FIRItem.CommandSequenceNumber; |
| 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 | } |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 1179 | } else { |
| 1180 | // received signal that we need to send a new key frame |
| 1181 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; |
| 1182 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | void |
| 1186 | RTCPReceiver::HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1187 | RTCPPacketInformation& rtcpPacketInformation) |
| 1188 | { |
| 1189 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1190 | |
| 1191 | rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpApp; |
| 1192 | rtcpPacketInformation.applicationSubType = rtcpPacket.APP.SubType; |
| 1193 | rtcpPacketInformation.applicationName = rtcpPacket.APP.Name; |
| 1194 | |
| 1195 | rtcpParser.Iterate(); |
| 1196 | } |
| 1197 | |
| 1198 | void |
| 1199 | RTCPReceiver::HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser, |
| 1200 | RTCPPacketInformation& rtcpPacketInformation) |
| 1201 | { |
| 1202 | const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
| 1203 | |
| 1204 | rtcpPacketInformation.AddApplicationData(rtcpPacket.APP.Data, rtcpPacket.APP.Size); |
| 1205 | |
| 1206 | rtcpParser.Iterate(); |
| 1207 | } |
| 1208 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1209 | int32_t RTCPReceiver::UpdateTMMBR() { |
| 1210 | int32_t numBoundingSet = 0; |
| 1211 | uint32_t bitrate = 0; |
| 1212 | uint32_t accNumCandidates = 0; |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1213 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1214 | int32_t size = TMMBRReceived(0, 0, NULL); |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1215 | if (size > 0) { |
| 1216 | TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size); |
| 1217 | // Get candidate set from receiver. |
| 1218 | accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet); |
| 1219 | } else { |
| 1220 | // Candidate set empty. |
| 1221 | VerifyAndAllocateCandidateSet(0); // resets candidate set |
| 1222 | } |
| 1223 | // Find bounding set |
| 1224 | TMMBRSet* boundingSet = NULL; |
| 1225 | numBoundingSet = FindTMMBRBoundingSet(boundingSet); |
| 1226 | if (numBoundingSet == -1) { |
| 1227 | WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, |
| 1228 | "Failed to find TMMBR bounding set."); |
| 1229 | return -1; |
| 1230 | } |
| 1231 | // Set bounding set |
| 1232 | // Inform remote clients about the new bandwidth |
| 1233 | // inform the remote client |
| 1234 | _rtpRtcp.SetTMMBN(boundingSet); |
| 1235 | |
| 1236 | // might trigger a TMMBN |
| 1237 | if (numBoundingSet == 0) { |
| 1238 | // owner of max bitrate request has timed out |
| 1239 | // empty bounding set has been sent |
| 1240 | return 0; |
| 1241 | } |
| 1242 | // Get net bitrate from bounding set depending on sent packet rate |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1243 | if (CalcMinBitRate(&bitrate)) { |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1244 | // we have a new bandwidth estimate on this channel |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1245 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 1246 | if (_cbRtcpBandwidthObserver) { |
| 1247 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000); |
| 1248 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
| 1249 | "Set TMMBR request:%d kbps", bitrate); |
| 1250 | } |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 1251 | } |
| 1252 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | // Holding no Critical section |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1256 | void RTCPReceiver::TriggerCallbacksFromRTCPPacket( |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1257 | RTCPPacketInformation& rtcpPacketInformation) { |
| 1258 | // Process TMMBR and REMB first to avoid multiple callbacks |
| 1259 | // to OnNetworkChanged. |
| 1260 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTmmbr) { |
| 1261 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1262 | "SIG [RTCP] Incoming TMMBR to id:%d", _id); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1263 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1264 | // Might trigger a OnReceivedBandwidthEstimateUpdate. |
| 1265 | UpdateTMMBR(); |
| 1266 | } |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1267 | unsigned int local_ssrc = 0; |
| 1268 | { |
| 1269 | // We don't want to hold this critsect when triggering the callbacks below. |
| 1270 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 1271 | local_ssrc = _SSRC; |
| 1272 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1273 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq) { |
| 1274 | _rtpRtcp.OnRequestSendReport(); |
| 1275 | } |
| 1276 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) { |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 1277 | if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1278 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1279 | "SIG [RTCP] Incoming NACK length:%d", |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 1280 | rtcpPacketInformation.nackSequenceNumbers.size()); |
| 1281 | _rtpRtcp.OnReceivedNACK(rtcpPacketInformation.nackSequenceNumbers); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1282 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1283 | } |
| 1284 | { |
| 1285 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
pwestin@webrtc.org | 3aa25de | 2012-01-05 08:40:56 +0000 | [diff] [blame] | 1286 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1287 | // We need feedback that we have received a report block(s) so that we |
| 1288 | // can generate a new packet in a conference relay scenario, one received |
| 1289 | // report can generate several RTCP packets, based on number relayed/mixed |
| 1290 | // a send report block should go out to all receivers. |
| 1291 | if (_cbRtcpIntraFrameObserver) { |
| 1292 | if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) || |
| 1293 | (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpFir)) { |
| 1294 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) { |
| 1295 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1296 | "SIG [RTCP] Incoming PLI from SSRC:0x%x", |
| 1297 | rtcpPacketInformation.remoteSSRC); |
| 1298 | } else { |
| 1299 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1300 | "SIG [RTCP] Incoming FIR from SSRC:0x%x", |
| 1301 | rtcpPacketInformation.remoteSSRC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1302 | } |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1303 | _cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1304 | } |
| 1305 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSli) { |
| 1306 | _cbRtcpIntraFrameObserver->OnReceivedSLI( |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1307 | local_ssrc, rtcpPacketInformation.sliPictureId); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1308 | } |
| 1309 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRpsi) { |
| 1310 | _cbRtcpIntraFrameObserver->OnReceivedRPSI( |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 1311 | local_ssrc, rtcpPacketInformation.rpsiPictureId); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1312 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1313 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1314 | if (_cbRtcpBandwidthObserver) { |
| 1315 | if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb) { |
| 1316 | WEBRTC_TRACE(kTraceStateInfo, kTraceRtpRtcp, _id, |
| 1317 | "SIG [RTCP] Incoming REMB:%d", |
| 1318 | rtcpPacketInformation.receiverEstimatedMaxBitrate); |
| 1319 | _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate( |
| 1320 | rtcpPacketInformation.receiverEstimatedMaxBitrate); |
| 1321 | } |
| 1322 | if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr || |
| 1323 | rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr) && |
| 1324 | rtcpPacketInformation.reportBlock) { |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1325 | int64_t now = _clock->TimeInMilliseconds(); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1326 | _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( |
| 1327 | rtcpPacketInformation.remoteSSRC, |
| 1328 | rtcpPacketInformation.fractionLost, |
| 1329 | rtcpPacketInformation.roundTripTime, |
| 1330 | rtcpPacketInformation.lastReceivedExtendedHighSeqNum, |
| 1331 | now); |
| 1332 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1333 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1334 | if(_cbRtcpFeedback) { |
| 1335 | if(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr) { |
| 1336 | _cbRtcpFeedback->OnSendReportReceived(_id, |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 1337 | rtcpPacketInformation.remoteSSRC, |
| 1338 | rtcpPacketInformation.ntp_secs, |
| 1339 | rtcpPacketInformation.ntp_frac, |
| 1340 | rtcpPacketInformation.rtp_timestamp); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1341 | } else { |
| 1342 | _cbRtcpFeedback->OnReceiveReportReceived(_id, |
| 1343 | rtcpPacketInformation.remoteSSRC); |
| 1344 | } |
| 1345 | if(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpXrVoipMetric) { |
| 1346 | _cbRtcpFeedback->OnXRVoIPMetricReceived(_id, |
| 1347 | rtcpPacketInformation.VoIPMetric); |
| 1348 | } |
| 1349 | if(rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpApp) { |
| 1350 | _cbRtcpFeedback->OnApplicationDataReceived(_id, |
| 1351 | rtcpPacketInformation.applicationSubType, |
| 1352 | rtcpPacketInformation.applicationName, |
| 1353 | rtcpPacketInformation.applicationLength, |
| 1354 | rtcpPacketInformation.applicationData); |
| 1355 | } |
| 1356 | } |
| 1357 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1360 | int32_t RTCPReceiver::CNAME(const uint32_t remoteSSRC, |
| 1361 | char cName[RTCP_CNAME_SIZE]) const { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1362 | assert(cName); |
| 1363 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1364 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 1365 | RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 1366 | if (cnameInfo == NULL) { |
| 1367 | return -1; |
| 1368 | } |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 1369 | cName[RTCP_CNAME_SIZE - 1] = 0; |
| 1370 | strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); |
| 1371 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // no callbacks allowed inside this function |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1375 | int32_t RTCPReceiver::TMMBRReceived(const uint32_t size, |
| 1376 | const uint32_t accNumCandidates, |
| 1377 | TMMBRSet* candidateSet) const { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1378 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1379 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1380 | std::map<uint32_t, RTCPReceiveInformation*>::const_iterator |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1381 | receiveInfoIt = _receivedInfoMap.begin(); |
| 1382 | if (receiveInfoIt == _receivedInfoMap.end()) { |
| 1383 | return -1; |
| 1384 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1385 | uint32_t num = accNumCandidates; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1386 | if (candidateSet) { |
| 1387 | while( num < size && receiveInfoIt != _receivedInfoMap.end()) { |
| 1388 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 1389 | if (receiveInfo == NULL) { |
| 1390 | return 0; |
| 1391 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1392 | for (uint32_t i = 0; |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1393 | (num < size) && (i < receiveInfo->TmmbrSet.lengthOfSet()); i++) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1394 | if (receiveInfo->GetTMMBRSet(i, num, candidateSet, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 1395 | _clock->TimeInMilliseconds()) == 0) { |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1396 | num++; |
| 1397 | } |
| 1398 | } |
| 1399 | receiveInfoIt++; |
| 1400 | } |
| 1401 | } else { |
| 1402 | while (receiveInfoIt != _receivedInfoMap.end()) { |
| 1403 | RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 1404 | if(receiveInfo == NULL) { |
| 1405 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 1406 | "%s failed to get RTCPReceiveInformation", |
| 1407 | __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1408 | return -1; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1409 | } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 1410 | num += receiveInfo->TmmbrSet.lengthOfSet(); |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1411 | receiveInfoIt++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1412 | } |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 1413 | } |
| 1414 | return num; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1417 | int32_t |
| 1418 | RTCPReceiver::SetPacketTimeout(const uint32_t timeoutMS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1419 | { |
| 1420 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 1421 | _packetTimeOutMS = timeoutMS; |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | void RTCPReceiver::PacketTimeout() |
| 1426 | { |
| 1427 | if(_packetTimeOutMS == 0) |
| 1428 | { |
| 1429 | // not configured |
| 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | bool packetTimeOut = false; |
| 1434 | { |
| 1435 | CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
| 1436 | if(_lastReceived == 0) |
| 1437 | { |
| 1438 | // not active |
| 1439 | return; |
| 1440 | } |
| 1441 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 1442 | int64_t now = _clock->TimeInMilliseconds(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1443 | if(now - _lastReceived > _packetTimeOutMS) |
| 1444 | { |
| 1445 | packetTimeOut = true; |
| 1446 | _lastReceived = 0; // only one callback |
| 1447 | } |
| 1448 | } |
| 1449 | CriticalSectionScoped lock(_criticalSectionFeedbacks); |
| 1450 | if(packetTimeOut && _cbRtcpFeedback) |
| 1451 | { |
| 1452 | _cbRtcpFeedback->OnRTCPPacketTimeout(_id); |
| 1453 | } |
| 1454 | } |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 1455 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1456 | } // namespace webrtc |