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