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

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

Issue 11233023: Handle audio device changes on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Callbacks! Created 8 years, 2 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 | Annotate | Revision Log
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( 156 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy(
157 const AudioParameters& params) { 157 const AudioParameters& params) {
158 #if defined(OS_IOS) 158 #if defined(OS_IOS)
159 // IOS implements audio input only. 159 // IOS implements audio input only.
160 NOTIMPLEMENTED(); 160 NOTIMPLEMENTED();
161 return NULL; 161 return NULL;
162 #else 162 #else
163 DCHECK(message_loop_->BelongsToCurrentThread()); 163 DCHECK(message_loop_->BelongsToCurrentThread());
164 164
165 AudioOutputDispatchersMap::iterator it = output_dispatchers_.find(params); 165 bool use_audio_output_resampler =
166 !CommandLine::ForCurrentProcess()->HasSwitch(
167 switches::kDisableAudioOutputResampler) &&
168 params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY;
169
170 // If we're not using AudioOutputResampler our output parameters are the same
171 // as our input parameters.
172 AudioParameters output_params = params;
173 if (use_audio_output_resampler) {
174 output_params = GetPreferredLowLatencyOutputStreamParameters(params);
175
176 // Ensure we only pass on valid output parameters.
177 if (!output_params.IsValid()) {
178 // We've received invalid audio output parameters, so switch to a mock
179 // output device based on the input parameters. This may happen if the OS
180 // provided us junk values for the hardware configuration.
181 LOG(ERROR) << "Invalid audio output parameters received; using fake "
182 << "audio path. Channels: " << output_params.channels() << ", "
183 << "Sample Rate: " << output_params.sample_rate() << ", "
184 << "Bits Per Sample: " << output_params.bits_per_sample()
185 << ", Frames Per Buffer: "
186 << output_params.frames_per_buffer();
187
188 // Tell the AudioManager to create a fake output device.
189 output_params = AudioParameters(
190 AudioParameters::AUDIO_FAKE, params.channel_layout(),
191 params.sample_rate(), params.bits_per_sample(),
192 params.frames_per_buffer());
193 }
194 }
195
196 std::pair<AudioParameters, AudioParameters> dispatcher_key =
197 std::make_pair(params, output_params);
198 AudioOutputDispatchersMap::iterator it =
199 output_dispatchers_.find(dispatcher_key);
166 if (it != output_dispatchers_.end()) 200 if (it != output_dispatchers_.end())
167 return new AudioOutputProxy(it->second); 201 return new AudioOutputProxy(it->second);
168 202
169 base::TimeDelta close_delay = 203 base::TimeDelta close_delay =
170 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); 204 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds);
171 205
172 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 206 if (use_audio_output_resampler &&
173 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler) && 207 output_params.format() != AudioParameters::AUDIO_FAKE) {
174 params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { 208 scoped_refptr<AudioOutputDispatcher> dispatcher =
175 AudioParameters output_params = 209 new AudioOutputResampler(this, params, output_params, close_delay);
176 GetPreferredLowLatencyOutputStreamParameters(params); 210 output_dispatchers_[dispatcher_key] = dispatcher;
177 211 return new AudioOutputProxy(dispatcher);
178 // Ensure we only pass on valid output parameters.
179 if (output_params.IsValid()) {
180 scoped_refptr<AudioOutputDispatcher> dispatcher =
181 new AudioOutputResampler(this, params, output_params, close_delay);
182 output_dispatchers_[params] = dispatcher;
183 return new AudioOutputProxy(dispatcher);
184 }
185
186 // We've received invalid audio output parameters, so switch to a mock
187 // output device based on the input parameters. This may happen if the OS
188 // provided us junk values for the hardware configuration.
189 LOG(ERROR) << "Invalid audio output parameters received; using fake audio "
190 << "path. Channels: " << output_params.channels() << ", "
191 << "Sample Rate: " << output_params.sample_rate() << ", "
192 << "Bits Per Sample: " << output_params.bits_per_sample()
193 << ", Frames Per Buffer: " << output_params.frames_per_buffer();
194
195 // Passing AUDIO_FAKE tells the AudioManager to create a fake output device.
196 output_params = AudioParameters(
197 AudioParameters::AUDIO_FAKE, params.channel_layout(),
198 params.sample_rate(), params.bits_per_sample(),
199 params.frames_per_buffer());
200 } 212 }
201 213
202 #if defined(ENABLE_AUDIO_MIXER) 214 #if defined(ENABLE_AUDIO_MIXER)
203 // TODO(dalecurtis): Browser side mixing has a couple issues that must be 215 // TODO(dalecurtis): Browser side mixing has a couple issues that must be
204 // fixed before it can be turned on by default: http://crbug.com/138098 and 216 // fixed before it can be turned on by default: http://crbug.com/138098 and
205 // http://crbug.com/140247 217 // http://crbug.com/140247
206 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) { 218 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) {
207 scoped_refptr<AudioOutputDispatcher> dispatcher = 219 scoped_refptr<AudioOutputDispatcher> dispatcher =
208 new AudioOutputMixer(this, params, close_delay); 220 new AudioOutputMixer(this, params, close_delay);
209 output_dispatchers_[params] = dispatcher; 221 output_dispatchers_[dispatcher_key] = dispatcher;
210 return new AudioOutputProxy(dispatcher); 222 return new AudioOutputProxy(dispatcher);
211 } 223 }
212 #endif 224 #endif
213 225
214 scoped_refptr<AudioOutputDispatcher> dispatcher = 226 scoped_refptr<AudioOutputDispatcher> dispatcher =
215 new AudioOutputDispatcherImpl(this, params, close_delay); 227 new AudioOutputDispatcherImpl(this, params, close_delay);
216 output_dispatchers_[params] = dispatcher; 228 output_dispatchers_[dispatcher_key] = dispatcher;
217 return new AudioOutputProxy(dispatcher); 229 return new AudioOutputProxy(dispatcher);
218 #endif // defined(OS_IOS) 230 #endif // defined(OS_IOS)
219 } 231 }
220 232
221 bool AudioManagerBase::CanShowAudioInputSettings() { 233 bool AudioManagerBase::CanShowAudioInputSettings() {
222 return false; 234 return false;
223 } 235 }
224 236
225 void AudioManagerBase::ShowAudioInputSettings() { 237 void AudioManagerBase::ShowAudioInputSettings() {
226 } 238 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 output_listeners_.RemoveObserver(listener); 349 output_listeners_.RemoveObserver(listener);
338 } 350 }
339 351
340 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() { 352 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() {
341 DCHECK(message_loop_->BelongsToCurrentThread()); 353 DCHECK(message_loop_->BelongsToCurrentThread());
342 DVLOG(1) << "Firing OnDeviceChange() notifications."; 354 DVLOG(1) << "Firing OnDeviceChange() notifications.";
343 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange()); 355 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange());
344 } 356 }
345 357
346 } // namespace media 358 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698