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

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: Comments! 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 "media/audio/audio_output_dispatcher_impl.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( 166 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy(
167 const AudioParameters& params) { 167 const AudioParameters& params) {
168 #if defined(OS_IOS) 168 #if defined(OS_IOS)
169 // IOS implements audio input only. 169 // IOS implements audio input only.
170 NOTIMPLEMENTED(); 170 NOTIMPLEMENTED();
171 return NULL; 171 return NULL;
172 #else 172 #else
173 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 173 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
174 174
175 AudioOutputDispatchersMap::iterator it = output_dispatchers_.find(params); 175 bool use_audio_output_resampler =
176 !CommandLine::ForCurrentProcess()->HasSwitch(
177 switches::kDisableAudioOutputResampler) &&
178 params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY;
179
180 // If we're not using AudioOutputResampler our output parameters are the same
181 // as our input parameters.
182 AudioParameters output_params = params;
183 if (use_audio_output_resampler) {
184 output_params = GetPreferredLowLatencyOutputStreamParameters(params);
185
186 // Ensure we only pass on valid output parameters.
187 if (!output_params.IsValid()) {
188 // We've received invalid audio output parameters, so switch to a mock
189 // output device based on the input parameters. This may happen if the OS
190 // provided us junk values for the hardware configuration.
191 LOG(ERROR) << "Invalid audio output parameters received; using fake "
192 << "audio path. Channels: " << output_params.channels() << ", "
193 << "Sample Rate: " << output_params.sample_rate() << ", "
194 << "Bits Per Sample: " << output_params.bits_per_sample()
195 << ", Frames Per Buffer: "
196 << output_params.frames_per_buffer();
197
198 // Tell the AudioManager to create a fake output device.
199 output_params = AudioParameters(
200 AudioParameters::AUDIO_FAKE, params.channel_layout(),
201 params.sample_rate(), params.bits_per_sample(),
202 params.frames_per_buffer());
203 }
204 }
205
206 std::pair<AudioParameters, AudioParameters> dispatcher_key =
207 std::make_pair(params, output_params);
208 AudioOutputDispatchersMap::iterator it =
209 output_dispatchers_.find(dispatcher_key);
176 if (it != output_dispatchers_.end()) 210 if (it != output_dispatchers_.end())
177 return new AudioOutputProxy(it->second); 211 return new AudioOutputProxy(it->second);
178 212
179 base::TimeDelta close_delay = 213 base::TimeDelta close_delay =
180 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); 214 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds);
181 215
182 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 216 if (use_audio_output_resampler &&
183 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler) && 217 output_params.format() != AudioParameters::AUDIO_FAKE) {
184 params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { 218 scoped_refptr<AudioOutputDispatcher> dispatcher =
185 AudioParameters output_params = 219 new AudioOutputResampler(this, params, output_params, close_delay);
186 GetPreferredLowLatencyOutputStreamParameters(params); 220 output_dispatchers_[dispatcher_key] = dispatcher;
187 221 return new AudioOutputProxy(dispatcher);
188 // Ensure we only pass on valid output parameters.
189 if (output_params.IsValid()) {
190 scoped_refptr<AudioOutputDispatcher> dispatcher =
191 new AudioOutputResampler(this, params, output_params, close_delay);
192 output_dispatchers_[params] = dispatcher;
193 return new AudioOutputProxy(dispatcher);
194 }
195
196 // We've received invalid audio output parameters, so switch to a mock
197 // output device based on the input parameters. This may happen if the OS
198 // provided us junk values for the hardware configuration.
199 LOG(ERROR) << "Invalid audio output parameters received; using fake audio "
200 << "path. Channels: " << output_params.channels() << ", "
201 << "Sample Rate: " << output_params.sample_rate() << ", "
202 << "Bits Per Sample: " << output_params.bits_per_sample()
203 << ", Frames Per Buffer: " << output_params.frames_per_buffer();
204
205 // Passing AUDIO_FAKE tells the AudioManager to create a fake output device.
206 output_params = AudioParameters(
207 AudioParameters::AUDIO_FAKE, params.channel_layout(),
208 params.sample_rate(), params.bits_per_sample(),
209 params.frames_per_buffer());
210 } 222 }
211 223
212 #if defined(ENABLE_AUDIO_MIXER) 224 #if defined(ENABLE_AUDIO_MIXER)
213 // TODO(dalecurtis): Browser side mixing has a couple issues that must be 225 // TODO(dalecurtis): Browser side mixing has a couple issues that must be
214 // fixed before it can be turned on by default: http://crbug.com/138098 and 226 // fixed before it can be turned on by default: http://crbug.com/138098 and
215 // http://crbug.com/140247 227 // http://crbug.com/140247
216 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) { 228 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) {
217 scoped_refptr<AudioOutputDispatcher> dispatcher = 229 scoped_refptr<AudioOutputDispatcher> dispatcher =
218 new AudioOutputMixer(this, params, close_delay); 230 new AudioOutputMixer(this, params, close_delay);
219 output_dispatchers_[params] = dispatcher; 231 output_dispatchers_[dispatcher_key] = dispatcher;
220 return new AudioOutputProxy(dispatcher); 232 return new AudioOutputProxy(dispatcher);
221 } 233 }
222 #endif 234 #endif
223 235
224 scoped_refptr<AudioOutputDispatcher> dispatcher = 236 scoped_refptr<AudioOutputDispatcher> dispatcher =
225 new AudioOutputDispatcherImpl(this, params, close_delay); 237 new AudioOutputDispatcherImpl(this, params, close_delay);
226 output_dispatchers_[params] = dispatcher; 238 output_dispatchers_[dispatcher_key] = dispatcher;
227 return new AudioOutputProxy(dispatcher); 239 return new AudioOutputProxy(dispatcher);
228 #endif // defined(OS_IOS) 240 #endif // defined(OS_IOS)
229 } 241 }
230 242
231 bool AudioManagerBase::CanShowAudioInputSettings() { 243 bool AudioManagerBase::CanShowAudioInputSettings() {
232 return false; 244 return false;
233 } 245 }
234 246
235 void AudioManagerBase::ShowAudioInputSettings() { 247 void AudioManagerBase::ShowAudioInputSettings() {
236 } 248 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 358 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
347 output_listeners_.RemoveObserver(listener); 359 output_listeners_.RemoveObserver(listener);
348 } 360 }
349 361
350 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() { 362 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() {
351 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 363 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
352 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange()); 364 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange());
353 } 365 }
354 366
355 } // namespace media 367 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698