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..d8418dbaf0aded79f111a5cf99cfacfecffb012d |
--- /dev/null |
+++ b/media/audio/audio_debug_recording_helper.h |
@@ -0,0 +1,76 @@ |
+// 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/callback.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/thread_checker.h" |
+#include "media/audio/audio_file_writer.h" |
+#include "media/base/audio_parameters.h" |
+ |
+namespace base { |
+class FilePath; |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace media { |
+ |
+class AudioBus; |
+ |
+// Interface for feeding data to a recorder. |
+class AudioDebugRecorder { |
+ public: |
+ virtual ~AudioDebugRecorder() {} |
+ |
+ // If debug recording is enabled, copies audio data and makes sure it's |
+ // written on the right thread. Otherwise ignores the data. Can be called on |
+ // any thread. |
+ virtual void OnData(const AudioBus* source) = 0; |
+}; |
+ |
+// A helper class for those who 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 : public AudioDebugRecorder { |
+ public: |
+ AudioDebugRecordingHelper( |
+ const AudioParameters& params, |
+ const CreateAudioFileWriterCallback& create_audio_file_writer_callback, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ ~AudioDebugRecordingHelper() override; |
+ |
+ // 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 base::FilePath& file_name); |
+ void DisableDebugRecording(); |
+ |
+ // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread. |
+ // Must not be called after DisableDebugRecording(). |
+ bool WillWrite(); |
+ |
+ // AudioDebugRecorder implementation. |
+ void OnData(const AudioBus* source) override; |
+ |
+ private: |
+ // Writes debug data to |debug_writer_|. |
+ void DoWrite(std::unique_ptr<media::AudioBus> data); |
+ |
+ const AudioParameters params_; |
+ CreateAudioFileWriterCallback create_audio_file_writer_callback_; |
+ std::unique_ptr<AudioFileWriter> debug_writer_; |
+ |
+ // The task runner for accessing |debug_writer_|. |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; |
+ DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |