| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 61 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(DispatcherParams); | 64 DISALLOW_COPY_AND_ASSIGN(DispatcherParams); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class AudioManagerBase::CompareByParams { | 67 class AudioManagerBase::CompareByParams { |
| 68 public: | 68 public: |
| 69 explicit CompareByParams(const DispatcherParams* dispatcher) | 69 explicit CompareByParams(const DispatcherParams* dispatcher) |
| 70 : dispatcher_(dispatcher) {} | 70 : dispatcher_(dispatcher) {} |
| 71 bool operator()(DispatcherParams* dispatcher_in) const { | 71 bool operator()( |
| 72 const std::unique_ptr<DispatcherParams>& dispatcher_in) const { |
| 72 // We will reuse the existing dispatcher when: | 73 // We will reuse the existing dispatcher when: |
| 73 // 1) Unified IO is not used, input_params and output_params of the | 74 // 1) Unified IO is not used, input_params and output_params of the |
| 74 // existing dispatcher are the same as the requested dispatcher. | 75 // existing dispatcher are the same as the requested dispatcher. |
| 75 // 2) Unified IO is used, input_params and output_params of the existing | 76 // 2) Unified IO is used, input_params and output_params of the existing |
| 76 // dispatcher are the same as the request dispatcher. | 77 // dispatcher are the same as the request dispatcher. |
| 77 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && | 78 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && |
| 78 dispatcher_->output_params.Equals(dispatcher_in->output_params) && | 79 dispatcher_->output_params.Equals(dispatcher_in->output_params) && |
| 79 dispatcher_->output_device_id == dispatcher_in->output_device_id); | 80 dispatcher_->output_device_id == dispatcher_in->output_device_id); |
| 80 } | 81 } |
| 81 | 82 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 271 |
| 271 // Tell the AudioManager to create a fake output device. | 272 // Tell the AudioManager to create a fake output device. |
| 272 output_params = params; | 273 output_params = params; |
| 273 output_params.set_format(AudioParameters::AUDIO_FAKE); | 274 output_params.set_format(AudioParameters::AUDIO_FAKE); |
| 274 } else if (params.effects() != output_params.effects()) { | 275 } else if (params.effects() != output_params.effects()) { |
| 275 // Turn off effects that weren't requested. | 276 // Turn off effects that weren't requested. |
| 276 output_params.set_effects(params.effects() & output_params.effects()); | 277 output_params.set_effects(params.effects() & output_params.effects()); |
| 277 } | 278 } |
| 278 } | 279 } |
| 279 | 280 |
| 280 DispatcherParams* dispatcher_params = | 281 std::unique_ptr<DispatcherParams> dispatcher_params = |
| 281 new DispatcherParams(params, output_params, output_device_id); | 282 base::MakeUnique<DispatcherParams>(params, output_params, |
| 283 output_device_id); |
| 282 | 284 |
| 283 AudioOutputDispatchers::iterator it = | 285 auto it = std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), |
| 284 std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), | 286 CompareByParams(dispatcher_params.get())); |
| 285 CompareByParams(dispatcher_params)); | 287 if (it != output_dispatchers_.end()) |
| 286 if (it != output_dispatchers_.end()) { | |
| 287 delete dispatcher_params; | |
| 288 return (*it)->dispatcher->CreateStreamProxy(); | 288 return (*it)->dispatcher->CreateStreamProxy(); |
| 289 } | |
| 290 | 289 |
| 291 const base::TimeDelta kCloseDelay = | 290 const base::TimeDelta kCloseDelay = |
| 292 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 291 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| 293 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 292 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 294 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 293 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
| 295 // Using unretained for |debug_recording_manager_| is safe since it | 294 // Using unretained for |debug_recording_manager_| is safe since it |
| 296 // outlives the dispatchers (cleared in Shutdown()). | 295 // outlives the dispatchers (cleared in Shutdown()). |
| 297 dispatcher = base::MakeUnique<AudioOutputResampler>( | 296 dispatcher = base::MakeUnique<AudioOutputResampler>( |
| 298 this, params, output_params, output_device_id, kCloseDelay, | 297 this, params, output_params, output_device_id, kCloseDelay, |
| 299 debug_recording_manager_ | 298 debug_recording_manager_ |
| 300 ? base::BindRepeating( | 299 ? base::BindRepeating( |
| 301 &AudioDebugRecordingManager::RegisterDebugRecordingSource, | 300 &AudioDebugRecordingManager::RegisterDebugRecordingSource, |
| 302 base::Unretained(debug_recording_manager_.get()), | 301 base::Unretained(debug_recording_manager_.get()), |
| 303 FILE_PATH_LITERAL("output")) | 302 FILE_PATH_LITERAL("output")) |
| 304 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); | 303 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); |
| 305 } else { | 304 } else { |
| 306 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 305 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 307 this, output_params, output_device_id, kCloseDelay); | 306 this, output_params, output_device_id, kCloseDelay); |
| 308 } | 307 } |
| 309 | 308 |
| 310 dispatcher_params->dispatcher = std::move(dispatcher); | 309 dispatcher_params->dispatcher = std::move(dispatcher); |
| 311 output_dispatchers_.push_back(dispatcher_params); | 310 output_dispatchers_.push_back(std::move(dispatcher_params)); |
| 312 return dispatcher_params->dispatcher->CreateStreamProxy(); | 311 return output_dispatchers_.back()->dispatcher->CreateStreamProxy(); |
| 313 } | 312 } |
| 314 | 313 |
| 315 void AudioManagerBase::ShowAudioInputSettings() { | 314 void AudioManagerBase::ShowAudioInputSettings() { |
| 316 } | 315 } |
| 317 | 316 |
| 318 void AudioManagerBase::GetAudioInputDeviceNames( | 317 void AudioManagerBase::GetAudioInputDeviceNames( |
| 319 AudioDeviceNames* device_names) { | 318 AudioDeviceNames* device_names) { |
| 320 } | 319 } |
| 321 | 320 |
| 322 void AudioManagerBase::GetAudioOutputDeviceNames( | 321 void AudioManagerBase::GetAudioOutputDeviceNames( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 std::move(task_runner), std::move(file_task_runner)); | 486 std::move(task_runner), std::move(file_task_runner)); |
| 488 } | 487 } |
| 489 | 488 |
| 490 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 489 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| 491 int max_output) { | 490 int max_output) { |
| 492 max_num_output_streams_ = max_output; | 491 max_num_output_streams_ = max_output; |
| 493 max_num_input_streams_ = max_input; | 492 max_num_input_streams_ = max_input; |
| 494 } | 493 } |
| 495 | 494 |
| 496 } // namespace media | 495 } // namespace media |
| OLD | NEW |