Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: media/audio/audio_debug_recording_manager.cc

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Code review. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/audio/audio_debug_recording_manager.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_number_conversions.h"
12
13 namespace media {
14
15 namespace {
16
17 // Running id recording sources.
18 int g_next_stream_id = 1;
19
20 #if defined(OS_WIN)
21 #define IntToStringType base::IntToString16
22 #else
23 #define IntToStringType base::IntToString
24 #endif
25
26 // Helper function that returns |base_file_name| with |file_name_extension| and
27 // |id| added to it as as extensions.
28 base::FilePath GetOutputDebugRecordingFileNameWithExtensions(
29 const base::FilePath& base_file_name,
30 const base::FilePath::StringType& file_name_extension,
31 int id) {
32 return base_file_name.AddExtension(file_name_extension)
33 .AddExtension(IntToStringType(id));
34 }
35
36 } // namespace
37
38 AudioDebugRecordingManager::AudioDebugRecordingManager(
39 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
40 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
41 : task_runner_(std::move(task_runner)),
42 file_task_runner_(std::move(file_task_runner)),
43 weak_factory_(this) {}
44
45 AudioDebugRecordingManager::~AudioDebugRecordingManager() {}
46
47 void AudioDebugRecordingManager::EnableDebugRecording(
48 const base::FilePath& base_file_name) {
49 DCHECK(task_runner_->BelongsToCurrentThread());
50 DCHECK(!base_file_name.empty());
51
52 for (const auto& it : debug_recording_helpers_) {
53 it.second.first->EnableDebugRecording(
54 GetOutputDebugRecordingFileNameWithExtensions(
55 base_file_name, it.second.second, it.first));
56 }
57 debug_recording_base_file_name_ = base_file_name;
58 }
59
60 void AudioDebugRecordingManager::DisableDebugRecording() {
61 DCHECK(task_runner_->BelongsToCurrentThread());
62 for (const auto& it : debug_recording_helpers_)
63 it.second.first->DisableDebugRecording();
64 debug_recording_base_file_name_.clear();
65 }
66
67 std::unique_ptr<AudioDebugRecorder>
68 AudioDebugRecordingManager::RegisterDebugRecordingSource(
69 const base::FilePath::StringType& file_name_extension,
70 const AudioParameters& params) {
71 DCHECK(task_runner_->BelongsToCurrentThread());
72
73 const int id = g_next_stream_id++;
74
75 // 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.
77 std::unique_ptr<AudioDebugRecordingHelper> recording_helper =
78 CreateAudioDebugRecordingHelper(
79 params, task_runner_, file_task_runner_,
80 base::BindOnce(
81 &AudioDebugRecordingManager::UnregisterDebugRecordingSource,
82 weak_factory_.GetWeakPtr(), id));
83
84 if (IsDebugRecordingEnabled()) {
85 recording_helper->EnableDebugRecording(
86 GetOutputDebugRecordingFileNameWithExtensions(
87 debug_recording_base_file_name_, file_name_extension, id));
88 }
89
90 debug_recording_helpers_[id] =
91 std::make_pair(recording_helper.get(), file_name_extension);
92
93 return base::WrapUnique<AudioDebugRecorder>(recording_helper.release());
94 }
95
96 void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) {
97 DCHECK(task_runner_->BelongsToCurrentThread());
98 auto it = debug_recording_helpers_.find(id);
99 DCHECK(it != debug_recording_helpers_.end());
100 debug_recording_helpers_.erase(id);
101 }
102
103 std::unique_ptr<AudioDebugRecordingHelper>
104 AudioDebugRecordingManager::CreateAudioDebugRecordingHelper(
105 const AudioParameters& params,
106 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
107 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
108 base::OnceClosure on_destruction_closure) {
109 return base::MakeUnique<AudioDebugRecordingHelper>(
110 params, task_runner, file_task_runner, std::move(on_destruction_closure));
111 }
112
113 bool AudioDebugRecordingManager::IsDebugRecordingEnabled() {
114 DCHECK(task_runner_->BelongsToCurrentThread());
115 return !debug_recording_base_file_name_.empty();
116 }
117
118 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_debug_recording_manager.h ('k') | media/audio/audio_debug_recording_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698