| 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" |
| 11 #include "media/audio/audio_output_dispatcher_impl.h" | 11 #include "media/audio/audio_output_dispatcher_impl.h" |
| 12 #include "media/audio/audio_output_proxy.h" | 12 #include "media/audio/audio_output_proxy.h" |
| 13 #include "media/audio/audio_output_resampler.h" |
| 14 #include "media/audio/audio_util.h" |
| 13 #include "media/audio/fake_audio_input_stream.h" | 15 #include "media/audio/fake_audio_input_stream.h" |
| 14 #include "media/audio/fake_audio_output_stream.h" | 16 #include "media/audio/fake_audio_output_stream.h" |
| 15 #include "media/base/media_switches.h" | 17 #include "media/base/media_switches.h" |
| 16 | 18 |
| 17 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, | 19 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, |
| 18 // http://crbug.com/114700 | 20 // http://crbug.com/114700 |
| 19 #if defined(ENABLE_AUDIO_MIXER) | 21 #if defined(ENABLE_AUDIO_MIXER) |
| 20 #include "media/audio/audio_output_mixer.h" | 22 #include "media/audio/audio_output_mixer.h" |
| 21 #endif | 23 #endif |
| 22 | 24 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 142 |
| 141 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( | 143 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| 142 const AudioParameters& params) { | 144 const AudioParameters& params) { |
| 143 #if defined(OS_IOS) | 145 #if defined(OS_IOS) |
| 144 // IOS implements audio input only. | 146 // IOS implements audio input only. |
| 145 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
| 146 return NULL; | 148 return NULL; |
| 147 #else | 149 #else |
| 148 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); | 150 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); |
| 149 | 151 |
| 150 scoped_refptr<AudioOutputDispatcher>& dispatcher = | 152 AudioOutputDispatchersMap::iterator it = output_dispatchers_.find(params); |
| 151 output_dispatchers_[params]; | 153 if (it != output_dispatchers_.end()) |
| 152 if (!dispatcher) { | 154 return new AudioOutputProxy(it->second); |
| 153 base::TimeDelta close_delay = | 155 |
| 154 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 156 base::TimeDelta close_delay = |
| 155 // TODO(dalecurtis): Browser side mixing has a couple issues that must be | 157 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| 156 // fixed before it can be turned on by default: http://crbug.com/138098 and | 158 |
| 157 // http://crbug.com/140247 | 159 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 160 if (cmd_line->HasSwitch(switches::kEnableAudioOutputResampler) && |
| 161 params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 162 scoped_refptr<AudioOutputDispatcher> dispatcher = new AudioOutputResampler( |
| 163 this, params, |
| 164 GetPreferredLowLatencyOutputStreamParameters(params.channel_layout()), |
| 165 close_delay); |
| 166 output_dispatchers_[params] = dispatcher; |
| 167 return new AudioOutputProxy(dispatcher); |
| 168 } |
| 169 |
| 158 #if defined(ENABLE_AUDIO_MIXER) | 170 #if defined(ENABLE_AUDIO_MIXER) |
| 159 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 171 // TODO(dalecurtis): Browser side mixing has a couple issues that must be |
| 160 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) | 172 // fixed before it can be turned on by default: http://crbug.com/138098 and |
| 161 dispatcher = new AudioOutputMixer(this, params, close_delay); | 173 // http://crbug.com/140247 |
| 162 else | 174 if (cmd_line->HasSwitch(switches::kEnableAudioMixer)) { |
| 175 scoped_refptr<AudioOutputDispatcher> dispatcher = |
| 176 new AudioOutputMixer(this, params, close_delay); |
| 177 output_dispatchers_[params] = dispatcher; |
| 178 return new AudioOutputProxy(dispatcher); |
| 179 } |
| 163 #endif | 180 #endif |
| 164 dispatcher = new AudioOutputDispatcherImpl(this, params, close_delay); | 181 |
| 165 } | 182 scoped_refptr<AudioOutputDispatcher> dispatcher = |
| 183 new AudioOutputDispatcherImpl(this, params, close_delay); |
| 184 output_dispatchers_[params] = dispatcher; |
| 166 return new AudioOutputProxy(dispatcher); | 185 return new AudioOutputProxy(dispatcher); |
| 167 #endif // defined(OS_IOS) | 186 #endif // defined(OS_IOS) |
| 168 } | 187 } |
| 169 | 188 |
| 170 bool AudioManagerBase::CanShowAudioInputSettings() { | 189 bool AudioManagerBase::CanShowAudioInputSettings() { |
| 171 return false; | 190 return false; |
| 172 } | 191 } |
| 173 | 192 |
| 174 void AudioManagerBase::ShowAudioInputSettings() { | 193 void AudioManagerBase::ShowAudioInputSettings() { |
| 175 } | 194 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // So, better crash now than later. | 271 // So, better crash now than later. |
| 253 DCHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive"; | 272 DCHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive"; |
| 254 dispatcher = NULL; | 273 dispatcher = NULL; |
| 255 } | 274 } |
| 256 } | 275 } |
| 257 | 276 |
| 258 output_dispatchers_.clear(); | 277 output_dispatchers_.clear(); |
| 259 #endif // defined(OS_IOS) | 278 #endif // defined(OS_IOS) |
| 260 } | 279 } |
| 261 | 280 |
| 281 AudioParameters AudioManagerBase::GetPreferredLowLatencyOutputStreamParameters( |
| 282 ChannelLayout channel_layout) { |
| 283 // TODO(dalecurtis): This should include bits per channel and channel layout |
| 284 // eventually. |
| 285 return AudioParameters( |
| 286 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 287 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); |
| 288 } |
| 289 |
| 262 } // namespace media | 290 } // namespace media |
| OLD | NEW |