| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_device_impl.h" | 5 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 10 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 11 #include "content/renderer/media/media_stream_audio_processor.h" | |
| 12 #include "content/renderer/media/webrtc_audio_capturer.h" | |
| 13 #include "content/renderer/media/webrtc_audio_renderer.h" | 10 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 14 #include "content/renderer/render_thread_impl.h" | |
| 15 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
| 16 #include "media/audio/sample_rates.h" | 12 #include "media/audio/sample_rates.h" |
| 17 | 13 |
| 18 using media::AudioParameters; | 14 using media::AudioParameters; |
| 19 using media::ChannelLayout; | 15 using media::ChannelLayout; |
| 20 | 16 |
| 21 namespace content { | 17 namespace content { |
| 22 | 18 |
| 23 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() | 19 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() |
| 24 : ref_count_(0), | 20 : ref_count_(0), |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 DCHECK(worker_thread_checker_.CalledOnValidThread()); | 350 DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 355 base::AutoLock auto_lock(lock_); | 351 base::AutoLock auto_lock(lock_); |
| 356 *delay_ms = static_cast<uint16_t>(output_delay_ms_); | 352 *delay_ms = static_cast<uint16_t>(output_delay_ms_); |
| 357 return 0; | 353 return 0; |
| 358 } | 354 } |
| 359 | 355 |
| 360 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { | 356 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { |
| 361 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 357 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 362 | 358 |
| 363 // There is no way to report a correct delay value to WebRTC since there | 359 // There is no way to report a correct delay value to WebRTC since there |
| 364 // might be multiple WebRtcAudioCapturer instances. | 360 // might be multiple ProcessedLocalAudioSource instances. |
| 365 NOTREACHED(); | 361 NOTREACHED(); |
| 366 return -1; | 362 return -1; |
| 367 } | 363 } |
| 368 | 364 |
| 369 int32_t WebRtcAudioDeviceImpl::RecordingSampleRate( | 365 int32_t WebRtcAudioDeviceImpl::RecordingSampleRate( |
| 370 uint32_t* sample_rate) const { | 366 uint32_t* sample_rate) const { |
| 371 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 367 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 372 // We use the default capturer as the recording sample rate. | 368 // We use the default capturer as the recording sample rate. |
| 373 base::AutoLock auto_lock(lock_); | 369 base::AutoLock auto_lock(lock_); |
| 374 if (capturers_.empty()) | 370 if (capturers_.empty()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 audio_renderer_thread_checker_.DetachFromThread(); | 411 audio_renderer_thread_checker_.DetachFromThread(); |
| 416 | 412 |
| 417 // We acquire |lock_| again and assert our precondition, since we are | 413 // We acquire |lock_| again and assert our precondition, since we are |
| 418 // accessing the internal state again. | 414 // accessing the internal state again. |
| 419 base::AutoLock auto_lock(lock_); | 415 base::AutoLock auto_lock(lock_); |
| 420 DCHECK(!renderer_.get()); | 416 DCHECK(!renderer_.get()); |
| 421 renderer_ = renderer; | 417 renderer_ = renderer; |
| 422 return true; | 418 return true; |
| 423 } | 419 } |
| 424 | 420 |
| 425 void WebRtcAudioDeviceImpl::AddAudioCapturer(WebRtcAudioCapturer* capturer) { | 421 void WebRtcAudioDeviceImpl::AddAudioCapturer( |
| 422 ProcessedLocalAudioSource* capturer) { |
| 426 DCHECK(main_thread_checker_.CalledOnValidThread()); | 423 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 427 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 424 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 428 DCHECK(capturer); | 425 DCHECK(capturer); |
| 429 DCHECK(!capturer->device_info().device.id.empty()); | 426 DCHECK(!capturer->device_info().device.id.empty()); |
| 430 | 427 |
| 431 base::AutoLock auto_lock(lock_); | 428 base::AutoLock auto_lock(lock_); |
| 432 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == | 429 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| 433 capturers_.end()); | 430 capturers_.end()); |
| 434 capturers_.push_back(capturer); | 431 capturers_.push_back(capturer); |
| 435 } | 432 } |
| 436 | 433 |
| 437 void WebRtcAudioDeviceImpl::RemoveAudioCapturer(WebRtcAudioCapturer* capturer) { | 434 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| 435 ProcessedLocalAudioSource* capturer) { |
| 438 DCHECK(main_thread_checker_.CalledOnValidThread()); | 436 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 439 DVLOG(1) << "WebRtcAudioDeviceImpl::RemoveAudioCapturer()"; | 437 DVLOG(1) << "WebRtcAudioDeviceImpl::RemoveAudioCapturer()"; |
| 440 DCHECK(capturer); | 438 DCHECK(capturer); |
| 441 base::AutoLock auto_lock(lock_); | 439 base::AutoLock auto_lock(lock_); |
| 442 capturers_.remove(capturer); | 440 capturers_.remove(capturer); |
| 443 } | 441 } |
| 444 | 442 |
| 445 void WebRtcAudioDeviceImpl::AddPlayoutSink( | 443 void WebRtcAudioDeviceImpl::AddPlayoutSink( |
| 446 WebRtcPlayoutDataSource::Sink* sink) { | 444 WebRtcPlayoutDataSource::Sink* sink) { |
| 447 DCHECK(main_thread_checker_.CalledOnValidThread()); | 445 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 479 |
| 482 *session_id = device_info.session_id; | 480 *session_id = device_info.session_id; |
| 483 *output_sample_rate = device_info.device.matched_output.sample_rate; | 481 *output_sample_rate = device_info.device.matched_output.sample_rate; |
| 484 *output_frames_per_buffer = | 482 *output_frames_per_buffer = |
| 485 device_info.device.matched_output.frames_per_buffer; | 483 device_info.device.matched_output.frames_per_buffer; |
| 486 | 484 |
| 487 return true; | 485 return true; |
| 488 } | 486 } |
| 489 | 487 |
| 490 } // namespace content | 488 } // namespace content |
| OLD | NEW |