| 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "media/audio/audio_device_description.h" | 16 #include "media/audio/audio_device_description.h" |
| 16 #include "media/audio/audio_output_dispatcher_impl.h" | 17 #include "media/audio/audio_output_dispatcher_impl.h" |
| 17 #include "media/audio/audio_output_proxy.h" | 18 #include "media/audio/audio_output_proxy.h" |
| 18 #include "media/audio/audio_output_resampler.h" | 19 #include "media/audio/audio_output_resampler.h" |
| 19 #include "media/audio/fake_audio_input_stream.h" | 20 #include "media/audio/fake_audio_input_stream.h" |
| 20 #include "media/audio/fake_audio_output_stream.h" | 21 #include "media/audio/fake_audio_output_stream.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 const AudioParameters& output, | 43 const AudioParameters& output, |
| 43 const std::string& output_device_id) | 44 const std::string& output_device_id) |
| 44 : input_params(input), | 45 : input_params(input), |
| 45 output_params(output), | 46 output_params(output), |
| 46 output_device_id(output_device_id) {} | 47 output_device_id(output_device_id) {} |
| 47 ~DispatcherParams() {} | 48 ~DispatcherParams() {} |
| 48 | 49 |
| 49 const AudioParameters input_params; | 50 const AudioParameters input_params; |
| 50 const AudioParameters output_params; | 51 const AudioParameters output_params; |
| 51 const std::string output_device_id; | 52 const std::string output_device_id; |
| 52 scoped_refptr<AudioOutputDispatcher> dispatcher; | 53 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(DispatcherParams); | 56 DISALLOW_COPY_AND_ASSIGN(DispatcherParams); |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 class AudioManagerBase::CompareByParams { | 59 class AudioManagerBase::CompareByParams { |
| 59 public: | 60 public: |
| 60 explicit CompareByParams(const DispatcherParams* dispatcher) | 61 explicit CompareByParams(const DispatcherParams* dispatcher) |
| 61 : dispatcher_(dispatcher) {} | 62 : dispatcher_(dispatcher) {} |
| 62 bool operator()(DispatcherParams* dispatcher_in) const { | 63 bool operator()(DispatcherParams* dispatcher_in) const { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 AudioOutputDispatchers::iterator it = | 252 AudioOutputDispatchers::iterator it = |
| 252 std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), | 253 std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), |
| 253 CompareByParams(dispatcher_params)); | 254 CompareByParams(dispatcher_params)); |
| 254 if (it != output_dispatchers_.end()) { | 255 if (it != output_dispatchers_.end()) { |
| 255 delete dispatcher_params; | 256 delete dispatcher_params; |
| 256 return new AudioOutputProxy((*it)->dispatcher.get()); | 257 return new AudioOutputProxy((*it)->dispatcher.get()); |
| 257 } | 258 } |
| 258 | 259 |
| 259 const base::TimeDelta kCloseDelay = | 260 const base::TimeDelta kCloseDelay = |
| 260 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 261 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| 261 scoped_refptr<AudioOutputDispatcher> dispatcher; | 262 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 262 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 263 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
| 263 dispatcher = new AudioOutputResampler(this, params, output_params, | 264 dispatcher = base::MakeUnique<AudioOutputResampler>( |
| 264 output_device_id, | 265 this, params, output_params, output_device_id, kCloseDelay); |
| 265 kCloseDelay); | |
| 266 } else { | 266 } else { |
| 267 dispatcher = new AudioOutputDispatcherImpl(this, output_params, | 267 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 268 output_device_id, | 268 this, output_params, output_device_id, kCloseDelay); |
| 269 kCloseDelay); | |
| 270 } | 269 } |
| 271 | 270 |
| 272 dispatcher_params->dispatcher = dispatcher; | 271 dispatcher_params->dispatcher = std::move(dispatcher); |
| 273 output_dispatchers_.push_back(dispatcher_params); | 272 output_dispatchers_.push_back(dispatcher_params); |
| 274 return new AudioOutputProxy(dispatcher.get()); | 273 return new AudioOutputProxy(dispatcher_params->dispatcher.get()); |
| 275 } | 274 } |
| 276 | 275 |
| 277 void AudioManagerBase::ShowAudioInputSettings() { | 276 void AudioManagerBase::ShowAudioInputSettings() { |
| 278 } | 277 } |
| 279 | 278 |
| 280 void AudioManagerBase::GetAudioInputDeviceNames( | 279 void AudioManagerBase::GetAudioInputDeviceNames( |
| 281 AudioDeviceNames* device_names) { | 280 AudioDeviceNames* device_names) { |
| 282 } | 281 } |
| 283 | 282 |
| 284 void AudioManagerBase::GetAudioOutputDeviceNames( | 283 void AudioManagerBase::GetAudioOutputDeviceNames( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 299 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { | 298 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
| 300 CHECK(GetTaskRunner()->BelongsToCurrentThread()); | 299 CHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 301 DCHECK(stream); | 300 DCHECK(stream); |
| 302 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. | 301 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
| 303 CHECK_EQ(1u, input_streams_.erase(stream)); | 302 CHECK_EQ(1u, input_streams_.erase(stream)); |
| 304 delete stream; | 303 delete stream; |
| 305 } | 304 } |
| 306 | 305 |
| 307 void AudioManagerBase::Shutdown() { | 306 void AudioManagerBase::Shutdown() { |
| 308 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 307 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 308 |
| 309 // Close all output streams. | 309 // Close all output streams. |
| 310 while (!output_dispatchers_.empty()) { | 310 output_dispatchers_.clear(); |
| 311 output_dispatchers_.back()->dispatcher->Shutdown(); | |
| 312 output_dispatchers_.pop_back(); | |
| 313 } | |
| 314 | 311 |
| 315 #if defined(OS_MACOSX) | 312 #if defined(OS_MACOSX) |
| 316 // On mac, AudioManager runs on the main thread, loop for which stops | 313 // On mac, AudioManager runs on the main thread, loop for which stops |
| 317 // processing task queue at this point. So even if tasks to close the | 314 // processing task queue at this point. So even if tasks to close the |
| 318 // streams are enqueued, they would not run leading to CHECKs getting hit | 315 // streams are enqueued, they would not run leading to CHECKs getting hit |
| 319 // in the destructor about open streams. Close them explicitly here. | 316 // in the destructor about open streams. Close them explicitly here. |
| 320 // crbug.com/608049. | 317 // crbug.com/608049. |
| 321 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) { | 318 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) { |
| 322 // Note: Closing the stream will invalidate the iterator. | 319 // Note: Closing the stream will invalidate the iterator. |
| 323 // Increment the iterator before closing the stream. | 320 // Increment the iterator before closing the stream. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 402 |
| 406 return 0; | 403 return 0; |
| 407 } | 404 } |
| 408 | 405 |
| 409 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 406 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| 410 AudioLogFactory::AudioComponent component) { | 407 AudioLogFactory::AudioComponent component) { |
| 411 return audio_log_factory_->CreateAudioLog(component); | 408 return audio_log_factory_->CreateAudioLog(component); |
| 412 } | 409 } |
| 413 | 410 |
| 414 } // namespace media | 411 } // namespace media |
| OLD | NEW |