OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ | 11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ |
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ | 12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ |
13 | 13 |
14 #include <assert.h> | 14 #include <assert.h> |
15 #include <math.h> | 15 #include <math.h> |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <list> | 18 #include <list> |
19 #include <numeric> | 19 #include <numeric> |
20 #include <sstream> | 20 #include <sstream> |
21 #include <string> | 21 #include <string> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
| 24 #include "webrtc/base/common.h" |
24 #include "webrtc/base/scoped_ptr.h" | 25 #include "webrtc/base/scoped_ptr.h" |
25 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 26 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
26 #include "webrtc/modules/interface/module_common_types.h" | 27 #include "webrtc/modules/interface/module_common_types.h" |
27 #include "webrtc/modules/pacing/include/paced_sender.h" | 28 #include "webrtc/modules/pacing/include/paced_sender.h" |
28 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 29 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
29 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 30 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
30 #include "webrtc/modules/remote_bitrate_estimator/test/packet.h" | 31 #include "webrtc/modules/remote_bitrate_estimator/test/packet.h" |
31 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 32 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
32 #include "webrtc/system_wrappers/interface/clock.h" | 33 #include "webrtc/system_wrappers/interface/clock.h" |
33 | 34 |
34 namespace webrtc { | 35 namespace webrtc { |
35 | 36 |
36 class RtcpBandwidthObserver; | 37 class RtcpBandwidthObserver; |
37 | 38 |
38 namespace testing { | 39 namespace testing { |
39 namespace bwe { | 40 namespace bwe { |
40 | 41 |
41 class DelayCapHelper; | 42 class DelayCapHelper; |
42 class RateCounter; | 43 |
| 44 class RateCounter { |
| 45 public: |
| 46 RateCounter(int64_t window_size_ms) |
| 47 : window_size_us_(1000 * window_size_ms), |
| 48 recently_received_packets_(0), |
| 49 recently_received_bytes_(0), |
| 50 last_accumulated_us_(0), |
| 51 window_() {} |
| 52 |
| 53 RateCounter() : RateCounter(1000) {} |
| 54 |
| 55 void UpdateRates(int64_t send_time_us, uint32_t payload_size); |
| 56 |
| 57 int64_t window_size_ms() const { return window_size_us_ / 1000; } |
| 58 uint32_t packets_per_second() const; |
| 59 uint32_t bits_per_second() const; |
| 60 |
| 61 private: |
| 62 double window_size_s() const; |
| 63 typedef std::pair<int64_t, uint32_t> TimeSizePair; |
| 64 |
| 65 int64_t window_size_us_; |
| 66 uint32_t recently_received_packets_; |
| 67 uint32_t recently_received_bytes_; |
| 68 int64_t last_accumulated_us_; |
| 69 std::list<TimeSizePair> window_; |
| 70 }; |
43 | 71 |
44 typedef std::set<int> FlowIds; | 72 typedef std::set<int> FlowIds; |
45 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids); | 73 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids); |
| 74 const FlowIds CreateFlowIdRange(int initial_value, int last_value); |
46 | 75 |
47 template <typename T> | 76 template <typename T> |
48 bool DereferencingComparator(const T* const& a, const T* const& b) { | 77 bool DereferencingComparator(const T* const& a, const T* const& b) { |
49 assert(a != NULL); | 78 assert(a != NULL); |
50 assert(b != NULL); | 79 assert(b != NULL); |
51 return *a < *b; | 80 return *a < *b; |
52 } | 81 } |
53 | 82 |
54 template<typename T> class Stats { | 83 template<typename T> class Stats { |
55 public: | 84 public: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 T max_; | 171 T max_; |
143 }; | 172 }; |
144 | 173 |
145 class Random { | 174 class Random { |
146 public: | 175 public: |
147 explicit Random(uint32_t seed); | 176 explicit Random(uint32_t seed); |
148 | 177 |
149 // Return pseudo random number in the interval [0.0, 1.0]. | 178 // Return pseudo random number in the interval [0.0, 1.0]. |
150 float Rand(); | 179 float Rand(); |
151 | 180 |
| 181 // Return pseudo rounded random number in interval [low, high]. |
| 182 int Rand(int low, int high); |
| 183 |
152 // Normal Distribution. | 184 // Normal Distribution. |
153 int Gaussian(int mean, int standard_deviation); | 185 int Gaussian(int mean, int standard_deviation); |
154 | 186 |
| 187 // Exponential Distribution. |
| 188 int Exponential(float lambda); |
| 189 |
155 // TODO(solenberg): Random from histogram. | 190 // TODO(solenberg): Random from histogram. |
156 // template<typename T> int Distribution(const std::vector<T> histogram) { | 191 // template<typename T> int Distribution(const std::vector<T> histogram) { |
157 | 192 |
158 private: | 193 private: |
159 uint32_t a_; | 194 uint32_t a_; |
160 uint32_t b_; | 195 uint32_t b_; |
161 | 196 |
162 DISALLOW_IMPLICIT_CONSTRUCTORS(Random); | 197 DISALLOW_IMPLICIT_CONSTRUCTORS(Random); |
163 }; | 198 }; |
164 | 199 |
(...skipping 26 matching lines...) Expand all Loading... |
191 // internal data. | 226 // internal data. |
192 virtual void Plot(int64_t timestamp_ms) {} | 227 virtual void Plot(int64_t timestamp_ms) {} |
193 | 228 |
194 // Run simulation for |time_ms| milliseconds, consuming packets from, and | 229 // Run simulation for |time_ms| milliseconds, consuming packets from, and |
195 // producing packets into in_out. The outgoing packet list must be sorted on | 230 // producing packets into in_out. The outgoing packet list must be sorted on |
196 // |send_time_us_|. The simulation time |time_ms| is optional to use. | 231 // |send_time_us_|. The simulation time |time_ms| is optional to use. |
197 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0; | 232 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0; |
198 | 233 |
199 const FlowIds& flow_ids() const { return flow_ids_; } | 234 const FlowIds& flow_ids() const { return flow_ids_; } |
200 | 235 |
| 236 uint32_t packets_per_second() const; |
| 237 uint32_t bits_per_second() const; |
| 238 |
| 239 protected: |
| 240 RateCounter rate_counter_; |
| 241 |
201 private: | 242 private: |
202 PacketProcessorListener* listener_; | 243 PacketProcessorListener* listener_; |
203 const FlowIds flow_ids_; | 244 const FlowIds flow_ids_; |
204 | 245 |
205 DISALLOW_COPY_AND_ASSIGN(PacketProcessor); | 246 DISALLOW_COPY_AND_ASSIGN(PacketProcessor); |
206 }; | 247 }; |
207 | 248 |
208 class RateCounterFilter : public PacketProcessor { | 249 class RateCounterFilter : public PacketProcessor { |
209 public: | 250 public: |
210 RateCounterFilter(PacketProcessorListener* listener, | 251 RateCounterFilter(PacketProcessorListener* listener, |
211 int flow_id, | 252 int flow_id, |
212 const char* name); | 253 const char* name); |
213 RateCounterFilter(PacketProcessorListener* listener, | 254 RateCounterFilter(PacketProcessorListener* listener, |
214 const FlowIds& flow_ids, | 255 const FlowIds& flow_ids, |
215 const char* name); | 256 const char* name); |
| 257 RateCounterFilter(PacketProcessorListener* listener, |
| 258 const FlowIds& flow_ids, |
| 259 const char* name, |
| 260 int64_t start_plotting_time_ms); |
216 virtual ~RateCounterFilter(); | 261 virtual ~RateCounterFilter(); |
217 | 262 |
218 uint32_t packets_per_second() const; | |
219 uint32_t bits_per_second() const; | |
220 | |
221 void LogStats(); | 263 void LogStats(); |
222 Stats<double> GetBitrateStats() const; | 264 Stats<double> GetBitrateStats() const; |
223 virtual void Plot(int64_t timestamp_ms); | 265 virtual void Plot(int64_t timestamp_ms); |
224 virtual void RunFor(int64_t time_ms, Packets* in_out); | 266 virtual void RunFor(int64_t time_ms, Packets* in_out); |
225 | 267 |
226 private: | 268 private: |
227 rtc::scoped_ptr<RateCounter> rate_counter_; | |
228 Stats<double> packets_per_second_stats_; | 269 Stats<double> packets_per_second_stats_; |
229 Stats<double> kbps_stats_; | 270 Stats<double> kbps_stats_; |
230 std::string name_; | 271 std::string name_; |
| 272 int64_t start_plotting_time_ms_; |
231 | 273 |
232 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter); | 274 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter); |
233 }; | 275 }; |
234 | 276 |
235 class LossFilter : public PacketProcessor { | 277 class LossFilter : public PacketProcessor { |
236 public: | 278 public: |
237 LossFilter(PacketProcessorListener* listener, int flow_id); | 279 LossFilter(PacketProcessorListener* listener, int flow_id); |
238 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); | 280 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); |
239 virtual ~LossFilter() {} | 281 virtual ~LossFilter() {} |
240 | 282 |
241 void SetLoss(float loss_percent); | 283 void SetLoss(float loss_percent); |
242 virtual void RunFor(int64_t time_ms, Packets* in_out); | 284 virtual void RunFor(int64_t time_ms, Packets* in_out); |
243 | 285 |
244 private: | 286 private: |
245 Random random_; | 287 Random random_; |
246 float loss_fraction_; | 288 float loss_fraction_; |
247 | 289 |
248 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter); | 290 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter); |
249 }; | 291 }; |
250 | 292 |
251 class DelayFilter : public PacketProcessor { | 293 class DelayFilter : public PacketProcessor { |
252 public: | 294 public: |
253 DelayFilter(PacketProcessorListener* listener, int flow_id); | 295 DelayFilter(PacketProcessorListener* listener, int flow_id); |
254 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); | 296 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); |
255 virtual ~DelayFilter() {} | 297 virtual ~DelayFilter() {} |
256 | 298 |
257 void SetDelayMs(int64_t delay_ms); | 299 void SetOneWayDelayMs(int64_t one_way_delay_ms); |
258 virtual void RunFor(int64_t time_ms, Packets* in_out); | 300 virtual void RunFor(int64_t time_ms, Packets* in_out); |
259 | 301 |
260 private: | 302 private: |
261 int64_t delay_us_; | 303 int64_t one_way_delay_us_; |
262 int64_t last_send_time_us_; | 304 int64_t last_send_time_us_; |
263 | 305 |
264 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter); | 306 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter); |
265 }; | 307 }; |
266 | 308 |
267 class JitterFilter : public PacketProcessor { | 309 class JitterFilter : public PacketProcessor { |
268 public: | 310 public: |
269 JitterFilter(PacketProcessorListener* listener, int flow_id); | 311 JitterFilter(PacketProcessorListener* listener, int flow_id); |
270 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); | 312 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); |
271 virtual ~JitterFilter() {} | 313 virtual ~JitterFilter() {} |
(...skipping 26 matching lines...) Expand all Loading... |
298 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter); | 340 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter); |
299 }; | 341 }; |
300 | 342 |
301 // Apply a bitrate choke with an infinite queue on the packet stream. | 343 // Apply a bitrate choke with an infinite queue on the packet stream. |
302 class ChokeFilter : public PacketProcessor { | 344 class ChokeFilter : public PacketProcessor { |
303 public: | 345 public: |
304 ChokeFilter(PacketProcessorListener* listener, int flow_id); | 346 ChokeFilter(PacketProcessorListener* listener, int flow_id); |
305 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); | 347 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); |
306 virtual ~ChokeFilter(); | 348 virtual ~ChokeFilter(); |
307 | 349 |
308 void SetCapacity(uint32_t kbps); | 350 void set_capacity_kbps(uint32_t kbps); |
309 void SetMaxDelay(int max_delay_ms); | 351 void set_max_delay_ms(int64_t max_queueing_delay_ms); |
| 352 |
| 353 uint32_t capacity_kbps(); |
| 354 |
310 virtual void RunFor(int64_t time_ms, Packets* in_out); | 355 virtual void RunFor(int64_t time_ms, Packets* in_out); |
311 | 356 |
312 Stats<double> GetDelayStats() const; | 357 Stats<double> GetDelayStats() const; |
313 | 358 |
314 private: | 359 private: |
315 uint32_t kbps_; | 360 uint32_t capacity_kbps_; |
316 int64_t last_send_time_us_; | 361 int64_t last_send_time_us_; |
317 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_; | 362 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_; |
| 363 int64_t max_delay_us_; |
318 | 364 |
319 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter); | 365 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter); |
320 }; | 366 }; |
321 | 367 |
322 class TraceBasedDeliveryFilter : public PacketProcessor { | 368 class TraceBasedDeliveryFilter : public PacketProcessor { |
323 public: | 369 public: |
324 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id); | 370 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id); |
325 TraceBasedDeliveryFilter(PacketProcessorListener* listener, | 371 TraceBasedDeliveryFilter(PacketProcessorListener* listener, |
326 const FlowIds& flow_ids); | 372 const FlowIds& flow_ids); |
327 TraceBasedDeliveryFilter(PacketProcessorListener* listener, | 373 TraceBasedDeliveryFilter(PacketProcessorListener* listener, |
328 int flow_id, | 374 int flow_id, |
329 const char* name); | 375 const char* name); |
330 virtual ~TraceBasedDeliveryFilter(); | 376 virtual ~TraceBasedDeliveryFilter(); |
331 | 377 |
332 // The file should contain nanosecond timestamps corresponding to the time | 378 // The file should contain nanosecond timestamps corresponding to the time |
333 // when the network can accept another packet. The timestamps should be | 379 // when the network can accept another packet. The timestamps should be |
334 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..." | 380 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..." |
335 bool Init(const std::string& filename); | 381 bool Init(const std::string& filename); |
336 virtual void Plot(int64_t timestamp_ms); | 382 virtual void Plot(int64_t timestamp_ms); |
337 virtual void RunFor(int64_t time_ms, Packets* in_out); | 383 virtual void RunFor(int64_t time_ms, Packets* in_out); |
338 | 384 |
339 void SetMaxDelay(int max_delay_ms); | 385 void set_max_delay_ms(int64_t max_delay_ms); |
340 Stats<double> GetDelayStats() const; | 386 Stats<double> GetDelayStats() const; |
341 Stats<double> GetBitrateStats() const; | 387 Stats<double> GetBitrateStats() const; |
342 | 388 |
343 private: | 389 private: |
344 void ProceedToNextSlot(); | 390 void ProceedToNextSlot(); |
345 | 391 |
346 typedef std::vector<int64_t> TimeList; | 392 typedef std::vector<int64_t> TimeList; |
347 int64_t current_offset_us_; | 393 int64_t current_offset_us_; |
348 TimeList delivery_times_us_; | 394 TimeList delivery_times_us_; |
349 TimeList::const_iterator next_delivery_it_; | 395 TimeList::const_iterator next_delivery_it_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 const uint32_t kTimestampBase; | 429 const uint32_t kTimestampBase; |
384 const double frame_period_ms_; | 430 const double frame_period_ms_; |
385 uint32_t bits_per_second_; | 431 uint32_t bits_per_second_; |
386 uint32_t frame_size_bytes_; | 432 uint32_t frame_size_bytes_; |
387 | 433 |
388 private: | 434 private: |
389 const int flow_id_; | 435 const int flow_id_; |
390 int64_t next_frame_ms_; | 436 int64_t next_frame_ms_; |
391 int64_t now_ms_; | 437 int64_t now_ms_; |
392 RTPHeader prototype_header_; | 438 RTPHeader prototype_header_; |
| 439 int64_t start_plotting_ms_; |
| 440 uint32_t previous_bitrate_bps_; |
393 | 441 |
394 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoSource); | 442 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoSource); |
395 }; | 443 }; |
396 | 444 |
397 class AdaptiveVideoSource : public VideoSource { | 445 class AdaptiveVideoSource : public VideoSource { |
398 public: | 446 public: |
399 AdaptiveVideoSource(int flow_id, | 447 AdaptiveVideoSource(int flow_id, |
400 float fps, | 448 float fps, |
401 uint32_t kbps, | 449 uint32_t kbps, |
402 uint32_t ssrc, | 450 uint32_t ssrc, |
(...skipping 26 matching lines...) Expand all Loading... |
429 uint32_t frame_counter_; | 477 uint32_t frame_counter_; |
430 int compensation_bytes_; | 478 int compensation_bytes_; |
431 int compensation_per_frame_; | 479 int compensation_per_frame_; |
432 DISALLOW_IMPLICIT_CONSTRUCTORS(PeriodicKeyFrameSource); | 480 DISALLOW_IMPLICIT_CONSTRUCTORS(PeriodicKeyFrameSource); |
433 }; | 481 }; |
434 } // namespace bwe | 482 } // namespace bwe |
435 } // namespace testing | 483 } // namespace testing |
436 } // namespace webrtc | 484 } // namespace webrtc |
437 | 485 |
438 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ | 486 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ |
OLD | NEW |