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

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: Added probing unittests to DelayBasedBwe and feedback fixes. 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/system_wrappers/include/clock.h"
15
16 namespace webrtc {
17
18 class TestDelayBasedBwe : public ::testing::Test, public RemoteBitrateObserver {
danilchap 2016/06/08 13:20:07 DelayBasedBweTest
philipel 2016/06/08 14:34:40 Hmm... I usually use this format. Doing 'git grep
danilchap 2016/06/08 14:51:05 it also good idea to do a local style search: both
19 public:
20 static constexpr int kArrivalTimeClockOffsetMs = 60000;
21
22 TestDelayBasedBwe()
23 : bwe_(this), clock_(0), bitrate_updated_(false), latest_bitrate_(0) {}
24
25 uint32_t AbsSendTime(int64_t t, int64_t denom) {
26 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful;
27 }
28
29 void IncomingPacket(uint32_t ssrc,
30 size_t payload_size,
31 int64_t arrival_time,
32 uint32_t rtp_timestamp,
33 uint32_t absolute_send_time,
34 bool was_paced,
35 int probe_cluster_id) {
36 RTPHeader header;
37 memset(&header, 0, sizeof(header));
38 header.ssrc = ssrc;
39 header.timestamp = rtp_timestamp;
40 header.extension.hasAbsoluteSendTime = true;
41 header.extension.absoluteSendTime = absolute_send_time;
42 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size,
43 header, was_paced, probe_cluster_id);
44 }
45
46 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
47 uint32_t bitrate) {
48 bitrate_updated_ = true;
49 latest_bitrate_ = bitrate;
50 }
51
52 bool bitrate_updated() {
53 bool res = bitrate_updated_;
54 bitrate_updated_ = false;
55 return res;
56 }
57
58 int latest_bitrate() { return latest_bitrate_; }
59
60 DelayBasedBwe bwe_;
61 SimulatedClock clock_;
62
63 private:
64 bool bitrate_updated_;
65 int latest_bitrate_;
66 };
67
68 TEST_F(TestDelayBasedBwe, TestProbeDetection) {
69 const int kProbeLength = 5;
danilchap 2016/06/08 13:20:07 constexpr may be name it kNumberOfProbes (ProbeLen
philipel 2016/06/08 14:34:40 Done.
70 int64_t now_ms = clock_.TimeInMilliseconds();
71
72 // First burst sent at 8 * 1000 / 10 = 800 kbps.
73 for (int i = 0; i < kProbeLength; ++i) {
74 clock_.AdvanceTimeMilliseconds(10);
75 now_ms = clock_.TimeInMilliseconds();
76 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
77 true, 0);
78 }
79 EXPECT_TRUE(bitrate_updated());
80
81 // Second burst sent at 8 * 1000 / 5 = 1600 kbps.
82 for (int i = 0; i < kProbeLength; ++i) {
83 clock_.AdvanceTimeMilliseconds(5);
84 now_ms = clock_.TimeInMilliseconds();
85 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
86 true, 1);
87 }
88
89 EXPECT_TRUE(bitrate_updated());
90 EXPECT_GT(latest_bitrate(), 1500000);
91 }
92
93 TEST_F(TestDelayBasedBwe, TestProbeDetectionNonPacedPackets) {
94 const int kProbeLength = 5;
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 < kProbeLength; ++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, 100, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
danilchap 2016/06/08 13:20:07 may be use regular size packets for this test. (si
philipel 2016/06/08 14:34:39 Done.
106 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, TestProbeDetectionTooHighBitrate) {
116 const int kProbeLength = 5;
117 int64_t now_ms = clock_.TimeInMilliseconds();
118 int64_t send_time_ms = 0;
119 // First burst sent at 8 * 1000 / 10 = 800 kbps.
120 for (int i = 0; i < kProbeLength; ++i) {
121 clock_.AdvanceTimeMilliseconds(10);
122 now_ms = clock_.TimeInMilliseconds();
123 send_time_ms += 10;
124 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
125 AbsSendTime(send_time_ms, 1000), true, 0);
126 }
127
128 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 =
129 // 1000 kbps.
130 for (int i = 0; i < kProbeLength; ++i) {
131 clock_.AdvanceTimeMilliseconds(8);
132 now_ms = clock_.TimeInMilliseconds();
133 send_time_ms += 5;
134 IncomingPacket(0, 1000, now_ms, send_time_ms,
135 AbsSendTime(send_time_ms, 1000), true, 1);
136 }
137
138 EXPECT_TRUE(bitrate_updated());
139 EXPECT_NEAR(latest_bitrate(), 800000, 10000);
140 }
141
142 TEST_F(TestDelayBasedBwe, TestProbeDetectionSlightlyFasterArrival) {
143 const int kProbeLength = 5;
144 int64_t now_ms = clock_.TimeInMilliseconds();
145 // First burst sent at 8 * 1000 / 10 = 800 kbps.
146 // Arriving at 8 * 1000 / 5 = 1600 kbps.
147 int64_t send_time_ms = 0;
148 for (int i = 0; i < kProbeLength; ++i) {
149 clock_.AdvanceTimeMilliseconds(5);
150 send_time_ms += 10;
151 now_ms = clock_.TimeInMilliseconds();
152 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
153 AbsSendTime(send_time_ms, 1000), true, 23);
154 }
155
156 EXPECT_TRUE(bitrate_updated());
157 EXPECT_GT(latest_bitrate(), 800000);
158 }
159
160 TEST_F(TestDelayBasedBwe, TestProbeDetectionFasterArrival) {
161 const int kProbeLength = 5;
162 int64_t now_ms = clock_.TimeInMilliseconds();
163 // First burst sent at 8 * 1000 / 10 = 800 kbps.
164 // Arriving at 8 * 1000 / 5 = 1600 kbps.
165 int64_t send_time_ms = 0;
166 for (int i = 0; i < kProbeLength; ++i) {
167 clock_.AdvanceTimeMilliseconds(1);
168 send_time_ms += 10;
169 now_ms = clock_.TimeInMilliseconds();
170 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
171 AbsSendTime(send_time_ms, 1000), true, 0);
172 }
173
174 EXPECT_FALSE(bitrate_updated());
175 }
176
177 TEST_F(TestDelayBasedBwe, TestProbeDetectionSlowerArrival) {
178 const int kProbeLength = 5;
179 int64_t now_ms = clock_.TimeInMilliseconds();
180 // First burst sent at 8 * 1000 / 5 = 1600 kbps.
181 // Arriving at 8 * 1000 / 7 = 1142 kbps.
182 int64_t send_time_ms = 0;
183 for (int i = 0; i < kProbeLength; ++i) {
184 clock_.AdvanceTimeMilliseconds(7);
185 send_time_ms += 5;
186 now_ms = clock_.TimeInMilliseconds();
187 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
188 AbsSendTime(send_time_ms, 1000), true, 1);
189 }
190
191 EXPECT_TRUE(bitrate_updated());
192 EXPECT_NEAR(latest_bitrate(), 1140000, 10000);
193 }
194
195 TEST_F(TestDelayBasedBwe, TestProbeDetectionSlowerArrivalHighBitrate) {
danilchap 2016/06/08 13:20:08 Either all tests should start with word 'Test' (li
philipel 2016/06/08 14:34:40 Done.
196 const int kProbeLength = 5;
197 int64_t now_ms = clock_.TimeInMilliseconds();
198 // Burst sent at 8 * 1000 / 1 = 8000 kbps.
199 // Arriving at 8 * 1000 / 2 = 4000 kbps.
200 int64_t send_time_ms = 0;
201 for (int i = 0; i < kProbeLength; ++i) {
202 clock_.AdvanceTimeMilliseconds(2);
203 send_time_ms += 1;
204 now_ms = clock_.TimeInMilliseconds();
205 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms,
206 AbsSendTime(send_time_ms, 1000), true, 1);
207 }
208
209 EXPECT_TRUE(bitrate_updated());
210 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000);
211 }
212
213 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) {
214 const int kProbeLength = 5;
215 int64_t now_ms = clock_.TimeInMilliseconds();
216 // Probing with 200 bytes every 10 ms, should be ignored by the probe
217 // detection.
218 for (int i = 0; i < kProbeLength; ++i) {
219 clock_.AdvanceTimeMilliseconds(10);
220 now_ms = clock_.TimeInMilliseconds();
221 IncomingPacket(0, 200, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), true,
danilchap 2016/06/08 13:20:08 may be better use PacedSender::kMinProbePacketSize
philipel 2016/06/08 14:34:39 Done.
222 1);
223 }
224
225 EXPECT_FALSE(bitrate_updated());
226
227 // Followed by a probe with 1000 bytes packets, should be detected as a
228 // probe.
229 for (int i = 0; i < kProbeLength; ++i) {
230 clock_.AdvanceTimeMilliseconds(10);
231 now_ms = clock_.TimeInMilliseconds();
232 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000),
danilchap 2016/06/08 13:20:07 May be use (kMinProbePacketSize+1) instead of 1000
philipel 2016/06/08 14:34:40 I agree that is a good idea, but these tests are k
233 true, 1);
234 }
235
236 // Wait long enough so that we can call Process again.
237 clock_.AdvanceTimeMilliseconds(1000);
238
239 EXPECT_TRUE(bitrate_updated());
240 EXPECT_NEAR(latest_bitrate(), 800000u, 10000);
241 }
242 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698