2014-10-23 11:57:05 +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 <limits>
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/pacing/bitrate_prober.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2014-10-23 11:57:05 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) {
|
|
|
|
|
BitrateProber prober;
|
|
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
int64_t now_ms = 0;
|
2015-02-16 15:47:51 +00:00
|
|
|
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
|
2014-10-23 11:57:05 +00:00
|
|
|
|
2016-08-17 11:11:59 +02:00
|
|
|
prober.CreateProbeCluster(900000, 6);
|
|
|
|
|
prober.CreateProbeCluster(1800000, 5);
|
2014-10-23 11:57:05 +00:00
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(1000);
|
2014-10-23 11:57:05 +00:00
|
|
|
EXPECT_TRUE(prober.IsProbing());
|
2016-05-06 17:06:14 +02:00
|
|
|
EXPECT_EQ(0, prober.CurrentClusterId());
|
2014-10-23 11:57:05 +00:00
|
|
|
|
2016-02-16 16:23:08 +01:00
|
|
|
// First packet should probe as soon as possible.
|
2014-10-23 11:57:05 +00:00
|
|
|
EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms));
|
2016-10-04 08:29:38 -07:00
|
|
|
prober.ProbeSent(now_ms, 1000);
|
2014-10-23 11:57:05 +00:00
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
2014-11-04 19:33:55 +00:00
|
|
|
EXPECT_EQ(8, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
now_ms += 4;
|
|
|
|
|
EXPECT_EQ(4, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
now_ms += 4;
|
2014-10-23 11:57:05 +00:00
|
|
|
EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms));
|
2016-05-06 17:06:14 +02:00
|
|
|
EXPECT_EQ(0, prober.CurrentClusterId());
|
2016-10-04 08:29:38 -07:00
|
|
|
prober.ProbeSent(now_ms, 1000);
|
2014-10-23 11:57:05 +00:00
|
|
|
}
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
EXPECT_EQ(4, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
now_ms += 4;
|
|
|
|
|
EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms));
|
2016-05-06 17:06:14 +02:00
|
|
|
EXPECT_EQ(1, prober.CurrentClusterId());
|
2016-10-04 08:29:38 -07:00
|
|
|
prober.ProbeSent(now_ms, 1000);
|
2014-10-23 11:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-16 15:47:51 +00:00
|
|
|
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
|
2014-10-23 11:57:05 +00:00
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
}
|
2016-02-16 16:23:08 +01:00
|
|
|
|
|
|
|
|
TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) {
|
|
|
|
|
BitrateProber prober;
|
|
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
int64_t now_ms = 0;
|
|
|
|
|
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
|
2016-08-17 11:11:59 +02:00
|
|
|
prober.CreateProbeCluster(900000, 6);
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(1000);
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_TRUE(prober.IsProbing());
|
|
|
|
|
EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms));
|
2016-10-04 08:29:38 -07:00
|
|
|
prober.ProbeSent(now_ms, 1000);
|
2016-02-16 16:23:08 +01:00
|
|
|
// Let time pass, no large enough packets put into prober.
|
|
|
|
|
now_ms += 6000;
|
|
|
|
|
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
// Insert a small packet, not a candidate for probing.
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(100);
|
2016-10-04 08:29:38 -07:00
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
|
|
|
|
|
// Insert a large-enough packet after downtime while probing should reset to
|
|
|
|
|
// perform a new probe since the requested one didn't finish.
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(1000);
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms));
|
2016-10-04 08:29:38 -07:00
|
|
|
prober.ProbeSent(now_ms, 1000);
|
2016-02-16 16:23:08 +01:00
|
|
|
// Next packet should be part of new probe and be sent with non-zero delay.
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(1000);
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_GT(prober.TimeUntilNextProbe(now_ms), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BitrateProberTest, DoesntInitializeProbingForSmallPackets) {
|
|
|
|
|
BitrateProber prober;
|
|
|
|
|
prober.SetEnabled(true);
|
|
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
|
2016-08-15 11:51:06 -07:00
|
|
|
prober.OnIncomingPacket(100);
|
2016-02-16 16:23:08 +01:00
|
|
|
EXPECT_FALSE(prober.IsProbing());
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 08:29:38 -07:00
|
|
|
TEST(BitrateProberTest, VerifyProbeSizeOnHighBitrate) {
|
|
|
|
|
BitrateProber prober;
|
|
|
|
|
constexpr unsigned kHighBitrateBps = 10000000; // 10 Mbps
|
|
|
|
|
|
|
|
|
|
prober.CreateProbeCluster(kHighBitrateBps, 6);
|
|
|
|
|
// Probe size should ensure a minimum of 1 ms interval.
|
|
|
|
|
EXPECT_GT(prober.RecommendedMinProbeSize(), kHighBitrateBps / 8000);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
} // namespace webrtc
|