tor-browser

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

audio_encoder_opus_config.cc (2364B)


      1 /*
      2 *  Copyright (c) 2017 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 "api/audio_codecs/opus/audio_encoder_opus_config.h"
     12 
     13 #include "api/audio_codecs/audio_encoder.h"
     14 
     15 namespace webrtc {
     16 
     17 namespace {
     18 
     19 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
     20 constexpr int kDefaultComplexity = 5;
     21 #else
     22 constexpr int kDefaultComplexity = 9;
     23 #endif
     24 
     25 constexpr int kDefaultLowRateComplexity =
     26    WEBRTC_OPUS_VARIABLE_COMPLEXITY ? 9 : kDefaultComplexity;
     27 
     28 }  // namespace
     29 
     30 AudioEncoderOpusConfig::AudioEncoderOpusConfig()
     31    : frame_size_ms(kDefaultFrameSizeMs),
     32      sample_rate_hz(48000),
     33      num_channels(1),
     34      application(ApplicationMode::kVoip),
     35      bitrate_bps(32000),
     36      fec_enabled(false),
     37      cbr_enabled(false),
     38      max_playback_rate_hz(48000),
     39      complexity(kDefaultComplexity),
     40      low_rate_complexity(kDefaultLowRateComplexity),
     41      complexity_threshold_bps(12500),
     42      complexity_threshold_window_bps(1500),
     43      dtx_enabled(false),
     44      uplink_bandwidth_update_interval_ms(200),
     45      payload_type(-1) {}
     46 AudioEncoderOpusConfig::AudioEncoderOpusConfig(const AudioEncoderOpusConfig&) =
     47    default;
     48 AudioEncoderOpusConfig::~AudioEncoderOpusConfig() = default;
     49 AudioEncoderOpusConfig& AudioEncoderOpusConfig::operator=(
     50    const AudioEncoderOpusConfig&) = default;
     51 
     52 bool AudioEncoderOpusConfig::IsOk() const {
     53  if (frame_size_ms <= 0 || frame_size_ms % 10 != 0)
     54    return false;
     55  if (sample_rate_hz != 16000 && sample_rate_hz != 48000) {
     56    // Unsupported input sample rate. (libopus supports a few other rates as
     57    // well; we can add support for them when needed.)
     58    return false;
     59  }
     60  if (num_channels > AudioEncoder::kMaxNumberOfChannels) {
     61    return false;
     62  }
     63  if (!bitrate_bps)
     64    return false;
     65  if (*bitrate_bps < kMinBitrateBps || *bitrate_bps > kMaxBitrateBps)
     66    return false;
     67  if (complexity < 0 || complexity > 10)
     68    return false;
     69  if (low_rate_complexity < 0 || low_rate_complexity > 10)
     70    return false;
     71  return true;
     72 }
     73 }  // namespace webrtc