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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 429 |
| 430 renderer_ = renderer; | 430 renderer_ = renderer; |
| 431 return true; | 431 return true; |
| 432 } | 432 } |
| 433 | 433 |
| 434 void WebRtcAudioDeviceImpl::AddAudioCapturer( | 434 void WebRtcAudioDeviceImpl::AddAudioCapturer( |
| 435 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 435 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 436 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 436 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 437 DCHECK(thread_checker_.CalledOnValidThread()); | 437 DCHECK(thread_checker_.CalledOnValidThread()); |
| 438 DCHECK(capturer.get()); | 438 DCHECK(capturer.get()); |
| 439 DCHECK(!capturer->device_id().empty()); | |
| 440 base::AutoLock auto_lock(lock_); | |
| 441 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == | |
| 442 capturers_.end()); | |
| 443 capturers_.push_back(capturer); | |
| 444 } | |
| 439 | 445 |
| 440 // We only support one microphone today, which means the list can contain | 446 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| 441 // only one capturer with a valid device id. | 447 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 442 DCHECK(capturer->device_id().empty() || !GetDefaultCapturer()); | 448 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 449 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 450 DCHECK(capturer.get()); | |
| 443 base::AutoLock auto_lock(lock_); | 451 base::AutoLock auto_lock(lock_); |
| 444 capturers_.push_back(capturer); | 452 capturers_.remove(capturer); |
| 445 } | 453 } |
| 446 | 454 |
| 447 scoped_refptr<WebRtcAudioCapturer> | 455 scoped_refptr<WebRtcAudioCapturer> |
| 448 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { | 456 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { |
| 449 base::AutoLock auto_lock(lock_); | 457 base::AutoLock auto_lock(lock_); |
| 450 for (CapturerList::const_iterator iter = capturers_.begin(); | 458 // Use the last |capturer| which is from the latest getUserMedia call as |
| 451 iter != capturers_.end(); ++iter) { | 459 // the default capture device. |
| 452 if (!(*iter)->device_id().empty()) | 460 for (CapturerList::const_reverse_iterator iter = capturers_.rbegin(); |
|
perkj_chrome
2014/01/14 12:53:55
return capturers_.empty() ? NULL : capturers_[capt
no longer working on chromium
2014/01/14 14:10:56
Done.
no longer working on chromium
2014/01/14 14:10:56
capturers_ is a list whose element can't be access
perkj_chrome
2014/01/14 20:27:32
sure. You can also use *(capturers_.end()--) inste
no longer working on chromium
2014/01/15 18:31:03
I would like to use the existing approach since it
| |
| 453 return *iter; | 461 iter != capturers_.rend(); ++iter) { |
| 462 return *iter; | |
| 454 } | 463 } |
| 455 | 464 |
| 456 return NULL; | 465 return NULL; |
| 457 } | 466 } |
| 458 | 467 |
| 468 bool WebRtcAudioDeviceImpl::GetAuthorizedDeviceInfoForAudioRenderer( | |
| 469 int* session_id, | |
| 470 int* output_sample_rate, | |
| 471 int* output_frames_per_buffer) { | |
| 472 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 473 // If there is no capturer or there are more than one open capture devices, | |
| 474 // return false. | |
| 475 if (capturers_.empty() || capturers_.size() > 1) | |
| 476 return false; | |
| 477 | |
| 478 return GetDefaultCapturer()->GetPairedOutputParameters( | |
| 479 session_id, output_sample_rate, output_frames_per_buffer); | |
| 480 } | |
| 481 | |
| 459 } // namespace content | 482 } // namespace content |
| OLD | NEW |