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 <algorithm> | 11 #include <algorithm> |
12 #include <list> | 12 #include <list> |
| 13 #include <memory> |
13 | 14 |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/base/basictypes.h" |
15 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 20 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
18 | 21 |
19 using webrtc::ForwardErrorCorrection; | 22 namespace webrtc { |
20 | 23 |
21 // Minimum RTP header size in bytes. | 24 namespace { |
22 constexpr uint8_t kRtpHeaderSize = 12; | |
23 | 25 |
24 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. | 26 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
25 constexpr uint8_t kTransportOverhead = 28; | 27 constexpr size_t kTransportOverhead = 28; |
26 | 28 |
27 // Maximum number of media packets used in the FEC (RFC 5109). | 29 constexpr uint32_t kMediaSsrc = 83542; |
28 constexpr uint8_t kMaxNumberMediaPackets = | |
29 ForwardErrorCorrection::kMaxMediaPackets; | |
30 | 30 |
31 using PacketList = ForwardErrorCorrection::PacketList; | 31 // Deep copies |src| to |dst|, but only keeps every Nth packet. |
32 using ReceivedPacketList = ForwardErrorCorrection::ReceivedPacketList; | 32 void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, |
33 using RecoveredPacketList = ForwardErrorCorrection::RecoveredPacketList; | 33 int n, |
| 34 ForwardErrorCorrection::PacketList* dst) { |
| 35 RTC_DCHECK_GT(n, 0); |
| 36 int i = 0; |
| 37 for (const auto& packet : src) { |
| 38 if (i % n == 0) { |
| 39 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); |
| 40 } |
| 41 ++i; |
| 42 } |
| 43 } |
34 | 44 |
| 45 } // namespace |
| 46 |
| 47 using ::testing::Types; |
| 48 |
| 49 template <typename ForwardErrorCorrectionType> |
35 class RtpFecTest : public ::testing::Test { | 50 class RtpFecTest : public ::testing::Test { |
36 protected: | 51 protected: |
37 RtpFecTest() | 52 RtpFecTest() |
38 : random_(0xfec133700742), | 53 : random_(0xabcdef123456), |
39 ssrc_(random_.Rand<uint32_t>()), | 54 media_packet_generator_( |
40 fec_seq_num_(0) {} | 55 kRtpHeaderSize, // Minimum packet size. |
| 56 IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead - |
| 57 fec_.MaxPacketOverhead(), // Maximum packet size. |
| 58 kMediaSsrc, |
| 59 &random_) {} |
41 | 60 |
42 // Construct the media packet list, up to |num_media_packets| packets. | 61 // Construct |received_packets_|: a subset of the media and FEC packets. |
43 // Returns the next sequence number after the last media packet. | |
44 // (this will be the sequence of the first FEC packet) | |
45 int ConstructMediaPacketsSeqNum(int num_media_packets, int start_seq_num); | |
46 int ConstructMediaPackets(int num_media_packets); | |
47 | |
48 // Deep copies |src| to |dst|, but only keeps every Nth packet. | |
49 void DeepCopyEveryNthPacket(const PacketList& src, int n, PacketList* dst); | |
50 | |
51 // Construct |received_packet_list_|: a subset of the media and FEC packets. | |
52 // | 62 // |
53 // Media packet "i" is lost if media_loss_mask_[i] = 1, received if | 63 // Media packet "i" is lost if media_loss_mask_[i] = 1, received if |
54 // media_loss_mask_[i] = 0. | 64 // media_loss_mask_[i] = 0. |
55 // FEC packet "i" is lost if fec_loss_mask_[i] = 1, received if | 65 // FEC packet "i" is lost if fec_loss_mask_[i] = 1, received if |
56 // fec_loss_mask_[i] = 0. | 66 // fec_loss_mask_[i] = 0. |
57 void NetworkReceivedPackets(int* media_loss_mask, int* fec_loss_mask); | 67 void NetworkReceivedPackets(int* media_loss_mask, int* fec_loss_mask); |
58 | 68 |
59 // Add packet from |packet_list| to list of received packets, using the | 69 // Add packet from |packet_list| to list of received packets, using the |
60 // |loss_mask|. | 70 // |loss_mask|. |
61 // The |packet_list| may be a media packet list (is_fec = false), or a | 71 // The |packet_list| may be a media packet list (is_fec = false), or a |
62 // FEC packet list (is_fec = true). | 72 // FEC packet list (is_fec = true). |
63 template <typename T> | 73 template <typename T> |
64 void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec); | 74 void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec); |
65 | 75 |
66 // Check for complete recovery after FEC decoding. | 76 // Check for complete recovery after FEC decoding. |
67 bool IsRecoveryComplete(); | 77 bool IsRecoveryComplete(); |
68 | 78 |
69 // Delete the media and FEC packets. | 79 ForwardErrorCorrectionType fec_; |
70 void TearDown(); | |
71 | 80 |
72 webrtc::Random random_; | 81 Random random_; |
73 ForwardErrorCorrection fec_; | 82 test::fec::MediaPacketGenerator media_packet_generator_; |
74 int ssrc_; | |
75 uint16_t fec_seq_num_; | |
76 | 83 |
77 PacketList media_packet_list_; | 84 ForwardErrorCorrection::PacketList media_packets_; |
78 std::list<ForwardErrorCorrection::Packet*> fec_packet_list_; | 85 std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_; |
79 ReceivedPacketList received_packet_list_; | 86 ForwardErrorCorrection::ReceivedPacketList received_packets_; |
80 RecoveredPacketList recovered_packet_list_; | 87 ForwardErrorCorrection::RecoveredPacketList recovered_packets_; |
81 | 88 |
82 int media_loss_mask_[kMaxNumberMediaPackets]; | 89 int media_loss_mask_[ForwardErrorCorrection::kMaxMediaPackets]; |
83 int fec_loss_mask_[kMaxNumberMediaPackets]; | 90 int fec_loss_mask_[ForwardErrorCorrection::kMaxMediaPackets]; |
84 }; | 91 }; |
85 | 92 |
86 TEST_F(RtpFecTest, FecRecoveryNoLoss) { | 93 // Define gTest typed test to loop over both ULPFEC and FlexFEC. |
| 94 // Since the tests now are parameterized, we need to access |
| 95 // member variables using |this|, thereby enforcing runtime |
| 96 // resolution. |
| 97 using FecTypes = Types<ForwardErrorCorrection>; |
| 98 TYPED_TEST_CASE(RtpFecTest, FecTypes); |
| 99 |
| 100 TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { |
87 constexpr int kNumImportantPackets = 0; | 101 constexpr int kNumImportantPackets = 0; |
88 constexpr bool kUseUnequalProtection = false; | 102 constexpr bool kUseUnequalProtection = false; |
89 constexpr int kNumMediaPackets = 4; | 103 constexpr int kNumMediaPackets = 4; |
90 constexpr uint8_t kProtectionFactor = 60; | 104 constexpr uint8_t kProtectionFactor = 60; |
91 | 105 |
92 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 106 this->media_packets_ = |
| 107 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
93 | 108 |
94 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 109 EXPECT_EQ( |
95 kNumImportantPackets, kUseUnequalProtection, | 110 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
96 webrtc::kFecMaskBursty, &fec_packet_list_)); | 111 kNumImportantPackets, kUseUnequalProtection, |
| 112 kFecMaskBursty, &this->generated_fec_packets_)); |
97 | 113 |
98 // Expect 1 FEC packet. | 114 // Expect 1 FEC packet. |
99 EXPECT_EQ(1u, fec_packet_list_.size()); | 115 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
100 | 116 |
101 // No packets lost. | 117 // No packets lost. |
102 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 118 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
103 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 119 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
104 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 120 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
105 | 121 |
106 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 122 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 123 &this->recovered_packets_)); |
107 | 124 |
108 // No packets lost, expect complete recovery. | 125 // No packets lost, expect complete recovery. |
109 EXPECT_TRUE(IsRecoveryComplete()); | 126 EXPECT_TRUE(this->IsRecoveryComplete()); |
110 } | 127 } |
111 | 128 |
112 TEST_F(RtpFecTest, FecRecoveryWithLoss) { | 129 TYPED_TEST(RtpFecTest, FecRecoveryWithLoss) { |
113 constexpr int kNumImportantPackets = 0; | 130 constexpr int kNumImportantPackets = 0; |
114 constexpr bool kUseUnequalProtection = false; | 131 constexpr bool kUseUnequalProtection = false; |
115 constexpr int kNumMediaPackets = 4; | 132 constexpr int kNumMediaPackets = 4; |
116 constexpr uint8_t kProtectionFactor = 60; | 133 constexpr uint8_t kProtectionFactor = 60; |
117 | 134 |
118 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 135 this->media_packets_ = |
| 136 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
119 | 137 |
120 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 138 EXPECT_EQ( |
121 kNumImportantPackets, kUseUnequalProtection, | 139 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
122 webrtc::kFecMaskBursty, &fec_packet_list_)); | 140 kNumImportantPackets, kUseUnequalProtection, |
| 141 kFecMaskBursty, &this->generated_fec_packets_)); |
123 | 142 |
124 // Expect 1 FEC packet. | 143 // Expect 1 FEC packet. |
125 EXPECT_EQ(1u, fec_packet_list_.size()); | 144 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
126 | 145 |
127 // 1 media packet lost | 146 // 1 media packet lost |
128 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 147 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
129 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 148 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
130 media_loss_mask_[3] = 1; | 149 this->media_loss_mask_[3] = 1; |
131 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 150 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
132 | 151 |
133 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 152 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 153 &this->recovered_packets_)); |
134 | 154 |
135 // One packet lost, one FEC packet, expect complete recovery. | 155 // One packet lost, one FEC packet, expect complete recovery. |
136 EXPECT_TRUE(IsRecoveryComplete()); | 156 EXPECT_TRUE(this->IsRecoveryComplete()); |
137 recovered_packet_list_.clear(); | 157 this->recovered_packets_.clear(); |
138 | 158 |
139 // 2 media packets lost. | 159 // 2 media packets lost. |
140 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 160 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
141 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 161 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
142 media_loss_mask_[1] = 1; | 162 this->media_loss_mask_[1] = 1; |
143 media_loss_mask_[3] = 1; | 163 this->media_loss_mask_[3] = 1; |
144 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 164 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
145 | 165 |
146 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 166 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 167 &this->recovered_packets_)); |
147 | 168 |
148 // 2 packets lost, one FEC packet, cannot get complete recovery. | 169 // 2 packets lost, one FEC packet, cannot get complete recovery. |
149 EXPECT_FALSE(IsRecoveryComplete()); | 170 EXPECT_FALSE(this->IsRecoveryComplete()); |
150 } | 171 } |
151 | 172 |
152 // Verify that we don't use an old FEC packet for FEC decoding. | 173 // Verify that we don't use an old FEC packet for FEC decoding. |
153 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) { | 174 TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapTwoFrames) { |
154 constexpr int kNumImportantPackets = 0; | 175 constexpr int kNumImportantPackets = 0; |
155 constexpr bool kUseUnequalProtection = false; | 176 constexpr bool kUseUnequalProtection = false; |
156 constexpr uint8_t kProtectionFactor = 20; | 177 constexpr uint8_t kProtectionFactor = 20; |
157 | 178 |
158 // Two frames: first frame (old) with two media packets and 1 FEC packet. | 179 // Two frames: first frame (old) with two media packets and 1 FEC packet. |
159 // Second frame (new) with 3 media packets, and no FEC packets. | 180 // Second frame (new) with 3 media packets, and no FEC packets. |
160 // ---Frame 1---- ----Frame 2------ | 181 // ---Frame 1---- ----Frame 2------ |
161 // #0(media) #1(media) #2(FEC) #65535(media) #0(media) #1(media). | 182 // #0(media) #1(media) #2(FEC) #65535(media) #0(media) #1(media). |
162 // If we lose either packet 0 or 1 of second frame, FEC decoding should not | 183 // If we lose either packet 0 or 1 of second frame, FEC decoding should not |
163 // try to decode using "old" FEC packet #2. | 184 // try to decode using "old" FEC packet #2. |
164 | 185 |
165 // Construct media packets for first frame, starting at sequence number 0. | 186 // Construct media packets for first frame, starting at sequence number 0. |
166 fec_seq_num_ = ConstructMediaPacketsSeqNum(2, 0); | 187 this->media_packets_ = |
| 188 this->media_packet_generator_.ConstructMediaPackets(2, 0); |
167 | 189 |
168 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 190 EXPECT_EQ( |
169 kNumImportantPackets, kUseUnequalProtection, | 191 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
170 webrtc::kFecMaskBursty, &fec_packet_list_)); | 192 kNumImportantPackets, kUseUnequalProtection, |
| 193 kFecMaskBursty, &this->generated_fec_packets_)); |
171 // Expect 1 FEC packet. | 194 // Expect 1 FEC packet. |
172 EXPECT_EQ(1u, fec_packet_list_.size()); | 195 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
173 // Add FEC packet (seq#2) of this first frame to received list (i.e., assume | 196 // Add FEC packet (seq#2) of this first frame to received list (i.e., assume |
174 // the two media packet were lost). | 197 // the two media packet were lost). |
175 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 198 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
176 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); | 199 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 200 true); |
177 | 201 |
178 // Construct media packets for second frame, with sequence number wrap. | 202 // Construct media packets for second frame, with sequence number wrap. |
179 media_packet_list_.clear(); | 203 this->media_packets_ = |
180 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65535); | 204 this->media_packet_generator_.ConstructMediaPackets(3, 65535); |
181 | 205 |
182 // Expect 3 media packets for this frame. | 206 // Expect 3 media packets for this frame. |
183 EXPECT_EQ(3u, media_packet_list_.size()); | 207 EXPECT_EQ(3u, this->media_packets_.size()); |
184 | 208 |
185 // Second media packet lost (seq#0). | 209 // Second media packet lost (seq#0). |
186 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 210 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
187 media_loss_mask_[1] = 1; | 211 this->media_loss_mask_[1] = 1; |
188 // Add packets #65535, and #1 to received list. | 212 // Add packets #65535, and #1 to received list. |
189 ReceivedPackets(media_packet_list_, media_loss_mask_, false); | 213 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
190 | 214 |
191 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 215 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 216 &this->recovered_packets_)); |
192 | 217 |
193 // Expect that no decoding is done to get missing packet (seq#0) of second | 218 // Expect that no decoding is done to get missing packet (seq#0) of second |
194 // frame, using old FEC packet (seq#2) from first (old) frame. So number of | 219 // frame, using old FEC packet (seq#2) from first (old) frame. So number of |
195 // recovered packets is 2, and not equal to number of media packets (=3). | 220 // recovered packets is 2, and not equal to number of media packets (=3). |
196 EXPECT_EQ(2u, recovered_packet_list_.size()); | 221 EXPECT_EQ(2u, this->recovered_packets_.size()); |
197 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size()); | 222 EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size()); |
198 } | 223 } |
199 | 224 |
200 // Verify we can still recover frame if sequence number wrap occurs within | 225 // Verify we can still recover frame if sequence number wrap occurs within |
201 // the frame and FEC packet following wrap is received after media packets. | 226 // the frame and FEC packet following wrap is received after media packets. |
202 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) { | 227 TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) { |
203 constexpr int kNumImportantPackets = 0; | 228 constexpr int kNumImportantPackets = 0; |
204 constexpr bool kUseUnequalProtection = false; | 229 constexpr bool kUseUnequalProtection = false; |
205 constexpr uint8_t kProtectionFactor = 20; | 230 constexpr uint8_t kProtectionFactor = 20; |
206 | 231 |
207 // One frame, with sequence number wrap in media packets. | 232 // One frame, with sequence number wrap in media packets. |
208 // -----Frame 1---- | 233 // -----Frame 1---- |
209 // #65534(media) #65535(media) #0(media) #1(FEC). | 234 // #65534(media) #65535(media) #0(media) #1(FEC). |
210 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65534); | 235 this->media_packets_ = |
| 236 this->media_packet_generator_.ConstructMediaPackets(3, 65534); |
211 | 237 |
212 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 238 EXPECT_EQ( |
213 kNumImportantPackets, kUseUnequalProtection, | 239 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
214 webrtc::kFecMaskBursty, &fec_packet_list_)); | 240 kNumImportantPackets, kUseUnequalProtection, |
| 241 kFecMaskBursty, &this->generated_fec_packets_)); |
215 | 242 |
216 // Expect 1 FEC packet. | 243 // Expect 1 FEC packet. |
217 EXPECT_EQ(1u, fec_packet_list_.size()); | 244 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
218 | 245 |
219 // Lose one media packet (seq# 65535). | 246 // Lose one media packet (seq# 65535). |
220 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 247 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
221 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 248 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
222 media_loss_mask_[1] = 1; | 249 this->media_loss_mask_[1] = 1; |
223 ReceivedPackets(media_packet_list_, media_loss_mask_, false); | 250 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
224 // Add FEC packet to received list following the media packets. | 251 // Add FEC packet to received list following the media packets. |
225 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); | 252 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 253 true); |
226 | 254 |
227 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 255 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 256 &this->recovered_packets_)); |
228 | 257 |
229 // Expect 3 media packets in recovered list, and complete recovery. | 258 // Expect 3 media packets in recovered list, and complete recovery. |
230 // Wrap-around won't remove FEC packet, as it follows the wrap. | 259 // Wrap-around won't remove FEC packet, as it follows the wrap. |
231 EXPECT_EQ(3u, recovered_packet_list_.size()); | 260 EXPECT_EQ(3u, this->recovered_packets_.size()); |
232 EXPECT_TRUE(IsRecoveryComplete()); | 261 EXPECT_TRUE(this->IsRecoveryComplete()); |
233 } | 262 } |
234 | 263 |
235 // Sequence number wrap occurs within the FEC packets for the frame. | 264 // Sequence number wrap occurs within the FEC packets for the frame. |
236 // In this case we will discard FEC packet and full recovery is not expected. | 265 // In this case we will discard FEC packet and full recovery is not expected. |
237 // Same problem will occur if wrap is within media packets but FEC packet is | 266 // Same problem will occur if wrap is within media packets but FEC packet is |
238 // received before the media packets. This may be improved if timing information | 267 // received before the media packets. This may be improved if timing information |
239 // is used to detect old FEC packets. | 268 // is used to detect old FEC packets. |
240 // TODO(marpan): Update test if wrap-around handling changes in FEC decoding. | 269 // TODO(marpan): Update test if wrap-around handling changes in FEC decoding. |
241 TEST_F(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) { | 270 TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameNoRecovery) { |
242 constexpr int kNumImportantPackets = 0; | 271 constexpr int kNumImportantPackets = 0; |
243 constexpr bool kUseUnequalProtection = false; | 272 constexpr bool kUseUnequalProtection = false; |
244 constexpr uint8_t kProtectionFactor = 200; | 273 constexpr uint8_t kProtectionFactor = 200; |
245 | 274 |
246 // 1 frame: 3 media packets and 2 FEC packets. | 275 // 1 frame: 3 media packets and 2 FEC packets. |
247 // Sequence number wrap in FEC packets. | 276 // Sequence number wrap in FEC packets. |
248 // -----Frame 1---- | 277 // -----Frame 1---- |
249 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC). | 278 // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC). |
250 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 65532); | 279 this->media_packets_ = |
| 280 this->media_packet_generator_.ConstructMediaPackets(3, 65532); |
251 | 281 |
252 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 282 EXPECT_EQ( |
253 kNumImportantPackets, kUseUnequalProtection, | 283 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
254 webrtc::kFecMaskBursty, &fec_packet_list_)); | 284 kNumImportantPackets, kUseUnequalProtection, |
| 285 kFecMaskBursty, &this->generated_fec_packets_)); |
255 | 286 |
256 // Expect 2 FEC packets. | 287 // Expect 2 FEC packets. |
257 EXPECT_EQ(2u, fec_packet_list_.size()); | 288 EXPECT_EQ(2u, this->generated_fec_packets_.size()); |
258 | 289 |
259 // Lose the last two media packets (seq# 65533, 65534). | 290 // Lose the last two media packets (seq# 65533, 65534). |
260 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 291 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
261 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 292 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
262 media_loss_mask_[1] = 1; | 293 this->media_loss_mask_[1] = 1; |
263 media_loss_mask_[2] = 1; | 294 this->media_loss_mask_[2] = 1; |
264 ReceivedPackets(media_packet_list_, media_loss_mask_, false); | 295 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
265 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); | 296 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 297 true); |
266 | 298 |
267 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 299 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 300 &this->recovered_packets_)); |
268 | 301 |
269 // The two FEC packets are received and should allow for complete recovery, | 302 // The two FEC packets are received and should allow for complete recovery, |
270 // but because of the wrap the second FEC packet will be discarded, and only | 303 // but because of the wrap the second FEC packet will be discarded, and only |
271 // one media packet is recoverable. So exepct 2 media packets on recovered | 304 // one media packet is recoverable. So exepct 2 media packets on recovered |
272 // list and no complete recovery. | 305 // list and no complete recovery. |
273 EXPECT_EQ(2u, recovered_packet_list_.size()); | 306 EXPECT_EQ(2u, this->recovered_packets_.size()); |
274 EXPECT_TRUE(recovered_packet_list_.size() != media_packet_list_.size()); | 307 EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size()); |
275 EXPECT_FALSE(IsRecoveryComplete()); | 308 EXPECT_FALSE(this->IsRecoveryComplete()); |
276 } | 309 } |
277 | 310 |
278 // Verify we can still recover frame if media packets are reordered. | 311 // Verify we can still recover frame if media packets are reordered. |
279 TEST_F(RtpFecTest, FecRecoveryWithMediaOutOfOrder) { | 312 TYPED_TEST(RtpFecTest, FecRecoveryWithMediaOutOfOrder) { |
280 constexpr int kNumImportantPackets = 0; | 313 constexpr int kNumImportantPackets = 0; |
281 constexpr bool kUseUnequalProtection = false; | 314 constexpr bool kUseUnequalProtection = false; |
282 constexpr uint8_t kProtectionFactor = 20; | 315 constexpr uint8_t kProtectionFactor = 20; |
283 | 316 |
284 // One frame: 3 media packets, 1 FEC packet. | 317 // One frame: 3 media packets, 1 FEC packet. |
285 // -----Frame 1---- | 318 // -----Frame 1---- |
286 // #0(media) #1(media) #2(media) #3(FEC). | 319 // #0(media) #1(media) #2(media) #3(FEC). |
287 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0); | 320 this->media_packets_ = |
| 321 this->media_packet_generator_.ConstructMediaPackets(3, 0); |
288 | 322 |
289 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 323 EXPECT_EQ( |
290 kNumImportantPackets, kUseUnequalProtection, | 324 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
291 webrtc::kFecMaskBursty, &fec_packet_list_)); | 325 kNumImportantPackets, kUseUnequalProtection, |
| 326 kFecMaskBursty, &this->generated_fec_packets_)); |
292 | 327 |
293 // Expect 1 FEC packet. | 328 // Expect 1 FEC packet. |
294 EXPECT_EQ(1u, fec_packet_list_.size()); | 329 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
295 | 330 |
296 // Lose one media packet (seq# 1). | 331 // Lose one media packet (seq# 1). |
297 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 332 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
298 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 333 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
299 media_loss_mask_[1] = 1; | 334 this->media_loss_mask_[1] = 1; |
300 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 335 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
301 | 336 |
302 // Reorder received media packets. | 337 // Reorder received media packets. |
303 auto it0 = received_packet_list_.begin(); | 338 auto it0 = this->received_packets_.begin(); |
304 auto it2 = received_packet_list_.begin(); | 339 auto it2 = this->received_packets_.begin(); |
305 it2++; | 340 it2++; |
306 std::swap(*it0, *it2); | 341 std::swap(*it0, *it2); |
307 | 342 |
308 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 343 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 344 &this->recovered_packets_)); |
309 | 345 |
310 // Expect 3 media packets in recovered list, and complete recovery. | 346 // Expect 3 media packets in recovered list, and complete recovery. |
311 EXPECT_EQ(3u, recovered_packet_list_.size()); | 347 EXPECT_EQ(3u, this->recovered_packets_.size()); |
312 EXPECT_TRUE(IsRecoveryComplete()); | 348 EXPECT_TRUE(this->IsRecoveryComplete()); |
313 } | 349 } |
314 | 350 |
315 // Verify we can still recover frame if FEC is received before media packets. | 351 // Verify we can still recover frame if FEC is received before media packets. |
316 TEST_F(RtpFecTest, FecRecoveryWithFecOutOfOrder) { | 352 TYPED_TEST(RtpFecTest, FecRecoveryWithFecOutOfOrder) { |
317 constexpr int kNumImportantPackets = 0; | 353 constexpr int kNumImportantPackets = 0; |
318 constexpr bool kUseUnequalProtection = false; | 354 constexpr bool kUseUnequalProtection = false; |
319 constexpr uint8_t kProtectionFactor = 20; | 355 constexpr uint8_t kProtectionFactor = 20; |
320 | 356 |
321 // One frame: 3 media packets, 1 FEC packet. | 357 // One frame: 3 media packets, 1 FEC packet. |
322 // -----Frame 1---- | 358 // -----Frame 1---- |
323 // #0(media) #1(media) #2(media) #3(FEC). | 359 // #0(media) #1(media) #2(media) #3(FEC). |
324 fec_seq_num_ = ConstructMediaPacketsSeqNum(3, 0); | 360 this->media_packets_ = |
| 361 this->media_packet_generator_.ConstructMediaPackets(3, 0); |
325 | 362 |
326 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 363 EXPECT_EQ( |
327 kNumImportantPackets, kUseUnequalProtection, | 364 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
328 webrtc::kFecMaskBursty, &fec_packet_list_)); | 365 kNumImportantPackets, kUseUnequalProtection, |
| 366 kFecMaskBursty, &this->generated_fec_packets_)); |
329 | 367 |
330 // Expect 1 FEC packet. | 368 // Expect 1 FEC packet. |
331 EXPECT_EQ(1u, fec_packet_list_.size()); | 369 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
332 | 370 |
333 // Lose one media packet (seq# 1). | 371 // Lose one media packet (seq# 1). |
334 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 372 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
335 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 373 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
336 media_loss_mask_[1] = 1; | 374 this->media_loss_mask_[1] = 1; |
337 // Add FEC packet to received list before the media packets. | 375 // Add FEC packet to received list before the media packets. |
338 ReceivedPackets(fec_packet_list_, fec_loss_mask_, true); | 376 this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 377 true); |
339 // Add media packets to received list. | 378 // Add media packets to received list. |
340 ReceivedPackets(media_packet_list_, media_loss_mask_, false); | 379 this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
341 | 380 |
342 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 381 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 382 &this->recovered_packets_)); |
343 | 383 |
344 // Expect 3 media packets in recovered list, and complete recovery. | 384 // Expect 3 media packets in recovered list, and complete recovery. |
345 EXPECT_EQ(3u, recovered_packet_list_.size()); | 385 EXPECT_EQ(3u, this->recovered_packets_.size()); |
346 EXPECT_TRUE(IsRecoveryComplete()); | 386 EXPECT_TRUE(this->IsRecoveryComplete()); |
347 } | 387 } |
348 | 388 |
349 // Test 50% protection with random mask type: Two cases are considered: | 389 // Test 50% protection with random mask type: Two cases are considered: |
350 // a 50% non-consecutive loss which can be fully recovered, and a 50% | 390 // a 50% non-consecutive loss which can be fully recovered, and a 50% |
351 // consecutive loss which cannot be fully recovered. | 391 // consecutive loss which cannot be fully recovered. |
352 TEST_F(RtpFecTest, FecRecoveryWithLoss50percRandomMask) { | 392 TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percRandomMask) { |
353 constexpr int kNumImportantPackets = 0; | 393 constexpr int kNumImportantPackets = 0; |
354 constexpr bool kUseUnequalProtection = false; | 394 constexpr bool kUseUnequalProtection = false; |
355 constexpr int kNumMediaPackets = 4; | 395 constexpr int kNumMediaPackets = 4; |
356 constexpr uint8_t kProtectionFactor = 255; | 396 constexpr uint8_t kProtectionFactor = 255; |
357 | 397 |
358 // Packet Mask for (4,4,0) code, from random mask table. | 398 // Packet Mask for (4,4,0) code, from random mask table. |
359 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) | 399 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) |
360 | 400 |
361 // media#0 media#1 media#2 media#3 | 401 // media#0 media#1 media#2 media#3 |
362 // fec#0: 1 1 0 0 | 402 // fec#0: 1 1 0 0 |
363 // fec#1: 1 0 1 0 | 403 // fec#1: 1 0 1 0 |
364 // fec#2: 0 0 1 1 | 404 // fec#2: 0 0 1 1 |
365 // fec#3: 0 1 0 1 | 405 // fec#3: 0 1 0 1 |
366 // | 406 // |
367 | 407 |
368 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 408 this->media_packets_ = |
| 409 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
369 | 410 |
370 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 411 EXPECT_EQ( |
371 kNumImportantPackets, kUseUnequalProtection, | 412 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
372 webrtc::kFecMaskRandom, &fec_packet_list_)); | 413 kNumImportantPackets, kUseUnequalProtection, |
| 414 kFecMaskRandom, &this->generated_fec_packets_)); |
373 | 415 |
374 // Expect 4 FEC packets. | 416 // Expect 4 FEC packets. |
375 EXPECT_EQ(4u, fec_packet_list_.size()); | 417 EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
376 | 418 |
377 // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost. | 419 // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost. |
378 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 420 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
379 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 421 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
380 fec_loss_mask_[0] = 1; | 422 this->fec_loss_mask_[0] = 1; |
381 media_loss_mask_[0] = 1; | 423 this->media_loss_mask_[0] = 1; |
382 media_loss_mask_[2] = 1; | 424 this->media_loss_mask_[2] = 1; |
383 media_loss_mask_[3] = 1; | 425 this->media_loss_mask_[3] = 1; |
384 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 426 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
385 | 427 |
386 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 428 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 429 &this->recovered_packets_)); |
387 | 430 |
388 // With media packet#1 and FEC packets #1, #2, #3, expect complete recovery. | 431 // With media packet#1 and FEC packets #1, #2, #3, expect complete recovery. |
389 EXPECT_TRUE(IsRecoveryComplete()); | 432 EXPECT_TRUE(this->IsRecoveryComplete()); |
390 recovered_packet_list_.clear(); | 433 this->recovered_packets_.clear(); |
391 | 434 |
392 // 4 consecutive packets lost: media packets 0, 1, 2, 3. | 435 // 4 consecutive packets lost: media packets 0, 1, 2, 3. |
393 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 436 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
394 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 437 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
395 media_loss_mask_[0] = 1; | 438 this->media_loss_mask_[0] = 1; |
396 media_loss_mask_[1] = 1; | 439 this->media_loss_mask_[1] = 1; |
397 media_loss_mask_[2] = 1; | 440 this->media_loss_mask_[2] = 1; |
398 media_loss_mask_[3] = 1; | 441 this->media_loss_mask_[3] = 1; |
399 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 442 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
400 | 443 |
401 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 444 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 445 &this->recovered_packets_)); |
402 | 446 |
403 // Cannot get complete recovery for this loss configuration with random mask. | 447 // Cannot get complete recovery for this loss configuration with random mask. |
404 EXPECT_FALSE(IsRecoveryComplete()); | 448 EXPECT_FALSE(this->IsRecoveryComplete()); |
405 } | 449 } |
406 | 450 |
407 // Test 50% protection with bursty type: Three cases are considered: | 451 // Test 50% protection with bursty type: Three cases are considered: |
408 // two 50% consecutive losses which can be fully recovered, and one | 452 // two 50% consecutive losses which can be fully recovered, and one |
409 // non-consecutive which cannot be fully recovered. | 453 // non-consecutive which cannot be fully recovered. |
410 TEST_F(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) { | 454 TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) { |
411 constexpr int kNumImportantPackets = 0; | 455 constexpr int kNumImportantPackets = 0; |
412 constexpr bool kUseUnequalProtection = false; | 456 constexpr bool kUseUnequalProtection = false; |
413 constexpr int kNumMediaPackets = 4; | 457 constexpr int kNumMediaPackets = 4; |
414 constexpr uint8_t kProtectionFactor = 255; | 458 constexpr uint8_t kProtectionFactor = 255; |
415 | 459 |
416 // Packet Mask for (4,4,0) code, from bursty mask table. | 460 // Packet Mask for (4,4,0) code, from bursty mask table. |
417 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) | 461 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) |
418 | 462 |
419 // media#0 media#1 media#2 media#3 | 463 // media#0 media#1 media#2 media#3 |
420 // fec#0: 1 0 0 0 | 464 // fec#0: 1 0 0 0 |
421 // fec#1: 1 1 0 0 | 465 // fec#1: 1 1 0 0 |
422 // fec#2: 0 1 1 0 | 466 // fec#2: 0 1 1 0 |
423 // fec#3: 0 0 1 1 | 467 // fec#3: 0 0 1 1 |
424 // | 468 // |
425 | 469 |
426 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 470 this->media_packets_ = |
| 471 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
427 | 472 |
428 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 473 EXPECT_EQ( |
429 kNumImportantPackets, kUseUnequalProtection, | 474 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
430 webrtc::kFecMaskBursty, &fec_packet_list_)); | 475 kNumImportantPackets, kUseUnequalProtection, |
| 476 kFecMaskBursty, &this->generated_fec_packets_)); |
431 | 477 |
432 // Expect 4 FEC packets. | 478 // Expect 4 FEC packets. |
433 EXPECT_EQ(4u, fec_packet_list_.size()); | 479 EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
434 | 480 |
435 // 4 consecutive packets lost: media packets 0,1,2,3. | 481 // 4 consecutive packets lost: media packets 0,1,2,3. |
436 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 482 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
437 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 483 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
438 media_loss_mask_[0] = 1; | 484 this->media_loss_mask_[0] = 1; |
439 media_loss_mask_[1] = 1; | 485 this->media_loss_mask_[1] = 1; |
440 media_loss_mask_[2] = 1; | 486 this->media_loss_mask_[2] = 1; |
441 media_loss_mask_[3] = 1; | 487 this->media_loss_mask_[3] = 1; |
442 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 488 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
443 | 489 |
444 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 490 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 491 &this->recovered_packets_)); |
445 | 492 |
446 // Expect complete recovery for consecutive packet loss <= 50%. | 493 // Expect complete recovery for consecutive packet loss <= 50%. |
447 EXPECT_TRUE(IsRecoveryComplete()); | 494 EXPECT_TRUE(this->IsRecoveryComplete()); |
448 recovered_packet_list_.clear(); | 495 this->recovered_packets_.clear(); |
449 | 496 |
450 // 4 consecutive packets lost: media packets 1,2, 3, and FEC packet 0. | 497 // 4 consecutive packets lost: media packets 1,2, 3, and FEC packet 0. |
451 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 498 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
452 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 499 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
453 fec_loss_mask_[0] = 1; | 500 this->fec_loss_mask_[0] = 1; |
454 media_loss_mask_[1] = 1; | 501 this->media_loss_mask_[1] = 1; |
455 media_loss_mask_[2] = 1; | 502 this->media_loss_mask_[2] = 1; |
456 media_loss_mask_[3] = 1; | 503 this->media_loss_mask_[3] = 1; |
457 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 504 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
458 | 505 |
459 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 506 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 507 &this->recovered_packets_)); |
460 | 508 |
461 // Expect complete recovery for consecutive packet loss <= 50%. | 509 // Expect complete recovery for consecutive packet loss <= 50%. |
462 EXPECT_TRUE(IsRecoveryComplete()); | 510 EXPECT_TRUE(this->IsRecoveryComplete()); |
463 recovered_packet_list_.clear(); | 511 this->recovered_packets_.clear(); |
464 | 512 |
465 // 4 packets lost (non-consecutive loss): media packets 0, 3, and FEC# 0, 3. | 513 // 4 packets lost (non-consecutive loss): media packets 0, 3, and FEC# 0, 3. |
466 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 514 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
467 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 515 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
468 fec_loss_mask_[0] = 1; | 516 this->fec_loss_mask_[0] = 1; |
469 fec_loss_mask_[3] = 1; | 517 this->fec_loss_mask_[3] = 1; |
470 media_loss_mask_[0] = 1; | 518 this->media_loss_mask_[0] = 1; |
471 media_loss_mask_[3] = 1; | 519 this->media_loss_mask_[3] = 1; |
472 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 520 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
473 | 521 |
474 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 522 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 523 &this->recovered_packets_)); |
475 | 524 |
476 // Cannot get complete recovery for this loss configuration. | 525 // Cannot get complete recovery for this loss configuration. |
477 EXPECT_FALSE(IsRecoveryComplete()); | 526 EXPECT_FALSE(this->IsRecoveryComplete()); |
478 } | 527 } |
479 | 528 |
480 TEST_F(RtpFecTest, FecRecoveryNoLossUep) { | 529 TYPED_TEST(RtpFecTest, FecRecoveryNoLossUep) { |
481 constexpr int kNumImportantPackets = 2; | 530 constexpr int kNumImportantPackets = 2; |
482 constexpr bool kUseUnequalProtection = true; | 531 constexpr bool kUseUnequalProtection = true; |
483 constexpr int kNumMediaPackets = 4; | 532 constexpr int kNumMediaPackets = 4; |
484 constexpr uint8_t kProtectionFactor = 60; | 533 constexpr uint8_t kProtectionFactor = 60; |
485 | 534 |
486 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 535 this->media_packets_ = |
| 536 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
487 | 537 |
488 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 538 EXPECT_EQ( |
489 kNumImportantPackets, kUseUnequalProtection, | 539 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
490 webrtc::kFecMaskBursty, &fec_packet_list_)); | 540 kNumImportantPackets, kUseUnequalProtection, |
| 541 kFecMaskBursty, &this->generated_fec_packets_)); |
491 | 542 |
492 // Expect 1 FEC packet. | 543 // Expect 1 FEC packet. |
493 EXPECT_EQ(1u, fec_packet_list_.size()); | 544 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
494 | 545 |
495 // No packets lost. | 546 // No packets lost. |
496 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 547 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
497 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 548 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
498 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 549 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
499 | 550 |
500 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 551 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 552 &this->recovered_packets_)); |
501 | 553 |
502 // No packets lost, expect complete recovery. | 554 // No packets lost, expect complete recovery. |
503 EXPECT_TRUE(IsRecoveryComplete()); | 555 EXPECT_TRUE(this->IsRecoveryComplete()); |
504 } | 556 } |
505 | 557 |
506 TEST_F(RtpFecTest, FecRecoveryWithLossUep) { | 558 TYPED_TEST(RtpFecTest, FecRecoveryWithLossUep) { |
507 constexpr int kNumImportantPackets = 2; | 559 constexpr int kNumImportantPackets = 2; |
508 constexpr bool kUseUnequalProtection = true; | 560 constexpr bool kUseUnequalProtection = true; |
509 constexpr int kNumMediaPackets = 4; | 561 constexpr int kNumMediaPackets = 4; |
510 constexpr uint8_t kProtectionFactor = 60; | 562 constexpr uint8_t kProtectionFactor = 60; |
511 | 563 |
512 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 564 this->media_packets_ = |
| 565 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
513 | 566 |
514 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 567 EXPECT_EQ( |
515 kNumImportantPackets, kUseUnequalProtection, | 568 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
516 webrtc::kFecMaskBursty, &fec_packet_list_)); | 569 kNumImportantPackets, kUseUnequalProtection, |
| 570 kFecMaskBursty, &this->generated_fec_packets_)); |
517 | 571 |
518 // Expect 1 FEC packet. | 572 // Expect 1 FEC packet. |
519 EXPECT_EQ(1u, fec_packet_list_.size()); | 573 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
520 | 574 |
521 // 1 media packet lost. | 575 // 1 media packet lost. |
522 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 576 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
523 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 577 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
524 media_loss_mask_[3] = 1; | 578 this->media_loss_mask_[3] = 1; |
525 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 579 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
526 | 580 |
527 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 581 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 582 &this->recovered_packets_)); |
528 | 583 |
529 // One packet lost, one FEC packet, expect complete recovery. | 584 // One packet lost, one FEC packet, expect complete recovery. |
530 EXPECT_TRUE(IsRecoveryComplete()); | 585 EXPECT_TRUE(this->IsRecoveryComplete()); |
531 recovered_packet_list_.clear(); | 586 this->recovered_packets_.clear(); |
532 | 587 |
533 // 2 media packets lost. | 588 // 2 media packets lost. |
534 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 589 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
535 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 590 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
536 media_loss_mask_[1] = 1; | 591 this->media_loss_mask_[1] = 1; |
537 media_loss_mask_[3] = 1; | 592 this->media_loss_mask_[3] = 1; |
538 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 593 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
539 | 594 |
540 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 595 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 596 &this->recovered_packets_)); |
541 | 597 |
542 // 2 packets lost, one FEC packet, cannot get complete recovery. | 598 // 2 packets lost, one FEC packet, cannot get complete recovery. |
543 EXPECT_FALSE(IsRecoveryComplete()); | 599 EXPECT_FALSE(this->IsRecoveryComplete()); |
544 } | 600 } |
545 | 601 |
546 // Test 50% protection with random mask type for UEP on. | 602 // Test 50% protection with random mask type for UEP on. |
547 TEST_F(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) { | 603 TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) { |
548 constexpr int kNumImportantPackets = 1; | 604 constexpr int kNumImportantPackets = 1; |
549 constexpr bool kUseUnequalProtection = true; | 605 constexpr bool kUseUnequalProtection = true; |
550 constexpr int kNumMediaPackets = 4; | 606 constexpr int kNumMediaPackets = 4; |
551 constexpr uint8_t kProtectionFactor = 255; | 607 constexpr uint8_t kProtectionFactor = 255; |
552 | 608 |
553 // Packet Mask for (4,4,1) code, from random mask table. | 609 // Packet Mask for (4,4,1) code, from random mask table. |
554 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1) | 610 // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1) |
555 | 611 |
556 // media#0 media#1 media#2 media#3 | 612 // media#0 media#1 media#2 media#3 |
557 // fec#0: 1 0 0 0 | 613 // fec#0: 1 0 0 0 |
558 // fec#1: 1 1 0 0 | 614 // fec#1: 1 1 0 0 |
559 // fec#2: 1 0 1 1 | 615 // fec#2: 1 0 1 1 |
560 // fec#3: 0 1 1 0 | 616 // fec#3: 0 1 1 0 |
561 // | 617 // |
562 | 618 |
563 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 619 this->media_packets_ = |
564 | 620 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
565 EXPECT_EQ(0, fec_.GenerateFec(media_packet_list_, kProtectionFactor, | 621 |
566 kNumImportantPackets, kUseUnequalProtection, | 622 EXPECT_EQ( |
567 webrtc::kFecMaskRandom, &fec_packet_list_)); | 623 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 624 kNumImportantPackets, kUseUnequalProtection, |
| 625 kFecMaskRandom, &this->generated_fec_packets_)); |
568 | 626 |
569 // Expect 4 FEC packets. | 627 // Expect 4 FEC packets. |
570 EXPECT_EQ(4u, fec_packet_list_.size()); | 628 EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
571 | 629 |
572 // 4 packets lost: 3 media packets and FEC packet#1 lost. | 630 // 4 packets lost: 3 media packets and FEC packet#1 lost. |
573 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 631 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
574 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 632 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
575 fec_loss_mask_[1] = 1; | 633 this->fec_loss_mask_[1] = 1; |
576 media_loss_mask_[0] = 1; | 634 this->media_loss_mask_[0] = 1; |
577 media_loss_mask_[2] = 1; | 635 this->media_loss_mask_[2] = 1; |
578 media_loss_mask_[3] = 1; | 636 this->media_loss_mask_[3] = 1; |
579 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 637 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
580 | 638 |
581 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 639 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 640 &this->recovered_packets_)); |
582 | 641 |
583 // With media packet#3 and FEC packets #0, #1, #3, expect complete recovery. | 642 // With media packet#3 and FEC packets #0, #1, #3, expect complete recovery. |
584 EXPECT_TRUE(IsRecoveryComplete()); | 643 EXPECT_TRUE(this->IsRecoveryComplete()); |
585 recovered_packet_list_.clear(); | 644 this->recovered_packets_.clear(); |
586 | 645 |
587 // 5 packets lost: 4 media packets and one FEC packet#2 lost. | 646 // 5 packets lost: 4 media packets and one FEC packet#2 lost. |
588 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 647 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
589 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 648 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
590 fec_loss_mask_[2] = 1; | 649 this->fec_loss_mask_[2] = 1; |
591 media_loss_mask_[0] = 1; | 650 this->media_loss_mask_[0] = 1; |
592 media_loss_mask_[1] = 1; | 651 this->media_loss_mask_[1] = 1; |
593 media_loss_mask_[2] = 1; | 652 this->media_loss_mask_[2] = 1; |
594 media_loss_mask_[3] = 1; | 653 this->media_loss_mask_[3] = 1; |
595 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 654 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
596 | 655 |
597 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 656 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 657 &this->recovered_packets_)); |
598 | 658 |
599 // Cannot get complete recovery for this loss configuration. | 659 // Cannot get complete recovery for this loss configuration. |
600 EXPECT_FALSE(IsRecoveryComplete()); | 660 EXPECT_FALSE(this->IsRecoveryComplete()); |
601 } | 661 } |
602 | 662 |
603 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePackets) { | 663 TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePackets) { |
604 constexpr int kNumImportantPackets = 0; | 664 constexpr int kNumImportantPackets = 0; |
605 constexpr bool kUseUnequalProtection = false; | 665 constexpr bool kUseUnequalProtection = false; |
606 constexpr int kNumMediaPackets = 5; | 666 constexpr int kNumMediaPackets = 5; |
607 constexpr uint8_t kProtectionFactor = 60; | 667 constexpr uint8_t kProtectionFactor = 60; |
608 | 668 |
609 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 669 this->media_packets_ = |
| 670 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
610 | 671 |
611 // Create a new temporary packet list for generating FEC packets. | 672 // Create a new temporary packet list for generating FEC packets. |
612 // This list should have every other packet removed. | 673 // This list should have every other packet removed. |
613 PacketList protected_media_packets; | 674 ForwardErrorCorrection::PacketList protected_media_packets; |
614 DeepCopyEveryNthPacket(media_packet_list_, 2, &protected_media_packets); | 675 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
615 | 676 |
616 EXPECT_EQ(0, fec_.GenerateFec(protected_media_packets, kProtectionFactor, | 677 EXPECT_EQ( |
617 kNumImportantPackets, kUseUnequalProtection, | 678 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
618 webrtc::kFecMaskBursty, &fec_packet_list_)); | 679 kNumImportantPackets, kUseUnequalProtection, |
| 680 kFecMaskBursty, &this->generated_fec_packets_)); |
619 | 681 |
620 // Expect 1 FEC packet. | 682 // Expect 1 FEC packet. |
621 EXPECT_EQ(1u, fec_packet_list_.size()); | 683 EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
622 | 684 |
623 // 1 protected media packet lost | 685 // 1 protected media packet lost |
624 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 686 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
625 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 687 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
626 media_loss_mask_[2] = 1; | 688 this->media_loss_mask_[2] = 1; |
627 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 689 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
628 | 690 |
629 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 691 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 692 &this->recovered_packets_)); |
630 | 693 |
631 // One packet lost, one FEC packet, expect complete recovery. | 694 // One packet lost, one FEC packet, expect complete recovery. |
632 EXPECT_TRUE(IsRecoveryComplete()); | 695 EXPECT_TRUE(this->IsRecoveryComplete()); |
633 recovered_packet_list_.clear(); | 696 this->recovered_packets_.clear(); |
634 | 697 |
635 // Unprotected packet lost. | 698 // Unprotected packet lost. |
636 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 699 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
637 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 700 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
638 media_loss_mask_[1] = 1; | 701 this->media_loss_mask_[1] = 1; |
639 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 702 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
640 | 703 |
641 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 704 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 705 &this->recovered_packets_)); |
642 | 706 |
643 // Unprotected packet lost. Recovery not possible. | 707 // Unprotected packet lost. Recovery not possible. |
644 EXPECT_FALSE(IsRecoveryComplete()); | 708 EXPECT_FALSE(this->IsRecoveryComplete()); |
645 recovered_packet_list_.clear(); | 709 this->recovered_packets_.clear(); |
646 | 710 |
647 // 2 media packets lost. | 711 // 2 media packets lost. |
648 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 712 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
649 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 713 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
650 media_loss_mask_[0] = 1; | 714 this->media_loss_mask_[0] = 1; |
651 media_loss_mask_[2] = 1; | 715 this->media_loss_mask_[2] = 1; |
652 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 716 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
653 | 717 |
654 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 718 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 719 &this->recovered_packets_)); |
655 | 720 |
656 // 2 protected packets lost, one FEC packet, cannot get complete recovery. | 721 // 2 protected packets lost, one FEC packet, cannot get complete recovery. |
657 EXPECT_FALSE(IsRecoveryComplete()); | 722 EXPECT_FALSE(this->IsRecoveryComplete()); |
658 } | 723 } |
659 | 724 |
660 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) { | 725 TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) { |
661 constexpr int kNumImportantPackets = 0; | 726 constexpr int kNumImportantPackets = 0; |
662 constexpr bool kUseUnequalProtection = false; | 727 constexpr bool kUseUnequalProtection = false; |
663 constexpr int kNumMediaPackets = 21; | 728 constexpr int kNumMediaPackets = 21; |
664 uint8_t kProtectionFactor = 127; | 729 uint8_t kProtectionFactor = 127; |
665 | 730 |
666 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 731 this->media_packets_ = |
| 732 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
667 | 733 |
668 // Create a new temporary packet list for generating FEC packets. | 734 // Create a new temporary packet list for generating FEC packets. |
669 // This list should have every other packet removed. | 735 // This list should have every other packet removed. |
670 PacketList protected_media_packets; | 736 ForwardErrorCorrection::PacketList protected_media_packets; |
671 DeepCopyEveryNthPacket(media_packet_list_, 2, &protected_media_packets); | 737 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
672 | 738 |
673 // Zero column insertion will have to extend the size of the packet | 739 // Zero column insertion will have to extend the size of the packet |
674 // mask since the number of actual packets are 21, while the number | 740 // mask since the number of actual packets are 21, while the number |
675 // of protected packets are 11. | 741 // of protected packets are 11. |
676 EXPECT_EQ(0, fec_.GenerateFec(protected_media_packets, kProtectionFactor, | 742 EXPECT_EQ( |
677 kNumImportantPackets, kUseUnequalProtection, | 743 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
678 webrtc::kFecMaskBursty, &fec_packet_list_)); | 744 kNumImportantPackets, kUseUnequalProtection, |
| 745 kFecMaskBursty, &this->generated_fec_packets_)); |
679 | 746 |
680 // Expect 5 FEC packet. | 747 // Expect 5 FEC packet. |
681 EXPECT_EQ(5u, fec_packet_list_.size()); | 748 EXPECT_EQ(5u, this->generated_fec_packets_.size()); |
682 | 749 |
683 // Last protected media packet lost | 750 // Last protected media packet lost |
684 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 751 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
685 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 752 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
686 media_loss_mask_[kNumMediaPackets - 1] = 1; | 753 this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
687 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 754 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
688 | 755 |
689 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 756 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 757 &this->recovered_packets_)); |
690 | 758 |
691 // One packet lost, one FEC packet, expect complete recovery. | 759 // One packet lost, one FEC packet, expect complete recovery. |
692 EXPECT_TRUE(IsRecoveryComplete()); | 760 EXPECT_TRUE(this->IsRecoveryComplete()); |
693 recovered_packet_list_.clear(); | 761 this->recovered_packets_.clear(); |
694 | 762 |
695 // Last unprotected packet lost. | 763 // Last unprotected packet lost. |
696 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 764 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
697 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 765 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
698 media_loss_mask_[kNumMediaPackets - 2] = 1; | 766 this->media_loss_mask_[kNumMediaPackets - 2] = 1; |
699 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 767 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
700 | 768 |
701 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 769 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 770 &this->recovered_packets_)); |
702 | 771 |
703 // Unprotected packet lost. Recovery not possible. | 772 // Unprotected packet lost. Recovery not possible. |
704 EXPECT_FALSE(IsRecoveryComplete()); | 773 EXPECT_FALSE(this->IsRecoveryComplete()); |
705 recovered_packet_list_.clear(); | 774 this->recovered_packets_.clear(); |
706 | 775 |
707 // 6 media packets lost. | 776 // 6 media packets lost. |
708 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 777 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
709 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 778 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
710 media_loss_mask_[kNumMediaPackets - 11] = 1; | 779 this->media_loss_mask_[kNumMediaPackets - 11] = 1; |
711 media_loss_mask_[kNumMediaPackets - 9] = 1; | 780 this->media_loss_mask_[kNumMediaPackets - 9] = 1; |
712 media_loss_mask_[kNumMediaPackets - 7] = 1; | 781 this->media_loss_mask_[kNumMediaPackets - 7] = 1; |
713 media_loss_mask_[kNumMediaPackets - 5] = 1; | 782 this->media_loss_mask_[kNumMediaPackets - 5] = 1; |
714 media_loss_mask_[kNumMediaPackets - 3] = 1; | 783 this->media_loss_mask_[kNumMediaPackets - 3] = 1; |
715 media_loss_mask_[kNumMediaPackets - 1] = 1; | 784 this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
716 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 785 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
717 | 786 |
718 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 787 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 788 &this->recovered_packets_)); |
719 | 789 |
720 // 5 protected packets lost, one FEC packet, cannot get complete recovery. | 790 // 5 protected packets lost, one FEC packet, cannot get complete recovery. |
721 EXPECT_FALSE(IsRecoveryComplete()); | 791 EXPECT_FALSE(this->IsRecoveryComplete()); |
722 } | 792 } |
723 | 793 |
724 TEST_F(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) { | 794 TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) { |
725 constexpr int kNumImportantPackets = 0; | 795 constexpr int kNumImportantPackets = 0; |
726 constexpr bool kUseUnequalProtection = false; | 796 constexpr bool kUseUnequalProtection = false; |
727 constexpr int kNumMediaPackets = 21; | 797 constexpr int kNumMediaPackets = 21; |
728 uint8_t kProtectionFactor = 127; | 798 uint8_t kProtectionFactor = 127; |
729 | 799 |
730 fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5); | 800 this->media_packets_ = this->media_packet_generator_.ConstructMediaPackets( |
| 801 kNumMediaPackets, 0xFFFF - 5); |
731 | 802 |
732 // Create a new temporary packet list for generating FEC packets. | 803 // Create a new temporary packet list for generating FEC packets. |
733 // This list should have every other packet removed. | 804 // This list should have every other packet removed. |
734 PacketList protected_media_packets; | 805 ForwardErrorCorrection::PacketList protected_media_packets; |
735 DeepCopyEveryNthPacket(media_packet_list_, 2, &protected_media_packets); | 806 DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
736 | 807 |
737 // Zero column insertion will have to extend the size of the packet | 808 // Zero column insertion will have to extend the size of the packet |
738 // mask since the number of actual packets are 21, while the number | 809 // mask since the number of actual packets are 21, while the number |
739 // of protected packets are 11. | 810 // of protected packets are 11. |
740 EXPECT_EQ(0, fec_.GenerateFec(protected_media_packets, kProtectionFactor, | 811 EXPECT_EQ( |
741 kNumImportantPackets, kUseUnequalProtection, | 812 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
742 webrtc::kFecMaskBursty, &fec_packet_list_)); | 813 kNumImportantPackets, kUseUnequalProtection, |
| 814 kFecMaskBursty, &this->generated_fec_packets_)); |
743 | 815 |
744 // Expect 5 FEC packet. | 816 // Expect 5 FEC packet. |
745 EXPECT_EQ(5u, fec_packet_list_.size()); | 817 EXPECT_EQ(5u, this->generated_fec_packets_.size()); |
746 | 818 |
747 // Last protected media packet lost | 819 // Last protected media packet lost |
748 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 820 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
749 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 821 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
750 media_loss_mask_[kNumMediaPackets - 1] = 1; | 822 this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
751 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 823 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
752 | 824 |
753 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 825 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 826 &this->recovered_packets_)); |
754 | 827 |
755 // One packet lost, one FEC packet, expect complete recovery. | 828 // One packet lost, one FEC packet, expect complete recovery. |
756 EXPECT_TRUE(IsRecoveryComplete()); | 829 EXPECT_TRUE(this->IsRecoveryComplete()); |
757 recovered_packet_list_.clear(); | 830 this->recovered_packets_.clear(); |
758 | 831 |
759 // Last unprotected packet lost. | 832 // Last unprotected packet lost. |
760 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 833 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
761 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 834 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
762 media_loss_mask_[kNumMediaPackets - 2] = 1; | 835 this->media_loss_mask_[kNumMediaPackets - 2] = 1; |
763 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 836 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
764 | 837 |
765 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 838 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 839 &this->recovered_packets_)); |
766 | 840 |
767 // Unprotected packet lost. Recovery not possible. | 841 // Unprotected packet lost. Recovery not possible. |
768 EXPECT_FALSE(IsRecoveryComplete()); | 842 EXPECT_FALSE(this->IsRecoveryComplete()); |
769 recovered_packet_list_.clear(); | 843 this->recovered_packets_.clear(); |
770 | 844 |
771 // 6 media packets lost. | 845 // 6 media packets lost. |
772 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | 846 memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
773 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | 847 memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
774 media_loss_mask_[kNumMediaPackets - 11] = 1; | 848 this->media_loss_mask_[kNumMediaPackets - 11] = 1; |
775 media_loss_mask_[kNumMediaPackets - 9] = 1; | 849 this->media_loss_mask_[kNumMediaPackets - 9] = 1; |
776 media_loss_mask_[kNumMediaPackets - 7] = 1; | 850 this->media_loss_mask_[kNumMediaPackets - 7] = 1; |
777 media_loss_mask_[kNumMediaPackets - 5] = 1; | 851 this->media_loss_mask_[kNumMediaPackets - 5] = 1; |
778 media_loss_mask_[kNumMediaPackets - 3] = 1; | 852 this->media_loss_mask_[kNumMediaPackets - 3] = 1; |
779 media_loss_mask_[kNumMediaPackets - 1] = 1; | 853 this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
780 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | 854 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
781 | 855 |
782 EXPECT_EQ(0, fec_.DecodeFec(&received_packet_list_, &recovered_packet_list_)); | 856 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
| 857 &this->recovered_packets_)); |
783 | 858 |
784 // 5 protected packets lost, one FEC packet, cannot get complete recovery. | 859 // 5 protected packets lost, one FEC packet, cannot get complete recovery. |
785 EXPECT_FALSE(IsRecoveryComplete()); | 860 EXPECT_FALSE(this->IsRecoveryComplete()); |
786 } | 861 } |
787 | 862 |
788 void RtpFecTest::TearDown() { | 863 template <typename ForwardErrorCorrectionType> |
789 fec_.ResetState(&recovered_packet_list_); | 864 bool RtpFecTest<ForwardErrorCorrectionType>::IsRecoveryComplete() { |
790 recovered_packet_list_.clear(); | |
791 media_packet_list_.clear(); | |
792 EXPECT_TRUE(media_packet_list_.empty()); | |
793 } | |
794 | |
795 bool RtpFecTest::IsRecoveryComplete() { | |
796 // We must have equally many recovered packets as original packets. | 865 // We must have equally many recovered packets as original packets. |
797 if (recovered_packet_list_.size() != media_packet_list_.size()) { | 866 if (recovered_packets_.size() != media_packets_.size()) { |
798 return false; | 867 return false; |
799 } | 868 } |
800 | 869 |
801 // All recovered packets must be identical to the corresponding | 870 // All recovered packets must be identical to the corresponding |
802 // original packets. | 871 // original packets. |
803 using PacketPtr = std::unique_ptr<ForwardErrorCorrection::Packet>; | 872 using PacketPtr = std::unique_ptr<ForwardErrorCorrection::Packet>; |
804 using RecoveredPacketPtr = | 873 using RecoveredPacketPtr = |
805 std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>; | 874 std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>; |
806 auto cmp = [](const PacketPtr& media_packet, | 875 auto cmp = [](const PacketPtr& media_packet, |
807 const RecoveredPacketPtr& recovered_packet) { | 876 const RecoveredPacketPtr& recovered_packet) { |
808 if (media_packet->length != recovered_packet->pkt->length) { | 877 if (media_packet->length != recovered_packet->pkt->length) { |
809 return false; | 878 return false; |
810 } | 879 } |
811 if (memcmp(media_packet->data, | 880 if (memcmp(media_packet->data, |
812 recovered_packet->pkt->data, | 881 recovered_packet->pkt->data, |
813 media_packet->length) != 0) { | 882 media_packet->length) != 0) { |
814 return false; | 883 return false; |
815 } | 884 } |
816 return true; | 885 return true; |
817 }; | 886 }; |
818 return std::equal(media_packet_list_.cbegin(), media_packet_list_.cend(), | 887 return std::equal(media_packets_.cbegin(), media_packets_.cend(), |
819 recovered_packet_list_.cbegin(), cmp); | 888 recovered_packets_.cbegin(), cmp); |
820 } | 889 } |
821 | 890 |
822 void RtpFecTest::NetworkReceivedPackets(int* media_loss_mask, | 891 template <typename ForwardErrorCorrectionType> |
823 int* fec_loss_mask) { | 892 void RtpFecTest<ForwardErrorCorrectionType>::NetworkReceivedPackets( |
| 893 int* media_loss_mask, |
| 894 int* fec_loss_mask) { |
824 constexpr bool kFecPacket = true; | 895 constexpr bool kFecPacket = true; |
825 ReceivedPackets(media_packet_list_, media_loss_mask, !kFecPacket); | 896 ReceivedPackets(media_packets_, media_loss_mask, !kFecPacket); |
826 ReceivedPackets(fec_packet_list_, fec_loss_mask, kFecPacket); | 897 ReceivedPackets(generated_fec_packets_, fec_loss_mask, kFecPacket); |
827 } | 898 } |
828 | 899 |
829 template <typename T> | 900 template <typename ForwardErrorCorrectionType> |
830 void RtpFecTest::ReceivedPackets(const T& packet_list, int* loss_mask, | 901 template <typename PacketListType> |
831 bool is_fec) { | 902 void RtpFecTest<ForwardErrorCorrectionType>::ReceivedPackets( |
832 int seq_num = fec_seq_num_; | 903 const PacketListType& packet_list, |
| 904 int* loss_mask, |
| 905 bool is_fec) { |
| 906 uint16_t fec_seq_num = media_packet_generator_.GetFecSeqNum(); |
833 int packet_idx = 0; | 907 int packet_idx = 0; |
834 | 908 |
835 for (const auto& packet : packet_list) { | 909 for (const auto& packet : packet_list) { |
836 if (loss_mask[packet_idx] == 0) { | 910 if (loss_mask[packet_idx] == 0) { |
837 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( | 911 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( |
838 new ForwardErrorCorrection::ReceivedPacket()); | 912 new ForwardErrorCorrection::ReceivedPacket()); |
839 received_packet->pkt = new ForwardErrorCorrection::Packet(); | 913 received_packet->pkt = new ForwardErrorCorrection::Packet(); |
840 received_packet->pkt->length = packet->length; | 914 received_packet->pkt->length = packet->length; |
841 memcpy(received_packet->pkt->data, packet->data, packet->length); | 915 memcpy(received_packet->pkt->data, packet->data, packet->length); |
842 received_packet->is_fec = is_fec; | 916 received_packet->is_fec = is_fec; |
843 if (!is_fec) { | 917 if (!is_fec) { |
844 // For media packets, the sequence number and marker bit is | 918 // For media packets, the sequence number and marker bit is |
845 // obtained from RTP header. These were set in ConstructMediaPackets(). | 919 // obtained from RTP header. These were set in ConstructMediaPackets(). |
846 received_packet->seq_num = | 920 received_packet->seq_num = |
847 webrtc::ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]); | 921 ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]); |
848 } else { | 922 } else { |
849 // The sequence number, marker bit, and ssrc number are defined in the | 923 // The sequence number, marker bit, and ssrc number are defined in the |
850 // RTP header of the FEC packet, which is not constructed in this test. | 924 // RTP header of the FEC packet, which is not constructed in this test. |
851 // So we set these values below based on the values generated in | 925 // So we set these values below based on the values generated in |
852 // ConstructMediaPackets(). | 926 // ConstructMediaPackets(). |
853 received_packet->seq_num = seq_num; | 927 received_packet->seq_num = fec_seq_num; |
854 // The ssrc value for FEC packets is set to the one used for the | 928 // The ssrc value for FEC packets is set to the one used for the |
855 // media packets in ConstructMediaPackets(). | 929 // media packets in ConstructMediaPackets(). |
856 received_packet->ssrc = ssrc_; | 930 received_packet->ssrc = kMediaSsrc; |
857 } | 931 } |
858 received_packet_list_.push_back(std::move(received_packet)); | 932 received_packets_.push_back(std::move(received_packet)); |
859 } | 933 } |
860 packet_idx++; | 934 packet_idx++; |
861 // Sequence number of FEC packets are defined as increment by 1 from | 935 // Sequence number of FEC packets are defined as increment by 1 from |
862 // last media packet in frame. | 936 // last media packet in frame. |
863 if (is_fec) seq_num++; | 937 if (is_fec) |
| 938 fec_seq_num++; |
864 } | 939 } |
865 } | 940 } |
866 | 941 |
867 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, | 942 } // namespace webrtc |
868 int start_seq_num) { | |
869 RTC_DCHECK_GT(num_media_packets, 0); | |
870 int sequence_number = start_seq_num; | |
871 int time_stamp = random_.Rand<int>(); | |
872 | |
873 for (int i = 0; i < num_media_packets; ++i) { | |
874 std::unique_ptr<ForwardErrorCorrection::Packet> media_packet( | |
875 new ForwardErrorCorrection::Packet()); | |
876 constexpr uint32_t kMinPacketSize = kRtpHeaderSize; | |
877 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize - | |
878 kTransportOverhead - | |
879 fec_.MaxPacketOverhead(); | |
880 media_packet->length = random_.Rand(kMinPacketSize, kMaxPacketSize); | |
881 | |
882 // Generate random values for the first 2 bytes | |
883 media_packet->data[0] = random_.Rand<uint8_t>(); | |
884 media_packet->data[1] = random_.Rand<uint8_t>(); | |
885 | |
886 // The first two bits are assumed to be 10 by the FEC encoder. | |
887 // In fact the FEC decoder will set the two first bits to 10 regardless of | |
888 // what they actually were. Set the first two bits to 10 so that a memcmp | |
889 // can be performed for the whole restored packet. | |
890 media_packet->data[0] |= 0x80; | |
891 media_packet->data[0] &= 0xbf; | |
892 | |
893 // FEC is applied to a whole frame. | |
894 // A frame is signaled by multiple packets without the marker bit set | |
895 // followed by the last packet of the frame for which the marker bit is set. | |
896 // Only push one (fake) frame to the FEC. | |
897 media_packet->data[1] &= 0x7f; | |
898 | |
899 webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], | |
900 sequence_number); | |
901 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], | |
902 time_stamp); | |
903 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_); | |
904 | |
905 // Generate random values for payload. | |
906 for (size_t j = 12; j < media_packet->length; ++j) { | |
907 media_packet->data[j] = random_.Rand<uint8_t>(); | |
908 } | |
909 sequence_number++; | |
910 media_packet_list_.push_back(std::move(media_packet)); | |
911 } | |
912 // Last packet, set marker bit. | |
913 ForwardErrorCorrection::Packet* media_packet = | |
914 media_packet_list_.back().get(); | |
915 RTC_DCHECK(media_packet); | |
916 media_packet->data[1] |= 0x80; | |
917 return sequence_number; | |
918 } | |
919 | |
920 int RtpFecTest::ConstructMediaPackets(int num_media_packets) { | |
921 return ConstructMediaPacketsSeqNum(num_media_packets, random_.Rand<int>()); | |
922 } | |
923 | |
924 void RtpFecTest::DeepCopyEveryNthPacket(const PacketList& src, int n, | |
925 PacketList* dst) { | |
926 RTC_DCHECK_GT(n, 0); | |
927 int i = 0; | |
928 for (const auto& packet : src) { | |
929 if (i % n == 0) { | |
930 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); | |
931 } | |
932 ++i; | |
933 } | |
934 } | |
OLD | NEW |