Chromium Code Reviews| 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/memory/weak_ptr.h" | |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "media/audio/audio_file_writer.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class FilePath; | |
| 16 class SingleThreadTaskRunner; | |
| 17 } | |
| 18 | |
| 19 namespace media { | |
| 20 | |
| 21 class AudioBus; | |
| 22 class AudioManager; | |
| 23 | |
| 24 // A helper class for objects that want to use AudioFileWriter. It handles | |
| 25 // copying AudioBus data, thread jump (MaybeWrite() can be called on any | |
| 26 // thread), and creating and deleting the AudioFileWriter at enable and disable. | |
| 27 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.
| |
| 28 public: | |
| 29 AudioDebugRecordingHelper( | |
| 30 AudioManager* audio_manager, | |
| 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 32 ~AudioDebugRecordingHelper(); | |
| 33 | |
| 34 // Enable and disable debug recording. When enabled, |audio_manager_| is asked | |
| 35 // to create a DebugWriter. Extension "wav" will be added to |file_name|. | |
| 36 void EnableDebugRecording(const AudioParameters& params, | |
| 37 const base::FilePath& file_name); | |
| 38 void DisableDebugRecording(); | |
| 39 | |
| 40 // If debug recording is enabled, copies audio data and posts DoWrite() on | |
| 41 // |task_runner_|. Can be called on any thread. | |
| 42 void MaybeWrite(const AudioBus* source); | |
| 43 | |
| 44 // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread. | |
| 45 bool WillWrite(); | |
| 46 | |
| 47 private: | |
| 48 // Writes debug data to |debug_writer_|. | |
| 49 void DoWrite(std::unique_ptr<media::AudioBus> data); | |
| 50 | |
| 51 AudioManager* audio_manager_; | |
| 52 std::unique_ptr<AudioFileWriter> debug_writer_; | |
| 53 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.
| |
| 54 | |
| 55 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; | |
| 56 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); | |
| 57 }; | |
| 58 | |
| 59 } // namspace media | |
| 60 | |
| 61 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ | |
| OLD | NEW |