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 AudioDebugRecordingManager::AudioDebugRecordingManager( | |
24 CreateAudioFileWriterCallback create_audio_file_writer_callback, | |
25 const std::string& file_name_extension, | |
26 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
27 : create_audio_file_writer_callback_( | |
28 std::move(create_audio_file_writer_callback)), | |
29 file_name_extension_(file_name_extension), | |
30 task_runner_(std::move(task_runner)) { | |
31 DCHECK(create_audio_file_writer_callback_); | |
32 } | |
33 | |
34 AudioDebugRecordingManager::~AudioDebugRecordingManager() {} | |
35 | |
36 void AudioDebugRecordingManager::EnableDebugRecording( | |
37 const base::FilePath& base_file_name) { | |
38 DCHECK(task_runner_->BelongsToCurrentThread()); | |
39 for (const auto& it : debug_recording_helpers_) { | |
40 it.second->EnableDebugRecording( | |
41 GetOutputDebugRecordingFileNameWithExtensions(base_file_name, | |
42 it.first)); | |
43 } | |
44 debug_recording_base_file_name_ = base_file_name; | |
45 } | |
46 | |
47 void AudioDebugRecordingManager::DisableDebugRecording() { | |
48 DCHECK(task_runner_->BelongsToCurrentThread()); | |
49 for (const auto& it : debug_recording_helpers_) | |
50 it.second->DisableDebugRecording(); | |
51 debug_recording_base_file_name_.clear(); | |
52 } | |
53 | |
54 std::unique_ptr<AudioDebugRecorder> | |
55 AudioDebugRecordingManager::RegisterDebugRecordingSource( | |
56 const AudioParameters& params) { | |
57 DCHECK(task_runner_->BelongsToCurrentThread()); | |
58 | |
59 const int id = g_next_stream_id++; | |
60 | |
61 std::unique_ptr<AudioDebugRecordingHelper> recording_helper = | |
62 base::MakeUnique<AudioDebugRecordingHelper>( | |
63 params, create_audio_file_writer_callback_, task_runner_, | |
64 base::Bind( | |
65 &AudioDebugRecordingManager::UnregisterDebugRecordingSource, | |
66 base::Unretained(this), id)); | |
o1ka
2017/01/31 11:00:11
Please specify why Unretained() is safe.
Henrik Grunell
2017/02/08 11:29:37
Changed it to use a weak pointer. Unretained() was
| |
67 | |
68 if (!debug_recording_base_file_name_.empty()) { | |
o1ka
2017/01/31 11:00:11
Then you need to check it in Enable/Disbale() as w
Henrik Grunell
2017/02/08 11:29:37
I'm not sure what you mean. Enable() takes the fil
| |
69 recording_helper->EnableDebugRecording( | |
70 GetOutputDebugRecordingFileNameWithExtensions( | |
71 debug_recording_base_file_name_, id)); | |
72 } | |
73 | |
74 debug_recording_helpers_[id] = recording_helper.get(); | |
75 | |
76 return recording_helper; | |
77 } | |
78 | |
79 void AudioDebugRecordingManager::UnregisterDebugRecordingSource(int id) { | |
80 DCHECK(task_runner_->BelongsToCurrentThread()); | |
81 auto it = debug_recording_helpers_.find(id); | |
82 DCHECK(it != debug_recording_helpers_.end()); | |
83 debug_recording_helpers_.erase(id); | |
84 } | |
85 | |
86 #if defined(OS_WIN) | |
87 #define IntToStringType base::IntToString16 | |
88 #else | |
89 #define IntToStringType base::IntToString | |
90 #endif | |
91 | |
92 base::FilePath | |
93 AudioDebugRecordingManager::GetOutputDebugRecordingFileNameWithExtensions( | |
94 const base::FilePath& file_name, | |
95 int id) { | |
96 DCHECK(task_runner_->BelongsToCurrentThread()); | |
97 return file_name.AddExtension(file_name_extension_) | |
98 .AddExtension(IntToStringType(id)); | |
99 } | |
100 | |
101 } // namespace media | |
OLD | NEW |