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/browser/renderer_host/media/audio_input_device_manager_event_h andler.h" | 9 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h andler.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/common/media_stream_request.h" | 11 #include "content/public/common/media_stream_request.h" |
| 12 #include "media/audio/audio_device_name.h" | 12 #include "media/audio/audio_device_name.h" |
| 13 #include "media/audio/audio_input_ipc.h" | 13 #include "media/audio/audio_input_ipc.h" |
| 14 #include "media/audio/audio_manager_base.h" | 14 #include "media/audio/audio_manager_base.h" |
| 15 #include "media/audio/audio_util.h" | |
| 16 #include "media/base/channel_layout.h" | |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| 18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; | 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 // Starting id for the first capture session. | 23 // Starting id for the first capture session. |
| 22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; | 24 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; |
| 23 } | 25 } |
| 24 | 26 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 // BrowserMainloop. | 147 // BrowserMainloop. |
| 146 audio_manager_->GetAudioInputDeviceNames(&device_names); | 148 audio_manager_->GetAudioInputDeviceNames(&device_names); |
| 147 break; | 149 break; |
| 148 | 150 |
| 149 default: | 151 default: |
| 150 NOTREACHED(); | 152 NOTREACHED(); |
| 151 break; | 153 break; |
| 152 } | 154 } |
| 153 | 155 |
| 154 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); | 156 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); |
| 157 int sample_rate = 0; | |
|
tommi (sloooow) - chröme
2013/01/15 17:43:49
define these two variables where they are used
henrika (OOO until Aug 14)
2013/01/16 16:37:17
Done.
| |
| 158 media::ChannelLayout channel_layout = media::CHANNEL_LAYOUT_NONE; | |
| 155 for (media::AudioDeviceNames::iterator it = device_names.begin(); | 159 for (media::AudioDeviceNames::iterator it = device_names.begin(); |
| 156 it != device_names.end(); ++it) { | 160 it != device_names.end(); ++it) { |
| 161 // Get the preferred sample rate and channel configuration for the | |
| 162 // current audio device. | |
| 163 sample_rate = | |
| 164 media::GetAudioInputHardwareSampleRate(it->unique_id); | |
| 165 channel_layout = | |
| 166 media::GetAudioInputHardwareChannelLayout(it->unique_id); | |
| 167 | |
| 168 // Add device information to device vector. | |
| 157 devices->push_back(StreamDeviceInfo( | 169 devices->push_back(StreamDeviceInfo( |
| 158 stream_type, it->device_name, it->unique_id, false)); | 170 stream_type, it->device_name, it->unique_id, sample_rate, |
| 171 channel_layout, false)); | |
| 159 } | 172 } |
| 160 | 173 |
| 161 // Return the device list through the listener by posting a task on | 174 // Return the device list through the listener by posting a task on |
| 162 // IO thread since MediaStreamManager handles the callback asynchronously. | 175 // IO thread since MediaStreamManager handles the callback asynchronously. |
| 163 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
| 164 BrowserThread::IO, | 177 BrowserThread::IO, |
| 165 FROM_HERE, | 178 FROM_HERE, |
| 166 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, | 179 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, |
| 167 this, stream_type, base::Passed(&devices))); | 180 this, stream_type, base::Passed(&devices))); |
| 168 } | 181 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 FROM_HERE, | 213 FROM_HERE, |
| 201 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread, | 214 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread, |
| 202 this, stream_type, session_id)); | 215 this, stream_type, session_id)); |
| 203 } | 216 } |
| 204 | 217 |
| 205 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( | 218 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( |
| 206 MediaStreamType stream_type, | 219 MediaStreamType stream_type, |
| 207 scoped_ptr<StreamDeviceInfoArray> devices) { | 220 scoped_ptr<StreamDeviceInfoArray> devices) { |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 209 // Ensure that |devices| gets deleted on exit. | 222 // Ensure that |devices| gets deleted on exit. |
| 210 if (listener_) | 223 if (listener_) { |
|
tommi (sloooow) - chröme
2013/01/15 17:43:49
nit: revert this change (it's not consistent with
henrika (OOO until Aug 14)
2013/01/16 16:37:17
Done.
| |
| 211 listener_->DevicesEnumerated(stream_type, *devices); | 224 listener_->DevicesEnumerated(stream_type, *devices); |
| 225 } | |
| 212 } | 226 } |
| 213 | 227 |
| 214 void AudioInputDeviceManager::OpenedOnIOThread(MediaStreamType stream_type, | 228 void AudioInputDeviceManager::OpenedOnIOThread(MediaStreamType stream_type, |
| 215 int session_id) { | 229 int session_id) { |
| 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 217 if (listener_) | 231 if (listener_) |
| 218 listener_->Opened(stream_type, session_id); | 232 listener_->Opened(stream_type, session_id); |
| 219 } | 233 } |
| 220 | 234 |
| 221 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, | 235 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, |
| 222 int session_id) { | 236 int session_id) { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 224 if (listener_) | 238 if (listener_) |
| 225 listener_->Closed(stream_type, session_id); | 239 listener_->Closed(stream_type, session_id); |
| 226 } | 240 } |
| 227 | 241 |
| 228 bool AudioInputDeviceManager::IsOnDeviceThread() const { | 242 bool AudioInputDeviceManager::IsOnDeviceThread() const { |
| 229 return device_loop_->BelongsToCurrentThread(); | 243 return device_loop_->BelongsToCurrentThread(); |
| 230 } | 244 } |
| 231 | 245 |
| 232 } // namespace content | 246 } // namespace content |
| OLD | NEW |