| 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 <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/call/call.h" | 13 #include "webrtc/call/call.h" |
| 14 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 14 #include "webrtc/system_wrappers/include/clock.h" | 15 #include "webrtc/system_wrappers/include/clock.h" |
| 15 #include "webrtc/test/fake_network_pipe.h" | 16 #include "webrtc/test/fake_network_pipe.h" |
| 16 #include "webrtc/test/gmock.h" | 17 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
| 18 | 19 |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
| 21 using ::testing::Return; | 22 using ::testing::Return; |
| 22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
| 23 | 24 |
| 24 namespace webrtc { | 25 namespace webrtc { |
| 25 | 26 |
| 27 namespace { |
| 28 |
| 29 constexpr uint8_t kDefaultVideoPayloadType = 102; |
| 30 |
| 31 constexpr size_t kMiniHeaderSize = 2; |
| 32 |
| 33 const std::map<uint8_t, MediaType> default_payload_type_map = { |
| 34 {kDefaultVideoPayloadType, MediaType::VIDEO}}; |
| 35 |
| 36 } // namespace |
| 37 |
| 26 class TestReceiver : public PacketReceiver { | 38 class TestReceiver : public PacketReceiver { |
| 27 public: | 39 public: |
| 28 TestReceiver() {} | 40 TestReceiver() {} |
| 29 virtual ~TestReceiver() {} | 41 virtual ~TestReceiver() {} |
| 30 | 42 |
| 31 void IncomingPacket(const uint8_t* data, size_t length) { | 43 void IncomingPacket(const uint8_t* data, size_t length) { |
| 32 DeliverPacket(MediaType::ANY, data, length, PacketTime()); | 44 DeliverPacket(MediaType::ANY, data, length, PacketTime()); |
| 33 delete [] data; | 45 delete [] data; |
| 34 } | 46 } |
| 35 | 47 |
| 36 virtual MOCK_METHOD4( | 48 virtual MOCK_METHOD4( |
| 37 DeliverPacket, | 49 DeliverPacket, |
| 38 DeliveryStatus(MediaType, const uint8_t*, size_t, const PacketTime&)); | 50 DeliveryStatus(MediaType, const uint8_t*, size_t, const PacketTime&)); |
| 39 }; | 51 }; |
| 40 | 52 |
| 41 class ReorderTestReceiver : public TestReceiver { | 53 class ReorderTestReceiver : public TestReceiver { |
| 42 public: | 54 public: |
| 43 ReorderTestReceiver() {} | 55 ReorderTestReceiver() {} |
| 44 virtual ~ReorderTestReceiver() {} | 56 virtual ~ReorderTestReceiver() {} |
| 45 | 57 |
| 46 DeliveryStatus DeliverPacket(MediaType media_type, | 58 DeliveryStatus DeliverPacket(MediaType media_type, |
| 47 const uint8_t* packet, | 59 const uint8_t* packet, |
| 48 size_t length, | 60 size_t length, |
| 49 const PacketTime& packet_time) override { | 61 const PacketTime& packet_time) override { |
| 62 RTC_DCHECK_GE(length, kMiniHeaderSize + sizeof(int)); |
| 50 int seq_num; | 63 int seq_num; |
| 51 memcpy(&seq_num, packet, sizeof(int)); | 64 memcpy(&seq_num, &packet[kMiniHeaderSize], sizeof(int)); |
| 52 delivered_sequence_numbers_.push_back(seq_num); | 65 delivered_sequence_numbers_.push_back(seq_num); |
| 53 return PacketReceiver::DELIVERY_OK; | 66 return PacketReceiver::DELIVERY_OK; |
| 54 } | 67 } |
| 55 std::vector<int> delivered_sequence_numbers_; | 68 std::vector<int> delivered_sequence_numbers_; |
| 56 }; | 69 }; |
| 57 | 70 |
| 58 class FakeNetworkPipeTest : public ::testing::Test { | 71 class FakeNetworkPipeTest : public ::testing::Test { |
| 59 public: | 72 public: |
| 60 FakeNetworkPipeTest() : fake_clock_(12345) {} | 73 FakeNetworkPipeTest() : fake_clock_(12345) {} |
| 61 | 74 |
| 62 protected: | 75 protected: |
| 63 virtual void SetUp() { | 76 virtual void SetUp() { |
| 64 receiver_.reset(new TestReceiver()); | 77 receiver_.reset(new TestReceiver()); |
| 65 ON_CALL(*receiver_, DeliverPacket(_, _, _, _)) | 78 ON_CALL(*receiver_, DeliverPacket(_, _, _, _)) |
| 66 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); | 79 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); |
| 67 } | 80 } |
| 68 | 81 |
| 69 virtual void TearDown() { | 82 virtual void TearDown() { |
| 70 } | 83 } |
| 71 | 84 |
| 72 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int packet_size) { | 85 void SendPackets(FakeNetworkPipe* pipe, |
| 73 RTC_DCHECK_GE(packet_size, sizeof(int)); | 86 int number_packets, |
| 87 int packet_size, |
| 88 uint8_t payload_type) { |
| 89 RTC_DCHECK_GE(packet_size, kMiniHeaderSize + sizeof(int)); |
| 90 RTC_DCHECK_LE(payload_type, 0x7f); |
| 91 // packet[0 .. 1] is reserved for header. |
| 74 std::unique_ptr<uint8_t[]> packet(new uint8_t[packet_size]); | 92 std::unique_ptr<uint8_t[]> packet(new uint8_t[packet_size]); |
| 93 RTC_DCHECK(!RtpHeaderParser::IsRtcp(packet.get(), packet_size)); |
| 94 packet[1] = payload_type; |
| 75 for (int i = 0; i < number_packets; ++i) { | 95 for (int i = 0; i < number_packets; ++i) { |
| 76 // Set a sequence number for the packets by | 96 // Insert a sequence number for the packets. |
| 77 // using the first bytes in the packet. | 97 memcpy(&packet[kMiniHeaderSize], &i, sizeof(int)); |
| 78 memcpy(packet.get(), &i, sizeof(int)); | |
| 79 pipe->SendPacket(packet.get(), packet_size); | 98 pipe->SendPacket(packet.get(), packet_size); |
| 80 } | 99 } |
| 81 } | 100 } |
| 82 | 101 |
| 83 int PacketTimeMs(int capacity_kbps, int packet_size) const { | 102 int PacketTimeMs(int capacity_kbps, int packet_size) const { |
| 84 return 8 * packet_size / capacity_kbps; | 103 return 8 * packet_size / capacity_kbps; |
| 85 } | 104 } |
| 86 | 105 |
| 87 SimulatedClock fake_clock_; | 106 SimulatedClock fake_clock_; |
| 88 std::unique_ptr<TestReceiver> receiver_; | 107 std::unique_ptr<TestReceiver> receiver_; |
| 89 }; | 108 }; |
| 90 | 109 |
| 91 void DeleteMemory(uint8_t* data, int length) { delete [] data; } | 110 void DeleteMemory(uint8_t* data, int length) { delete [] data; } |
| 92 | 111 |
| 93 // Test the capacity link and verify we get as many packets as we expect. | 112 // Test the capacity link and verify we get as many packets as we expect. |
| 94 TEST_F(FakeNetworkPipeTest, CapacityTest) { | 113 TEST_F(FakeNetworkPipeTest, CapacityTest) { |
| 95 FakeNetworkPipe::Config config; | 114 FakeNetworkPipe::Config config; |
| 96 config.queue_length_packets = 20; | 115 config.queue_length_packets = 20; |
| 97 config.link_capacity_kbps = 80; | 116 config.link_capacity_kbps = 80; |
| 98 std::unique_ptr<FakeNetworkPipe> pipe( | 117 std::unique_ptr<FakeNetworkPipe> pipe( |
| 99 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 118 new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
| 100 pipe->SetReceiver(receiver_.get()); | 119 pipe->SetReceiver(receiver_.get()); |
| 101 | 120 |
| 102 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 121 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 103 // get through the pipe. | 122 // get through the pipe. |
| 104 const int kNumPackets = 10; | 123 const int kNumPackets = 10; |
| 105 const int kPacketSize = 1000; | 124 const int kPacketSize = 1000; |
| 106 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 125 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 107 | 126 |
| 108 // Time to get one packet through the link. | 127 // Time to get one packet through the link. |
| 109 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 128 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 110 kPacketSize); | 129 kPacketSize); |
| 111 | 130 |
| 112 // Time haven't increased yet, so we souldn't get any packets. | 131 // Time haven't increased yet, so we souldn't get any packets. |
| 113 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 132 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); |
| 114 pipe->Process(); | 133 pipe->Process(); |
| 115 | 134 |
| 116 // Advance enough time to release one packet. | 135 // Advance enough time to release one packet. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 147 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); |
| 129 pipe->Process(); | 148 pipe->Process(); |
| 130 } | 149 } |
| 131 | 150 |
| 132 // Test the extra network delay. | 151 // Test the extra network delay. |
| 133 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { | 152 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { |
| 134 FakeNetworkPipe::Config config; | 153 FakeNetworkPipe::Config config; |
| 135 config.queue_length_packets = 20; | 154 config.queue_length_packets = 20; |
| 136 config.queue_delay_ms = 100; | 155 config.queue_delay_ms = 100; |
| 137 config.link_capacity_kbps = 80; | 156 config.link_capacity_kbps = 80; |
| 138 std::unique_ptr<FakeNetworkPipe> pipe( | 157 constexpr uint8_t kDefaultAudioPayloadType = 120; |
| 139 new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); | 158 std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
| 159 &fake_clock_, config, {{kDefaultAudioPayloadType, MediaType::AUDIO}})); |
| 140 pipe->SetReceiver(receiver_.get()); | 160 pipe->SetReceiver(receiver_.get()); |
| 141 | 161 |
| 142 const int kNumPackets = 2; | 162 const int kNumPackets = 2; |
| 143 const int kPacketSize = 1000; | 163 const int kPacketSize = 1000; |
| 144 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 164 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
| 145 | 165 |
| 146 // Time to get one packet through the link. | 166 // Time to get one packet through the link. |
| 147 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 167 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 148 kPacketSize); | 168 kPacketSize); |
| 149 | 169 |
| 150 // Increase more than kPacketTimeMs, but not more than the extra delay. | 170 // Increase more than kPacketTimeMs, but not more than the extra delay. |
| 151 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); | 171 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); |
| 152 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); | 172 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); |
| 153 pipe->Process(); | 173 pipe->Process(); |
| 154 | 174 |
| 155 // Advance the network delay to get the first packet. | 175 // Advance the network delay to get the first packet. |
| 156 fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms); | 176 fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms); |
| 157 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 177 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); |
| 158 pipe->Process(); | 178 pipe->Process(); |
| 159 | 179 |
| 160 // Advance one more kPacketTimeMs to get the last packet. | 180 // Advance one more kPacketTimeMs to get the last packet. |
| 161 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); | 181 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs); |
| 162 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); | 182 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(1); |
| 163 pipe->Process(); | 183 pipe->Process(); |
| 164 } | 184 } |
| 165 | 185 |
| 166 // Test the number of buffers and packets are dropped when sending too many | 186 // Test the number of buffers and packets are dropped when sending too many |
| 167 // packets too quickly. | 187 // packets too quickly. |
| 168 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { | 188 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
| 169 FakeNetworkPipe::Config config; | 189 FakeNetworkPipe::Config config; |
| 170 config.queue_length_packets = 2; | 190 config.queue_length_packets = 2; |
| 171 config.link_capacity_kbps = 80; | 191 config.link_capacity_kbps = 80; |
| 172 std::unique_ptr<FakeNetworkPipe> pipe( | 192 std::unique_ptr<FakeNetworkPipe> pipe( |
| 173 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 193 new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
| 174 pipe->SetReceiver(receiver_.get()); | 194 pipe->SetReceiver(receiver_.get()); |
| 175 | 195 |
| 176 const int kPacketSize = 1000; | 196 const int kPacketSize = 1000; |
| 177 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 197 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 178 kPacketSize); | 198 kPacketSize); |
| 179 | 199 |
| 180 // Send three packets and verify only 2 are delivered. | 200 // Send three packets and verify only 2 are delivered. |
| 181 SendPackets(pipe.get(), 3, kPacketSize); | 201 SendPackets(pipe.get(), 3, kPacketSize, kDefaultVideoPayloadType); |
| 182 | 202 |
| 183 // Increase time enough to deliver all three packets, verify only two are | 203 // Increase time enough to deliver all three packets, verify only two are |
| 184 // delivered. | 204 // delivered. |
| 185 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); | 205 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); |
| 186 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); | 206 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); |
| 187 pipe->Process(); | 207 pipe->Process(); |
| 188 } | 208 } |
| 189 | 209 |
| 190 // Test we get statistics as expected. | 210 // Test we get statistics as expected. |
| 191 TEST_F(FakeNetworkPipeTest, StatisticsTest) { | 211 TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
| 192 FakeNetworkPipe::Config config; | 212 FakeNetworkPipe::Config config; |
| 193 config.queue_length_packets = 2; | 213 config.queue_length_packets = 2; |
| 194 config.queue_delay_ms = 20; | 214 config.queue_delay_ms = 20; |
| 195 config.link_capacity_kbps = 80; | 215 config.link_capacity_kbps = 80; |
| 196 std::unique_ptr<FakeNetworkPipe> pipe( | 216 std::unique_ptr<FakeNetworkPipe> pipe( |
| 197 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 217 new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
| 198 pipe->SetReceiver(receiver_.get()); | 218 pipe->SetReceiver(receiver_.get()); |
| 199 | 219 |
| 200 const int kPacketSize = 1000; | 220 const int kPacketSize = 1000; |
| 201 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 221 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 202 kPacketSize); | 222 kPacketSize); |
| 203 | 223 |
| 204 // Send three packets and verify only 2 are delivered. | 224 // Send three packets and verify only 2 are delivered. |
| 205 SendPackets(pipe.get(), 3, kPacketSize); | 225 SendPackets(pipe.get(), 3, kPacketSize, kDefaultVideoPayloadType); |
| 206 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + | 226 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + |
| 207 config.queue_delay_ms); | 227 config.queue_delay_ms); |
| 208 | 228 |
| 209 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); | 229 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(2); |
| 210 pipe->Process(); | 230 pipe->Process(); |
| 211 | 231 |
| 212 // Packet 1: kPacketTimeMs + config.queue_delay_ms, | 232 // Packet 1: kPacketTimeMs + config.queue_delay_ms, |
| 213 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. | 233 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. |
| 214 EXPECT_EQ(pipe->AverageDelay(), 170); | 234 EXPECT_EQ(pipe->AverageDelay(), 170); |
| 215 EXPECT_EQ(pipe->sent_packets(), 2u); | 235 EXPECT_EQ(pipe->sent_packets(), 2u); |
| 216 EXPECT_EQ(pipe->dropped_packets(), 1u); | 236 EXPECT_EQ(pipe->dropped_packets(), 1u); |
| 217 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); | 237 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); |
| 218 } | 238 } |
| 219 | 239 |
| 220 // Change the link capacity half-way through the test and verify that the | 240 // Change the link capacity half-way through the test and verify that the |
| 221 // delivery times change accordingly. | 241 // delivery times change accordingly. |
| 222 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { | 242 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
| 223 FakeNetworkPipe::Config config; | 243 FakeNetworkPipe::Config config; |
| 224 config.queue_length_packets = 20; | 244 config.queue_length_packets = 20; |
| 225 config.link_capacity_kbps = 80; | 245 config.link_capacity_kbps = 80; |
| 226 std::unique_ptr<FakeNetworkPipe> pipe( | 246 std::unique_ptr<FakeNetworkPipe> pipe( |
| 227 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 247 new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
| 228 pipe->SetReceiver(receiver_.get()); | 248 pipe->SetReceiver(receiver_.get()); |
| 229 | 249 |
| 230 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 250 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 231 // get through the pipe. | 251 // get through the pipe. |
| 232 const int kNumPackets = 10; | 252 const int kNumPackets = 10; |
| 233 const int kPacketSize = 1000; | 253 const int kPacketSize = 1000; |
| 234 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 254 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 235 | 255 |
| 236 // Time to get one packet through the link. | 256 // Time to get one packet through the link. |
| 237 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 257 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 238 | 258 |
| 239 // Time hasn't increased yet, so we souldn't get any packets. | 259 // Time hasn't increased yet, so we souldn't get any packets. |
| 240 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 260 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); |
| 241 pipe->Process(); | 261 pipe->Process(); |
| 242 | 262 |
| 243 // Advance time in steps to release one packet at a time. | 263 // Advance time in steps to release one packet at a time. |
| 244 for (int i = 0; i < kNumPackets; ++i) { | 264 for (int i = 0; i < kNumPackets; ++i) { |
| 245 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); | 265 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); |
| 246 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 266 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); |
| 247 pipe->Process(); | 267 pipe->Process(); |
| 248 } | 268 } |
| 249 | 269 |
| 250 // Change the capacity. | 270 // Change the capacity. |
| 251 config.link_capacity_kbps /= 2; // Reduce to 50%. | 271 config.link_capacity_kbps /= 2; // Reduce to 50%. |
| 252 pipe->SetConfig(config); | 272 pipe->SetConfig(config); |
| 253 | 273 |
| 254 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two | 274 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 255 // seconds to get them through the pipe. | 275 // seconds to get them through the pipe. |
| 256 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 276 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 257 | 277 |
| 258 // Time to get one packet through the link. | 278 // Time to get one packet through the link. |
| 259 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 279 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 260 | 280 |
| 261 // Time hasn't increased yet, so we souldn't get any packets. | 281 // Time hasn't increased yet, so we souldn't get any packets. |
| 262 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 282 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); |
| 263 pipe->Process(); | 283 pipe->Process(); |
| 264 | 284 |
| 265 // Advance time in steps to release one packet at a time. | 285 // Advance time in steps to release one packet at a time. |
| 266 for (int i = 0; i < kNumPackets; ++i) { | 286 for (int i = 0; i < kNumPackets; ++i) { |
| 267 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); | 287 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms); |
| 268 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); | 288 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(1); |
| 269 pipe->Process(); | 289 pipe->Process(); |
| 270 } | 290 } |
| 271 | 291 |
| 272 // Check that all the packets were sent. | 292 // Check that all the packets were sent. |
| 273 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); | 293 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); |
| 274 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); | 294 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess()); |
| 275 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); | 295 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::VIDEO, _, _, _)).Times(0); |
| 276 pipe->Process(); | 296 pipe->Process(); |
| 277 } | 297 } |
| 278 | 298 |
| 279 // Change the link capacity half-way through the test and verify that the | 299 // Change the link capacity half-way through the test and verify that the |
| 280 // delivery times change accordingly. | 300 // delivery times change accordingly. |
| 281 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { | 301 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
| 282 FakeNetworkPipe::Config config; | 302 FakeNetworkPipe::Config config; |
| 283 config.queue_length_packets = 20; | 303 config.queue_length_packets = 20; |
| 284 config.link_capacity_kbps = 80; | 304 config.link_capacity_kbps = 80; |
| 285 std::unique_ptr<FakeNetworkPipe> pipe( | 305 constexpr uint8_t kDefaultAudioPayloadType = 120; |
| 286 new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); | 306 std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
| 307 &fake_clock_, config, {{kDefaultAudioPayloadType, MediaType::AUDIO}})); |
| 287 pipe->SetReceiver(receiver_.get()); | 308 pipe->SetReceiver(receiver_.get()); |
| 288 | 309 |
| 289 // Add 10 packets of 1000 bytes, = 80 kb. | 310 // Add 10 packets of 1000 bytes, = 80 kb. |
| 290 const int kNumPackets = 10; | 311 const int kNumPackets = 10; |
| 291 const int kPacketSize = 1000; | 312 const int kPacketSize = 1000; |
| 292 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 313 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
| 293 | 314 |
| 294 // Time to get one packet through the link at the initial speed. | 315 // Time to get one packet through the link at the initial speed. |
| 295 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 316 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 296 | 317 |
| 297 // Change the capacity. | 318 // Change the capacity. |
| 298 config.link_capacity_kbps *= 2; // Double the capacity. | 319 config.link_capacity_kbps *= 2; // Double the capacity. |
| 299 pipe->SetConfig(config); | 320 pipe->SetConfig(config); |
| 300 | 321 |
| 301 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two | 322 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 302 // seconds to get them through the pipe. | 323 // seconds to get them through the pipe. |
| 303 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 324 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
| 304 | 325 |
| 305 // Time to get one packet through the link at the new capacity. | 326 // Time to get one packet through the link at the new capacity. |
| 306 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 327 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 307 | 328 |
| 308 // Time hasn't increased yet, so we souldn't get any packets. | 329 // Time hasn't increased yet, so we souldn't get any packets. |
| 309 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); | 330 EXPECT_CALL(*receiver_, DeliverPacket(MediaType::AUDIO, _, _, _)).Times(0); |
| 310 pipe->Process(); | 331 pipe->Process(); |
| 311 | 332 |
| 312 // Advance time in steps to release one packet at a time. | 333 // Advance time in steps to release one packet at a time. |
| 313 for (int i = 0; i < kNumPackets; ++i) { | 334 for (int i = 0; i < kNumPackets; ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 330 pipe->Process(); | 351 pipe->Process(); |
| 331 } | 352 } |
| 332 | 353 |
| 333 // At first disallow reordering and then allow reordering. | 354 // At first disallow reordering and then allow reordering. |
| 334 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { | 355 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
| 335 FakeNetworkPipe::Config config; | 356 FakeNetworkPipe::Config config; |
| 336 config.queue_length_packets = 1000; | 357 config.queue_length_packets = 1000; |
| 337 config.link_capacity_kbps = 800; | 358 config.link_capacity_kbps = 800; |
| 338 config.queue_delay_ms = 100; | 359 config.queue_delay_ms = 100; |
| 339 config.delay_standard_deviation_ms = 10; | 360 config.delay_standard_deviation_ms = 10; |
| 340 std::unique_ptr<FakeNetworkPipe> pipe( | 361 std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
| 341 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 362 &fake_clock_, config, {{kDefaultVideoPayloadType, MediaType::VIDEO}})); |
| 342 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | 363 ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
| 343 receiver_.reset(receiver); | 364 receiver_.reset(receiver); |
| 344 pipe->SetReceiver(receiver_.get()); | 365 pipe->SetReceiver(receiver_.get()); |
| 345 | 366 |
| 346 const uint32_t kNumPackets = 100; | 367 const uint32_t kNumPackets = 100; |
| 347 const int kPacketSize = 10; | 368 const int kPacketSize = 10; |
| 348 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 369 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 349 fake_clock_.AdvanceTimeMilliseconds(1000); | 370 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 350 pipe->Process(); | 371 pipe->Process(); |
| 351 | 372 |
| 352 // Confirm that all packets have been delivered in order. | 373 // Confirm that all packets have been delivered in order. |
| 353 EXPECT_EQ(kNumPackets, receiver->delivered_sequence_numbers_.size()); | 374 EXPECT_EQ(kNumPackets, receiver->delivered_sequence_numbers_.size()); |
| 354 int last_seq_num = -1; | 375 int last_seq_num = -1; |
| 355 for (int seq_num : receiver->delivered_sequence_numbers_) { | 376 for (int seq_num : receiver->delivered_sequence_numbers_) { |
| 356 EXPECT_GT(seq_num, last_seq_num); | 377 EXPECT_GT(seq_num, last_seq_num); |
| 357 last_seq_num = seq_num; | 378 last_seq_num = seq_num; |
| 358 } | 379 } |
| 359 | 380 |
| 360 config.allow_reordering = true; | 381 config.allow_reordering = true; |
| 361 pipe->SetConfig(config); | 382 pipe->SetConfig(config); |
| 362 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 383 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 363 fake_clock_.AdvanceTimeMilliseconds(1000); | 384 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 364 receiver->delivered_sequence_numbers_.clear(); | 385 receiver->delivered_sequence_numbers_.clear(); |
| 365 pipe->Process(); | 386 pipe->Process(); |
| 366 | 387 |
| 367 // Confirm that all packets have been delivered | 388 // Confirm that all packets have been delivered |
| 368 // and that reordering has occured. | 389 // and that reordering has occured. |
| 369 EXPECT_EQ(kNumPackets, receiver->delivered_sequence_numbers_.size()); | 390 EXPECT_EQ(kNumPackets, receiver->delivered_sequence_numbers_.size()); |
| 370 bool reordering_has_occured = false; | 391 bool reordering_has_occured = false; |
| 371 last_seq_num = -1; | 392 last_seq_num = -1; |
| 372 for (int seq_num : receiver->delivered_sequence_numbers_) { | 393 for (int seq_num : receiver->delivered_sequence_numbers_) { |
| 373 if (last_seq_num > seq_num) { | 394 if (last_seq_num > seq_num) { |
| 374 reordering_has_occured = true; | 395 reordering_has_occured = true; |
| 375 break; | 396 break; |
| 376 } | 397 } |
| 377 last_seq_num = seq_num; | 398 last_seq_num = seq_num; |
| 378 } | 399 } |
| 379 EXPECT_TRUE(reordering_has_occured); | 400 EXPECT_TRUE(reordering_has_occured); |
| 380 } | 401 } |
| 381 | 402 |
| 382 TEST_F(FakeNetworkPipeTest, BurstLoss) { | 403 TEST_F(FakeNetworkPipeTest, BurstLoss) { |
| 383 const int kLossPercent = 5; | 404 const int kLossPercent = 5; |
| 384 const int kAvgBurstLength = 3; | 405 const int kAvgBurstLength = 3; |
| 385 const int kNumPackets = 10000; | 406 const int kNumPackets = 10000; |
| 386 const int kPacketSize = 10; | 407 const int kPacketSize = 10; |
| 387 | 408 |
| 388 FakeNetworkPipe::Config config; | 409 FakeNetworkPipe::Config config; |
| 389 config.queue_length_packets = kNumPackets; | 410 config.queue_length_packets = kNumPackets; |
| 390 config.loss_percent = kLossPercent; | 411 config.loss_percent = kLossPercent; |
| 391 config.avg_burst_loss_length = kAvgBurstLength; | 412 config.avg_burst_loss_length = kAvgBurstLength; |
| 392 std::unique_ptr<FakeNetworkPipe> pipe( | 413 std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
| 393 new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); | 414 &fake_clock_, config, {{kDefaultVideoPayloadType, MediaType::VIDEO}})); |
| 394 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | 415 ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
| 395 receiver_.reset(receiver); | 416 receiver_.reset(receiver); |
| 396 pipe->SetReceiver(receiver_.get()); | 417 pipe->SetReceiver(receiver_.get()); |
| 397 | 418 |
| 398 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 419 SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
| 399 fake_clock_.AdvanceTimeMilliseconds(1000); | 420 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 400 pipe->Process(); | 421 pipe->Process(); |
| 401 | 422 |
| 402 // Check that the average loss is |kLossPercent| percent. | 423 // Check that the average loss is |kLossPercent| percent. |
| 403 int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); | 424 int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); |
| 404 double loss_fraction = lost_packets / static_cast<double>(kNumPackets); | 425 double loss_fraction = lost_packets / static_cast<double>(kNumPackets); |
| 405 | 426 |
| 406 EXPECT_NEAR(kLossPercent / 100.0, loss_fraction, 0.05); | 427 EXPECT_NEAR(kLossPercent / 100.0, loss_fraction, 0.05); |
| 407 | 428 |
| 408 // Find the number of bursts that has occurred. | 429 // Find the number of bursts that has occurred. |
| 409 size_t received_packets = receiver->delivered_sequence_numbers_.size(); | 430 size_t received_packets = receiver->delivered_sequence_numbers_.size(); |
| 410 int num_bursts = 0; | 431 int num_bursts = 0; |
| 411 for (size_t i = 0; i < received_packets - 1; ++i) { | 432 for (size_t i = 0; i < received_packets - 1; ++i) { |
| 412 int diff = receiver->delivered_sequence_numbers_[i + 1] - | 433 int diff = receiver->delivered_sequence_numbers_[i + 1] - |
| 413 receiver->delivered_sequence_numbers_[i]; | 434 receiver->delivered_sequence_numbers_[i]; |
| 414 if (diff > 1) | 435 if (diff > 1) |
| 415 ++num_bursts; | 436 ++num_bursts; |
| 416 } | 437 } |
| 417 | 438 |
| 418 double average_burst_length = static_cast<double>(lost_packets) / num_bursts; | 439 double average_burst_length = static_cast<double>(lost_packets) / num_bursts; |
| 419 | 440 |
| 420 EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.3); | 441 EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.3); |
| 421 } | 442 } |
| 422 } // namespace webrtc | 443 } // namespace webrtc |
| OLD | NEW |