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

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: Addressing trybot failures 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
(...skipping 21 matching lines...) Expand all
32 #include "webrtc/system_wrappers/interface/clock.h" 32 #include "webrtc/system_wrappers/interface/clock.h"
33 33
34 namespace webrtc { 34 namespace webrtc {
35 35
36 class RtcpBandwidthObserver; 36 class RtcpBandwidthObserver;
37 37
38 namespace testing { 38 namespace testing {
39 namespace bwe { 39 namespace bwe {
40 40
41 class DelayCapHelper; 41 class DelayCapHelper;
42 class RateCounter; 42
43 class RateCounter {
44 public:
45 RateCounter()
46 : kWindowSizeUs(1000 * 1000),
47 packets_per_second_(0),
48 bytes_per_second_(0),
49 last_accumulated_us_(0),
50 window_() {}
51
52 void UpdateRates(int64_t send_time_us, uint32_t payload_size);
53 uint32_t bits_per_second() const { return bytes_per_second_ * 8; }
54
55 uint32_t packets_per_second() const { return packets_per_second_; }
56
57 private:
58 typedef std::pair<int64_t, uint32_t> TimeSizePair;
59
60 const int64_t kWindowSizeUs;
61 uint32_t packets_per_second_;
62 uint32_t bytes_per_second_;
63 int64_t last_accumulated_us_;
64 std::list<TimeSizePair> window_;
65 };
43 66
44 typedef std::set<int> FlowIds; 67 typedef std::set<int> FlowIds;
45 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids); 68 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids);
69 const FlowIds CreateFlowIdRange(int initial_value, int last_value);
46 70
47 template <typename T> 71 template <typename T>
48 bool DereferencingComparator(const T* const& a, const T* const& b) { 72 bool DereferencingComparator(const T* const& a, const T* const& b) {
49 assert(a != NULL); 73 assert(a != NULL);
50 assert(b != NULL); 74 assert(b != NULL);
51 return *a < *b; 75 return *a < *b;
52 } 76 }
53 77
54 template<typename T> class Stats { 78 template<typename T> class Stats {
55 public: 79 public:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 T max_; 166 T max_;
143 }; 167 };
144 168
145 class Random { 169 class Random {
146 public: 170 public:
147 explicit Random(uint32_t seed); 171 explicit Random(uint32_t seed);
148 172
149 // Return pseudo random number in the interval [0.0, 1.0]. 173 // Return pseudo random number in the interval [0.0, 1.0].
150 float Rand(); 174 float Rand();
151 175
176 // Return pseudo rounded random number in interval [low, high].
177 int Rand(int low, int high);
178
152 // Normal Distribution. 179 // Normal Distribution.
153 int Gaussian(int mean, int standard_deviation); 180 int Gaussian(int mean, int standard_deviation);
154 181
182 // Exponential Distribution.
183 int Exponential(float lambda);
184
155 // TODO(solenberg): Random from histogram. 185 // TODO(solenberg): Random from histogram.
156 // template<typename T> int Distribution(const std::vector<T> histogram) { 186 // template<typename T> int Distribution(const std::vector<T> histogram) {
157 187
158 private: 188 private:
159 uint32_t a_; 189 uint32_t a_;
160 uint32_t b_; 190 uint32_t b_;
161 191
162 DISALLOW_IMPLICIT_CONSTRUCTORS(Random); 192 DISALLOW_IMPLICIT_CONSTRUCTORS(Random);
163 }; 193 };
164 194
(...skipping 21 matching lines...) Expand all
186 const FlowIds& flow_ids, 216 const FlowIds& flow_ids,
187 ProcessorType type); 217 ProcessorType type);
188 virtual ~PacketProcessor(); 218 virtual ~PacketProcessor();
189 219
190 // Called after each simulation batch to allow the processor to plot any 220 // Called after each simulation batch to allow the processor to plot any
191 // internal data. 221 // internal data.
192 virtual void Plot(int64_t timestamp_ms) {} 222 virtual void Plot(int64_t timestamp_ms) {}
193 223
194 // Run simulation for |time_ms| milliseconds, consuming packets from, and 224 // Run simulation for |time_ms| milliseconds, consuming packets from, and
195 // producing packets into in_out. The outgoing packet list must be sorted on 225 // 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. 226 // |send_time_us_|. The simu lation time |time_ms| is optional to use.
stefan-webrtc 2015/06/25 14:44:04 simulation
magalhaesc 2015/07/01 12:48:40 Done.
197 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0; 227 virtual void RunFor(int64_t time_ms, Packets* in_out) = 0;
198 228
199 const FlowIds& flow_ids() const { return flow_ids_; } 229 const FlowIds& flow_ids() const { return flow_ids_; }
200 230
231 uint32_t packets_per_second() const;
232 uint32_t bits_per_second() const;
233
234 protected:
235 rtc::scoped_ptr<RateCounter> rate_counter_;
236
201 private: 237 private:
202 PacketProcessorListener* listener_; 238 PacketProcessorListener* listener_;
203 const FlowIds flow_ids_; 239 const FlowIds flow_ids_;
204 240
205 DISALLOW_COPY_AND_ASSIGN(PacketProcessor); 241 DISALLOW_COPY_AND_ASSIGN(PacketProcessor);
206 }; 242 };
207 243
208 class RateCounterFilter : public PacketProcessor { 244 class RateCounterFilter : public PacketProcessor {
209 public: 245 public:
210 RateCounterFilter(PacketProcessorListener* listener, 246 RateCounterFilter(PacketProcessorListener* listener,
211 int flow_id, 247 int flow_id,
212 const char* name); 248 const char* name);
213 RateCounterFilter(PacketProcessorListener* listener, 249 RateCounterFilter(PacketProcessorListener* listener,
214 const FlowIds& flow_ids, 250 const FlowIds& flow_ids,
215 const char* name); 251 const char* name);
252 RateCounterFilter(PacketProcessorListener* listener,
253 const FlowIds& flow_ids,
254 const char* name,
255 int64_t start_plotting_ms);
stefan-webrtc 2015/06/25 14:44:04 start_plotting_time_ms_
magalhaesc 2015/07/01 12:48:40 Done.
216 virtual ~RateCounterFilter(); 256 virtual ~RateCounterFilter();
217 257
218 uint32_t packets_per_second() const;
219 uint32_t bits_per_second() const;
220
221 void LogStats(); 258 void LogStats();
222 Stats<double> GetBitrateStats() const; 259 Stats<double> GetBitrateStats() const;
223 virtual void Plot(int64_t timestamp_ms); 260 virtual void Plot(int64_t timestamp_ms);
224 virtual void RunFor(int64_t time_ms, Packets* in_out); 261 virtual void RunFor(int64_t time_ms, Packets* in_out);
225 262
226 private: 263 private:
227 rtc::scoped_ptr<RateCounter> rate_counter_;
228 Stats<double> packets_per_second_stats_; 264 Stats<double> packets_per_second_stats_;
229 Stats<double> kbps_stats_; 265 Stats<double> kbps_stats_;
230 std::string name_; 266 std::string name_;
267 int64_t start_plotting_ms_;
231 268
232 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter); 269 DISALLOW_IMPLICIT_CONSTRUCTORS(RateCounterFilter);
233 }; 270 };
234 271
235 class LossFilter : public PacketProcessor { 272 class LossFilter : public PacketProcessor {
236 public: 273 public:
237 LossFilter(PacketProcessorListener* listener, int flow_id); 274 LossFilter(PacketProcessorListener* listener, int flow_id);
238 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 275 LossFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
239 virtual ~LossFilter() {} 276 virtual ~LossFilter() {}
240 277
241 void SetLoss(float loss_percent); 278 void SetLoss(float loss_percent);
242 virtual void RunFor(int64_t time_ms, Packets* in_out); 279 virtual void RunFor(int64_t time_ms, Packets* in_out);
243 280
244 private: 281 private:
245 Random random_; 282 Random random_;
246 float loss_fraction_; 283 float loss_fraction_;
247 284
248 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter); 285 DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter);
249 }; 286 };
250 287
251 class DelayFilter : public PacketProcessor { 288 class DelayFilter : public PacketProcessor {
252 public: 289 public:
253 DelayFilter(PacketProcessorListener* listener, int flow_id); 290 DelayFilter(PacketProcessorListener* listener, int flow_id);
254 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 291 DelayFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
255 virtual ~DelayFilter() {} 292 virtual ~DelayFilter() {}
256 293
257 void SetDelayMs(int64_t delay_ms); 294 void SetOneWayDelayMs(int64_t one_way_delay_ms);
258 virtual void RunFor(int64_t time_ms, Packets* in_out); 295 virtual void RunFor(int64_t time_ms, Packets* in_out);
259 296
260 private: 297 private:
261 int64_t delay_us_; 298 int64_t one_way_delay_us_;
262 int64_t last_send_time_us_; 299 int64_t last_send_time_us_;
263 300
264 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter); 301 DISALLOW_IMPLICIT_CONSTRUCTORS(DelayFilter);
265 }; 302 };
266 303
267 class JitterFilter : public PacketProcessor { 304 class JitterFilter : public PacketProcessor {
268 public: 305 public:
269 JitterFilter(PacketProcessorListener* listener, int flow_id); 306 JitterFilter(PacketProcessorListener* listener, int flow_id);
270 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 307 JitterFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
271 virtual ~JitterFilter() {} 308 virtual ~JitterFilter() {}
(...skipping 26 matching lines...) Expand all
298 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter); 335 DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter);
299 }; 336 };
300 337
301 // Apply a bitrate choke with an infinite queue on the packet stream. 338 // Apply a bitrate choke with an infinite queue on the packet stream.
302 class ChokeFilter : public PacketProcessor { 339 class ChokeFilter : public PacketProcessor {
303 public: 340 public:
304 ChokeFilter(PacketProcessorListener* listener, int flow_id); 341 ChokeFilter(PacketProcessorListener* listener, int flow_id);
305 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); 342 ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids);
306 virtual ~ChokeFilter(); 343 virtual ~ChokeFilter();
307 344
308 void SetCapacity(uint32_t kbps); 345 void SetCapacityKbps(uint32_t kbps);
309 void SetMaxDelay(int max_delay_ms); 346 void SetMaxDelayMs(int64_t max_queueing_delay_ms);
347 void PauseFlow(int flow_id); // Increases available capacity per flow.
348 void ResumeFlow(int flow_id); // Decreases available capacity per flow.
stefan-webrtc 2015/06/25 14:44:04 I don't understand what this does. If this is abou
magalhaesc 2015/07/01 12:48:40 Yes, it's done on the Source. It is also done here
349
310 virtual void RunFor(int64_t time_ms, Packets* in_out); 350 virtual void RunFor(int64_t time_ms, Packets* in_out);
311 351
312 Stats<double> GetDelayStats() const; 352 Stats<double> GetDelayStats() const;
313 353
314 private: 354 private:
315 uint32_t kbps_; 355 uint32_t available_capacity_kbps_;
316 int64_t last_send_time_us_; 356 int64_t last_send_time_us_;
317 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_; 357 rtc::scoped_ptr<DelayCapHelper> delay_cap_helper_;
358 int64_t max_delay_us_;
359 std::set<int> running_flows_;
318 360
319 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter); 361 DISALLOW_IMPLICIT_CONSTRUCTORS(ChokeFilter);
320 }; 362 };
321 363
322 class TraceBasedDeliveryFilter : public PacketProcessor { 364 class TraceBasedDeliveryFilter : public PacketProcessor {
323 public: 365 public:
324 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id); 366 TraceBasedDeliveryFilter(PacketProcessorListener* listener, int flow_id);
325 TraceBasedDeliveryFilter(PacketProcessorListener* listener, 367 TraceBasedDeliveryFilter(PacketProcessorListener* listener,
326 const FlowIds& flow_ids); 368 const FlowIds& flow_ids);
327 TraceBasedDeliveryFilter(PacketProcessorListener* listener, 369 TraceBasedDeliveryFilter(PacketProcessorListener* listener,
328 int flow_id, 370 int flow_id,
329 const char* name); 371 const char* name);
330 virtual ~TraceBasedDeliveryFilter(); 372 virtual ~TraceBasedDeliveryFilter();
331 373
332 // The file should contain nanosecond timestamps corresponding to the time 374 // The file should contain nanosecond timestamps corresponding to the time
333 // when the network can accept another packet. The timestamps should be 375 // when the network can accept another packet. The timestamps should be
334 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..." 376 // separated by new lines, e.g., "100000000\n125000000\n321000000\n..."
335 bool Init(const std::string& filename); 377 bool Init(const std::string& filename);
336 virtual void Plot(int64_t timestamp_ms); 378 virtual void Plot(int64_t timestamp_ms);
337 virtual void RunFor(int64_t time_ms, Packets* in_out); 379 virtual void RunFor(int64_t time_ms, Packets* in_out);
338 380
339 void SetMaxDelay(int max_delay_ms); 381 void SetMaxDelayMs(int64_t max_delay_ms);
340 Stats<double> GetDelayStats() const; 382 Stats<double> GetDelayStats() const;
341 Stats<double> GetBitrateStats() const; 383 Stats<double> GetBitrateStats() const;
342 384
343 private: 385 private:
344 void ProceedToNextSlot(); 386 void ProceedToNextSlot();
345 387
346 typedef std::vector<int64_t> TimeList; 388 typedef std::vector<int64_t> TimeList;
347 int64_t current_offset_us_; 389 int64_t current_offset_us_;
348 TimeList delivery_times_us_; 390 TimeList delivery_times_us_;
349 TimeList::const_iterator next_delivery_it_; 391 TimeList::const_iterator next_delivery_it_;
(...skipping 16 matching lines...) Expand all
366 int64_t first_frame_offset_ms); 408 int64_t first_frame_offset_ms);
367 virtual ~VideoSource() {} 409 virtual ~VideoSource() {}
368 410
369 virtual void RunFor(int64_t time_ms, Packets* in_out); 411 virtual void RunFor(int64_t time_ms, Packets* in_out);
370 412
371 virtual int flow_id() const { return flow_id_; } 413 virtual int flow_id() const { return flow_id_; }
372 virtual void SetBitrateBps(int bitrate_bps) {} 414 virtual void SetBitrateBps(int bitrate_bps) {}
373 uint32_t bits_per_second() const { return bits_per_second_; } 415 uint32_t bits_per_second() const { return bits_per_second_; }
374 uint32_t max_payload_size_bytes() const { return kMaxPayloadSizeBytes; } 416 uint32_t max_payload_size_bytes() const { return kMaxPayloadSizeBytes; }
375 int64_t GetTimeUntilNextFrameMs() const { return next_frame_ms_ - now_ms_; } 417 int64_t GetTimeUntilNextFrameMs() const { return next_frame_ms_ - now_ms_; }
418 virtual void Pause();
419 virtual void Resume();
420
421 void set_alg_name(const std::string& alg_name) { alg_name_ = alg_name; }
422 void set_plot_sending_estimate(bool plot) { plot_sending_estimate_ = plot; }
376 423
377 protected: 424 protected:
378 virtual uint32_t NextFrameSize(); 425 virtual uint32_t NextFrameSize();
379 virtual uint32_t NextPacketSize(uint32_t frame_size, 426 virtual uint32_t NextPacketSize(uint32_t frame_size,
380 uint32_t remaining_payload); 427 uint32_t remaining_payload);
381 428
382 const uint32_t kMaxPayloadSizeBytes; 429 const uint32_t kMaxPayloadSizeBytes;
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_;
434 bool running_;
387 435
388 private: 436 private:
389 const int flow_id_; 437 const int flow_id_;
390 int64_t next_frame_ms_; 438 int64_t next_frame_ms_;
391 int64_t now_ms_; 439 int64_t now_ms_;
392 RTPHeader prototype_header_; 440 RTPHeader prototype_header_;
441 int64_t start_plotting_ms_;
442 std::string alg_name_;
stefan-webrtc 2015/06/25 14:44:04 It feels odd that we have to know about an algorit
magalhaesc 2015/07/01 12:48:40 I agree, done.
443 bool plot_sending_estimate_; // False by default.
393 444
394 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoSource); 445 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoSource);
395 }; 446 };
396 447
397 class AdaptiveVideoSource : public VideoSource { 448 class AdaptiveVideoSource : public VideoSource {
398 public: 449 public:
399 AdaptiveVideoSource(int flow_id, 450 AdaptiveVideoSource(int flow_id,
400 float fps, 451 float fps,
401 uint32_t kbps, 452 uint32_t kbps,
402 uint32_t ssrc, 453 uint32_t ssrc,
(...skipping 26 matching lines...) Expand all
429 uint32_t frame_counter_; 480 uint32_t frame_counter_;
430 int compensation_bytes_; 481 int compensation_bytes_;
431 int compensation_per_frame_; 482 int compensation_per_frame_;
432 DISALLOW_IMPLICIT_CONSTRUCTORS(PeriodicKeyFrameSource); 483 DISALLOW_IMPLICIT_CONSTRUCTORS(PeriodicKeyFrameSource);
433 }; 484 };
434 } // namespace bwe 485 } // namespace bwe
435 } // namespace testing 486 } // namespace testing
436 } // namespace webrtc 487 } // namespace webrtc
437 488
438 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_ 489 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_FRAMEWORK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698