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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc

Issue 1202253003: More Simulation Framework features (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed [4] 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 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h"
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 #include <sstream> 15 #include <sstream>
16 #include <iostream>
16 17
17 namespace webrtc { 18 namespace webrtc {
18 namespace testing { 19 namespace testing {
19 namespace bwe { 20 namespace bwe {
20 21
21 class DelayCapHelper { 22 class DelayCapHelper {
22 public: 23 public:
24 // Max delay = 0 stands for +infinite.
23 DelayCapHelper() : max_delay_us_(0), delay_stats_() {} 25 DelayCapHelper() : max_delay_us_(0), delay_stats_() {}
24 26
25 void SetMaxDelay(int max_delay_ms) { 27 void set_max_delay_ms(int64_t max_delay_ms) {
26 BWE_TEST_LOGGING_ENABLE(false); 28 BWE_TEST_LOGGING_ENABLE(false);
27 BWE_TEST_LOGGING_LOG1("Max Delay", "%d ms", static_cast<int>(max_delay_ms)); 29 BWE_TEST_LOGGING_LOG1("Max Delay", "%d ms", static_cast<int>(max_delay_ms));
28 assert(max_delay_ms >= 0); 30 assert(max_delay_ms >= 0);
29 max_delay_us_ = max_delay_ms * 1000; 31 max_delay_us_ = max_delay_ms * 1000;
30 } 32 }
31 33
32 bool ShouldSendPacket(int64_t send_time_us, int64_t arrival_time_us) { 34 bool ShouldSendPacket(int64_t send_time_us, int64_t arrival_time_us) {
33 int64_t packet_delay_us = send_time_us - arrival_time_us; 35 int64_t packet_delay_us = send_time_us - arrival_time_us;
34 delay_stats_.Push(std::min(packet_delay_us, max_delay_us_) / 1000); 36 delay_stats_.Push(std::min(packet_delay_us, max_delay_us_) / 1000);
35 return (max_delay_us_ == 0 || max_delay_us_ >= packet_delay_us); 37 return (max_delay_us_ == 0 || max_delay_us_ >= packet_delay_us);
36 } 38 }
37 39
38 const Stats<double>& delay_stats() const { 40 const Stats<double>& delay_stats() const {
39 return delay_stats_; 41 return delay_stats_;
40 } 42 }
41 43
42 private: 44 private:
43 int64_t max_delay_us_; 45 int64_t max_delay_us_;
44 Stats<double> delay_stats_; 46 Stats<double> delay_stats_;
45 47
46 DISALLOW_COPY_AND_ASSIGN(DelayCapHelper); 48 DISALLOW_COPY_AND_ASSIGN(DelayCapHelper);
47 }; 49 };
48 50
49 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids) { 51 const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids) {
50 FlowIds flow_ids(&flow_ids_array[0], flow_ids_array + num_flow_ids); 52 FlowIds flow_ids(&flow_ids_array[0], flow_ids_array + num_flow_ids);
51 return flow_ids; 53 return flow_ids;
52 } 54 }
53 55
54 class RateCounter { 56 const FlowIds CreateFlowIdRange(int initial_value, int last_value) {
55 public: 57 int size = last_value - initial_value + 1;
56 RateCounter() 58 assert(size > 0);
57 : kWindowSizeUs(1000000), 59 int* flow_ids_array = new int[size];
58 packets_per_second_(0), 60 for (int i = initial_value; i <= last_value; ++i) {
59 bytes_per_second_(0), 61 flow_ids_array[i - initial_value] = i;
60 last_accumulated_us_(0), 62 }
61 window_() {} 63 return CreateFlowIds(flow_ids_array, size);
64 }
62 65
63 void UpdateRates(int64_t send_time_us, uint32_t payload_size) { 66 void RateCounter::UpdateRates(int64_t send_time_us, uint32_t payload_size) {
64 packets_per_second_++; 67 recently_received_packets_++;
65 bytes_per_second_ += payload_size; 68 recently_received_bytes_ += payload_size;
66 last_accumulated_us_ = send_time_us; 69 last_accumulated_us_ = send_time_us;
67 window_.push_back(std::make_pair(send_time_us, payload_size)); 70 window_.push_back(std::make_pair(send_time_us, payload_size));
68 while (!window_.empty()) { 71 while (!window_.empty()) {
69 const TimeSizePair& packet = window_.front(); 72 const TimeSizePair& packet = window_.front();
70 if (packet.first > (last_accumulated_us_ - kWindowSizeUs)) { 73 if (packet.first > (last_accumulated_us_ - window_size_us_)) {
71 break; 74 break;
72 }
73 assert(packets_per_second_ >= 1);
74 assert(bytes_per_second_ >= packet.second);
75 packets_per_second_--;
76 bytes_per_second_ -= packet.second;
77 window_.pop_front();
78 } 75 }
76 assert(recently_received_packets_ >= 1);
77 assert(recently_received_bytes_ >= packet.second);
78 recently_received_packets_--;
79 recently_received_bytes_ -= packet.second;
80 window_.pop_front();
79 } 81 }
82 }
80 83
81 uint32_t bits_per_second() const { 84 uint32_t RateCounter::bits_per_second() const {
82 return bytes_per_second_ * 8; 85 return (8 * recently_received_bytes_) / window_size_s();
83 } 86 }
84 87
85 uint32_t packets_per_second() const { return packets_per_second_; } 88 uint32_t RateCounter::packets_per_second() const {
89 return recently_received_packets_ / window_size_s();
90 }
86 91
87 private: 92 double RateCounter::window_size_s() const {
88 typedef std::pair<int64_t, uint32_t> TimeSizePair; 93 return static_cast<double>(window_size_us_) / (1000 * 1000);
89 94 }
90 const int64_t kWindowSizeUs;
91 uint32_t packets_per_second_;
92 uint32_t bytes_per_second_;
93 int64_t last_accumulated_us_;
94 std::list<TimeSizePair> window_;
95 };
96 95
97 Random::Random(uint32_t seed) 96 Random::Random(uint32_t seed)
98 : a_(0x531FDB97 ^ seed), 97 : a_(0x531FDB97 ^ seed),
99 b_(0x6420ECA8 + seed) { 98 b_(0x6420ECA8 + seed) {
100 } 99 }
101 100
102 float Random::Rand() { 101 float Random::Rand() {
103 const float kScale = 1.0f / 0xffffffff; 102 const float kScale = 1.0f / 0xffffffff;
104 float result = kScale * b_; 103 float result = kScale * b_;
105 a_ ^= b_; 104 a_ ^= b_;
106 b_ += a_; 105 b_ += a_;
107 return result; 106 return result;
108 } 107 }
109 108
109 int Random::Rand(int low, int high) {
110 float uniform = Rand() * (high - low + 1) + low;
111 return static_cast<int>(uniform);
112 }
113
110 int Random::Gaussian(int mean, int standard_deviation) { 114 int Random::Gaussian(int mean, int standard_deviation) {
111 // Creating a Normal distribution variable from two independent uniform 115 // Creating a Normal distribution variable from two independent uniform
112 // variables based on the Box-Muller transform, which is defined on the 116 // variables based on the Box-Muller transform, which is defined on the
113 // interval (0, 1], hence the mask+add below. 117 // interval (0, 1], hence the mask+add below.
114 const double kPi = 3.14159265358979323846; 118 const double kPi = 3.14159265358979323846;
115 const double kScale = 1.0 / 0x80000000ul; 119 const double kScale = 1.0 / 0x80000000ul;
116 double u1 = kScale * ((a_ & 0x7ffffffful) + 1); 120 double u1 = kScale * ((a_ & 0x7ffffffful) + 1);
117 double u2 = kScale * ((b_ & 0x7ffffffful) + 1); 121 double u2 = kScale * ((b_ & 0x7ffffffful) + 1);
118 a_ ^= b_; 122 a_ ^= b_;
119 b_ += a_; 123 b_ += a_;
120 return static_cast<int>(mean + standard_deviation * 124 return static_cast<int>(mean + standard_deviation *
121 sqrt(-2 * log(u1)) * cos(2 * kPi * u2)); 125 sqrt(-2 * log(u1)) * cos(2 * kPi * u2));
122 } 126 }
123 127
128 int Random::Exponential(float lambda) {
129 float uniform = Rand();
130 return static_cast<int>(-log(uniform) / lambda);
131 }
132
124 Packet::Packet() 133 Packet::Packet()
125 : flow_id_(0), creation_time_us_(-1), send_time_us_(-1), payload_size_(0) { 134 : flow_id_(0), creation_time_us_(-1), send_time_us_(-1), payload_size_(0) {
126 } 135 }
127 136
128 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size) 137 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size)
129 : flow_id_(flow_id), 138 : flow_id_(flow_id),
130 creation_time_us_(send_time_us), 139 creation_time_us_(send_time_us),
131 send_time_us_(send_time_us), 140 send_time_us_(send_time_us),
132 payload_size_(payload_size) { 141 payload_size_(payload_size) {
133 } 142 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 listener_->AddPacketProcessor(this, type); 232 listener_->AddPacketProcessor(this, type);
224 } 233 }
225 } 234 }
226 235
227 PacketProcessor::~PacketProcessor() { 236 PacketProcessor::~PacketProcessor() {
228 if (listener_) { 237 if (listener_) {
229 listener_->RemovePacketProcessor(this); 238 listener_->RemovePacketProcessor(this);
230 } 239 }
231 } 240 }
232 241
242 uint32_t PacketProcessor::packets_per_second() const {
243 return rate_counter_.packets_per_second();
244 }
245
246 uint32_t PacketProcessor::bits_per_second() const {
247 return rate_counter_.bits_per_second();
248 }
249
233 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 250 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
234 int flow_id, 251 int flow_id,
235 const char* name) 252 const char* name)
236 : PacketProcessor(listener, flow_id, kRegular), 253 : PacketProcessor(listener, flow_id, kRegular),
237 rate_counter_(new RateCounter()),
238 packets_per_second_stats_(), 254 packets_per_second_stats_(),
239 kbps_stats_(), 255 kbps_stats_(),
240 name_() { 256 name_(),
257 start_plotting_time_ms_(0) {
241 std::stringstream ss; 258 std::stringstream ss;
242 ss << name << "_" << flow_id; 259 ss << name << "_" << flow_id;
243 name_ = ss.str(); 260 name_ = ss.str();
244 } 261 }
245 262
246 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 263 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
247 const FlowIds& flow_ids, 264 const FlowIds& flow_ids,
248 const char* name) 265 const char* name)
249 : PacketProcessor(listener, flow_ids, kRegular), 266 : PacketProcessor(listener, flow_ids, kRegular),
250 rate_counter_(new RateCounter()),
251 packets_per_second_stats_(), 267 packets_per_second_stats_(),
252 kbps_stats_(), 268 kbps_stats_(),
253 name_() { 269 name_(),
270 start_plotting_time_ms_(0) {
254 std::stringstream ss; 271 std::stringstream ss;
255 ss << name << "_"; 272 ss << name << "_";
256 for (int flow_id : flow_ids) { 273 for (int flow_id : flow_ids) {
257 ss << flow_id << ","; 274 ss << flow_id << ",";
258 } 275 }
259 name_ = ss.str(); 276 name_ = ss.str();
260 } 277 }
261 278
279 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
280 const FlowIds& flow_ids,
281 const char* name,
282 int64_t start_plotting_time_ms)
283 : RateCounterFilter(listener, flow_ids, name) {
284 start_plotting_time_ms_ = start_plotting_time_ms;
285 }
286
262 RateCounterFilter::~RateCounterFilter() { 287 RateCounterFilter::~RateCounterFilter() {
263 LogStats(); 288 LogStats();
264 } 289 }
265 290
266 uint32_t RateCounterFilter::packets_per_second() const {
267 return rate_counter_->packets_per_second();
268 }
269
270 uint32_t RateCounterFilter::bits_per_second() const {
271 return rate_counter_->bits_per_second();
272 }
273 291
274 void RateCounterFilter::LogStats() { 292 void RateCounterFilter::LogStats() {
275 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); 293 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter");
276 packets_per_second_stats_.Log("pps"); 294 packets_per_second_stats_.Log("pps");
277 kbps_stats_.Log("kbps"); 295 kbps_stats_.Log("kbps");
278 } 296 }
279 297
280 Stats<double> RateCounterFilter::GetBitrateStats() const { 298 Stats<double> RateCounterFilter::GetBitrateStats() const {
281 return kbps_stats_; 299 return kbps_stats_;
282 } 300 }
283 301
284 void RateCounterFilter::Plot(int64_t timestamp_ms) { 302 void RateCounterFilter::Plot(int64_t timestamp_ms) {
303 uint32_t plot_kbps = 0;
304 if (timestamp_ms >= start_plotting_time_ms_) {
305 plot_kbps = rate_counter_.bits_per_second() / 1000.0;
306 }
285 BWE_TEST_LOGGING_CONTEXT(name_.c_str()); 307 BWE_TEST_LOGGING_CONTEXT(name_.c_str());
286 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, 308 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, plot_kbps);
287 rate_counter_->bits_per_second() / 1000.0); 309 RTC_UNUSED(plot_kbps);
288 } 310 }
289 311
290 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 312 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
291 assert(in_out); 313 assert(in_out);
292 for (const Packet* packet : *in_out) { 314 for (const Packet* packet : *in_out) {
293 rate_counter_->UpdateRates(packet->send_time_us(), 315 rate_counter_.UpdateRates(packet->send_time_us(),
294 static_cast<int>(packet->payload_size())); 316 static_cast<int>(packet->payload_size()));
295 } 317 }
296 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 318 packets_per_second_stats_.Push(rate_counter_.packets_per_second());
297 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 319 kbps_stats_.Push(rate_counter_.bits_per_second() / 1000.0);
298 } 320 }
299 321
300 LossFilter::LossFilter(PacketProcessorListener* listener, int flow_id) 322 LossFilter::LossFilter(PacketProcessorListener* listener, int flow_id)
301 : PacketProcessor(listener, flow_id, kRegular), 323 : PacketProcessor(listener, flow_id, kRegular),
302 random_(0x12345678), 324 random_(0x12345678),
303 loss_fraction_(0.0f) { 325 loss_fraction_(0.0f) {
304 } 326 }
305 327
306 LossFilter::LossFilter(PacketProcessorListener* listener, 328 LossFilter::LossFilter(PacketProcessorListener* listener,
307 const FlowIds& flow_ids) 329 const FlowIds& flow_ids)
(...skipping 15 matching lines...) Expand all
323 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 345 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
324 if (random_.Rand() < loss_fraction_) { 346 if (random_.Rand() < loss_fraction_) {
325 delete *it; 347 delete *it;
326 it = in_out->erase(it); 348 it = in_out->erase(it);
327 } else { 349 } else {
328 ++it; 350 ++it;
329 } 351 }
330 } 352 }
331 } 353 }
332 354
355 const int64_t kDefaultOneWayDelayUs = 0;
356
333 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id) 357 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id)
334 : PacketProcessor(listener, flow_id, kRegular), 358 : PacketProcessor(listener, flow_id, kRegular),
335 delay_us_(0), 359 one_way_delay_us_(kDefaultOneWayDelayUs),
336 last_send_time_us_(0) { 360 last_send_time_us_(0) {
337 } 361 }
338 362
339 DelayFilter::DelayFilter(PacketProcessorListener* listener, 363 DelayFilter::DelayFilter(PacketProcessorListener* listener,
340 const FlowIds& flow_ids) 364 const FlowIds& flow_ids)
341 : PacketProcessor(listener, flow_ids, kRegular), 365 : PacketProcessor(listener, flow_ids, kRegular),
342 delay_us_(0), 366 one_way_delay_us_(kDefaultOneWayDelayUs),
343 last_send_time_us_(0) { 367 last_send_time_us_(0) {
344 } 368 }
345 369
346 void DelayFilter::SetDelayMs(int64_t delay_ms) { 370 void DelayFilter::SetOneWayDelayMs(int64_t one_way_delay_ms) {
347 BWE_TEST_LOGGING_ENABLE(false); 371 BWE_TEST_LOGGING_ENABLE(false);
348 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(delay_ms)); 372 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(one_way_delay_ms));
349 assert(delay_ms >= 0); 373 assert(one_way_delay_ms >= 0);
350 delay_us_ = delay_ms * 1000; 374 one_way_delay_us_ = one_way_delay_ms * 1000;
351 } 375 }
352 376
353 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 377 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
354 assert(in_out); 378 assert(in_out);
355 for (Packet* packet : *in_out) { 379 for (Packet* packet : *in_out) {
356 int64_t new_send_time_us = packet->send_time_us() + delay_us_; 380 int64_t new_send_time_us = packet->send_time_us() + one_way_delay_us_;
357 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us); 381 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us);
358 packet->set_send_time_us(last_send_time_us_); 382 packet->set_send_time_us(last_send_time_us_);
359 } 383 }
360 } 384 }
361 385
362 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) 386 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id)
363 : PacketProcessor(listener, flow_id, kRegular), 387 : PacketProcessor(listener, flow_id, kRegular),
364 random_(0x89674523), 388 random_(0x89674523),
365 stddev_jitter_us_(0), 389 stddev_jitter_us_(0),
366 last_send_time_us_(0) { 390 last_send_time_us_(0) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 int64_t t2 = (*it)->send_time_us(); 448 int64_t t2 = (*it)->send_time_us();
425 std::swap(*last_it, *it); 449 std::swap(*last_it, *it);
426 (*last_it)->set_send_time_us(t1); 450 (*last_it)->set_send_time_us(t1);
427 (*it)->set_send_time_us(t2); 451 (*it)->set_send_time_us(t2);
428 } 452 }
429 last_it = it; 453 last_it = it;
430 } 454 }
431 } 455 }
432 } 456 }
433 457
458 const uint32_t kDefaultKbps = 1200;
459
434 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id) 460 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id)
435 : PacketProcessor(listener, flow_id, kRegular), 461 : PacketProcessor(listener, flow_id, kRegular),
436 kbps_(1200), 462 capacity_kbps_(kDefaultKbps),
437 last_send_time_us_(0), 463 last_send_time_us_(0),
438 delay_cap_helper_(new DelayCapHelper()) { 464 delay_cap_helper_(new DelayCapHelper()) {
439 } 465 }
440 466
441 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, 467 ChokeFilter::ChokeFilter(PacketProcessorListener* listener,
442 const FlowIds& flow_ids) 468 const FlowIds& flow_ids)
443 : PacketProcessor(listener, flow_ids, kRegular), 469 : PacketProcessor(listener, flow_ids, kRegular),
444 kbps_(1200), 470 capacity_kbps_(kDefaultKbps),
445 last_send_time_us_(0), 471 last_send_time_us_(0),
446 delay_cap_helper_(new DelayCapHelper()) { 472 delay_cap_helper_(new DelayCapHelper()) {
447 } 473 }
448 474
449 ChokeFilter::~ChokeFilter() {} 475 ChokeFilter::~ChokeFilter() {}
450 476
451 void ChokeFilter::SetCapacity(uint32_t kbps) { 477 void ChokeFilter::set_capacity_kbps(uint32_t kbps) {
452 BWE_TEST_LOGGING_ENABLE(false); 478 BWE_TEST_LOGGING_ENABLE(false);
453 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps); 479 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps);
454 kbps_ = kbps; 480 capacity_kbps_ = kbps;
481 }
482
483 uint32_t ChokeFilter::capacity_kbps() {
484 return capacity_kbps_;
455 } 485 }
456 486
457 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 487 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
458 assert(in_out); 488 assert(in_out);
459 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 489 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
460 int64_t earliest_send_time_us = 490 int64_t earliest_send_time_us =
461 last_send_time_us_ + 491 last_send_time_us_ +
462 ((*it)->payload_size() * 8 * 1000 + kbps_ / 2) / kbps_; 492 ((*it)->payload_size() * 8 * 1000 + capacity_kbps_ / 2) /
493 capacity_kbps_;
494
463 int64_t new_send_time_us = 495 int64_t new_send_time_us =
464 std::max((*it)->send_time_us(), earliest_send_time_us); 496 std::max((*it)->send_time_us(), earliest_send_time_us);
497
465 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us, 498 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us,
466 (*it)->send_time_us())) { 499 (*it)->send_time_us())) {
467 (*it)->set_send_time_us(new_send_time_us); 500 (*it)->set_send_time_us(new_send_time_us);
468 last_send_time_us_ = new_send_time_us; 501 last_send_time_us_ = new_send_time_us;
469 ++it; 502 ++it;
470 } else { 503 } else {
471 delete *it; 504 delete *it;
472 it = in_out->erase(it); 505 it = in_out->erase(it);
473 } 506 }
474 } 507 }
475 } 508 }
476 509
477 void ChokeFilter::SetMaxDelay(int max_delay_ms) { 510 void ChokeFilter::set_max_delay_ms(int64_t max_delay_ms) {
478 delay_cap_helper_->SetMaxDelay(max_delay_ms); 511 delay_cap_helper_->set_max_delay_ms(max_delay_ms);
479 } 512 }
480 513
481 Stats<double> ChokeFilter::GetDelayStats() const { 514 Stats<double> ChokeFilter::GetDelayStats() const {
482 return delay_cap_helper_->delay_stats(); 515 return delay_cap_helper_->delay_stats();
483 } 516 }
484 517
485 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( 518 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter(
486 PacketProcessorListener* listener, 519 PacketProcessorListener* listener,
487 int flow_id) 520 int flow_id)
488 : PacketProcessor(listener, flow_id, kRegular), 521 : PacketProcessor(listener, flow_id, kRegular),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (local_time_us_ >= (*it)->send_time_us()) { 618 if (local_time_us_ >= (*it)->send_time_us()) {
586 (*it)->set_send_time_us(local_time_us_); 619 (*it)->set_send_time_us(local_time_us_);
587 ProceedToNextSlot(); 620 ProceedToNextSlot();
588 } 621 }
589 ++it; 622 ++it;
590 } 623 }
591 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 624 packets_per_second_stats_.Push(rate_counter_->packets_per_second());
592 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 625 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0);
593 } 626 }
594 627
595 void TraceBasedDeliveryFilter::SetMaxDelay(int max_delay_ms) { 628 void TraceBasedDeliveryFilter::set_max_delay_ms(int64_t max_delay_ms) {
596 delay_cap_helper_->SetMaxDelay(max_delay_ms); 629 delay_cap_helper_->set_max_delay_ms(max_delay_ms);
597 } 630 }
598 631
599 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { 632 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const {
600 return delay_cap_helper_->delay_stats(); 633 return delay_cap_helper_->delay_stats();
601 } 634 }
602 635
603 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { 636 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const {
604 return kbps_stats_; 637 return kbps_stats_;
605 } 638 }
606 639
(...skipping 20 matching lines...) Expand all
627 uint32_t ssrc, 660 uint32_t ssrc,
628 int64_t first_frame_offset_ms) 661 int64_t first_frame_offset_ms)
629 : kMaxPayloadSizeBytes(1200), 662 : kMaxPayloadSizeBytes(1200),
630 kTimestampBase(0xff80ff00ul), 663 kTimestampBase(0xff80ff00ul),
631 frame_period_ms_(1000.0 / fps), 664 frame_period_ms_(1000.0 / fps),
632 bits_per_second_(1000 * kbps), 665 bits_per_second_(1000 * kbps),
633 frame_size_bytes_(bits_per_second_ / 8 / fps), 666 frame_size_bytes_(bits_per_second_ / 8 / fps),
634 flow_id_(flow_id), 667 flow_id_(flow_id),
635 next_frame_ms_(first_frame_offset_ms), 668 next_frame_ms_(first_frame_offset_ms),
636 now_ms_(0), 669 now_ms_(0),
637 prototype_header_() { 670 prototype_header_(),
671 start_plotting_ms_(first_frame_offset_ms) {
638 memset(&prototype_header_, 0, sizeof(prototype_header_)); 672 memset(&prototype_header_, 0, sizeof(prototype_header_));
639 prototype_header_.ssrc = ssrc; 673 prototype_header_.ssrc = ssrc;
640 prototype_header_.sequenceNumber = 0xf000u; 674 prototype_header_.sequenceNumber = 0xf000u;
641 } 675 }
642 676
643 uint32_t VideoSource::NextFrameSize() { 677 uint32_t VideoSource::NextFrameSize() {
644 return frame_size_bytes_; 678 return frame_size_bytes_;
645 } 679 }
646 680
647 uint32_t VideoSource::NextPacketSize(uint32_t frame_size, 681 uint32_t VideoSource::NextPacketSize(uint32_t frame_size,
648 uint32_t remaining_payload) { 682 uint32_t remaining_payload) {
649 return std::min(kMaxPayloadSizeBytes, remaining_payload); 683 return std::min(kMaxPayloadSizeBytes, remaining_payload);
650 } 684 }
651 685
686 int i = 0;
stefan-webrtc 2015/07/07 12:46:37 Remove
magalhaesc 2015/07/08 18:12:31 Done.
687
652 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) { 688 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) {
653 assert(in_out); 689 assert(in_out);
654 std::stringstream ss; 690
655 ss << "SendEstimate_" << flow_id_ << "#1";
656 BWE_TEST_LOGGING_PLOT(0, ss.str(), now_ms_, bits_per_second_ / 1000);
657 now_ms_ += time_ms; 691 now_ms_ += time_ms;
658 Packets new_packets; 692 Packets new_packets;
693
659 while (now_ms_ >= next_frame_ms_) { 694 while (now_ms_ >= next_frame_ms_) {
660 prototype_header_.timestamp = kTimestampBase + 695 prototype_header_.timestamp = kTimestampBase +
661 static_cast<uint32_t>(next_frame_ms_ * 90.0); 696 static_cast<uint32_t>(next_frame_ms_ * 90.0);
662 prototype_header_.extension.transmissionTimeOffset = 0; 697 prototype_header_.extension.transmissionTimeOffset = 0;
663 698
664 // Generate new packets for this frame, all with the same timestamp, 699 // Generate new packets for this frame, all with the same timestamp,
665 // but the payload size is capped, so if the whole frame doesn't fit in 700 // but the payload size is capped, so if the whole frame doesn't fit in
666 // one packet, we will see a number of equally sized packets followed by 701 // one packet, we will see a number of equally sized packets followed by
667 // one smaller at the tail. 702 // one smaller at the tail.
703
668 int64_t send_time_us = next_frame_ms_ * 1000.0; 704 int64_t send_time_us = next_frame_ms_ * 1000.0;
705
669 uint32_t frame_size = NextFrameSize(); 706 uint32_t frame_size = NextFrameSize();
670 uint32_t payload_size = frame_size; 707 uint32_t payload_size = frame_size;
671 708
672 while (payload_size > 0) { 709 while (payload_size > 0) {
673 ++prototype_header_.sequenceNumber; 710 ++prototype_header_.sequenceNumber;
674 uint32_t size = NextPacketSize(frame_size, payload_size); 711 uint32_t size = NextPacketSize(frame_size, payload_size);
675 MediaPacket* new_packet = 712 MediaPacket* new_packet =
676 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); 713 new MediaPacket(flow_id_, send_time_us, size, prototype_header_);
677 new_packets.push_back(new_packet); 714 new_packets.push_back(new_packet);
678 new_packet->SetAbsSendTimeMs(next_frame_ms_); 715 new_packet->SetAbsSendTimeMs(next_frame_ms_);
679 new_packet->set_sender_timestamp_us(send_time_us); 716 new_packet->set_sender_timestamp_us(send_time_us);
680 payload_size -= size; 717 payload_size -= size;
681 } 718 }
682 719
683 next_frame_ms_ += frame_period_ms_; 720 // A variance picked uniformly from {-1, 0, 1} ms is added to the frame
721 // timestamp.
722 next_frame_ms_ +=
723 frame_period_ms_ - 1 + 2 * static_cast<float>(rand()) / RAND_MAX;
684 } 724 }
725
685 in_out->merge(new_packets, DereferencingComparator<Packet>); 726 in_out->merge(new_packets, DereferencingComparator<Packet>);
686 } 727 }
687 728
688 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id, 729 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id,
689 float fps, 730 float fps,
690 uint32_t kbps, 731 uint32_t kbps,
691 uint32_t ssrc, 732 uint32_t ssrc,
692 int64_t first_frame_offset_ms) 733 int64_t first_frame_offset_ms)
693 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) { 734 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) {
694 } 735 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, 782 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size,
742 uint32_t remaining_payload) { 783 uint32_t remaining_payload) {
743 uint32_t fragments = 784 uint32_t fragments =
744 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; 785 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes;
745 uint32_t avg_size = (frame_size + fragments - 1) / fragments; 786 uint32_t avg_size = (frame_size + fragments - 1) / fragments;
746 return std::min(avg_size, remaining_payload); 787 return std::min(avg_size, remaining_payload);
747 } 788 }
748 } // namespace bwe 789 } // namespace bwe
749 } // namespace testing 790 } // namespace testing
750 } // namespace webrtc 791 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698