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

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

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Code review (pfeldman@/dalecurtis@) and a fix. Rebase. Created 3 years, 10 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 #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 //
54 // AudioFileWriter is an interface implemented by the user (e.g. the content
55 // layer).
56 // AudioDebugRecordingManager is created when
57 // AudioManager::InitializeOutputDebugRecording() is called. In the content
58 // layer, that is done right after AudioManager creation in WebRTC enabled
59 // builds, and never in non WebRTC enabled builds. See
60 // content::BrowserMainLoop::CreateAudioManager().
61 // If AudioDebugRecordingManager is not created, neither is
62 // AudioDebugRecordingHelper or AudioFileWriter. In this case the pointers to
63 // AudioDebugRecordingManager and AudioDebugRecordingHelper are null.
64 //
65 class MEDIA_EXPORT AudioDebugRecordingManager {
66 public:
67 AudioDebugRecordingManager(
68 AudioFileWriter::CreateCallback create_audio_file_writer_callback,
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
70 virtual ~AudioDebugRecordingManager();
71
72 // Enables and disables debug recording.
73 virtual void EnableDebugRecording(const base::FilePath& base_file_name);
74 virtual void DisableDebugRecording();
75
76 // Registers a source and returns a wrapped recorder. |file_name_extension| is
77 // added to the base filename, along with a unique running ID.
78 std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource(
79 const base::FilePath::StringType& file_name_extension,
80 const AudioParameters& params);
81
82 protected:
83 // Creates a AudioDebugRecordingHelper. Overridden by test.
84 virtual std::unique_ptr<AudioDebugRecordingHelper>
85 CreateAudioDebugRecordingHelper(
86 const AudioParameters& params,
87 const AudioFileWriter::CreateCallback& create_audio_file_writer_callback,
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
89 base::OnceClosure on_destruction_closure);
90
91 // Callback for creating AudioFileWriter objects.
92 const AudioFileWriter::CreateCallback create_audio_file_writer_callback_;
93
94 // The task runner this class lives on. Also handed to
95 // AudioDebugRecordingHelpers.
96 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
97
98 private:
99 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest,
100 RegisterAutomaticUnregisterAtDelete);
101 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest,
102 RegisterEnableDisable);
103 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest,
104 EnableRegisterDisable);
105
106 // Map type from source id to recorder and its filename extension.
107 using DebugRecordingHelperMap = std::map<
108 int,
109 std::pair<AudioDebugRecordingHelper*, base::FilePath::StringType>>;
110
111 // Unregisters a source.
112 void UnregisterDebugRecordingSource(int id);
113
114 bool IsDebugRecordingEnabled();
115
116 // Recorders, one per source.
117 DebugRecordingHelperMap debug_recording_helpers_;
118
119 // The base file name for debug recording files. If this is non-empty, debug
120 // recording is enabled.
121 base::FilePath debug_recording_base_file_name_;
122
123 base::WeakPtrFactory<AudioDebugRecordingManager> weak_factory_;
124 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager);
125 };
126
127 } // namespace media
128
129 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698