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

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: Addressing trybot failures 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 SetMaxDelayMs(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 packets_per_second_++;
65 bytes_per_second_ += payload_size; 67 bytes_per_second_ += 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_ - kWindowSizeUs)) {
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(packets_per_second_ >= 1);
76 assert(bytes_per_second_ >= packet.second);
77 packets_per_second_--;
78 bytes_per_second_ -= packet.second;
79 window_.pop_front();
79 } 80 }
80 81 }
81 uint32_t bits_per_second() const {
82 return bytes_per_second_ * 8;
83 }
84
85 uint32_t packets_per_second() const { return packets_per_second_; }
86
87 private:
88 typedef std::pair<int64_t, uint32_t> TimeSizePair;
89
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 82
97 Random::Random(uint32_t seed) 83 Random::Random(uint32_t seed)
98 : a_(0x531FDB97 ^ seed), 84 : a_(0x531FDB97 ^ seed),
99 b_(0x6420ECA8 + seed) { 85 b_(0x6420ECA8 + seed) {
100 } 86 }
101 87
102 float Random::Rand() { 88 float Random::Rand() {
103 const float kScale = 1.0f / 0xffffffff; 89 const float kScale = 1.0f / 0xffffffff;
104 float result = kScale * b_; 90 float result = kScale * b_;
105 a_ ^= b_; 91 a_ ^= b_;
106 b_ += a_; 92 b_ += a_;
107 return result; 93 return result;
108 } 94 }
109 95
96 int Random::Rand(int low, int high) {
97 float uniform = Rand() * (high - low + 1) + low;
98 return static_cast<int>(uniform);
99 }
100
110 int Random::Gaussian(int mean, int standard_deviation) { 101 int Random::Gaussian(int mean, int standard_deviation) {
111 // Creating a Normal distribution variable from two independent uniform 102 // Creating a Normal distribution variable from two independent uniform
112 // variables based on the Box-Muller transform, which is defined on the 103 // variables based on the Box-Muller transform, which is defined on the
113 // interval (0, 1], hence the mask+add below. 104 // interval (0, 1], hence the mask+add below.
114 const double kPi = 3.14159265358979323846; 105 const double kPi = 3.14159265358979323846;
115 const double kScale = 1.0 / 0x80000000ul; 106 const double kScale = 1.0 / 0x80000000ul;
116 double u1 = kScale * ((a_ & 0x7ffffffful) + 1); 107 double u1 = kScale * ((a_ & 0x7ffffffful) + 1);
117 double u2 = kScale * ((b_ & 0x7ffffffful) + 1); 108 double u2 = kScale * ((b_ & 0x7ffffffful) + 1);
118 a_ ^= b_; 109 a_ ^= b_;
119 b_ += a_; 110 b_ += a_;
120 return static_cast<int>(mean + standard_deviation * 111 return static_cast<int>(mean + standard_deviation *
121 sqrt(-2 * log(u1)) * cos(2 * kPi * u2)); 112 sqrt(-2 * log(u1)) * cos(2 * kPi * u2));
122 } 113 }
123 114
115 int Random::Exponential(float lambda) {
116 float uniform = Rand();
117 return static_cast<int>(-log(uniform) / lambda);
118 }
119
124 Packet::Packet() 120 Packet::Packet()
125 : flow_id_(0), creation_time_us_(-1), send_time_us_(-1), payload_size_(0) { 121 : flow_id_(0),
122 creation_time_us_(-1),
123 send_time_us_(-1),
124 payload_size_(0),
125 sending_estimate_kbps_(0) {
126 } 126 }
127 127
128 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size) 128 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size)
129 : flow_id_(flow_id), 129 : flow_id_(flow_id),
130 creation_time_us_(send_time_us), 130 creation_time_us_(send_time_us),
131 send_time_us_(send_time_us), 131 send_time_us_(send_time_us),
132 payload_size_(payload_size) { 132 payload_size_(payload_size),
133 sending_estimate_kbps_(0),
134 total_capacity_kbps_(0),
135 capacity_per_flow_kbps_(0) {
stefan-webrtc 2015/06/25 14:44:04 As discussed offline, we should find a better way
magalhaesc 2015/07/01 12:48:40 Fields removed from Packet class.
133 } 136 }
134 137
135 Packet::~Packet() { 138 Packet::~Packet() {
136 } 139 }
137 140
138 bool Packet::operator<(const Packet& rhs) const { 141 bool Packet::operator<(const Packet& rhs) const {
139 return send_time_us_ < rhs.send_time_us_; 142 return send_time_us_ < rhs.send_time_us_;
140 } 143 }
141 144
142 void Packet::set_send_time_us(int64_t send_time_us) { 145 void Packet::set_send_time_us(int64_t send_time_us) {
143 assert(send_time_us >= 0); 146 assert(send_time_us >= 0);
144 send_time_us_ = send_time_us; 147 send_time_us_ = send_time_us;
145 } 148 }
146 149
150 void Packet::set_sending_estimate_kbps(uint32_t sending_estimate_kbps) {
151 sending_estimate_kbps_ = sending_estimate_kbps;
152 }
153
154 void Packet::set_total_capacity_kbps(uint32_t total_capacity_kbps) {
155 total_capacity_kbps_ = total_capacity_kbps;
156 }
157
158 void Packet::set_capacity_per_flow_kbps(uint32_t capacity_per_flow_kbps) {
159 capacity_per_flow_kbps_ = capacity_per_flow_kbps;
160 }
161
147 MediaPacket::MediaPacket() { 162 MediaPacket::MediaPacket() {
148 memset(&header_, 0, sizeof(header_)); 163 memset(&header_, 0, sizeof(header_));
149 } 164 }
150 165
151 MediaPacket::MediaPacket(int flow_id, 166 MediaPacket::MediaPacket(int flow_id,
152 int64_t send_time_us, 167 int64_t send_time_us,
153 size_t payload_size, 168 size_t payload_size,
154 uint16_t sequence_number) 169 uint16_t sequence_number)
155 : Packet(flow_id, send_time_us, payload_size) { 170 : Packet(flow_id, send_time_us, payload_size) {
156 header_ = RTPHeader(); 171 header_ = RTPHeader();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return false; 217 return false;
203 } 218 }
204 last_it = it; 219 last_it = it;
205 } 220 }
206 return true; 221 return true;
207 } 222 }
208 223
209 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, 224 PacketProcessor::PacketProcessor(PacketProcessorListener* listener,
210 int flow_id, 225 int flow_id,
211 ProcessorType type) 226 ProcessorType type)
212 : listener_(listener), flow_ids_(&flow_id, &flow_id + 1) { 227 : rate_counter_(new RateCounter()),
228 listener_(listener),
229 flow_ids_(&flow_id, &flow_id + 1) {
213 if (listener_) { 230 if (listener_) {
214 listener_->AddPacketProcessor(this, type); 231 listener_->AddPacketProcessor(this, type);
215 } 232 }
216 } 233 }
217 234
218 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, 235 PacketProcessor::PacketProcessor(PacketProcessorListener* listener,
219 const FlowIds& flow_ids, 236 const FlowIds& flow_ids,
220 ProcessorType type) 237 ProcessorType type)
221 : listener_(listener), flow_ids_(flow_ids) { 238 : rate_counter_(new RateCounter()),
239 listener_(listener),
240 flow_ids_(flow_ids) {
222 if (listener_) { 241 if (listener_) {
223 listener_->AddPacketProcessor(this, type); 242 listener_->AddPacketProcessor(this, type);
224 } 243 }
225 } 244 }
226 245
227 PacketProcessor::~PacketProcessor() { 246 PacketProcessor::~PacketProcessor() {
228 if (listener_) { 247 if (listener_) {
229 listener_->RemovePacketProcessor(this); 248 listener_->RemovePacketProcessor(this);
230 } 249 }
231 } 250 }
232 251
252 uint32_t PacketProcessor::packets_per_second() const {
253 return rate_counter_->packets_per_second();
254 }
255
256 uint32_t PacketProcessor::bits_per_second() const {
257 return rate_counter_->bits_per_second();
258 }
259
233 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 260 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
234 int flow_id, 261 int flow_id,
235 const char* name) 262 const char* name)
236 : PacketProcessor(listener, flow_id, kRegular), 263 : PacketProcessor(listener, flow_id, kRegular),
237 rate_counter_(new RateCounter()),
238 packets_per_second_stats_(), 264 packets_per_second_stats_(),
239 kbps_stats_(), 265 kbps_stats_(),
240 name_() { 266 name_(),
267 start_plotting_ms_(0) {
241 std::stringstream ss; 268 std::stringstream ss;
242 ss << name << "_" << flow_id; 269 ss << name << "_" << flow_id;
243 name_ = ss.str(); 270 name_ = ss.str();
244 } 271 }
245 272
246 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, 273 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
247 const FlowIds& flow_ids, 274 const FlowIds& flow_ids,
248 const char* name) 275 const char* name)
249 : PacketProcessor(listener, flow_ids, kRegular), 276 : PacketProcessor(listener, flow_ids, kRegular),
250 rate_counter_(new RateCounter()),
251 packets_per_second_stats_(), 277 packets_per_second_stats_(),
252 kbps_stats_(), 278 kbps_stats_(),
253 name_() { 279 name_(),
280 start_plotting_ms_(0) {
254 std::stringstream ss; 281 std::stringstream ss;
255 ss << name << "_"; 282 ss << name << "_";
256 for (int flow_id : flow_ids) { 283 for (int flow_id : flow_ids) {
257 ss << flow_id << ","; 284 ss << flow_id << ",";
258 } 285 }
259 name_ = ss.str(); 286 name_ = ss.str();
260 } 287 }
261 288
289 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
290 const FlowIds& flow_ids,
291 const char* name,
292 int64_t start_plotting_ms)
293 : RateCounterFilter(listener, flow_ids, name) {
294 start_plotting_ms_ = start_plotting_ms;
295 }
296
262 RateCounterFilter::~RateCounterFilter() { 297 RateCounterFilter::~RateCounterFilter() {
263 LogStats(); 298 LogStats();
264 } 299 }
265 300
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 301
274 void RateCounterFilter::LogStats() { 302 void RateCounterFilter::LogStats() {
275 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); 303 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter");
276 packets_per_second_stats_.Log("pps"); 304 packets_per_second_stats_.Log("pps");
277 kbps_stats_.Log("kbps"); 305 kbps_stats_.Log("kbps");
278 } 306 }
279 307
280 Stats<double> RateCounterFilter::GetBitrateStats() const { 308 Stats<double> RateCounterFilter::GetBitrateStats() const {
281 return kbps_stats_; 309 return kbps_stats_;
282 } 310 }
283 311
284 void RateCounterFilter::Plot(int64_t timestamp_ms) { 312 void RateCounterFilter::Plot(int64_t timestamp_ms) {
313 uint32_t plot_kbps = rate_counter_->bits_per_second() / 1000.0;
314 if (timestamp_ms < start_plotting_ms_) {
315 plot_kbps = 0;
stefan-webrtc 2015/06/25 14:44:04 I prefer to swap this with 313, so you do plot_kbp
magalhaesc 2015/07/01 12:48:40 Done.
316 }
285 BWE_TEST_LOGGING_CONTEXT(name_.c_str()); 317 BWE_TEST_LOGGING_CONTEXT(name_.c_str());
286 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, 318 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, plot_kbps);
287 rate_counter_->bits_per_second() / 1000.0); 319 // Silencing unused variable compiling error.
320 (void)plot_kbps;
stefan-webrtc 2015/06/25 14:44:04 RTC_UNUSED
magalhaesc 2015/07/01 12:48:40 Done.
288 } 321 }
289 322
290 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 323 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
291 assert(in_out); 324 assert(in_out);
292 for (const Packet* packet : *in_out) { 325 for (const Packet* packet : *in_out) {
293 rate_counter_->UpdateRates(packet->send_time_us(), 326 rate_counter_->UpdateRates(packet->send_time_us(),
294 static_cast<int>(packet->payload_size())); 327 static_cast<int>(packet->payload_size()));
295 } 328 }
296 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 329 packets_per_second_stats_.Push(rate_counter_->packets_per_second());
297 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 330 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0);
(...skipping 25 matching lines...) Expand all
323 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 356 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
324 if (random_.Rand() < loss_fraction_) { 357 if (random_.Rand() < loss_fraction_) {
325 delete *it; 358 delete *it;
326 it = in_out->erase(it); 359 it = in_out->erase(it);
327 } else { 360 } else {
328 ++it; 361 ++it;
329 } 362 }
330 } 363 }
331 } 364 }
332 365
366 const int64_t kDefaultOneWayDelayUs = 0;
367
333 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id) 368 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id)
334 : PacketProcessor(listener, flow_id, kRegular), 369 : PacketProcessor(listener, flow_id, kRegular),
335 delay_us_(0), 370 one_way_delay_us_(kDefaultOneWayDelayUs),
336 last_send_time_us_(0) { 371 last_send_time_us_(0) {
337 } 372 }
338 373
339 DelayFilter::DelayFilter(PacketProcessorListener* listener, 374 DelayFilter::DelayFilter(PacketProcessorListener* listener,
340 const FlowIds& flow_ids) 375 const FlowIds& flow_ids)
341 : PacketProcessor(listener, flow_ids, kRegular), 376 : PacketProcessor(listener, flow_ids, kRegular),
342 delay_us_(0), 377 one_way_delay_us_(kDefaultOneWayDelayUs),
343 last_send_time_us_(0) { 378 last_send_time_us_(0) {
344 } 379 }
345 380
346 void DelayFilter::SetDelayMs(int64_t delay_ms) { 381 void DelayFilter::SetOneWayDelayMs(int64_t one_way_delay_ms) {
347 BWE_TEST_LOGGING_ENABLE(false); 382 BWE_TEST_LOGGING_ENABLE(false);
348 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(delay_ms)); 383 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(one_way_delay_ms));
349 assert(delay_ms >= 0); 384 assert(one_way_delay_ms >= 0);
350 delay_us_ = delay_ms * 1000; 385 one_way_delay_us_ = one_way_delay_ms * 1000;
351 } 386 }
352 387
353 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 388 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
354 assert(in_out); 389 assert(in_out);
355 for (Packet* packet : *in_out) { 390 for (Packet* packet : *in_out) {
356 int64_t new_send_time_us = packet->send_time_us() + delay_us_; 391 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); 392 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us);
358 packet->set_send_time_us(last_send_time_us_); 393 packet->set_send_time_us(last_send_time_us_);
359 } 394 }
360 } 395 }
361 396
362 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) 397 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id)
363 : PacketProcessor(listener, flow_id, kRegular), 398 : PacketProcessor(listener, flow_id, kRegular),
364 random_(0x89674523), 399 random_(0x89674523),
365 stddev_jitter_us_(0), 400 stddev_jitter_us_(0),
366 last_send_time_us_(0) { 401 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(); 459 int64_t t2 = (*it)->send_time_us();
425 std::swap(*last_it, *it); 460 std::swap(*last_it, *it);
426 (*last_it)->set_send_time_us(t1); 461 (*last_it)->set_send_time_us(t1);
427 (*it)->set_send_time_us(t2); 462 (*it)->set_send_time_us(t2);
428 } 463 }
429 last_it = it; 464 last_it = it;
430 } 465 }
431 } 466 }
432 } 467 }
433 468
469 const uint32_t kDefaultKbps = 1200;
470
434 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id) 471 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id)
435 : PacketProcessor(listener, flow_id, kRegular), 472 : PacketProcessor(listener, flow_id, kRegular),
436 kbps_(1200), 473 available_capacity_kbps_(kDefaultKbps),
437 last_send_time_us_(0), 474 last_send_time_us_(0),
438 delay_cap_helper_(new DelayCapHelper()) { 475 delay_cap_helper_(new DelayCapHelper()) {
476 running_flows_.insert(flow_id);
439 } 477 }
440 478
441 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, 479 ChokeFilter::ChokeFilter(PacketProcessorListener* listener,
442 const FlowIds& flow_ids) 480 const FlowIds& flow_ids)
443 : PacketProcessor(listener, flow_ids, kRegular), 481 : PacketProcessor(listener, flow_ids, kRegular),
444 kbps_(1200), 482 available_capacity_kbps_(kDefaultKbps),
stefan-webrtc 2015/06/25 14:44:04 Just capacity_kbps_
magalhaesc 2015/07/01 12:48:40 Done.
445 last_send_time_us_(0), 483 last_send_time_us_(0),
446 delay_cap_helper_(new DelayCapHelper()) { 484 delay_cap_helper_(new DelayCapHelper()),
485 running_flows_(flow_ids) {
486 }
487
488 void ChokeFilter::PauseFlow(int flow_id) {
489 running_flows_.erase(flow_id);
490 }
491
492 void ChokeFilter::ResumeFlow(int flow_id) {
493 running_flows_.insert(flow_id);
447 } 494 }
448 495
449 ChokeFilter::~ChokeFilter() {} 496 ChokeFilter::~ChokeFilter() {}
450 497
451 void ChokeFilter::SetCapacity(uint32_t kbps) { 498 void ChokeFilter::SetCapacityKbps(uint32_t kbps) {
452 BWE_TEST_LOGGING_ENABLE(false); 499 BWE_TEST_LOGGING_ENABLE(false);
453 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps); 500 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps);
454 kbps_ = kbps; 501 available_capacity_kbps_ = kbps;
455 } 502 }
456 503
457 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 504 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
458 assert(in_out); 505 assert(in_out);
459 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { 506 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) {
460 int64_t earliest_send_time_us = 507 int64_t earliest_send_time_us =
461 last_send_time_us_ + 508 last_send_time_us_ +
462 ((*it)->payload_size() * 8 * 1000 + kbps_ / 2) / kbps_; 509 ((*it)->payload_size() * 8 * 1000 + available_capacity_kbps_ / 2) /
510 available_capacity_kbps_;
463 int64_t new_send_time_us = 511 int64_t new_send_time_us =
464 std::max((*it)->send_time_us(), earliest_send_time_us); 512 std::max((*it)->send_time_us(), earliest_send_time_us);
465 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us, 513 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us,
466 (*it)->send_time_us())) { 514 (*it)->send_time_us())) {
467 (*it)->set_send_time_us(new_send_time_us); 515 (*it)->set_send_time_us(new_send_time_us);
516
517 (*it)->set_total_capacity_kbps(
518 static_cast<uint32_t>(available_capacity_kbps_));
519 uint32_t available_capacity_per_flow_kbps = 0;
520 if (running_flows_.find((*it)->flow_id()) != running_flows_.end()) {
521 available_capacity_per_flow_kbps =
522 available_capacity_kbps_ /
523 static_cast<uint32_t>(running_flows_.size());
524 }
525 (*it)->set_capacity_per_flow_kbps(available_capacity_per_flow_kbps);
stefan-webrtc 2015/06/25 14:44:04 If we are going to pass the capacity per flow with
magalhaesc 2015/07/01 12:48:40 Right, actually the capacity_per_flow field was re
526
468 last_send_time_us_ = new_send_time_us; 527 last_send_time_us_ = new_send_time_us;
469 ++it; 528 ++it;
470 } else { 529 } else {
471 delete *it; 530 delete *it;
472 it = in_out->erase(it); 531 it = in_out->erase(it);
473 } 532 }
474 } 533 }
475 } 534 }
476 535
477 void ChokeFilter::SetMaxDelay(int max_delay_ms) { 536 void ChokeFilter::SetMaxDelayMs(int64_t max_delay_ms) {
478 delay_cap_helper_->SetMaxDelay(max_delay_ms); 537 delay_cap_helper_->SetMaxDelayMs(max_delay_ms);
479 } 538 }
480 539
481 Stats<double> ChokeFilter::GetDelayStats() const { 540 Stats<double> ChokeFilter::GetDelayStats() const {
482 return delay_cap_helper_->delay_stats(); 541 return delay_cap_helper_->delay_stats();
483 } 542 }
484 543
485 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( 544 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter(
486 PacketProcessorListener* listener, 545 PacketProcessorListener* listener,
487 int flow_id) 546 int flow_id)
488 : PacketProcessor(listener, flow_id, kRegular), 547 : 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()) { 644 if (local_time_us_ >= (*it)->send_time_us()) {
586 (*it)->set_send_time_us(local_time_us_); 645 (*it)->set_send_time_us(local_time_us_);
587 ProceedToNextSlot(); 646 ProceedToNextSlot();
588 } 647 }
589 ++it; 648 ++it;
590 } 649 }
591 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); 650 packets_per_second_stats_.Push(rate_counter_->packets_per_second());
592 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); 651 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0);
593 } 652 }
594 653
595 void TraceBasedDeliveryFilter::SetMaxDelay(int max_delay_ms) { 654 void TraceBasedDeliveryFilter::SetMaxDelayMs(int64_t max_delay_ms) {
596 delay_cap_helper_->SetMaxDelay(max_delay_ms); 655 delay_cap_helper_->SetMaxDelayMs(max_delay_ms);
597 } 656 }
598 657
599 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { 658 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const {
600 return delay_cap_helper_->delay_stats(); 659 return delay_cap_helper_->delay_stats();
601 } 660 }
602 661
603 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { 662 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const {
604 return kbps_stats_; 663 return kbps_stats_;
605 } 664 }
606 665
(...skipping 17 matching lines...) Expand all
624 VideoSource::VideoSource(int flow_id, 683 VideoSource::VideoSource(int flow_id,
625 float fps, 684 float fps,
626 uint32_t kbps, 685 uint32_t kbps,
627 uint32_t ssrc, 686 uint32_t ssrc,
628 int64_t first_frame_offset_ms) 687 int64_t first_frame_offset_ms)
629 : kMaxPayloadSizeBytes(1200), 688 : kMaxPayloadSizeBytes(1200),
630 kTimestampBase(0xff80ff00ul), 689 kTimestampBase(0xff80ff00ul),
631 frame_period_ms_(1000.0 / fps), 690 frame_period_ms_(1000.0 / fps),
632 bits_per_second_(1000 * kbps), 691 bits_per_second_(1000 * kbps),
633 frame_size_bytes_(bits_per_second_ / 8 / fps), 692 frame_size_bytes_(bits_per_second_ / 8 / fps),
693 running_(true),
634 flow_id_(flow_id), 694 flow_id_(flow_id),
635 next_frame_ms_(first_frame_offset_ms), 695 next_frame_ms_(first_frame_offset_ms),
636 now_ms_(0), 696 now_ms_(0),
637 prototype_header_() { 697 prototype_header_(),
698 start_plotting_ms_(first_frame_offset_ms),
699 alg_name_() {
638 memset(&prototype_header_, 0, sizeof(prototype_header_)); 700 memset(&prototype_header_, 0, sizeof(prototype_header_));
639 prototype_header_.ssrc = ssrc; 701 prototype_header_.ssrc = ssrc;
640 prototype_header_.sequenceNumber = 0xf000u; 702 prototype_header_.sequenceNumber = 0xf000u;
641 } 703 }
642 704
643 uint32_t VideoSource::NextFrameSize() { 705 uint32_t VideoSource::NextFrameSize() {
644 return frame_size_bytes_; 706 return frame_size_bytes_;
645 } 707 }
646 708
647 uint32_t VideoSource::NextPacketSize(uint32_t frame_size, 709 uint32_t VideoSource::NextPacketSize(uint32_t frame_size,
648 uint32_t remaining_payload) { 710 uint32_t remaining_payload) {
649 return std::min(kMaxPayloadSizeBytes, remaining_payload); 711 return std::min(kMaxPayloadSizeBytes, remaining_payload);
650 } 712 }
651 713
652 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) { 714 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) {
653 assert(in_out); 715 assert(in_out);
654 std::stringstream ss; 716
655 ss << "SendEstimate_" << flow_id_ << "#1"; 717 if (plot_sending_estimate_) {
656 BWE_TEST_LOGGING_PLOT(0, ss.str(), now_ms_, bits_per_second_ / 1000); 718 std::stringstream ss;
719 ss << "SendEstimate_" << flow_id_ << "#1";
720 uint32_t plot_kbps = bits_per_second_ / 1000;
721 if (now_ms_ < start_plotting_ms_) {
722 plot_kbps = 0;
723 }
724 BWE_TEST_LOGGING_PLOT_WITH_NAME(0, ss.str(), now_ms_, plot_kbps, alg_name_);
725 // Silencing unused variable compiling error.
726 (void)plot_kbps;
stefan-webrtc 2015/06/25 14:44:04 RTC_UNUSED
magalhaesc 2015/07/01 12:48:40 This plot_sending_estimate, which was set false by
727 }
728
657 now_ms_ += time_ms; 729 now_ms_ += time_ms;
658 Packets new_packets; 730 Packets new_packets;
731
659 while (now_ms_ >= next_frame_ms_) { 732 while (now_ms_ >= next_frame_ms_) {
660 prototype_header_.timestamp = kTimestampBase + 733 prototype_header_.timestamp = kTimestampBase +
661 static_cast<uint32_t>(next_frame_ms_ * 90.0); 734 static_cast<uint32_t>(next_frame_ms_ * 90.0);
662 prototype_header_.extension.transmissionTimeOffset = 0; 735 prototype_header_.extension.transmissionTimeOffset = 0;
663 736
664 // Generate new packets for this frame, all with the same timestamp, 737 // 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 738 // 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 739 // one packet, we will see a number of equally sized packets followed by
667 // one smaller at the tail. 740 // one smaller at the tail.
741
668 int64_t send_time_us = next_frame_ms_ * 1000.0; 742 int64_t send_time_us = next_frame_ms_ * 1000.0;
669 uint32_t frame_size = NextFrameSize();
670 uint32_t payload_size = frame_size;
671 743
672 while (payload_size > 0) { 744 if (running_) {
745 uint32_t frame_size = NextFrameSize();
746 uint32_t payload_size = frame_size;
747
748 while (payload_size > 0) {
749 ++prototype_header_.sequenceNumber;
750 uint32_t size = NextPacketSize(frame_size, payload_size);
751 MediaPacket* new_packet =
752 new MediaPacket(flow_id_, send_time_us, size, prototype_header_);
753 new_packets.push_back(new_packet);
754 new_packet->SetAbsSendTimeMs(next_frame_ms_);
755 new_packet->set_sender_timestamp_us(send_time_us);
756 new_packet->set_sending_estimate_kbps(bits_per_second_ / 1000);
757 payload_size -= size;
758 }
759 } else {
760 int64_t send_time_us = next_frame_ms_ * 1000.0;
673 ++prototype_header_.sequenceNumber; 761 ++prototype_header_.sequenceNumber;
674 uint32_t size = NextPacketSize(frame_size, payload_size); 762 uint32_t size = 0;
675 MediaPacket* new_packet = 763 MediaPacket* new_packet =
676 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); 764 new MediaPacket(flow_id_, send_time_us, size, prototype_header_);
677 new_packets.push_back(new_packet); 765 new_packets.push_back(new_packet);
678 new_packet->SetAbsSendTimeMs(next_frame_ms_); 766 new_packet->SetAbsSendTimeMs(next_frame_ms_);
679 new_packet->set_sender_timestamp_us(send_time_us); 767 new_packet->set_sender_timestamp_us(send_time_us);
680 payload_size -= size; 768 new_packet->set_sending_estimate_kbps(bits_per_second_ / 1000);
stefan-webrtc 2015/06/25 14:44:04 If possible, I'd prefer to not have to set this.
magalhaesc 2015/07/01 12:48:40 Removed.
681 } 769 }
682 770
683 next_frame_ms_ += frame_period_ms_; 771 next_frame_ms_ +=
stefan-webrtc 2015/06/25 14:44:04 Add a comment saying that this adds a 1 ms uniform
magalhaesc 2015/07/01 12:48:40 Done.
772 frame_period_ms_ - 1 + 2 * static_cast<float>(rand()) / RAND_MAX;
684 } 773 }
774
685 in_out->merge(new_packets, DereferencingComparator<Packet>); 775 in_out->merge(new_packets, DereferencingComparator<Packet>);
686 } 776 }
687 777
778 void VideoSource::Pause() {
779 running_ = false;
780 SetBitrateBps(0);
stefan-webrtc 2015/06/25 14:44:04 I'm not sure it's correct to set to 0 here? I'd su
magalhaesc 2015/07/01 13:44:55 Done.
781 }
782
783 void VideoSource::Resume() {
784 running_ = true;
785 const int kResumeBitrateBps = 300 * 1000;
786 SetBitrateBps(kResumeBitrateBps);
stefan-webrtc 2015/06/25 14:44:04 I would actually suspect that we would resume at t
magalhaesc 2015/07/01 13:44:55 Ok, it will be left unchanged.
787 }
788
789 void AdaptiveVideoSource::SetBitrateBps(int bitrate_bps) {
790 if (!running_) {
791 bitrate_bps = 0;
792 }
793 bits_per_second_ = std::min(bitrate_bps, 2500000);
794 frame_size_bytes_ = (bits_per_second_ / 8 * frame_period_ms_ + 500) / 1000;
795 }
796
688 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id, 797 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id,
689 float fps, 798 float fps,
690 uint32_t kbps, 799 uint32_t kbps,
691 uint32_t ssrc, 800 uint32_t ssrc,
692 int64_t first_frame_offset_ms) 801 int64_t first_frame_offset_ms)
693 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) { 802 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) {
694 } 803 }
695 804
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, 805 PeriodicKeyFrameSource::PeriodicKeyFrameSource(int flow_id,
702 float fps, 806 float fps,
703 uint32_t kbps, 807 uint32_t kbps,
704 uint32_t ssrc, 808 uint32_t ssrc,
705 int64_t first_frame_offset_ms, 809 int64_t first_frame_offset_ms,
706 int key_frame_interval) 810 int key_frame_interval)
707 : AdaptiveVideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms), 811 : AdaptiveVideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms),
708 key_frame_interval_(key_frame_interval), 812 key_frame_interval_(key_frame_interval),
709 frame_counter_(0), 813 frame_counter_(0),
710 compensation_bytes_(0), 814 compensation_bytes_(0),
(...skipping 30 matching lines...) Expand all
741 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, 845 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size,
742 uint32_t remaining_payload) { 846 uint32_t remaining_payload) {
743 uint32_t fragments = 847 uint32_t fragments =
744 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; 848 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes;
745 uint32_t avg_size = (frame_size + fragments - 1) / fragments; 849 uint32_t avg_size = (frame_size + fragments - 1) / fragments;
746 return std::min(avg_size, remaining_payload); 850 return std::min(avg_size, remaining_payload);
747 } 851 }
748 } // namespace bwe 852 } // namespace bwe
749 } // namespace testing 853 } // namespace testing
750 } // namespace webrtc 854 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698