Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc

Issue 2319873002: Adding ChannelController to audio network adaptor. (Closed)
Patch Set: further simplying test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9fbc86fc35f006465e3a29ef7aace4d543233501
--- /dev/null
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc
@@ -0,0 +1,91 @@
+/*
+ * 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 <memory>
+
+#include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace webrtc {
+
+namespace {
+
+constexpr int kChannel1To2BandwidthBps = 31000;
+constexpr int kChannel2To1BandwidthBps = 29000;
+
+void CheckChannelControllersDecision(ChannelController* controller,
+ const Controller::NetworkMetrics& metrics,
+ size_t expected_num_channels) {
+ AudioNetworkAdaptor::EncoderRuntimeConfig config;
+ controller->MakeDecision(metrics, &config);
+ EXPECT_EQ(rtc::Optional<size_t>(expected_num_channels), config.num_channels);
+}
+
+} // namespace
+
+TEST(ChannelControllerTest, OutputInitValueWhenUplinkBandwidthUnknown) {
+ constexpr int kNumChannels = 2;
+ constexpr int kInitChannels = 1;
+ ChannelController controller(ChannelController::Config(
+ kInitChannels, kNumChannels, kChannel1To2BandwidthBps,
+ kChannel2To1BandwidthBps));
+ Controller::NetworkMetrics metrics;
+ CheckChannelControllersDecision(&controller, metrics, kInitChannels);
+}
+
+TEST(ChannelControllerTest, SwitchTo2ChannelsOnHighUplinkBandwidth) {
+ // Set initial number of encoded channels to 1.
+ ChannelController controller(ChannelController::Config(
+ 2, 1, kChannel1To2BandwidthBps, kChannel2To1BandwidthBps));
+ Controller::NetworkMetrics metrics;
+
+ // Use high bandwidth to check output switch to 2.
+ metrics.uplink_bandwidth_bps = rtc::Optional<int>(kChannel1To2BandwidthBps);
+ CheckChannelControllersDecision(&controller, metrics, 2);
+}
+
+TEST(ChannelControllerTest, SwitchTo1ChannelOnLowUplinkBandwidth) {
+ // Set initial number of encoded channels to 2.
+ ChannelController controller(ChannelController::Config(
+ 2, 2, kChannel1To2BandwidthBps, kChannel2To1BandwidthBps));
+ Controller::NetworkMetrics metrics;
+
+ // Use low bandwidth to check output switch to 1.
+ metrics.uplink_bandwidth_bps = rtc::Optional<int>(kChannel2To1BandwidthBps);
+ CheckChannelControllersDecision(&controller, metrics, 1);
+}
+
+TEST(ChannelControllerTest, Maintain1ChannelOnMediumUplinkBandwidth) {
+ // Set initial number of encoded channels to 1.
+ ChannelController controller(ChannelController::Config(
+ 2, 1, kChannel1To2BandwidthBps, kChannel2To1BandwidthBps));
+ Controller::NetworkMetrics metrics;
+
+ constexpr int kBandwidth =
+ (kChannel1To2BandwidthBps + kChannel2To1BandwidthBps) / 2;
+ // Use between-thresholds bandwidth to check output remains at 1.
+ metrics.uplink_bandwidth_bps = rtc::Optional<int>(kBandwidth);
+ CheckChannelControllersDecision(&controller, metrics, 1);
+}
+
+TEST(ChannelControllerTest, Maintain2ChannelsOnMediumUplinkBandwidth) {
+ // Set initial number of encoded channels to 2.
+ ChannelController controller(ChannelController::Config(
+ 2, 2, kChannel1To2BandwidthBps, kChannel2To1BandwidthBps));
+ Controller::NetworkMetrics metrics;
+
+ constexpr int kBandwidth =
+ (kChannel1To2BandwidthBps + kChannel2To1BandwidthBps) / 2;
+ // Use between-thresholds bandwidth to check output remains at 2.
+ metrics.uplink_bandwidth_bps = rtc::Optional<int>(kBandwidth);
+ CheckChannelControllersDecision(&controller, metrics, 2);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698