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

Side by Side Diff: webrtc/test/fake_network_pipe.cc

Issue 1512853002: Nuke TickTime::UseFakeClock. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 5 years 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
« no previous file with comments | « webrtc/test/fake_network_pipe.h ('k') | webrtc/test/fake_network_pipe_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <algorithm> 16 #include <algorithm>
17 17
18 #include "webrtc/call.h" 18 #include "webrtc/call.h"
19 #include "webrtc/system_wrappers/include/tick_util.h" 19 #include "webrtc/system_wrappers/include/clock.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 const double kPi = 3.14159265; 23 const double kPi = 3.14159265;
24 24
25 static int GaussianRandom(int mean_delay_ms, int standard_deviation_ms) { 25 static int GaussianRandom(int mean_delay_ms, int standard_deviation_ms) {
26 // Creating a Normal distribution variable from two independent uniform 26 // Creating a Normal distribution variable from two independent uniform
27 // variables based on the Box-Muller transform. 27 // variables based on the Box-Muller transform.
28 double uniform1 = (rand() + 1.0) / (RAND_MAX + 1.0); // NOLINT 28 double uniform1 = (rand() + 1.0) / (RAND_MAX + 1.0); // NOLINT
29 double uniform2 = (rand() + 1.0) / (RAND_MAX + 1.0); // NOLINT 29 double uniform2 = (rand() + 1.0) / (RAND_MAX + 1.0); // NOLINT
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // The packet data. 63 // The packet data.
64 uint8_t* data_; 64 uint8_t* data_;
65 // Length of data_. 65 // Length of data_.
66 size_t data_length_; 66 size_t data_length_;
67 // The time the packet was sent out on the network. 67 // The time the packet was sent out on the network.
68 const int64_t send_time_; 68 const int64_t send_time_;
69 // The time the packet should arrive at the reciver. 69 // The time the packet should arrive at the reciver.
70 int64_t arrival_time_; 70 int64_t arrival_time_;
71 }; 71 };
72 72
73 FakeNetworkPipe::FakeNetworkPipe(const FakeNetworkPipe::Config& config) 73 FakeNetworkPipe::FakeNetworkPipe(Clock* clock,
74 : packet_receiver_(NULL), 74 const FakeNetworkPipe::Config& config)
75 : clock_(clock),
76 packet_receiver_(NULL),
75 config_(config), 77 config_(config),
76 dropped_packets_(0), 78 dropped_packets_(0),
77 sent_packets_(0), 79 sent_packets_(0),
78 total_packet_delay_(0), 80 total_packet_delay_(0),
79 next_process_time_(TickTime::MillisecondTimestamp()) { 81 next_process_time_(clock_->TimeInMilliseconds()) {}
80 }
81 82
82 FakeNetworkPipe::~FakeNetworkPipe() { 83 FakeNetworkPipe::~FakeNetworkPipe() {
83 while (!capacity_link_.empty()) { 84 while (!capacity_link_.empty()) {
84 delete capacity_link_.front(); 85 delete capacity_link_.front();
85 capacity_link_.pop(); 86 capacity_link_.pop();
86 } 87 }
87 while (!delay_link_.empty()) { 88 while (!delay_link_.empty()) {
88 delete delay_link_.front(); 89 delete delay_link_.front();
89 delay_link_.pop(); 90 delay_link_.pop();
90 } 91 }
(...skipping 14 matching lines...) Expand all
105 if (packet_receiver_ == NULL) 106 if (packet_receiver_ == NULL)
106 return; 107 return;
107 rtc::CritScope crit(&lock_); 108 rtc::CritScope crit(&lock_);
108 if (config_.queue_length_packets > 0 && 109 if (config_.queue_length_packets > 0 &&
109 capacity_link_.size() >= config_.queue_length_packets) { 110 capacity_link_.size() >= config_.queue_length_packets) {
110 // Too many packet on the link, drop this one. 111 // Too many packet on the link, drop this one.
111 ++dropped_packets_; 112 ++dropped_packets_;
112 return; 113 return;
113 } 114 }
114 115
115 int64_t time_now = TickTime::MillisecondTimestamp(); 116 int64_t time_now = clock_->TimeInMilliseconds();
116 117
117 // Delay introduced by the link capacity. 118 // Delay introduced by the link capacity.
118 int64_t capacity_delay_ms = 0; 119 int64_t capacity_delay_ms = 0;
119 if (config_.link_capacity_kbps > 0) 120 if (config_.link_capacity_kbps > 0)
120 capacity_delay_ms = data_length / (config_.link_capacity_kbps / 8); 121 capacity_delay_ms = data_length / (config_.link_capacity_kbps / 8);
121 int64_t network_start_time = time_now; 122 int64_t network_start_time = time_now;
122 123
123 // Check if there already are packets on the link and change network start 124 // Check if there already are packets on the link and change network start
124 // time if there is. 125 // time if there is.
125 if (capacity_link_.size() > 0) 126 if (capacity_link_.size() > 0)
(...skipping 16 matching lines...) Expand all
142 143
143 int FakeNetworkPipe::AverageDelay() { 144 int FakeNetworkPipe::AverageDelay() {
144 rtc::CritScope crit(&lock_); 145 rtc::CritScope crit(&lock_);
145 if (sent_packets_ == 0) 146 if (sent_packets_ == 0)
146 return 0; 147 return 0;
147 148
148 return total_packet_delay_ / static_cast<int>(sent_packets_); 149 return total_packet_delay_ / static_cast<int>(sent_packets_);
149 } 150 }
150 151
151 void FakeNetworkPipe::Process() { 152 void FakeNetworkPipe::Process() {
152 int64_t time_now = TickTime::MillisecondTimestamp(); 153 int64_t time_now = clock_->TimeInMilliseconds();
153 std::queue<NetworkPacket*> packets_to_deliver; 154 std::queue<NetworkPacket*> packets_to_deliver;
154 { 155 {
155 rtc::CritScope crit(&lock_); 156 rtc::CritScope crit(&lock_);
156 // Check the capacity link first. 157 // Check the capacity link first.
157 while (capacity_link_.size() > 0 && 158 while (capacity_link_.size() > 0 &&
158 time_now >= capacity_link_.front()->arrival_time()) { 159 time_now >= capacity_link_.front()->arrival_time()) {
159 // Time to get this packet. 160 // Time to get this packet.
160 NetworkPacket* packet = capacity_link_.front(); 161 NetworkPacket* packet = capacity_link_.front();
161 capacity_link_.pop(); 162 capacity_link_.pop();
162 163
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 packet->data_length(), PacketTime()); 204 packet->data_length(), PacketTime());
204 delete packet; 205 delete packet;
205 } 206 }
206 } 207 }
207 208
208 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { 209 int64_t FakeNetworkPipe::TimeUntilNextProcess() const {
209 rtc::CritScope crit(&lock_); 210 rtc::CritScope crit(&lock_);
210 const int64_t kDefaultProcessIntervalMs = 30; 211 const int64_t kDefaultProcessIntervalMs = 30;
211 if (capacity_link_.size() == 0 || delay_link_.size() == 0) 212 if (capacity_link_.size() == 0 || delay_link_.size() == 0)
212 return kDefaultProcessIntervalMs; 213 return kDefaultProcessIntervalMs;
213 return std::max<int64_t>( 214 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(),
214 next_process_time_ - TickTime::MillisecondTimestamp(), 0); 215 0);
215 } 216 }
216 217
217 } // namespace webrtc 218 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fake_network_pipe.h ('k') | webrtc/test/fake_network_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698