Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/renderer_host/media/audio_input_device_manager.h" | 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/common/media_stream_request.h" | 10 #include "content/public/common/media_stream_request.h" |
| 11 #include "media/audio/audio_device_name.h" | 11 #include "media/audio/audio_device_name.h" |
| 12 #include "media/audio/audio_input_ipc.h" | 12 #include "media/audio/audio_input_ipc.h" |
| 13 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
| 14 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
| 15 #include "media/base/channel_layout.h" | 15 #include "media/base/channel_layout.h" |
| 16 #include "media/base/scoped_histogram_timer.h" | 16 #include "media/base/scoped_histogram_timer.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; | 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; |
| 21 | 21 |
| 22 const char kFakeDeviceName[] = "Fake Audio"; | |
| 23 const char kFakeDeviceId[] = "fake_audio"; | |
| 24 | |
| 22 namespace { | 25 namespace { |
| 23 // Starting id for the first capture session. | 26 // Starting id for the first capture session. |
| 24 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; | 27 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; |
| 25 } | 28 } |
| 26 | 29 |
| 27 AudioInputDeviceManager::AudioInputDeviceManager( | 30 AudioInputDeviceManager::AudioInputDeviceManager( |
| 28 media::AudioManager* audio_manager) | 31 media::AudioManager* audio_manager) |
| 29 : listener_(NULL), | 32 : listener_(NULL), |
| 30 next_capture_session_id_(kFirstSessionId), | 33 next_capture_session_id_(kFirstSessionId), |
| 31 use_fake_device_(false), | 34 use_fake_device_(false), |
| 32 audio_manager_(audio_manager) { | 35 audio_manager_(audio_manager) { |
| 33 // TODO(xians): Remove this fake_device after the unittests do not need it. | 36 // TODO(xians): Remove this fake_device after the unittests do not need it. |
| 34 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE, | 37 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 35 media::AudioManagerBase::kDefaultDeviceName, | 38 kFakeDeviceName, |
| 36 media::AudioManagerBase::kDefaultDeviceId, | 39 kFakeDeviceName, |
|
DaleCurtis
2014/04/29 17:33:31
FakeDeviceId?
no longer working on chromium
2014/05/02 14:30:47
Done.
| |
| 37 44100, media::CHANNEL_LAYOUT_STEREO, | 40 44100, media::CHANNEL_LAYOUT_STEREO, |
| 38 0); | 41 0); |
| 39 fake_device.session_id = kFakeOpenSessionId; | 42 fake_device.session_id = kFakeOpenSessionId; |
| 40 devices_.push_back(fake_device); | 43 devices_.push_back(fake_device); |
| 41 } | 44 } |
| 42 | 45 |
| 43 AudioInputDeviceManager::~AudioInputDeviceManager() { | 46 AudioInputDeviceManager::~AudioInputDeviceManager() { |
| 44 } | 47 } |
| 45 | 48 |
| 46 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( | 49 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // BrowserMainloop. | 135 // BrowserMainloop. |
| 133 audio_manager_->GetAudioInputDeviceNames(&device_names); | 136 audio_manager_->GetAudioInputDeviceNames(&device_names); |
| 134 break; | 137 break; |
| 135 | 138 |
| 136 default: | 139 default: |
| 137 NOTREACHED(); | 140 NOTREACHED(); |
| 138 break; | 141 break; |
| 139 } | 142 } |
| 140 | 143 |
| 141 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); | 144 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); |
| 142 for (media::AudioDeviceNames::iterator it = device_names.begin(); | 145 // If the |use_fake_device_| flag is on or there is no available device on |
| 143 it != device_names.end(); ++it) { | 146 // the OS, inject the fake device. |
| 144 // Add device information to device vector. | 147 if (use_fake_device_ || devices->empty()) { |
|
DaleCurtis
2014/04/29 17:33:31
Won't devices() always be empty()? You're construc
phoglund_chromium
2014/04/30 08:03:49
Yeah, looks like the else branch will never be tak
no longer working on chromium
2014/05/02 14:30:47
Ah, right, I just missed that devices were differe
no longer working on chromium
2014/05/02 14:30:47
That was what I was thinking but realized that it
| |
| 145 devices->push_back(StreamDeviceInfo( | 148 devices->push_back(StreamDeviceInfo(stream_type, kFakeDeviceName, |
| 146 stream_type, it->device_name, it->unique_id)); | 149 kFakeDeviceId)); |
| 147 } | 150 } else { |
| 148 | 151 for (media::AudioDeviceNames::iterator it = device_names.begin(); |
| 149 // If the |use_fake_device_| flag is on, inject the fake device if there is | 152 it != device_names.end(); ++it) { |
| 150 // no available device on the OS. | 153 // Add device information to device vector. |
| 151 if (use_fake_device_ && devices->empty()) { | 154 devices->push_back(StreamDeviceInfo( |
| 152 devices->push_back(StreamDeviceInfo( | 155 stream_type, it->device_name, it->unique_id)); |
| 153 stream_type, media::AudioManagerBase::kDefaultDeviceName, | 156 } |
|
DaleCurtis
2014/04/29 17:33:31
You're no longer injecting a fake device if no dev
no longer working on chromium
2014/05/02 14:30:47
We don't inject the fake device in production. The
| |
| 154 media::AudioManagerBase::kDefaultDeviceId)); | |
| 155 } | 157 } |
| 156 | 158 |
| 157 // Return the device list through the listener by posting a task on | 159 // Return the device list through the listener by posting a task on |
| 158 // IO thread since MediaStreamManager handles the callback asynchronously. | 160 // IO thread since MediaStreamManager handles the callback asynchronously. |
| 159 BrowserThread::PostTask( | 161 BrowserThread::PostTask( |
| 160 BrowserThread::IO, | 162 BrowserThread::IO, |
| 161 FROM_HERE, | 163 FROM_HERE, |
| 162 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, | 164 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, |
| 163 this, stream_type, base::Passed(&devices))); | 165 this, stream_type, base::Passed(&devices))); |
| 164 } | 166 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); | 251 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); |
| 250 ++i) { | 252 ++i) { |
| 251 if (i->session_id == session_id) | 253 if (i->session_id == session_id) |
| 252 return i; | 254 return i; |
| 253 } | 255 } |
| 254 | 256 |
| 255 return devices_.end(); | 257 return devices_.end(); |
| 256 } | 258 } |
| 257 | 259 |
| 258 } // namespace content | 260 } // namespace content |
| OLD | NEW |