Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 1761813002: Removed the inheritance from ProcessingComponent for EchoCancellerImpl. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // Throughout webrtc, it's assumed that success is represented by zero. 79 // Throughout webrtc, it's assumed that success is represented by zero.
80 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); 80 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
81 81
82 struct AudioProcessingImpl::ApmPublicSubmodules { 82 struct AudioProcessingImpl::ApmPublicSubmodules {
83 ApmPublicSubmodules() 83 ApmPublicSubmodules()
84 : echo_cancellation(nullptr), 84 : echo_cancellation(nullptr),
85 echo_control_mobile(nullptr), 85 echo_control_mobile(nullptr),
86 gain_control(nullptr) {} 86 gain_control(nullptr) {}
87 // Accessed externally of APM without any lock acquired. 87 // Accessed externally of APM without any lock acquired.
88 EchoCancellationImpl* echo_cancellation; 88 std::unique_ptr<EchoCancellationImpl> echo_cancellation;
89 EchoControlMobileImpl* echo_control_mobile; 89 EchoControlMobileImpl* echo_control_mobile;
90 GainControlImpl* gain_control; 90 GainControlImpl* gain_control;
91 std::unique_ptr<HighPassFilterImpl> high_pass_filter; 91 std::unique_ptr<HighPassFilterImpl> high_pass_filter;
92 std::unique_ptr<LevelEstimatorImpl> level_estimator; 92 std::unique_ptr<LevelEstimatorImpl> level_estimator;
93 std::unique_ptr<NoiseSuppressionImpl> noise_suppression; 93 std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
94 std::unique_ptr<VoiceDetectionImpl> voice_detection; 94 std::unique_ptr<VoiceDetectionImpl> voice_detection;
95 std::unique_ptr<GainControlForExperimentalAgc> 95 std::unique_ptr<GainControlForExperimentalAgc>
96 gain_control_for_experimental_agc; 96 gain_control_for_experimental_agc;
97 97
98 // Accessed internally from both render and capture. 98 // Accessed internally from both render and capture.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 capture_(config.Get<ExperimentalNs>().enabled, 161 capture_(config.Get<ExperimentalNs>().enabled,
162 #endif 162 #endif
163 config.Get<Beamforming>().array_geometry, 163 config.Get<Beamforming>().array_geometry,
164 config.Get<Beamforming>().target_direction), 164 config.Get<Beamforming>().target_direction),
165 capture_nonlocked_(config.Get<Beamforming>().enabled) 165 capture_nonlocked_(config.Get<Beamforming>().enabled)
166 { 166 {
167 { 167 {
168 rtc::CritScope cs_render(&crit_render_); 168 rtc::CritScope cs_render(&crit_render_);
169 rtc::CritScope cs_capture(&crit_capture_); 169 rtc::CritScope cs_capture(&crit_capture_);
170 170
171 public_submodules_->echo_cancellation = 171 public_submodules_->echo_cancellation.reset(
172 new EchoCancellationImpl(this, &crit_render_, &crit_capture_); 172 new EchoCancellationImpl(this, &crit_render_, &crit_capture_));
173 public_submodules_->echo_control_mobile = 173 public_submodules_->echo_control_mobile =
174 new EchoControlMobileImpl(this, &crit_render_, &crit_capture_); 174 new EchoControlMobileImpl(this, &crit_render_, &crit_capture_);
175 public_submodules_->gain_control = 175 public_submodules_->gain_control =
176 new GainControlImpl(this, &crit_capture_, &crit_capture_); 176 new GainControlImpl(this, &crit_capture_, &crit_capture_);
177 public_submodules_->high_pass_filter.reset( 177 public_submodules_->high_pass_filter.reset(
178 new HighPassFilterImpl(&crit_capture_)); 178 new HighPassFilterImpl(&crit_capture_));
179 public_submodules_->level_estimator.reset( 179 public_submodules_->level_estimator.reset(
180 new LevelEstimatorImpl(&crit_capture_)); 180 new LevelEstimatorImpl(&crit_capture_));
181 public_submodules_->noise_suppression.reset( 181 public_submodules_->noise_suppression.reset(
182 new NoiseSuppressionImpl(&crit_capture_)); 182 new NoiseSuppressionImpl(&crit_capture_));
183 public_submodules_->voice_detection.reset( 183 public_submodules_->voice_detection.reset(
184 new VoiceDetectionImpl(&crit_capture_)); 184 new VoiceDetectionImpl(&crit_capture_));
185 public_submodules_->gain_control_for_experimental_agc.reset( 185 public_submodules_->gain_control_for_experimental_agc.reset(
186 new GainControlForExperimentalAgc(public_submodules_->gain_control, 186 new GainControlForExperimentalAgc(public_submodules_->gain_control,
187 &crit_capture_)); 187 &crit_capture_));
188
189 private_submodules_->component_list.push_back(
190 public_submodules_->echo_cancellation);
191 private_submodules_->component_list.push_back( 188 private_submodules_->component_list.push_back(
192 public_submodules_->echo_control_mobile); 189 public_submodules_->echo_control_mobile);
193 private_submodules_->component_list.push_back( 190 private_submodules_->component_list.push_back(
194 public_submodules_->gain_control); 191 public_submodules_->gain_control);
195 } 192 }
196 193
197 SetExtraOptions(config); 194 SetExtraOptions(config);
198 } 195 }
199 196
200 AudioProcessingImpl::~AudioProcessingImpl() { 197 AudioProcessingImpl::~AudioProcessingImpl() {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 formats_.api_format.output_stream().num_frames())); 312 formats_.api_format.output_stream().num_frames()));
316 313
317 // Initialize all components. 314 // Initialize all components.
318 for (auto item : private_submodules_->component_list) { 315 for (auto item : private_submodules_->component_list) {
319 int err = item->Initialize(); 316 int err = item->Initialize();
320 if (err != kNoError) { 317 if (err != kNoError) {
321 return err; 318 return err;
322 } 319 }
323 } 320 }
324 321
322 InitializeEchoCanceller();
325 InitializeExperimentalAgc(); 323 InitializeExperimentalAgc();
326 InitializeTransient(); 324 InitializeTransient();
327 InitializeBeamformer(); 325 InitializeBeamformer();
328 InitializeIntelligibility(); 326 InitializeIntelligibility();
329 InitializeHighPassFilter(); 327 InitializeHighPassFilter();
330 InitializeNoiseSuppression(); 328 InitializeNoiseSuppression();
331 InitializeLevelEstimator(); 329 InitializeLevelEstimator();
332 InitializeVoiceDetection(); 330 InitializeVoiceDetection();
333 331
334 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 332 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 414 }
417 415
418 void AudioProcessingImpl::SetExtraOptions(const Config& config) { 416 void AudioProcessingImpl::SetExtraOptions(const Config& config) {
419 // Run in a single-threaded manner when setting the extra options. 417 // Run in a single-threaded manner when setting the extra options.
420 rtc::CritScope cs_render(&crit_render_); 418 rtc::CritScope cs_render(&crit_render_);
421 rtc::CritScope cs_capture(&crit_capture_); 419 rtc::CritScope cs_capture(&crit_capture_);
422 for (auto item : private_submodules_->component_list) { 420 for (auto item : private_submodules_->component_list) {
423 item->SetExtraOptions(config); 421 item->SetExtraOptions(config);
424 } 422 }
425 423
424 public_submodules_->echo_cancellation->SetExtraOptions(config);
425
426 if (capture_.transient_suppressor_enabled != 426 if (capture_.transient_suppressor_enabled !=
427 config.Get<ExperimentalNs>().enabled) { 427 config.Get<ExperimentalNs>().enabled) {
428 capture_.transient_suppressor_enabled = 428 capture_.transient_suppressor_enabled =
429 config.Get<ExperimentalNs>().enabled; 429 config.Get<ExperimentalNs>().enabled;
430 InitializeTransient(); 430 InitializeTransient();
431 } 431 }
432 432
433 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 433 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
434 if (capture_nonlocked_.beamformer_enabled != 434 if (capture_nonlocked_.beamformer_enabled !=
435 config.Get<Beamforming>().enabled) { 435 config.Get<Beamforming>().enabled) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 } 1080 }
1081 return kNoError; 1081 return kNoError;
1082 #else 1082 #else
1083 return kUnsupportedFunctionError; 1083 return kUnsupportedFunctionError;
1084 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1084 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1085 } 1085 }
1086 1086
1087 EchoCancellation* AudioProcessingImpl::echo_cancellation() const { 1087 EchoCancellation* AudioProcessingImpl::echo_cancellation() const {
1088 // Adding a lock here has no effect as it allows any access to the submodule 1088 // Adding a lock here has no effect as it allows any access to the submodule
1089 // from the returned pointer. 1089 // from the returned pointer.
1090 return public_submodules_->echo_cancellation; 1090 return public_submodules_->echo_cancellation.get();
1091 } 1091 }
1092 1092
1093 EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const { 1093 EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const {
1094 // Adding a lock here has no effect as it allows any access to the submodule 1094 // Adding a lock here has no effect as it allows any access to the submodule
1095 // from the returned pointer. 1095 // from the returned pointer.
1096 return public_submodules_->echo_control_mobile; 1096 return public_submodules_->echo_control_mobile;
1097 } 1097 }
1098 1098
1099 GainControl* AudioProcessingImpl::gain_control() const { 1099 GainControl* AudioProcessingImpl::gain_control() const {
1100 // Adding a lock here has no effect as it allows any access to the submodule 1100 // Adding a lock here has no effect as it allows any access to the submodule
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return true; 1138 return true;
1139 } 1139 }
1140 1140
1141 // All of the private submodules modify the data. 1141 // All of the private submodules modify the data.
1142 for (auto item : private_submodules_->component_list) { 1142 for (auto item : private_submodules_->component_list) {
1143 if (item->is_component_enabled()) { 1143 if (item->is_component_enabled()) {
1144 return true; 1144 return true;
1145 } 1145 }
1146 } 1146 }
1147 1147
1148 if (public_submodules_->echo_cancellation->is_enabled()) {
the sun 2016/03/03 13:13:05 I think you can put this in the first conditional
peah-webrtc 2016/03/03 13:56:16 Done.
1149 return true;
1150 }
1151
1148 // The capture data is otherwise unchanged. 1152 // The capture data is otherwise unchanged.
1149 return false; 1153 return false;
1150 } 1154 }
1151 1155
1152 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { 1156 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const {
1153 // Check if we've upmixed or downmixed the audio. 1157 // Check if we've upmixed or downmixed the audio.
1154 return ((formats_.api_format.output_stream().num_channels() != 1158 return ((formats_.api_format.output_stream().num_channels() !=
1155 formats_.api_format.input_stream().num_channels()) || 1159 formats_.api_format.input_stream().num_channels()) ||
1156 is_data_processed || capture_.transient_suppressor_enabled); 1160 is_data_processed || capture_.transient_suppressor_enabled);
1157 } 1161 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 void AudioProcessingImpl::InitializeHighPassFilter() { 1246 void AudioProcessingImpl::InitializeHighPassFilter() {
1243 public_submodules_->high_pass_filter->Initialize(num_proc_channels(), 1247 public_submodules_->high_pass_filter->Initialize(num_proc_channels(),
1244 proc_sample_rate_hz()); 1248 proc_sample_rate_hz());
1245 } 1249 }
1246 1250
1247 void AudioProcessingImpl::InitializeNoiseSuppression() { 1251 void AudioProcessingImpl::InitializeNoiseSuppression() {
1248 public_submodules_->noise_suppression->Initialize(num_proc_channels(), 1252 public_submodules_->noise_suppression->Initialize(num_proc_channels(),
1249 proc_sample_rate_hz()); 1253 proc_sample_rate_hz());
1250 } 1254 }
1251 1255
1256 void AudioProcessingImpl::InitializeEchoCanceller() {
1257 public_submodules_->echo_cancellation->Initialize();
1258 }
1259
1252 void AudioProcessingImpl::InitializeLevelEstimator() { 1260 void AudioProcessingImpl::InitializeLevelEstimator() {
1253 public_submodules_->level_estimator->Initialize(); 1261 public_submodules_->level_estimator->Initialize();
1254 } 1262 }
1255 1263
1256 void AudioProcessingImpl::InitializeVoiceDetection() { 1264 void AudioProcessingImpl::InitializeVoiceDetection() {
1257 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); 1265 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
1258 } 1266 }
1259 1267
1260 void AudioProcessingImpl::MaybeUpdateHistograms() { 1268 void AudioProcessingImpl::MaybeUpdateHistograms() {
1261 static const int kMinDiffDelayMs = 60; 1269 static const int kMinDiffDelayMs = 60;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); 1458 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
1451 1459
1452 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1460 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1453 &debug_dump_.num_bytes_left_for_log_, 1461 &debug_dump_.num_bytes_left_for_log_,
1454 &crit_debug_, &debug_dump_.capture)); 1462 &crit_debug_, &debug_dump_.capture));
1455 return kNoError; 1463 return kNoError;
1456 } 1464 }
1457 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1465 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1458 1466
1459 } // namespace webrtc 1467 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698