Chromium Code Reviews| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 capacity_link_.size() >= config_.queue_length_packets) { | 125 capacity_link_.size() >= config_.queue_length_packets) { |
| 126 // Too many packet on the link, drop this one. | 126 // Too many packet on the link, drop this one. |
| 127 ++dropped_packets_; | 127 ++dropped_packets_; |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 int64_t time_now = clock_->TimeInMilliseconds(); | 131 int64_t time_now = clock_->TimeInMilliseconds(); |
| 132 | 132 |
| 133 // Delay introduced by the link capacity. | 133 // Delay introduced by the link capacity. |
| 134 int64_t capacity_delay_ms = 0; | 134 int64_t capacity_delay_ms = 0; |
| 135 if (config_.link_capacity_kbps > 0) | 135 if (config_.link_capacity_kbps > 0) { |
| 136 capacity_delay_ms = data_length / (config_.link_capacity_kbps / 8); | 136 const int bytes_per_millisecond = config_.link_capacity_kbps / 8; |
|
terelius
2017/09/04 12:19:39
nit: Would bytes_per_ms make the capacity_delay ca
| |
| 137 // To round to the closest millisecond we add half a milliseconds worth of | |
| 138 // bytes to the delay calculation. | |
| 139 capacity_delay_ms = (data_length + capacity_delay_error_bytes_ + | |
| 140 bytes_per_millisecond / 2) / | |
| 141 bytes_per_millisecond; | |
| 142 capacity_delay_error_bytes_ += | |
| 143 data_length - capacity_delay_ms * bytes_per_millisecond; | |
| 144 } | |
| 137 int64_t network_start_time = time_now; | 145 int64_t network_start_time = time_now; |
| 138 | 146 |
| 139 // Check if there already are packets on the link and change network start | 147 // Check if there already are packets on the link and change network start |
| 140 // time forward if there is. | 148 // time forward if there is. |
| 141 if (!capacity_link_.empty() && | 149 if (!capacity_link_.empty() && |
| 142 network_start_time < capacity_link_.back()->arrival_time()) | 150 network_start_time < capacity_link_.back()->arrival_time()) |
| 143 network_start_time = capacity_link_.back()->arrival_time(); | 151 network_start_time = capacity_link_.back()->arrival_time(); |
| 144 | 152 |
| 145 int64_t arrival_time = network_start_time + capacity_delay_ms; | 153 int64_t arrival_time = network_start_time + capacity_delay_ms; |
| 146 NetworkPacket* packet = new NetworkPacket(data, data_length, time_now, | 154 NetworkPacket* packet = new NetworkPacket(data, data_length, time_now, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 : time_now + kDefaultProcessIntervalMs; | 246 : time_now + kDefaultProcessIntervalMs; |
| 239 } | 247 } |
| 240 | 248 |
| 241 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { | 249 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { |
| 242 rtc::CritScope crit(&lock_); | 250 rtc::CritScope crit(&lock_); |
| 243 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), | 251 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), |
| 244 0); | 252 0); |
| 245 } | 253 } |
| 246 | 254 |
| 247 } // namespace webrtc | 255 } // namespace webrtc |
| OLD | NEW |