Index: webrtc/test/fake_network_pipe_unittest.cc |
diff --git a/webrtc/test/fake_network_pipe_unittest.cc b/webrtc/test/fake_network_pipe_unittest.cc |
index c19b0014bb9f6cac21ce2a9d2bb1aa11bebb69e2..99d33dbe18b7ffc4a1fc9f98860fd3027d1fc0af 100644 |
--- a/webrtc/test/fake_network_pipe_unittest.cc |
+++ b/webrtc/test/fake_network_pipe_unittest.cc |
@@ -11,6 +11,7 @@ |
#include <memory> |
#include "webrtc/call/call.h" |
+#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
#include "webrtc/system_wrappers/include/clock.h" |
#include "webrtc/test/fake_network_pipe.h" |
#include "webrtc/test/gmock.h" |
@@ -23,6 +24,17 @@ using ::testing::Invoke; |
namespace webrtc { |
+namespace { |
+ |
+constexpr uint8_t kDefaultVideoPayloadType = 102; |
+ |
+constexpr size_t kMiniHeaderSize = 2; |
+ |
+const std::map<uint8_t, MediaType> default_payload_type_map = { |
+ {kDefaultVideoPayloadType, MediaType::VIDEO}}; |
+ |
+} // namespace |
+ |
class TestReceiver : public PacketReceiver { |
public: |
TestReceiver() {} |
@@ -47,8 +59,9 @@ class ReorderTestReceiver : public TestReceiver { |
const uint8_t* packet, |
size_t length, |
const PacketTime& packet_time) override { |
+ RTC_DCHECK_GE(length, kMiniHeaderSize + sizeof(int)); |
int seq_num; |
- memcpy(&seq_num, packet, sizeof(int)); |
+ memcpy(&seq_num, &packet[kMiniHeaderSize], sizeof(int)); |
delivered_sequence_numbers_.push_back(seq_num); |
return PacketReceiver::DELIVERY_OK; |
} |
@@ -69,13 +82,19 @@ class FakeNetworkPipeTest : public ::testing::Test { |
virtual void TearDown() { |
} |
- void SendPackets(FakeNetworkPipe* pipe, int number_packets, int packet_size) { |
- RTC_DCHECK_GE(packet_size, sizeof(int)); |
+ void SendPackets(FakeNetworkPipe* pipe, |
+ int number_packets, |
+ int packet_size, |
+ uint8_t payload_type) { |
+ RTC_DCHECK_GE(packet_size, kMiniHeaderSize + sizeof(int)); |
+ RTC_DCHECK_LE(payload_type, 0x7f); |
+ // packet[0 .. 1] is reserved for header. |
std::unique_ptr<uint8_t[]> packet(new uint8_t[packet_size]); |
+ RTC_DCHECK(!RtpHeaderParser::IsRtcp(packet.get(), packet_size)); |
+ packet[1] = payload_type; |
for (int i = 0; i < number_packets; ++i) { |
- // Set a sequence number for the packets by |
- // using the first bytes in the packet. |
- memcpy(packet.get(), &i, sizeof(int)); |
+ // Insert a sequence number for the packets. |
+ memcpy(&packet[kMiniHeaderSize], &i, sizeof(int)); |
pipe->SendPacket(packet.get(), packet_size); |
} |
} |
@@ -96,14 +115,14 @@ TEST_F(FakeNetworkPipeTest, CapacityTest) { |
config.queue_length_packets = 20; |
config.link_capacity_kbps = 80; |
std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
pipe->SetReceiver(receiver_.get()); |
// Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
// get through the pipe. |
const int kNumPackets = 10; |
const int kPacketSize = 1000; |
- SendPackets(pipe.get(), kNumPackets , kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
// Time to get one packet through the link. |
const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
@@ -135,13 +154,14 @@ TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { |
config.queue_length_packets = 20; |
config.queue_delay_ms = 100; |
config.link_capacity_kbps = 80; |
- std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); |
+ constexpr uint8_t kDefaultAudioPayloadType = 120; |
+ std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
+ &fake_clock_, config, {{kDefaultAudioPayloadType, MediaType::AUDIO}})); |
pipe->SetReceiver(receiver_.get()); |
const int kNumPackets = 2; |
const int kPacketSize = 1000; |
- SendPackets(pipe.get(), kNumPackets , kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
// Time to get one packet through the link. |
const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
@@ -170,7 +190,7 @@ TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
config.queue_length_packets = 2; |
config.link_capacity_kbps = 80; |
std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
pipe->SetReceiver(receiver_.get()); |
const int kPacketSize = 1000; |
@@ -178,7 +198,7 @@ TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
kPacketSize); |
// Send three packets and verify only 2 are delivered. |
- SendPackets(pipe.get(), 3, kPacketSize); |
+ SendPackets(pipe.get(), 3, kPacketSize, kDefaultVideoPayloadType); |
// Increase time enough to deliver all three packets, verify only two are |
// delivered. |
@@ -194,7 +214,7 @@ TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
config.queue_delay_ms = 20; |
config.link_capacity_kbps = 80; |
std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
pipe->SetReceiver(receiver_.get()); |
const int kPacketSize = 1000; |
@@ -202,7 +222,7 @@ TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
kPacketSize); |
// Send three packets and verify only 2 are delivered. |
- SendPackets(pipe.get(), 3, kPacketSize); |
+ SendPackets(pipe.get(), 3, kPacketSize, kDefaultVideoPayloadType); |
fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + |
config.queue_delay_ms); |
@@ -224,14 +244,14 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
config.queue_length_packets = 20; |
config.link_capacity_kbps = 80; |
std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ new FakeNetworkPipe(&fake_clock_, config, default_payload_type_map)); |
pipe->SetReceiver(receiver_.get()); |
// Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
// get through the pipe. |
const int kNumPackets = 10; |
const int kPacketSize = 1000; |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
// Time to get one packet through the link. |
int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
@@ -253,7 +273,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
// Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
// seconds to get them through the pipe. |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
// Time to get one packet through the link. |
packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
@@ -282,14 +302,15 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
FakeNetworkPipe::Config config; |
config.queue_length_packets = 20; |
config.link_capacity_kbps = 80; |
- std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::AUDIO)); |
+ constexpr uint8_t kDefaultAudioPayloadType = 120; |
+ std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
+ &fake_clock_, config, {{kDefaultAudioPayloadType, MediaType::AUDIO}})); |
pipe->SetReceiver(receiver_.get()); |
// Add 10 packets of 1000 bytes, = 80 kb. |
const int kNumPackets = 10; |
const int kPacketSize = 1000; |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
// Time to get one packet through the link at the initial speed. |
int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
@@ -300,7 +321,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
// Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
// seconds to get them through the pipe. |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultAudioPayloadType); |
// Time to get one packet through the link at the new capacity. |
int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
@@ -337,15 +358,15 @@ TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
config.link_capacity_kbps = 800; |
config.queue_delay_ms = 100; |
config.delay_standard_deviation_ms = 10; |
- std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
+ &fake_clock_, config, {{kDefaultVideoPayloadType, MediaType::VIDEO}})); |
ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
receiver_.reset(receiver); |
pipe->SetReceiver(receiver_.get()); |
const uint32_t kNumPackets = 100; |
const int kPacketSize = 10; |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
fake_clock_.AdvanceTimeMilliseconds(1000); |
pipe->Process(); |
@@ -359,7 +380,7 @@ TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
config.allow_reordering = true; |
pipe->SetConfig(config); |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
fake_clock_.AdvanceTimeMilliseconds(1000); |
receiver->delivered_sequence_numbers_.clear(); |
pipe->Process(); |
@@ -389,13 +410,13 @@ TEST_F(FakeNetworkPipeTest, BurstLoss) { |
config.queue_length_packets = kNumPackets; |
config.loss_percent = kLossPercent; |
config.avg_burst_loss_length = kAvgBurstLength; |
- std::unique_ptr<FakeNetworkPipe> pipe( |
- new FakeNetworkPipe(&fake_clock_, config, MediaType::VIDEO)); |
+ std::unique_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe( |
+ &fake_clock_, config, {{kDefaultVideoPayloadType, MediaType::VIDEO}})); |
ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
receiver_.reset(receiver); |
pipe->SetReceiver(receiver_.get()); |
- SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize, kDefaultVideoPayloadType); |
fake_clock_.AdvanceTimeMilliseconds(1000); |
pipe->Process(); |