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

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: Using rtc::scoped_ptr on nada_unittest.cc 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_) + 500) / 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_ - window_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_) / BitrateWindowS();
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_ / BitrateWindowS();
89 }
86 90
87 private: 91 double RateCounter::BitrateWindowS() const {
88 typedef std::pair<int64_t, uint32_t> TimeSizePair; 92 return static_cast<double>(window_size_us_) / (1000 * 1000);
93 }
89 94
90 const int64_t kWindowSizeUs; 95 Random::Random(uint32_t seed) : a_(0x531FDB97 ^ seed), b_(0x6420ECA8 + seed) {
91 uint32_t packets_per_second_; 96 }
92 uint32_t bytes_per_second_; 97
93 int64_t last_accumulated_us_; 98 float Random::Rand() {
94 std::list<TimeSizePair> window_; 99 const float kScale = 1.0f / 0xffffffff;
95 }; 100 float result = kScale * b_;
101 a_ ^= b_;
102 b_ += a_;
103 return result;
104 }
105
106 int Random::Rand(int low, int high) {
107 float uniform = Rand() * (high - low + 1) + low;
108 return static_cast<int>(uniform);
109 }
110
111 int Random::Gaussian(int mean, int standard_deviation) {
112 // Creating a Normal distribution variable from two independent uniform
113 // variables based on the Box-Muller transform, which is defined on the
114 // interval (0, 1], hence the mask+add below.
115 const double kPi = 3.14159265358979323846;
116 const double kScale = 1.0 / 0x80000000ul;
117 double u1 = kScale * ((a_ & 0x7ffffffful) + 1);
118 double u2 = kScale * ((b_ & 0x7ffffffful) + 1);
119 a_ ^= b_;
120 b_ += a_;
121 return static_cast<int>(
122 mean + standard_deviation * sqrt(-2 * log(u1)) * cos(2 * kPi * u2));
123 }
124
125 int Random::Exponential(float lambda) {
126 float uniform = Rand();
127 return static_cast<int>(-log(uniform) / lambda);
128 }
96 129
97 Packet::Packet() 130 Packet::Packet()
98 : flow_id_(0), creation_time_us_(-1), send_time_us_(-1), payload_size_(0) { 131 : flow_id_(0),
132 creation_time_us_(-1),
133 send_time_us_(-1),
134 sender_timestamp_us_(-1),
135 payload_size_(0) {
99 } 136 }
100 137
101 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size) 138 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size)
102 : flow_id_(flow_id), 139 : flow_id_(flow_id),
103 creation_time_us_(send_time_us), 140 creation_time_us_(send_time_us),
104 send_time_us_(send_time_us), 141 send_time_us_(send_time_us),
142 sender_timestamp_us_(send_time_us),
105 payload_size_(payload_size) { 143 payload_size_(payload_size) {
106 } 144 }
107 145
108 Packet::~Packet() { 146 Packet::~Packet() {
109 } 147 }
110 148
111 bool Packet::operator<(const Packet& rhs) const { 149 bool Packet::operator<(const Packet& rhs) const {
112 return send_time_us_ < rhs.send_time_us_; 150 return send_time_us_ < rhs.send_time_us_;
113 } 151 }
114 152
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 listener_->AddPacketProcessor(this, type); 234 listener_->AddPacketProcessor(this, type);
197 } 235 }
198 } 236 }
199 237
200 PacketProcessor::~PacketProcessor() { 238 PacketProcessor::~PacketProcessor() {
201 if (listener_) { 239 if (listener_) {
202 listener_->RemovePacketProcessor(this); 240 listener_->RemovePacketProcessor(this);
203 } 241 }
204 } 242 }
205 243
244 uint32_t PacketProcessor::packets_per_second() const {
245 return rate_counter_.packets_per_second();
246 }
247
248 uint32_t PacketProcessor::bits_per_second() const {
249 return rate_counter_.bits_per_second();
250 }
251
206 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 252 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
207 int flow_id, 253 int flow_id,
208 const char* name) 254 const char* name)
209 : PacketProcessor(listener, flow_id, kRegular), 255 : PacketProcessor(listener, flow_id, kRegular),
210 rate_counter_(new RateCounter()),
211 packets_per_second_stats_(), 256 packets_per_second_stats_(),
212 kbps_stats_(), 257 kbps_stats_(),
213 name_() { 258 name_(),
259 start_plotting_time_ms_(0) {
214 std::stringstream ss; 260 std::stringstream ss;
215 ss << name << "_" << flow_id; 261 ss << name << "_" << flow_id;
216 name_ = ss.str(); 262 name_ = ss.str();
217 } 263 }
218 264
219 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 265 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
220 const FlowIds& flow_ids, 266 const FlowIds& flow_ids,
221 const char* name) 267 const char* name)
222 : PacketProcessor(listener, flow_ids, kRegular), 268 : PacketProcessor(listener, flow_ids, kRegular),
223 rate_counter_(new RateCounter()),
224 packets_per_second_stats_(), 269 packets_per_second_stats_(),
225 kbps_stats_(), 270 kbps_stats_(),
226 name_() { 271 name_(),
272 start_plotting_time_ms_(0) {
227 std::stringstream ss; 273 std::stringstream ss;
228 ss << name << "_"; 274 ss << name << "_";
229 for (int flow_id : flow_ids) { 275 for (int flow_id : flow_ids) {
230 ss << flow_id << ","; 276 ss << flow_id << ",";
231 } 277 }
232 name_ = ss.str(); 278 name_ = ss.str();
233 } 279 }
234 280
281 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
282 const FlowIds& flow_ids,
283 const char* name,
284 int64_t start_plotting_time_ms)
285 : RateCounterFilter(listener, flow_ids, name) {
286 start_plotting_time_ms_ = start_plotting_time_ms;
287 }
288
235 RateCounterFilter::~RateCounterFilter() { 289 RateCounterFilter::~RateCounterFilter() {
236 LogStats(); 290 LogStats();
237 } 291 }
238 292
239 uint32_t RateCounterFilter::packets_per_second() const {
240 return rate_counter_->packets_per_second();
241 }
242
243 uint32_t RateCounterFilter::bits_per_second() const {
244 return rate_counter_->bits_per_second();
245 }
246 293
247 void RateCounterFilter::LogStats() { 294 void RateCounterFilter::LogStats() {
248 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); 295 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter");
249 packets_per_second_stats_.Log("pps"); 296 packets_per_second_stats_.Log("pps");
250 kbps_stats_.Log("kbps"); 297 kbps_stats_.Log("kbps");
251 } 298 }
252 299
253 Stats<double> RateCounterFilter::GetBitrateStats() const { 300 Stats<double> RateCounterFilter::GetBitrateStats() const {
254 return kbps_stats_; 301 return kbps_stats_;
255 } 302 }
256 303
257 void RateCounterFilter::Plot(int64_t timestamp_ms) { 304 void RateCounterFilter::Plot(int64_t timestamp_ms) {
305 uint32_t plot_kbps = 0;
306 if (timestamp_ms >= start_plotting_time_ms_) {
307 plot_kbps = rate_counter_.bits_per_second() / 1000.0;
308 }
258 BWE_TEST_LOGGING_CONTEXT(name_.c_str()); 309 BWE_TEST_LOGGING_CONTEXT(name_.c_str());
259 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, 310 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, plot_kbps);
260 rate_counter_->bits_per_second() / 1000.0); 311 RTC_UNUSED(plot_kbps);
261 } 312 }
262 313
263 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 314 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
264 assert(in_out); 315 assert(in_out);
265 for (const Packet* packet : *in_out) { 316 for (const Packet* packet : *in_out) {
266 rate_counter_->UpdateRates(packet->send_time_us(), 317 rate_counter_.UpdateRates(packet->send_time_us(),
267 static_cast<int>(packet->payload_size())); 318 static_cast<int>(packet->payload_size()));
268 } 319 }
269 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 320 packets_per_second_stats_.Push(rate_counter_.packets_per_second());
270 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 321 kbps_stats_.Push(rate_counter_.bits_per_second() / 1000.0);
271 } 322 }
272 323
273 LossFilter::LossFilter(PacketProcessorListener* listener, int flow_id) 324 LossFilter::LossFilter(PacketProcessorListener* listener, int flow_id)
274 : PacketProcessor(listener, flow_id, kRegular), 325 : PacketProcessor(listener, flow_id, kRegular),
275 random_(0x12345678), 326 random_(0x12345678),
276 loss_fraction_(0.0f) { 327 loss_fraction_(0.0f) {
277 } 328 }
278 329
279 LossFilter::LossFilter(PacketProcessorListener* listener, 330 LossFilter::LossFilter(PacketProcessorListener* listener,
280 const FlowIds& flow_ids) 331 const FlowIds& flow_ids)
(...skipping 15 matching lines...) Expand all
296 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 347 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
297 if (random_.Rand() < loss_fraction_) { 348 if (random_.Rand() < loss_fraction_) {
298 delete *it; 349 delete *it;
299 it = in_out->erase(it); 350 it = in_out->erase(it);
300 } else { 351 } else {
301 ++it; 352 ++it;
302 } 353 }
303 } 354 }
304 } 355 }
305 356
357 const int64_t kDefaultOneWayDelayUs = 0;
358
306 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id) 359 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id)
307 : PacketProcessor(listener, flow_id, kRegular), 360 : PacketProcessor(listener, flow_id, kRegular),
308 delay_us_(0), 361 one_way_delay_us_(kDefaultOneWayDelayUs),
309 last_send_time_us_(0) { 362 last_send_time_us_(0) {
310 } 363 }
311 364
312 DelayFilter::DelayFilter(PacketProcessorListener* listener, 365 DelayFilter::DelayFilter(PacketProcessorListener* listener,
313 const FlowIds& flow_ids) 366 const FlowIds& flow_ids)
314 : PacketProcessor(listener, flow_ids, kRegular), 367 : PacketProcessor(listener, flow_ids, kRegular),
315 delay_us_(0), 368 one_way_delay_us_(kDefaultOneWayDelayUs),
316 last_send_time_us_(0) { 369 last_send_time_us_(0) {
317 } 370 }
318 371
319 void DelayFilter::SetDelayMs(int64_t delay_ms) { 372 void DelayFilter::SetOneWayDelayMs(int64_t one_way_delay_ms) {
320 BWE_TEST_LOGGING_ENABLE(false); 373 BWE_TEST_LOGGING_ENABLE(false);
321 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(delay_ms)); 374 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(one_way_delay_ms));
322 assert(delay_ms >= 0); 375 assert(one_way_delay_ms >= 0);
323 delay_us_ = delay_ms * 1000; 376 one_way_delay_us_ = one_way_delay_ms * 1000;
324 } 377 }
325 378
326 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 379 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
327 assert(in_out); 380 assert(in_out);
328 for (Packet* packet : *in_out) { 381 for (Packet* packet : *in_out) {
329 int64_t new_send_time_us = packet->send_time_us() + delay_us_; 382 int64_t new_send_time_us = packet->send_time_us() + one_way_delay_us_;
330 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us); 383 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us);
331 packet->set_send_time_us(last_send_time_us_); 384 packet->set_send_time_us(last_send_time_us_);
332 } 385 }
333 } 386 }
334 387
335 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) 388 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id)
336 : PacketProcessor(listener, flow_id, kRegular), 389 : PacketProcessor(listener, flow_id, kRegular),
337 random_(0x89674523), 390 random_(0x89674523),
338 stddev_jitter_us_(0), 391 stddev_jitter_us_(0),
339 last_send_time_us_(0) { 392 last_send_time_us_(0) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 int64_t t2 = (*it)->send_time_us(); 450 int64_t t2 = (*it)->send_time_us();
398 std::swap(*last_it, *it); 451 std::swap(*last_it, *it);
399 (*last_it)->set_send_time_us(t1); 452 (*last_it)->set_send_time_us(t1);
400 (*it)->set_send_time_us(t2); 453 (*it)->set_send_time_us(t2);
401 } 454 }
402 last_it = it; 455 last_it = it;
403 } 456 }
404 } 457 }
405 } 458 }
406 459
460 const uint32_t kDefaultKbps = 1200;
461
407 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id) 462 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id)
408 : PacketProcessor(listener, flow_id, kRegular), 463 : PacketProcessor(listener, flow_id, kRegular),
409 kbps_(1200), 464 capacity_kbps_(kDefaultKbps),
410 last_send_time_us_(0), 465 last_send_time_us_(0),
411 delay_cap_helper_(new DelayCapHelper()) { 466 delay_cap_helper_(new DelayCapHelper()) {
412 } 467 }
413 468
414 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, 469 ChokeFilter::ChokeFilter(PacketProcessorListener* listener,
415 const FlowIds& flow_ids) 470 const FlowIds& flow_ids)
416 : PacketProcessor(listener, flow_ids, kRegular), 471 : PacketProcessor(listener, flow_ids, kRegular),
417 kbps_(1200), 472 capacity_kbps_(kDefaultKbps),
418 last_send_time_us_(0), 473 last_send_time_us_(0),
419 delay_cap_helper_(new DelayCapHelper()) { 474 delay_cap_helper_(new DelayCapHelper()) {
420 } 475 }
421 476
422 ChokeFilter::~ChokeFilter() {} 477 ChokeFilter::~ChokeFilter() {}
423 478
424 void ChokeFilter::SetCapacity(uint32_t kbps) { 479 void ChokeFilter::set_capacity_kbps(uint32_t kbps) {
425 BWE_TEST_LOGGING_ENABLE(false); 480 BWE_TEST_LOGGING_ENABLE(false);
426 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps); 481 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps);
427 kbps_ = kbps; 482 capacity_kbps_ = kbps;
483 }
484
485 uint32_t ChokeFilter::capacity_kbps() {
486 return capacity_kbps_;
428 } 487 }
429 488
430 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 489 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
431 assert(in_out); 490 assert(in_out);
432 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 491 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
433 int64_t earliest_send_time_us = 492 int64_t earliest_send_time_us =
434 std::max(last_send_time_us_, (*it)->send_time_us()); 493 std::max(last_send_time_us_, (*it)->send_time_us());
494
435 int64_t new_send_time_us = 495 int64_t new_send_time_us =
436 earliest_send_time_us + 496 earliest_send_time_us +
437 ((*it)->payload_size() * 8 * 1000 + kbps_ / 2) / kbps_; 497 ((*it)->payload_size() * 8 * 1000 + capacity_kbps_ / 2) /
498 capacity_kbps_;
499
438 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us, 500 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us,
439 (*it)->send_time_us())) { 501 (*it)->send_time_us())) {
440 (*it)->set_send_time_us(new_send_time_us); 502 (*it)->set_send_time_us(new_send_time_us);
441 last_send_time_us_ = new_send_time_us; 503 last_send_time_us_ = new_send_time_us;
442 ++it; 504 ++it;
443 } else { 505 } else {
444 delete *it; 506 delete *it;
445 it = in_out->erase(it); 507 it = in_out->erase(it);
446 } 508 }
447 } 509 }
448 } 510 }
449 511
450 void ChokeFilter::SetMaxDelay(int max_delay_ms) { 512 void ChokeFilter::set_max_delay_ms(int64_t max_delay_ms) {
451 delay_cap_helper_->SetMaxDelay(max_delay_ms); 513 delay_cap_helper_->set_max_delay_ms(max_delay_ms);
452 } 514 }
453 515
454 Stats<double> ChokeFilter::GetDelayStats() const { 516 Stats<double> ChokeFilter::GetDelayStats() const {
455 return delay_cap_helper_->delay_stats(); 517 return delay_cap_helper_->delay_stats();
456 } 518 }
457 519
458 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( 520 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter(
459 PacketProcessorListener* listener, 521 PacketProcessorListener* listener,
460 int flow_id) 522 int flow_id)
461 : PacketProcessor(listener, flow_id, kRegular), 523 : PacketProcessor(listener, flow_id, kRegular),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (local_time_us_ >= (*it)->send_time_us()) { 620 if (local_time_us_ >= (*it)->send_time_us()) {
559 (*it)->set_send_time_us(local_time_us_); 621 (*it)->set_send_time_us(local_time_us_);
560 ProceedToNextSlot(); 622 ProceedToNextSlot();
561 } 623 }
562 ++it; 624 ++it;
563 } 625 }
564 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 626 packets_per_second_stats_.Push(rate_counter_->packets_per_second());
565 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 627 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0);
566 } 628 }
567 629
568 void TraceBasedDeliveryFilter::SetMaxDelay(int max_delay_ms) { 630 void TraceBasedDeliveryFilter::set_max_delay_ms(int64_t max_delay_ms) {
569 delay_cap_helper_->SetMaxDelay(max_delay_ms); 631 delay_cap_helper_->set_max_delay_ms(max_delay_ms);
570 } 632 }
571 633
572 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { 634 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const {
573 return delay_cap_helper_->delay_stats(); 635 return delay_cap_helper_->delay_stats();
574 } 636 }
575 637
576 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { 638 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const {
577 return kbps_stats_; 639 return kbps_stats_;
578 } 640 }
579 641
(...skipping 19 matching lines...) Expand all
599 uint32_t kbps, 661 uint32_t kbps,
600 uint32_t ssrc, 662 uint32_t ssrc,
601 int64_t first_frame_offset_ms) 663 int64_t first_frame_offset_ms)
602 : kMaxPayloadSizeBytes(1200), 664 : kMaxPayloadSizeBytes(1200),
603 kTimestampBase(0xff80ff00ul), 665 kTimestampBase(0xff80ff00ul),
604 frame_period_ms_(1000.0 / fps), 666 frame_period_ms_(1000.0 / fps),
605 bits_per_second_(1000 * kbps), 667 bits_per_second_(1000 * kbps),
606 frame_size_bytes_(bits_per_second_ / 8 / fps), 668 frame_size_bytes_(bits_per_second_ / 8 / fps),
607 flow_id_(flow_id), 669 flow_id_(flow_id),
608 next_frame_ms_(first_frame_offset_ms), 670 next_frame_ms_(first_frame_offset_ms),
671 next_frame_rand_ms_(0),
609 now_ms_(0), 672 now_ms_(0),
610 prototype_header_() { 673 prototype_header_(),
674 start_plotting_ms_(first_frame_offset_ms) {
611 memset(&prototype_header_, 0, sizeof(prototype_header_)); 675 memset(&prototype_header_, 0, sizeof(prototype_header_));
612 prototype_header_.ssrc = ssrc; 676 prototype_header_.ssrc = ssrc;
613 prototype_header_.sequenceNumber = 0xf000u; 677 prototype_header_.sequenceNumber = 0xf000u;
614 } 678 }
615 679
616 uint32_t VideoSource::NextFrameSize() { 680 uint32_t VideoSource::NextFrameSize() {
617 return frame_size_bytes_; 681 return frame_size_bytes_;
618 } 682 }
619 683
684 int64_t VideoSource::GetTimeUntilNextFrameMs() const {
685 return next_frame_ms_ + next_frame_rand_ms_ - now_ms_;
686 }
687
620 uint32_t VideoSource::NextPacketSize(uint32_t frame_size, 688 uint32_t VideoSource::NextPacketSize(uint32_t frame_size,
621 uint32_t remaining_payload) { 689 uint32_t remaining_payload) {
622 return std::min(kMaxPayloadSizeBytes, remaining_payload); 690 return std::min(kMaxPayloadSizeBytes, remaining_payload);
623 } 691 }
624 692
625 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) { 693 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) {
626 assert(in_out); 694 assert(in_out);
627 std::stringstream ss; 695
628 ss << "SendEstimate_" << flow_id_ << "#1";
629 BWE_TEST_LOGGING_PLOT(0, ss.str(), now_ms_, bits_per_second_ / 1000);
630 now_ms_ += time_ms; 696 now_ms_ += time_ms;
631 Packets new_packets; 697 Packets new_packets;
698
632 while (now_ms_ >= next_frame_ms_) { 699 while (now_ms_ >= next_frame_ms_) {
633 prototype_header_.timestamp = kTimestampBase + 700 const int64_t kRandAmplitude = 2;
634 static_cast<uint32_t>(next_frame_ms_ * 90.0); 701 // A variance picked uniformly from {-1, 0, 1} ms is added to the frame
702 // timestamp.
703 next_frame_rand_ms_ =
704 kRandAmplitude * static_cast<float>(rand()) / RAND_MAX -
705 kRandAmplitude / 2;
706
707 // Ensure frame will not have a negative timestamp.
708 int64_t next_frame_ms =
709 std::max<int64_t>(next_frame_ms_ + next_frame_rand_ms_, 0);
710
711 prototype_header_.timestamp =
712 kTimestampBase + static_cast<uint32_t>(next_frame_ms * 90.0);
635 prototype_header_.extension.transmissionTimeOffset = 0; 713 prototype_header_.extension.transmissionTimeOffset = 0;
636 714
637 // Generate new packets for this frame, all with the same timestamp, 715 // Generate new packets for this frame, all with the same timestamp,
638 // but the payload size is capped, so if the whole frame doesn't fit in 716 // but the payload size is capped, so if the whole frame doesn't fit in
639 // one packet, we will see a number of equally sized packets followed by 717 // one packet, we will see a number of equally sized packets followed by
640 // one smaller at the tail. 718 // one smaller at the tail.
641 int64_t send_time_us = next_frame_ms_ * 1000.0; 719
720 int64_t send_time_us = next_frame_ms * 1000.0;
721
642 uint32_t frame_size = NextFrameSize(); 722 uint32_t frame_size = NextFrameSize();
643 uint32_t payload_size = frame_size; 723 uint32_t payload_size = frame_size;
644 724
645 while (payload_size > 0) { 725 while (payload_size > 0) {
646 ++prototype_header_.sequenceNumber; 726 ++prototype_header_.sequenceNumber;
647 uint32_t size = NextPacketSize(frame_size, payload_size); 727 uint32_t size = NextPacketSize(frame_size, payload_size);
648 MediaPacket* new_packet = 728 MediaPacket* new_packet =
649 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); 729 new MediaPacket(flow_id_, send_time_us, size, prototype_header_);
650 new_packets.push_back(new_packet); 730 new_packets.push_back(new_packet);
651 new_packet->SetAbsSendTimeMs(next_frame_ms_); 731 new_packet->SetAbsSendTimeMs(next_frame_ms);
652 new_packet->set_sender_timestamp_us(send_time_us); 732 new_packet->set_sender_timestamp_us(send_time_us);
653 payload_size -= size; 733 payload_size -= size;
654 } 734 }
655 735
656 next_frame_ms_ += frame_period_ms_; 736 next_frame_ms_ += frame_period_ms_;
657 } 737 }
738
658 in_out->merge(new_packets, DereferencingComparator<Packet>); 739 in_out->merge(new_packets, DereferencingComparator<Packet>);
659 } 740 }
660 741
661 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id, 742 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id,
662 float fps, 743 float fps,
663 uint32_t kbps, 744 uint32_t kbps,
664 uint32_t ssrc, 745 uint32_t ssrc,
665 int64_t first_frame_offset_ms) 746 int64_t first_frame_offset_ms)
666 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) { 747 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) {
667 } 748 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, 795 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size,
715 uint32_t remaining_payload) { 796 uint32_t remaining_payload) {
716 uint32_t fragments = 797 uint32_t fragments =
717 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; 798 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes;
718 uint32_t avg_size = (frame_size + fragments - 1) / fragments; 799 uint32_t avg_size = (frame_size + fragments - 1) / fragments;
719 return std::min(avg_size, remaining_payload); 800 return std::min(avg_size, remaining_payload);
720 } 801 }
721 } // namespace bwe 802 } // namespace bwe
722 } // namespace testing 803 } // namespace testing
723 } // namespace webrtc 804 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698