1 2 /* 3 * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. 4 * 5 * Use of this source code is governed by a BSD-style license 6 * that can be found in the LICENSE file in the root of the source 7 * tree. An additional intellectual property rights grant can be found 8 * in the file PATENTS. All contributing project authors may 9 * be found in the AUTHORS file in the root of the source tree. 10 */ 11 12 #include "modules/audio_processing/aec3/config_selector.h" 13 14 #include "rtc_base/checks.h" 15 16 namespace webrtc { 17 namespace { 18 19 // Validates that the mono and the multichannel configs have compatible fields. CompatibleConfigs(const EchoCanceller3Config & mono_config,const EchoCanceller3Config & multichannel_config)20bool CompatibleConfigs(const EchoCanceller3Config& mono_config, 21 const EchoCanceller3Config& multichannel_config) { 22 if (mono_config.delay.fixed_capture_delay_samples != 23 multichannel_config.delay.fixed_capture_delay_samples) { 24 return false; 25 } 26 if (mono_config.filter.export_linear_aec_output != 27 multichannel_config.filter.export_linear_aec_output) { 28 return false; 29 } 30 if (mono_config.filter.high_pass_filter_echo_reference != 31 multichannel_config.filter.high_pass_filter_echo_reference) { 32 return false; 33 } 34 if (mono_config.multi_channel.detect_stereo_content != 35 multichannel_config.multi_channel.detect_stereo_content) { 36 return false; 37 } 38 if (mono_config.multi_channel.stereo_detection_timeout_threshold_seconds != 39 multichannel_config.multi_channel 40 .stereo_detection_timeout_threshold_seconds) { 41 return false; 42 } 43 return true; 44 } 45 46 } // namespace 47 ConfigSelector(const EchoCanceller3Config & config,const absl::optional<EchoCanceller3Config> & multichannel_config,int num_render_input_channels)48ConfigSelector::ConfigSelector( 49 const EchoCanceller3Config& config, 50 const absl::optional<EchoCanceller3Config>& multichannel_config, 51 int num_render_input_channels) 52 : config_(config), multichannel_config_(multichannel_config) { 53 if (multichannel_config_.has_value()) { 54 RTC_DCHECK(CompatibleConfigs(config_, *multichannel_config_)); 55 } 56 57 Update(!config_.multi_channel.detect_stereo_content && 58 num_render_input_channels > 1); 59 60 RTC_DCHECK(active_config_); 61 } 62 Update(bool multichannel_content)63void ConfigSelector::Update(bool multichannel_content) { 64 if (multichannel_content && multichannel_config_.has_value()) { 65 active_config_ = &(*multichannel_config_); 66 } else { 67 active_config_ = &config_; 68 } 69 } 70 71 } // namespace webrtc 72