| 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 |
| 11 #include "webrtc/test/fake_network_pipe.h" | 11 #include "webrtc/test/fake_network_pipe.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <math.h> | 14 #include <math.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include <cmath> | 18 #include <cmath> |
| 19 | 19 |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/call/call.h" | 21 #include "webrtc/call/call.h" |
| 22 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 | 23 |
| 24 namespace webrtc { | 24 namespace webrtc { |
| 25 | 25 |
| 26 namespace { |
| 27 constexpr int64_t kDefaultProcessIntervalMs = 5; |
| 28 } |
| 29 |
| 26 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 30 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| 27 const FakeNetworkPipe::Config& config) | 31 const FakeNetworkPipe::Config& config) |
| 28 : FakeNetworkPipe(clock, config, 1) {} | 32 : FakeNetworkPipe(clock, config, 1) {} |
| 29 | 33 |
| 30 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 34 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| 31 const FakeNetworkPipe::Config& config, | 35 const FakeNetworkPipe::Config& config, |
| 32 uint64_t seed) | 36 uint64_t seed) |
| 33 : clock_(clock), | 37 : clock_(clock), |
| 34 packet_receiver_(NULL), | 38 packet_receiver_(NULL), |
| 35 random_(seed), | 39 random_(seed), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 172 |
| 169 // If reordering is not allowed then adjust arrival_time_jitter | 173 // If reordering is not allowed then adjust arrival_time_jitter |
| 170 // to make sure all packets are sent in order. | 174 // to make sure all packets are sent in order. |
| 171 if (!config_.allow_reordering && !delay_link_.empty() && | 175 if (!config_.allow_reordering && !delay_link_.empty() && |
| 172 packet->arrival_time() + arrival_time_jitter < | 176 packet->arrival_time() + arrival_time_jitter < |
| 173 (*delay_link_.rbegin())->arrival_time()) { | 177 (*delay_link_.rbegin())->arrival_time()) { |
| 174 arrival_time_jitter = | 178 arrival_time_jitter = |
| 175 (*delay_link_.rbegin())->arrival_time() - packet->arrival_time(); | 179 (*delay_link_.rbegin())->arrival_time() - packet->arrival_time(); |
| 176 } | 180 } |
| 177 packet->IncrementArrivalTime(arrival_time_jitter); | 181 packet->IncrementArrivalTime(arrival_time_jitter); |
| 178 if (packet->arrival_time() < next_process_time_) | |
| 179 next_process_time_ = packet->arrival_time(); | |
| 180 delay_link_.insert(packet); | 182 delay_link_.insert(packet); |
| 181 } | 183 } |
| 182 | 184 |
| 183 // Check the extra delay queue. | 185 // Check the extra delay queue. |
| 184 while (!delay_link_.empty() && | 186 while (!delay_link_.empty() && |
| 185 time_now >= (*delay_link_.begin())->arrival_time()) { | 187 time_now >= (*delay_link_.begin())->arrival_time()) { |
| 186 // Deliver this packet. | 188 // Deliver this packet. |
| 187 NetworkPacket* packet = *delay_link_.begin(); | 189 NetworkPacket* packet = *delay_link_.begin(); |
| 188 packets_to_deliver.push(packet); | 190 packets_to_deliver.push(packet); |
| 189 delay_link_.erase(delay_link_.begin()); | 191 delay_link_.erase(delay_link_.begin()); |
| 190 // |time_now| might be later than when the packet should have arrived, due | 192 // |time_now| might be later than when the packet should have arrived, due |
| 191 // to NetworkProcess being called too late. For stats, use the time it | 193 // to NetworkProcess being called too late. For stats, use the time it |
| 192 // should have been on the link. | 194 // should have been on the link. |
| 193 total_packet_delay_ += packet->arrival_time() - packet->send_time(); | 195 total_packet_delay_ += packet->arrival_time() - packet->send_time(); |
| 194 } | 196 } |
| 195 sent_packets_ += packets_to_deliver.size(); | 197 sent_packets_ += packets_to_deliver.size(); |
| 196 } | 198 } |
| 197 while (!packets_to_deliver.empty()) { | 199 while (!packets_to_deliver.empty()) { |
| 198 NetworkPacket* packet = packets_to_deliver.front(); | 200 NetworkPacket* packet = packets_to_deliver.front(); |
| 199 packets_to_deliver.pop(); | 201 packets_to_deliver.pop(); |
| 200 packet_receiver_->DeliverPacket(MediaType::ANY, packet->data(), | 202 packet_receiver_->DeliverPacket(MediaType::ANY, packet->data(), |
| 201 packet->data_length(), PacketTime()); | 203 packet->data_length(), PacketTime()); |
| 202 delete packet; | 204 delete packet; |
| 203 } | 205 } |
| 206 |
| 207 next_process_time_ = !delay_link_.empty() |
| 208 ? (*delay_link_.begin())->arrival_time() |
| 209 : time_now + kDefaultProcessIntervalMs; |
| 204 } | 210 } |
| 205 | 211 |
| 206 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { | 212 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { |
| 207 rtc::CritScope crit(&lock_); | 213 rtc::CritScope crit(&lock_); |
| 208 const int64_t kDefaultProcessIntervalMs = 5; | |
| 209 if (capacity_link_.empty() || delay_link_.empty()) | |
| 210 return kDefaultProcessIntervalMs; | |
| 211 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), | 214 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), |
| 212 0); | 215 0); |
| 213 } | 216 } |
| 214 | 217 |
| 215 } // namespace webrtc | 218 } // namespace webrtc |
| OLD | NEW |