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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 77 |
78 AudioManagerBase::AudioManagerBase( | 78 AudioManagerBase::AudioManagerBase( |
79 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
80 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 80 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
81 AudioLogFactory* audio_log_factory) | 81 AudioLogFactory* audio_log_factory) |
82 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), | 82 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), |
83 max_num_output_streams_(kDefaultMaxOutputStreams), | 83 max_num_output_streams_(kDefaultMaxOutputStreams), |
84 max_num_input_streams_(kDefaultMaxInputStreams), | 84 max_num_input_streams_(kDefaultMaxInputStreams), |
85 num_output_streams_(0), | 85 num_output_streams_(0), |
86 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we | 86 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we |
87 // don't | 87 // don't block the UI thread when swapping devices. |
88 // block the UI thread when swapping devices. | |
89 output_listeners_( | 88 output_listeners_( |
90 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), | 89 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
91 audio_log_factory_(audio_log_factory) {} | 90 audio_log_factory_(audio_log_factory) {} |
92 | 91 |
93 AudioManagerBase::~AudioManagerBase() { | 92 AudioManagerBase::~AudioManagerBase() { |
94 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 93 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
95 | 94 |
96 // All the output streams should have been deleted. | 95 // All the output streams should have been deleted. |
97 CHECK_EQ(0, num_output_streams_); | 96 CHECK_EQ(0, num_output_streams_); |
98 // All the input streams should have been deleted. | 97 // All the input streams should have been deleted. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 CompareByParams(dispatcher_params)); | 277 CompareByParams(dispatcher_params)); |
279 if (it != output_dispatchers_.end()) { | 278 if (it != output_dispatchers_.end()) { |
280 delete dispatcher_params; | 279 delete dispatcher_params; |
281 return (*it)->dispatcher->CreateStreamProxy(); | 280 return (*it)->dispatcher->CreateStreamProxy(); |
282 } | 281 } |
283 | 282 |
284 const base::TimeDelta kCloseDelay = | 283 const base::TimeDelta kCloseDelay = |
285 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 284 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
286 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 285 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
287 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 286 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
287 // If |debug_recording_manager_| is set we tell AudioOutputResampler to | |
288 // register sources with it. | |
289 AudioOutputResampler::RegisterDebugRecordingSourceCallback | |
290 register_debug_recording_source_callback; | |
291 if (debug_recording_manager_) { | |
292 // Using unretained is safe since |debug_recording_manager_| | |
293 // outlives the dispatchers (cleared in Shutdown()). | |
294 register_debug_recording_source_callback = base::BindRepeating( | |
295 &AudioDebugRecordingManager::RegisterDebugRecordingSource, | |
296 base::Unretained(debug_recording_manager_.get()), "output"); | |
297 } | |
288 dispatcher = base::MakeUnique<AudioOutputResampler>( | 298 dispatcher = base::MakeUnique<AudioOutputResampler>( |
289 this, params, output_params, output_device_id, kCloseDelay); | 299 this, params, output_params, output_device_id, kCloseDelay, |
300 register_debug_recording_source_callback); | |
o1ka
2017/02/09 13:04:03
just (debug_recording_manager_) ? base::BindRepea
Henrik Grunell
2017/02/10 09:00:56
Done.
| |
290 } else { | 301 } else { |
291 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 302 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
292 this, output_params, output_device_id, kCloseDelay); | 303 this, output_params, output_device_id, kCloseDelay); |
293 } | 304 } |
294 | 305 |
295 dispatcher_params->dispatcher = std::move(dispatcher); | 306 dispatcher_params->dispatcher = std::move(dispatcher); |
296 output_dispatchers_.push_back(dispatcher_params); | 307 output_dispatchers_.push_back(dispatcher_params); |
297 return dispatcher_params->dispatcher->CreateStreamProxy(); | 308 return dispatcher_params->dispatcher->CreateStreamProxy(); |
298 } | 309 } |
299 | 310 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 return buffer_size; | 437 return buffer_size; |
427 | 438 |
428 return 0; | 439 return 0; |
429 } | 440 } |
430 | 441 |
431 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 442 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
432 AudioLogFactory::AudioComponent component) { | 443 AudioLogFactory::AudioComponent component) { |
433 return audio_log_factory_->CreateAudioLog(component); | 444 return audio_log_factory_->CreateAudioLog(component); |
434 } | 445 } |
435 | 446 |
447 void AudioManagerBase::InitializeOutputDebugRecording( | |
448 CreateAudioFileWriterCallback create_audio_file_writer_callback) { | |
449 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
450 DCHECK(!debug_recording_manager_); | |
451 debug_recording_manager_ = base::MakeUnique<AudioDebugRecordingManager>( | |
452 create_audio_file_writer_callback, GetTaskRunner()); | |
453 } | |
454 | |
455 void AudioManagerBase::EnableOutputDebugRecording( | |
456 const base::FilePath& base_file_name) { | |
457 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
458 debug_recording_manager_->EnableDebugRecording(base_file_name); | |
o1ka
2017/02/09 13:04:03
if (debug_recording_manager_)?
Looks like unit tes
Henrik Grunell
2017/02/10 09:00:56
I wrote answer in a previous comment answer. :) Th
o1ka
2017/02/10 15:21:53
This intention is not obvious at all.
DCHECK(debug
Henrik Grunell
2017/02/13 15:16:48
Yeah, it's only in the header comment in AudioMana
| |
459 } | |
460 | |
461 void AudioManagerBase::DisableOutputDebugRecording() { | |
462 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
463 if (debug_recording_manager_) | |
464 debug_recording_manager_->DisableDebugRecording(); | |
465 } | |
466 | |
436 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 467 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
437 int max_output) { | 468 int max_output) { |
438 max_num_output_streams_ = max_output; | 469 max_num_output_streams_ = max_output; |
439 max_num_input_streams_ = max_input; | 470 max_num_input_streams_ = max_input; |
440 } | 471 } |
441 | 472 |
442 } // namespace media | 473 } // namespace media |
OLD | NEW |