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 <algorithm>
12 :
13 : #include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h"
14 : #include "webrtc/base/checks.h"
15 :
16 : namespace webrtc {
17 :
18 0 : ChannelController::Config::Config(size_t num_encoder_channels,
19 : size_t intial_channels_to_encode,
20 : int channel_1_to_2_bandwidth_bps,
21 0 : int channel_2_to_1_bandwidth_bps)
22 : : num_encoder_channels(num_encoder_channels),
23 : intial_channels_to_encode(intial_channels_to_encode),
24 : channel_1_to_2_bandwidth_bps(channel_1_to_2_bandwidth_bps),
25 0 : channel_2_to_1_bandwidth_bps(channel_2_to_1_bandwidth_bps) {}
26 :
27 0 : ChannelController::ChannelController(const Config& config)
28 0 : : config_(config), channels_to_encode_(config_.intial_channels_to_encode) {
29 0 : RTC_DCHECK_GT(config_.intial_channels_to_encode, 0lu);
30 : // Currently, we require |intial_channels_to_encode| to be <= 2.
31 0 : RTC_DCHECK_LE(config_.intial_channels_to_encode, 2lu);
32 0 : RTC_DCHECK_GE(config_.num_encoder_channels,
33 0 : config_.intial_channels_to_encode);
34 0 : }
35 :
36 0 : void ChannelController::MakeDecision(
37 : const NetworkMetrics& metrics,
38 : AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
39 : // Decision on |num_channels| should not have been made.
40 0 : RTC_DCHECK(!config->num_channels);
41 :
42 0 : if (metrics.uplink_bandwidth_bps) {
43 0 : if (channels_to_encode_ == 2 &&
44 0 : *metrics.uplink_bandwidth_bps <= config_.channel_2_to_1_bandwidth_bps) {
45 0 : channels_to_encode_ = 1;
46 0 : } else if (channels_to_encode_ == 1 &&
47 0 : *metrics.uplink_bandwidth_bps >=
48 0 : config_.channel_1_to_2_bandwidth_bps) {
49 0 : channels_to_encode_ =
50 0 : std::min(static_cast<size_t>(2), config_.num_encoder_channels);
51 : }
52 : }
53 0 : config->num_channels = rtc::Optional<size_t>(channels_to_encode_);
54 0 : }
55 :
56 : } // namespace webrtc
|