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

Side by Side Diff: media/audio/audio_manager_base.cc

Issue 1480523004: Ensure both default audio device IDs are handled for creation. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 5 years 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
« no previous file with comments | « no previous file | media/audio/audio_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/audio/audio_manager_base.h" 5 #include "media/audio/audio_manager_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // dispatcher are the same as the request dispatcher. 69 // dispatcher are the same as the request dispatcher.
70 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && 70 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) &&
71 dispatcher_->output_params.Equals(dispatcher_in->output_params) && 71 dispatcher_->output_params.Equals(dispatcher_in->output_params) &&
72 dispatcher_->output_device_id == dispatcher_in->output_device_id); 72 dispatcher_->output_device_id == dispatcher_in->output_device_id);
73 } 73 }
74 74
75 private: 75 private:
76 const DispatcherParams* dispatcher_; 76 const DispatcherParams* dispatcher_;
77 }; 77 };
78 78
79 static bool IsDefaultDeviceId(const std::string& device_id) {
80 return device_id.empty() || device_id == AudioManagerBase::kDefaultDeviceId;
81 }
82
79 AudioManagerBase::AudioManagerBase(AudioLogFactory* audio_log_factory) 83 AudioManagerBase::AudioManagerBase(AudioLogFactory* audio_log_factory)
80 : max_num_output_streams_(kDefaultMaxOutputStreams), 84 : max_num_output_streams_(kDefaultMaxOutputStreams),
81 max_num_input_streams_(kDefaultMaxInputStreams), 85 max_num_input_streams_(kDefaultMaxInputStreams),
82 num_output_streams_(0), 86 num_output_streams_(0),
83 num_input_streams_(0), 87 num_input_streams_(0),
84 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we 88 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we
85 // don't 89 // don't
86 // block the UI thread when swapping devices. 90 // block the UI thread when swapping devices.
87 output_listeners_( 91 output_listeners_(
88 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), 92 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DLOG(ERROR) << "Number of opened output audio streams " 159 DLOG(ERROR) << "Number of opened output audio streams "
156 << num_output_streams_ 160 << num_output_streams_
157 << " exceed the max allowed number " 161 << " exceed the max allowed number "
158 << max_num_output_streams_; 162 << max_num_output_streams_;
159 return NULL; 163 return NULL;
160 } 164 }
161 165
162 AudioOutputStream* stream; 166 AudioOutputStream* stream;
163 switch (params.format()) { 167 switch (params.format()) {
164 case AudioParameters::AUDIO_PCM_LINEAR: 168 case AudioParameters::AUDIO_PCM_LINEAR:
165 DCHECK(device_id.empty()) 169 DCHECK(IsDefaultDeviceId(device_id))
166 << "AUDIO_PCM_LINEAR supports only the default device."; 170 << "AUDIO_PCM_LINEAR supports only the default device.";
167 stream = MakeLinearOutputStream(params); 171 stream = MakeLinearOutputStream(params);
168 break; 172 break;
169 case AudioParameters::AUDIO_PCM_LOW_LATENCY: 173 case AudioParameters::AUDIO_PCM_LOW_LATENCY:
170 stream = MakeLowLatencyOutputStream(params, device_id); 174 stream = MakeLowLatencyOutputStream(params, device_id);
171 break; 175 break;
172 case AudioParameters::AUDIO_FAKE: 176 case AudioParameters::AUDIO_FAKE:
173 stream = FakeAudioOutputStream::MakeFakeStream(this, params); 177 stream = FakeAudioOutputStream::MakeFakeStream(this, params);
174 break; 178 break;
175 default: 179 default:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 const AudioParameters& params, 238 const AudioParameters& params,
235 const std::string& device_id) { 239 const std::string& device_id) {
236 DCHECK(task_runner_->BelongsToCurrentThread()); 240 DCHECK(task_runner_->BelongsToCurrentThread());
237 241
238 // If the caller supplied an empty device id to select the default device, 242 // If the caller supplied an empty device id to select the default device,
239 // we fetch the actual device id of the default device so that the lookup 243 // we fetch the actual device id of the default device so that the lookup
240 // will find the correct device regardless of whether it was opened as 244 // will find the correct device regardless of whether it was opened as
241 // "default" or via the specific id. 245 // "default" or via the specific id.
242 // NOTE: Implementations that don't yet support opening non-default output 246 // NOTE: Implementations that don't yet support opening non-default output
243 // devices may return an empty string from GetDefaultOutputDeviceID(). 247 // devices may return an empty string from GetDefaultOutputDeviceID().
244 std::string output_device_id = device_id.empty() ? 248 std::string output_device_id =
245 GetDefaultOutputDeviceID() : device_id; 249 IsDefaultDeviceId(device_id) ? GetDefaultOutputDeviceID() : device_id;
246 250
247 // If we're not using AudioOutputResampler our output parameters are the same 251 // If we're not using AudioOutputResampler our output parameters are the same
248 // as our input parameters. 252 // as our input parameters.
249 AudioParameters output_params = params; 253 AudioParameters output_params = params;
250 if (params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { 254 if (params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
251 output_params = 255 output_params =
252 GetPreferredOutputStreamParameters(output_device_id, params); 256 GetPreferredOutputStreamParameters(output_device_id, params);
253 257
254 // Ensure we only pass on valid output parameters. 258 // Ensure we only pass on valid output parameters.
255 if (!output_params.IsValid()) { 259 if (!output_params.IsValid()) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 scoped_ptr<AudioLog> AudioManagerBase::CreateAudioLog( 412 scoped_ptr<AudioLog> AudioManagerBase::CreateAudioLog(
409 AudioLogFactory::AudioComponent component) { 413 AudioLogFactory::AudioComponent component) {
410 return audio_log_factory_->CreateAudioLog(component); 414 return audio_log_factory_->CreateAudioLog(component);
411 } 415 }
412 416
413 void AudioManagerBase::SetHasKeyboardMic() { 417 void AudioManagerBase::SetHasKeyboardMic() {
414 NOTREACHED(); 418 NOTREACHED();
415 } 419 }
416 420
417 } // namespace media 421 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698