Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc

Issue 1877253002: Replaced CriticalSectionWrapper with rtc::CriticalSection in rtp_rtcp module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: git cl format dtmf_queue.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 RtcpPacketTypeCounterObserver* packet_type_counter_observer, 42 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
43 RtcpBandwidthObserver* rtcp_bandwidth_observer, 43 RtcpBandwidthObserver* rtcp_bandwidth_observer,
44 RtcpIntraFrameObserver* rtcp_intra_frame_observer, 44 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
45 TransportFeedbackObserver* transport_feedback_observer, 45 TransportFeedbackObserver* transport_feedback_observer,
46 ModuleRtpRtcpImpl* owner) 46 ModuleRtpRtcpImpl* owner)
47 : TMMBRHelp(), 47 : TMMBRHelp(),
48 _clock(clock), 48 _clock(clock),
49 receiver_only_(receiver_only), 49 receiver_only_(receiver_only),
50 _lastReceived(0), 50 _lastReceived(0),
51 _rtpRtcp(*owner), 51 _rtpRtcp(*owner),
52 _criticalSectionFeedbacks(
53 CriticalSectionWrapper::CreateCriticalSection()),
54 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), 52 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer),
55 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), 53 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer),
56 _cbTransportFeedbackObserver(transport_feedback_observer), 54 _cbTransportFeedbackObserver(transport_feedback_observer),
57 _criticalSectionRTCPReceiver(
58 CriticalSectionWrapper::CreateCriticalSection()),
59 main_ssrc_(0), 55 main_ssrc_(0),
60 _remoteSSRC(0), 56 _remoteSSRC(0),
61 _remoteSenderInfo(), 57 _remoteSenderInfo(),
62 _lastReceivedSRNTPsecs(0), 58 _lastReceivedSRNTPsecs(0),
63 _lastReceivedSRNTPfrac(0), 59 _lastReceivedSRNTPfrac(0),
64 _lastReceivedXRNTPsecs(0), 60 _lastReceivedXRNTPsecs(0),
65 _lastReceivedXRNTPfrac(0), 61 _lastReceivedXRNTPfrac(0),
66 xr_rrtr_status_(false), 62 xr_rrtr_status_(false),
67 xr_rr_rtt_ms_(0), 63 xr_rr_rtt_ms_(0),
68 _receivedInfoMap(), 64 _receivedInfoMap(),
69 _lastReceivedRrMs(0), 65 _lastReceivedRrMs(0),
70 _lastIncreasedSequenceNumberMs(0), 66 _lastIncreasedSequenceNumberMs(0),
71 stats_callback_(NULL), 67 stats_callback_(NULL),
72 packet_type_counter_observer_(packet_type_counter_observer), 68 packet_type_counter_observer_(packet_type_counter_observer),
73 num_skipped_packets_(0), 69 num_skipped_packets_(0),
74 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { 70 last_skipped_packets_warning_(clock->TimeInMilliseconds()) {
75 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); 71 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
76 } 72 }
77 73
78 RTCPReceiver::~RTCPReceiver() { 74 RTCPReceiver::~RTCPReceiver() {
79 delete _criticalSectionRTCPReceiver;
80 delete _criticalSectionFeedbacks;
81
82 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); 75 ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
83 for (; it != _receivedReportBlockMap.end(); ++it) { 76 for (; it != _receivedReportBlockMap.end(); ++it) {
84 ReportBlockInfoMap* info_map = &(it->second); 77 ReportBlockInfoMap* info_map = &(it->second);
85 while (!info_map->empty()) { 78 while (!info_map->empty()) {
86 ReportBlockInfoMap::iterator it_info = info_map->begin(); 79 ReportBlockInfoMap::iterator it_info = info_map->begin();
87 delete it_info->second; 80 delete it_info->second;
88 info_map->erase(it_info); 81 info_map->erase(it_info);
89 } 82 }
90 } 83 }
91 while (!_receivedInfoMap.empty()) { 84 while (!_receivedInfoMap.empty()) {
92 std::map<uint32_t, RTCPReceiveInformation*>::iterator first = 85 std::map<uint32_t, RTCPReceiveInformation*>::iterator first =
93 _receivedInfoMap.begin(); 86 _receivedInfoMap.begin();
94 delete first->second; 87 delete first->second;
95 _receivedInfoMap.erase(first); 88 _receivedInfoMap.erase(first);
96 } 89 }
97 while (!_receivedCnameMap.empty()) { 90 while (!_receivedCnameMap.empty()) {
98 std::map<uint32_t, RTCPCnameInformation*>::iterator first = 91 std::map<uint32_t, RTCPCnameInformation*>::iterator first =
99 _receivedCnameMap.begin(); 92 _receivedCnameMap.begin();
100 delete first->second; 93 delete first->second;
101 _receivedCnameMap.erase(first); 94 _receivedCnameMap.erase(first);
102 } 95 }
103 } 96 }
104 97
105 int64_t RTCPReceiver::LastReceived() { 98 int64_t RTCPReceiver::LastReceived() {
106 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 99 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
107 return _lastReceived; 100 return _lastReceived;
108 } 101 }
109 102
110 int64_t RTCPReceiver::LastReceivedReceiverReport() const { 103 int64_t RTCPReceiver::LastReceivedReceiverReport() const {
111 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 104 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
112 int64_t last_received_rr = -1; 105 int64_t last_received_rr = -1;
113 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); 106 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin();
114 it != _receivedInfoMap.end(); ++it) { 107 it != _receivedInfoMap.end(); ++it) {
115 if (it->second->lastTimeReceived > last_received_rr) { 108 if (it->second->lastTimeReceived > last_received_rr) {
116 last_received_rr = it->second->lastTimeReceived; 109 last_received_rr = it->second->lastTimeReceived;
117 } 110 }
118 } 111 }
119 return last_received_rr; 112 return last_received_rr;
120 } 113 }
121 114
122 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { 115 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) {
123 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 116 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
124 117
125 // new SSRC reset old reports 118 // new SSRC reset old reports
126 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); 119 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
127 _lastReceivedSRNTPsecs = 0; 120 _lastReceivedSRNTPsecs = 0;
128 _lastReceivedSRNTPfrac = 0; 121 _lastReceivedSRNTPfrac = 0;
129 122
130 _remoteSSRC = ssrc; 123 _remoteSSRC = ssrc;
131 } 124 }
132 125
133 uint32_t RTCPReceiver::RemoteSSRC() const { 126 uint32_t RTCPReceiver::RemoteSSRC() const {
134 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 127 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
135 return _remoteSSRC; 128 return _remoteSSRC;
136 } 129 }
137 130
138 void RTCPReceiver::SetSsrcs(uint32_t main_ssrc, 131 void RTCPReceiver::SetSsrcs(uint32_t main_ssrc,
139 const std::set<uint32_t>& registered_ssrcs) { 132 const std::set<uint32_t>& registered_ssrcs) {
140 uint32_t old_ssrc = 0; 133 uint32_t old_ssrc = 0;
141 { 134 {
142 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 135 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
143 old_ssrc = main_ssrc_; 136 old_ssrc = main_ssrc_;
144 main_ssrc_ = main_ssrc; 137 main_ssrc_ = main_ssrc;
145 registered_ssrcs_ = registered_ssrcs; 138 registered_ssrcs_ = registered_ssrcs;
146 } 139 }
147 { 140 {
148 if (_cbRtcpIntraFrameObserver && old_ssrc != main_ssrc) { 141 if (_cbRtcpIntraFrameObserver && old_ssrc != main_ssrc) {
149 _cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, main_ssrc); 142 _cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, main_ssrc);
150 } 143 }
151 } 144 }
152 } 145 }
153 146
154 int32_t RTCPReceiver::RTT(uint32_t remoteSSRC, 147 int32_t RTCPReceiver::RTT(uint32_t remoteSSRC,
155 int64_t* RTT, 148 int64_t* RTT,
156 int64_t* avgRTT, 149 int64_t* avgRTT,
157 int64_t* minRTT, 150 int64_t* minRTT,
158 int64_t* maxRTT) const { 151 int64_t* maxRTT) const {
159 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 152 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
160 153
161 RTCPReportBlockInformation* reportBlock = 154 RTCPReportBlockInformation* reportBlock =
162 GetReportBlockInformation(remoteSSRC, main_ssrc_); 155 GetReportBlockInformation(remoteSSRC, main_ssrc_);
163 156
164 if (reportBlock == NULL) { 157 if (reportBlock == NULL) {
165 return -1; 158 return -1;
166 } 159 }
167 if (RTT) { 160 if (RTT) {
168 *RTT = reportBlock->RTT; 161 *RTT = reportBlock->RTT;
169 } 162 }
170 if (avgRTT) { 163 if (avgRTT) {
171 *avgRTT = reportBlock->avgRTT; 164 *avgRTT = reportBlock->avgRTT;
172 } 165 }
173 if (minRTT) { 166 if (minRTT) {
174 *minRTT = reportBlock->minRTT; 167 *minRTT = reportBlock->minRTT;
175 } 168 }
176 if (maxRTT) { 169 if (maxRTT) {
177 *maxRTT = reportBlock->maxRTT; 170 *maxRTT = reportBlock->maxRTT;
178 } 171 }
179 return 0; 172 return 0;
180 } 173 }
181 174
182 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) { 175 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) {
183 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 176 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
184 xr_rrtr_status_ = enable; 177 xr_rrtr_status_ = enable;
185 } 178 }
186 179
187 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { 180 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) {
188 assert(rtt_ms); 181 assert(rtt_ms);
189 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 182 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
190 if (xr_rr_rtt_ms_ == 0) { 183 if (xr_rr_rtt_ms_ == 0) {
191 return false; 184 return false;
192 } 185 }
193 *rtt_ms = xr_rr_rtt_ms_; 186 *rtt_ms = xr_rr_rtt_ms_;
194 xr_rr_rtt_ms_ = 0; 187 xr_rr_rtt_ms_ = 0;
195 return true; 188 return true;
196 } 189 }
197 190
198 // TODO(pbos): Make this fail when we haven't received NTP. 191 // TODO(pbos): Make this fail when we haven't received NTP.
199 bool RTCPReceiver::NTP(uint32_t* ReceivedNTPsecs, 192 bool RTCPReceiver::NTP(uint32_t* ReceivedNTPsecs,
200 uint32_t* ReceivedNTPfrac, 193 uint32_t* ReceivedNTPfrac,
201 uint32_t* RTCPArrivalTimeSecs, 194 uint32_t* RTCPArrivalTimeSecs,
202 uint32_t* RTCPArrivalTimeFrac, 195 uint32_t* RTCPArrivalTimeFrac,
203 uint32_t* rtcp_timestamp) const 196 uint32_t* rtcp_timestamp) const
204 { 197 {
205 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 198 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
206 if(ReceivedNTPsecs) 199 if(ReceivedNTPsecs)
207 { 200 {
208 *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; // NTP from incoming Se ndReport 201 *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; // NTP from incoming Se ndReport
209 } 202 }
210 if(ReceivedNTPfrac) 203 if(ReceivedNTPfrac)
211 { 204 {
212 *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction; 205 *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction;
213 } 206 }
214 if(RTCPArrivalTimeFrac) 207 if(RTCPArrivalTimeFrac)
215 { 208 {
216 *RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we received a RTCP packet with a send block 209 *RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we received a RTCP packet with a send block
217 } 210 }
218 if(RTCPArrivalTimeSecs) 211 if(RTCPArrivalTimeSecs)
219 { 212 {
220 *RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs; 213 *RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs;
221 } 214 }
222 if (rtcp_timestamp) { 215 if (rtcp_timestamp) {
223 *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp; 216 *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp;
224 } 217 }
225 return true; 218 return true;
226 } 219 }
227 220
228 bool RTCPReceiver::LastReceivedXrReferenceTimeInfo( 221 bool RTCPReceiver::LastReceivedXrReferenceTimeInfo(
229 RtcpReceiveTimeInfo* info) const { 222 RtcpReceiveTimeInfo* info) const {
230 assert(info); 223 assert(info);
231 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 224 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
232 if (_lastReceivedXRNTPsecs == 0 && _lastReceivedXRNTPfrac == 0) { 225 if (_lastReceivedXRNTPsecs == 0 && _lastReceivedXRNTPfrac == 0) {
233 return false; 226 return false;
234 } 227 }
235 228
236 info->sourceSSRC = _remoteXRReceiveTimeInfo.sourceSSRC; 229 info->sourceSSRC = _remoteXRReceiveTimeInfo.sourceSSRC;
237 info->lastRR = _remoteXRReceiveTimeInfo.lastRR; 230 info->lastRR = _remoteXRReceiveTimeInfo.lastRR;
238 231
239 // Get the delay since last received report (RFC 3611). 232 // Get the delay since last received report (RFC 3611).
240 uint32_t receive_time = RTCPUtility::MidNtp(_lastReceivedXRNTPsecs, 233 uint32_t receive_time = RTCPUtility::MidNtp(_lastReceivedXRNTPsecs,
241 _lastReceivedXRNTPfrac); 234 _lastReceivedXRNTPfrac);
242 235
243 uint32_t ntp_sec = 0; 236 uint32_t ntp_sec = 0;
244 uint32_t ntp_frac = 0; 237 uint32_t ntp_frac = 0;
245 _clock->CurrentNtp(ntp_sec, ntp_frac); 238 _clock->CurrentNtp(ntp_sec, ntp_frac);
246 uint32_t now = RTCPUtility::MidNtp(ntp_sec, ntp_frac); 239 uint32_t now = RTCPUtility::MidNtp(ntp_sec, ntp_frac);
247 240
248 info->delaySinceLastRR = now - receive_time; 241 info->delaySinceLastRR = now - receive_time;
249 return true; 242 return true;
250 } 243 }
251 244
252 int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const { 245 int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const {
253 assert(senderInfo); 246 assert(senderInfo);
254 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 247 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
255 if (_lastReceivedSRNTPsecs == 0) { 248 if (_lastReceivedSRNTPsecs == 0) {
256 return -1; 249 return -1;
257 } 250 }
258 memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo)); 251 memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo));
259 return 0; 252 return 0;
260 } 253 }
261 254
262 // statistics 255 // statistics
263 // we can get multiple receive reports when we receive the report from a CE 256 // we can get multiple receive reports when we receive the report from a CE
264 int32_t RTCPReceiver::StatisticsReceived( 257 int32_t RTCPReceiver::StatisticsReceived(
265 std::vector<RTCPReportBlock>* receiveBlocks) const { 258 std::vector<RTCPReportBlock>* receiveBlocks) const {
266 assert(receiveBlocks); 259 assert(receiveBlocks);
267 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 260 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
268 ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin(); 261 ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin();
269 for (; it != _receivedReportBlockMap.end(); ++it) { 262 for (; it != _receivedReportBlockMap.end(); ++it) {
270 const ReportBlockInfoMap* info_map = &(it->second); 263 const ReportBlockInfoMap* info_map = &(it->second);
271 ReportBlockInfoMap::const_iterator it_info = info_map->begin(); 264 ReportBlockInfoMap::const_iterator it_info = info_map->begin();
272 for (; it_info != info_map->end(); ++it_info) { 265 for (; it_info != info_map->end(); ++it_info) {
273 receiveBlocks->push_back(it_info->second->remoteReceiveBlock); 266 receiveBlocks->push_back(it_info->second->remoteReceiveBlock);
274 } 267 }
275 } 268 }
276 return 0; 269 return 0;
277 } 270 }
278 271
279 int32_t 272 int32_t
280 RTCPReceiver::IncomingRTCPPacket(RTCPPacketInformation& rtcpPacketInformation, 273 RTCPReceiver::IncomingRTCPPacket(RTCPPacketInformation& rtcpPacketInformation,
281 RTCPUtility::RTCPParserV2* rtcpParser) 274 RTCPUtility::RTCPParserV2* rtcpParser)
282 { 275 {
283 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 276 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
284 277
285 _lastReceived = _clock->TimeInMilliseconds(); 278 _lastReceived = _clock->TimeInMilliseconds();
286 279
287 if (packet_type_counter_.first_packet_time_ms == -1) { 280 if (packet_type_counter_.first_packet_time_ms == -1) {
288 packet_type_counter_.first_packet_time_ms = _lastReceived; 281 packet_type_counter_.first_packet_time_ms = _lastReceived;
289 } 282 }
290 283
291 RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin(); 284 RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin();
292 while (pktType != RTCPPacketTypes::kInvalid) { 285 while (pktType != RTCPPacketTypes::kInvalid) {
293 // Each "case" is responsible for iterate the parser to the 286 // Each "case" is responsible for iterate the parser to the
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 const ReportBlockInfoMap* info_map = &(it->second); 576 const ReportBlockInfoMap* info_map = &(it->second);
584 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc); 577 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc);
585 if (it_info == info_map->end()) { 578 if (it_info == info_map->end()) {
586 return NULL; 579 return NULL;
587 } 580 }
588 return it_info->second; 581 return it_info->second;
589 } 582 }
590 583
591 RTCPCnameInformation* 584 RTCPCnameInformation*
592 RTCPReceiver::CreateCnameInformation(uint32_t remoteSSRC) { 585 RTCPReceiver::CreateCnameInformation(uint32_t remoteSSRC) {
593 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 586 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
594 587
595 std::map<uint32_t, RTCPCnameInformation*>::iterator it = 588 std::map<uint32_t, RTCPCnameInformation*>::iterator it =
596 _receivedCnameMap.find(remoteSSRC); 589 _receivedCnameMap.find(remoteSSRC);
597 590
598 if (it != _receivedCnameMap.end()) { 591 if (it != _receivedCnameMap.end()) {
599 return it->second; 592 return it->second;
600 } 593 }
601 RTCPCnameInformation* cnameInfo = new RTCPCnameInformation; 594 RTCPCnameInformation* cnameInfo = new RTCPCnameInformation;
602 memset(cnameInfo->name, 0, RTCP_CNAME_SIZE); 595 memset(cnameInfo->name, 0, RTCP_CNAME_SIZE);
603 _receivedCnameMap[remoteSSRC] = cnameInfo; 596 _receivedCnameMap[remoteSSRC] = cnameInfo;
604 return cnameInfo; 597 return cnameInfo;
605 } 598 }
606 599
607 RTCPCnameInformation* 600 RTCPCnameInformation*
608 RTCPReceiver::GetCnameInformation(uint32_t remoteSSRC) const { 601 RTCPReceiver::GetCnameInformation(uint32_t remoteSSRC) const {
609 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 602 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
610 603
611 std::map<uint32_t, RTCPCnameInformation*>::const_iterator it = 604 std::map<uint32_t, RTCPCnameInformation*>::const_iterator it =
612 _receivedCnameMap.find(remoteSSRC); 605 _receivedCnameMap.find(remoteSSRC);
613 606
614 if (it == _receivedCnameMap.end()) { 607 if (it == _receivedCnameMap.end()) {
615 return NULL; 608 return NULL;
616 } 609 }
617 return it->second; 610 return it->second;
618 } 611 }
619 612
620 RTCPReceiveInformation* 613 RTCPReceiveInformation*
621 RTCPReceiver::CreateReceiveInformation(uint32_t remoteSSRC) { 614 RTCPReceiver::CreateReceiveInformation(uint32_t remoteSSRC) {
622 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 615 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
623 616
624 std::map<uint32_t, RTCPReceiveInformation*>::iterator it = 617 std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
625 _receivedInfoMap.find(remoteSSRC); 618 _receivedInfoMap.find(remoteSSRC);
626 619
627 if (it != _receivedInfoMap.end()) { 620 if (it != _receivedInfoMap.end()) {
628 return it->second; 621 return it->second;
629 } 622 }
630 RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation; 623 RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation;
631 _receivedInfoMap[remoteSSRC] = receiveInfo; 624 _receivedInfoMap[remoteSSRC] = receiveInfo;
632 return receiveInfo; 625 return receiveInfo;
633 } 626 }
634 627
635 RTCPReceiveInformation* 628 RTCPReceiveInformation*
636 RTCPReceiver::GetReceiveInformation(uint32_t remoteSSRC) { 629 RTCPReceiver::GetReceiveInformation(uint32_t remoteSSRC) {
637 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 630 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
638 631
639 std::map<uint32_t, RTCPReceiveInformation*>::iterator it = 632 std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
640 _receivedInfoMap.find(remoteSSRC); 633 _receivedInfoMap.find(remoteSSRC);
641 if (it == _receivedInfoMap.end()) { 634 if (it == _receivedInfoMap.end()) {
642 return NULL; 635 return NULL;
643 } 636 }
644 return it->second; 637 return it->second;
645 } 638 }
646 639
647 void RTCPReceiver::UpdateReceiveInformation( 640 void RTCPReceiver::UpdateReceiveInformation(
648 RTCPReceiveInformation& receiveInformation) { 641 RTCPReceiveInformation& receiveInformation) {
649 // Update that this remote is alive 642 // Update that this remote is alive
650 receiveInformation.lastTimeReceived = _clock->TimeInMilliseconds(); 643 receiveInformation.lastTimeReceived = _clock->TimeInMilliseconds();
651 } 644 }
652 645
653 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { 646 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) {
654 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 647 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
655 if (_lastReceivedRrMs == 0) 648 if (_lastReceivedRrMs == 0)
656 return false; 649 return false;
657 650
658 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; 651 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms;
659 if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { 652 if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) {
660 // Reset the timer to only trigger one log. 653 // Reset the timer to only trigger one log.
661 _lastReceivedRrMs = 0; 654 _lastReceivedRrMs = 0;
662 return true; 655 return true;
663 } 656 }
664 return false; 657 return false;
665 } 658 }
666 659
667 bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) { 660 bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) {
668 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 661 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
669 if (_lastIncreasedSequenceNumberMs == 0) 662 if (_lastIncreasedSequenceNumberMs == 0)
670 return false; 663 return false;
671 664
672 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; 665 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms;
673 if (_clock->TimeInMilliseconds() > _lastIncreasedSequenceNumberMs + 666 if (_clock->TimeInMilliseconds() > _lastIncreasedSequenceNumberMs +
674 time_out_ms) { 667 time_out_ms) {
675 // Reset the timer to only trigger one log. 668 // Reset the timer to only trigger one log.
676 _lastIncreasedSequenceNumberMs = 0; 669 _lastIncreasedSequenceNumberMs = 0;
677 return true; 670 return true;
678 } 671 }
679 return false; 672 return false;
680 } 673 }
681 674
682 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { 675 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() {
683 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 676 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
684 677
685 bool updateBoundingSet = false; 678 bool updateBoundingSet = false;
686 int64_t timeNow = _clock->TimeInMilliseconds(); 679 int64_t timeNow = _clock->TimeInMilliseconds();
687 680
688 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = 681 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
689 _receivedInfoMap.begin(); 682 _receivedInfoMap.begin();
690 683
691 while (receiveInfoIt != _receivedInfoMap.end()) { 684 while (receiveInfoIt != _receivedInfoMap.end()) {
692 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; 685 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
693 if (receiveInfo == NULL) { 686 if (receiveInfo == NULL) {
(...skipping 23 matching lines...) Expand all
717 delete receiveInfoItemToBeErased->second; 710 delete receiveInfoItemToBeErased->second;
718 _receivedInfoMap.erase(receiveInfoItemToBeErased); 711 _receivedInfoMap.erase(receiveInfoItemToBeErased);
719 } else { 712 } else {
720 receiveInfoIt++; 713 receiveInfoIt++;
721 } 714 }
722 } 715 }
723 return updateBoundingSet; 716 return updateBoundingSet;
724 } 717 }
725 718
726 int32_t RTCPReceiver::BoundingSet(bool* tmmbrOwner, TMMBRSet* boundingSetRec) { 719 int32_t RTCPReceiver::BoundingSet(bool* tmmbrOwner, TMMBRSet* boundingSetRec) {
727 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 720 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
728 721
729 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = 722 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
730 _receivedInfoMap.find(_remoteSSRC); 723 _receivedInfoMap.find(_remoteSSRC);
731 724
732 if (receiveInfoIt == _receivedInfoMap.end()) { 725 if (receiveInfoIt == _receivedInfoMap.end()) {
733 return -1; 726 return -1;
734 } 727 }
735 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; 728 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
736 if (receiveInfo == NULL) { 729 if (receiveInfo == NULL) {
737 return -1; 730 return -1;
(...skipping 28 matching lines...) Expand all
766 759
767 void RTCPReceiver::HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser) { 760 void RTCPReceiver::HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser) {
768 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 761 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
769 RTCPCnameInformation* cnameInfo = 762 RTCPCnameInformation* cnameInfo =
770 CreateCnameInformation(rtcpPacket.CName.SenderSSRC); 763 CreateCnameInformation(rtcpPacket.CName.SenderSSRC);
771 assert(cnameInfo); 764 assert(cnameInfo);
772 765
773 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; 766 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0;
774 strncpy(cnameInfo->name, rtcpPacket.CName.CName, RTCP_CNAME_SIZE - 1); 767 strncpy(cnameInfo->name, rtcpPacket.CName.CName, RTCP_CNAME_SIZE - 1);
775 { 768 {
776 CriticalSectionScoped lock(_criticalSectionFeedbacks); 769 rtc::CritScope lock(&_criticalSectionFeedbacks);
777 if (stats_callback_ != NULL) { 770 if (stats_callback_ != NULL) {
778 stats_callback_->CNameChanged(rtcpPacket.CName.CName, 771 stats_callback_->CNameChanged(rtcpPacket.CName.CName,
779 rtcpPacket.CName.SenderSSRC); 772 rtcpPacket.CName.SenderSSRC);
780 } 773 }
781 } 774 }
782 } 775 }
783 776
784 void RTCPReceiver::HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser, 777 void RTCPReceiver::HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
785 RTCPPacketInformation& rtcpPacketInformation) { 778 RTCPPacketInformation& rtcpPacketInformation) {
786 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 779 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 // we have a new bandwidth estimate on this channel 1269 // we have a new bandwidth estimate on this channel
1277 if (_cbRtcpBandwidthObserver) { 1270 if (_cbRtcpBandwidthObserver) {
1278 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000); 1271 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000);
1279 } 1272 }
1280 } 1273 }
1281 return 0; 1274 return 0;
1282 } 1275 }
1283 1276
1284 void RTCPReceiver::RegisterRtcpStatisticsCallback( 1277 void RTCPReceiver::RegisterRtcpStatisticsCallback(
1285 RtcpStatisticsCallback* callback) { 1278 RtcpStatisticsCallback* callback) {
1286 CriticalSectionScoped cs(_criticalSectionFeedbacks); 1279 rtc::CritScope cs(&_criticalSectionFeedbacks);
1287 stats_callback_ = callback; 1280 stats_callback_ = callback;
1288 } 1281 }
1289 1282
1290 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { 1283 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() {
1291 CriticalSectionScoped cs(_criticalSectionFeedbacks); 1284 rtc::CritScope cs(&_criticalSectionFeedbacks);
1292 return stats_callback_; 1285 return stats_callback_;
1293 } 1286 }
1294 1287
1295 // Holding no Critical section 1288 // Holding no Critical section
1296 void RTCPReceiver::TriggerCallbacksFromRTCPPacket( 1289 void RTCPReceiver::TriggerCallbacksFromRTCPPacket(
1297 RTCPPacketInformation& rtcpPacketInformation) { 1290 RTCPPacketInformation& rtcpPacketInformation) {
1298 // Process TMMBR and REMB first to avoid multiple callbacks 1291 // Process TMMBR and REMB first to avoid multiple callbacks
1299 // to OnNetworkChanged. 1292 // to OnNetworkChanged.
1300 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTmmbr) { 1293 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTmmbr) {
1301 // Might trigger a OnReceivedBandwidthEstimateUpdate. 1294 // Might trigger a OnReceivedBandwidthEstimateUpdate.
1302 UpdateTMMBR(); 1295 UpdateTMMBR();
1303 } 1296 }
1304 uint32_t local_ssrc; 1297 uint32_t local_ssrc;
1305 std::set<uint32_t> registered_ssrcs; 1298 std::set<uint32_t> registered_ssrcs;
1306 { 1299 {
1307 // We don't want to hold this critsect when triggering the callbacks below. 1300 // We don't want to hold this critsect when triggering the callbacks below.
1308 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 1301 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1309 local_ssrc = main_ssrc_; 1302 local_ssrc = main_ssrc_;
1310 registered_ssrcs = registered_ssrcs_; 1303 registered_ssrcs = registered_ssrcs_;
1311 } 1304 }
1312 if (!receiver_only_ && 1305 if (!receiver_only_ &&
1313 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq)) { 1306 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq)) {
1314 _rtpRtcp.OnRequestSendReport(); 1307 _rtpRtcp.OnRequestSendReport();
1315 } 1308 }
1316 if (!receiver_only_ && 1309 if (!receiver_only_ &&
1317 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack)) { 1310 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack)) {
1318 if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { 1311 if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 rtcpPacketInformation.transport_feedback_->GetMediaSourceSsrc(); 1364 rtcpPacketInformation.transport_feedback_->GetMediaSourceSsrc();
1372 if (media_source_ssrc == local_ssrc || 1365 if (media_source_ssrc == local_ssrc ||
1373 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { 1366 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) {
1374 _cbTransportFeedbackObserver->OnTransportFeedback( 1367 _cbTransportFeedbackObserver->OnTransportFeedback(
1375 *rtcpPacketInformation.transport_feedback_.get()); 1368 *rtcpPacketInformation.transport_feedback_.get());
1376 } 1369 }
1377 } 1370 }
1378 } 1371 }
1379 1372
1380 if (!receiver_only_) { 1373 if (!receiver_only_) {
1381 CriticalSectionScoped cs(_criticalSectionFeedbacks); 1374 rtc::CritScope cs(&_criticalSectionFeedbacks);
1382 if (stats_callback_) { 1375 if (stats_callback_) {
1383 for (ReportBlockList::const_iterator it = 1376 for (ReportBlockList::const_iterator it =
1384 rtcpPacketInformation.report_blocks.begin(); 1377 rtcpPacketInformation.report_blocks.begin();
1385 it != rtcpPacketInformation.report_blocks.end(); 1378 it != rtcpPacketInformation.report_blocks.end();
1386 ++it) { 1379 ++it) {
1387 RtcpStatistics stats; 1380 RtcpStatistics stats;
1388 stats.cumulative_lost = it->cumulativeLost; 1381 stats.cumulative_lost = it->cumulativeLost;
1389 stats.extended_max_sequence_number = it->extendedHighSeqNum; 1382 stats.extended_max_sequence_number = it->extendedHighSeqNum;
1390 stats.fraction_lost = it->fractionLost; 1383 stats.fraction_lost = it->fractionLost;
1391 stats.jitter = it->jitter; 1384 stats.jitter = it->jitter;
1392 1385
1393 stats_callback_->StatisticsUpdated(stats, it->sourceSSRC); 1386 stats_callback_->StatisticsUpdated(stats, it->sourceSSRC);
1394 } 1387 }
1395 } 1388 }
1396 } 1389 }
1397 } 1390 }
1398 1391
1399 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, 1392 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC,
1400 char cName[RTCP_CNAME_SIZE]) const { 1393 char cName[RTCP_CNAME_SIZE]) const {
1401 assert(cName); 1394 assert(cName);
1402 1395
1403 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 1396 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1404 RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); 1397 RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC);
1405 if (cnameInfo == NULL) { 1398 if (cnameInfo == NULL) {
1406 return -1; 1399 return -1;
1407 } 1400 }
1408 cName[RTCP_CNAME_SIZE - 1] = 0; 1401 cName[RTCP_CNAME_SIZE - 1] = 0;
1409 strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); 1402 strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1);
1410 return 0; 1403 return 0;
1411 } 1404 }
1412 1405
1413 // no callbacks allowed inside this function 1406 // no callbacks allowed inside this function
1414 int32_t RTCPReceiver::TMMBRReceived(uint32_t size, 1407 int32_t RTCPReceiver::TMMBRReceived(uint32_t size,
1415 uint32_t accNumCandidates, 1408 uint32_t accNumCandidates,
1416 TMMBRSet* candidateSet) const { 1409 TMMBRSet* candidateSet) const {
1417 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); 1410 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1418 1411
1419 std::map<uint32_t, RTCPReceiveInformation*>::const_iterator 1412 std::map<uint32_t, RTCPReceiveInformation*>::const_iterator
1420 receiveInfoIt = _receivedInfoMap.begin(); 1413 receiveInfoIt = _receivedInfoMap.begin();
1421 if (receiveInfoIt == _receivedInfoMap.end()) { 1414 if (receiveInfoIt == _receivedInfoMap.end()) {
1422 return -1; 1415 return -1;
1423 } 1416 }
1424 uint32_t num = accNumCandidates; 1417 uint32_t num = accNumCandidates;
1425 if (candidateSet) { 1418 if (candidateSet) {
1426 while( num < size && receiveInfoIt != _receivedInfoMap.end()) { 1419 while( num < size && receiveInfoIt != _receivedInfoMap.end()) {
1427 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; 1420 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
(...skipping 16 matching lines...) Expand all
1444 return -1; 1437 return -1;
1445 } 1438 }
1446 num += receiveInfo->TmmbrSet.lengthOfSet(); 1439 num += receiveInfo->TmmbrSet.lengthOfSet();
1447 receiveInfoIt++; 1440 receiveInfoIt++;
1448 } 1441 }
1449 } 1442 }
1450 return num; 1443 return num;
1451 } 1444 }
1452 1445
1453 } // namespace webrtc 1446 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698