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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 RtpReceiverImpl::RtpReceiverImpl( 55 RtpReceiverImpl::RtpReceiverImpl(
56 Clock* clock, 56 Clock* clock,
57 RtpFeedback* incoming_messages_callback, 57 RtpFeedback* incoming_messages_callback,
58 RTPPayloadRegistry* rtp_payload_registry, 58 RTPPayloadRegistry* rtp_payload_registry,
59 RTPReceiverStrategy* rtp_media_receiver) 59 RTPReceiverStrategy* rtp_media_receiver)
60 : clock_(clock), 60 : clock_(clock),
61 rtp_payload_registry_(rtp_payload_registry), 61 rtp_payload_registry_(rtp_payload_registry),
62 rtp_media_receiver_(rtp_media_receiver), 62 rtp_media_receiver_(rtp_media_receiver),
63 cb_rtp_feedback_(incoming_messages_callback), 63 cb_rtp_feedback_(incoming_messages_callback),
64 critical_section_rtp_receiver_(
65 CriticalSectionWrapper::CreateCriticalSection()),
66 last_receive_time_(0), 64 last_receive_time_(0),
67 last_received_payload_length_(0), 65 last_received_payload_length_(0),
68 ssrc_(0), 66 ssrc_(0),
69 num_csrcs_(0), 67 num_csrcs_(0),
70 current_remote_csrc_(), 68 current_remote_csrc_(),
71 last_received_timestamp_(0), 69 last_received_timestamp_(0),
72 last_received_frame_time_ms_(-1), 70 last_received_frame_time_ms_(-1),
73 last_received_sequence_number_(0), 71 last_received_sequence_number_(0),
74 nack_method_(kNackOff) { 72 nack_method_(kNackOff) {
75 assert(incoming_messages_callback); 73 assert(incoming_messages_callback);
76 74
77 memset(current_remote_csrc_, 0, sizeof(current_remote_csrc_)); 75 memset(current_remote_csrc_, 0, sizeof(current_remote_csrc_));
78 } 76 }
79 77
80 RtpReceiverImpl::~RtpReceiverImpl() { 78 RtpReceiverImpl::~RtpReceiverImpl() {
81 for (int i = 0; i < num_csrcs_; ++i) { 79 for (int i = 0; i < num_csrcs_; ++i) {
82 cb_rtp_feedback_->OnIncomingCSRCChanged(current_remote_csrc_[i], false); 80 cb_rtp_feedback_->OnIncomingCSRCChanged(current_remote_csrc_[i], false);
83 } 81 }
84 } 82 }
85 83
86 int32_t RtpReceiverImpl::RegisterReceivePayload( 84 int32_t RtpReceiverImpl::RegisterReceivePayload(
87 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 85 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
88 const int8_t payload_type, 86 const int8_t payload_type,
89 const uint32_t frequency, 87 const uint32_t frequency,
90 const size_t channels, 88 const size_t channels,
91 const uint32_t rate) { 89 const uint32_t rate) {
92 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 90 rtc::CritScope lock(&critical_section_rtp_receiver_);
93 91
94 // TODO(phoglund): Try to streamline handling of the RED codec and some other 92 // TODO(phoglund): Try to streamline handling of the RED codec and some other
95 // cases which makes it necessary to keep track of whether we created a 93 // cases which makes it necessary to keep track of whether we created a
96 // payload or not. 94 // payload or not.
97 bool created_new_payload = false; 95 bool created_new_payload = false;
98 int32_t result = rtp_payload_registry_->RegisterReceivePayload( 96 int32_t result = rtp_payload_registry_->RegisterReceivePayload(
99 payload_name, payload_type, frequency, channels, rate, 97 payload_name, payload_type, frequency, channels, rate,
100 &created_new_payload); 98 &created_new_payload);
101 if (created_new_payload) { 99 if (created_new_payload) {
102 if (rtp_media_receiver_->OnNewPayloadTypeCreated(payload_name, payload_type, 100 if (rtp_media_receiver_->OnNewPayloadTypeCreated(payload_name, payload_type,
103 frequency) != 0) { 101 frequency) != 0) {
104 LOG(LS_ERROR) << "Failed to register payload: " << payload_name << "/" 102 LOG(LS_ERROR) << "Failed to register payload: " << payload_name << "/"
105 << static_cast<int>(payload_type); 103 << static_cast<int>(payload_type);
106 return -1; 104 return -1;
107 } 105 }
108 } 106 }
109 return result; 107 return result;
110 } 108 }
111 109
112 int32_t RtpReceiverImpl::DeRegisterReceivePayload( 110 int32_t RtpReceiverImpl::DeRegisterReceivePayload(
113 const int8_t payload_type) { 111 const int8_t payload_type) {
114 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 112 rtc::CritScope lock(&critical_section_rtp_receiver_);
115 return rtp_payload_registry_->DeRegisterReceivePayload(payload_type); 113 return rtp_payload_registry_->DeRegisterReceivePayload(payload_type);
116 } 114 }
117 115
118 NACKMethod RtpReceiverImpl::NACK() const { 116 NACKMethod RtpReceiverImpl::NACK() const {
119 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 117 rtc::CritScope lock(&critical_section_rtp_receiver_);
120 return nack_method_; 118 return nack_method_;
121 } 119 }
122 120
123 // Turn negative acknowledgment requests on/off. 121 // Turn negative acknowledgment requests on/off.
124 void RtpReceiverImpl::SetNACKStatus(const NACKMethod method) { 122 void RtpReceiverImpl::SetNACKStatus(const NACKMethod method) {
125 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 123 rtc::CritScope lock(&critical_section_rtp_receiver_);
126 nack_method_ = method; 124 nack_method_ = method;
127 } 125 }
128 126
129 uint32_t RtpReceiverImpl::SSRC() const { 127 uint32_t RtpReceiverImpl::SSRC() const {
130 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 128 rtc::CritScope lock(&critical_section_rtp_receiver_);
131 return ssrc_; 129 return ssrc_;
132 } 130 }
133 131
134 // Get remote CSRC. 132 // Get remote CSRC.
135 int32_t RtpReceiverImpl::CSRCs(uint32_t array_of_csrcs[kRtpCsrcSize]) const { 133 int32_t RtpReceiverImpl::CSRCs(uint32_t array_of_csrcs[kRtpCsrcSize]) const {
136 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 134 rtc::CritScope lock(&critical_section_rtp_receiver_);
137 135
138 assert(num_csrcs_ <= kRtpCsrcSize); 136 assert(num_csrcs_ <= kRtpCsrcSize);
139 137
140 if (num_csrcs_ > 0) { 138 if (num_csrcs_ > 0) {
141 memcpy(array_of_csrcs, current_remote_csrc_, sizeof(uint32_t)*num_csrcs_); 139 memcpy(array_of_csrcs, current_remote_csrc_, sizeof(uint32_t)*num_csrcs_);
142 } 140 }
143 return num_csrcs_; 141 return num_csrcs_;
144 } 142 }
145 143
146 int32_t RtpReceiverImpl::Energy( 144 int32_t RtpReceiverImpl::Energy(
(...skipping 25 matching lines...) Expand all
172 170
173 WebRtcRTPHeader webrtc_rtp_header; 171 WebRtcRTPHeader webrtc_rtp_header;
174 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header)); 172 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header));
175 webrtc_rtp_header.header = rtp_header; 173 webrtc_rtp_header.header = rtp_header;
176 CheckCSRC(webrtc_rtp_header); 174 CheckCSRC(webrtc_rtp_header);
177 175
178 size_t payload_data_length = payload_length - rtp_header.paddingLength; 176 size_t payload_data_length = payload_length - rtp_header.paddingLength;
179 177
180 bool is_first_packet_in_frame = false; 178 bool is_first_packet_in_frame = false;
181 { 179 {
182 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 180 rtc::CritScope lock(&critical_section_rtp_receiver_);
183 if (HaveReceivedFrame()) { 181 if (HaveReceivedFrame()) {
184 is_first_packet_in_frame = 182 is_first_packet_in_frame =
185 last_received_sequence_number_ + 1 == rtp_header.sequenceNumber && 183 last_received_sequence_number_ + 1 == rtp_header.sequenceNumber &&
186 last_received_timestamp_ != rtp_header.timestamp; 184 last_received_timestamp_ != rtp_header.timestamp;
187 } else { 185 } else {
188 is_first_packet_in_frame = true; 186 is_first_packet_in_frame = true;
189 } 187 }
190 } 188 }
191 189
192 int32_t ret_val = rtp_media_receiver_->ParseRtpPacket( 190 int32_t ret_val = rtp_media_receiver_->ParseRtpPacket(
193 &webrtc_rtp_header, payload_specific, is_red, payload, payload_length, 191 &webrtc_rtp_header, payload_specific, is_red, payload, payload_length,
194 clock_->TimeInMilliseconds(), is_first_packet_in_frame); 192 clock_->TimeInMilliseconds(), is_first_packet_in_frame);
195 193
196 if (ret_val < 0) { 194 if (ret_val < 0) {
197 return false; 195 return false;
198 } 196 }
199 197
200 { 198 {
201 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 199 rtc::CritScope lock(&critical_section_rtp_receiver_);
202 200
203 last_receive_time_ = clock_->TimeInMilliseconds(); 201 last_receive_time_ = clock_->TimeInMilliseconds();
204 last_received_payload_length_ = payload_data_length; 202 last_received_payload_length_ = payload_data_length;
205 203
206 if (in_order) { 204 if (in_order) {
207 if (last_received_timestamp_ != rtp_header.timestamp) { 205 if (last_received_timestamp_ != rtp_header.timestamp) {
208 last_received_timestamp_ = rtp_header.timestamp; 206 last_received_timestamp_ = rtp_header.timestamp;
209 last_received_frame_time_ms_ = clock_->TimeInMilliseconds(); 207 last_received_frame_time_ms_ = clock_->TimeInMilliseconds();
210 } 208 }
211 last_received_sequence_number_ = rtp_header.sequenceNumber; 209 last_received_sequence_number_ = rtp_header.sequenceNumber;
212 } 210 }
213 } 211 }
214 return true; 212 return true;
215 } 213 }
216 214
217 TelephoneEventHandler* RtpReceiverImpl::GetTelephoneEventHandler() { 215 TelephoneEventHandler* RtpReceiverImpl::GetTelephoneEventHandler() {
218 return rtp_media_receiver_->GetTelephoneEventHandler(); 216 return rtp_media_receiver_->GetTelephoneEventHandler();
219 } 217 }
220 218
221 bool RtpReceiverImpl::Timestamp(uint32_t* timestamp) const { 219 bool RtpReceiverImpl::Timestamp(uint32_t* timestamp) const {
222 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 220 rtc::CritScope lock(&critical_section_rtp_receiver_);
223 if (!HaveReceivedFrame()) 221 if (!HaveReceivedFrame())
224 return false; 222 return false;
225 *timestamp = last_received_timestamp_; 223 *timestamp = last_received_timestamp_;
226 return true; 224 return true;
227 } 225 }
228 226
229 bool RtpReceiverImpl::LastReceivedTimeMs(int64_t* receive_time_ms) const { 227 bool RtpReceiverImpl::LastReceivedTimeMs(int64_t* receive_time_ms) const {
230 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 228 rtc::CritScope lock(&critical_section_rtp_receiver_);
231 if (!HaveReceivedFrame()) 229 if (!HaveReceivedFrame())
232 return false; 230 return false;
233 *receive_time_ms = last_received_frame_time_ms_; 231 *receive_time_ms = last_received_frame_time_ms_;
234 return true; 232 return true;
235 } 233 }
236 234
237 bool RtpReceiverImpl::HaveReceivedFrame() const { 235 bool RtpReceiverImpl::HaveReceivedFrame() const {
238 return last_received_frame_time_ms_ >= 0; 236 return last_received_frame_time_ms_ >= 0;
239 } 237 }
240 238
241 // Implementation note: must not hold critsect when called. 239 // Implementation note: must not hold critsect when called.
242 void RtpReceiverImpl::CheckSSRCChanged(const RTPHeader& rtp_header) { 240 void RtpReceiverImpl::CheckSSRCChanged(const RTPHeader& rtp_header) {
243 bool new_ssrc = false; 241 bool new_ssrc = false;
244 bool re_initialize_decoder = false; 242 bool re_initialize_decoder = false;
245 char payload_name[RTP_PAYLOAD_NAME_SIZE]; 243 char payload_name[RTP_PAYLOAD_NAME_SIZE];
246 size_t channels = 1; 244 size_t channels = 1;
247 uint32_t rate = 0; 245 uint32_t rate = 0;
248 246
249 { 247 {
250 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 248 rtc::CritScope lock(&critical_section_rtp_receiver_);
251 249
252 int8_t last_received_payload_type = 250 int8_t last_received_payload_type =
253 rtp_payload_registry_->last_received_payload_type(); 251 rtp_payload_registry_->last_received_payload_type();
254 if (ssrc_ != rtp_header.ssrc || 252 if (ssrc_ != rtp_header.ssrc ||
255 (last_received_payload_type == -1 && ssrc_ == 0)) { 253 (last_received_payload_type == -1 && ssrc_ == 0)) {
256 // We need the payload_type_ to make the call if the remote SSRC is 0. 254 // We need the payload_type_ to make the call if the remote SSRC is 0.
257 new_ssrc = true; 255 new_ssrc = true;
258 256
259 last_received_timestamp_ = 0; 257 last_received_timestamp_ = 0;
260 last_received_sequence_number_ = 0; 258 last_received_sequence_number_ = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 int32_t RtpReceiverImpl::CheckPayloadChanged(const RTPHeader& rtp_header, 309 int32_t RtpReceiverImpl::CheckPayloadChanged(const RTPHeader& rtp_header,
312 const int8_t first_payload_byte, 310 const int8_t first_payload_byte,
313 bool* is_red, 311 bool* is_red,
314 PayloadUnion* specific_payload) { 312 PayloadUnion* specific_payload) {
315 bool re_initialize_decoder = false; 313 bool re_initialize_decoder = false;
316 314
317 char payload_name[RTP_PAYLOAD_NAME_SIZE]; 315 char payload_name[RTP_PAYLOAD_NAME_SIZE];
318 int8_t payload_type = rtp_header.payloadType; 316 int8_t payload_type = rtp_header.payloadType;
319 317
320 { 318 {
321 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 319 rtc::CritScope lock(&critical_section_rtp_receiver_);
322 320
323 int8_t last_received_payload_type = 321 int8_t last_received_payload_type =
324 rtp_payload_registry_->last_received_payload_type(); 322 rtp_payload_registry_->last_received_payload_type();
325 // TODO(holmer): Remove this code when RED parsing has been broken out from 323 // TODO(holmer): Remove this code when RED parsing has been broken out from
326 // RtpReceiverAudio. 324 // RtpReceiverAudio.
327 if (payload_type != last_received_payload_type) { 325 if (payload_type != last_received_payload_type) {
328 if (rtp_payload_registry_->red_payload_type() == payload_type) { 326 if (rtp_payload_registry_->red_payload_type() == payload_type) {
329 // Get the real codec payload type. 327 // Get the real codec payload type.
330 payload_type = first_payload_byte & 0x7f; 328 payload_type = first_payload_byte & 0x7f;
331 *is_red = true; 329 *is_red = true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 return 0; 392 return 0;
395 } 393 }
396 394
397 // Implementation note: must not hold critsect when called. 395 // Implementation note: must not hold critsect when called.
398 void RtpReceiverImpl::CheckCSRC(const WebRtcRTPHeader& rtp_header) { 396 void RtpReceiverImpl::CheckCSRC(const WebRtcRTPHeader& rtp_header) {
399 int32_t num_csrcs_diff = 0; 397 int32_t num_csrcs_diff = 0;
400 uint32_t old_remote_csrc[kRtpCsrcSize]; 398 uint32_t old_remote_csrc[kRtpCsrcSize];
401 uint8_t old_num_csrcs = 0; 399 uint8_t old_num_csrcs = 0;
402 400
403 { 401 {
404 CriticalSectionScoped lock(critical_section_rtp_receiver_.get()); 402 rtc::CritScope lock(&critical_section_rtp_receiver_);
405 403
406 if (!rtp_media_receiver_->ShouldReportCsrcChanges( 404 if (!rtp_media_receiver_->ShouldReportCsrcChanges(
407 rtp_header.header.payloadType)) { 405 rtp_header.header.payloadType)) {
408 return; 406 return;
409 } 407 }
410 old_num_csrcs = num_csrcs_; 408 old_num_csrcs = num_csrcs_;
411 if (old_num_csrcs > 0) { 409 if (old_num_csrcs > 0) {
412 // Make a copy of old. 410 // Make a copy of old.
413 memcpy(old_remote_csrc, current_remote_csrc_, 411 memcpy(old_remote_csrc, current_remote_csrc_,
414 num_csrcs_ * sizeof(uint32_t)); 412 num_csrcs_ * sizeof(uint32_t));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // implementations might have CSRC 0 as a valid value. 468 // implementations might have CSRC 0 as a valid value.
471 if (num_csrcs_diff > 0) { 469 if (num_csrcs_diff > 0) {
472 cb_rtp_feedback_->OnIncomingCSRCChanged(0, true); 470 cb_rtp_feedback_->OnIncomingCSRCChanged(0, true);
473 } else if (num_csrcs_diff < 0) { 471 } else if (num_csrcs_diff < 0) {
474 cb_rtp_feedback_->OnIncomingCSRCChanged(0, false); 472 cb_rtp_feedback_->OnIncomingCSRCChanged(0, false);
475 } 473 }
476 } 474 }
477 } 475 }
478 476
479 } // namespace webrtc 477 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698