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

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/webrtc_audio_capturer.h" 5 #include "content/renderer/media/webrtc_audio_capturer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 const scoped_refptr<media::AudioCapturerSource>& source, 227 const scoped_refptr<media::AudioCapturerSource>& source,
228 media::ChannelLayout channel_layout, 228 media::ChannelLayout channel_layout,
229 float sample_rate) { 229 float sample_rate) {
230 DCHECK(thread_checker_.CalledOnValidThread()); 230 DCHECK(thread_checker_.CalledOnValidThread());
231 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," 231 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << ","
232 << "sample_rate=" << sample_rate << ")"; 232 << "sample_rate=" << sample_rate << ")";
233 scoped_refptr<media::AudioCapturerSource> old_source; 233 scoped_refptr<media::AudioCapturerSource> old_source;
234 scoped_refptr<ConfiguredBuffer> current_buffer; 234 scoped_refptr<ConfiguredBuffer> current_buffer;
235 { 235 {
236 base::AutoLock auto_lock(lock_); 236 base::AutoLock auto_lock(lock_);
237 if (source_ == source) 237 if (source_.get() == source.get())
238 return; 238 return;
239 239
240 source_.swap(old_source); 240 source_.swap(old_source);
241 source_ = source; 241 source_ = source;
242 current_buffer = buffer_; 242 current_buffer = buffer_;
243 243
244 // Reset the flag to allow calling Start() for the new source. 244 // Reset the flag to allow calling Start() for the new source.
245 running_ = false; 245 running_ = false;
246 } 246 }
247 247
248 const bool no_default_audio_source_exists = !current_buffer; 248 const bool no_default_audio_source_exists = !current_buffer.get();
249 249
250 // Detach the old source from normal recording or perform first-time 250 // Detach the old source from normal recording or perform first-time
251 // initialization if Initialize() has never been called. For the second 251 // initialization if Initialize() has never been called. For the second
252 // case, the caller is not "taking over an ongoing session" but instead 252 // case, the caller is not "taking over an ongoing session" but instead
253 // "taking control over a new session". 253 // "taking control over a new session".
254 if (old_source || no_default_audio_source_exists) { 254 if (old_source.get() || no_default_audio_source_exists) {
255 DVLOG(1) << "New capture source will now be utilized."; 255 DVLOG(1) << "New capture source will now be utilized.";
256 if (old_source) 256 if (old_source.get())
257 old_source->Stop(); 257 old_source->Stop();
258 258
259 // Dispatch the new parameters both to the sink(s) and to the new source. 259 // Dispatch the new parameters both to the sink(s) and to the new source.
260 // The idea is to get rid of any dependency of the microphone parameters 260 // The idea is to get rid of any dependency of the microphone parameters
261 // which would normally be used by default. 261 // which would normally be used by default.
262 if (!Reconfigure(sample_rate, channel_layout)) { 262 if (!Reconfigure(sample_rate, channel_layout)) {
263 return; 263 return;
264 } else { 264 } else {
265 // The buffer has been reconfigured. Update |current_buffer|. 265 // The buffer has been reconfigured. Update |current_buffer|.
266 base::AutoLock auto_lock(lock_); 266 base::AutoLock auto_lock(lock_);
267 current_buffer = buffer_; 267 current_buffer = buffer_;
268 } 268 }
269 } 269 }
270 270
271 if (source) { 271 if (source.get()) {
272 // Make sure to grab the new parameters in case they were reconfigured. 272 // Make sure to grab the new parameters in case they were reconfigured.
273 source->Initialize(current_buffer->params(), this, session_id_); 273 source->Initialize(current_buffer->params(), this, session_id_);
274 } 274 }
275 } 275 }
276 276
277 void WebRtcAudioCapturer::Start() { 277 void WebRtcAudioCapturer::Start() {
278 DVLOG(1) << "WebRtcAudioCapturer::Start()"; 278 DVLOG(1) << "WebRtcAudioCapturer::Start()";
279 base::AutoLock auto_lock(lock_); 279 base::AutoLock auto_lock(lock_);
280 if (running_) 280 if (running_)
281 return; 281 return;
282 282
283 // Start the data source, i.e., start capturing data from the current source. 283 // Start the data source, i.e., start capturing data from the current source.
284 // Note that, the source does not have to be a microphone. 284 // Note that, the source does not have to be a microphone.
285 if (source_) { 285 if (source_.get()) {
286 // We need to set the AGC control before starting the stream. 286 // We need to set the AGC control before starting the stream.
287 source_->SetAutomaticGainControl(agc_is_enabled_); 287 source_->SetAutomaticGainControl(agc_is_enabled_);
288 source_->Start(); 288 source_->Start();
289 } 289 }
290 290
291 running_ = true; 291 running_ = true;
292 } 292 }
293 293
294 void WebRtcAudioCapturer::Stop() { 294 void WebRtcAudioCapturer::Stop() {
295 DVLOG(1) << "WebRtcAudioCapturer::Stop()"; 295 DVLOG(1) << "WebRtcAudioCapturer::Stop()";
296 scoped_refptr<media::AudioCapturerSource> source; 296 scoped_refptr<media::AudioCapturerSource> source;
297 { 297 {
298 base::AutoLock auto_lock(lock_); 298 base::AutoLock auto_lock(lock_);
299 if (!running_) 299 if (!running_)
300 return; 300 return;
301 301
302 source = source_; 302 source = source_;
303 running_ = false; 303 running_ = false;
304 } 304 }
305 305
306 if (source) 306 if (source.get())
307 source->Stop(); 307 source->Stop();
308 } 308 }
309 309
310 void WebRtcAudioCapturer::SetVolume(double volume) { 310 void WebRtcAudioCapturer::SetVolume(double volume) {
311 DVLOG(1) << "WebRtcAudioCapturer::SetVolume()"; 311 DVLOG(1) << "WebRtcAudioCapturer::SetVolume()";
312 base::AutoLock auto_lock(lock_); 312 base::AutoLock auto_lock(lock_);
313 if (source_) 313 if (source_.get())
314 source_->SetVolume(volume); 314 source_->SetVolume(volume);
315 } 315 }
316 316
317 void WebRtcAudioCapturer::SetAutomaticGainControl(bool enable) { 317 void WebRtcAudioCapturer::SetAutomaticGainControl(bool enable) {
318 base::AutoLock auto_lock(lock_); 318 base::AutoLock auto_lock(lock_);
319 // Store the setting since SetAutomaticGainControl() can be called before 319 // Store the setting since SetAutomaticGainControl() can be called before
320 // Initialize(), in this case stored setting will be applied in Start(). 320 // Initialize(), in this case stored setting will be applied in Start().
321 agc_is_enabled_ = enable; 321 agc_is_enabled_ = enable;
322 322
323 if (source_) 323 if (source_.get())
324 source_->SetAutomaticGainControl(enable); 324 source_->SetAutomaticGainControl(enable);
325 } 325 }
326 326
327 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, 327 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source,
328 int audio_delay_milliseconds, 328 int audio_delay_milliseconds,
329 double volume) { 329 double volume) {
330 // This callback is driven by AudioInputDevice::AudioThreadCallback if 330 // This callback is driven by AudioInputDevice::AudioThreadCallback if
331 // |source_| is AudioInputDevice, otherwise it is driven by client's 331 // |source_| is AudioInputDevice, otherwise it is driven by client's
332 // CaptureCallback. 332 // CaptureCallback.
333 TrackList tracks; 333 TrackList tracks;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 367 }
368 368
369 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { 369 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const {
370 base::AutoLock auto_lock(lock_); 370 base::AutoLock auto_lock(lock_);
371 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not 371 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not
372 // been called. 372 // been called.
373 return buffer_.get() ? buffer_->params() : media::AudioParameters(); 373 return buffer_.get() ? buffer_->params() : media::AudioParameters();
374 } 374 }
375 375
376 } // namespace content 376 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_source_handler.cc ('k') | content/renderer/media/webrtc_audio_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698