| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 void DeleteMemory(uint8_t* data, int length) { delete [] data; } | 91 void DeleteMemory(uint8_t* data, int length) { delete [] data; } |
| 92 | 92 |
| 93 // Test the capacity link and verify we get as many packets as we expect. | 93 // Test the capacity link and verify we get as many packets as we expect. |
| 94 TEST_F(FakeNetworkPipeTest, CapacityTest) { | 94 TEST_F(FakeNetworkPipeTest, CapacityTest) { |
| 95 FakeNetworkPipe::Config config; | 95 FakeNetworkPipe::Config config; |
| 96 config.queue_length_packets = 20; | 96 config.queue_length_packets = 20; |
| 97 config.link_capacity_kbps = 80; | 97 config.link_capacity_kbps = 80; |
| 98 std::unique_ptr<FakeNetworkPipe> pipe( | 98 std::unique_ptr<FakeNetworkPipe> pipe( |
| 99 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 99 new FakeNetworkPipe(&fake_clock_, config)); |
| 100 pipe->SetReceiver(receiver_.get()); | 100 pipe->SetReceiver(receiver_.get()); |
| 101 | 101 |
| 102 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 102 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 103 // get through the pipe. | 103 // get through the pipe. |
| 104 const int kNumPackets = 10; | 104 const int kNumPackets = 10; |
| 105 const int kPacketSize = 1000; | 105 const int kPacketSize = 1000; |
| 106 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 106 SendPackets(pipe.get(), kNumPackets , kPacketSize); |
| 107 | 107 |
| 108 // Time to get one packet through the link. | 108 // Time to get one packet through the link. |
| 109 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 109 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 110 kPacketSize); | 110 kPacketSize); |
| 111 | 111 |
| 112 // Time haven't increased yet, so we souldn't get any packets. | 112 // Time haven't increased yet, so we souldn't get any packets. |
| 113 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 113 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 114 pipe->Process(); | 114 pipe->Process(); |
| 115 | 115 |
| 116 // Advance enough time to release one packet. | 116 // Advance enough time to release one packet. |
| 117 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); | 117 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); |
| 118 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 118 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 119 pipe->Process(); | 119 pipe->Process(); |
| 120 | 120 |
| 121 // Release all but one packet | 121 // Release all but one packet |
| 122 fake_clock_.AdvanceTimeMilliseconds(9 * kPacketTimeMs - 1); | 122 fake_clock_.AdvanceTimeMilliseconds(9 * kPacketTimeMs - 1); |
| 123 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(8); | 123 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(8); |
| 124 pipe->Process(); | 124 pipe->Process(); |
| 125 | 125 |
| 126 // And the last one. | 126 // And the last one. |
| 127 fake_clock_.AdvanceTimeMilliseconds(1); | 127 fake_clock_.AdvanceTimeMilliseconds(1); |
| 128 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 128 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 129 pipe->Process(); | 129 pipe->Process(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Test the extra network delay. | 132 // Test the extra network delay. |
| 133 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { | 133 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { |
| 134 FakeNetworkPipe::Config config; | 134 FakeNetworkPipe::Config config; |
| 135 config.queue_length_packets = 20; | 135 config.queue_length_packets = 20; |
| 136 config.queue_delay_ms = 100; | 136 config.queue_delay_ms = 100; |
| 137 config.link_capacity_kbps = 80; | 137 config.link_capacity_kbps = 80; |
| 138 std::unique_ptr<FakeNetworkPipe> pipe( | 138 std::unique_ptr<FakeNetworkPipe> pipe( |
| 139 new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); | 139 new FakeNetworkPipe(&fake_clock_, config)); |
| 140 pipe->SetReceiver(receiver_.get()); | 140 pipe->SetReceiver(receiver_.get()); |
| 141 | 141 |
| 142 const int kNumPackets = 2; | 142 const int kNumPackets = 2; |
| 143 const int kPacketSize = 1000; | 143 const int kPacketSize = 1000; |
| 144 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 144 SendPackets(pipe.get(), kNumPackets , kPacketSize); |
| 145 | 145 |
| 146 // Time to get one packet through the link. | 146 // Time to get one packet through the link. |
| 147 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 147 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 148 kPacketSize); | 148 kPacketSize); |
| 149 | 149 |
| 150 // Increase more than kPacketTimeMs, but not more than the extra delay. | 150 // Increase more than kPacketTimeMs, but not more than the extra delay. |
| 151 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); | 151 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); |
| 152 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); | 152 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 153 pipe->Process(); | 153 pipe->Process(); |
| 154 | 154 |
| 155 // Advance the network delay to get the first packet. | 155 // Advance the network delay to get the first packet. |
| 156 fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms); | 156 fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms); |
| 157 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 157 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 158 pipe->Process(); | 158 pipe->Process(); |
| 159 | 159 |
| 160 // Advance one more kPacketTimeMs to get the last packet. | 160 // Advance one more kPacketTimeMs to get the last packet. |
| 161 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); | 161 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); |
| 162 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 162 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 163 pipe->Process(); | 163 pipe->Process(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Test the number of buffers and packets are dropped when sending too many | 166 // Test the number of buffers and packets are dropped when sending too many |
| 167 // packets too quickly. | 167 // packets too quickly. |
| 168 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { | 168 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
| 169 FakeNetworkPipe::Config config; | 169 FakeNetworkPipe::Config config; |
| 170 config.queue_length_packets = 2; | 170 config.queue_length_packets = 2; |
| 171 config.link_capacity_kbps = 80; | 171 config.link_capacity_kbps = 80; |
| 172 std::unique_ptr<FakeNetworkPipe> pipe( | 172 std::unique_ptr<FakeNetworkPipe> pipe( |
| 173 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 173 new FakeNetworkPipe(&fake_clock_, config)); |
| 174 pipe->SetReceiver(receiver_.get()); | 174 pipe->SetReceiver(receiver_.get()); |
| 175 | 175 |
| 176 const int kPacketSize = 1000; | 176 const int kPacketSize = 1000; |
| 177 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 177 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 178 kPacketSize); | 178 kPacketSize); |
| 179 | 179 |
| 180 // Send three packets and verify only 2 are delivered. | 180 // Send three packets and verify only 2 are delivered. |
| 181 SendPackets(pipe.get(), 3, kPacketSize); | 181 SendPackets(pipe.get(), 3, kPacketSize); |
| 182 | 182 |
| 183 // Increase time enough to deliver all three packets, verify only two are | 183 // Increase time enough to deliver all three packets, verify only two are |
| 184 // delivered. | 184 // delivered. |
| 185 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); | 185 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); |
| 186 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); | 186 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); |
| 187 pipe->Process(); | 187 pipe->Process(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Test we get statistics as expected. | 190 // Test we get statistics as expected. |
| 191 TEST_F(FakeNetworkPipeTest, StatisticsTest) { | 191 TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
| 192 FakeNetworkPipe::Config config; | 192 FakeNetworkPipe::Config config; |
| 193 config.queue_length_packets = 2; | 193 config.queue_length_packets = 2; |
| 194 config.queue_delay_ms = 20; | 194 config.queue_delay_ms = 20; |
| 195 config.link_capacity_kbps = 80; | 195 config.link_capacity_kbps = 80; |
| 196 std::unique_ptr<FakeNetworkPipe> pipe( | 196 std::unique_ptr<FakeNetworkPipe> pipe( |
| 197 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 197 new FakeNetworkPipe(&fake_clock_, config)); |
| 198 pipe->SetReceiver(receiver_.get()); | 198 pipe->SetReceiver(receiver_.get()); |
| 199 | 199 |
| 200 const int kPacketSize = 1000; | 200 const int kPacketSize = 1000; |
| 201 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 201 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 202 kPacketSize); | 202 kPacketSize); |
| 203 | 203 |
| 204 // Send three packets and verify only 2 are delivered. | 204 // Send three packets and verify only 2 are delivered. |
| 205 SendPackets(pipe.get(), 3, kPacketSize); | 205 SendPackets(pipe.get(), 3, kPacketSize); |
| 206 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + | 206 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + |
| 207 config.queue_delay_ms); | 207 config.queue_delay_ms); |
| 208 | 208 |
| 209 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); | 209 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); |
| 210 pipe->Process(); | 210 pipe->Process(); |
| 211 | 211 |
| 212 // Packet 1: kPacketTimeMs + config.queue_delay_ms, | 212 // Packet 1: kPacketTimeMs + config.queue_delay_ms, |
| 213 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. | 213 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. |
| 214 EXPECT_EQ(pipe->AverageDelay(), 170); | 214 EXPECT_EQ(pipe->AverageDelay(), 170); |
| 215 EXPECT_EQ(pipe->sent_packets(), 2u); | 215 EXPECT_EQ(pipe->sent_packets(), 2u); |
| 216 EXPECT_EQ(pipe->dropped_packets(), 1u); | 216 EXPECT_EQ(pipe->dropped_packets(), 1u); |
| 217 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); | 217 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Change the link capacity half-way through the test and verify that the | 220 // Change the link capacity half-way through the test and verify that the |
| 221 // delivery times change accordingly. | 221 // delivery times change accordingly. |
| 222 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { | 222 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
| 223 FakeNetworkPipe::Config config; | 223 FakeNetworkPipe::Config config; |
| 224 config.queue_length_packets = 20; | 224 config.queue_length_packets = 20; |
| 225 config.link_capacity_kbps = 80; | 225 config.link_capacity_kbps = 80; |
| 226 std::unique_ptr<FakeNetworkPipe> pipe( | 226 std::unique_ptr<FakeNetworkPipe> pipe( |
| 227 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 227 new FakeNetworkPipe(&fake_clock_, config)); |
| 228 pipe->SetReceiver(receiver_.get()); | 228 pipe->SetReceiver(receiver_.get()); |
| 229 | 229 |
| 230 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 230 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 231 // get through the pipe. | 231 // get through the pipe. |
| 232 const int kNumPackets = 10; | 232 const int kNumPackets = 10; |
| 233 const int kPacketSize = 1000; | 233 const int kPacketSize = 1000; |
| 234 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 234 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 235 | 235 |
| 236 // Time to get one packet through the link. | 236 // Time to get one packet through the link. |
| 237 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 237 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 238 | 238 |
| 239 // Time hasn't increased yet, so we souldn't get any packets. | 239 // Time hasn't increased yet, so we souldn't get any packets. |
| 240 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 240 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 241 pipe->Process(); | 241 pipe->Process(); |
| 242 | 242 |
| 243 // Advance time in steps to release one packet at a time. | 243 // Advance time in steps to release one packet at a time. |
| 244 for (int i = 0; i < kNumPackets; ++i) { | 244 for (int i = 0; i < kNumPackets; ++i) { |
| 245 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); | 245 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); |
| 246 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 246 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 247 pipe->Process(); | 247 pipe->Process(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 // Change the capacity. | 250 // Change the capacity. |
| 251 config.link_capacity_kbps /= 2; // Reduce to 50%. | 251 config.link_capacity_kbps /= 2; // Reduce to 50%. |
| 252 pipe->SetConfig(config); | 252 pipe->SetConfig(config); |
| 253 | 253 |
| 254 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two | 254 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 255 // seconds to get them through the pipe. | 255 // seconds to get them through the pipe. |
| 256 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 256 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 257 | 257 |
| 258 // Time to get one packet through the link. | 258 // Time to get one packet through the link. |
| 259 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 259 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 260 | 260 |
| 261 // Time hasn't increased yet, so we souldn't get any packets. | 261 // Time hasn't increased yet, so we souldn't get any packets. |
| 262 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 262 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 263 pipe->Process(); | 263 pipe->Process(); |
| 264 | 264 |
| 265 // Advance time in steps to release one packet at a time. | 265 // Advance time in steps to release one packet at a time. |
| 266 for (int i = 0; i < kNumPackets; ++i) { | 266 for (int i = 0; i < kNumPackets; ++i) { |
| 267 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); | 267 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); |
| 268 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 268 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 269 pipe->Process(); | 269 pipe->Process(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Check that all the packets were sent. | 272 // Check that all the packets were sent. |
| 273 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); | 273 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); |
| 274 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); | 274 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); |
| 275 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 275 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 276 pipe->Process(); | 276 pipe->Process(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Change the link capacity half-way through the test and verify that the | 279 // Change the link capacity half-way through the test and verify that the |
| 280 // delivery times change accordingly. | 280 // delivery times change accordingly. |
| 281 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { | 281 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
| 282 FakeNetworkPipe::Config config; | 282 FakeNetworkPipe::Config config; |
| 283 config.queue_length_packets = 20; | 283 config.queue_length_packets = 20; |
| 284 config.link_capacity_kbps = 80; | 284 config.link_capacity_kbps = 80; |
| 285 std::unique_ptr<FakeNetworkPipe> pipe( | 285 std::unique_ptr<FakeNetworkPipe> pipe( |
| 286 new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); | 286 new FakeNetworkPipe(&fake_clock_, config)); |
| 287 pipe->SetReceiver(receiver_.get()); | 287 pipe->SetReceiver(receiver_.get()); |
| 288 | 288 |
| 289 // Add 10 packets of 1000 bytes, = 80 kb. | 289 // Add 10 packets of 1000 bytes, = 80 kb. |
| 290 const int kNumPackets = 10; | 290 const int kNumPackets = 10; |
| 291 const int kPacketSize = 1000; | 291 const int kPacketSize = 1000; |
| 292 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 292 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 293 | 293 |
| 294 // Time to get one packet through the link at the initial speed. | 294 // Time to get one packet through the link at the initial speed. |
| 295 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 295 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 296 | 296 |
| 297 // Change the capacity. | 297 // Change the capacity. |
| 298 config.link_capacity_kbps *= 2; // Double the capacity. | 298 config.link_capacity_kbps *= 2; // Double the capacity. |
| 299 pipe->SetConfig(config); | 299 pipe->SetConfig(config); |
| 300 | 300 |
| 301 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two | 301 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 302 // seconds to get them through the pipe. | 302 // seconds to get them through the pipe. |
| 303 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 303 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 304 | 304 |
| 305 // Time to get one packet through the link at the new capacity. | 305 // Time to get one packet through the link at the new capacity. |
| 306 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 306 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 307 | 307 |
| 308 // Time hasn't increased yet, so we souldn't get any packets. | 308 // Time hasn't increased yet, so we souldn't get any packets. |
| 309 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); | 309 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 310 pipe->Process(); | 310 pipe->Process(); |
| 311 | 311 |
| 312 // Advance time in steps to release one packet at a time. | 312 // Advance time in steps to release one packet at a time. |
| 313 for (int i = 0; i < kNumPackets; ++i) { | 313 for (int i = 0; i < kNumPackets; ++i) { |
| 314 fake_clock_.AdvanceTimeMilliseconds(packet_time_1_ms); | 314 fake_clock_.AdvanceTimeMilliseconds(packet_time_1_ms); |
| 315 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 315 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 316 pipe->Process(); | 316 pipe->Process(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Advance time in steps to release one packet at a time. | 319 // Advance time in steps to release one packet at a time. |
| 320 for (int i = 0; i < kNumPackets; ++i) { | 320 for (int i = 0; i < kNumPackets; ++i) { |
| 321 fake_clock_.AdvanceTimeMilliseconds(packet_time_2_ms); | 321 fake_clock_.AdvanceTimeMilliseconds(packet_time_2_ms); |
| 322 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 322 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
| 323 pipe->Process(); | 323 pipe->Process(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 // Check that all the packets were sent. | 326 // Check that all the packets were sent. |
| 327 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); | 327 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); |
| 328 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); | 328 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); |
| 329 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); | 329 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
| 330 pipe->Process(); | 330 pipe->Process(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // At first disallow reordering and then allow reordering. | 333 // At first disallow reordering and then allow reordering. |
| 334 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { | 334 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
| 335 FakeNetworkPipe::Config config; | 335 FakeNetworkPipe::Config config; |
| 336 config.queue_length_packets = 1000; | 336 config.queue_length_packets = 1000; |
| 337 config.link_capacity_kbps = 800; | 337 config.link_capacity_kbps = 800; |
| 338 config.queue_delay_ms = 100; | 338 config.queue_delay_ms = 100; |
| 339 config.delay_standard_deviation_ms = 10; | 339 config.delay_standard_deviation_ms = 10; |
| 340 std::unique_ptr<FakeNetworkPipe> pipe( | 340 std::unique_ptr<FakeNetworkPipe> pipe( |
| 341 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 341 new FakeNetworkPipe(&fake_clock_, config)); |
| 342 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | 342 ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
| 343 receiver_.reset(receiver); | 343 receiver_.reset(receiver); |
| 344 pipe->SetReceiver(receiver_.get()); | 344 pipe->SetReceiver(receiver_.get()); |
| 345 | 345 |
| 346 const uint32_t kNumPackets = 100; | 346 const uint32_t kNumPackets = 100; |
| 347 const int kPacketSize = 10; | 347 const int kPacketSize = 10; |
| 348 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 348 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 349 fake_clock_.AdvanceTimeMilliseconds(1000); | 349 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 350 pipe->Process(); | 350 pipe->Process(); |
| 351 | 351 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 const int kLossPercent = 5; | 383 const int kLossPercent = 5; |
| 384 const int kAvgBurstLength = 3; | 384 const int kAvgBurstLength = 3; |
| 385 const int kNumPackets = 10000; | 385 const int kNumPackets = 10000; |
| 386 const int kPacketSize = 10; | 386 const int kPacketSize = 10; |
| 387 | 387 |
| 388 FakeNetworkPipe::Config config; | 388 FakeNetworkPipe::Config config; |
| 389 config.queue_length_packets = kNumPackets; | 389 config.queue_length_packets = kNumPackets; |
| 390 config.loss_percent = kLossPercent; | 390 config.loss_percent = kLossPercent; |
| 391 config.avg_burst_loss_length = kAvgBurstLength; | 391 config.avg_burst_loss_length = kAvgBurstLength; |
| 392 std::unique_ptr<FakeNetworkPipe> pipe( | 392 std::unique_ptr<FakeNetworkPipe> pipe( |
| 393 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 393 new FakeNetworkPipe(&fake_clock_, config)); |
| 394 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | 394 ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
| 395 receiver_.reset(receiver); | 395 receiver_.reset(receiver); |
| 396 pipe->SetReceiver(receiver_.get()); | 396 pipe->SetReceiver(receiver_.get()); |
| 397 | 397 |
| 398 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 398 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 399 fake_clock_.AdvanceTimeMilliseconds(1000); | 399 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 400 pipe->Process(); | 400 pipe->Process(); |
| 401 | 401 |
| 402 // Check that the average loss is |kLossPercent| percent. | 402 // Check that the average loss is |kLossPercent| percent. |
| 403 int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); | 403 int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); |
| 404 double loss_fraction = lost_packets / static_cast<double>(kNumPackets); | 404 double loss_fraction = lost_packets / static_cast<double>(kNumPackets); |
| 405 | 405 |
| 406 EXPECT_NEAR(kLossPercent / 100.0, loss_fraction, 0.05); | 406 EXPECT_NEAR(kLossPercent / 100.0, loss_fraction, 0.05); |
| 407 | 407 |
| 408 // Find the number of bursts that has occurred. | 408 // Find the number of bursts that has occurred. |
| 409 size_t received_packets = receiver->delivered_sequence_numbers_.size(); | 409 size_t received_packets = receiver->delivered_sequence_numbers_.size(); |
| 410 int num_bursts = 0; | 410 int num_bursts = 0; |
| 411 for (size_t i = 0; i < received_packets - 1; ++i) { | 411 for (size_t i = 0; i < received_packets - 1; ++i) { |
| 412 int diff = receiver->delivered_sequence_numbers_[i + 1] - | 412 int diff = receiver->delivered_sequence_numbers_[i + 1] - |
| 413 receiver->delivered_sequence_numbers_[i]; | 413 receiver->delivered_sequence_numbers_[i]; |
| 414 if (diff > 1) | 414 if (diff > 1) |
| 415 ++num_bursts; | 415 ++num_bursts; |
| 416 } | 416 } |
| 417 | 417 |
| 418 double average_burst_length = static_cast<double>(lost_packets) / num_bursts; | 418 double average_burst_length = static_cast<double>(lost_packets) / num_bursts; |
| 419 | 419 |
| 420 EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.3); | 420 EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.3); |
| 421 } | 421 } |
| 422 } // namespace webrtc | 422 } // namespace webrtc |
| OLD | NEW |