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

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

Powered by Google App Engine
This is Rietveld 408576698