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 23 matching lines...) Expand all Loading... | |
34 EXPECT_EQ(red_payload_type, data[1] & 0x7F); | 34 EXPECT_EQ(red_payload_type, data[1] & 0x7F); |
35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]); | 35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]); |
36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) + | 36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) + |
37 (data[6] << 8) + data[7]; | 37 (data[6] << 8) + data[7]; |
38 EXPECT_EQ(timestamp, parsed_timestamp); | 38 EXPECT_EQ(timestamp, parsed_timestamp); |
39 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]); | 39 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]); |
40 } | 40 } |
41 | 41 |
42 class ProducerFecTest : public ::testing::Test { | 42 class ProducerFecTest : public ::testing::Test { |
43 protected: | 43 protected: |
44 ProducerFecTest() : producer_(&fec_) {} | |
45 | |
46 ForwardErrorCorrection fec_; | |
47 ProducerFec producer_; | 44 ProducerFec producer_; |
48 FrameGenerator generator_; | 45 test::fec::FrameGenerator generator_; |
49 }; | 46 }; |
50 | 47 |
51 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us | 48 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us |
52 // to move past the end of the current FEC packet mask byte without moving to | 49 // to move past the end of the current FEC packet mask byte without moving to |
53 // the next byte. That likely caused us to repeatedly read from the same byte, | 50 // the next byte. That likely caused us to repeatedly read from the same byte, |
54 // and if that byte didn't protect packets we would generate empty FEC. | 51 // and if that byte didn't protect packets we would generate empty FEC. |
55 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) { | 52 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) { |
56 struct Packet { | 53 struct Packet { |
57 size_t header_size; | 54 size_t header_size; |
58 size_t payload_size; | 55 size_t payload_size; |
(...skipping 18 matching lines...) Expand all Loading... | |
77 if (p.marker_bit) { | 74 if (p.marker_bit) { |
78 packet[1] |= 0x80; | 75 packet[1] |= 0x80; |
79 } else { | 76 } else { |
80 packet[1] &= ~0x80; | 77 packet[1] &= ~0x80; |
81 } | 78 } |
82 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num); | 79 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num); |
83 producer_.AddRtpPacketAndGenerateFec(packet, p.payload_size, p.header_size); | 80 producer_.AddRtpPacketAndGenerateFec(packet, p.payload_size, p.header_size); |
84 uint16_t num_fec_packets = producer_.NumAvailableFecPackets(); | 81 uint16_t num_fec_packets = producer_.NumAvailableFecPackets(); |
85 if (num_fec_packets > 0) { | 82 if (num_fec_packets > 0) { |
86 std::vector<std::unique_ptr<RedPacket>> fec_packets = | 83 std::vector<std::unique_ptr<RedPacket>> fec_packets = |
87 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, 100, | 84 producer_.GetFecPacketsAsRed(test::fec::kRedPayloadType, |
85 test::fec::kFecPayloadType, 100, | |
88 p.header_size); | 86 p.header_size); |
89 EXPECT_EQ(num_fec_packets, fec_packets.size()); | 87 EXPECT_EQ(num_fec_packets, fec_packets.size()); |
90 } | 88 } |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 TEST_F(ProducerFecTest, OneFrameFec) { | 92 TEST_F(ProducerFecTest, OneFrameFec) { |
95 // The number of media packets (|kNumPackets|), number of frames (one for | 93 // The number of media packets (|kNumPackets|), number of frames (one for |
96 // this test), and the protection factor (|params->fec_rate|) are set to make | 94 // this test), and the protection factor (|params->fec_rate|) are set to make |
97 // sure the conditions for generating FEC are satisfied. This means: | 95 // sure the conditions for generating FEC are satisfied. This means: |
98 // (1) protection factor is high enough so that actual overhead over 1 frame | 96 // (1) protection factor is high enough so that actual overhead over 1 frame |
99 // of packets is within |kMaxExcessOverhead|, and (2) the total number of | 97 // of packets is within |kMaxExcessOverhead|, and (2) the total number of |
100 // media packets for 1 frame is at least |minimum_media_packets_fec_|. | 98 // media packets for 1 frame is at least |minimum_media_packets_fec_|. |
101 const int kNumPackets = 4; | 99 const int kNumPackets = 4; |
102 FecProtectionParams params = {15, 3, kFecMaskRandom}; | 100 FecProtectionParams params = {15, 3, kFecMaskRandom}; |
103 std::list<test::RawRtpPacket*> rtp_packets; | 101 std::list<test::fec::RawRtpPacket*> rtp_packets; |
danilchap
2016/08/22 13:00:41
consider add using ::webrtc::test::fec::RawRtpPack
brandtr
2016/08/23 08:19:11
Done, see https://codereview.webrtc.org/2267393002
| |
104 generator_.NewFrame(kNumPackets); | 102 generator_.NewFrame(kNumPackets); |
105 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. | 103 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. |
106 uint32_t last_timestamp = 0; | 104 uint32_t last_timestamp = 0; |
107 for (int i = 0; i < kNumPackets; ++i) { | 105 for (int i = 0; i < kNumPackets; ++i) { |
108 test::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); | 106 test::fec::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); |
109 rtp_packets.push_back(rtp_packet); | 107 rtp_packets.push_back(rtp_packet); |
110 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( | 108 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( |
111 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); | 109 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); |
112 last_timestamp = rtp_packet->header.header.timestamp; | 110 last_timestamp = rtp_packet->header.header.timestamp; |
113 } | 111 } |
114 EXPECT_TRUE(producer_.FecAvailable()); | 112 EXPECT_TRUE(producer_.FecAvailable()); |
115 uint16_t seq_num = generator_.NextSeqNum(); | 113 uint16_t seq_num = generator_.NextSeqNum(); |
116 std::vector<std::unique_ptr<RedPacket>> packets = | 114 std::vector<std::unique_ptr<RedPacket>> packets = |
117 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, | 115 producer_.GetFecPacketsAsRed(test::fec::kRedPayloadType, |
danilchap
2016/08/22 13:00:41
does this constants need to be general?
may be kee
brandtr
2016/08/23 08:19:11
Done.
| |
116 test::fec::kFecPayloadType, seq_num, | |
118 kRtpHeaderSize); | 117 kRtpHeaderSize); |
119 EXPECT_FALSE(producer_.FecAvailable()); | 118 EXPECT_FALSE(producer_.FecAvailable()); |
120 ASSERT_EQ(1u, packets.size()); | 119 ASSERT_EQ(1u, packets.size()); |
121 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, | 120 VerifyHeader(seq_num, last_timestamp, test::fec::kRedPayloadType, |
122 packets.front().get(), false); | 121 test::fec::kFecPayloadType, packets.front().get(), false); |
123 while (!rtp_packets.empty()) { | 122 while (!rtp_packets.empty()) { |
124 delete rtp_packets.front(); | 123 delete rtp_packets.front(); |
125 rtp_packets.pop_front(); | 124 rtp_packets.pop_front(); |
126 } | 125 } |
127 } | 126 } |
128 | 127 |
129 TEST_F(ProducerFecTest, TwoFrameFec) { | 128 TEST_F(ProducerFecTest, TwoFrameFec) { |
130 // The number of media packets/frame (|kNumPackets|), the number of frames | 129 // The number of media packets/frame (|kNumPackets|), the number of frames |
131 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to | 130 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to |
132 // make sure the conditions for generating FEC are satisfied. This means: | 131 // make sure the conditions for generating FEC are satisfied. This means: |
133 // (1) protection factor is high enough so that actual overhead over | 132 // (1) protection factor is high enough so that actual overhead over |
134 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of | 133 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of |
135 // media packets for |kNumFrames| frames is at least | 134 // media packets for |kNumFrames| frames is at least |
136 // |minimum_media_packets_fec_|. | 135 // |minimum_media_packets_fec_|. |
137 const int kNumPackets = 2; | 136 const int kNumPackets = 2; |
138 const int kNumFrames = 2; | 137 const int kNumFrames = 2; |
139 | 138 |
140 FecProtectionParams params = {15, 3, kFecMaskRandom}; | 139 FecProtectionParams params = {15, 3, kFecMaskRandom}; |
141 std::list<test::RawRtpPacket*> rtp_packets; | 140 std::list<test::fec::RawRtpPacket*> rtp_packets; |
142 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. | 141 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. |
143 uint32_t last_timestamp = 0; | 142 uint32_t last_timestamp = 0; |
144 for (int i = 0; i < kNumFrames; ++i) { | 143 for (int i = 0; i < kNumFrames; ++i) { |
145 generator_.NewFrame(kNumPackets); | 144 generator_.NewFrame(kNumPackets); |
146 for (int j = 0; j < kNumPackets; ++j) { | 145 for (int j = 0; j < kNumPackets; ++j) { |
147 test::RawRtpPacket* rtp_packet = | 146 test::fec::RawRtpPacket* rtp_packet = |
148 generator_.NextPacket(i * kNumPackets + j, 10); | 147 generator_.NextPacket(i * kNumPackets + j, 10); |
149 rtp_packets.push_back(rtp_packet); | 148 rtp_packets.push_back(rtp_packet); |
150 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( | 149 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( |
151 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); | 150 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); |
152 last_timestamp = rtp_packet->header.header.timestamp; | 151 last_timestamp = rtp_packet->header.header.timestamp; |
153 } | 152 } |
154 } | 153 } |
155 EXPECT_TRUE(producer_.FecAvailable()); | 154 EXPECT_TRUE(producer_.FecAvailable()); |
156 uint16_t seq_num = generator_.NextSeqNum(); | 155 uint16_t seq_num = generator_.NextSeqNum(); |
157 std::vector<std::unique_ptr<RedPacket>> packets = | 156 std::vector<std::unique_ptr<RedPacket>> packets = |
158 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, | 157 producer_.GetFecPacketsAsRed(test::fec::kRedPayloadType, |
158 test::fec::kFecPayloadType, seq_num, | |
159 kRtpHeaderSize); | 159 kRtpHeaderSize); |
160 EXPECT_FALSE(producer_.FecAvailable()); | 160 EXPECT_FALSE(producer_.FecAvailable()); |
161 ASSERT_EQ(1u, packets.size()); | 161 ASSERT_EQ(1u, packets.size()); |
162 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, | 162 VerifyHeader(seq_num, last_timestamp, test::fec::kRedPayloadType, |
163 packets.front().get(), false); | 163 test::fec::kFecPayloadType, packets.front().get(), false); |
164 while (!rtp_packets.empty()) { | 164 while (!rtp_packets.empty()) { |
165 delete rtp_packets.front(); | 165 delete rtp_packets.front(); |
166 rtp_packets.pop_front(); | 166 rtp_packets.pop_front(); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 TEST_F(ProducerFecTest, BuildRedPacket) { | 170 TEST_F(ProducerFecTest, BuildRedPacket) { |
171 generator_.NewFrame(1); | 171 generator_.NewFrame(1); |
172 test::RawRtpPacket* packet = generator_.NextPacket(0, 10); | 172 test::fec::RawRtpPacket* packet = generator_.NextPacket(0, 10); |
173 std::unique_ptr<RedPacket> red_packet = | 173 std::unique_ptr<RedPacket> red_packet = |
174 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, | 174 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, |
175 kRtpHeaderSize, kRedPayloadType); | 175 kRtpHeaderSize, test::fec::kRedPayloadType); |
176 EXPECT_EQ(packet->length + 1, red_packet->length()); | 176 EXPECT_EQ(packet->length + 1, red_packet->length()); |
177 VerifyHeader(packet->header.header.sequenceNumber, | 177 VerifyHeader(packet->header.header.sequenceNumber, |
178 packet->header.header.timestamp, | 178 packet->header.header.timestamp, test::fec::kRedPayloadType, |
179 kRedPayloadType, | 179 packet->header.header.payloadType, red_packet.get(), |
180 packet->header.header.payloadType, | |
181 red_packet.get(), | |
182 true); // Marker bit set. | 180 true); // Marker bit set. |
183 for (int i = 0; i < 10; ++i) | 181 for (int i = 0; i < 10; ++i) |
184 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); | 182 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); |
185 delete packet; | 183 delete packet; |
186 } | 184 } |
187 | 185 |
188 } // namespace webrtc | 186 } // namespace webrtc |
OLD | NEW |