Index: media/audio/audio_debug_recording_helper.h |
diff --git a/media/audio/audio_debug_recording_helper.h b/media/audio/audio_debug_recording_helper.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..813e4b29572b6bbbb6bc1155ee48b960cdc313b6 |
--- /dev/null |
+++ b/media/audio/audio_debug_recording_helper.h |
@@ -0,0 +1,61 @@ |
+// 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_HELPER_H_ |
+#define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
+ |
+#include <memory> |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/thread_checker.h" |
+#include "media/audio/audio_file_writer.h" |
+ |
+namespace base { |
+class FilePath; |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace media { |
+ |
+class AudioBus; |
+class AudioManager; |
+ |
+// A helper class for objects that want to use AudioFileWriter. It handles |
+// copying AudioBus data, thread jump (MaybeWrite() can be called on any |
+// thread), and creating and deleting the AudioFileWriter at enable and disable. |
+class AudioDebugRecordingHelper { |
o1ka
2017/01/20 11:36:26
Switch AudioInputController to using this as well?
o1ka
2017/01/25 17:47:00
Ping?
Henrik Grunell
2017/01/26 10:25:09
Good point. I'll do that.
|
+ public: |
+ AudioDebugRecordingHelper( |
+ AudioManager* audio_manager, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ ~AudioDebugRecordingHelper(); |
+ |
+ // Enable and disable debug recording. When enabled, |audio_manager_| is asked |
+ // to create a DebugWriter. Extension "wav" will be added to |file_name|. |
+ void EnableDebugRecording(const AudioParameters& params, |
+ const base::FilePath& file_name); |
+ void DisableDebugRecording(); |
+ |
+ // If debug recording is enabled, copies audio data and posts DoWrite() on |
+ // |task_runner_|. Can be called on any thread. |
+ void MaybeWrite(const AudioBus* source); |
+ |
+ // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread. |
+ bool WillWrite(); |
+ |
+ private: |
+ // Writes debug data to |debug_writer_|. |
+ void DoWrite(std::unique_ptr<media::AudioBus> data); |
+ |
+ AudioManager* audio_manager_; |
+ std::unique_ptr<AudioFileWriter> debug_writer_; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
o1ka
2017/01/20 11:36:26
Add a comment what |task_runner_| is for?
Henrik Grunell
2017/01/26 10:25:09
Done.
|
+ |
+ base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; |
+ DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); |
+}; |
+ |
+} // namspace media |
+ |
+#endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |