Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: webrtc/modules/congestion_controller/delay_based_bwe_unittest.cc

Issue 2038023002: Use |probe_cluster_id| to cluster packets. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: BUILD file fix. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 "webrtc/modules/congestion_controller/delay_based_bwe.h"
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/pacing/paced_sender.h"
15 #include "webrtc/system_wrappers/include/clock.h"
16
17 namespace webrtc {
18
19 class TestDelayBasedBwe : public ::testing::Test, public RemoteBitrateObserver {
20 public:
21 static constexpr int kArrivalTimeClockOffsetMs = 60000;
22 static constexpr int kNumProbes = 5;
23
24 TestDelayBasedBwe()
25 : bwe_(this), clock_(0), bitrate_updated_(false), latest_bitrate_(0) {}
26
27 uint32_t AbsSendTime(int64_t t, int64_t denom) {
28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful;
29 }
30
31 void IncomingPacket(uint32_t ssrc,
32 size_t payload_size,
33 int64_t arrival_time,
34 uint32_t rtp_timestamp,
35 uint32_t absolute_send_time,
36 bool was_paced,
37 int probe_cluster_id) {
38 RTPHeader header;
39 memset(&header, 0, sizeof(header));
40 header.ssrc = ssrc;
41 header.timestamp = rtp_timestamp;
42 header.extension.hasAbsoluteSendTime = true;
43 header.extension.absoluteSendTime = absolute_send_time;
44 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size,
45 header, was_paced, probe_cluster_id);
46 }
47
48 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
49 uint32_t bitrate) {
50 bitrate_updated_ = true;
51 latest_bitrate_ = bitrate;
52 }
53
54 bool bitrate_updated() {
55 bool res = bitrate_updated_;
56 bitrate_updated_ = false;
57 return res;
58 }
59
60 int latest_bitrate() { return latest_bitrate_; }
61
62 DelayBasedBwe bwe_;
63 SimulatedClock clock_;
64
65 private:
66 bool bitrate_updated_;
67 int latest_bitrate_;
68 };
69
70 TEST_F(TestDelayBasedBwe, ProbeDetection) {
71 int64_t now_ms = clock_.TimeInMilliseconds();
72
73 // First burst sent at 8 * 1000 / 10 = 800 kbps.
74 for (int i = 0; i < kNumProbes; ++i) {
75 clock_.AdvanceTimeMilliseconds(10);
76 now_ms = clock_.TimeInMilliseconds();
77 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
78 true, 0);
79 }
80 EXPECT_TRUE(bitrate_updated());
81
82 // Second burst sent at 8 * 1000 / 5 = 1600 kbps.
83 for (int i = 0; i < kNumProbes; ++i) {
84 clock_.AdvanceTimeMilliseconds(5);
85 now_ms = clock_.TimeInMilliseconds();
86 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
87 true, 1);
88 }
89
90 EXPECT_TRUE(bitrate_updated());
91 EXPECT_GT(latest_bitrate(), 1500000);
92 }
93
94 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) {
95 int64_t now_ms = clock_.TimeInMilliseconds();
96 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet
97 // not being paced which could mess things up.
98 for (int i = 0; i < kNumProbes; ++i) {
99 clock_.AdvanceTimeMilliseconds(5);
100 now_ms = clock_.TimeInMilliseconds();
101 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
102 true, 0);
103 // Non-paced packet, arriving 5 ms after.
104 clock_.AdvanceTimeMilliseconds(5);
105 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms,
106 AbsSendTime(now_ms, 1000), false, PacketInfo::kNotAProbe);
107 }
108
109 EXPECT_TRUE(bitrate_updated());
110 EXPECT_GT(latest_bitrate(), 800000);
111 }
112
113 // Packets will require 5 ms to be transmitted to the receiver, causing packets
114 // of the second probe to be dispersed.
115 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) {
116 int64_t now_ms = clock_.TimeInMilliseconds();
117 int64_t send_time_ms = 0;
118 // First burst sent at 8 * 1000 / 10 = 800 kbps.
119 for (int i = 0; i < kNumProbes; ++i) {
120 clock_.AdvanceTimeMilliseconds(10);
121 now_ms = clock_.TimeInMilliseconds();
122 send_time_ms += 10;
123 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
124 AbsSendTime(send_time_ms, 1000), true, 0);
125 }
126
127 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 =
128 // 1000 kbps.
129 for (int i = 0; i < kNumProbes; ++i) {
130 clock_.AdvanceTimeMilliseconds(8);
131 now_ms = clock_.TimeInMilliseconds();
132 send_time_ms += 5;
133 IncomingPacket(0, 1000, now_ms, send_time_ms,
134 AbsSendTime(send_time_ms, 1000), true, 1);
135 }
136
137 EXPECT_TRUE(bitrate_updated());
138 EXPECT_NEAR(latest_bitrate(), 800000, 10000);
139 }
140
141 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) {
142 int64_t now_ms = clock_.TimeInMilliseconds();
143 // First burst sent at 8 * 1000 / 10 = 800 kbps.
144 // Arriving at 8 * 1000 / 5 = 1600 kbps.
145 int64_t send_time_ms = 0;
146 for (int i = 0; i < kNumProbes; ++i) {
147 clock_.AdvanceTimeMilliseconds(5);
148 send_time_ms += 10;
149 now_ms = clock_.TimeInMilliseconds();
150 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
151 AbsSendTime(send_time_ms, 1000), true, 23);
152 }
153
154 EXPECT_TRUE(bitrate_updated());
155 EXPECT_GT(latest_bitrate(), 800000);
156 }
157
158 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) {
159 int64_t now_ms = clock_.TimeInMilliseconds();
160 // First burst sent at 8 * 1000 / 10 = 800 kbps.
161 // Arriving at 8 * 1000 / 5 = 1600 kbps.
162 int64_t send_time_ms = 0;
163 for (int i = 0; i < kNumProbes; ++i) {
164 clock_.AdvanceTimeMilliseconds(1);
165 send_time_ms += 10;
166 now_ms = clock_.TimeInMilliseconds();
167 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
168 AbsSendTime(send_time_ms, 1000), true, 0);
169 }
170
171 EXPECT_FALSE(bitrate_updated());
172 }
173
174 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) {
175 int64_t now_ms = clock_.TimeInMilliseconds();
176 // First burst sent at 8 * 1000 / 5 = 1600 kbps.
177 // Arriving at 8 * 1000 / 7 = 1142 kbps.
178 int64_t send_time_ms = 0;
179 for (int i = 0; i < kNumProbes; ++i) {
180 clock_.AdvanceTimeMilliseconds(7);
181 send_time_ms += 5;
182 now_ms = clock_.TimeInMilliseconds();
183 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
184 AbsSendTime(send_time_ms, 1000), true, 1);
185 }
186
187 EXPECT_TRUE(bitrate_updated());
188 EXPECT_NEAR(latest_bitrate(), 1140000, 10000);
189 }
190
191 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) {
192 int64_t now_ms = clock_.TimeInMilliseconds();
193 // Burst sent at 8 * 1000 / 1 = 8000 kbps.
194 // Arriving at 8 * 1000 / 2 = 4000 kbps.
195 int64_t send_time_ms = 0;
196 for (int i = 0; i < kNumProbes; ++i) {
197 clock_.AdvanceTimeMilliseconds(2);
198 send_time_ms += 1;
199 now_ms = clock_.TimeInMilliseconds();
200 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
201 AbsSendTime(send_time_ms, 1000), true, 1);
202 }
203
204 EXPECT_TRUE(bitrate_updated());
205 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000);
206 }
207
208 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) {
209 int64_t now_ms = clock_.TimeInMilliseconds();
210 // Probing with 200 bytes every 10 ms, should be ignored by the probe
211 // detection.
212 for (int i = 0; i < kNumProbes; ++i) {
213 clock_.AdvanceTimeMilliseconds(10);
214 now_ms = clock_.TimeInMilliseconds();
215 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms,
216 AbsSendTime(now_ms, 1000), true, 1);
217 }
218
219 EXPECT_FALSE(bitrate_updated());
220
221 // Followed by a probe with 1000 bytes packets, should be detected as a
222 // probe.
223 for (int i = 0; i < kNumProbes; ++i) {
224 clock_.AdvanceTimeMilliseconds(10);
225 now_ms = clock_.TimeInMilliseconds();
226 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
227 true, 1);
228 }
229
230 // Wait long enough so that we can call Process again.
231 clock_.AdvanceTimeMilliseconds(1000);
232
233 EXPECT_TRUE(bitrate_updated());
234 EXPECT_NEAR(latest_bitrate(), 800000u, 10000);
235 }
236 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698