Index: media/audio/audio_debug_recording_manager.cc |
diff --git a/media/audio/audio_debug_recording_manager.cc b/media/audio/audio_debug_recording_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d5d857cedd962df0d67387b8cf230afd6b4b101a |
--- /dev/null |
+++ b/media/audio/audio_debug_recording_manager.cc |
@@ -0,0 +1,113 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/audio/audio_debug_recording_manager.h" |
+ |
+#include "base/bind.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/single_thread_task_runner.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "media/audio/audio_manager.h" |
+ |
+namespace media { |
+ |
+namespace { |
+ |
+// Running id recording sources. |
+int g_next_stream_id = 1; |
+ |
+} // namespace |
+ |
+AudioDebugRecorderWrapper::AudioDebugRecorderWrapper( |
+ std::unique_ptr<AudioDebugRecorder> recorder, |
+ UnregisterAudioDebugRecorderCallback unregister_callback) |
+ : recorder(std::move(recorder)), unregister_callback(unregister_callback) {} |
+ |
+AudioDebugRecorderWrapper::~AudioDebugRecorderWrapper() {} |
+ |
+AudioDebugRecordingManager::AudioDebugRecordingManager( |
+ CreateAudioFileWriterCallback create_audio_file_writer_callback, |
+ const std::string& file_name_extension, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
+ : create_audio_file_writer_callback_( |
+ std::move(create_audio_file_writer_callback)), |
+ file_name_extension_(file_name_extension), |
+ task_runner_(std::move(task_runner)) { |
+ DCHECK(create_audio_file_writer_callback_); |
+} |
+ |
+AudioDebugRecordingManager::~AudioDebugRecordingManager() {} |
+ |
+void AudioDebugRecordingManager::EnableDebugRecording( |
+ const base::FilePath& base_file_name) { |
+ DCHECK(task_runner_->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 AudioDebugRecordingManager::DisableDebugRecording() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ for (const auto& it : debug_recording_helpers_) |
+ it.second->DisableDebugRecording(); |
+ debug_recording_base_file_name_.clear(); |
+} |
+ |
+AudioDebugRecorderWrapperUniquePtr |
+AudioDebugRecordingManager::RegisterDebugRecordingSource( |
+ const AudioParameters& params) { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ |
+ std::unique_ptr<AudioDebugRecordingHelper> recording_helper = |
+ base::MakeUnique<AudioDebugRecordingHelper>( |
+ params, create_audio_file_writer_callback_, task_runner_); |
+ |
+ const int id = g_next_stream_id++; |
+ |
+ if (!debug_recording_base_file_name_.empty()) { |
+ recording_helper->EnableDebugRecording( |
+ GetOutputDebugRecordingFileNameWithExtensions( |
+ debug_recording_base_file_name_, id)); |
+ } |
+ |
+ debug_recording_helpers_[id] = recording_helper.get(); |
+ |
+ AudioDebugRecorderWrapperUniquePtr recorder_wrapper( |
+ new AudioDebugRecorderWrapper( |
+ std::move(recording_helper), |
+ base::Bind( |
+ &AudioDebugRecordingManager::UnregisterDebugRecordingSource, |
+ base::Unretained(this), id))); |
+ |
+ return recorder_wrapper; |
+} |
+ |
+void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ auto it = debug_recording_helpers_.find(id); |
+ DCHECK(it != debug_recording_helpers_.end()); |
+ it->second->DisableDebugRecording(); |
o1ka
2017/01/27 09:25:26
The code implies that the helper is still alive. D
Henrik Grunell
2017/01/27 16:07:23
I removed this, it's not necessary since unregistr
|
+ debug_recording_helpers_.erase(id); |
+} |
+ |
+#if defined(OS_WIN) |
+#define IntToStringType base::IntToString16 |
+#else |
+#define IntToStringType base::IntToString |
+#endif |
+ |
+base::FilePath |
+AudioDebugRecordingManager::GetOutputDebugRecordingFileNameWithExtensions( |
+ const base::FilePath& file_name, |
+ int id) { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ return file_name.AddExtension(file_name_extension_) |
+ .AddExtension(IntToStringType(id)); |
+} |
+ |
+} // namespace media |