| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 26 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| 27 const FakeNetworkPipe::Config& config) | 27 const FakeNetworkPipe::Config& config) |
| 28 : FakeNetworkPipe(clock, config, 1) {} | 28 : FakeNetworkPipe(clock, config, 1) {} |
| 29 | 29 |
| 30 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 30 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| 31 const FakeNetworkPipe::Config& config, | 31 const FakeNetworkPipe::Config& config, |
| 32 uint64_t seed) | 32 uint64_t seed) |
| 33 : clock_(clock), | 33 : clock_(clock), |
| 34 packet_receiver_(NULL), | 34 packet_receiver_(NULL), |
| 35 random_(seed), | 35 random_(seed), |
| 36 config_(), | 36 config_(config), |
| 37 dropped_packets_(0), | 37 dropped_packets_(0), |
| 38 sent_packets_(0), | 38 sent_packets_(0), |
| 39 total_packet_delay_(0), | 39 total_packet_delay_(0), |
| 40 bursting_(false), | 40 bursting_(false), |
| 41 next_process_time_(clock_->TimeInMilliseconds()), | 41 next_process_time_(clock_->TimeInMilliseconds()), |
| 42 last_log_time_(clock_->TimeInMilliseconds()) { | 42 last_log_time_(clock_->TimeInMilliseconds()) { |
| 43 SetConfig(config); | |
| 44 } | |
| 45 | |
| 46 FakeNetworkPipe::~FakeNetworkPipe() { | |
| 47 while (!capacity_link_.empty()) { | |
| 48 delete capacity_link_.front(); | |
| 49 capacity_link_.pop(); | |
| 50 } | |
| 51 while (!delay_link_.empty()) { | |
| 52 delete *delay_link_.begin(); | |
| 53 delay_link_.erase(delay_link_.begin()); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void FakeNetworkPipe::SetReceiver(PacketReceiver* receiver) { | |
| 58 packet_receiver_ = receiver; | |
| 59 } | |
| 60 | |
| 61 void FakeNetworkPipe::SetConfig(const FakeNetworkPipe::Config& config) { | |
| 62 rtc::CritScope crit(&lock_); | |
| 63 config_ = config; // Shallow copy of the struct. | |
| 64 double prob_loss = config.loss_percent / 100.0; | 43 double prob_loss = config.loss_percent / 100.0; |
| 65 if (config_.avg_burst_loss_length == -1) { | 44 if (config_.avg_burst_loss_length == -1) { |
| 66 // Uniform loss | 45 // Uniform loss |
| 67 prob_loss_bursting_ = prob_loss; | 46 prob_loss_bursting_ = prob_loss; |
| 68 prob_start_bursting_ = prob_loss; | 47 prob_start_bursting_ = prob_loss; |
| 69 } else { | 48 } else { |
| 70 // Lose packets according to a gilbert-elliot model. | 49 // Lose packets according to a gilbert-elliot model. |
| 71 int avg_burst_loss_length = config.avg_burst_loss_length; | 50 int avg_burst_loss_length = config.avg_burst_loss_length; |
| 72 int min_avg_burst_loss_length = std::ceil(prob_loss / (1 - prob_loss)); | 51 int min_avg_burst_loss_length = std::ceil(prob_loss / (1 - prob_loss)); |
| 73 | 52 |
| 74 RTC_CHECK_GT(avg_burst_loss_length, min_avg_burst_loss_length) | 53 RTC_CHECK_GT(avg_burst_loss_length, min_avg_burst_loss_length) |
| 75 << "For a total packet loss of " << config.loss_percent << "%% then" | 54 << "For a total packet loss of " << config.loss_percent << "%% then" |
| 76 << " avg_burst_loss_length must be " << min_avg_burst_loss_length + 1 | 55 << " avg_burst_loss_length must be " << min_avg_burst_loss_length + 1 |
| 77 << " or higher."; | 56 << " or higher."; |
| 78 | 57 |
| 79 prob_loss_bursting_ = (1.0 - 1.0 / avg_burst_loss_length); | 58 prob_loss_bursting_ = (1.0 - 1.0 / avg_burst_loss_length); |
| 80 prob_start_bursting_ = prob_loss / (1 - prob_loss) / avg_burst_loss_length; | 59 prob_start_bursting_ = prob_loss / (1 - prob_loss) / avg_burst_loss_length; |
| 81 } | 60 } |
| 82 } | 61 } |
| 83 | 62 |
| 63 FakeNetworkPipe::~FakeNetworkPipe() { |
| 64 while (!capacity_link_.empty()) { |
| 65 delete capacity_link_.front(); |
| 66 capacity_link_.pop(); |
| 67 } |
| 68 while (!delay_link_.empty()) { |
| 69 delete *delay_link_.begin(); |
| 70 delay_link_.erase(delay_link_.begin()); |
| 71 } |
| 72 } |
| 73 |
| 74 void FakeNetworkPipe::SetReceiver(PacketReceiver* receiver) { |
| 75 packet_receiver_ = receiver; |
| 76 } |
| 77 |
| 78 void FakeNetworkPipe::SetConfig(const FakeNetworkPipe::Config& config) { |
| 79 rtc::CritScope crit(&lock_); |
| 80 config_ = config; // Shallow copy of the struct. |
| 81 } |
| 82 |
| 84 void FakeNetworkPipe::SendPacket(const uint8_t* data, size_t data_length) { | 83 void FakeNetworkPipe::SendPacket(const uint8_t* data, size_t data_length) { |
| 85 // A NULL packet_receiver_ means that this pipe will terminate the flow of | 84 // A NULL packet_receiver_ means that this pipe will terminate the flow of |
| 86 // packets. | 85 // packets. |
| 87 if (packet_receiver_ == NULL) | 86 if (packet_receiver_ == NULL) |
| 88 return; | 87 return; |
| 89 rtc::CritScope crit(&lock_); | 88 rtc::CritScope crit(&lock_); |
| 90 if (config_.queue_length_packets > 0 && | 89 if (config_.queue_length_packets > 0 && |
| 91 capacity_link_.size() >= config_.queue_length_packets) { | 90 capacity_link_.size() >= config_.queue_length_packets) { |
| 92 // Too many packet on the link, drop this one. | 91 // Too many packet on the link, drop this one. |
| 93 ++dropped_packets_; | 92 ++dropped_packets_; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { | 205 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { |
| 207 rtc::CritScope crit(&lock_); | 206 rtc::CritScope crit(&lock_); |
| 208 const int64_t kDefaultProcessIntervalMs = 5; | 207 const int64_t kDefaultProcessIntervalMs = 5; |
| 209 if (capacity_link_.empty() || delay_link_.empty()) | 208 if (capacity_link_.empty() || delay_link_.empty()) |
| 210 return kDefaultProcessIntervalMs; | 209 return kDefaultProcessIntervalMs; |
| 211 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), | 210 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), |
| 212 0); | 211 0); |
| 213 } | 212 } |
| 214 | 213 |
| 215 } // namespace webrtc | 214 } // namespace webrtc |
| OLD | NEW |