1/* 2 * Copyright (c) 2014 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#include <vector> 13 14#include "testing/gtest/include/gtest/gtest.h" 15#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h" 16 17namespace webrtc { 18 19TEST(SendSideBweTest, InitialRembWithProbing) { 20 SendSideBandwidthEstimation bwe; 21 bwe.SetMinMaxBitrate(100000, 1500000); 22 bwe.SetSendBitrate(200000); 23 24 const int kRembBps = 1000000; 25 const int kSecondRembBps = kRembBps + 500000; 26 int64_t now_ms = 0; 27 28 bwe.UpdateReceiverBlock(0, 50, 1, now_ms); 29 30 // Initial REMB applies immediately. 31 bwe.UpdateReceiverEstimate(now_ms, kRembBps); 32 bwe.UpdateEstimate(now_ms); 33 int bitrate; 34 uint8_t fraction_loss; 35 int64_t rtt; 36 bwe.CurrentEstimate(&bitrate, &fraction_loss, &rtt); 37 EXPECT_EQ(kRembBps, bitrate); 38 39 // Second REMB doesn't apply immediately. 40 now_ms += 2001; 41 bwe.UpdateReceiverEstimate(now_ms, kSecondRembBps); 42 bwe.UpdateEstimate(now_ms); 43 bitrate = 0; 44 bwe.CurrentEstimate(&bitrate, &fraction_loss, &rtt); 45 EXPECT_EQ(kRembBps, bitrate); 46} 47 48TEST(SendSideBweTest, DoesntReapplyBitrateDecreaseWithoutFollowingRemb) { 49 SendSideBandwidthEstimation bwe; 50 static const int kMinBitrateBps = 100000; 51 static const int kInitialBitrateBps = 1000000; 52 bwe.SetMinMaxBitrate(kMinBitrateBps, 1500000); 53 bwe.SetSendBitrate(kInitialBitrateBps); 54 55 static const uint8_t kFractionLoss = 128; 56 static const int64_t kRttMs = 50; 57 58 int64_t now_ms = 0; 59 int bitrate_bps; 60 uint8_t fraction_loss; 61 int64_t rtt_ms; 62 bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); 63 EXPECT_EQ(kInitialBitrateBps, bitrate_bps); 64 EXPECT_EQ(0, fraction_loss); 65 EXPECT_EQ(0, rtt_ms); 66 67 // Signal heavy loss to go down in bitrate. 68 bwe.UpdateReceiverBlock(kFractionLoss, kRttMs, 100, now_ms); 69 // Trigger an update 2 seconds later to not be rate limited. 70 now_ms += 2000; 71 bwe.UpdateEstimate(now_ms); 72 73 bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); 74 EXPECT_LT(bitrate_bps, kInitialBitrateBps); 75 // Verify that the obtained bitrate isn't hitting the min bitrate, or this 76 // test doesn't make sense. If this ever happens, update the thresholds or 77 // loss rates so that it doesn't hit min bitrate after one bitrate update. 78 EXPECT_GT(bitrate_bps, kMinBitrateBps); 79 EXPECT_EQ(kFractionLoss, fraction_loss); 80 EXPECT_EQ(kRttMs, rtt_ms); 81 82 // Triggering an update shouldn't apply further downgrade nor upgrade since 83 // there's no intermediate receiver block received indicating whether this is 84 // currently good or not. 85 int last_bitrate_bps = bitrate_bps; 86 // Trigger an update 2 seconds later to not be rate limited (but it still 87 // shouldn't update). 88 now_ms += 2000; 89 bwe.UpdateEstimate(now_ms); 90 bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); 91 92 EXPECT_EQ(last_bitrate_bps, bitrate_bps); 93 // The old loss rate should still be applied though. 94 EXPECT_EQ(kFractionLoss, fraction_loss); 95 EXPECT_EQ(kRttMs, rtt_ms); 96} 97 98} // namespace webrtc 99