| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_debug_recording_manager.h" | 5 #include "media/audio/audio_debug_recording_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const base::FilePath& base_file_name, | 29 const base::FilePath& base_file_name, |
| 30 const base::FilePath::StringType& file_name_extension, | 30 const base::FilePath::StringType& file_name_extension, |
| 31 int id) { | 31 int id) { |
| 32 return base_file_name.AddExtension(file_name_extension) | 32 return base_file_name.AddExtension(file_name_extension) |
| 33 .AddExtension(IntToStringType(id)); | 33 .AddExtension(IntToStringType(id)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 AudioDebugRecordingManager::AudioDebugRecordingManager( | 38 AudioDebugRecordingManager::AudioDebugRecordingManager( |
| 39 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 40 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) | 40 : task_runner_(std::move(task_runner)), weak_factory_(this) {} |
| 41 : task_runner_(std::move(task_runner)), | |
| 42 file_task_runner_(std::move(file_task_runner)), | |
| 43 weak_factory_(this) {} | |
| 44 | 41 |
| 45 AudioDebugRecordingManager::~AudioDebugRecordingManager() {} | 42 AudioDebugRecordingManager::~AudioDebugRecordingManager() {} |
| 46 | 43 |
| 47 void AudioDebugRecordingManager::EnableDebugRecording( | 44 void AudioDebugRecordingManager::EnableDebugRecording( |
| 48 const base::FilePath& base_file_name) { | 45 const base::FilePath& base_file_name) { |
| 49 DCHECK(task_runner_->BelongsToCurrentThread()); | 46 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 50 DCHECK(!base_file_name.empty()); | 47 DCHECK(!base_file_name.empty()); |
| 51 | 48 |
| 52 for (const auto& it : debug_recording_helpers_) { | 49 for (const auto& it : debug_recording_helpers_) { |
| 53 it.second.first->EnableDebugRecording( | 50 it.second.first->EnableDebugRecording( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 const base::FilePath::StringType& file_name_extension, | 66 const base::FilePath::StringType& file_name_extension, |
| 70 const AudioParameters& params) { | 67 const AudioParameters& params) { |
| 71 DCHECK(task_runner_->BelongsToCurrentThread()); | 68 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 72 | 69 |
| 73 const int id = g_next_stream_id++; | 70 const int id = g_next_stream_id++; |
| 74 | 71 |
| 75 // Normally, the manager will outlive the one who registers and owns the | 72 // Normally, the manager will outlive the one who registers and owns the |
| 76 // returned recorder. But to not require this we use a weak pointer. | 73 // returned recorder. But to not require this we use a weak pointer. |
| 77 std::unique_ptr<AudioDebugRecordingHelper> recording_helper = | 74 std::unique_ptr<AudioDebugRecordingHelper> recording_helper = |
| 78 CreateAudioDebugRecordingHelper( | 75 CreateAudioDebugRecordingHelper( |
| 79 params, task_runner_, file_task_runner_, | 76 params, task_runner_, |
| 80 base::BindOnce( | 77 base::BindOnce( |
| 81 &AudioDebugRecordingManager::UnregisterDebugRecordingSource, | 78 &AudioDebugRecordingManager::UnregisterDebugRecordingSource, |
| 82 weak_factory_.GetWeakPtr(), id)); | 79 weak_factory_.GetWeakPtr(), id)); |
| 83 | 80 |
| 84 if (IsDebugRecordingEnabled()) { | 81 if (IsDebugRecordingEnabled()) { |
| 85 recording_helper->EnableDebugRecording( | 82 recording_helper->EnableDebugRecording( |
| 86 GetOutputDebugRecordingFileNameWithExtensions( | 83 GetOutputDebugRecordingFileNameWithExtensions( |
| 87 debug_recording_base_file_name_, file_name_extension, id)); | 84 debug_recording_base_file_name_, file_name_extension, id)); |
| 88 } | 85 } |
| 89 | 86 |
| 90 debug_recording_helpers_[id] = | 87 debug_recording_helpers_[id] = |
| 91 std::make_pair(recording_helper.get(), file_name_extension); | 88 std::make_pair(recording_helper.get(), file_name_extension); |
| 92 | 89 |
| 93 return base::WrapUnique<AudioDebugRecorder>(recording_helper.release()); | 90 return base::WrapUnique<AudioDebugRecorder>(recording_helper.release()); |
| 94 } | 91 } |
| 95 | 92 |
| 96 void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) { | 93 void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) { |
| 97 DCHECK(task_runner_->BelongsToCurrentThread()); | 94 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 98 auto it = debug_recording_helpers_.find(id); | 95 auto it = debug_recording_helpers_.find(id); |
| 99 DCHECK(it != debug_recording_helpers_.end()); | 96 DCHECK(it != debug_recording_helpers_.end()); |
| 100 debug_recording_helpers_.erase(id); | 97 debug_recording_helpers_.erase(id); |
| 101 } | 98 } |
| 102 | 99 |
| 103 std::unique_ptr<AudioDebugRecordingHelper> | 100 std::unique_ptr<AudioDebugRecordingHelper> |
| 104 AudioDebugRecordingManager::CreateAudioDebugRecordingHelper( | 101 AudioDebugRecordingManager::CreateAudioDebugRecordingHelper( |
| 105 const AudioParameters& params, | 102 const AudioParameters& params, |
| 106 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 103 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 107 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | |
| 108 base::OnceClosure on_destruction_closure) { | 104 base::OnceClosure on_destruction_closure) { |
| 109 return base::MakeUnique<AudioDebugRecordingHelper>( | 105 return base::MakeUnique<AudioDebugRecordingHelper>( |
| 110 params, task_runner, file_task_runner, std::move(on_destruction_closure)); | 106 params, task_runner, std::move(on_destruction_closure)); |
| 111 } | 107 } |
| 112 | 108 |
| 113 bool AudioDebugRecordingManager::IsDebugRecordingEnabled() { | 109 bool AudioDebugRecordingManager::IsDebugRecordingEnabled() { |
| 114 DCHECK(task_runner_->BelongsToCurrentThread()); | 110 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 115 return !debug_recording_base_file_name_.empty(); | 111 return !debug_recording_base_file_name_.empty(); |
| 116 } | 112 } |
| 117 | 113 |
| 118 } // namespace media | 114 } // namespace media |
| OLD | NEW |