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