OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
6 #define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ | 6 #define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // could be skipped then. Currently we have | 46 // could be skipped then. Currently we have |
47 // soundcard thread -> control thread -> file thread, | 47 // soundcard thread -> control thread -> file thread, |
48 // and with the merge we should be able to do | 48 // and with the merge we should be able to do |
49 // soundcard thread -> file thread. | 49 // soundcard thread -> file thread. |
50 class MEDIA_EXPORT AudioDebugRecordingHelper | 50 class MEDIA_EXPORT AudioDebugRecordingHelper |
51 : public NON_EXPORTED_BASE(AudioDebugRecorder) { | 51 : public NON_EXPORTED_BASE(AudioDebugRecorder) { |
52 public: | 52 public: |
53 AudioDebugRecordingHelper( | 53 AudioDebugRecordingHelper( |
54 const AudioParameters& params, | 54 const AudioParameters& params, |
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
56 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | |
57 base::OnceClosure on_destruction_closure); | 56 base::OnceClosure on_destruction_closure); |
58 ~AudioDebugRecordingHelper() override; | 57 ~AudioDebugRecordingHelper() override; |
59 | 58 |
60 // Enable debug recording. The create callback is first run to create an | 59 // Enable debug recording. The create callback is first run to create an |
61 // AudioDebugFileWriter. | 60 // AudioDebugFileWriter. |
62 virtual void EnableDebugRecording(const base::FilePath& file_name); | 61 virtual void EnableDebugRecording(const base::FilePath& file_name); |
63 | 62 |
64 // Disable debug recording. The AudioDebugFileWriter is destroyed. | 63 // Disable debug recording. The AudioDebugFileWriter is destroyed. |
65 virtual void DisableDebugRecording(); | 64 virtual void DisableDebugRecording(); |
66 | 65 |
67 // AudioDebugRecorder implementation. Can be called on any thread. | 66 // AudioDebugRecorder implementation. Can be called on any thread. |
68 void OnData(const AudioBus* source) override; | 67 void OnData(const AudioBus* source) override; |
69 | 68 |
70 private: | 69 private: |
71 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, EnableDisable); | 70 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, EnableDisable); |
72 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, OnData); | 71 FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, OnData); |
73 | 72 |
74 // Writes debug data to |debug_writer_|. | 73 // Writes debug data to |debug_writer_|. |
75 void DoWrite(std::unique_ptr<media::AudioBus> data); | 74 void DoWrite(std::unique_ptr<media::AudioBus> data); |
76 | 75 |
77 // Creates an AudioDebugFileWriter. Overridden by test. | 76 // Creates an AudioDebugFileWriter. Overridden by test. |
78 virtual std::unique_ptr<AudioDebugFileWriter> CreateAudioDebugFileWriter( | 77 virtual std::unique_ptr<AudioDebugFileWriter> CreateAudioDebugFileWriter( |
79 const AudioParameters& params, | 78 const AudioParameters& params); |
80 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | |
81 | 79 |
82 const AudioParameters params_; | 80 const AudioParameters params_; |
83 std::unique_ptr<AudioDebugFileWriter> debug_writer_; | 81 std::unique_ptr<AudioDebugFileWriter> debug_writer_; |
84 | 82 |
85 // Used as a flag to indicate if recording is enabled, accessed on different | 83 // Used as a flag to indicate if recording is enabled, accessed on different |
86 // threads. | 84 // threads. |
87 base::subtle::Atomic32 recording_enabled_; | 85 base::subtle::Atomic32 recording_enabled_; |
88 | 86 |
89 // The task runner for accessing |debug_writer_|. | 87 // The task runner for accessing |debug_writer_|. |
90 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 88 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
91 | 89 |
92 // Task runner passed to |debug_writer_| to do file output operations on. | |
93 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | |
94 | |
95 // Runs in destructor if set. | 90 // Runs in destructor if set. |
96 base::OnceClosure on_destruction_closure_; | 91 base::OnceClosure on_destruction_closure_; |
97 | 92 |
98 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; | 93 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_; |
99 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); | 94 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper); |
100 }; | 95 }; |
101 | 96 |
102 } // namespace media | 97 } // namespace media |
103 | 98 |
104 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ | 99 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_ |
OLD | NEW |