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

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: Comments addressed [2] 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()
47 : windows_size_us_(1000 * 1000),
48 packets_per_second_(0),
49 recently_received_bytes(0),
50 last_accumulated_us_(0),
51 window_() {}
52
53 void UpdateRates(int64_t send_time_us, uint32_t payload_size);
54 void set_windows_size_ms(int64_t windows_size_ms);
55
56 int64_t windows_size_ms() const { return windows_size_us_ / 1000; }
57 uint32_t packets_per_second() const { return packets_per_second_; }
58 uint32_t bits_per_second() const;
59
60 private:
61 typedef std::pair<int64_t, uint32_t> TimeSizePair;
62
63 int64_t windows_size_us_;
64 uint32_t packets_per_second_;
65 uint32_t recently_received_bytes;
66 int64_t last_accumulated_us_;
67 std::list<TimeSizePair> window_;
68 };
43 69
44 typedef std::set<int> FlowIds; 70 typedef std::set<int> FlowIds;
45 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids); 71 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids);
72 const FlowIds CreateFlowIdRange(int initial_value, int last_value);
46 73
47 template <typename T> 74 template <typename T>
48 bool DereferencingComparator(const T* const& a, const T* const& b) { 75 bool DereferencingComparator(const T* const& a, const T* const& b) {
49 assert(a != NULL); 76 assert(a != NULL);
50 assert(b != NULL); 77 assert(b != NULL);
51 return *a < *b; 78 return *a < *b;
52 } 79 }
53 80
54 template<typename T> class Stats { 81 template<typename T> class Stats {
55 public: 82 public:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 T max_; 169 T max_;
143 }; 170 };
144 171
145 class Random { 172 class Random {
146 public: 173 public:
147 explicit Random(uint32_t seed); 174 explicit Random(uint32_t seed);
148 175
149 // Return pseudo random number in the interval [0.0, 1.0]. 176 // Return pseudo random number in the interval [0.0, 1.0].
150 float Rand(); 177 float Rand();
151 178
179 // Return pseudo rounded random number in interval [low, high].
180 int Rand(int low, int high);
181
152 // Normal Distribution. 182 // Normal Distribution.
153 int Gaussian(int mean, int standard_deviation); 183 int Gaussian(int mean, int standard_deviation);
154 184
185 // Exponential Distribution.
186 int Exponential(float lambda);
187
155 // TODO(solenberg): Random from histogram. 188 // TODO(solenberg): Random from histogram.
156 // template<typename T> int Distribution(const std::vector<T> histogram) { 189 // template<typename T> int Distribution(const std::vector<T> histogram) {
157 190
158 private: 191 private:
159 uint32_t a_; 192 uint32_t a_;
160 uint32_t b_; 193 uint32_t b_;
161 194
162 DISALLOW_IMPLICIT_CONSTRUCTORS(Random); 195 DISALLOW_IMPLICIT_CONSTRUCTORS(Random);
163 }; 196 };
164 197
(...skipping 26 matching lines...) Expand all
191 // internal data. 224 // internal data.
192 virtual void Plot(int64_t timestamp_ms) {} 225 virtual void Plot(int64_t timestamp_ms) {}
193 226
194 // Run simulation for |time_ms| milliseconds, consuming packets from, and 227 // Run simulation for |time_ms| milliseconds, consuming packets from, and
195 // producing packets into in_out. The outgoing packet list must be sorted on 228 // 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. 229 // |send_time_us_|. The simulation time |time_ms| is optional to use.
197 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0; 230 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0;
198 231
199 const FlowIds& flow_ids() const { return flow_ids_; } 232 const FlowIds& flow_ids() const { return flow_ids_; }
200 233
234 uint32_t packets_per_second() const;
235 uint32_t bits_per_second() const;
236
237 protected:
238 RateCounter rate_counter_;
239
201 private: 240 private:
202 PacketProcessorListener* listener_; 241 PacketProcessorListener* listener_;
203 const FlowIds flow_ids_; 242 const FlowIds flow_ids_;
204 243
205 DISALLOW_COPY_AND_ASSIGN(PacketProcessor); 244 DISALLOW_COPY_AND_ASSIGN(PacketProcessor);
206 }; 245 };
207 246
208 class RateCounterFilter : public PacketProcessor { 247 class RateCounterFilter : public PacketProcessor {
209 public: 248 public:
210 RateCounterFilter(PacketProcessorListener* listener, 249 RateCounterFilter(PacketProcessorListener* listener,
211 int flow_id, 250 int flow_id,
212 const char* name); 251 const char* name);
213 RateCounterFilter(PacketProcessorListener* listener, 252 RateCounterFilter(PacketProcessorListener* listener,
214 const FlowIds& flow_ids, 253 const FlowIds& flow_ids,
215 const char* name); 254 const char* name);
255 RateCounterFilter(PacketProcessorListener* listener,
256 const FlowIds& flow_ids,
257 const char* name,
258 int64_t start_plotting_time_ms);
216 virtual ~RateCounterFilter(); 259 virtual ~RateCounterFilter();
217 260
218 uint32_t packets_per_second() const;
219 uint32_t bits_per_second() const;
220
221 void LogStats(); 261 void LogStats();
222 Stats<double> GetBitrateStats() const; 262 Stats<double> GetBitrateStats() const;
223 virtual void Plot(int64_t timestamp_ms); 263 virtual void Plot(int64_t timestamp_ms);
224 virtual void RunFor(int64_t time_ms, Packets* in_out); 264 virtual void RunFor(int64_t time_ms, Packets* in_out);
225 265
226 private: 266 private:
227 rtc::scoped_ptr<RateCounter> rate_counter_;
228 Stats<double> packets_per_second_stats_; 267 Stats<double> packets_per_second_stats_;
229 Stats<double> kbps_stats_; 268 Stats<double> kbps_stats_;
230 std::string name_; 269 std::string name_;
270 int64_t start_plotting_time_ms_;
231 271
232 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter); 272 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter);
233 }; 273 };
234 274
235 class LossFilter : public PacketProcessor { 275 class LossFilter : public PacketProcessor {
236 public: 276 public:
237 LossFilter(PacketProcessorListener* listener, int flow_id); 277 LossFilter(PacketProcessorListener* listener, int flow_id);
238 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 278 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
239 virtual ~LossFilter() {} 279 virtual ~LossFilter() {}
240 280
241 void SetLoss(float loss_percent); 281 void SetLoss(float loss_percent);
242 virtual void RunFor(int64_t time_ms, Packets* in_out); 282 virtual void RunFor(int64_t time_ms, Packets* in_out);
243 283
244 private: 284 private:
245 Random random_; 285 Random random_;
246 float loss_fraction_; 286 float loss_fraction_;
247 287
248 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter); 288 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter);
249 }; 289 };
250 290
251 class DelayFilter : public PacketProcessor { 291 class DelayFilter : public PacketProcessor {
252 public: 292 public:
253 DelayFilter(PacketProcessorListener* listener, int flow_id); 293 DelayFilter(PacketProcessorListener* listener, int flow_id);
254 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 294 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
255 virtual ~DelayFilter() {} 295 virtual ~DelayFilter() {}
256 296
257 void SetDelayMs(int64_t delay_ms); 297 void SetOneWayDelayMs(int64_t one_way_delay_ms);
258 virtual void RunFor(int64_t time_ms, Packets* in_out); 298 virtual void RunFor(int64_t time_ms, Packets* in_out);
259 299
260 private: 300 private:
261 int64_t delay_us_; 301 int64_t one_way_delay_us_;
262 int64_t last_send_time_us_; 302 int64_t last_send_time_us_;
263 303
264 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter); 304 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter);
265 }; 305 };
266 306
267 class JitterFilter : public PacketProcessor { 307 class JitterFilter : public PacketProcessor {
268 public: 308 public:
269 JitterFilter(PacketProcessorListener* listener, int flow_id); 309 JitterFilter(PacketProcessorListener* listener, int flow_id);
270 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 310 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
271 virtual ~JitterFilter() {} 311 virtual ~JitterFilter() {}
(...skipping 26 matching lines...) Expand all
298 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter); 338 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter);
299 }; 339 };
300 340
301 // Apply a bitrate choke with an infinite queue on the packet stream. 341 // Apply a bitrate choke with an infinite queue on the packet stream.
302 class ChokeFilter : public PacketProcessor { 342 class ChokeFilter : public PacketProcessor {
303 public: 343 public:
304 ChokeFilter(PacketProcessorListener* listener, int flow_id); 344 ChokeFilter(PacketProcessorListener* listener, int flow_id);
305 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 345 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
306 virtual ~ChokeFilter(); 346 virtual ~ChokeFilter();
307 347
308 void SetCapacity(uint32_t kbps); 348 void set_capacity_kbps(uint32_t kbps);
309 void SetMaxDelay(int max_delay_ms); 349 void SetMaxDelayMs(int64_t max_queueing_delay_ms);
350
351 uint32_t capacity_kbps();
352
310 virtual void RunFor(int64_t time_ms, Packets* in_out); 353 virtual void RunFor(int64_t time_ms, Packets* in_out);
311 354
312 Stats<double> GetDelayStats() const; 355 Stats<double> GetDelayStats() const;
313 356
314 private: 357 private:
315 uint32_t kbps_; 358 uint32_t capacity_kbps_;
316 int64_t last_send_time_us_; 359 int64_t last_send_time_us_;
317 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_; 360 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_;
361 int64_t max_delay_us_;
318 362
319 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter); 363 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter);
320 }; 364 };
321 365
322 class TraceBasedDeliveryFilter : public PacketProcessor { 366 class TraceBasedDeliveryFilter : public PacketProcessor {
323 public: 367 public:
324 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id); 368 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id);
325 TraceBasedDeliveryFilter(PacketProcessorListener* listener, 369 TraceBasedDeliveryFilter(PacketProcessorListener* listener,
326 const FlowIds& flow_ids); 370 const FlowIds& flow_ids);
327 TraceBasedDeliveryFilter(PacketProcessorListener* listener, 371 TraceBasedDeliveryFilter(PacketProcessorListener* listener,
328 int flow_id, 372 int flow_id,
329 const char* name); 373 const char* name);
330 virtual ~TraceBasedDeliveryFilter(); 374 virtual ~TraceBasedDeliveryFilter();
331 375
332 // The file should contain nanosecond timestamps corresponding to the time 376 // The file should contain nanosecond timestamps corresponding to the time
333 // when the network can accept another packet. The timestamps should be 377 // when the network can accept another packet. The timestamps should be
334 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..." 378 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..."
335 bool Init(const std::string& filename); 379 bool Init(const std::string& filename);
336 virtual void Plot(int64_t timestamp_ms); 380 virtual void Plot(int64_t timestamp_ms);
337 virtual void RunFor(int64_t time_ms, Packets* in_out); 381 virtual void RunFor(int64_t time_ms, Packets* in_out);
338 382
339 void SetMaxDelay(int max_delay_ms); 383 void SetMaxDelayMs(int64_t max_delay_ms);
340 Stats<double> GetDelayStats() const; 384 Stats<double> GetDelayStats() const;
341 Stats<double> GetBitrateStats() const; 385 Stats<double> GetBitrateStats() const;
342 386
343 private: 387 private:
344 void ProceedToNextSlot(); 388 void ProceedToNextSlot();
345 389
346 typedef std::vector<int64_t> TimeList; 390 typedef std::vector<int64_t> TimeList;
347 int64_t current_offset_us_; 391 int64_t current_offset_us_;
348 TimeList delivery_times_us_; 392 TimeList delivery_times_us_;
349 TimeList::const_iterator next_delivery_it_; 393 TimeList::const_iterator next_delivery_it_;
(...skipping 16 matching lines...) Expand all
366 int64_t first_frame_offset_ms); 410 int64_t first_frame_offset_ms);
367 virtual ~VideoSource() {} 411 virtual ~VideoSource() {}
368 412
369 virtual void RunFor(int64_t time_ms, Packets* in_out); 413 virtual void RunFor(int64_t time_ms, Packets* in_out);
370 414
371 virtual int flow_id() const { return flow_id_; } 415 virtual int flow_id() const { return flow_id_; }
372 virtual void SetBitrateBps(int bitrate_bps) {} 416 virtual void SetBitrateBps(int bitrate_bps) {}
373 uint32_t bits_per_second() const { return bits_per_second_; } 417 uint32_t bits_per_second() const { return bits_per_second_; }
374 uint32_t max_payload_size_bytes() const { return kMaxPayloadSizeBytes; } 418 uint32_t max_payload_size_bytes() const { return kMaxPayloadSizeBytes; }
375 int64_t GetTimeUntilNextFrameMs() const { return next_frame_ms_ - now_ms_; } 419 int64_t GetTimeUntilNextFrameMs() const { return next_frame_ms_ - now_ms_; }
420 virtual void Pause();
421 virtual void Resume();
376 422
377 protected: 423 protected:
378 virtual uint32_t NextFrameSize(); 424 virtual uint32_t NextFrameSize();
379 virtual uint32_t NextPacketSize(uint32_t frame_size, 425 virtual uint32_t NextPacketSize(uint32_t frame_size,
380 uint32_t remaining_payload); 426 uint32_t remaining_payload);
381 427
382 const uint32_t kMaxPayloadSizeBytes; 428 const uint32_t kMaxPayloadSizeBytes;
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_;
433 bool running_;
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_;
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698