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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h

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

Powered by Google App Engine
This is Rietveld 408576698