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