2014-11-10 13:55:16 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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 <vector>
|
|
|
|
|
|
2016-10-25 07:04:37 -07:00
|
|
|
#include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h"
|
2014-11-10 13:55:16 +00:00
|
|
|
#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2014-11-10 13:55:16 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-01-21 08:55:03 -08:00
|
|
|
void TestProbing(bool use_delay_based) {
|
2016-07-04 07:06:55 -07:00
|
|
|
MockRtcEventLog event_log;
|
|
|
|
|
SendSideBandwidthEstimation bwe(&event_log);
|
2014-11-10 13:55:16 +00:00
|
|
|
bwe.SetMinMaxBitrate(100000, 1500000);
|
|
|
|
|
bwe.SetSendBitrate(200000);
|
|
|
|
|
|
2015-03-26 11:11:06 +01:00
|
|
|
const int kRembBps = 1000000;
|
|
|
|
|
const int kSecondRembBps = kRembBps + 500000;
|
2014-11-10 13:55:16 +00:00
|
|
|
int64_t now_ms = 0;
|
|
|
|
|
|
|
|
|
|
bwe.UpdateReceiverBlock(0, 50, 1, now_ms);
|
|
|
|
|
|
|
|
|
|
// Initial REMB applies immediately.
|
2016-01-21 08:55:03 -08:00
|
|
|
if (use_delay_based) {
|
|
|
|
|
bwe.UpdateDelayBasedEstimate(now_ms, kRembBps);
|
|
|
|
|
} else {
|
|
|
|
|
bwe.UpdateReceiverEstimate(now_ms, kRembBps);
|
|
|
|
|
}
|
2014-11-10 13:55:16 +00:00
|
|
|
bwe.UpdateEstimate(now_ms);
|
2015-03-26 11:11:06 +01:00
|
|
|
int bitrate;
|
2014-11-10 13:55:16 +00:00
|
|
|
uint8_t fraction_loss;
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t rtt;
|
2014-11-10 13:55:16 +00:00
|
|
|
bwe.CurrentEstimate(&bitrate, &fraction_loss, &rtt);
|
2015-03-26 11:11:06 +01:00
|
|
|
EXPECT_EQ(kRembBps, bitrate);
|
2014-11-10 13:55:16 +00:00
|
|
|
|
|
|
|
|
// Second REMB doesn't apply immediately.
|
|
|
|
|
now_ms += 2001;
|
2016-01-21 08:55:03 -08:00
|
|
|
if (use_delay_based) {
|
|
|
|
|
bwe.UpdateDelayBasedEstimate(now_ms, kSecondRembBps);
|
|
|
|
|
} else {
|
|
|
|
|
bwe.UpdateReceiverEstimate(now_ms, kSecondRembBps);
|
|
|
|
|
}
|
2014-11-10 13:55:16 +00:00
|
|
|
bwe.UpdateEstimate(now_ms);
|
|
|
|
|
bitrate = 0;
|
|
|
|
|
bwe.CurrentEstimate(&bitrate, &fraction_loss, &rtt);
|
2015-03-26 11:11:06 +01:00
|
|
|
EXPECT_EQ(kRembBps, bitrate);
|
2014-11-10 13:55:16 +00:00
|
|
|
}
|
2015-10-22 08:52:20 -07:00
|
|
|
|
2016-01-21 08:55:03 -08:00
|
|
|
TEST(SendSideBweTest, InitialRembWithProbing) {
|
|
|
|
|
TestProbing(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SendSideBweTest, InitialDelayBasedBweWithProbing) {
|
|
|
|
|
TestProbing(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 08:52:20 -07:00
|
|
|
TEST(SendSideBweTest, DoesntReapplyBitrateDecreaseWithoutFollowingRemb) {
|
2016-07-04 07:06:55 -07:00
|
|
|
MockRtcEventLog event_log;
|
2017-04-18 06:55:32 -07:00
|
|
|
EXPECT_CALL(event_log, LogLossBasedBweUpdate(testing::Gt(0), 0, 0)).Times(1);
|
2016-07-04 07:06:55 -07:00
|
|
|
EXPECT_CALL(event_log,
|
2017-02-20 05:14:41 -08:00
|
|
|
LogLossBasedBweUpdate(testing::Gt(0), testing::Gt(0), 0))
|
2017-04-18 06:55:32 -07:00
|
|
|
.Times(2);
|
2016-07-04 07:06:55 -07:00
|
|
|
SendSideBandwidthEstimation bwe(&event_log);
|
2015-10-22 08:52:20 -07:00
|
|
|
static const int kMinBitrateBps = 100000;
|
|
|
|
|
static const int kInitialBitrateBps = 1000000;
|
|
|
|
|
bwe.SetMinMaxBitrate(kMinBitrateBps, 1500000);
|
|
|
|
|
bwe.SetSendBitrate(kInitialBitrateBps);
|
|
|
|
|
|
|
|
|
|
static const uint8_t kFractionLoss = 128;
|
|
|
|
|
static const int64_t kRttMs = 50;
|
|
|
|
|
|
|
|
|
|
int64_t now_ms = 0;
|
|
|
|
|
int bitrate_bps;
|
|
|
|
|
uint8_t fraction_loss;
|
|
|
|
|
int64_t rtt_ms;
|
|
|
|
|
bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms);
|
|
|
|
|
EXPECT_EQ(kInitialBitrateBps, bitrate_bps);
|
|
|
|
|
EXPECT_EQ(0, fraction_loss);
|
|
|
|
|
EXPECT_EQ(0, rtt_ms);
|
|
|
|
|
|
|
|
|
|
// Signal heavy loss to go down in bitrate.
|
|
|
|
|
bwe.UpdateReceiverBlock(kFractionLoss, kRttMs, 100, now_ms);
|
|
|
|
|
// Trigger an update 2 seconds later to not be rate limited.
|
2016-09-20 14:14:23 +02:00
|
|
|
now_ms += 1000;
|
2015-10-22 08:52:20 -07:00
|
|
|
bwe.UpdateEstimate(now_ms);
|
|
|
|
|
|
|
|
|
|
bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms);
|
|
|
|
|
EXPECT_LT(bitrate_bps, kInitialBitrateBps);
|
|
|
|
|
// Verify that the obtained bitrate isn't hitting the min bitrate, or this
|
|
|
|
|
// test doesn't make sense. If this ever happens, update the thresholds or
|
|
|
|
|
// loss rates so that it doesn't hit min bitrate after one bitrate update.
|
|
|
|
|
EXPECT_GT(bitrate_bps, kMinBitrateBps);
|
|
|
|
|
EXPECT_EQ(kFractionLoss, fraction_loss);
|
|
|
|
|
EXPECT_EQ(kRttMs, rtt_ms);
|
|
|
|
|
|
|
|
|
|
// Triggering an update shouldn't apply further downgrade nor upgrade since
|
|
|
|
|
// there's no intermediate receiver block received indicating whether this is
|
|
|
|
|
// currently good or not.
|
|
|
|
|
int last_bitrate_bps = bitrate_bps;
|
|
|
|
|
// Trigger an update 2 seconds later to not be rate limited (but it still
|
|
|
|
|
// shouldn't update).
|
2016-09-20 14:14:23 +02:00
|
|
|
now_ms += 1000;
|
2015-10-22 08:52:20 -07:00
|
|
|
bwe.UpdateEstimate(now_ms);
|
|
|
|
|
bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(last_bitrate_bps, bitrate_bps);
|
|
|
|
|
// The old loss rate should still be applied though.
|
|
|
|
|
EXPECT_EQ(kFractionLoss, fraction_loss);
|
|
|
|
|
EXPECT_EQ(kRttMs, rtt_ms);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 13:55:16 +00:00
|
|
|
} // namespace webrtc
|