OLD | NEW |
---|---|
(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 #include "media/audio/audio_manager.h" | |
13 | |
14 namespace media { | |
15 | |
16 namespace { | |
17 | |
18 // Running id recording sources. | |
19 int g_next_stream_id = 1; | |
20 | |
21 } // namespace | |
22 | |
23 AudioDebugRecorderWrapper::AudioDebugRecorderWrapper( | |
24 std::unique_ptr<AudioDebugRecorder> recorder, | |
25 UnregisterAudioDebugRecorderCallback unregister_callback) | |
26 : recorder(std::move(recorder)), unregister_callback(unregister_callback) {} | |
27 | |
28 AudioDebugRecorderWrapper::~AudioDebugRecorderWrapper() {} | |
29 | |
30 AudioDebugRecordingManager::AudioDebugRecordingManager( | |
31 CreateAudioFileWriterCallback create_audio_file_writer_callback, | |
32 const std::string& file_name_extension, | |
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
34 : create_audio_file_writer_callback_( | |
35 std::move(create_audio_file_writer_callback)), | |
36 file_name_extension_(file_name_extension), | |
37 task_runner_(std::move(task_runner)) { | |
38 DCHECK(create_audio_file_writer_callback_); | |
39 } | |
40 | |
41 AudioDebugRecordingManager::~AudioDebugRecordingManager() {} | |
42 | |
43 void AudioDebugRecordingManager::EnableDebugRecording( | |
44 const base::FilePath& base_file_name) { | |
45 DCHECK(task_runner_->BelongsToCurrentThread()); | |
46 for (const auto& it : debug_recording_helpers_) { | |
47 it.second->EnableDebugRecording( | |
48 GetOutputDebugRecordingFileNameWithExtensions(base_file_name, | |
49 it.first)); | |
50 } | |
51 debug_recording_base_file_name_ = base_file_name; | |
52 } | |
53 | |
54 void AudioDebugRecordingManager::DisableDebugRecording() { | |
55 DCHECK(task_runner_->BelongsToCurrentThread()); | |
56 for (const auto& it : debug_recording_helpers_) | |
57 it.second->DisableDebugRecording(); | |
58 debug_recording_base_file_name_.clear(); | |
59 } | |
60 | |
61 AudioDebugRecorderWrapperUniquePtr | |
62 AudioDebugRecordingManager::RegisterDebugRecordingSource( | |
63 const AudioParameters& params) { | |
64 DCHECK(task_runner_->BelongsToCurrentThread()); | |
65 | |
66 std::unique_ptr<AudioDebugRecordingHelper> recording_helper = | |
67 base::MakeUnique<AudioDebugRecordingHelper>( | |
68 params, create_audio_file_writer_callback_, task_runner_); | |
69 | |
70 const int id = g_next_stream_id++; | |
71 | |
72 if (!debug_recording_base_file_name_.empty()) { | |
73 recording_helper->EnableDebugRecording( | |
74 GetOutputDebugRecordingFileNameWithExtensions( | |
75 debug_recording_base_file_name_, id)); | |
76 } | |
77 | |
78 debug_recording_helpers_[id] = recording_helper.get(); | |
79 | |
80 AudioDebugRecorderWrapperUniquePtr recorder_wrapper( | |
81 new AudioDebugRecorderWrapper( | |
82 std::move(recording_helper), | |
83 base::Bind( | |
84 &AudioDebugRecordingManager::UnregisterDebugRecordingSource, | |
85 base::Unretained(this), id))); | |
86 | |
87 return recorder_wrapper; | |
88 } | |
89 | |
90 void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) { | |
91 DCHECK(task_runner_->BelongsToCurrentThread()); | |
92 auto it = debug_recording_helpers_.find(id); | |
93 DCHECK(it != debug_recording_helpers_.end()); | |
94 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
| |
95 debug_recording_helpers_.erase(id); | |
96 } | |
97 | |
98 #if defined(OS_WIN) | |
99 #define IntToStringType base::IntToString16 | |
100 #else | |
101 #define IntToStringType base::IntToString | |
102 #endif | |
103 | |
104 base::FilePath | |
105 AudioDebugRecordingManager::GetOutputDebugRecordingFileNameWithExtensions( | |
106 const base::FilePath& file_name, | |
107 int id) { | |
108 DCHECK(task_runner_->BelongsToCurrentThread()); | |
109 return file_name.AddExtension(file_name_extension_) | |
110 .AddExtension(IntToStringType(id)); | |
111 } | |
112 | |
113 } // namespace media | |
OLD | NEW |