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

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

Issue 2334613002: Adding BitrateController to audio network adaptor. (Closed)
Patch Set: separate ANA test files to a source_set to avoid name conflict 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/bitrate_controller_unittest.cc
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller_unittest.cc b/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a21ce2980c25707467730a6ca75e3e34bc6d882
--- /dev/null
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller_unittest.cc
@@ -0,0 +1,97 @@
+/*
+ * 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 "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h"
+
+namespace webrtc {
+
+namespace {
+
+// L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits
+constexpr int kPacketOverheadBits = 512;
+
+void CheckBitrateControllersDecision(BitrateController* controller,
+ const Controller::NetworkMetrics& metrics,
+ int frame_length_ms,
+ int expected_bitrate_bps) {
+ AudioNetworkAdaptor::EncoderRuntimeConfig config;
+ config.frame_length_ms = rtc::Optional<int>(frame_length_ms);
+ controller->MakeDecision(metrics, &config);
+ EXPECT_EQ(config.bitrate_bps, rtc::Optional<int>(expected_bitrate_bps));
hlundin-webrtc 2016/09/15 11:01:09 Swap parameters. Expected value should go before t
minyue-webrtc 2016/09/15 12:12:15 Ok. There can be a bit more polishing to be made i
+}
+
+} // namespace
+
+// These tests are named AnaBitrateControllerTest to distinguish from
+// BitrateControllerTest in
+// modules/bitrate_controller/bitrate_controller_unittest.cc.
+
+TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) {
+ constexpr int kInitialBitrateBps = 32000;
+ constexpr int kInitialFrameLengthMs = 20;
+ BitrateController controller(
+ BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs));
+ Controller::NetworkMetrics metrics;
+ CheckBitrateControllersDecision(
+ &controller, metrics, kInitialFrameLengthMs * 2, kInitialBitrateBps);
+}
+
+TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) {
+ constexpr int kInitialBitrateBps = 32000;
+ constexpr int kInitialFrameLengthMs = 20;
+ BitrateController controller(
+ BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs));
+
+ Controller::NetworkMetrics metrics;
+ constexpr int kTargetBitrateBps = 48000;
+ metrics.target_audio_bitrate_bps = rtc::Optional<int>(kTargetBitrateBps);
+
+ // Frame length unchanged, bitrate changes in accordance with
+ // |metrics.target_audio_bitrate_bps|
+ CheckBitrateControllersDecision(&controller, metrics, kInitialFrameLengthMs,
+ kTargetBitrateBps);
+}
+
+TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) {
+ constexpr int kInitialBitrateBps = 32000;
+ constexpr int kInitialFrameLengthMs = 20;
+ BitrateController controller(
+ BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs));
+
+ Controller::NetworkMetrics metrics;
+ metrics.target_audio_bitrate_bps = rtc::Optional<int>(kInitialBitrateBps);
+
+ constexpr int kFrameLengthMs = 60;
+ constexpr int kPacketOverheadRateDiff =
+ kPacketOverheadBits * 1000 / kInitialFrameLengthMs -
+ kPacketOverheadBits * 1000 / kFrameLengthMs;
+ CheckBitrateControllersDecision(&controller, metrics, kFrameLengthMs,
+ kInitialBitrateBps + kPacketOverheadRateDiff);
+}
+
+TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) {
+ constexpr int kInitialBitrateBps = 32000;
+ constexpr int kInitialFrameLengthMs = 60;
+ BitrateController controller(
+ BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs));
+
+ Controller::NetworkMetrics metrics;
+ metrics.target_audio_bitrate_bps = rtc::Optional<int>(kInitialBitrateBps);
+
+ constexpr int kFrameLengthMs = 20;
+ constexpr int kPacketOverheadRateDiff =
+ kPacketOverheadBits * 1000 / kInitialFrameLengthMs -
+ kPacketOverheadBits * 1000 / kFrameLengthMs;
+ CheckBitrateControllersDecision(&controller, metrics, kFrameLengthMs,
+ kInitialBitrateBps + kPacketOverheadRateDiff);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698