| 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 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/base/criticalsection.h" |
| 18 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
| 20 #include "webrtc/base/thread_checker.h" | 21 #include "webrtc/base/thread_checker.h" |
| 21 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 22 | 23 |
| 23 namespace webrtc { | 24 namespace webrtc { |
| 24 | 25 |
| 25 class AgcManagerDirect; | 26 class AgcManagerDirect; |
| 26 class AudioBuffer; | 27 class AudioBuffer; |
| 27 class AudioConverter; | 28 class AudioConverter; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 int AnalyzeReverseStream(const float* const* data, | 93 int AnalyzeReverseStream(const float* const* data, |
| 93 size_t samples_per_channel, | 94 size_t samples_per_channel, |
| 94 int sample_rate_hz, | 95 int sample_rate_hz, |
| 95 ChannelLayout layout) override; | 96 ChannelLayout layout) override; |
| 96 int ProcessReverseStream(const float* const* src, | 97 int ProcessReverseStream(const float* const* src, |
| 97 const StreamConfig& reverse_input_config, | 98 const StreamConfig& reverse_input_config, |
| 98 const StreamConfig& reverse_output_config, | 99 const StreamConfig& reverse_output_config, |
| 99 float* const* dest) override; | 100 float* const* dest) override; |
| 100 int set_stream_delay_ms(int delay) override; | 101 int set_stream_delay_ms(int delay) override; |
| 101 int stream_delay_ms() const override; | 102 int stream_delay_ms() const override; |
| 102 bool was_stream_delay_set() const override; | 103 bool was_stream_delay_set() const override |
| 104 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 103 void set_delay_offset_ms(int offset) override; | 105 void set_delay_offset_ms(int offset) override; |
| 104 int delay_offset_ms() const override; | 106 int delay_offset_ms() const override; |
| 105 void set_stream_key_pressed(bool key_pressed) override; | 107 void set_stream_key_pressed(bool key_pressed) override; |
| 106 int StartDebugRecording(const char filename[kMaxFilenameSize]) override; | 108 int StartDebugRecording(const char filename[kMaxFilenameSize]) override; |
| 107 int StartDebugRecording(FILE* handle) override; | 109 int StartDebugRecording(FILE* handle) override; |
| 108 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; | 110 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; |
| 109 int StopDebugRecording() override; | 111 int StopDebugRecording() override; |
| 110 void UpdateHistogramsOnCallEnd() override; | 112 void UpdateHistogramsOnCallEnd() override; |
| 111 EchoCancellation* echo_cancellation() const override; | 113 EchoCancellation* echo_cancellation() const override; |
| 112 EchoControlMobile* echo_control_mobile() const override; | 114 EchoControlMobile* echo_control_mobile() const override; |
| 113 GainControl* gain_control() const override; | 115 GainControl* gain_control() const override; |
| 114 HighPassFilter* high_pass_filter() const override; | 116 HighPassFilter* high_pass_filter() const override; |
| 115 LevelEstimator* level_estimator() const override; | 117 LevelEstimator* level_estimator() const override; |
| 116 NoiseSuppression* noise_suppression() const override; | 118 NoiseSuppression* noise_suppression() const override; |
| 117 VoiceDetection* voice_detection() const override; | 119 VoiceDetection* voice_detection() const override; |
| 118 | 120 |
| 119 protected: | 121 protected: |
| 120 // Overridden in a mock. | 122 // Overridden in a mock. |
| 121 virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 123 virtual int InitializeLocked() |
| 124 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 122 | 125 |
| 123 private: | 126 private: |
| 124 int InitializeLocked(const ProcessingConfig& config) | 127 int InitializeLocked(const ProcessingConfig& config) |
| 125 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 128 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 126 int MaybeInitializeLocked(const ProcessingConfig& config) | 129 int MaybeInitialize(const ProcessingConfig& config) |
| 127 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 130 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 128 // TODO(ekm): Remove once all clients updated to new interface. | 131 // TODO(ekm): Remove once all clients updated to new interface. |
| 129 int AnalyzeReverseStream(const float* const* src, | 132 int AnalyzeReverseStreamLocked(const float* const* src, |
| 130 const StreamConfig& input_config, | 133 const StreamConfig& input_config, |
| 131 const StreamConfig& output_config); | 134 const StreamConfig& output_config) |
| 132 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 135 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 133 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 136 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 137 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 134 | 138 |
| 135 bool is_data_processed() const; | 139 bool is_data_processed() const EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 136 bool output_copy_needed(bool is_data_processed) const; | 140 bool output_copy_needed(bool is_data_processed) const |
| 137 bool synthesis_needed(bool is_data_processed) const; | 141 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 138 bool analysis_needed(bool is_data_processed) const; | 142 bool synthesis_needed(bool is_data_processed) const |
| 139 bool is_rev_processed() const; | 143 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 140 bool rev_conversion_needed() const; | 144 bool analysis_needed(bool is_data_processed) const |
| 141 void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 145 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 142 void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 146 bool is_rev_processed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 143 void InitializeBeamformer() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 147 bool rev_conversion_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 144 void InitializeIntelligibility() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 148 void InitializeExperimentalAgc() |
| 145 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 149 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 150 void InitializeTransient() |
| 151 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 152 void InitializeBeamformer() |
| 153 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 154 void InitializeIntelligibility() |
| 155 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 156 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 146 | 157 |
| 147 EchoCancellationImpl* echo_cancellation_; | 158 EchoCancellationImpl* echo_cancellation_; |
| 148 EchoControlMobileImpl* echo_control_mobile_; | 159 EchoControlMobileImpl* echo_control_mobile_; |
| 149 GainControlImpl* gain_control_; | 160 GainControlImpl* gain_control_; |
| 150 HighPassFilterImpl* high_pass_filter_; | 161 HighPassFilterImpl* high_pass_filter_; |
| 151 LevelEstimatorImpl* level_estimator_; | 162 LevelEstimatorImpl* level_estimator_; |
| 152 NoiseSuppressionImpl* noise_suppression_; | 163 NoiseSuppressionImpl* noise_suppression_; |
| 153 VoiceDetectionImpl* voice_detection_; | 164 VoiceDetectionImpl* voice_detection_; |
| 154 rtc::scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc_; | 165 rtc::scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc_; |
| 155 | 166 |
| 156 std::list<ProcessingComponent*> component_list_; | 167 std::list<ProcessingComponent*> component_list_ GUARDED_BY(crit_capture_); |
| 157 CriticalSectionWrapper* crit_; | 168 mutable rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_); |
| 169 mutable rtc::CriticalSection crit_capture_; |
| 158 rtc::ThreadChecker render_thread_; | 170 rtc::ThreadChecker render_thread_; |
| 159 rtc::ThreadChecker capture_thread_; | 171 rtc::ThreadChecker capture_thread_; |
| 160 rtc::scoped_ptr<AudioBuffer> render_audio_; | 172 rtc::scoped_ptr<AudioBuffer> render_audio_ GUARDED_BY(crit_render_); |
| 161 rtc::scoped_ptr<AudioBuffer> capture_audio_; | 173 rtc::scoped_ptr<AudioBuffer> capture_audio_ GUARDED_BY(crit_capture_); |
| 162 rtc::scoped_ptr<AudioConverter> render_converter_; | 174 rtc::scoped_ptr<AudioConverter> render_converter_ GUARDED_BY(crit_render_); |
| 163 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 175 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 164 // TODO(andrew): make this more graceful. Ideally we would split this stuff | 176 // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 165 // out into a separate class with an "enabled" and "disabled" implementation. | 177 // out into a separate class with an "enabled" and "disabled" implementation. |
| 166 int WriteMessageToDebugFile(); | 178 int WriteMessageToDebugFile(); |
| 167 int WriteInitMessage(); | 179 int WriteInitMessage(); |
| 168 | 180 |
| 169 // Writes Config message. If not |forced|, only writes the current config if | 181 // Writes Config message. If not |forced|, only writes the current config if |
| 170 // it is different from the last saved one; if |forced|, writes the config | 182 // it is different from the last saved one; if |forced|, writes the config |
| 171 // regardless of the last saved. | 183 // regardless of the last saved. |
| 172 int WriteConfigMessage(bool forced); | 184 int WriteConfigMessage(bool forced) EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 173 | 185 |
| 174 rtc::scoped_ptr<FileWrapper> debug_file_; | 186 rtc::scoped_ptr<FileWrapper> debug_file_; |
| 175 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. | 187 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
| 176 std::string event_str_; // Memory for protobuf serialization. | 188 std::string event_str_; // Memory for protobuf serialization. |
| 177 | 189 |
| 178 // Serialized string of last saved APM configuration. | 190 // Serialized string of last saved APM configuration. |
| 179 std::string last_serialized_config_; | 191 std::string last_serialized_config_; |
| 180 #endif | 192 #endif |
| 181 | 193 |
| 182 // State that is written to while holding both the render and capture locks | 194 // State that is written to while holding both the render and capture locks |
| 183 // but can be read while holding only one of the locks. | 195 // but can be read while holding only one of the locks. |
| 184 struct SharedState { | 196 struct SharedState { |
| 185 SharedState() | 197 SharedState() |
| 186 : // Format of processing streams at input/output call sites. | 198 : // Format of processing streams at input/output call sites. |
| 187 api_format_({{{kSampleRate16kHz, 1, false}, | 199 api_format_({{{kSampleRate16kHz, 1, false}, |
| 188 {kSampleRate16kHz, 1, false}, | 200 {kSampleRate16kHz, 1, false}, |
| 189 {kSampleRate16kHz, 1, false}, | 201 {kSampleRate16kHz, 1, false}, |
| 190 {kSampleRate16kHz, 1, false}}}) {} | 202 {kSampleRate16kHz, 1, false}}}) {} |
| 191 ProcessingConfig api_format_; | 203 ProcessingConfig api_format_; |
| 192 } shared_state_; | 204 } shared_state_; |
| 193 | 205 |
| 194 // Only the rate and samples fields of fwd_proc_format_ are used because the | 206 // Only the rate and samples fields of fwd_proc_format_ are used because the |
| 195 // forward processing number of channels is mutable and is tracked by the | 207 // forward processing number of channels is mutable and is tracked by the |
| 196 // capture_audio_. | 208 // capture_audio_. |
| 197 StreamConfig fwd_proc_format_; | 209 StreamConfig fwd_proc_format_; |
| 198 StreamConfig rev_proc_format_; | 210 StreamConfig rev_proc_format_; |
| 199 int split_rate_; | 211 int split_rate_; |
| 200 | 212 |
| 201 int stream_delay_ms_; | 213 int stream_delay_ms_ GUARDED_BY(crit_capture_); |
| 202 int delay_offset_ms_; | 214 int delay_offset_ms_ GUARDED_BY(crit_capture_); |
| 203 bool was_stream_delay_set_; | 215 bool was_stream_delay_set_ GUARDED_BY(crit_capture_); |
| 204 int last_stream_delay_ms_; | 216 int last_stream_delay_ms_ GUARDED_BY(crit_capture_); |
| 205 int last_aec_system_delay_ms_; | 217 int last_aec_system_delay_ms_ GUARDED_BY(crit_capture_); |
| 206 int stream_delay_jumps_; | 218 int stream_delay_jumps_ GUARDED_BY(crit_capture_); |
| 207 int aec_system_delay_jumps_; | 219 int aec_system_delay_jumps_ GUARDED_BY(crit_capture_); |
| 208 | 220 |
| 209 bool output_will_be_muted_ GUARDED_BY(crit_); | 221 bool output_will_be_muted_ GUARDED_BY(crit_capture_); |
| 210 | 222 |
| 211 bool key_pressed_; | 223 bool key_pressed_ GUARDED_BY(crit_capture_); |
| 212 | 224 |
| 213 // Only set through the constructor's Config parameter. | 225 // Only set through the constructor's Config parameter. |
| 214 const bool use_new_agc_; | 226 const bool use_new_agc_; |
| 215 rtc::scoped_ptr<AgcManagerDirect> agc_manager_ GUARDED_BY(crit_); | 227 rtc::scoped_ptr<AgcManagerDirect> agc_manager_ GUARDED_BY(crit_capture_); |
| 216 int agc_startup_min_volume_; | 228 int agc_startup_min_volume_ GUARDED_BY(crit_render_) |
| 229 GUARDED_BY(crit_capture_); |
| 217 | 230 |
| 218 bool transient_suppressor_enabled_; | 231 bool transient_suppressor_enabled_ GUARDED_BY(crit_capture_); |
| 219 rtc::scoped_ptr<TransientSuppressor> transient_suppressor_; | 232 |
| 220 const bool beamformer_enabled_; | 233 rtc::scoped_ptr<TransientSuppressor> transient_suppressor_ |
| 221 rtc::scoped_ptr<Beamformer<float>> beamformer_; | 234 GUARDED_BY(crit_capture_); |
| 222 const std::vector<Point> array_geometry_; | 235 const bool beamformer_enabled_ GUARDED_BY(crit_capture_); |
| 236 rtc::scoped_ptr<Beamformer<float>> beamformer_ GUARDED_BY(crit_capture_); |
| 237 const std::vector<Point> array_geometry_ GUARDED_BY(crit_render_) |
| 238 GUARDED_BY(crit_capture_); |
| 223 | 239 |
| 224 bool intelligibility_enabled_; | 240 bool intelligibility_enabled_; |
| 225 rtc::scoped_ptr<IntelligibilityEnhancer> intelligibility_enhancer_; | 241 rtc::scoped_ptr<IntelligibilityEnhancer> intelligibility_enhancer_; |
| 226 }; | 242 }; |
| 227 | 243 |
| 228 } // namespace webrtc | 244 } // namespace webrtc |
| 229 | 245 |
| 230 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ | 246 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
| OLD | NEW |