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

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

Issue 1333483002: Wire up PacketTime to ReceiveStreams. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 months 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.cc ('k') | webrtc/video/audio_receive_stream.h » ('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
(...skipping 11 matching lines...) Expand all
22 using ::testing::Invoke; 22 using ::testing::Invoke;
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 class MockReceiver : public PacketReceiver { 26 class MockReceiver : public PacketReceiver {
27 public: 27 public:
28 MockReceiver() {} 28 MockReceiver() {}
29 virtual ~MockReceiver() {} 29 virtual ~MockReceiver() {}
30 30
31 void IncomingPacket(const uint8_t* data, size_t length) { 31 void IncomingPacket(const uint8_t* data, size_t length) {
32 DeliverPacket(MediaType::ANY, data, length); 32 DeliverPacket(MediaType::ANY, data, length, PacketTime());
33 delete [] data; 33 delete [] data;
34 } 34 }
35 35
36 MOCK_METHOD3(DeliverPacket, 36 MOCK_METHOD4(
37 DeliveryStatus(MediaType, const uint8_t*, size_t)); 37 DeliverPacket,
38 DeliveryStatus(MediaType, const uint8_t*, size_t, const PacketTime&));
38 }; 39 };
39 40
40 class FakeNetworkPipeTest : public ::testing::Test { 41 class FakeNetworkPipeTest : public ::testing::Test {
41 protected: 42 protected:
42 virtual void SetUp() { 43 virtual void SetUp() {
43 TickTime::UseFakeClock(12345); 44 TickTime::UseFakeClock(12345);
44 receiver_.reset(new MockReceiver()); 45 receiver_.reset(new MockReceiver());
45 ON_CALL(*receiver_, DeliverPacket(_, _, _)) 46 ON_CALL(*receiver_, DeliverPacket(_, _, _, _))
46 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); 47 .WillByDefault(Return(PacketReceiver::DELIVERY_OK));
47 } 48 }
48 49
49 virtual void TearDown() { 50 virtual void TearDown() {
50 } 51 }
51 52
52 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) { 53 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) {
53 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]); 54 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]);
54 for (int i = 0; i < number_packets; ++i) { 55 for (int i = 0; i < number_packets; ++i) {
55 pipe->SendPacket(packet.get(), kPacketSize); 56 pipe->SendPacket(packet.get(), kPacketSize);
(...skipping 21 matching lines...) Expand all
77 // get through the pipe. 78 // get through the pipe.
78 const int kNumPackets = 10; 79 const int kNumPackets = 10;
79 const int kPacketSize = 1000; 80 const int kPacketSize = 1000;
80 SendPackets(pipe.get(), kNumPackets , kPacketSize); 81 SendPackets(pipe.get(), kNumPackets , kPacketSize);
81 82
82 // Time to get one packet through the link. 83 // Time to get one packet through the link.
83 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 84 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
84 kPacketSize); 85 kPacketSize);
85 86
86 // Time haven't increased yet, so we souldn't get any packets. 87 // Time haven't increased yet, so we souldn't get any packets.
87 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 88 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
88 .Times(0);
89 pipe->Process(); 89 pipe->Process();
90 90
91 // Advance enough time to release one packet. 91 // Advance enough time to release one packet.
92 TickTime::AdvanceFakeClock(kPacketTimeMs); 92 TickTime::AdvanceFakeClock(kPacketTimeMs);
93 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 93 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
94 .Times(1);
95 pipe->Process(); 94 pipe->Process();
96 95
97 // Release all but one packet 96 // Release all but one packet
98 TickTime::AdvanceFakeClock(9 * kPacketTimeMs - 1); 97 TickTime::AdvanceFakeClock(9 * kPacketTimeMs - 1);
99 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 98 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(8);
100 .Times(8);
101 pipe->Process(); 99 pipe->Process();
102 100
103 // And the last one. 101 // And the last one.
104 TickTime::AdvanceFakeClock(1); 102 TickTime::AdvanceFakeClock(1);
105 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 103 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
106 .Times(1);
107 pipe->Process(); 104 pipe->Process();
108 } 105 }
109 106
110 // Test the extra network delay. 107 // Test the extra network delay.
111 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { 108 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) {
112 FakeNetworkPipe::Config config; 109 FakeNetworkPipe::Config config;
113 config.queue_length_packets = 20; 110 config.queue_length_packets = 20;
114 config.queue_delay_ms = 100; 111 config.queue_delay_ms = 100;
115 config.link_capacity_kbps = 80; 112 config.link_capacity_kbps = 80;
116 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 113 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
117 pipe->SetReceiver(receiver_.get()); 114 pipe->SetReceiver(receiver_.get());
118 115
119 const int kNumPackets = 2; 116 const int kNumPackets = 2;
120 const int kPacketSize = 1000; 117 const int kPacketSize = 1000;
121 SendPackets(pipe.get(), kNumPackets , kPacketSize); 118 SendPackets(pipe.get(), kNumPackets , kPacketSize);
122 119
123 // Time to get one packet through the link. 120 // Time to get one packet through the link.
124 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 121 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
125 kPacketSize); 122 kPacketSize);
126 123
127 // Increase more than kPacketTimeMs, but not more than the extra delay. 124 // Increase more than kPacketTimeMs, but not more than the extra delay.
128 TickTime::AdvanceFakeClock(kPacketTimeMs); 125 TickTime::AdvanceFakeClock(kPacketTimeMs);
129 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 126 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
130 .Times(0);
131 pipe->Process(); 127 pipe->Process();
132 128
133 // Advance the network delay to get the first packet. 129 // Advance the network delay to get the first packet.
134 TickTime::AdvanceFakeClock(config.queue_delay_ms); 130 TickTime::AdvanceFakeClock(config.queue_delay_ms);
135 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 131 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
136 .Times(1);
137 pipe->Process(); 132 pipe->Process();
138 133
139 // Advance one more kPacketTimeMs to get the last packet. 134 // Advance one more kPacketTimeMs to get the last packet.
140 TickTime::AdvanceFakeClock(kPacketTimeMs); 135 TickTime::AdvanceFakeClock(kPacketTimeMs);
141 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 136 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
142 .Times(1);
143 pipe->Process(); 137 pipe->Process();
144 } 138 }
145 139
146 // Test the number of buffers and packets are dropped when sending too many 140 // Test the number of buffers and packets are dropped when sending too many
147 // packets too quickly. 141 // packets too quickly.
148 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { 142 TEST_F(FakeNetworkPipeTest, QueueLengthTest) {
149 FakeNetworkPipe::Config config; 143 FakeNetworkPipe::Config config;
150 config.queue_length_packets = 2; 144 config.queue_length_packets = 2;
151 config.link_capacity_kbps = 80; 145 config.link_capacity_kbps = 80;
152 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 146 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
153 pipe->SetReceiver(receiver_.get()); 147 pipe->SetReceiver(receiver_.get());
154 148
155 const int kPacketSize = 1000; 149 const int kPacketSize = 1000;
156 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 150 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
157 kPacketSize); 151 kPacketSize);
158 152
159 // Send three packets and verify only 2 are delivered. 153 // Send three packets and verify only 2 are delivered.
160 SendPackets(pipe.get(), 3, kPacketSize); 154 SendPackets(pipe.get(), 3, kPacketSize);
161 155
162 // Increase time enough to deliver all three packets, verify only two are 156 // Increase time enough to deliver all three packets, verify only two are
163 // delivered. 157 // delivered.
164 TickTime::AdvanceFakeClock(3 * kPacketTimeMs); 158 TickTime::AdvanceFakeClock(3 * kPacketTimeMs);
165 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 159 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
166 .Times(2);
167 pipe->Process(); 160 pipe->Process();
168 } 161 }
169 162
170 // Test we get statistics as expected. 163 // Test we get statistics as expected.
171 TEST_F(FakeNetworkPipeTest, StatisticsTest) { 164 TEST_F(FakeNetworkPipeTest, StatisticsTest) {
172 FakeNetworkPipe::Config config; 165 FakeNetworkPipe::Config config;
173 config.queue_length_packets = 2; 166 config.queue_length_packets = 2;
174 config.queue_delay_ms = 20; 167 config.queue_delay_ms = 20;
175 config.link_capacity_kbps = 80; 168 config.link_capacity_kbps = 80;
176 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 169 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
177 pipe->SetReceiver(receiver_.get()); 170 pipe->SetReceiver(receiver_.get());
178 171
179 const int kPacketSize = 1000; 172 const int kPacketSize = 1000;
180 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 173 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
181 kPacketSize); 174 kPacketSize);
182 175
183 // Send three packets and verify only 2 are delivered. 176 // Send three packets and verify only 2 are delivered.
184 SendPackets(pipe.get(), 3, kPacketSize); 177 SendPackets(pipe.get(), 3, kPacketSize);
185 TickTime::AdvanceFakeClock(3 * kPacketTimeMs + config.queue_delay_ms); 178 TickTime::AdvanceFakeClock(3 * kPacketTimeMs + config.queue_delay_ms);
186 179
187 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) 180 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
188 .Times(2);
189 pipe->Process(); 181 pipe->Process();
190 182
191 // Packet 1: kPacketTimeMs + config.queue_delay_ms, 183 // Packet 1: kPacketTimeMs + config.queue_delay_ms,
192 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. 184 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average.
193 EXPECT_EQ(pipe->AverageDelay(), 170); 185 EXPECT_EQ(pipe->AverageDelay(), 170);
194 EXPECT_EQ(pipe->sent_packets(), 2u); 186 EXPECT_EQ(pipe->sent_packets(), 2u);
195 EXPECT_EQ(pipe->dropped_packets(), 1u); 187 EXPECT_EQ(pipe->dropped_packets(), 1u);
196 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); 188 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f);
197 } 189 }
198 190
199 // Change the link capacity half-way through the test and verify that the 191 // Change the link capacity half-way through the test and verify that the
200 // delivery times change accordingly. 192 // delivery times change accordingly.
201 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { 193 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) {
202 FakeNetworkPipe::Config config; 194 FakeNetworkPipe::Config config;
203 config.queue_length_packets = 20; 195 config.queue_length_packets = 20;
204 config.link_capacity_kbps = 80; 196 config.link_capacity_kbps = 80;
205 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 197 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
206 pipe->SetReceiver(receiver_.get()); 198 pipe->SetReceiver(receiver_.get());
207 199
208 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to 200 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to
209 // get through the pipe. 201 // get through the pipe.
210 const int kNumPackets = 10; 202 const int kNumPackets = 10;
211 const int kPacketSize = 1000; 203 const int kPacketSize = 1000;
212 SendPackets(pipe.get(), kNumPackets, kPacketSize); 204 SendPackets(pipe.get(), kNumPackets, kPacketSize);
213 205
214 // Time to get one packet through the link. 206 // Time to get one packet through the link.
215 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 207 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
216 208
217 // Time hasn't increased yet, so we souldn't get any packets. 209 // Time hasn't increased yet, so we souldn't get any packets.
218 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); 210 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
219 pipe->Process(); 211 pipe->Process();
220 212
221 // Advance time in steps to release one packet at a time. 213 // Advance time in steps to release one packet at a time.
222 for (int i = 0; i < kNumPackets; ++i) { 214 for (int i = 0; i < kNumPackets; ++i) {
223 TickTime::AdvanceFakeClock(packet_time_ms); 215 TickTime::AdvanceFakeClock(packet_time_ms);
224 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); 216 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
225 pipe->Process(); 217 pipe->Process();
226 } 218 }
227 219
228 // Change the capacity. 220 // Change the capacity.
229 config.link_capacity_kbps /= 2; // Reduce to 50%. 221 config.link_capacity_kbps /= 2; // Reduce to 50%.
230 pipe->SetConfig(config); 222 pipe->SetConfig(config);
231 223
232 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two 224 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two
233 // seconds to get them through the pipe. 225 // seconds to get them through the pipe.
234 SendPackets(pipe.get(), kNumPackets, kPacketSize); 226 SendPackets(pipe.get(), kNumPackets, kPacketSize);
235 227
236 // Time to get one packet through the link. 228 // Time to get one packet through the link.
237 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 229 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
238 230
239 // Time hasn't increased yet, so we souldn't get any packets. 231 // Time hasn't increased yet, so we souldn't get any packets.
240 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); 232 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
241 pipe->Process(); 233 pipe->Process();
242 234
243 // Advance time in steps to release one packet at a time. 235 // Advance time in steps to release one packet at a time.
244 for (int i = 0; i < kNumPackets; ++i) { 236 for (int i = 0; i < kNumPackets; ++i) {
245 TickTime::AdvanceFakeClock(packet_time_ms); 237 TickTime::AdvanceFakeClock(packet_time_ms);
246 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); 238 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
247 pipe->Process(); 239 pipe->Process();
248 } 240 }
249 241
250 // Check that all the packets were sent. 242 // Check that all the packets were sent.
251 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); 243 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
252 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); 244 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess());
253 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); 245 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
254 pipe->Process(); 246 pipe->Process();
255 } 247 }
256 248
257 // Change the link capacity half-way through the test and verify that the 249 // Change the link capacity half-way through the test and verify that the
258 // delivery times change accordingly. 250 // delivery times change accordingly.
259 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { 251 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) {
260 FakeNetworkPipe::Config config; 252 FakeNetworkPipe::Config config;
261 config.queue_length_packets = 20; 253 config.queue_length_packets = 20;
262 config.link_capacity_kbps = 80; 254 config.link_capacity_kbps = 80;
263 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 255 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
(...skipping 12 matching lines...) Expand all
276 pipe->SetConfig(config); 268 pipe->SetConfig(config);
277 269
278 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two 270 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two
279 // seconds to get them through the pipe. 271 // seconds to get them through the pipe.
280 SendPackets(pipe.get(), kNumPackets, kPacketSize); 272 SendPackets(pipe.get(), kNumPackets, kPacketSize);
281 273
282 // Time to get one packet through the link at the new capacity. 274 // Time to get one packet through the link at the new capacity.
283 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 275 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
284 276
285 // Time hasn't increased yet, so we souldn't get any packets. 277 // Time hasn't increased yet, so we souldn't get any packets.
286 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); 278 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
287 pipe->Process(); 279 pipe->Process();
288 280
289 // Advance time in steps to release one packet at a time. 281 // Advance time in steps to release one packet at a time.
290 for (int i = 0; i < kNumPackets; ++i) { 282 for (int i = 0; i < kNumPackets; ++i) {
291 TickTime::AdvanceFakeClock(packet_time_1_ms); 283 TickTime::AdvanceFakeClock(packet_time_1_ms);
292 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); 284 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
293 pipe->Process(); 285 pipe->Process();
294 } 286 }
295 287
296 // Advance time in steps to release one packet at a time. 288 // Advance time in steps to release one packet at a time.
297 for (int i = 0; i < kNumPackets; ++i) { 289 for (int i = 0; i < kNumPackets; ++i) {
298 TickTime::AdvanceFakeClock(packet_time_2_ms); 290 TickTime::AdvanceFakeClock(packet_time_2_ms);
299 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); 291 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
300 pipe->Process(); 292 pipe->Process();
301 } 293 }
302 294
303 // Check that all the packets were sent. 295 // Check that all the packets were sent.
304 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); 296 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
305 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); 297 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess());
306 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); 298 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
307 pipe->Process(); 299 pipe->Process();
308 } 300 }
309 } // namespace webrtc 301 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fake_network_pipe.cc ('k') | webrtc/video/audio_receive_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698