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 namespace webrtc {
14
15 namespace {
16
17 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
18 // If we are on Android, iOS and/or ARM, use a lower complexity setting by
19 // default, to save encoder complexity.
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 constexpr int AudioEncoderOpusConfig::kDefaultFrameSizeMs;
31 constexpr int AudioEncoderOpusConfig::kMinBitrateBps;
32 constexpr int AudioEncoderOpusConfig::kMaxBitrateBps;
33
AudioEncoderOpusConfig()34 AudioEncoderOpusConfig::AudioEncoderOpusConfig()
35 : frame_size_ms(kDefaultFrameSizeMs),
36 sample_rate_hz(48000),
37 num_channels(1),
38 application(ApplicationMode::kVoip),
39 bitrate_bps(32000),
40 fec_enabled(false),
41 cbr_enabled(false),
42 max_playback_rate_hz(48000),
43 complexity(kDefaultComplexity),
44 low_rate_complexity(kDefaultLowRateComplexity),
45 complexity_threshold_bps(12500),
46 complexity_threshold_window_bps(1500),
47 dtx_enabled(false),
48 uplink_bandwidth_update_interval_ms(200),
49 payload_type(-1) {}
50 AudioEncoderOpusConfig::AudioEncoderOpusConfig(const AudioEncoderOpusConfig&) =
51 default;
52 AudioEncoderOpusConfig::~AudioEncoderOpusConfig() = default;
53 AudioEncoderOpusConfig& AudioEncoderOpusConfig::operator=(
54 const AudioEncoderOpusConfig&) = default;
55
IsOk() const56 bool AudioEncoderOpusConfig::IsOk() const {
57 if (frame_size_ms <= 0 || frame_size_ms % 10 != 0)
58 return false;
59 if (sample_rate_hz != 16000 && sample_rate_hz != 48000) {
60 // Unsupported input sample rate. (libopus supports a few other rates as
61 // well; we can add support for them when needed.)
62 return false;
63 }
64 if (num_channels >= 255) {
65 return false;
66 }
67 if (!bitrate_bps)
68 return false;
69 if (*bitrate_bps < kMinBitrateBps || *bitrate_bps > kMaxBitrateBps)
70 return false;
71 if (complexity < 0 || complexity > 10)
72 return false;
73 if (low_rate_complexity < 0 || low_rate_complexity > 10)
74 return false;
75 return true;
76 }
77 } // namespace webrtc
78