Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Side by Side Diff: content/browser/renderer_host/media/audio_input_device_manager.cc

Issue 23731007: Implicit audio output device selection for getUserMedia. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 16 matching lines...) Expand all
27 AudioInputDeviceManager::AudioInputDeviceManager( 27 AudioInputDeviceManager::AudioInputDeviceManager(
28 media::AudioManager* audio_manager) 28 media::AudioManager* audio_manager)
29 : listener_(NULL), 29 : listener_(NULL),
30 next_capture_session_id_(kFirstSessionId), 30 next_capture_session_id_(kFirstSessionId),
31 use_fake_device_(false), 31 use_fake_device_(false),
32 audio_manager_(audio_manager) { 32 audio_manager_(audio_manager) {
33 // TODO(xians): Remove this fake_device after the unittests do not need it. 33 // TODO(xians): Remove this fake_device after the unittests do not need it.
34 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE, 34 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE,
35 media::AudioManagerBase::kDefaultDeviceName, 35 media::AudioManagerBase::kDefaultDeviceName,
36 media::AudioManagerBase::kDefaultDeviceId, 36 media::AudioManagerBase::kDefaultDeviceId,
37 44100, media::CHANNEL_LAYOUT_STEREO, false); 37 44100, media::CHANNEL_LAYOUT_STEREO,
38 2048, false);
Jói 2013/09/06 14:49:26 Why 2048?
no longer working on chromium 2013/09/06 15:17:37 nit, use 0 as indicating the value is also fake.
tommi (sloooow) - chröme 2013/09/06 16:56:54 Copied from test code that also used a fake device
tommi (sloooow) - chröme 2013/09/06 16:56:54 Done.
38 fake_device.session_id = kFakeOpenSessionId; 39 fake_device.session_id = kFakeOpenSessionId;
39 devices_.push_back(fake_device); 40 devices_.push_back(fake_device);
40 } 41 }
41 42
42 AudioInputDeviceManager::~AudioInputDeviceManager() { 43 AudioInputDeviceManager::~AudioInputDeviceManager() {
43 } 44 }
44 45
45 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( 46 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById(
46 int session_id) { 47 int session_id) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 this, stream_type, base::Passed(&devices))); 163 this, stream_type, base::Passed(&devices)));
163 } 164 }
164 165
165 void AudioInputDeviceManager::OpenOnDeviceThread( 166 void AudioInputDeviceManager::OpenOnDeviceThread(
166 int session_id, const StreamDeviceInfo& info) { 167 int session_id, const StreamDeviceInfo& info) {
167 SCOPED_UMA_HISTOGRAM_TIMER( 168 SCOPED_UMA_HISTOGRAM_TIMER(
168 "Media.AudioInputDeviceManager.OpenOnDeviceThreadTime"); 169 "Media.AudioInputDeviceManager.OpenOnDeviceThreadTime");
169 DCHECK(IsOnDeviceThread()); 170 DCHECK(IsOnDeviceThread());
170 171
171 StreamDeviceInfo out(info.device.type, info.device.name, info.device.id, 172 StreamDeviceInfo out(info.device.type, info.device.name, info.device.id,
172 0, 0, false); 173 0, 0, 2048, false);
no longer working on chromium 2013/09/06 15:17:37 ditto
tommi (sloooow) - chröme 2013/09/06 16:56:54 Done.
173 out.session_id = session_id; 174 out.session_id = session_id;
175
176 MediaStreamDevice::AudioDeviceParameters& input_params = out.device.input;
177
174 if (use_fake_device_) { 178 if (use_fake_device_) {
175 // Don't need to query the hardware information if using fake device. 179 // Don't need to query the hardware information if using fake device.
176 out.device.sample_rate = 44100; 180 input_params.sample_rate = 44100;
177 out.device.channel_layout = media::CHANNEL_LAYOUT_STEREO; 181 input_params.channel_layout = media::CHANNEL_LAYOUT_STEREO;
178 } else { 182 } else {
179 // Get the preferred sample rate and channel configuration for the 183 // Get the preferred sample rate and channel configuration for the
180 // audio device. 184 // audio device.
181 media::AudioParameters params = 185 media::AudioParameters params =
182 audio_manager_->GetInputStreamParameters(info.device.id); 186 audio_manager_->GetInputStreamParameters(info.device.id);
183 out.device.sample_rate = params.sample_rate(); 187 input_params.sample_rate = params.sample_rate();
184 out.device.channel_layout = params.channel_layout(); 188 input_params.channel_layout = params.channel_layout();
189 input_params.frames_per_buffer = params.frames_per_buffer();
190
191 // Add preferred output device information if a matching output device
192 // exists.
193 out.device.matched_output_device_id =
194 audio_manager_->GetAssociatedOutputDeviceID(info.device.id);
195 if (!out.device.matched_output_device_id.empty()) {
196 params = audio_manager_->GetOutputStreamParameters(
197 out.device.matched_output_device_id);
198 MediaStreamDevice::AudioDeviceParameters& matched_output_params =
199 out.device.matched_output;
200 matched_output_params.sample_rate = params.sample_rate();
201 matched_output_params.channel_layout = params.channel_layout();
202 matched_output_params.frames_per_buffer = params.frames_per_buffer();
203 }
185 } 204 }
186 205
187 // Return the |session_id| through the listener by posting a task on 206 // Return the |session_id| through the listener by posting a task on
188 // IO thread since MediaStreamManager handles the callback asynchronously. 207 // IO thread since MediaStreamManager handles the callback asynchronously.
189 BrowserThread::PostTask(BrowserThread::IO, 208 BrowserThread::PostTask(BrowserThread::IO,
190 FROM_HERE, 209 FROM_HERE,
191 base::Bind(&AudioInputDeviceManager::OpenedOnIOThread, 210 base::Bind(&AudioInputDeviceManager::OpenedOnIOThread,
192 this, session_id, out)); 211 this, session_id, out));
193 } 212 }
194 213
195 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( 214 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread(
196 MediaStreamType stream_type, 215 MediaStreamType stream_type,
197 scoped_ptr<StreamDeviceInfoArray> devices) { 216 scoped_ptr<StreamDeviceInfoArray> devices) {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
199 // Ensure that |devices| gets deleted on exit. 218 // Ensure that |devices| gets deleted on exit.
200 if (listener_) 219 if (listener_)
201 listener_->DevicesEnumerated(stream_type, *devices); 220 listener_->DevicesEnumerated(stream_type, *devices);
202 } 221 }
203 222
204 void AudioInputDeviceManager::OpenedOnIOThread(int session_id, 223 void AudioInputDeviceManager::OpenedOnIOThread(int session_id,
205 const StreamDeviceInfo& info) { 224 const StreamDeviceInfo& info) {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
207 DCHECK_EQ(session_id, info.session_id); 226 DCHECK_EQ(session_id, info.session_id);
208 DCHECK(GetDevice(session_id) == devices_.end()); 227 DCHECK(GetDevice(session_id) == devices_.end());
228
209 devices_.push_back(info); 229 devices_.push_back(info);
210 230
211 if (listener_) 231 if (listener_)
212 listener_->Opened(info.device.type, session_id); 232 listener_->Opened(info.device.type, session_id);
213 } 233 }
214 234
215 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, 235 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type,
216 int session_id) { 236 int session_id) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
218 if (listener_) 238 if (listener_)
219 listener_->Closed(stream_type, session_id); 239 listener_->Closed(stream_type, session_id);
220 } 240 }
221 241
222 bool AudioInputDeviceManager::IsOnDeviceThread() const { 242 bool AudioInputDeviceManager::IsOnDeviceThread() const {
223 return device_loop_->BelongsToCurrentThread(); 243 return device_loop_->BelongsToCurrentThread();
224 } 244 }
225 245
226 AudioInputDeviceManager::StreamDeviceList::iterator 246 AudioInputDeviceManager::StreamDeviceList::iterator
227 AudioInputDeviceManager::GetDevice(int session_id) { 247 AudioInputDeviceManager::GetDevice(int session_id) {
228 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); 248 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end();
229 ++i) { 249 ++i) {
230 if (i->session_id == session_id) 250 if (i->session_id == session_id)
231 return i; 251 return i;
232 } 252 }
233 253
234 return devices_.end(); 254 return devices_.end();
235 } 255 }
236 256
237 } // namespace content 257 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698