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