| 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 18 matching lines...) Expand all Loading... |
| 29 // Default maximum number of output streams that can be open simultaneously | 29 // Default maximum number of output streams that can be open simultaneously |
| 30 // for all platforms. | 30 // for all platforms. |
| 31 const int kDefaultMaxOutputStreams = 32; | 31 const int kDefaultMaxOutputStreams = 32; |
| 32 | 32 |
| 33 // Default maximum number of input streams that can be open simultaneously | 33 // Default maximum number of input streams that can be open simultaneously |
| 34 // for all platforms. | 34 // for all platforms. |
| 35 const int kDefaultMaxInputStreams = 32; | 35 const int kDefaultMaxInputStreams = 32; |
| 36 | 36 |
| 37 const int kMaxInputChannels = 3; | 37 const int kMaxInputChannels = 3; |
| 38 | 38 |
| 39 // Helper function to pass as callback when the audio debug recording is not |
| 40 // enabled. |
| 41 std::unique_ptr<AudioDebugRecorder> GetNullptrAudioDebugRecorder( |
| 42 const AudioParameters& params) { |
| 43 return nullptr; |
| 44 } |
| 45 |
| 39 } // namespace | 46 } // namespace |
| 40 | 47 |
| 41 struct AudioManagerBase::DispatcherParams { | 48 struct AudioManagerBase::DispatcherParams { |
| 42 DispatcherParams(const AudioParameters& input, | 49 DispatcherParams(const AudioParameters& input, |
| 43 const AudioParameters& output, | 50 const AudioParameters& output, |
| 44 const std::string& output_device_id) | 51 const std::string& output_device_id) |
| 45 : input_params(input), | 52 : input_params(input), |
| 46 output_params(output), | 53 output_params(output), |
| 47 output_device_id(output_device_id) {} | 54 output_device_id(output_device_id) {} |
| 48 ~DispatcherParams() {} | 55 ~DispatcherParams() {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 77 | 84 |
| 78 AudioManagerBase::AudioManagerBase( | 85 AudioManagerBase::AudioManagerBase( |
| 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 86 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 80 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 81 AudioLogFactory* audio_log_factory) | 88 AudioLogFactory* audio_log_factory) |
| 82 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), | 89 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), |
| 83 max_num_output_streams_(kDefaultMaxOutputStreams), | 90 max_num_output_streams_(kDefaultMaxOutputStreams), |
| 84 max_num_input_streams_(kDefaultMaxInputStreams), | 91 max_num_input_streams_(kDefaultMaxInputStreams), |
| 85 num_output_streams_(0), | 92 num_output_streams_(0), |
| 86 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we | 93 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we |
| 87 // don't | 94 // don't block the UI thread when swapping devices. |
| 88 // block the UI thread when swapping devices. | |
| 89 output_listeners_( | 95 output_listeners_( |
| 90 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), | 96 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
| 91 audio_log_factory_(audio_log_factory) {} | 97 audio_log_factory_(audio_log_factory) {} |
| 92 | 98 |
| 93 AudioManagerBase::~AudioManagerBase() { | 99 AudioManagerBase::~AudioManagerBase() { |
| 94 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 100 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 95 | 101 |
| 96 // All the output streams should have been deleted. | 102 // All the output streams should have been deleted. |
| 97 CHECK_EQ(0, num_output_streams_); | 103 CHECK_EQ(0, num_output_streams_); |
| 98 // All the input streams should have been deleted. | 104 // 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)); | 284 CompareByParams(dispatcher_params)); |
| 279 if (it != output_dispatchers_.end()) { | 285 if (it != output_dispatchers_.end()) { |
| 280 delete dispatcher_params; | 286 delete dispatcher_params; |
| 281 return (*it)->dispatcher->CreateStreamProxy(); | 287 return (*it)->dispatcher->CreateStreamProxy(); |
| 282 } | 288 } |
| 283 | 289 |
| 284 const base::TimeDelta kCloseDelay = | 290 const base::TimeDelta kCloseDelay = |
| 285 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 291 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| 286 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 292 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| 287 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 293 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
| 294 // Using unretained for |debug_recording_manager_| is safe since it |
| 295 // outlives the dispatchers (cleared in Shutdown()). |
| 288 dispatcher = base::MakeUnique<AudioOutputResampler>( | 296 dispatcher = base::MakeUnique<AudioOutputResampler>( |
| 289 this, params, output_params, output_device_id, kCloseDelay); | 297 this, params, output_params, output_device_id, kCloseDelay, |
| 298 debug_recording_manager_ |
| 299 ? base::BindRepeating( |
| 300 &AudioDebugRecordingManager::RegisterDebugRecordingSource, |
| 301 base::Unretained(debug_recording_manager_.get()), |
| 302 FILE_PATH_LITERAL("output")) |
| 303 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); |
| 290 } else { | 304 } else { |
| 291 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 305 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 292 this, output_params, output_device_id, kCloseDelay); | 306 this, output_params, output_device_id, kCloseDelay); |
| 293 } | 307 } |
| 294 | 308 |
| 295 dispatcher_params->dispatcher = std::move(dispatcher); | 309 dispatcher_params->dispatcher = std::move(dispatcher); |
| 296 output_dispatchers_.push_back(dispatcher_params); | 310 output_dispatchers_.push_back(dispatcher_params); |
| 297 return dispatcher_params->dispatcher->CreateStreamProxy(); | 311 return dispatcher_params->dispatcher->CreateStreamProxy(); |
| 298 } | 312 } |
| 299 | 313 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 return buffer_size; | 440 return buffer_size; |
| 427 | 441 |
| 428 return 0; | 442 return 0; |
| 429 } | 443 } |
| 430 | 444 |
| 431 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 445 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| 432 AudioLogFactory::AudioComponent component) { | 446 AudioLogFactory::AudioComponent component) { |
| 433 return audio_log_factory_->CreateAudioLog(component); | 447 return audio_log_factory_->CreateAudioLog(component); |
| 434 } | 448 } |
| 435 | 449 |
| 450 void AudioManagerBase::InitializeOutputDebugRecording( |
| 451 AudioFileWriter::CreateCallback create_audio_file_writer_callback) { |
| 452 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 453 DCHECK(!debug_recording_manager_); |
| 454 debug_recording_manager_ = CreateAudioDebugRecordingManager( |
| 455 create_audio_file_writer_callback, GetTaskRunner()); |
| 456 } |
| 457 |
| 458 void AudioManagerBase::EnableOutputDebugRecording( |
| 459 const base::FilePath& base_file_name) { |
| 460 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 461 DCHECK(debug_recording_manager_) |
| 462 << "InitializeOutputDebugRecording() must be called before enabling"; |
| 463 debug_recording_manager_->EnableDebugRecording(base_file_name); |
| 464 } |
| 465 |
| 466 void AudioManagerBase::DisableOutputDebugRecording() { |
| 467 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 468 if (debug_recording_manager_) |
| 469 debug_recording_manager_->DisableDebugRecording(); |
| 470 } |
| 471 |
| 472 std::unique_ptr<AudioDebugRecordingManager> |
| 473 AudioManagerBase::CreateAudioDebugRecordingManager( |
| 474 AudioFileWriter::CreateCallback create_audio_file_writer_callback, |
| 475 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 476 return base::MakeUnique<AudioDebugRecordingManager>( |
| 477 std::move(create_audio_file_writer_callback), std::move(task_runner)); |
| 478 } |
| 479 |
| 436 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 480 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| 437 int max_output) { | 481 int max_output) { |
| 438 max_num_output_streams_ = max_output; | 482 max_num_output_streams_ = max_output; |
| 439 max_num_input_streams_ = max_input; | 483 max_num_input_streams_ = max_input; |
| 440 } | 484 } |
| 441 | 485 |
| 442 } // namespace media | 486 } // namespace media |
| OLD | NEW |