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 base::OnceClosure on_destruction_closure); | |
46 ~AudioDebugRecordingHelper() override; | |
47 | |
48 // Enable and disable debug recording. When enabled, |audio_manager_| is asked | |
49 // to create a DebugWriter. Extension "wav" will be added to |file_name|. | |
50 void EnableDebugRecording(const base::FilePath& file_name); | |
51 void DisableDebugRecording(); | |
52 | |
53 // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread. | |
54 // Must not be called after DisableDebugRecording(). | |
55 bool WillWrite(); | |
o1ka
2017/01/31 11:00:11
Private?
Henrik Grunell
2017/02/08 11:29:37
I removed it. It's only used in one place internal
| |
56 | |
57 // AudioDebugRecorder implementation. | |
58 void OnData(const AudioBus* source) override; | |
59 | |
60 private: | |
61 // Writes debug data to |debug_writer_|. | |
62 void DoWrite(std::unique_ptr<media::AudioBus> data); | |
63 | |
64 const AudioParameters params_; | |
65 CreateAudioFileWriterCallback create_audio_file_writer_callback_; | |
66 std::unique_ptr<AudioFileWriter> debug_writer_; | |
67 | |
68 // The task runner for accessing |debug_writer_|. | |
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
70 | |
71 // Runs in destructor if set. | |
72 base::OnceClosure on_destruction_closure_; | |
73 | |
74 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; | |
75 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); | |
76 }; | |
77 | |
78 } // namespace media | |
79 | |
80 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ | |
OLD | NEW |