Line data Source code
1 : /*
2 : * Copyright (c) 2016 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 "webrtc/modules/audio_coding/audio_network_adaptor/dtx_controller.h"
12 : #include "webrtc/base/checks.h"
13 :
14 : namespace webrtc {
15 :
16 0 : DtxController::Config::Config(bool initial_dtx_enabled,
17 : int dtx_enabling_bandwidth_bps,
18 0 : int dtx_disabling_bandwidth_bps)
19 : : initial_dtx_enabled(initial_dtx_enabled),
20 : dtx_enabling_bandwidth_bps(dtx_enabling_bandwidth_bps),
21 0 : dtx_disabling_bandwidth_bps(dtx_disabling_bandwidth_bps) {}
22 :
23 0 : DtxController::DtxController(const Config& config)
24 0 : : config_(config), dtx_enabled_(config_.initial_dtx_enabled) {}
25 :
26 0 : void DtxController::MakeDecision(
27 : const NetworkMetrics& metrics,
28 : AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
29 : // Decision on |enable_dtx| should not have been made.
30 0 : RTC_DCHECK(!config->enable_dtx);
31 :
32 0 : if (metrics.uplink_bandwidth_bps) {
33 0 : if (dtx_enabled_ &&
34 0 : *metrics.uplink_bandwidth_bps >= config_.dtx_disabling_bandwidth_bps) {
35 0 : dtx_enabled_ = false;
36 0 : } else if (!dtx_enabled_ &&
37 0 : *metrics.uplink_bandwidth_bps <=
38 0 : config_.dtx_enabling_bandwidth_bps) {
39 0 : dtx_enabled_ = true;
40 : }
41 : }
42 0 : config->enable_dtx = rtc::Optional<bool>(dtx_enabled_);
43 0 : }
44 :
45 : } // namespace webrtc
|