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