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

Unified Diff: media/audio/audio_debug_recording_helper.h

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Code review. Rebase. Created 3 years, 10 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_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..7b66da2a7b0e2ef7bfd2452f18944c0ff025e70e
--- /dev/null
+++ b/media/audio/audio_debug_recording_helper.h
@@ -0,0 +1,81 @@
+// 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"
+#include "media/base/media_export.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 (OnData() can be called on any
+// thread), and creating and deleting the AudioFileWriter at enable and disable.
+// All functions except OnData() must be called on the thread |task_runner|
+// belongs to.
+class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder {
+ public:
+ AudioDebugRecordingHelper(
+ const AudioParameters& params,
+ const CreateAudioFileWriterCallback& create_audio_file_writer_callback,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ base::OnceClosure on_destruction_closure);
+ ~AudioDebugRecordingHelper() override;
+
+ // Enable debug recording. The create callback is first run to create an
+ // AudioFileWriter.
+ virtual void EnableDebugRecording(const base::FilePath& file_name);
+
+ // Disable debug recording. The AudioFileWriter is destroyed.
+ virtual void DisableDebugRecording();
+
+ // AudioDebugRecorder implementation. Can be called on any thread.
+ void OnData(const AudioBus* source) override;
+
+ private:
+ // Writes debug data to |debug_writer_|.
+ void DoWrite(std::unique_ptr<media::AudioBus> data);
+
+ const AudioParameters params_;
+ const 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_;
+
+ // Runs in destructor if set.
+ base::OnceClosure on_destruction_closure_;
+
+ base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_;
+ DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698