| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <limits> | 11 #include <limits> |
| 12 | 12 |
| 13 #include "webrtc/modules/pacing/bitrate_prober.h" | 13 #include "webrtc/modules/pacing/bitrate_prober.h" |
| 14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
| 15 | 15 |
| 16 namespace webrtc { | 16 namespace webrtc { |
| 17 | 17 |
| 18 TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) { | 18 TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) { |
| 19 BitrateProber prober; | 19 BitrateProber prober; |
| 20 EXPECT_FALSE(prober.IsProbing()); | 20 EXPECT_FALSE(prober.IsProbing()); |
| 21 int64_t now_ms = 0; | 21 int64_t now_ms = 0; |
| 22 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); | 22 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); |
| 23 | 23 |
| 24 const int kTestBitrate1 = 900000; | 24 const int kTestBitrate1 = 900000; |
| 25 const int kTestBitrate2 = 1800000; | 25 const int kTestBitrate2 = 1800000; |
| 26 const int kClusterSize = 5; | 26 const int kClusterSize = 5; |
| 27 const int kProbeSize = 1000; | 27 const int kProbeSize = 1000; |
| 28 const int kMinProbeDurationMs = 15; | 28 const int kMinProbeDurationMs = 15; |
| 29 | 29 |
| 30 prober.CreateProbeCluster(kTestBitrate1); | 30 prober.CreateProbeCluster(kTestBitrate1, now_ms); |
| 31 prober.CreateProbeCluster(kTestBitrate2); | 31 prober.CreateProbeCluster(kTestBitrate2, now_ms); |
| 32 EXPECT_FALSE(prober.IsProbing()); | 32 EXPECT_FALSE(prober.IsProbing()); |
| 33 | 33 |
| 34 prober.OnIncomingPacket(kProbeSize); | 34 prober.OnIncomingPacket(kProbeSize); |
| 35 EXPECT_TRUE(prober.IsProbing()); | 35 EXPECT_TRUE(prober.IsProbing()); |
| 36 EXPECT_EQ(0, prober.CurrentClusterId()); | 36 EXPECT_EQ(0, prober.CurrentClusterId()); |
| 37 | 37 |
| 38 // First packet should probe as soon as possible. | 38 // First packet should probe as soon as possible. |
| 39 EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms)); | 39 EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms)); |
| 40 | 40 |
| 41 for (int i = 0; i < kClusterSize; ++i) { | 41 for (int i = 0; i < kClusterSize; ++i) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 71 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); | 71 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); |
| 72 EXPECT_FALSE(prober.IsProbing()); | 72 EXPECT_FALSE(prober.IsProbing()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) { | 75 TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) { |
| 76 BitrateProber prober; | 76 BitrateProber prober; |
| 77 EXPECT_FALSE(prober.IsProbing()); | 77 EXPECT_FALSE(prober.IsProbing()); |
| 78 int64_t now_ms = 0; | 78 int64_t now_ms = 0; |
| 79 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); | 79 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); |
| 80 | 80 |
| 81 prober.CreateProbeCluster(900000); | 81 prober.CreateProbeCluster(900000, now_ms); |
| 82 EXPECT_FALSE(prober.IsProbing()); | 82 EXPECT_FALSE(prober.IsProbing()); |
| 83 | 83 |
| 84 prober.OnIncomingPacket(1000); | 84 prober.OnIncomingPacket(1000); |
| 85 EXPECT_TRUE(prober.IsProbing()); | 85 EXPECT_TRUE(prober.IsProbing()); |
| 86 EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms)); | 86 EXPECT_EQ(0, prober.TimeUntilNextProbe(now_ms)); |
| 87 prober.ProbeSent(now_ms, 1000); | 87 prober.ProbeSent(now_ms, 1000); |
| 88 // Let time pass, no large enough packets put into prober. | 88 // Let time pass, no large enough packets put into prober. |
| 89 now_ms += 6000; | 89 now_ms += 6000; |
| 90 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); | 90 EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms)); |
| 91 // Insert a large-enough packet after downtime while probing should reset to | 91 // Insert a large-enough packet after downtime while probing should reset to |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 EXPECT_FALSE(prober.IsProbing()); | 104 EXPECT_FALSE(prober.IsProbing()); |
| 105 | 105 |
| 106 prober.OnIncomingPacket(100); | 106 prober.OnIncomingPacket(100); |
| 107 EXPECT_FALSE(prober.IsProbing()); | 107 EXPECT_FALSE(prober.IsProbing()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(BitrateProberTest, VerifyProbeSizeOnHighBitrate) { | 110 TEST(BitrateProberTest, VerifyProbeSizeOnHighBitrate) { |
| 111 BitrateProber prober; | 111 BitrateProber prober; |
| 112 constexpr unsigned kHighBitrateBps = 10000000; // 10 Mbps | 112 constexpr unsigned kHighBitrateBps = 10000000; // 10 Mbps |
| 113 | 113 |
| 114 prober.CreateProbeCluster(kHighBitrateBps); | 114 prober.CreateProbeCluster(kHighBitrateBps, 0); |
| 115 // Probe size should ensure a minimum of 1 ms interval. | 115 // Probe size should ensure a minimum of 1 ms interval. |
| 116 EXPECT_GT(prober.RecommendedMinProbeSize(), kHighBitrateBps / 8000); | 116 EXPECT_GT(prober.RecommendedMinProbeSize(), kHighBitrateBps / 8000); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST(BitrateProberTest, MinumumNumberOfProbingPackets) { | 119 TEST(BitrateProberTest, MinumumNumberOfProbingPackets) { |
| 120 BitrateProber prober; | 120 BitrateProber prober; |
| 121 // Even when probing at a low bitrate we expect a minimum number | 121 // Even when probing at a low bitrate we expect a minimum number |
| 122 // of packets to be sent. | 122 // of packets to be sent. |
| 123 constexpr int kBitrateBps = 100000; // 100 kbps | 123 constexpr int kBitrateBps = 100000; // 100 kbps |
| 124 constexpr int kPacketSizeBytes = 1000; | 124 constexpr int kPacketSizeBytes = 1000; |
| 125 | 125 |
| 126 prober.CreateProbeCluster(kBitrateBps); | 126 prober.CreateProbeCluster(kBitrateBps, 0); |
| 127 prober.OnIncomingPacket(kPacketSizeBytes); | 127 prober.OnIncomingPacket(kPacketSizeBytes); |
| 128 for (int i = 0; i < 5; ++i) { | 128 for (int i = 0; i < 5; ++i) { |
| 129 EXPECT_TRUE(prober.IsProbing()); | 129 EXPECT_TRUE(prober.IsProbing()); |
| 130 prober.ProbeSent(0, kPacketSizeBytes); | 130 prober.ProbeSent(0, kPacketSizeBytes); |
| 131 } | 131 } |
| 132 | 132 |
| 133 EXPECT_FALSE(prober.IsProbing()); | 133 EXPECT_FALSE(prober.IsProbing()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST(BitrateProberTest, ScaleBytesUsedForProbing) { | 136 TEST(BitrateProberTest, ScaleBytesUsedForProbing) { |
| 137 BitrateProber prober; | 137 BitrateProber prober; |
| 138 constexpr int kBitrateBps = 10000000; // 10 Mbps | 138 constexpr int kBitrateBps = 10000000; // 10 Mbps |
| 139 constexpr int kPacketSizeBytes = 1000; | 139 constexpr int kPacketSizeBytes = 1000; |
| 140 constexpr int kExpectedBytesSent = kBitrateBps * 15 / 8000; | 140 constexpr int kExpectedBytesSent = kBitrateBps * 15 / 8000; |
| 141 | 141 |
| 142 prober.CreateProbeCluster(kBitrateBps); | 142 prober.CreateProbeCluster(kBitrateBps, 0); |
| 143 prober.OnIncomingPacket(kPacketSizeBytes); | 143 prober.OnIncomingPacket(kPacketSizeBytes); |
| 144 int bytes_sent = 0; | 144 int bytes_sent = 0; |
| 145 while (bytes_sent < kExpectedBytesSent) { | 145 while (bytes_sent < kExpectedBytesSent) { |
| 146 ASSERT_TRUE(prober.IsProbing()); | 146 ASSERT_TRUE(prober.IsProbing()); |
| 147 prober.ProbeSent(0, kPacketSizeBytes); | 147 prober.ProbeSent(0, kPacketSizeBytes); |
| 148 bytes_sent += kPacketSizeBytes; | 148 bytes_sent += kPacketSizeBytes; |
| 149 } | 149 } |
| 150 | 150 |
| 151 EXPECT_FALSE(prober.IsProbing()); | 151 EXPECT_FALSE(prober.IsProbing()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST(BitrateProberTest, ProbeClusterTimeout) { |
| 155 BitrateProber prober; |
| 156 constexpr int kBitrateBps = 300000; // 300 kbps |
| 157 constexpr int kSmallPacketSize = 20; |
| 158 // Expecting two probe clusters of 5 packets each. |
| 159 constexpr int kExpectedBytesSent = 20 * 2 * 5; |
| 160 constexpr int64_t kTimeoutMs = 5000; |
| 161 |
| 162 int64_t now_ms = 0; |
| 163 prober.CreateProbeCluster(kBitrateBps, now_ms); |
| 164 prober.OnIncomingPacket(kSmallPacketSize); |
| 165 EXPECT_FALSE(prober.IsProbing()); |
| 166 now_ms += kTimeoutMs; |
| 167 prober.CreateProbeCluster(kBitrateBps / 10, now_ms); |
| 168 prober.OnIncomingPacket(kSmallPacketSize); |
| 169 EXPECT_FALSE(prober.IsProbing()); |
| 170 now_ms += 1; |
| 171 prober.CreateProbeCluster(kBitrateBps / 10, now_ms); |
| 172 prober.OnIncomingPacket(kSmallPacketSize); |
| 173 EXPECT_TRUE(prober.IsProbing()); |
| 174 int bytes_sent = 0; |
| 175 while (bytes_sent < kExpectedBytesSent) { |
| 176 ASSERT_TRUE(prober.IsProbing()); |
| 177 prober.ProbeSent(0, kSmallPacketSize); |
| 178 bytes_sent += kSmallPacketSize; |
| 179 } |
| 180 |
| 181 EXPECT_FALSE(prober.IsProbing()); |
| 182 } |
| 154 } // namespace webrtc | 183 } // namespace webrtc |
| OLD | NEW |