Chromium Code Reviews| 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" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/platform_file.h" | |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
| 11 #include "content/renderer/media/webrtc_audio_capturer.h" | 12 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 12 #include "content/renderer/media/webrtc_audio_renderer.h" | 13 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 13 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
| 14 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
| 15 #include "media/audio/sample_rates.h" | 16 #include "media/audio/sample_rates.h" |
| 16 | 17 |
| 17 using media::AudioParameters; | 18 using media::AudioParameters; |
| 18 using media::ChannelLayout; | 19 using media::ChannelLayout; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() | 23 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() |
| 23 : ref_count_(0), | 24 : ref_count_(0), |
| 24 audio_transport_callback_(NULL), | 25 audio_transport_callback_(NULL), |
| 25 input_delay_ms_(0), | 26 input_delay_ms_(0), |
| 26 output_delay_ms_(0), | 27 output_delay_ms_(0), |
| 27 initialized_(false), | 28 initialized_(false), |
| 28 playing_(false), | 29 playing_(false), |
| 29 recording_(false), | 30 recording_(false), |
| 30 microphone_volume_(0) { | 31 microphone_volume_(0), |
| 32 aec_dump_file_(base::kInvalidPlatformFileValue) { | |
| 31 DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()"; | 33 DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()"; |
| 32 } | 34 } |
| 33 | 35 |
| 34 WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl() { | 36 WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl() { |
| 35 DVLOG(1) << "WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl()"; | 37 DVLOG(1) << "WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl()"; |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 Terminate(); | 39 Terminate(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 int32_t WebRtcAudioDeviceImpl::AddRef() { | 42 int32_t WebRtcAudioDeviceImpl::AddRef() { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 for (PlayoutDataSinkList::const_iterator it = playout_sinks_.begin(); | 170 for (PlayoutDataSinkList::const_iterator it = playout_sinks_.begin(); |
| 169 it != playout_sinks_.end(); ++it) { | 171 it != playout_sinks_.end(); ++it) { |
| 170 (*it)->OnPlayoutData(audio_bus, sample_rate, audio_delay_milliseconds); | 172 (*it)->OnPlayoutData(audio_bus, sample_rate, audio_delay_milliseconds); |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 void WebRtcAudioDeviceImpl::RemoveAudioRenderer(WebRtcAudioRenderer* renderer) { | 176 void WebRtcAudioDeviceImpl::RemoveAudioRenderer(WebRtcAudioRenderer* renderer) { |
| 175 DCHECK(thread_checker_.CalledOnValidThread()); | 177 DCHECK(thread_checker_.CalledOnValidThread()); |
| 176 DCHECK_EQ(renderer, renderer_); | 178 DCHECK_EQ(renderer, renderer_); |
| 177 base::AutoLock auto_lock(lock_); | 179 base::AutoLock auto_lock(lock_); |
| 178 // Notify the playout sink of the change. | 180 // Notify the playout sink of the change. |
|
Henrik Grunell
2014/03/06 19:55:12
Is this needed for the AEC dump? Why?
no longer working on chromium
2014/03/06 20:00:36
It is not from this CL, just some rebased code fro
| |
| 179 for (PlayoutDataSinkList::const_iterator it = playout_sinks_.begin(); | 181 for (PlayoutDataSinkList::const_iterator it = playout_sinks_.begin(); |
| 180 it != playout_sinks_.end(); ++it) { | 182 it != playout_sinks_.end(); ++it) { |
| 181 (*it)->OnPlayoutDataSourceChanged(); | 183 (*it)->OnPlayoutDataSourceChanged(); |
| 182 } | 184 } |
| 183 | 185 |
| 184 renderer_ = NULL; | 186 renderer_ = NULL; |
| 185 playing_ = false; | 187 playing_ = false; |
| 186 } | 188 } |
| 187 | 189 |
| 188 int32_t WebRtcAudioDeviceImpl::RegisterAudioCallback( | 190 int32_t WebRtcAudioDeviceImpl::RegisterAudioCallback( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 213 // Calling Terminate() multiple times in a row is OK. | 215 // Calling Terminate() multiple times in a row is OK. |
| 214 if (!initialized_) | 216 if (!initialized_) |
| 215 return 0; | 217 return 0; |
| 216 | 218 |
| 217 StopRecording(); | 219 StopRecording(); |
| 218 StopPlayout(); | 220 StopPlayout(); |
| 219 | 221 |
| 220 DCHECK(!renderer_.get() || !renderer_->IsStarted()) | 222 DCHECK(!renderer_.get() || !renderer_->IsStarted()) |
| 221 << "The shared audio renderer shouldn't be running"; | 223 << "The shared audio renderer shouldn't be running"; |
| 222 | 224 |
| 225 DisableAecDump(); | |
| 226 | |
| 223 capturers_.clear(); | 227 capturers_.clear(); |
| 224 | 228 |
| 225 initialized_ = false; | 229 initialized_ = false; |
| 226 return 0; | 230 return 0; |
| 227 } | 231 } |
| 228 | 232 |
| 229 bool WebRtcAudioDeviceImpl::Initialized() const { | 233 bool WebRtcAudioDeviceImpl::Initialized() const { |
| 230 return initialized_; | 234 return initialized_; |
| 231 } | 235 } |
| 232 | 236 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 renderer_ = renderer; | 428 renderer_ = renderer; |
| 425 return true; | 429 return true; |
| 426 } | 430 } |
| 427 | 431 |
| 428 void WebRtcAudioDeviceImpl::AddAudioCapturer( | 432 void WebRtcAudioDeviceImpl::AddAudioCapturer( |
| 429 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 433 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 430 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 434 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 431 DCHECK(thread_checker_.CalledOnValidThread()); | 435 DCHECK(thread_checker_.CalledOnValidThread()); |
| 432 DCHECK(capturer.get()); | 436 DCHECK(capturer.get()); |
| 433 DCHECK(!capturer->device_id().empty()); | 437 DCHECK(!capturer->device_id().empty()); |
| 434 base::AutoLock auto_lock(lock_); | 438 { |
| 435 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == | 439 base::AutoLock auto_lock(lock_); |
| 436 capturers_.end()); | 440 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| 437 capturers_.push_back(capturer); | 441 capturers_.end()); |
| 442 capturers_.push_back(capturer); | |
| 443 } | |
| 444 | |
| 445 // Start the Aec dump if the Aec dump has been enabled and has not been | |
| 446 // started. | |
| 447 if (aec_dump_file_ != base::kInvalidPlatformFileValue) | |
| 448 StartAecDump(); | |
| 438 } | 449 } |
| 439 | 450 |
| 440 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( | 451 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| 441 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 452 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 442 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 453 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 443 DCHECK(thread_checker_.CalledOnValidThread()); | 454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 444 DCHECK(capturer.get()); | 455 DCHECK(capturer.get()); |
| 445 base::AutoLock auto_lock(lock_); | 456 { |
|
Henrik Grunell
2014/03/07 09:14:57
Nit: don't need {}
no longer working on chromium
2014/03/07 10:14:54
Done.
| |
| 446 capturers_.remove(capturer); | 457 base::AutoLock auto_lock(lock_); |
| 458 capturers_.remove(capturer); | |
| 459 } | |
| 447 } | 460 } |
| 448 | 461 |
| 449 scoped_refptr<WebRtcAudioCapturer> | 462 scoped_refptr<WebRtcAudioCapturer> |
| 450 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { | 463 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { |
| 451 base::AutoLock auto_lock(lock_); | 464 base::AutoLock auto_lock(lock_); |
| 452 // Use the last |capturer| which is from the latest getUserMedia call as | 465 // Use the last |capturer| which is from the latest getUserMedia call as |
| 453 // the default capture device. | 466 // the default capture device. |
| 454 for (CapturerList::const_reverse_iterator iter = capturers_.rbegin(); | 467 for (CapturerList::const_reverse_iterator iter = capturers_.rbegin(); |
| 455 iter != capturers_.rend(); ++iter) { | 468 iter != capturers_.rend(); ++iter) { |
| 456 return *iter; | 469 return *iter; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 484 DCHECK(thread_checker_.CalledOnValidThread()); | 497 DCHECK(thread_checker_.CalledOnValidThread()); |
| 485 // If there is no capturer or there are more than one open capture devices, | 498 // If there is no capturer or there are more than one open capture devices, |
| 486 // return false. | 499 // return false. |
| 487 if (capturers_.empty() || capturers_.size() > 1) | 500 if (capturers_.empty() || capturers_.size() > 1) |
| 488 return false; | 501 return false; |
| 489 | 502 |
| 490 return GetDefaultCapturer()->GetPairedOutputParameters( | 503 return GetDefaultCapturer()->GetPairedOutputParameters( |
| 491 session_id, output_sample_rate, output_frames_per_buffer); | 504 session_id, output_sample_rate, output_frames_per_buffer); |
| 492 } | 505 } |
| 493 | 506 |
| 507 void WebRtcAudioDeviceImpl::EnableAecDump( | |
| 508 const base::PlatformFile& aec_dump_file) { | |
| 509 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 510 DCHECK_NE(aec_dump_file, base::kInvalidPlatformFileValue); | |
| 511 DCHECK_EQ(aec_dump_file_, base::kInvalidPlatformFileValue); | |
| 512 aec_dump_file_ = aec_dump_file; | |
| 513 StartAecDump(); | |
|
Henrik Grunell
2014/03/07 09:14:57
Have StartAecDump() take the file as an argument,
no longer working on chromium
2014/03/07 10:14:54
Discussed offline, keep the way how it is.
| |
| 514 } | |
| 515 | |
| 516 void WebRtcAudioDeviceImpl::DisableAecDump() { | |
| 517 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 518 // Simply invalidate the |aec_dump_file_| if we have not pass the ownership | |
| 519 // to WebRtc. | |
| 520 if (aec_dump_file_ != base::kInvalidPlatformFileValue) { | |
| 521 aec_dump_file_ = base::kInvalidPlatformFileValue; | |
|
Henrik Grunell
2014/03/07 09:14:57
Close the file before setting to invalid.
| |
| 522 return; | |
| 523 } | |
| 524 | |
| 525 // We might have call StartAecDump() on one of the capturer. Loop through all | |
| 526 // the capturers and call StopAecDump() on each of them to stop Aec dump. | |
| 527 for (CapturerList::const_iterator iter = capturers_.begin(); | |
| 528 iter != capturers_.end(); ++iter) { | |
| 529 (*iter)->StopAecDump(); | |
| 530 } | |
| 531 } | |
| 532 | |
| 533 void WebRtcAudioDeviceImpl::StartAecDump() { | |
| 534 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 535 DCHECK_NE(aec_dump_file_, base::kInvalidPlatformFileValue); | |
| 536 | |
| 537 // Start the Aec dump on the current default capturer. | |
| 538 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); | |
| 539 if (!default_capturer) | |
| 540 return; | |
| 541 | |
| 542 default_capturer->StartAecDump(aec_dump_file_); | |
| 543 | |
| 544 // Invalidate the |aec_dump_file_| since the ownership of the file has been | |
| 545 // passed to WebRtc. | |
| 546 aec_dump_file_ = base::kInvalidPlatformFileValue; | |
| 547 } | |
| 548 | |
| 494 } // namespace content | 549 } // namespace content |
| OLD | NEW |