Chromium Code Reviews| Index: media/audio/audio_manager_base.cc |
| diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc |
| index 670820dc3a6ad0f446d429cd97b4e3a7484f5c67..06ff8ea61f1720ea9d8380ba4b9e759a6c0d3226 100644 |
| --- a/media/audio/audio_manager_base.cc |
| +++ b/media/audio/audio_manager_base.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "build/build_config.h" |
| +#include "media/audio/audio_debug_recording_helper.h" |
| #include "media/audio/audio_device_description.h" |
| #include "media/audio/audio_output_dispatcher_impl.h" |
| #include "media/audio/audio_output_proxy.h" |
| @@ -36,6 +37,19 @@ const int kDefaultMaxInputStreams = 32; |
| const int kMaxInputChannels = 3; |
| +#if defined(OS_WIN) |
| +#define IntToStringType base::IntToString16 |
| +#else |
| +#define IntToStringType base::IntToString |
| +#endif |
| + |
| +// Helper function. |
| +base::FilePath GetOutputDebugRecordingFileNameWithExtensions( |
| + const base::FilePath& file_name, |
| + int id) { |
| + return file_name.AddExtension("output").AddExtension(IntToStringType(id)); |
| +} |
| + |
| } // namespace |
| struct AudioManagerBase::DispatcherParams { |
| @@ -78,17 +92,21 @@ class AudioManagerBase::CompareByParams { |
| AudioManagerBase::AudioManagerBase( |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| - AudioLogFactory* audio_log_factory) |
| + AudioLogFactory* audio_log_factory, |
| + CreateAudioFileWriterCallback create_audio_file_writer_callback) |
| : AudioManager(std::move(task_runner), std::move(worker_task_runner)), |
| max_num_output_streams_(kDefaultMaxOutputStreams), |
| max_num_input_streams_(kDefaultMaxInputStreams), |
| num_output_streams_(0), |
| // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we |
| - // don't |
| - // block the UI thread when swapping devices. |
| + // don't block the UI thread when swapping devices. |
| output_listeners_( |
| base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
| - audio_log_factory_(audio_log_factory) {} |
| + audio_log_factory_(audio_log_factory), |
| + create_audio_file_writer_callback_( |
| + std::move(create_audio_file_writer_callback)) { |
| + DCHECK(create_audio_file_writer_callback_); |
| +} |
| AudioManagerBase::~AudioManagerBase() { |
| DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| @@ -285,8 +303,19 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
| std::unique_ptr<AudioOutputDispatcher> dispatcher; |
| if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
| - dispatcher = base::MakeUnique<AudioOutputResampler>( |
| - this, params, output_params, output_device_id, kCloseDelay); |
| + std::unique_ptr<AudioOutputResampler> resampler = |
| + base::MakeUnique<AudioOutputResampler>(this, params, output_params, |
| + output_device_id, kCloseDelay); |
| + |
| + resampler->SetDebugRecordingCallbacks( |
| + base::Bind(&AudioManagerBase::RegisterDebugRecordingSource, |
| + base::Unretained(this)), |
| + base::Bind(&AudioManagerBase::UnregisterDebugRecordingSource, |
| + base::Unretained(this)), |
| + base::Bind(&AudioManagerBase::OnDebugRecordingData, |
| + base::Unretained(this))); |
| + |
| + dispatcher = std::move(resampler); |
| } else { |
| dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
| this, output_params, output_device_id, kCloseDelay); |
| @@ -433,6 +462,54 @@ std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| return audio_log_factory_->CreateAudioLog(component); |
| } |
| +void AudioManagerBase::EnableOutputDebugRecording( |
| + const base::FilePath& base_file_name) { |
| + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| + for (const auto& it : debug_recording_helpers_) { |
| + it.second->EnableDebugRecording( |
| + GetOutputDebugRecordingFileNameWithExtensions(base_file_name, |
| + it.first)); |
| + } |
| + debug_recording_base_file_name_ = base_file_name; |
| +} |
| + |
| +void AudioManagerBase::DisableOutputDebugRecording() { |
| + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| + for (const auto& it : debug_recording_helpers_) |
| + it.second->DisableDebugRecording(); |
| + debug_recording_base_file_name_.clear(); |
| +} |
| + |
| +void AudioManagerBase::RegisterDebugRecordingSource( |
|
o1ka
2017/01/25 17:47:00
If keeping this logic, could you move it into a he
Henrik Grunell
2017/01/26 10:25:09
Yep, agree.
|
| + int id, |
| + const AudioParameters& params) { |
| + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| + DCHECK(debug_recording_helpers_.find(id) == debug_recording_helpers_.end()); |
| + debug_recording_helpers_[id] = base::MakeUnique<AudioDebugRecordingHelper>( |
| + params, create_audio_file_writer_callback_, GetTaskRunner()); |
| + if (!debug_recording_base_file_name_.empty()) { |
| + debug_recording_helpers_[id]->EnableDebugRecording( |
| + GetOutputDebugRecordingFileNameWithExtensions( |
| + debug_recording_base_file_name_, id)); |
| + } |
| +} |
| + |
| +void AudioManagerBase::UnregisterDebugRecordingSource(int id) { |
| + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| + auto it = debug_recording_helpers_.find(id); |
| + DCHECK(it != debug_recording_helpers_.end()); |
| + it->second->DisableDebugRecording(); |
| + debug_recording_helpers_.erase(id); |
| +} |
| + |
| +void AudioManagerBase::OnDebugRecordingData(int id, AudioBus* data) { |
| + // TODO BEFORE COMMIT: Comment on why accessing |debug_recording_helpers_| |
| + // here is safe. |
|
o1ka
2017/01/25 17:47:00
This does not looks like a good separation of conc
Henrik Grunell
2017/01/26 10:25:09
Yes, will do.
|
| + auto it = debug_recording_helpers_.find(id); |
| + DCHECK(it != debug_recording_helpers_.end()); |
| + it->second->MaybeWrite(data); |
| +} |
| + |
| void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| int max_output) { |
| max_num_output_streams_ = max_output; |