| 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 // Using unretained for |debug_recording_manager_| is safe since it |
| 288 // outlives the dispatchers (cleared in Shutdown()). |
| 288 dispatcher = base::MakeUnique<AudioOutputResampler>( | 289 dispatcher = base::MakeUnique<AudioOutputResampler>( |
| 289 this, params, output_params, output_device_id, kCloseDelay); | 290 this, params, output_params, output_device_id, kCloseDelay, |
| 291 debug_recording_manager_ |
| 292 ? base::BindRepeating( |
| 293 &AudioDebugRecordingManager::RegisterDebugRecordingSource, |
| 294 base::Unretained(debug_recording_manager_.get()), "output") |
| 295 : AudioOutputResampler::RegisterDebugRecordingSourceCallback()); |
| 290 } else { | 296 } else { |
| 291 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 297 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 292 this, output_params, output_device_id, kCloseDelay); | 298 this, output_params, output_device_id, kCloseDelay); |
| 293 } | 299 } |
| 294 | 300 |
| 295 dispatcher_params->dispatcher = std::move(dispatcher); | 301 dispatcher_params->dispatcher = std::move(dispatcher); |
| 296 output_dispatchers_.push_back(dispatcher_params); | 302 output_dispatchers_.push_back(dispatcher_params); |
| 297 return dispatcher_params->dispatcher->CreateStreamProxy(); | 303 return dispatcher_params->dispatcher->CreateStreamProxy(); |
| 298 } | 304 } |
| 299 | 305 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 return buffer_size; | 432 return buffer_size; |
| 427 | 433 |
| 428 return 0; | 434 return 0; |
| 429 } | 435 } |
| 430 | 436 |
| 431 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 437 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| 432 AudioLogFactory::AudioComponent component) { | 438 AudioLogFactory::AudioComponent component) { |
| 433 return audio_log_factory_->CreateAudioLog(component); | 439 return audio_log_factory_->CreateAudioLog(component); |
| 434 } | 440 } |
| 435 | 441 |
| 442 void AudioManagerBase::InitializeOutputDebugRecording( |
| 443 AudioFileWriter::CreateCallback create_audio_file_writer_callback) { |
| 444 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 445 DCHECK(!debug_recording_manager_); |
| 446 debug_recording_manager_ = CreateAudioDebugRecordingManager( |
| 447 create_audio_file_writer_callback, GetTaskRunner()); |
| 448 } |
| 449 |
| 450 void AudioManagerBase::EnableOutputDebugRecording( |
| 451 const base::FilePath& base_file_name) { |
| 452 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 453 debug_recording_manager_->EnableDebugRecording(base_file_name); |
| 454 } |
| 455 |
| 456 void AudioManagerBase::DisableOutputDebugRecording() { |
| 457 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 458 if (debug_recording_manager_) |
| 459 debug_recording_manager_->DisableDebugRecording(); |
| 460 } |
| 461 |
| 462 std::unique_ptr<AudioDebugRecordingManager> |
| 463 AudioManagerBase::CreateAudioDebugRecordingManager( |
| 464 AudioFileWriter::CreateCallback create_audio_file_writer_callback, |
| 465 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 466 return base::MakeUnique<AudioDebugRecordingManager>( |
| 467 std::move(create_audio_file_writer_callback), std::move(task_runner)); |
| 468 } |
| 469 |
| 436 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 470 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| 437 int max_output) { | 471 int max_output) { |
| 438 max_num_output_streams_ = max_output; | 472 max_num_output_streams_ = max_output; |
| 439 max_num_input_streams_ = max_input; | 473 max_num_input_streams_ = max_input; |
| 440 } | 474 } |
| 441 | 475 |
| 442 } // namespace media | 476 } // namespace media |
| OLD | NEW |