blob: c55344da7947bcda1faf8495ab38681ba0f5ecb7 [file] [log] [blame]
Sam Zackrisson64cdcc02022-04-07 15:28:14 +02001
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
16namespace webrtc {
17namespace {
18
19// Validates that the mono and the multichannel configs have compatible fields.
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 }
Sam Zackrisson64cdcc02022-04-07 15:28:14 +020026 if (mono_config.filter.export_linear_aec_output !=
27 multichannel_config.filter.export_linear_aec_output) {
28 return false;
29 }
Sam Zackrisson64cdcc02022-04-07 15:28:14 +020030 if (mono_config.filter.high_pass_filter_echo_reference !=
31 multichannel_config.filter.high_pass_filter_echo_reference) {
32 return false;
33 }
Sam Zackrisson64cdcc02022-04-07 15:28:14 +020034 if (mono_config.multi_channel.detect_stereo_content !=
35 multichannel_config.multi_channel.detect_stereo_content) {
36 return false;
37 }
Sam Zackrissonfa07b432022-04-08 15:28:45 +020038 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 Zackrisson64cdcc02022-04-07 15:28:14 +020043 return true;
44}
45
46} // namespace
47
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
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