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 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ | |
6 #define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 #include <utility> | |
12 | |
13 #include "base/callback.h" | |
14 #include "base/files/file_path.h" | |
15 #include "base/gtest_prod_util.h" | |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/threading/thread_checker.h" | |
18 #include "media/audio/audio_debug_recording_helper.h" | |
19 #include "media/audio/audio_file_writer.h" | |
20 #include "media/base/audio_parameters.h" | |
21 #include "media/base/media_export.h" | |
22 | |
23 namespace base { | |
24 class FilePath; | |
25 class SingleThreadTaskRunner; | |
26 } | |
27 | |
28 namespace media { | |
29 | |
30 class AudioDebugRecordingHelper; | |
31 | |
32 // A manager for audio debug recording that handles registration of data | |
33 // sources and hands them a recorder (AudioDebugRecordingHelper) to feed data | |
34 // to. The recorder will unregister with the manager automatically when deleted. | |
35 // When debug recording is enabled, it is enabled on all recorders and | |
36 // constructs a unique file name for each recorder by using a running ID. | |
37 // A somewhat simplified diagram of the the debug recording infrastructure, | |
38 // interfaces omitted: | |
39 // | |
40 // AudioFileWriter | |
41 // ^ | |
42 // | owns | |
43 // owns | | |
44 // OnMoreDataConverter -----> AudioDebugRecordingHelper | |
45 // ^ ^ | |
46 // | owns several | raw pointer to several | |
47 // | | | |
48 // AudioOutputResampler AudioDebugRecordingManager | |
49 // ^ ^ | |
50 // | | owns | |
51 // | owns several | | |
52 // ------------------ AudioManagerBase | |
53 // | |
o1ka
2017/02/10 15:21:53
This is awesome. Could you also indicate which of
Henrik Grunell
2017/02/13 15:16:48
Thanks. Sounds good, done. It involves what conten
| |
54 class MEDIA_EXPORT AudioDebugRecordingManager { | |
55 public: | |
56 AudioDebugRecordingManager( | |
57 AudioFileWriter::CreateCallback create_audio_file_writer_callback, | |
58 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
59 virtual ~AudioDebugRecordingManager(); | |
60 | |
61 // Enables and disables debug recording. | |
62 virtual void EnableDebugRecording(const base::FilePath& base_file_name); | |
63 virtual void DisableDebugRecording(); | |
64 | |
65 // Registers a source and returns a wrapped recorder. |file_name_extension| is | |
66 // added to the base filename, along with a unique running ID. | |
67 std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource( | |
68 const std::string& file_name_extension, | |
69 const AudioParameters& params); | |
70 | |
71 protected: | |
72 // Creates a AudioDebugRecordingHelper. Overridden by test. | |
73 virtual std::unique_ptr<AudioDebugRecordingHelper> | |
74 CreateAudioDebugRecordingHelper( | |
75 const AudioParameters& params, | |
76 const AudioFileWriter::CreateCallback& create_audio_file_writer_callback, | |
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
78 base::OnceClosure on_destruction_closure); | |
79 | |
80 // Callback for creating AudioFileWriter objects. | |
81 const AudioFileWriter::CreateCallback create_audio_file_writer_callback_; | |
82 | |
83 // The task runner this class lives on. Also handed to | |
84 // AudioDebugRecordingHelpers. | |
85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
86 | |
87 private: | |
88 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, | |
89 RegisterAutomaticUnregisterAtDelete); | |
90 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, | |
91 RegisterEnableDisable); | |
92 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, | |
93 EnableRegisterDisable); | |
94 | |
95 // Map type from source id to recorder and its filename extension. | |
96 using DebugRecordingHelperMap = | |
97 std::map<int, std::pair<AudioDebugRecordingHelper*, std::string>>; | |
98 | |
99 // Unregisters a source. | |
100 void UnregisterDebugRecordingSource(int id); | |
101 | |
102 bool IsDebugRecordingEnabled(); | |
103 | |
104 // Recorders, one per source. | |
105 DebugRecordingHelperMap debug_recording_helpers_; | |
106 | |
107 // The base file name for debug recording files. If this is non-empty, debug | |
108 // recording is enabled. | |
109 base::FilePath debug_recording_base_file_name_; | |
110 | |
111 base::WeakPtrFactory<AudioDebugRecordingManager> weak_factory_; | |
112 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager); | |
113 }; | |
114 | |
115 } // namespace media | |
116 | |
117 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ | |
OLD | NEW |