OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/atomicops.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "media/audio/audio_file_writer.h" |
| 15 #include "media/base/audio_parameters.h" |
| 16 #include "media/base/media_export.h" |
| 17 |
| 18 namespace base { |
| 19 class FilePath; |
| 20 class SingleThreadTaskRunner; |
| 21 } |
| 22 |
| 23 namespace media { |
| 24 |
| 25 class AudioBus; |
| 26 |
| 27 // Interface for feeding data to a recorder. |
| 28 class AudioDebugRecorder { |
| 29 public: |
| 30 virtual ~AudioDebugRecorder() {} |
| 31 |
| 32 // If debug recording is enabled, copies audio data and makes sure it's |
| 33 // written on the right thread. Otherwise ignores the data. Can be called on |
| 34 // any thread. |
| 35 virtual void OnData(const AudioBus* source) = 0; |
| 36 }; |
| 37 |
| 38 // A helper class for those who want to use AudioFileWriter. It handles |
| 39 // copying AudioBus data, thread jump (OnData() can be called on any |
| 40 // thread), and creating and deleting the AudioFileWriter at enable and disable. |
| 41 // All functions except OnData() must be called on the thread |task_runner| |
| 42 // belongs to. |
| 43 class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder { |
| 44 public: |
| 45 AudioDebugRecordingHelper( |
| 46 const AudioParameters& params, |
| 47 const AudioFileWriter::CreateCallback& create_audio_file_writer_callback, |
| 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 49 base::OnceClosure on_destruction_closure); |
| 50 ~AudioDebugRecordingHelper() override; |
| 51 |
| 52 // Enable debug recording. The create callback is first run to create an |
| 53 // AudioFileWriter. |
| 54 virtual void EnableDebugRecording(const base::FilePath& file_name); |
| 55 |
| 56 // Disable debug recording. The AudioFileWriter is destroyed. |
| 57 virtual void DisableDebugRecording(); |
| 58 |
| 59 // AudioDebugRecorder implementation. Can be called on any thread. |
| 60 void OnData(const AudioBus* source) override; |
| 61 |
| 62 private: |
| 63 // Writes debug data to |debug_writer_|. |
| 64 void DoWrite(std::unique_ptr<media::AudioBus> data); |
| 65 |
| 66 const AudioParameters params_; |
| 67 const AudioFileWriter::CreateCallback create_audio_file_writer_callback_; |
| 68 std::unique_ptr<AudioFileWriter> debug_writer_; |
| 69 |
| 70 // Used as a flag to indicate if recording is enabled. |
| 71 base::subtle::Atomic32 recording_enabled_; |
| 72 |
| 73 // The task runner for accessing |debug_writer_|. |
| 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 75 |
| 76 // Runs in destructor if set. |
| 77 base::OnceClosure on_destruction_closure_; |
| 78 |
| 79 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; |
| 80 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); |
| 81 }; |
| 82 |
| 83 } // namespace media |
| 84 |
| 85 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
OLD | NEW |