From 4bdd873f6e154619bea5e84f73b33efcc9a21938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Thu, 26 Mar 2020 10:37:09 +0100 Subject: [PATCH] Make BitrateProber::IsProbing() inline. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trivial perf optimization. Bug: None Change-Id: I0ceabc2a6aa0c52f4626c8792c17a60d2028712d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171694 Reviewed-by: Stefan Holmer Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/master@{#30901} --- modules/pacing/bitrate_prober.cc | 4 --- modules/pacing/bitrate_prober.h | 2 +- modules/pacing/bitrate_prober_unittest.cc | 38 +++++++++++------------ modules/pacing/pacing_controller.cc | 4 +-- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/modules/pacing/bitrate_prober.cc b/modules/pacing/bitrate_prober.cc index e4ac7ddf80..e7ce01d95c 100644 --- a/modules/pacing/bitrate_prober.cc +++ b/modules/pacing/bitrate_prober.cc @@ -74,10 +74,6 @@ void BitrateProber::SetEnabled(bool enable) { } } -bool BitrateProber::IsProbing() const { - return probing_state_ == ProbingState::kActive; -} - void BitrateProber::OnIncomingPacket(size_t packet_size) { // Don't initialize probing unless we have something large enough to start // probing. diff --git a/modules/pacing/bitrate_prober.h b/modules/pacing/bitrate_prober.h index ec234e8f5f..3ebe26ac1f 100644 --- a/modules/pacing/bitrate_prober.h +++ b/modules/pacing/bitrate_prober.h @@ -52,7 +52,7 @@ class BitrateProber { // Returns true if the prober is in a probing session, i.e., it currently // wants packets to be sent out according to the time returned by // TimeUntilNextProbe(). - bool IsProbing() const; + bool is_probing() const { return probing_state_ == ProbingState::kActive; } // Initializes a new probing session if the prober is allowed to probe. Does // not initialize the prober unless the packet size is large enough to probe diff --git a/modules/pacing/bitrate_prober_unittest.cc b/modules/pacing/bitrate_prober_unittest.cc index 2d10c0447e..62277a0d2f 100644 --- a/modules/pacing/bitrate_prober_unittest.cc +++ b/modules/pacing/bitrate_prober_unittest.cc @@ -19,7 +19,7 @@ namespace webrtc { TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) { const FieldTrialBasedConfig config; BitrateProber prober(config); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); Timestamp now = Timestamp::Millis(0); const Timestamp start_time = now; @@ -33,10 +33,10 @@ TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) { prober.CreateProbeCluster(kTestBitrate1, now, 0); prober.CreateProbeCluster(kTestBitrate2, now, 1); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); prober.OnIncomingPacket(kProbeSize); - EXPECT_TRUE(prober.IsProbing()); + EXPECT_TRUE(prober.is_probing()); EXPECT_EQ(0, prober.CurrentCluster().probe_cluster_id); // First packet should probe as soon as possible. @@ -74,7 +74,7 @@ TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) { EXPECT_LT(bitrate, kTestBitrate2 * 1.1); EXPECT_EQ(prober.NextProbeTime(now), Timestamp::PlusInfinity()); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) { @@ -85,10 +85,10 @@ TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) { EXPECT_EQ(prober.NextProbeTime(now), Timestamp::PlusInfinity()); prober.CreateProbeCluster(DataRate::KilobitsPerSec(900), now, 0); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); prober.OnIncomingPacket(1000); - EXPECT_TRUE(prober.IsProbing()); + EXPECT_TRUE(prober.is_probing()); EXPECT_EQ(now, std::max(now, prober.NextProbeTime(now))); prober.ProbeSent(now, 1000); // Let time pass, no large enough packets put into prober. @@ -105,10 +105,10 @@ TEST(BitrateProberTest, DoesntInitializeProbingForSmallPackets) { BitrateProber prober(config); prober.SetEnabled(true); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); prober.OnIncomingPacket(100); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } TEST(BitrateProberTest, VerifyProbeSizeOnHighBitrate) { @@ -136,11 +136,11 @@ TEST(BitrateProberTest, MinumumNumberOfProbingPackets) { prober.CreateProbeCluster(kBitrate, now, 0); prober.OnIncomingPacket(kPacketSizeBytes); for (int i = 0; i < 5; ++i) { - EXPECT_TRUE(prober.IsProbing()); + EXPECT_TRUE(prober.is_probing()); prober.ProbeSent(now, kPacketSizeBytes); } - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } TEST(BitrateProberTest, ScaleBytesUsedForProbing) { @@ -155,12 +155,12 @@ TEST(BitrateProberTest, ScaleBytesUsedForProbing) { prober.OnIncomingPacket(kPacketSizeBytes); int bytes_sent = 0; while (bytes_sent < kExpectedBytesSent) { - ASSERT_TRUE(prober.IsProbing()); + ASSERT_TRUE(prober.is_probing()); prober.ProbeSent(now, kPacketSizeBytes); bytes_sent += kPacketSizeBytes; } - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } TEST(BitrateProberTest, HighBitrateProbing) { @@ -175,12 +175,12 @@ TEST(BitrateProberTest, HighBitrateProbing) { prober.OnIncomingPacket(kPacketSizeBytes); int bytes_sent = 0; while (bytes_sent < kExpectedBytesSent) { - ASSERT_TRUE(prober.IsProbing()); + ASSERT_TRUE(prober.is_probing()); prober.ProbeSent(now, kPacketSizeBytes); bytes_sent += kPacketSizeBytes; } - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } TEST(BitrateProberTest, ProbeClusterTimeout) { @@ -195,22 +195,22 @@ TEST(BitrateProberTest, ProbeClusterTimeout) { Timestamp now = Timestamp::Millis(0); prober.CreateProbeCluster(kBitrate, now, /*cluster_id=*/0); prober.OnIncomingPacket(kSmallPacketSize); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); now += kTimeout; prober.CreateProbeCluster(kBitrate / 10, now, /*cluster_id=*/1); prober.OnIncomingPacket(kSmallPacketSize); - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); now += TimeDelta::Millis(1); prober.CreateProbeCluster(kBitrate / 10, now, /*cluster_id=*/2); prober.OnIncomingPacket(kSmallPacketSize); - EXPECT_TRUE(prober.IsProbing()); + EXPECT_TRUE(prober.is_probing()); int bytes_sent = 0; while (bytes_sent < kExpectedBytesSent) { - ASSERT_TRUE(prober.IsProbing()); + ASSERT_TRUE(prober.is_probing()); prober.ProbeSent(now, kSmallPacketSize); bytes_sent += kSmallPacketSize; } - EXPECT_FALSE(prober.IsProbing()); + EXPECT_FALSE(prober.is_probing()); } } // namespace webrtc diff --git a/modules/pacing/pacing_controller.cc b/modules/pacing/pacing_controller.cc index 8d41963a7e..70f39f591c 100644 --- a/modules/pacing/pacing_controller.cc +++ b/modules/pacing/pacing_controller.cc @@ -327,7 +327,7 @@ Timestamp PacingController::NextSendTime() const { } // If probing is active, that always takes priority. - if (prober_.IsProbing()) { + if (prober_.is_probing()) { Timestamp probe_time = prober_.NextProbeTime(now); // |probe_time| == PlusInfinity indicates no probe scheduled. if (probe_time != Timestamp::PlusInfinity() && !probing_send_failure_) { @@ -462,7 +462,7 @@ void PacingController::ProcessPackets() { } bool first_packet_in_probe = false; - bool is_probing = prober_.IsProbing(); + bool is_probing = prober_.is_probing(); PacedPacketInfo pacing_info; absl::optional recommended_probe_size; if (is_probing) {