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

Unified Diff: media/audio/audio_debug_recording_manager.h

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Reworked callbacks and interfaces. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
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..760ca52de3a9858b1d9005aeb501b6dffb858633
--- /dev/null
+++ b/media/audio/audio_debug_recording_manager.h
@@ -0,0 +1,130 @@
+// 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 "base/callback.h"
+#include "base/files/file_path.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"
+
+namespace base {
+class FilePath;
+class SingleThreadTaskRunner;
+}
+
+namespace media {
+
+class AudioDebugRecordingHelper;
+
+// TODO BEFORE COMMIT: Is this a good location for these?
+
+// Callback type to unregister an AudioDebugRecorder.
+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
+
+// A wrapper for AudioDebugRecorder to be able to automatically unregister at
+// destruction.
+// TODO BEFORE COMMIT: I'm not too keen on this. It would be better to have a
+// single interface given to the converter. This could perhaps be incorporated
+// in the recorder interface, making it a base class that contains the
+// unregister callback. But that means the recoder/helper needs to know about
+// registation which is not good either. Alternatively, we could skip automatic
+// unregistration alltogether.
+struct AudioDebugRecorderWrapper {
+ AudioDebugRecorderWrapper(
+ std::unique_ptr<AudioDebugRecorder> recorder,
+ UnregisterAudioDebugRecorderCallback unregister_callback);
+ ~AudioDebugRecorderWrapper();
+
+ // The wrapped recorder.
+ std::unique_ptr<AudioDebugRecorder> recorder;
+
+ // Run by deleter to unregister recorder.
+ UnregisterAudioDebugRecorderCallback unregister_callback;
+};
+
+// Deleter for the wrapper. Runs the unregister callback before deleting.
+struct AudioDebugRecorderWrapperDeleter {
+ void operator()(AudioDebugRecorderWrapper* recorder_wrapper) {
+ recorder_wrapper->unregister_callback.Run();
+ delete recorder_wrapper;
+ }
+};
+
+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
+ std::unique_ptr<AudioDebugRecorderWrapper,
+ AudioDebugRecorderWrapperDeleter>;
+
+// Callback type to register an AudioDebugRecorder. Returns an
+// AudioDebugRecorderWrapperUniquePtr which automatically unregisters the
+// recorder at destruction.
+using RegisterDebugRecordingSourceCallback =
+ base::RepeatingCallback<AudioDebugRecorderWrapperUniquePtr(
+ const AudioParameters&)>;
+
+// A manager for audio debug recording that handles registration of data
+// sources and hands them a recorder (AudioDebugRecordingHelper) to feed data
+// to, wrapped so that it unregisters automatically when deleted. When debug
+// recording is enabled, it is enabled on all recorders. It handles constructing
+// a file name for each recorder.
+class AudioDebugRecordingManager {
+ public:
+ explicit AudioDebugRecordingManager(
+ CreateAudioFileWriterCallback create_audio_file_writer_callback,
+ const std::string& file_name_extension,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ ~AudioDebugRecordingManager();
+
+ // Enables and disables debug recording.
+ void EnableDebugRecording(const base::FilePath& base_file_name);
+ void DisableDebugRecording();
+
+ // Registers a source and returns a wrapped recorder.
+ AudioDebugRecorderWrapperUniquePtr RegisterDebugRecordingSource(
+ const AudioParameters& params);
+
+ private:
+ // Map type from source id to recorder.
+ using DebugRecordingHelperMap = std::map<int, AudioDebugRecordingHelper*>;
+
+ // 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.
+ void UnregisterDebugRecordingSource(int id);
+
+ // Returns |file_name| with |file_name_extension_| and |id| added to it as
+ // as extensions.
+ base::FilePath GetOutputDebugRecordingFileNameWithExtensions(
+ const base::FilePath& file_name,
+ int id);
+
+ // Recorders, one per source.
+ DebugRecordingHelperMap debug_recording_helpers_;
+
+ // Callback for creating AudioFileWriter objects.
+ const CreateAudioFileWriterCallback create_audio_file_writer_callback_;
+
+ // The base file name for debug recording files. If this is non-empty, debug
+ // recording is enabled.
+ base::FilePath debug_recording_base_file_name_;
+
+ // File name extension that will be added to the base file name.
+ const std::string file_name_extension_;
+
+ // The task runner this class lives on. Also handed to
+ // AudioDebugRecordingHelpers.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ base::ThreadChecker thread_checker_;
+ DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManager);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698