Sam Zackrisson | 64cdcc0 | 2022-04-07 15:28:14 +0200 | [diff] [blame] | 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. |
| 20 | bool 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 | } |
Sam Zackrisson | 64cdcc0 | 2022-04-07 15:28:14 +0200 | [diff] [blame] | 26 | if (mono_config.filter.export_linear_aec_output != |
| 27 | multichannel_config.filter.export_linear_aec_output) { |
| 28 | return false; |
| 29 | } |
Sam Zackrisson | 64cdcc0 | 2022-04-07 15:28:14 +0200 | [diff] [blame] | 30 | if (mono_config.filter.high_pass_filter_echo_reference != |
| 31 | multichannel_config.filter.high_pass_filter_echo_reference) { |
| 32 | return false; |
| 33 | } |
Sam Zackrisson | 64cdcc0 | 2022-04-07 15:28:14 +0200 | [diff] [blame] | 34 | if (mono_config.multi_channel.detect_stereo_content != |
| 35 | multichannel_config.multi_channel.detect_stereo_content) { |
| 36 | return false; |
| 37 | } |
Sam Zackrisson | fa07b43 | 2022-04-08 15:28:45 +0200 | [diff] [blame] | 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 | } |
Sam Zackrisson | 64cdcc0 | 2022-04-07 15:28:14 +0200 | [diff] [blame] | 43 | return true; |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | |
| 48 | ConfigSelector::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 | |
| 63 | void 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 |