OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <string> | 15 #include <string> |
| 16 #include <vector> |
16 | 17 |
17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/base/thread_annotations.h" | 19 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 20 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 | 23 |
23 class AgcManagerDirect; | 24 class AgcManagerDirect; |
24 class AudioBuffer; | 25 class AudioBuffer; |
25 | 26 |
(...skipping 14 matching lines...) Expand all Loading... |
40 class VoiceDetectionImpl; | 41 class VoiceDetectionImpl; |
41 | 42 |
42 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 43 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
43 namespace audioproc { | 44 namespace audioproc { |
44 | 45 |
45 class Event; | 46 class Event; |
46 | 47 |
47 } // namespace audioproc | 48 } // namespace audioproc |
48 #endif | 49 #endif |
49 | 50 |
50 class AudioRate { | |
51 public: | |
52 explicit AudioRate(int sample_rate_hz) { set(sample_rate_hz); } | |
53 virtual ~AudioRate() {} | |
54 | |
55 void set(int rate) { | |
56 rate_ = rate; | |
57 samples_per_channel_ = AudioProcessing::kChunkSizeMs * rate_ / 1000; | |
58 } | |
59 | |
60 int rate() const { return rate_; } | |
61 int samples_per_channel() const { return samples_per_channel_; } | |
62 | |
63 private: | |
64 int rate_; | |
65 int samples_per_channel_; | |
66 }; | |
67 | |
68 class AudioFormat : public AudioRate { | |
69 public: | |
70 AudioFormat(int sample_rate_hz, int num_channels) | |
71 : AudioRate(sample_rate_hz), | |
72 num_channels_(num_channels) {} | |
73 virtual ~AudioFormat() {} | |
74 | |
75 void set(int rate, int num_channels) { | |
76 AudioRate::set(rate); | |
77 num_channels_ = num_channels; | |
78 } | |
79 | |
80 int num_channels() const { return num_channels_; } | |
81 | |
82 private: | |
83 int num_channels_; | |
84 }; | |
85 | |
86 class AudioProcessingImpl : public AudioProcessing { | 51 class AudioProcessingImpl : public AudioProcessing { |
87 public: | 52 public: |
88 explicit AudioProcessingImpl(const Config& config); | 53 explicit AudioProcessingImpl(const Config& config); |
89 | 54 |
90 // AudioProcessingImpl takes ownership of beamformer. | 55 // AudioProcessingImpl takes ownership of beamformer. |
91 AudioProcessingImpl(const Config& config, Beamformer<float>* beamformer); | 56 AudioProcessingImpl(const Config& config, Beamformer<float>* beamformer); |
92 virtual ~AudioProcessingImpl(); | 57 virtual ~AudioProcessingImpl(); |
93 | 58 |
94 // AudioProcessing methods. | 59 // AudioProcessing methods. |
95 int Initialize() override; | 60 int Initialize() override; |
96 int Initialize(int input_sample_rate_hz, | 61 int Initialize(int input_sample_rate_hz, |
97 int output_sample_rate_hz, | 62 int output_sample_rate_hz, |
98 int reverse_sample_rate_hz, | 63 int reverse_sample_rate_hz, |
99 ChannelLayout input_layout, | 64 ChannelLayout input_layout, |
100 ChannelLayout output_layout, | 65 ChannelLayout output_layout, |
101 ChannelLayout reverse_layout) override; | 66 ChannelLayout reverse_layout) override; |
| 67 int Initialize(const ProcessingConfig& processing_config) override; |
102 void SetExtraOptions(const Config& config) override; | 68 void SetExtraOptions(const Config& config) override; |
103 int set_sample_rate_hz(int rate) override; | 69 int set_sample_rate_hz(int rate) override; |
104 int input_sample_rate_hz() const override; | 70 int input_sample_rate_hz() const override; |
105 int sample_rate_hz() const override; | 71 int sample_rate_hz() const override; |
106 int proc_sample_rate_hz() const override; | 72 int proc_sample_rate_hz() const override; |
107 int proc_split_sample_rate_hz() const override; | 73 int proc_split_sample_rate_hz() const override; |
108 int num_input_channels() const override; | 74 int num_input_channels() const override; |
109 int num_output_channels() const override; | 75 int num_output_channels() const override; |
110 int num_reverse_channels() const override; | 76 int num_reverse_channels() const override; |
111 void set_output_will_be_muted(bool muted) override; | 77 void set_output_will_be_muted(bool muted) override; |
112 bool output_will_be_muted() const override; | 78 bool output_will_be_muted() const override; |
113 int ProcessStream(AudioFrame* frame) override; | 79 int ProcessStream(AudioFrame* frame) override; |
114 int ProcessStream(const float* const* src, | 80 int ProcessStream(const float* const* src, |
115 int samples_per_channel, | 81 int samples_per_channel, |
116 int input_sample_rate_hz, | 82 int input_sample_rate_hz, |
117 ChannelLayout input_layout, | 83 ChannelLayout input_layout, |
118 int output_sample_rate_hz, | 84 int output_sample_rate_hz, |
119 ChannelLayout output_layout, | 85 ChannelLayout output_layout, |
120 float* const* dest) override; | 86 float* const* dest) override; |
| 87 int ProcessStream(const float* const* src, |
| 88 const StreamConfig& input_config, |
| 89 const StreamConfig& output_config, |
| 90 float* const* dest) override; |
121 int AnalyzeReverseStream(AudioFrame* frame) override; | 91 int AnalyzeReverseStream(AudioFrame* frame) override; |
122 int AnalyzeReverseStream(const float* const* data, | 92 int AnalyzeReverseStream(const float* const* data, |
123 int samples_per_channel, | 93 int samples_per_channel, |
124 int sample_rate_hz, | 94 int sample_rate_hz, |
125 ChannelLayout layout) override; | 95 ChannelLayout layout) override; |
| 96 int AnalyzeReverseStream(const float* const* data, |
| 97 const StreamConfig& reverse_config) override; |
126 int set_stream_delay_ms(int delay) override; | 98 int set_stream_delay_ms(int delay) override; |
127 int stream_delay_ms() const override; | 99 int stream_delay_ms() const override; |
128 bool was_stream_delay_set() const override; | 100 bool was_stream_delay_set() const override; |
129 void set_delay_offset_ms(int offset) override; | 101 void set_delay_offset_ms(int offset) override; |
130 int delay_offset_ms() const override; | 102 int delay_offset_ms() const override; |
131 void set_stream_key_pressed(bool key_pressed) override; | 103 void set_stream_key_pressed(bool key_pressed) override; |
132 bool stream_key_pressed() const override; | 104 bool stream_key_pressed() const override; |
133 int StartDebugRecording(const char filename[kMaxFilenameSize]) override; | 105 int StartDebugRecording(const char filename[kMaxFilenameSize]) override; |
134 int StartDebugRecording(FILE* handle) override; | 106 int StartDebugRecording(FILE* handle) override; |
135 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; | 107 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; |
136 int StopDebugRecording() override; | 108 int StopDebugRecording() override; |
137 void UpdateHistogramsOnCallEnd() override; | 109 void UpdateHistogramsOnCallEnd() override; |
138 EchoCancellation* echo_cancellation() const override; | 110 EchoCancellation* echo_cancellation() const override; |
139 EchoControlMobile* echo_control_mobile() const override; | 111 EchoControlMobile* echo_control_mobile() const override; |
140 GainControl* gain_control() const override; | 112 GainControl* gain_control() const override; |
141 HighPassFilter* high_pass_filter() const override; | 113 HighPassFilter* high_pass_filter() const override; |
142 LevelEstimator* level_estimator() const override; | 114 LevelEstimator* level_estimator() const override; |
143 NoiseSuppression* noise_suppression() const override; | 115 NoiseSuppression* noise_suppression() const override; |
144 VoiceDetection* voice_detection() const override; | 116 VoiceDetection* voice_detection() const override; |
145 | 117 |
146 protected: | 118 protected: |
147 // Overridden in a mock. | 119 // Overridden in a mock. |
148 virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 120 virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
149 | 121 |
150 private: | 122 private: |
151 int InitializeLocked(int input_sample_rate_hz, | 123 int InitializeLocked(const ProcessingConfig& config) |
152 int output_sample_rate_hz, | |
153 int reverse_sample_rate_hz, | |
154 int num_input_channels, | |
155 int num_output_channels, | |
156 int num_reverse_channels) | |
157 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 124 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
158 int MaybeInitializeLocked(int input_sample_rate_hz, | 125 int MaybeInitializeLocked(const ProcessingConfig& config) |
159 int output_sample_rate_hz, | |
160 int reverse_sample_rate_hz, | |
161 int num_input_channels, | |
162 int num_output_channels, | |
163 int num_reverse_channels) | |
164 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 126 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
165 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 127 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
166 int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 128 int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
167 | 129 |
168 bool is_data_processed() const; | 130 bool is_data_processed() const; |
169 bool output_copy_needed(bool is_data_processed) const; | 131 bool output_copy_needed(bool is_data_processed) const; |
170 bool synthesis_needed(bool is_data_processed) const; | 132 bool synthesis_needed(bool is_data_processed) const; |
171 bool analysis_needed(bool is_data_processed) const; | 133 bool analysis_needed(bool is_data_processed) const; |
172 void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 134 void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
173 void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 135 void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
(...skipping 16 matching lines...) Expand all Loading... |
190 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 152 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
191 // TODO(andrew): make this more graceful. Ideally we would split this stuff | 153 // TODO(andrew): make this more graceful. Ideally we would split this stuff |
192 // out into a separate class with an "enabled" and "disabled" implementation. | 154 // out into a separate class with an "enabled" and "disabled" implementation. |
193 int WriteMessageToDebugFile(); | 155 int WriteMessageToDebugFile(); |
194 int WriteInitMessage(); | 156 int WriteInitMessage(); |
195 rtc::scoped_ptr<FileWrapper> debug_file_; | 157 rtc::scoped_ptr<FileWrapper> debug_file_; |
196 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. | 158 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
197 std::string event_str_; // Memory for protobuf serialization. | 159 std::string event_str_; // Memory for protobuf serialization. |
198 #endif | 160 #endif |
199 | 161 |
200 AudioFormat fwd_in_format_; | 162 // Format of processing streams at input/output call sites. |
201 // This one is an AudioRate, because the forward processing number of channels | 163 ProcessingConfig api_format_; |
202 // is mutable and is tracked by the capture_audio_. | 164 |
203 AudioRate fwd_proc_format_; | 165 // Only the rate and samples fields of fwd_proc_format_ are used because the |
204 AudioFormat fwd_out_format_; | 166 // forward processing number of channels is mutable and is tracked by the |
205 AudioFormat rev_in_format_; | 167 // capture_audio_. |
206 AudioFormat rev_proc_format_; | 168 StreamConfig fwd_proc_format_; |
| 169 StreamConfig rev_proc_format_; |
207 int split_rate_; | 170 int split_rate_; |
208 | 171 |
209 int stream_delay_ms_; | 172 int stream_delay_ms_; |
210 int delay_offset_ms_; | 173 int delay_offset_ms_; |
211 bool was_stream_delay_set_; | 174 bool was_stream_delay_set_; |
212 int last_stream_delay_ms_; | 175 int last_stream_delay_ms_; |
213 int last_aec_system_delay_ms_; | 176 int last_aec_system_delay_ms_; |
214 int stream_delay_jumps_; | 177 int stream_delay_jumps_; |
215 int aec_system_delay_jumps_; | 178 int aec_system_delay_jumps_; |
216 | 179 |
(...skipping 11 matching lines...) Expand all Loading... |
228 const bool beamformer_enabled_; | 191 const bool beamformer_enabled_; |
229 rtc::scoped_ptr<Beamformer<float>> beamformer_; | 192 rtc::scoped_ptr<Beamformer<float>> beamformer_; |
230 const std::vector<Point> array_geometry_; | 193 const std::vector<Point> array_geometry_; |
231 | 194 |
232 const bool supports_48kHz_; | 195 const bool supports_48kHz_; |
233 }; | 196 }; |
234 | 197 |
235 } // namespace webrtc | 198 } // namespace webrtc |
236 | 199 |
237 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ | 200 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
OLD | NEW |