Chromium Code Reviews| 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 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "media/audio/audio_debug_recording_helper.h" | |
| 16 #include "media/audio/audio_file_writer.h" | |
| 17 #include "media/base/audio_parameters.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class FilePath; | |
| 21 class SingleThreadTaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace media { | |
| 25 | |
| 26 class AudioDebugRecordingHelper; | |
| 27 | |
| 28 // TODO BEFORE COMMIT: Is this a good location for these? | |
| 29 | |
| 30 // Callback type to unregister an AudioDebugRecorder. | |
| 31 using UnregisterAudioDebugRecorderCallback = base::Callback<void()>; | |
|
Max Morin
2017/01/26 17:49:42
Should probably be a OnceCallback (but some techni
Henrik Grunell
2017/01/27 16:07:23
Good point. I'm not sure actually about limitation
| |
| 32 | |
| 33 // A wrapper for AudioDebugRecorder to be able to automatically unregister at | |
| 34 // destruction. | |
| 35 // TODO BEFORE COMMIT: I'm not too keen on this. It would be better to have a | |
| 36 // single interface given to the converter. This could perhaps be incorporated | |
| 37 // in the recorder interface, making it a base class that contains the | |
| 38 // unregister callback. But that means the recoder/helper needs to know about | |
| 39 // registation which is not good either. Alternatively, we could skip automatic | |
| 40 // unregistration alltogether. | |
| 41 struct AudioDebugRecorderWrapper { | |
| 42 AudioDebugRecorderWrapper( | |
| 43 std::unique_ptr<AudioDebugRecorder> recorder, | |
| 44 UnregisterAudioDebugRecorderCallback unregister_callback); | |
| 45 ~AudioDebugRecorderWrapper(); | |
| 46 | |
| 47 // The wrapped recorder. | |
| 48 std::unique_ptr<AudioDebugRecorder> recorder; | |
| 49 | |
| 50 // Run by deleter to unregister recorder. | |
| 51 UnregisterAudioDebugRecorderCallback unregister_callback; | |
| 52 }; | |
| 53 | |
| 54 // Deleter for the wrapper. Runs the unregister callback before deleting. | |
| 55 struct AudioDebugRecorderWrapperDeleter { | |
| 56 void operator()(AudioDebugRecorderWrapper* recorder_wrapper) { | |
| 57 recorder_wrapper->unregister_callback.Run(); | |
| 58 delete recorder_wrapper; | |
| 59 } | |
| 60 }; | |
| 61 | |
| 62 using AudioDebugRecorderWrapperUniquePtr = | |
|
Max Morin
2017/01/26 17:49:43
I'm reading this on the train so I may be complete
o1ka
2017/01/27 09:25:26
Agree.
Henrik Grunell
2017/01/27 16:07:23
Removed the wrapper. The helper takes an on destru
| |
| 63 std::unique_ptr<AudioDebugRecorderWrapper, | |
| 64 AudioDebugRecorderWrapperDeleter>; | |
| 65 | |
| 66 // Callback type to register an AudioDebugRecorder. Returns an | |
| 67 // AudioDebugRecorderWrapperUniquePtr which automatically unregisters the | |
| 68 // recorder at destruction. | |
| 69 using RegisterDebugRecordingSourceCallback = | |
| 70 base::RepeatingCallback<AudioDebugRecorderWrapperUniquePtr( | |
| 71 const AudioParameters&)>; | |
| 72 | |
| 73 // A manager for audio debug recording that handles registration of data | |
| 74 // sources and hands them a recorder (AudioDebugRecordingHelper) to feed data | |
| 75 // to, wrapped so that it unregisters automatically when deleted. When debug | |
| 76 // recording is enabled, it is enabled on all recorders. It handles constructing | |
| 77 // a file name for each recorder. | |
| 78 class AudioDebugRecordingManager { | |
| 79 public: | |
| 80 explicit AudioDebugRecordingManager( | |
| 81 CreateAudioFileWriterCallback create_audio_file_writer_callback, | |
| 82 const std::string& file_name_extension, | |
| 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 84 ~AudioDebugRecordingManager(); | |
| 85 | |
| 86 // Enables and disables debug recording. | |
| 87 void EnableDebugRecording(const base::FilePath& base_file_name); | |
| 88 void DisableDebugRecording(); | |
| 89 | |
| 90 // Registers a source and returns a wrapped recorder. | |
| 91 AudioDebugRecorderWrapperUniquePtr RegisterDebugRecordingSource( | |
| 92 const AudioParameters& params); | |
| 93 | |
| 94 private: | |
| 95 // Map type from source id to recorder. | |
| 96 using DebugRecordingHelperMap = std::map<int, AudioDebugRecordingHelper*>; | |
| 97 | |
| 98 // Unregisters a source. Stops recording on it's recorder. | |
|
Max Morin
2017/01/26 17:49:43
its
Henrik Grunell
2017/01/27 16:07:23
Removed that sentence.
| |
| 99 void UnregisterDebugRecordingSource(int id); | |
| 100 | |
| 101 // Returns |file_name| with |file_name_extension_| and |id| added to it as | |
| 102 // as extensions. | |
| 103 base::FilePath GetOutputDebugRecordingFileNameWithExtensions( | |
| 104 const base::FilePath& file_name, | |
| 105 int id); | |
| 106 | |
| 107 // Recorders, one per source. | |
| 108 DebugRecordingHelperMap debug_recording_helpers_; | |
| 109 | |
| 110 // Callback for creating AudioFileWriter objects. | |
| 111 const CreateAudioFileWriterCallback create_audio_file_writer_callback_; | |
| 112 | |
| 113 // The base file name for debug recording files. If this is non-empty, debug | |
| 114 // recording is enabled. | |
| 115 base::FilePath debug_recording_base_file_name_; | |
| 116 | |
| 117 // File name extension that will be added to the base file name. | |
| 118 const std::string file_name_extension_; | |
| 119 | |
| 120 // The task runner this class lives on. Also handed to | |
| 121 // AudioDebugRecordingHelpers. | |
| 122 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 123 | |
| 124 base::ThreadChecker thread_checker_; | |
| 125 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager); | |
| 126 }; | |
| 127 | |
| 128 } // namespace media | |
| 129 | |
| 130 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ | |
| OLD | NEW |