Index: webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.cc |
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.cc b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bec6047eb67a803791ddef2ee2f4809383d51637 |
--- /dev/null |
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.cc |
@@ -0,0 +1,54 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include <algorithm> |
+ |
+#include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h" |
+#include "webrtc/base/checks.h" |
+ |
+namespace webrtc { |
+ |
+ChannelController::Config::Config(size_t num_encoder_channels, |
+ size_t intial_channels_to_encode, |
+ int channel_1_to_2_bandwidth_bps, |
+ int channel_2_to_1_bandwidth_bps) |
+ : num_encoder_channels(num_encoder_channels), |
+ intial_channels_to_encode(intial_channels_to_encode), |
+ channel_1_to_2_bandwidth_bps(channel_1_to_2_bandwidth_bps), |
+ channel_2_to_1_bandwidth_bps(channel_2_to_1_bandwidth_bps) { |
+ RTC_DCHECK_GT(intial_channels_to_encode, 0lu); |
hlundin-webrtc
2016/09/08 07:47:44
I think these checks should go in the ChannelContr
minyue-webrtc
2016/09/08 08:37:00
True, good concern.
|
+ RTC_DCHECK_GE(num_encoder_channels, intial_channels_to_encode); |
+} |
+ |
+ChannelController::Config::~Config() = default; |
+ |
+ChannelController::ChannelController(const Config& config) |
+ : config_(config), channels_to_encode_(config.intial_channels_to_encode) {} |
hlundin-webrtc
2016/09/08 07:47:44
You will have to make sure that config.intial_chan
minyue-webrtc
2016/09/08 08:36:59
True, will add DCHECK.
|
+ |
+void ChannelController::MakeDecision( |
+ const NetworkMetrics& metrics, |
+ AudioNetworkAdaptor::EncoderRuntimeConfig* config) { |
+ // Decision on |num_channels| should not have been made. |
+ RTC_DCHECK(!config->num_channels); |
+ |
+ if (metrics.uplink_bandwidth_bps) { |
+ if (channels_to_encode_ == 2 && |
+ *metrics.uplink_bandwidth_bps <= config_.channel_2_to_1_bandwidth_bps) { |
+ channels_to_encode_ = 1; |
+ } else if (channels_to_encode_ == 1 && |
+ *metrics.uplink_bandwidth_bps >= |
+ config_.channel_1_to_2_bandwidth_bps) { |
+ channels_to_encode_ = std::min(2lu, config_.num_encoder_channels); |
+ } |
+ } |
+ config->num_channels = rtc::Optional<size_t>(channels_to_encode_); |
+} |
+ |
+} // namespace webrtc |