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/base/audio_parameters.h" |
| 20 #include "media/base/media_export.h" |
| 21 |
| 22 namespace base { |
| 23 class FilePath; |
| 24 class SingleThreadTaskRunner; |
| 25 } |
| 26 |
| 27 namespace media { |
| 28 |
| 29 class AudioDebugRecordingHelper; |
| 30 |
| 31 // A manager for audio debug recording that handles registration of data |
| 32 // sources and hands them a recorder (AudioDebugRecordingHelper) to feed data |
| 33 // to. The recorder will unregister with the manager automatically when deleted. |
| 34 // When debug recording is enabled, it is enabled on all recorders and |
| 35 // constructs a unique file name for each recorder by using a running ID. |
| 36 // A somewhat simplified diagram of the the debug recording infrastructure, |
| 37 // interfaces omitted: |
| 38 // |
| 39 // AudioDebugFileWriter |
| 40 // ^ |
| 41 // | owns |
| 42 // owns | |
| 43 // OnMoreDataConverter ----> AudioDebugRecordingHelper |
| 44 // ^ ^ |
| 45 // | owns several | raw pointer to several |
| 46 // | | |
| 47 // AudioOutputResampler AudioDebugRecordingManager |
| 48 // ^ ^ |
| 49 // | | owns |
| 50 // | owns several | |
| 51 // ------------------ AudioManagerBase |
| 52 // |
| 53 // AudioDebugRecordingManager is created when |
| 54 // AudioManager::InitializeOutputDebugRecording() is called. That is done |
| 55 // in AudioManager::Create() in WebRTC enabled builds, but not in non WebRTC |
| 56 // enabled builds. |
| 57 // If AudioDebugRecordingManager is not created, neither is |
| 58 // AudioDebugRecordingHelper or AudioDebugFileWriter. In this case the pointers |
| 59 // to AudioDebugRecordingManager and AudioDebugRecordingHelper are null. |
| 60 // |
| 61 class MEDIA_EXPORT AudioDebugRecordingManager { |
| 62 public: |
| 63 AudioDebugRecordingManager( |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 65 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 66 virtual ~AudioDebugRecordingManager(); |
| 67 |
| 68 // Enables and disables debug recording. |
| 69 virtual void EnableDebugRecording(const base::FilePath& base_file_name); |
| 70 virtual void DisableDebugRecording(); |
| 71 |
| 72 // Registers a source and returns a wrapped recorder. |file_name_extension| is |
| 73 // added to the base filename, along with a unique running ID. |
| 74 std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource( |
| 75 const base::FilePath::StringType& file_name_extension, |
| 76 const AudioParameters& params); |
| 77 |
| 78 protected: |
| 79 // Creates a AudioDebugRecordingHelper. Overridden by test. |
| 80 virtual std::unique_ptr<AudioDebugRecordingHelper> |
| 81 CreateAudioDebugRecordingHelper( |
| 82 const AudioParameters& params, |
| 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 84 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
| 85 base::OnceClosure on_destruction_closure); |
| 86 |
| 87 // The task runner this class lives on. Also handed to |
| 88 // AudioDebugRecordingHelpers. |
| 89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 90 |
| 91 private: |
| 92 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| 93 RegisterAutomaticUnregisterAtDelete); |
| 94 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| 95 RegisterEnableDisable); |
| 96 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| 97 EnableRegisterDisable); |
| 98 |
| 99 // Map type from source id to recorder and its filename extension. |
| 100 using DebugRecordingHelperMap = std::map< |
| 101 int, |
| 102 std::pair<AudioDebugRecordingHelper*, base::FilePath::StringType>>; |
| 103 |
| 104 // Unregisters a source. |
| 105 void UnregisterDebugRecordingSource(int id); |
| 106 |
| 107 bool IsDebugRecordingEnabled(); |
| 108 |
| 109 // Recorders, one per source. |
| 110 DebugRecordingHelperMap debug_recording_helpers_; |
| 111 |
| 112 // The base file name for debug recording files. If this is non-empty, debug |
| 113 // recording is enabled. |
| 114 base::FilePath debug_recording_base_file_name_; |
| 115 |
| 116 // Task runner that the file writer does file output operations on. Handed to |
| 117 // AudioDebugRecordingHelpers |
| 118 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 119 |
| 120 base::WeakPtrFactory<AudioDebugRecordingManager> weak_factory_; |
| 121 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager); |
| 122 }; |
| 123 |
| 124 } // namespace media |
| 125 |
| 126 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ |
OLD | NEW |