tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

config_selector.cc (2354B)


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