Chromium Code Reviews| 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_ptr = |
| 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 DispatcherParams* dispatcher_params = dispatcher_params_ptr.get(); |
|
tommi (sloooow) - chröme
2017/05/05 08:58:43
nit: just remove this variable and pass dispatcher
Chandan
2017/05/05 09:19:32
Done.
| |
| 284 std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), | 286 |
| 285 CompareByParams(dispatcher_params)); | 287 auto it = std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), |
| 288 CompareByParams(dispatcher_params)); | |
| 286 if (it != output_dispatchers_.end()) { | 289 if (it != output_dispatchers_.end()) { |
| 287 delete dispatcher_params; | 290 dispatcher_params_ptr.reset(); |
|
tommi (sloooow) - chröme
2017/05/05 08:58:43
necessary? dispatcher_params_ptr is about to go ou
Chandan
2017/05/05 09:19:32
Right. This can be dropped.
| |
| 288 return (*it)->dispatcher->CreateStreamProxy(); | 291 return (*it)->dispatcher->CreateStreamProxy(); |
| 289 } | 292 } |
| 290 | 293 |
| 291 const base::TimeDelta kCloseDelay = | 294 const base::TimeDelta kCloseDelay = |
| 292 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 295 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| 293 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 296 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 294 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 297 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
| 295 // Using unretained for |debug_recording_manager_| is safe since it | 298 // Using unretained for |debug_recording_manager_| is safe since it |
| 296 // outlives the dispatchers (cleared in Shutdown()). | 299 // outlives the dispatchers (cleared in Shutdown()). |
| 297 dispatcher = base::MakeUnique<AudioOutputResampler>( | 300 dispatcher = base::MakeUnique<AudioOutputResampler>( |
| 298 this, params, output_params, output_device_id, kCloseDelay, | 301 this, params, output_params, output_device_id, kCloseDelay, |
| 299 debug_recording_manager_ | 302 debug_recording_manager_ |
| 300 ? base::BindRepeating( | 303 ? base::BindRepeating( |
| 301 &AudioDebugRecordingManager::RegisterDebugRecordingSource, | 304 &AudioDebugRecordingManager::RegisterDebugRecordingSource, |
| 302 base::Unretained(debug_recording_manager_.get()), | 305 base::Unretained(debug_recording_manager_.get()), |
| 303 FILE_PATH_LITERAL("output")) | 306 FILE_PATH_LITERAL("output")) |
| 304 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); | 307 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); |
| 305 } else { | 308 } else { |
| 306 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 309 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 307 this, output_params, output_device_id, kCloseDelay); | 310 this, output_params, output_device_id, kCloseDelay); |
| 308 } | 311 } |
| 309 | 312 |
| 310 dispatcher_params->dispatcher = std::move(dispatcher); | 313 dispatcher_params_ptr->dispatcher = std::move(dispatcher); |
| 311 output_dispatchers_.push_back(dispatcher_params); | 314 output_dispatchers_.push_back(std::move(dispatcher_params_ptr)); |
| 312 return dispatcher_params->dispatcher->CreateStreamProxy(); | 315 return dispatcher_params->dispatcher->CreateStreamProxy(); |
|
tommi (sloooow) - chröme
2017/05/05 08:58:43
If we're removing |dispatcher_params|, you'd have
Chandan
2017/05/05 09:19:32
Intention was to avoid accessing the vector. Initi
| |
| 313 } | 316 } |
| 314 | 317 |
| 315 void AudioManagerBase::ShowAudioInputSettings() { | 318 void AudioManagerBase::ShowAudioInputSettings() { |
| 316 } | 319 } |
| 317 | 320 |
| 318 void AudioManagerBase::GetAudioInputDeviceNames( | 321 void AudioManagerBase::GetAudioInputDeviceNames( |
| 319 AudioDeviceNames* device_names) { | 322 AudioDeviceNames* device_names) { |
| 320 } | 323 } |
| 321 | 324 |
| 322 void AudioManagerBase::GetAudioOutputDeviceNames( | 325 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)); | 490 std::move(task_runner), std::move(file_task_runner)); |
| 488 } | 491 } |
| 489 | 492 |
| 490 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 493 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| 491 int max_output) { | 494 int max_output) { |
| 492 max_num_output_streams_ = max_output; | 495 max_num_output_streams_ = max_output; |
| 493 max_num_input_streams_ = max_input; | 496 max_num_input_streams_ = max_input; |
| 494 } | 497 } |
| 495 | 498 |
| 496 } // namespace media | 499 } // namespace media |
| OLD | NEW |