Chromium Code Reviews| Index: media/audio/audio_manager_base.cc |
| diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc |
| index 09e2b05d1f89316e07fbed542546c39b2e847d1e..6eb7439b2745382c20cf223a789cbd693206a6c5 100644 |
| --- a/media/audio/audio_manager_base.cc |
| +++ b/media/audio/audio_manager_base.cc |
| @@ -172,41 +172,53 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| #else |
| DCHECK(GetMessageLoop()->BelongsToCurrentThread()); |
| - AudioOutputDispatchersMap::iterator it = output_dispatchers_.find(params); |
| + bool use_audio_output_resampler = |
| + !CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableAudioOutputResampler) && |
| + params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY; |
| + |
| + // If we're not using AudioOutputResampler our output parameters are the same |
| + // as our input parameters. |
| + AudioParameters output_params = params; |
| + if (use_audio_output_resampler) { |
| + output_params = GetPreferredLowLatencyOutputStreamParameters(params); |
| + |
| + // Ensure we only pass on valid output parameters. |
| + if (!output_params.IsValid()) { |
| + // We've received invalid audio output parameters, so switch to a mock |
| + // output device based on the input parameters. This may happen if the OS |
| + // provided us junk values for the hardware configuration. |
| + LOG(ERROR) << "Invalid audio output parameters received; using fake " |
| + << "audio path. Channels: " << output_params.channels() << ", " |
| + << "Sample Rate: " << output_params.sample_rate() << ", " |
| + << "Bits Per Sample: " << output_params.bits_per_sample() |
| + << ", Frames Per Buffer: " |
| + << output_params.frames_per_buffer(); |
| + |
| + // Tell the AudioManager to create a fake output device. |
| + output_params = AudioParameters( |
| + AudioParameters::AUDIO_FAKE, params.channel_layout(), |
| + params.sample_rate(), params.bits_per_sample(), |
| + params.frames_per_buffer()); |
| + } |
| + } |
| + |
| + std::pair<AudioParameters, AudioParameters> dispatcher_key = |
| + std::make_pair(params, output_params); |
| + AudioOutputDispatchersMap::iterator it = |
| + output_dispatchers_.find(dispatcher_key); |
| if (it != output_dispatchers_.end()) |
| return new AudioOutputProxy(it->second); |
| base::TimeDelta close_delay = |
| base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| - const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| - if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler) && |
| - params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| - AudioParameters output_params = |
| - GetPreferredLowLatencyOutputStreamParameters(params); |
| - |
| - // Ensure we only pass on valid output parameters. |
| - if (output_params.IsValid()) { |
| - scoped_refptr<AudioOutputDispatcher> dispatcher = |
| - new AudioOutputResampler(this, params, output_params, close_delay); |
| - output_dispatchers_[params] = dispatcher; |
| - return new AudioOutputProxy(dispatcher); |
| - } |
| - |
| - // We've received invalid audio output parameters, so switch to a mock |
| - // output device based on the input parameters. This may happen if the OS |
| - // provided us junk values for the hardware configuration. |
| - LOG(ERROR) << "Invalid audio output parameters received; using fake audio " |
| - << "path. Channels: " << output_params.channels() << ", " |
| - << "Sample Rate: " << output_params.sample_rate() << ", " |
| - << "Bits Per Sample: " << output_params.bits_per_sample() |
| - << ", Frames Per Buffer: " << output_params.frames_per_buffer(); |
| - |
| - // Passing AUDIO_FAKE tells the AudioManager to create a fake output device. |
| - output_params = AudioParameters( |
| - AudioParameters::AUDIO_FAKE, params.channel_layout(), |
| - params.sample_rate(), params.bits_per_sample(), |
| - params.frames_per_buffer()); |
| + if (use_audio_output_resampler && |
| + output_params.format() != AudioParameters::AUDIO_FAKE) { |
|
scherkus (not reviewing)
2012/10/22 23:51:05
sanity q: do we want to explicitly handle the AUDI
DaleCurtis
2012/10/23 01:49:42
That'd be okay and probably even preferable since
|
| + scoped_refptr<AudioOutputDispatcher> dispatcher = |
| + new AudioOutputResampler(this, params, output_params, close_delay); |
| + output_dispatchers_[dispatcher_key] = dispatcher; |
| + return new AudioOutputProxy(dispatcher); |
| } |
| #if defined(ENABLE_AUDIO_MIXER) |
| @@ -216,14 +228,14 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) { |
| scoped_refptr<AudioOutputDispatcher> dispatcher = |
| new AudioOutputMixer(this, params, close_delay); |
| - output_dispatchers_[params] = dispatcher; |
| + output_dispatchers_[dispatcher_key] = dispatcher; |
| return new AudioOutputProxy(dispatcher); |
| } |
| #endif |
| scoped_refptr<AudioOutputDispatcher> dispatcher = |
| new AudioOutputDispatcherImpl(this, params, close_delay); |
| - output_dispatchers_[params] = dispatcher; |
| + output_dispatchers_[dispatcher_key] = dispatcher; |
| return new AudioOutputProxy(dispatcher); |
| #endif // defined(OS_IOS) |
| } |