OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #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), creation_time_us_(-1), send_time_us_(-1), payload_size_(0) { |
126 } | 122 } |
127 | 123 |
128 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size) | 124 Packet::Packet(int flow_id, int64_t send_time_us, size_t payload_size) |
129 : flow_id_(flow_id), | 125 : flow_id_(flow_id), |
130 creation_time_us_(send_time_us), | 126 creation_time_us_(send_time_us), |
131 send_time_us_(send_time_us), | 127 send_time_us_(send_time_us), |
132 payload_size_(payload_size) { | 128 payload_size_(payload_size) { |
133 } | 129 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 return false; | 198 return false; |
203 } | 199 } |
204 last_it = it; | 200 last_it = it; |
205 } | 201 } |
206 return true; | 202 return true; |
207 } | 203 } |
208 | 204 |
209 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, | 205 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, |
210 int flow_id, | 206 int flow_id, |
211 ProcessorType type) | 207 ProcessorType type) |
212 : listener_(listener), flow_ids_(&flow_id, &flow_id + 1) { | 208 : rate_counter_(new RateCounter()), |
209 listener_(listener), | |
210 flow_ids_(&flow_id, &flow_id + 1) { | |
213 if (listener_) { | 211 if (listener_) { |
214 listener_->AddPacketProcessor(this, type); | 212 listener_->AddPacketProcessor(this, type); |
215 } | 213 } |
216 } | 214 } |
217 | 215 |
218 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, | 216 PacketProcessor::PacketProcessor(PacketProcessorListener* listener, |
219 const FlowIds& flow_ids, | 217 const FlowIds& flow_ids, |
220 ProcessorType type) | 218 ProcessorType type) |
221 : listener_(listener), flow_ids_(flow_ids) { | 219 : rate_counter_(new RateCounter()), |
220 listener_(listener), | |
221 flow_ids_(flow_ids) { | |
222 if (listener_) { | 222 if (listener_) { |
223 listener_->AddPacketProcessor(this, type); | 223 listener_->AddPacketProcessor(this, type); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 PacketProcessor::~PacketProcessor() { | 227 PacketProcessor::~PacketProcessor() { |
228 if (listener_) { | 228 if (listener_) { |
229 listener_->RemovePacketProcessor(this); | 229 listener_->RemovePacketProcessor(this); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 uint32_t PacketProcessor::packets_per_second() const { | |
234 return rate_counter_->packets_per_second(); | |
235 } | |
236 | |
237 uint32_t PacketProcessor::bits_per_second() const { | |
238 return rate_counter_->bits_per_second(); | |
239 } | |
stefan-webrtc
2015/07/02 11:03:41
Good suggestion to move this to the PacketProcesso
| |
240 | |
233 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, | 241 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, |
234 int flow_id, | 242 int flow_id, |
235 const char* name) | 243 const char* name) |
236 : PacketProcessor(listener, flow_id, kRegular), | 244 : PacketProcessor(listener, flow_id, kRegular), |
237 rate_counter_(new RateCounter()), | |
238 packets_per_second_stats_(), | 245 packets_per_second_stats_(), |
239 kbps_stats_(), | 246 kbps_stats_(), |
240 name_() { | 247 name_(), |
248 start_plotting_time_ms_(0) { | |
241 std::stringstream ss; | 249 std::stringstream ss; |
242 ss << name << "_" << flow_id; | 250 ss << name << "_" << flow_id; |
243 name_ = ss.str(); | 251 name_ = ss.str(); |
244 } | 252 } |
245 | 253 |
246 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, | 254 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, |
247 const FlowIds& flow_ids, | 255 const FlowIds& flow_ids, |
248 const char* name) | 256 const char* name) |
249 : PacketProcessor(listener, flow_ids, kRegular), | 257 : PacketProcessor(listener, flow_ids, kRegular), |
250 rate_counter_(new RateCounter()), | |
251 packets_per_second_stats_(), | 258 packets_per_second_stats_(), |
252 kbps_stats_(), | 259 kbps_stats_(), |
253 name_() { | 260 name_(), |
261 start_plotting_time_ms_(0) { | |
254 std::stringstream ss; | 262 std::stringstream ss; |
255 ss << name << "_"; | 263 ss << name << "_"; |
256 for (int flow_id : flow_ids) { | 264 for (int flow_id : flow_ids) { |
257 ss << flow_id << ","; | 265 ss << flow_id << ","; |
258 } | 266 } |
259 name_ = ss.str(); | 267 name_ = ss.str(); |
260 } | 268 } |
261 | 269 |
270 RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, | |
271 const FlowIds& flow_ids, | |
272 const char* name, | |
273 int64_t start_plotting_time_ms) | |
274 : RateCounterFilter(listener, flow_ids, name) { | |
275 start_plotting_time_ms_ = start_plotting_time_ms; | |
276 } | |
277 | |
262 RateCounterFilter::~RateCounterFilter() { | 278 RateCounterFilter::~RateCounterFilter() { |
263 LogStats(); | 279 LogStats(); |
264 } | 280 } |
265 | 281 |
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 | 282 |
274 void RateCounterFilter::LogStats() { | 283 void RateCounterFilter::LogStats() { |
275 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); | 284 BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); |
276 packets_per_second_stats_.Log("pps"); | 285 packets_per_second_stats_.Log("pps"); |
277 kbps_stats_.Log("kbps"); | 286 kbps_stats_.Log("kbps"); |
278 } | 287 } |
279 | 288 |
280 Stats<double> RateCounterFilter::GetBitrateStats() const { | 289 Stats<double> RateCounterFilter::GetBitrateStats() const { |
281 return kbps_stats_; | 290 return kbps_stats_; |
282 } | 291 } |
283 | 292 |
284 void RateCounterFilter::Plot(int64_t timestamp_ms) { | 293 void RateCounterFilter::Plot(int64_t timestamp_ms) { |
294 uint32_t plot_kbps = 0; | |
295 if (timestamp_ms >= start_plotting_time_ms_) { | |
296 plot_kbps = rate_counter_->bits_per_second() / 1000.0; | |
297 } | |
285 BWE_TEST_LOGGING_CONTEXT(name_.c_str()); | 298 BWE_TEST_LOGGING_CONTEXT(name_.c_str()); |
286 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, | 299 BWE_TEST_LOGGING_PLOT(0, "Throughput_#1", timestamp_ms, plot_kbps); |
287 rate_counter_->bits_per_second() / 1000.0); | 300 // Silencing unused variable compiling error. |
stefan-webrtc
2015/07/02 11:03:41
Remove this comment, RTC_UNUSED is enough
magalhaesc
2015/07/02 17:06:18
Done.
| |
301 RTC_UNUSED(plot_kbps); | |
288 } | 302 } |
289 | 303 |
290 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { | 304 void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { |
291 assert(in_out); | 305 assert(in_out); |
292 for (const Packet* packet : *in_out) { | 306 for (const Packet* packet : *in_out) { |
293 rate_counter_->UpdateRates(packet->send_time_us(), | 307 rate_counter_->UpdateRates(packet->send_time_us(), |
294 static_cast<int>(packet->payload_size())); | 308 static_cast<int>(packet->payload_size())); |
295 } | 309 } |
296 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); | 310 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); |
297 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); | 311 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); |
(...skipping 25 matching lines...) Expand all Loading... | |
323 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { | 337 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { |
324 if (random_.Rand() < loss_fraction_) { | 338 if (random_.Rand() < loss_fraction_) { |
325 delete *it; | 339 delete *it; |
326 it = in_out->erase(it); | 340 it = in_out->erase(it); |
327 } else { | 341 } else { |
328 ++it; | 342 ++it; |
329 } | 343 } |
330 } | 344 } |
331 } | 345 } |
332 | 346 |
347 const int64_t kDefaultOneWayDelayUs = 0; | |
348 | |
333 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id) | 349 DelayFilter::DelayFilter(PacketProcessorListener* listener, int flow_id) |
334 : PacketProcessor(listener, flow_id, kRegular), | 350 : PacketProcessor(listener, flow_id, kRegular), |
335 delay_us_(0), | 351 one_way_delay_us_(kDefaultOneWayDelayUs), |
336 last_send_time_us_(0) { | 352 last_send_time_us_(0) { |
337 } | 353 } |
338 | 354 |
339 DelayFilter::DelayFilter(PacketProcessorListener* listener, | 355 DelayFilter::DelayFilter(PacketProcessorListener* listener, |
340 const FlowIds& flow_ids) | 356 const FlowIds& flow_ids) |
341 : PacketProcessor(listener, flow_ids, kRegular), | 357 : PacketProcessor(listener, flow_ids, kRegular), |
342 delay_us_(0), | 358 one_way_delay_us_(kDefaultOneWayDelayUs), |
343 last_send_time_us_(0) { | 359 last_send_time_us_(0) { |
344 } | 360 } |
345 | 361 |
346 void DelayFilter::SetDelayMs(int64_t delay_ms) { | 362 void DelayFilter::SetOneWayDelayMs(int64_t one_way_delay_ms) { |
347 BWE_TEST_LOGGING_ENABLE(false); | 363 BWE_TEST_LOGGING_ENABLE(false); |
348 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(delay_ms)); | 364 BWE_TEST_LOGGING_LOG1("Delay", "%d ms", static_cast<int>(one_way_delay_ms)); |
349 assert(delay_ms >= 0); | 365 assert(one_way_delay_ms >= 0); |
350 delay_us_ = delay_ms * 1000; | 366 one_way_delay_us_ = one_way_delay_ms * 1000; |
351 } | 367 } |
352 | 368 |
353 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { | 369 void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { |
354 assert(in_out); | 370 assert(in_out); |
355 for (Packet* packet : *in_out) { | 371 for (Packet* packet : *in_out) { |
356 int64_t new_send_time_us = packet->send_time_us() + delay_us_; | 372 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); | 373 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us); |
358 packet->set_send_time_us(last_send_time_us_); | 374 packet->set_send_time_us(last_send_time_us_); |
359 } | 375 } |
360 } | 376 } |
361 | 377 |
362 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) | 378 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) |
363 : PacketProcessor(listener, flow_id, kRegular), | 379 : PacketProcessor(listener, flow_id, kRegular), |
364 random_(0x89674523), | 380 random_(0x89674523), |
365 stddev_jitter_us_(0), | 381 stddev_jitter_us_(0), |
366 last_send_time_us_(0) { | 382 last_send_time_us_(0) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 int64_t t2 = (*it)->send_time_us(); | 440 int64_t t2 = (*it)->send_time_us(); |
425 std::swap(*last_it, *it); | 441 std::swap(*last_it, *it); |
426 (*last_it)->set_send_time_us(t1); | 442 (*last_it)->set_send_time_us(t1); |
427 (*it)->set_send_time_us(t2); | 443 (*it)->set_send_time_us(t2); |
428 } | 444 } |
429 last_it = it; | 445 last_it = it; |
430 } | 446 } |
431 } | 447 } |
432 } | 448 } |
433 | 449 |
450 const uint32_t kDefaultKbps = 1200; | |
451 | |
434 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id) | 452 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, int flow_id) |
435 : PacketProcessor(listener, flow_id, kRegular), | 453 : PacketProcessor(listener, flow_id, kRegular), |
436 kbps_(1200), | 454 capacity_kbps_(kDefaultKbps), |
437 last_send_time_us_(0), | 455 last_send_time_us_(0), |
438 delay_cap_helper_(new DelayCapHelper()) { | 456 delay_cap_helper_(new DelayCapHelper()) { |
457 running_flows_.insert(flow_id); | |
439 } | 458 } |
440 | 459 |
441 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, | 460 ChokeFilter::ChokeFilter(PacketProcessorListener* listener, |
442 const FlowIds& flow_ids) | 461 const FlowIds& flow_ids) |
443 : PacketProcessor(listener, flow_ids, kRegular), | 462 : PacketProcessor(listener, flow_ids, kRegular), |
444 kbps_(1200), | 463 capacity_kbps_(kDefaultKbps), |
445 last_send_time_us_(0), | 464 last_send_time_us_(0), |
446 delay_cap_helper_(new DelayCapHelper()) { | 465 delay_cap_helper_(new DelayCapHelper()), |
466 running_flows_(flow_ids) { | |
467 } | |
468 | |
469 void ChokeFilter::PauseFlow(int flow_id) { | |
470 running_flows_.erase(flow_id); | |
471 } | |
472 | |
473 void ChokeFilter::ResumeFlow(int flow_id) { | |
474 running_flows_.insert(flow_id); | |
447 } | 475 } |
448 | 476 |
449 ChokeFilter::~ChokeFilter() {} | 477 ChokeFilter::~ChokeFilter() {} |
450 | 478 |
451 void ChokeFilter::SetCapacity(uint32_t kbps) { | 479 void ChokeFilter::SetCapacityKbps(uint32_t kbps) { |
452 BWE_TEST_LOGGING_ENABLE(false); | 480 BWE_TEST_LOGGING_ENABLE(false); |
453 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps); | 481 BWE_TEST_LOGGING_LOG1("BitrateChoke", "%d kbps", kbps); |
454 kbps_ = kbps; | 482 capacity_kbps_ = kbps; |
483 } | |
484 | |
485 uint32_t ChokeFilter::TotalAvailableKbps() { | |
486 return capacity_kbps_; | |
487 } | |
488 | |
489 uint32_t ChokeFilter::AvailablePerFlowKbps(int flow_id) { | |
stefan-webrtc
2015/07/02 11:03:41
Or just a getter for the total capacity, and then
magalhaesc
2015/07/02 17:06:18
Right, the per flow one was moved to a new class i
| |
490 uint32_t available_capacity_per_flow_kbps = 0; | |
491 if (running_flows_.find(flow_id) != running_flows_.end()) { | |
492 available_capacity_per_flow_kbps = | |
493 capacity_kbps_ / static_cast<uint32_t>(running_flows_.size()); | |
494 } | |
495 return available_capacity_per_flow_kbps; | |
455 } | 496 } |
456 | 497 |
457 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { | 498 void ChokeFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { |
458 assert(in_out); | 499 assert(in_out); |
459 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { | 500 for (PacketsIt it = in_out->begin(); it != in_out->end(); ) { |
460 int64_t earliest_send_time_us = | 501 int64_t earliest_send_time_us = |
461 last_send_time_us_ + | 502 last_send_time_us_ + |
462 ((*it)->payload_size() * 8 * 1000 + kbps_ / 2) / kbps_; | 503 ((*it)->payload_size() * 8 * 1000 + capacity_kbps_ / 2) / |
504 capacity_kbps_; | |
505 | |
463 int64_t new_send_time_us = | 506 int64_t new_send_time_us = |
464 std::max((*it)->send_time_us(), earliest_send_time_us); | 507 std::max((*it)->send_time_us(), earliest_send_time_us); |
508 | |
465 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us, | 509 if (delay_cap_helper_->ShouldSendPacket(new_send_time_us, |
466 (*it)->send_time_us())) { | 510 (*it)->send_time_us())) { |
467 (*it)->set_send_time_us(new_send_time_us); | 511 (*it)->set_send_time_us(new_send_time_us); |
468 last_send_time_us_ = new_send_time_us; | 512 last_send_time_us_ = new_send_time_us; |
469 ++it; | 513 ++it; |
470 } else { | 514 } else { |
471 delete *it; | 515 delete *it; |
472 it = in_out->erase(it); | 516 it = in_out->erase(it); |
473 } | 517 } |
474 } | 518 } |
475 } | 519 } |
476 | 520 |
477 void ChokeFilter::SetMaxDelay(int max_delay_ms) { | 521 void ChokeFilter::SetMaxDelayMs(int64_t max_delay_ms) { |
478 delay_cap_helper_->SetMaxDelay(max_delay_ms); | 522 delay_cap_helper_->SetMaxDelayMs(max_delay_ms); |
479 } | 523 } |
480 | 524 |
481 Stats<double> ChokeFilter::GetDelayStats() const { | 525 Stats<double> ChokeFilter::GetDelayStats() const { |
482 return delay_cap_helper_->delay_stats(); | 526 return delay_cap_helper_->delay_stats(); |
483 } | 527 } |
484 | 528 |
485 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( | 529 TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( |
486 PacketProcessorListener* listener, | 530 PacketProcessorListener* listener, |
487 int flow_id) | 531 int flow_id) |
488 : PacketProcessor(listener, flow_id, kRegular), | 532 : PacketProcessor(listener, flow_id, kRegular), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 if (local_time_us_ >= (*it)->send_time_us()) { | 629 if (local_time_us_ >= (*it)->send_time_us()) { |
586 (*it)->set_send_time_us(local_time_us_); | 630 (*it)->set_send_time_us(local_time_us_); |
587 ProceedToNextSlot(); | 631 ProceedToNextSlot(); |
588 } | 632 } |
589 ++it; | 633 ++it; |
590 } | 634 } |
591 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); | 635 packets_per_second_stats_.Push(rate_counter_->packets_per_second()); |
592 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); | 636 kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); |
593 } | 637 } |
594 | 638 |
595 void TraceBasedDeliveryFilter::SetMaxDelay(int max_delay_ms) { | 639 void TraceBasedDeliveryFilter::SetMaxDelayMs(int64_t max_delay_ms) { |
596 delay_cap_helper_->SetMaxDelay(max_delay_ms); | 640 delay_cap_helper_->SetMaxDelayMs(max_delay_ms); |
597 } | 641 } |
598 | 642 |
599 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { | 643 Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { |
600 return delay_cap_helper_->delay_stats(); | 644 return delay_cap_helper_->delay_stats(); |
601 } | 645 } |
602 | 646 |
603 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { | 647 Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { |
604 return kbps_stats_; | 648 return kbps_stats_; |
605 } | 649 } |
606 | 650 |
(...skipping 17 matching lines...) Expand all Loading... | |
624 VideoSource::VideoSource(int flow_id, | 668 VideoSource::VideoSource(int flow_id, |
625 float fps, | 669 float fps, |
626 uint32_t kbps, | 670 uint32_t kbps, |
627 uint32_t ssrc, | 671 uint32_t ssrc, |
628 int64_t first_frame_offset_ms) | 672 int64_t first_frame_offset_ms) |
629 : kMaxPayloadSizeBytes(1200), | 673 : kMaxPayloadSizeBytes(1200), |
630 kTimestampBase(0xff80ff00ul), | 674 kTimestampBase(0xff80ff00ul), |
631 frame_period_ms_(1000.0 / fps), | 675 frame_period_ms_(1000.0 / fps), |
632 bits_per_second_(1000 * kbps), | 676 bits_per_second_(1000 * kbps), |
633 frame_size_bytes_(bits_per_second_ / 8 / fps), | 677 frame_size_bytes_(bits_per_second_ / 8 / fps), |
678 running_(true), | |
634 flow_id_(flow_id), | 679 flow_id_(flow_id), |
635 next_frame_ms_(first_frame_offset_ms), | 680 next_frame_ms_(first_frame_offset_ms), |
636 now_ms_(0), | 681 now_ms_(0), |
637 prototype_header_() { | 682 prototype_header_(), |
683 start_plotting_ms_(first_frame_offset_ms) { | |
638 memset(&prototype_header_, 0, sizeof(prototype_header_)); | 684 memset(&prototype_header_, 0, sizeof(prototype_header_)); |
639 prototype_header_.ssrc = ssrc; | 685 prototype_header_.ssrc = ssrc; |
640 prototype_header_.sequenceNumber = 0xf000u; | 686 prototype_header_.sequenceNumber = 0xf000u; |
641 } | 687 } |
642 | 688 |
643 uint32_t VideoSource::NextFrameSize() { | 689 uint32_t VideoSource::NextFrameSize() { |
644 return frame_size_bytes_; | 690 return frame_size_bytes_; |
645 } | 691 } |
646 | 692 |
647 uint32_t VideoSource::NextPacketSize(uint32_t frame_size, | 693 uint32_t VideoSource::NextPacketSize(uint32_t frame_size, |
648 uint32_t remaining_payload) { | 694 uint32_t remaining_payload) { |
649 return std::min(kMaxPayloadSizeBytes, remaining_payload); | 695 return std::min(kMaxPayloadSizeBytes, remaining_payload); |
650 } | 696 } |
651 | 697 |
652 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) { | 698 void VideoSource::RunFor(int64_t time_ms, Packets* in_out) { |
653 assert(in_out); | 699 assert(in_out); |
654 std::stringstream ss; | 700 |
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; | 701 now_ms_ += time_ms; |
658 Packets new_packets; | 702 Packets new_packets; |
703 | |
659 while (now_ms_ >= next_frame_ms_) { | 704 while (now_ms_ >= next_frame_ms_) { |
660 prototype_header_.timestamp = kTimestampBase + | 705 prototype_header_.timestamp = kTimestampBase + |
661 static_cast<uint32_t>(next_frame_ms_ * 90.0); | 706 static_cast<uint32_t>(next_frame_ms_ * 90.0); |
662 prototype_header_.extension.transmissionTimeOffset = 0; | 707 prototype_header_.extension.transmissionTimeOffset = 0; |
663 | 708 |
664 // Generate new packets for this frame, all with the same timestamp, | 709 // 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 | 710 // 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 | 711 // one packet, we will see a number of equally sized packets followed by |
667 // one smaller at the tail. | 712 // one smaller at the tail. |
713 | |
668 int64_t send_time_us = next_frame_ms_ * 1000.0; | 714 int64_t send_time_us = next_frame_ms_ * 1000.0; |
669 uint32_t frame_size = NextFrameSize(); | |
670 uint32_t payload_size = frame_size; | |
671 | 715 |
672 while (payload_size > 0) { | 716 if (running_) { |
717 uint32_t frame_size = NextFrameSize(); | |
718 uint32_t payload_size = frame_size; | |
719 | |
720 while (payload_size > 0) { | |
721 ++prototype_header_.sequenceNumber; | |
722 uint32_t size = NextPacketSize(frame_size, payload_size); | |
723 MediaPacket* new_packet = | |
724 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); | |
725 new_packets.push_back(new_packet); | |
726 new_packet->SetAbsSendTimeMs(next_frame_ms_); | |
727 new_packet->set_sender_timestamp_us(send_time_us); | |
728 // dynamics_->set_sending_estimate_kbps(bits_per_second_ / 1000); | |
stefan-webrtc
2015/07/02 11:03:41
Can this and line 740 be removed?
magalhaesc
2015/07/02 17:06:18
Yes, removed
| |
729 payload_size -= size; | |
730 } | |
731 } else { | |
732 int64_t send_time_us = next_frame_ms_ * 1000.0; | |
673 ++prototype_header_.sequenceNumber; | 733 ++prototype_header_.sequenceNumber; |
674 uint32_t size = NextPacketSize(frame_size, payload_size); | 734 uint32_t size = 0; |
675 MediaPacket* new_packet = | 735 MediaPacket* new_packet = |
676 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); | 736 new MediaPacket(flow_id_, send_time_us, size, prototype_header_); |
stefan-webrtc
2015/07/02 11:03:41
Why exactly do we have to create empty packets whe
magalhaesc
2015/07/02 17:06:18
This was for plotting reasons, for not having a ju
| |
677 new_packets.push_back(new_packet); | 737 new_packets.push_back(new_packet); |
678 new_packet->SetAbsSendTimeMs(next_frame_ms_); | 738 new_packet->SetAbsSendTimeMs(next_frame_ms_); |
679 new_packet->set_sender_timestamp_us(send_time_us); | 739 new_packet->set_sender_timestamp_us(send_time_us); |
680 payload_size -= size; | 740 // dynamics_->set_sending_estimate_kbps(bits_per_second_ / 1000); |
681 } | 741 } |
682 | 742 |
683 next_frame_ms_ += frame_period_ms_; | 743 // A variance picked uniformly from {-1, 0, 1}ms is added to the frame |
stefan-webrtc
2015/07/02 11:03:41
Space between } and ms
magalhaesc
2015/07/02 17:06:18
Done.
| |
744 // timestamp. | |
745 next_frame_ms_ += | |
746 frame_period_ms_ - 1 + 2 * static_cast<float>(rand()) / RAND_MAX; | |
684 } | 747 } |
748 | |
685 in_out->merge(new_packets, DereferencingComparator<Packet>); | 749 in_out->merge(new_packets, DereferencingComparator<Packet>); |
686 } | 750 } |
687 | 751 |
752 void VideoSource::Pause() { | |
753 running_ = false; | |
754 } | |
755 | |
756 void VideoSource::Resume() { | |
757 running_ = true; | |
758 } | |
759 | |
760 void AdaptiveVideoSource::SetBitrateBps(int bitrate_bps) { | |
761 if (!running_) { | |
762 bitrate_bps = 0; | |
763 } | |
764 bits_per_second_ = std::min(bitrate_bps, 2500000); | |
765 frame_size_bytes_ = (bits_per_second_ / 8 * frame_period_ms_ + 500) / 1000; | |
766 } | |
767 | |
688 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id, | 768 AdaptiveVideoSource::AdaptiveVideoSource(int flow_id, |
689 float fps, | 769 float fps, |
690 uint32_t kbps, | 770 uint32_t kbps, |
691 uint32_t ssrc, | 771 uint32_t ssrc, |
692 int64_t first_frame_offset_ms) | 772 int64_t first_frame_offset_ms) |
693 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) { | 773 : VideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms) { |
694 } | 774 } |
695 | 775 |
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, | 776 PeriodicKeyFrameSource::PeriodicKeyFrameSource(int flow_id, |
702 float fps, | 777 float fps, |
703 uint32_t kbps, | 778 uint32_t kbps, |
704 uint32_t ssrc, | 779 uint32_t ssrc, |
705 int64_t first_frame_offset_ms, | 780 int64_t first_frame_offset_ms, |
706 int key_frame_interval) | 781 int key_frame_interval) |
707 : AdaptiveVideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms), | 782 : AdaptiveVideoSource(flow_id, fps, kbps, ssrc, first_frame_offset_ms), |
708 key_frame_interval_(key_frame_interval), | 783 key_frame_interval_(key_frame_interval), |
709 frame_counter_(0), | 784 frame_counter_(0), |
710 compensation_bytes_(0), | 785 compensation_bytes_(0), |
(...skipping 30 matching lines...) Expand all Loading... | |
741 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, | 816 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, |
742 uint32_t remaining_payload) { | 817 uint32_t remaining_payload) { |
743 uint32_t fragments = | 818 uint32_t fragments = |
744 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; | 819 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; |
745 uint32_t avg_size = (frame_size + fragments - 1) / fragments; | 820 uint32_t avg_size = (frame_size + fragments - 1) / fragments; |
746 return std::min(avg_size, remaining_payload); | 821 return std::min(avg_size, remaining_payload); |
747 } | 822 } |
748 } // namespace bwe | 823 } // namespace bwe |
749 } // namespace testing | 824 } // namespace testing |
750 } // namespace webrtc | 825 } // namespace webrtc |
OLD | NEW |