OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 uint32_t AbsSendTime(int64_t t, int64_t denom) { | 27 uint32_t AbsSendTime(int64_t t, int64_t denom) { |
28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
29 } | 29 } |
30 | 30 |
31 void IncomingPacket(uint32_t ssrc, | 31 void IncomingPacket(uint32_t ssrc, |
32 size_t payload_size, | 32 size_t payload_size, |
33 int64_t arrival_time, | 33 int64_t arrival_time, |
34 uint32_t rtp_timestamp, | 34 uint32_t rtp_timestamp, |
35 uint32_t absolute_send_time, | 35 uint32_t absolute_send_time, |
36 bool was_paced, | |
37 int probe_cluster_id) { | 36 int probe_cluster_id) { |
38 RTPHeader header; | 37 RTPHeader header; |
39 memset(&header, 0, sizeof(header)); | 38 memset(&header, 0, sizeof(header)); |
40 header.ssrc = ssrc; | 39 header.ssrc = ssrc; |
41 header.timestamp = rtp_timestamp; | 40 header.timestamp = rtp_timestamp; |
42 header.extension.hasAbsoluteSendTime = true; | 41 header.extension.hasAbsoluteSendTime = true; |
43 header.extension.absoluteSendTime = absolute_send_time; | 42 header.extension.absoluteSendTime = absolute_send_time; |
44 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size, | 43 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size, |
45 header, was_paced, probe_cluster_id); | 44 header, probe_cluster_id); |
46 } | 45 } |
47 | 46 |
48 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, | 47 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
49 uint32_t bitrate) { | 48 uint32_t bitrate) { |
50 bitrate_updated_ = true; | 49 bitrate_updated_ = true; |
51 latest_bitrate_ = bitrate; | 50 latest_bitrate_ = bitrate; |
52 } | 51 } |
53 | 52 |
54 bool bitrate_updated() { | 53 bool bitrate_updated() { |
55 bool res = bitrate_updated_; | 54 bool res = bitrate_updated_; |
(...skipping 11 matching lines...) Expand all Loading... |
67 int latest_bitrate_; | 66 int latest_bitrate_; |
68 }; | 67 }; |
69 | 68 |
70 TEST_F(TestDelayBasedBwe, ProbeDetection) { | 69 TEST_F(TestDelayBasedBwe, ProbeDetection) { |
71 int64_t now_ms = clock_.TimeInMilliseconds(); | 70 int64_t now_ms = clock_.TimeInMilliseconds(); |
72 | 71 |
73 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 72 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
74 for (int i = 0; i < kNumProbes; ++i) { | 73 for (int i = 0; i < kNumProbes; ++i) { |
75 clock_.AdvanceTimeMilliseconds(10); | 74 clock_.AdvanceTimeMilliseconds(10); |
76 now_ms = clock_.TimeInMilliseconds(); | 75 now_ms = clock_.TimeInMilliseconds(); |
77 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 76 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); |
78 true, 0); | |
79 } | 77 } |
80 EXPECT_TRUE(bitrate_updated()); | 78 EXPECT_TRUE(bitrate_updated()); |
81 | 79 |
82 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. | 80 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. |
83 for (int i = 0; i < kNumProbes; ++i) { | 81 for (int i = 0; i < kNumProbes; ++i) { |
84 clock_.AdvanceTimeMilliseconds(5); | 82 clock_.AdvanceTimeMilliseconds(5); |
85 now_ms = clock_.TimeInMilliseconds(); | 83 now_ms = clock_.TimeInMilliseconds(); |
86 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 84 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); |
87 true, 1); | |
88 } | 85 } |
89 | 86 |
90 EXPECT_TRUE(bitrate_updated()); | 87 EXPECT_TRUE(bitrate_updated()); |
91 EXPECT_GT(latest_bitrate(), 1500000); | 88 EXPECT_GT(latest_bitrate(), 1500000); |
92 } | 89 } |
93 | 90 |
94 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { | 91 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { |
95 int64_t now_ms = clock_.TimeInMilliseconds(); | 92 int64_t now_ms = clock_.TimeInMilliseconds(); |
96 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet | 93 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet |
97 // not being paced which could mess things up. | 94 // not being paced which could mess things up. |
98 for (int i = 0; i < kNumProbes; ++i) { | 95 for (int i = 0; i < kNumProbes; ++i) { |
99 clock_.AdvanceTimeMilliseconds(5); | 96 clock_.AdvanceTimeMilliseconds(5); |
100 now_ms = clock_.TimeInMilliseconds(); | 97 now_ms = clock_.TimeInMilliseconds(); |
101 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 98 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); |
102 true, 0); | |
103 // Non-paced packet, arriving 5 ms after. | 99 // Non-paced packet, arriving 5 ms after. |
104 clock_.AdvanceTimeMilliseconds(5); | 100 clock_.AdvanceTimeMilliseconds(5); |
105 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, | 101 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, |
106 AbsSendTime(now_ms, 1000), false, PacketInfo::kNotAProbe); | 102 AbsSendTime(now_ms, 1000), PacketInfo::kNotAProbe); |
107 } | 103 } |
108 | 104 |
109 EXPECT_TRUE(bitrate_updated()); | 105 EXPECT_TRUE(bitrate_updated()); |
110 EXPECT_GT(latest_bitrate(), 800000); | 106 EXPECT_GT(latest_bitrate(), 800000); |
111 } | 107 } |
112 | 108 |
113 // Packets will require 5 ms to be transmitted to the receiver, causing packets | 109 // Packets will require 5 ms to be transmitted to the receiver, causing packets |
114 // of the second probe to be dispersed. | 110 // of the second probe to be dispersed. |
115 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { | 111 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { |
116 int64_t now_ms = clock_.TimeInMilliseconds(); | 112 int64_t now_ms = clock_.TimeInMilliseconds(); |
117 int64_t send_time_ms = 0; | 113 int64_t send_time_ms = 0; |
118 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 114 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
119 for (int i = 0; i < kNumProbes; ++i) { | 115 for (int i = 0; i < kNumProbes; ++i) { |
120 clock_.AdvanceTimeMilliseconds(10); | 116 clock_.AdvanceTimeMilliseconds(10); |
121 now_ms = clock_.TimeInMilliseconds(); | 117 now_ms = clock_.TimeInMilliseconds(); |
122 send_time_ms += 10; | 118 send_time_ms += 10; |
123 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 119 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
124 AbsSendTime(send_time_ms, 1000), true, 0); | 120 AbsSendTime(send_time_ms, 1000), 0); |
125 } | 121 } |
126 | 122 |
127 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = | 123 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = |
128 // 1000 kbps. | 124 // 1000 kbps. |
129 for (int i = 0; i < kNumProbes; ++i) { | 125 for (int i = 0; i < kNumProbes; ++i) { |
130 clock_.AdvanceTimeMilliseconds(8); | 126 clock_.AdvanceTimeMilliseconds(8); |
131 now_ms = clock_.TimeInMilliseconds(); | 127 now_ms = clock_.TimeInMilliseconds(); |
132 send_time_ms += 5; | 128 send_time_ms += 5; |
133 IncomingPacket(0, 1000, now_ms, send_time_ms, | 129 IncomingPacket(0, 1000, now_ms, send_time_ms, |
134 AbsSendTime(send_time_ms, 1000), true, 1); | 130 AbsSendTime(send_time_ms, 1000), 1); |
135 } | 131 } |
136 | 132 |
137 EXPECT_TRUE(bitrate_updated()); | 133 EXPECT_TRUE(bitrate_updated()); |
138 EXPECT_NEAR(latest_bitrate(), 800000, 10000); | 134 EXPECT_NEAR(latest_bitrate(), 800000, 10000); |
139 } | 135 } |
140 | 136 |
141 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { | 137 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { |
142 int64_t now_ms = clock_.TimeInMilliseconds(); | 138 int64_t now_ms = clock_.TimeInMilliseconds(); |
143 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 139 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
144 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 140 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
145 int64_t send_time_ms = 0; | 141 int64_t send_time_ms = 0; |
146 for (int i = 0; i < kNumProbes; ++i) { | 142 for (int i = 0; i < kNumProbes; ++i) { |
147 clock_.AdvanceTimeMilliseconds(5); | 143 clock_.AdvanceTimeMilliseconds(5); |
148 send_time_ms += 10; | 144 send_time_ms += 10; |
149 now_ms = clock_.TimeInMilliseconds(); | 145 now_ms = clock_.TimeInMilliseconds(); |
150 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 146 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
151 AbsSendTime(send_time_ms, 1000), true, 23); | 147 AbsSendTime(send_time_ms, 1000), 23); |
152 } | 148 } |
153 | 149 |
154 EXPECT_TRUE(bitrate_updated()); | 150 EXPECT_TRUE(bitrate_updated()); |
155 EXPECT_GT(latest_bitrate(), 800000); | 151 EXPECT_GT(latest_bitrate(), 800000); |
156 } | 152 } |
157 | 153 |
158 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { | 154 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { |
159 int64_t now_ms = clock_.TimeInMilliseconds(); | 155 int64_t now_ms = clock_.TimeInMilliseconds(); |
160 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 156 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
161 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 157 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
162 int64_t send_time_ms = 0; | 158 int64_t send_time_ms = 0; |
163 for (int i = 0; i < kNumProbes; ++i) { | 159 for (int i = 0; i < kNumProbes; ++i) { |
164 clock_.AdvanceTimeMilliseconds(1); | 160 clock_.AdvanceTimeMilliseconds(1); |
165 send_time_ms += 10; | 161 send_time_ms += 10; |
166 now_ms = clock_.TimeInMilliseconds(); | 162 now_ms = clock_.TimeInMilliseconds(); |
167 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 163 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
168 AbsSendTime(send_time_ms, 1000), true, 0); | 164 AbsSendTime(send_time_ms, 1000), 0); |
169 } | 165 } |
170 | 166 |
171 EXPECT_FALSE(bitrate_updated()); | 167 EXPECT_FALSE(bitrate_updated()); |
172 } | 168 } |
173 | 169 |
174 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { | 170 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { |
175 int64_t now_ms = clock_.TimeInMilliseconds(); | 171 int64_t now_ms = clock_.TimeInMilliseconds(); |
176 // First burst sent at 8 * 1000 / 5 = 1600 kbps. | 172 // First burst sent at 8 * 1000 / 5 = 1600 kbps. |
177 // Arriving at 8 * 1000 / 7 = 1142 kbps. | 173 // Arriving at 8 * 1000 / 7 = 1142 kbps. |
178 int64_t send_time_ms = 0; | 174 int64_t send_time_ms = 0; |
179 for (int i = 0; i < kNumProbes; ++i) { | 175 for (int i = 0; i < kNumProbes; ++i) { |
180 clock_.AdvanceTimeMilliseconds(7); | 176 clock_.AdvanceTimeMilliseconds(7); |
181 send_time_ms += 5; | 177 send_time_ms += 5; |
182 now_ms = clock_.TimeInMilliseconds(); | 178 now_ms = clock_.TimeInMilliseconds(); |
183 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 179 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
184 AbsSendTime(send_time_ms, 1000), true, 1); | 180 AbsSendTime(send_time_ms, 1000), 1); |
185 } | 181 } |
186 | 182 |
187 EXPECT_TRUE(bitrate_updated()); | 183 EXPECT_TRUE(bitrate_updated()); |
188 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); | 184 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); |
189 } | 185 } |
190 | 186 |
191 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { | 187 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { |
192 int64_t now_ms = clock_.TimeInMilliseconds(); | 188 int64_t now_ms = clock_.TimeInMilliseconds(); |
193 // Burst sent at 8 * 1000 / 1 = 8000 kbps. | 189 // Burst sent at 8 * 1000 / 1 = 8000 kbps. |
194 // Arriving at 8 * 1000 / 2 = 4000 kbps. | 190 // Arriving at 8 * 1000 / 2 = 4000 kbps. |
195 int64_t send_time_ms = 0; | 191 int64_t send_time_ms = 0; |
196 for (int i = 0; i < kNumProbes; ++i) { | 192 for (int i = 0; i < kNumProbes; ++i) { |
197 clock_.AdvanceTimeMilliseconds(2); | 193 clock_.AdvanceTimeMilliseconds(2); |
198 send_time_ms += 1; | 194 send_time_ms += 1; |
199 now_ms = clock_.TimeInMilliseconds(); | 195 now_ms = clock_.TimeInMilliseconds(); |
200 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 196 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
201 AbsSendTime(send_time_ms, 1000), true, 1); | 197 AbsSendTime(send_time_ms, 1000), 1); |
202 } | 198 } |
203 | 199 |
204 EXPECT_TRUE(bitrate_updated()); | 200 EXPECT_TRUE(bitrate_updated()); |
205 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); | 201 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); |
206 } | 202 } |
207 | 203 |
208 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { | 204 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { |
209 int64_t now_ms = clock_.TimeInMilliseconds(); | 205 int64_t now_ms = clock_.TimeInMilliseconds(); |
210 // Probing with 200 bytes every 10 ms, should be ignored by the probe | 206 // Probing with 200 bytes every 10 ms, should be ignored by the probe |
211 // detection. | 207 // detection. |
212 for (int i = 0; i < kNumProbes; ++i) { | 208 for (int i = 0; i < kNumProbes; ++i) { |
213 clock_.AdvanceTimeMilliseconds(10); | 209 clock_.AdvanceTimeMilliseconds(10); |
214 now_ms = clock_.TimeInMilliseconds(); | 210 now_ms = clock_.TimeInMilliseconds(); |
215 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, | 211 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, |
216 AbsSendTime(now_ms, 1000), true, 1); | 212 AbsSendTime(now_ms, 1000), 1); |
217 } | 213 } |
218 | 214 |
219 EXPECT_FALSE(bitrate_updated()); | 215 EXPECT_FALSE(bitrate_updated()); |
220 | 216 |
221 // Followed by a probe with 1000 bytes packets, should be detected as a | 217 // Followed by a probe with 1000 bytes packets, should be detected as a |
222 // probe. | 218 // probe. |
223 for (int i = 0; i < kNumProbes; ++i) { | 219 for (int i = 0; i < kNumProbes; ++i) { |
224 clock_.AdvanceTimeMilliseconds(10); | 220 clock_.AdvanceTimeMilliseconds(10); |
225 now_ms = clock_.TimeInMilliseconds(); | 221 now_ms = clock_.TimeInMilliseconds(); |
226 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 222 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); |
227 true, 1); | |
228 } | 223 } |
229 | 224 |
230 // Wait long enough so that we can call Process again. | 225 // Wait long enough so that we can call Process again. |
231 clock_.AdvanceTimeMilliseconds(1000); | 226 clock_.AdvanceTimeMilliseconds(1000); |
232 | 227 |
233 EXPECT_TRUE(bitrate_updated()); | 228 EXPECT_TRUE(bitrate_updated()); |
234 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); | 229 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); |
235 } | 230 } |
236 } // namespace webrtc | 231 } // namespace webrtc |
OLD | NEW |