Chromium Code Reviews| Index: media/audio/audio_debug_recording_manager.h |
| diff --git a/media/audio/audio_debug_recording_manager.h b/media/audio/audio_debug_recording_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..098c3d97f561601bf03c2cc67649fc36313f9a41 |
| --- /dev/null |
| +++ b/media/audio/audio_debug_recording_manager.h |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ |
| +#define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ |
| + |
| +#include <map> |
| +#include <memory> |
| +#include <string> |
| +#include <utility> |
| + |
| +#include "base/callback.h" |
| +#include "base/files/file_path.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "media/audio/audio_debug_recording_helper.h" |
| +#include "media/audio/audio_file_writer.h" |
| +#include "media/base/audio_parameters.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace base { |
| +class FilePath; |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace media { |
| + |
| +class AudioDebugRecordingHelper; |
| + |
| +// A manager for audio debug recording that handles registration of data |
| +// sources and hands them a recorder (AudioDebugRecordingHelper) to feed data |
| +// to. The recorder will unregister with the manager automatically when deleted. |
| +// When debug recording is enabled, it is enabled on all recorders and |
| +// constructs a unique file name for each recorder by using a running ID. |
| +class MEDIA_EXPORT AudioDebugRecordingManager { |
|
o1ka
2017/02/09 13:04:03
Can we have a description or pseudo-graphic of the
Henrik Grunell
2017/02/10 09:00:56
That's a good idea. I created a diagram doc to ass
|
| + public: |
| + AudioDebugRecordingManager( |
| + CreateAudioFileWriterCallback create_audio_file_writer_callback, |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| + virtual ~AudioDebugRecordingManager(); |
| + |
| + // Enables and disables debug recording. |
| + void EnableDebugRecording(const base::FilePath& base_file_name); |
| + void DisableDebugRecording(); |
| + |
| + // Registers a source and returns a wrapped recorder. |file_name_extension| is |
| + // added to the base filename, along with a unique running ID. |
| + std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource( |
| + const std::string& file_name_extension, |
| + const AudioParameters& params); |
| + |
| + protected: |
| + // Creates a AudioDebugRecordingHelper. Overridden by test. |
| + virtual std::unique_ptr<AudioDebugRecordingHelper> |
| + CreateAudioDebugRecordingHelper( |
| + const AudioParameters& params, |
| + const CreateAudioFileWriterCallback& create_audio_file_writer_callback, |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + base::OnceClosure on_destruction_closure); |
| + |
| + // Callback for creating AudioFileWriter objects. |
| + const CreateAudioFileWriterCallback create_audio_file_writer_callback_; |
| + |
| + // The task runner this class lives on. Also handed to |
| + // AudioDebugRecordingHelpers. |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| + RegisterAutomaticUnregisterAtDelete); |
| + FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| + RegisterEnableDisable); |
| + FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest, |
| + EnableRegisterDisable); |
| + |
| + // Map type from source id to recorder and its filename extension. |
| + using DebugRecordingHelperMap = |
| + std::map<int, std::pair<AudioDebugRecordingHelper*, std::string>>; |
| + |
| + // Unregisters a source. |
| + void UnregisterDebugRecordingSource(int id); |
| + |
| + // Recorders, one per source. |
| + DebugRecordingHelperMap debug_recording_helpers_; |
| + |
| + // The base file name for debug recording files. If this is non-empty, debug |
| + // recording is enabled. |
| + base::FilePath debug_recording_base_file_name_; |
| + |
| + base::WeakPtrFactory<AudioDebugRecordingManager> weak_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_ |