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/callback.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" |
| 13 #include "media/audio/audio_file_writer.h" |
| 14 #include "media/base/audio_parameters.h" |
| 15 |
| 16 namespace base { |
| 17 class FilePath; |
| 18 class SingleThreadTaskRunner; |
| 19 } |
| 20 |
| 21 namespace media { |
| 22 |
| 23 class AudioBus; |
| 24 |
| 25 // Interface for feeding data to a recorder. |
| 26 class AudioDebugRecorder { |
| 27 public: |
| 28 virtual ~AudioDebugRecorder() {} |
| 29 |
| 30 // If debug recording is enabled, copies audio data and makes sure it's |
| 31 // written on the right thread. Otherwise ignores the data. Can be called on |
| 32 // any thread. |
| 33 virtual void OnData(const AudioBus* source) = 0; |
| 34 }; |
| 35 |
| 36 // A helper class for those who want to use AudioFileWriter. It handles |
| 37 // copying AudioBus data, thread jump (MaybeWrite() can be called on any |
| 38 // thread), and creating and deleting the AudioFileWriter at enable and disable. |
| 39 class AudioDebugRecordingHelper : public AudioDebugRecorder { |
| 40 public: |
| 41 AudioDebugRecordingHelper( |
| 42 const AudioParameters& params, |
| 43 const CreateAudioFileWriterCallback& create_audio_file_writer_callback, |
| 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 45 ~AudioDebugRecordingHelper() override; |
| 46 |
| 47 // Enable and disable debug recording. When enabled, |audio_manager_| is asked |
| 48 // to create a DebugWriter. Extension "wav" will be added to |file_name|. |
| 49 void EnableDebugRecording(const base::FilePath& file_name); |
| 50 void DisableDebugRecording(); |
| 51 |
| 52 // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread. |
| 53 // Must not be called after DisableDebugRecording(). |
| 54 bool WillWrite(); |
| 55 |
| 56 // AudioDebugRecorder implementation. |
| 57 void OnData(const AudioBus* source) override; |
| 58 |
| 59 private: |
| 60 // Writes debug data to |debug_writer_|. |
| 61 void DoWrite(std::unique_ptr<media::AudioBus> data); |
| 62 |
| 63 const AudioParameters params_; |
| 64 CreateAudioFileWriterCallback create_audio_file_writer_callback_; |
| 65 std::unique_ptr<AudioFileWriter> debug_writer_; |
| 66 |
| 67 // The task runner for accessing |debug_writer_|. |
| 68 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 69 |
| 70 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; |
| 71 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); |
| 72 }; |
| 73 |
| 74 } // namespace media |
| 75 |
| 76 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
OLD | NEW |