marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Rasmus Brandt | ae4f767 | 2016-07-07 09:40:51 +0200 | [diff] [blame] | 11 | #include <algorithm> |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 12 | #include <list> |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 13 | #include <memory> |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "modules/rtp_rtcp/source/byte_io.h" |
| 16 | #include "modules/rtp_rtcp/source/fec_test_helper.h" |
| 17 | #include "modules/rtp_rtcp/source/flexfec_header_reader_writer.h" |
| 18 | #include "modules/rtp_rtcp/source/forward_error_correction.h" |
| 19 | #include "modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_base/random.h" |
| 21 | #include "test/gtest.h" |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 22 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 23 | namespace webrtc { |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 24 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 25 | namespace { |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 26 | |
| 27 | // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 28 | constexpr size_t kTransportOverhead = 28; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 29 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 30 | constexpr uint32_t kMediaSsrc = 83542; |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 31 | constexpr uint32_t kFlexfecSsrc = 43245; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 32 | |
Rasmus Brandt | d73ba12 | 2017-12-07 10:22:49 +0100 | [diff] [blame] | 33 | constexpr size_t kMaxMediaPackets = 48; |
| 34 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 35 | // Deep copies |src| to |dst|, but only keeps every Nth packet. |
| 36 | void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, |
| 37 | int n, |
| 38 | ForwardErrorCorrection::PacketList* dst) { |
| 39 | RTC_DCHECK_GT(n, 0); |
| 40 | int i = 0; |
| 41 | for (const auto& packet : src) { |
| 42 | if (i % n == 0) { |
| 43 | dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); |
| 44 | } |
| 45 | ++i; |
| 46 | } |
| 47 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 48 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 49 | } // namespace |
| 50 | |
| 51 | using ::testing::Types; |
| 52 | |
| 53 | template <typename ForwardErrorCorrectionType> |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 54 | class RtpFecTest : public ::testing::Test { |
| 55 | protected: |
| 56 | RtpFecTest() |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 57 | : random_(0xabcdef123456), |
| 58 | media_packet_generator_( |
| 59 | kRtpHeaderSize, // Minimum packet size. |
| 60 | IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead - |
| 61 | fec_.MaxPacketOverhead(), // Maximum packet size. |
| 62 | kMediaSsrc, |
| 63 | &random_) {} |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 64 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 65 | // Construct |received_packets_|: a subset of the media and FEC packets. |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 66 | // |
| 67 | // Media packet "i" is lost if media_loss_mask_[i] = 1, received if |
| 68 | // media_loss_mask_[i] = 0. |
| 69 | // FEC packet "i" is lost if fec_loss_mask_[i] = 1, received if |
| 70 | // fec_loss_mask_[i] = 0. |
| 71 | void NetworkReceivedPackets(int* media_loss_mask, int* fec_loss_mask); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 72 | |
| 73 | // Add packet from |packet_list| to list of received packets, using the |
| 74 | // |loss_mask|. |
| 75 | // The |packet_list| may be a media packet list (is_fec = false), or a |
| 76 | // FEC packet list (is_fec = true). |
brandtr | 35c480c | 2016-08-09 01:23:23 -0700 | [diff] [blame] | 77 | template <typename T> |
| 78 | void ReceivedPackets(const T& packet_list, int* loss_mask, bool is_fec); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 79 | |
| 80 | // Check for complete recovery after FEC decoding. |
| 81 | bool IsRecoveryComplete(); |
| 82 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 83 | ForwardErrorCorrectionType fec_; |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 84 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 85 | Random random_; |
| 86 | test::fec::MediaPacketGenerator media_packet_generator_; |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 87 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 88 | ForwardErrorCorrection::PacketList media_packets_; |
| 89 | std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_; |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 90 | std::vector<std::unique_ptr<ForwardErrorCorrection::ReceivedPacket>> |
| 91 | received_packets_; |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 92 | ForwardErrorCorrection::RecoveredPacketList recovered_packets_; |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 93 | |
Rasmus Brandt | 78db158 | 2016-09-21 09:19:34 +0200 | [diff] [blame] | 94 | int media_loss_mask_[kUlpfecMaxMediaPackets]; |
| 95 | int fec_loss_mask_[kUlpfecMaxMediaPackets]; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 98 | template <typename ForwardErrorCorrectionType> |
| 99 | void RtpFecTest<ForwardErrorCorrectionType>::NetworkReceivedPackets( |
| 100 | int* media_loss_mask, |
| 101 | int* fec_loss_mask) { |
| 102 | constexpr bool kFecPacket = true; |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 103 | this->received_packets_.clear(); |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 104 | ReceivedPackets(media_packets_, media_loss_mask, !kFecPacket); |
| 105 | ReceivedPackets(generated_fec_packets_, fec_loss_mask, kFecPacket); |
| 106 | } |
| 107 | |
| 108 | template <typename ForwardErrorCorrectionType> |
| 109 | template <typename PacketListType> |
| 110 | void RtpFecTest<ForwardErrorCorrectionType>::ReceivedPackets( |
| 111 | const PacketListType& packet_list, |
| 112 | int* loss_mask, |
| 113 | bool is_fec) { |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 114 | uint16_t fec_seq_num = ForwardErrorCorrectionType::GetFirstFecSeqNum( |
| 115 | media_packet_generator_.GetNextSeqNum()); |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 116 | int packet_idx = 0; |
| 117 | |
| 118 | for (const auto& packet : packet_list) { |
| 119 | if (loss_mask[packet_idx] == 0) { |
| 120 | std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( |
| 121 | new ForwardErrorCorrection::ReceivedPacket()); |
| 122 | received_packet->pkt = new ForwardErrorCorrection::Packet(); |
| 123 | received_packet->pkt->length = packet->length; |
| 124 | memcpy(received_packet->pkt->data, packet->data, packet->length); |
| 125 | received_packet->is_fec = is_fec; |
| 126 | if (!is_fec) { |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 127 | received_packet->ssrc = kMediaSsrc; |
| 128 | // For media packets, the sequence number is obtained from the |
| 129 | // RTP header as written by MediaPacketGenerator::ConstructMediaPackets. |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 130 | received_packet->seq_num = |
| 131 | ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]); |
| 132 | } else { |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 133 | received_packet->ssrc = ForwardErrorCorrectionType::kFecSsrc; |
| 134 | // For FEC packets, we simulate the sequence numbers differently |
| 135 | // depending on if ULPFEC or FlexFEC is used. See the definition of |
| 136 | // ForwardErrorCorrectionType::GetFirstFecSeqNum. |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 137 | received_packet->seq_num = fec_seq_num; |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 138 | } |
| 139 | received_packets_.push_back(std::move(received_packet)); |
| 140 | } |
| 141 | packet_idx++; |
| 142 | // Sequence number of FEC packets are defined as increment by 1 from |
| 143 | // last media packet in frame. |
| 144 | if (is_fec) |
| 145 | fec_seq_num++; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | template <typename ForwardErrorCorrectionType> |
| 150 | bool RtpFecTest<ForwardErrorCorrectionType>::IsRecoveryComplete() { |
| 151 | // We must have equally many recovered packets as original packets. |
| 152 | if (recovered_packets_.size() != media_packets_.size()) { |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | // All recovered packets must be identical to the corresponding |
| 157 | // original packets. |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 158 | auto cmp = []( |
| 159 | const std::unique_ptr<ForwardErrorCorrection::Packet>& media_packet, |
| 160 | const std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>& |
| 161 | recovered_packet) { |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 162 | if (media_packet->length != recovered_packet->pkt->length) { |
| 163 | return false; |
| 164 | } |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 165 | if (memcmp(media_packet->data, recovered_packet->pkt->data, |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 166 | media_packet->length) != 0) { |
| 167 | return false; |
| 168 | } |
| 169 | return true; |
| 170 | }; |
| 171 | return std::equal(media_packets_.cbegin(), media_packets_.cend(), |
| 172 | recovered_packets_.cbegin(), cmp); |
| 173 | } |
| 174 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 175 | // Define gTest typed test to loop over both ULPFEC and FlexFEC. |
| 176 | // Since the tests now are parameterized, we need to access |
| 177 | // member variables using |this|, thereby enforcing runtime |
| 178 | // resolution. |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 179 | |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 180 | class FlexfecForwardErrorCorrection : public ForwardErrorCorrection { |
| 181 | public: |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 182 | static const uint32_t kFecSsrc = kFlexfecSsrc; |
| 183 | |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 184 | FlexfecForwardErrorCorrection() |
| 185 | : ForwardErrorCorrection( |
| 186 | std::unique_ptr<FecHeaderReader>(new FlexfecHeaderReader()), |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 187 | std::unique_ptr<FecHeaderWriter>(new FlexfecHeaderWriter()), |
| 188 | kFecSsrc, |
| 189 | kMediaSsrc) {} |
| 190 | |
| 191 | // For FlexFEC we let the FEC packet sequence numbers be independent of |
| 192 | // the media packet sequence numbers. |
| 193 | static uint16_t GetFirstFecSeqNum(uint16_t next_media_seq_num) { |
| 194 | Random random(0xbe110); |
| 195 | return random.Rand<uint16_t>(); |
| 196 | } |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 199 | class UlpfecForwardErrorCorrection : public ForwardErrorCorrection { |
| 200 | public: |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 201 | static const uint32_t kFecSsrc = kMediaSsrc; |
| 202 | |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 203 | UlpfecForwardErrorCorrection() |
| 204 | : ForwardErrorCorrection( |
| 205 | std::unique_ptr<FecHeaderReader>(new UlpfecHeaderReader()), |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 206 | std::unique_ptr<FecHeaderWriter>(new UlpfecHeaderWriter()), |
| 207 | kFecSsrc, |
| 208 | kMediaSsrc) {} |
| 209 | |
| 210 | // For ULPFEC we assume that the FEC packets are subsequent to the media |
| 211 | // packets in terms of sequence number. |
| 212 | static uint16_t GetFirstFecSeqNum(uint16_t next_media_seq_num) { |
| 213 | return next_media_seq_num; |
| 214 | } |
Rasmus Brandt | ea7beb9 | 2016-09-21 12:01:19 +0200 | [diff] [blame] | 215 | }; |
| 216 | |
brandtr | 0496de2 | 2016-10-03 00:43:25 -0700 | [diff] [blame] | 217 | using FecTypes = |
| 218 | Types<FlexfecForwardErrorCorrection, UlpfecForwardErrorCorrection>; |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 219 | TYPED_TEST_CASE(RtpFecTest, FecTypes); |
| 220 | |
Rasmus Brandt | d73ba12 | 2017-12-07 10:22:49 +0100 | [diff] [blame] | 221 | TYPED_TEST(RtpFecTest, WillProtectMediaPacketsWithLargeSequenceNumberGap) { |
| 222 | constexpr int kNumImportantPackets = 0; |
| 223 | constexpr bool kUseUnequalProtection = false; |
| 224 | constexpr int kNumMediaPackets = 2; |
| 225 | constexpr uint8_t kProtectionFactor = 127; |
| 226 | |
| 227 | this->media_packets_ = |
| 228 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
| 229 | |
| 230 | // Create |kMaxMediaPackets - 1| sequence number difference. |
| 231 | ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.front()->data[2], |
| 232 | 1); |
| 233 | ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.back()->data[2], |
| 234 | kMaxMediaPackets); |
| 235 | |
| 236 | EXPECT_EQ( |
| 237 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 238 | kNumImportantPackets, kUseUnequalProtection, |
| 239 | kFecMaskBursty, &this->generated_fec_packets_)); |
| 240 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
| 241 | } |
| 242 | |
| 243 | TYPED_TEST(RtpFecTest, |
| 244 | WillNotProtectMediaPacketsWithTooLargeSequenceNumberGap) { |
| 245 | constexpr int kNumImportantPackets = 0; |
| 246 | constexpr bool kUseUnequalProtection = false; |
| 247 | constexpr int kNumMediaPackets = 2; |
| 248 | constexpr uint8_t kProtectionFactor = 127; |
| 249 | |
| 250 | this->media_packets_ = |
| 251 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
| 252 | |
| 253 | // Create |kMaxMediaPackets| sequence number difference. |
| 254 | ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.front()->data[2], |
| 255 | 1); |
| 256 | ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.back()->data[2], |
| 257 | kMaxMediaPackets + 1); |
| 258 | |
| 259 | EXPECT_EQ( |
| 260 | -1, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 261 | kNumImportantPackets, kUseUnequalProtection, |
| 262 | kFecMaskBursty, &this->generated_fec_packets_)); |
| 263 | EXPECT_TRUE(this->generated_fec_packets_.empty()); |
| 264 | } |
| 265 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 266 | TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 267 | constexpr int kNumImportantPackets = 0; |
| 268 | constexpr bool kUseUnequalProtection = false; |
| 269 | constexpr int kNumMediaPackets = 4; |
| 270 | constexpr uint8_t kProtectionFactor = 60; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 271 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 272 | this->media_packets_ = |
| 273 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 274 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 275 | EXPECT_EQ( |
| 276 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 277 | kNumImportantPackets, kUseUnequalProtection, |
| 278 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 279 | |
| 280 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 281 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 282 | |
| 283 | // No packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 284 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 285 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 286 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 287 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 288 | for (const auto& received_packet : this->received_packets_) { |
| 289 | this->fec_.DecodeFec(*received_packet, |
| 290 | &this->recovered_packets_); |
| 291 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 292 | |
| 293 | // No packets lost, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 294 | EXPECT_TRUE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 295 | } |
| 296 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 297 | TYPED_TEST(RtpFecTest, FecRecoveryWithLoss) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 298 | constexpr int kNumImportantPackets = 0; |
| 299 | constexpr bool kUseUnequalProtection = false; |
| 300 | constexpr int kNumMediaPackets = 4; |
| 301 | constexpr uint8_t kProtectionFactor = 60; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 302 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 303 | this->media_packets_ = |
| 304 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 305 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 306 | EXPECT_EQ( |
| 307 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 308 | kNumImportantPackets, kUseUnequalProtection, |
| 309 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 310 | |
| 311 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 312 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 313 | |
| 314 | // 1 media packet lost |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 315 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 316 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 317 | this->media_loss_mask_[3] = 1; |
| 318 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 319 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 320 | for (const auto& received_packet : this->received_packets_) { |
| 321 | this->fec_.DecodeFec(*received_packet, |
| 322 | &this->recovered_packets_); |
| 323 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 324 | |
| 325 | // One packet lost, one FEC packet, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 326 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 327 | this->recovered_packets_.clear(); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 328 | |
| 329 | // 2 media packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 330 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 331 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 332 | this->media_loss_mask_[1] = 1; |
| 333 | this->media_loss_mask_[3] = 1; |
| 334 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 335 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 336 | for (const auto& received_packet : this->received_packets_) { |
| 337 | this->fec_.DecodeFec(*received_packet, |
| 338 | &this->recovered_packets_); |
| 339 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 340 | |
| 341 | // 2 packets lost, one FEC packet, cannot get complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 342 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 343 | } |
| 344 | |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 345 | // Verify that we don't use an old FEC packet for FEC decoding. |
Niels Möller | 958288a | 2017-10-02 13:51:36 +0200 | [diff] [blame] | 346 | TYPED_TEST(RtpFecTest, NoFecRecoveryWithOldFecPacket) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 347 | constexpr int kNumImportantPackets = 0; |
| 348 | constexpr bool kUseUnequalProtection = false; |
| 349 | constexpr uint8_t kProtectionFactor = 20; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 350 | |
| 351 | // Two frames: first frame (old) with two media packets and 1 FEC packet. |
Niels Möller | 958288a | 2017-10-02 13:51:36 +0200 | [diff] [blame] | 352 | // Third frame (new) with 3 media packets, and no FEC packets. |
| 353 | // |
| 354 | // #0(media) #1(media) #2(FEC) ----Frame 1----- |
| 355 | // #32767(media) 32768(media) 32769(media) ----Frame 2----- |
| 356 | // #65535(media) #0(media) #1(media). ----Frame 3----- |
| 357 | // If we lose either packet 0 or 1 of third frame, FEC decoding should not |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 358 | // try to decode using "old" FEC packet #2. |
| 359 | |
| 360 | // Construct media packets for first frame, starting at sequence number 0. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 361 | this->media_packets_ = |
| 362 | this->media_packet_generator_.ConstructMediaPackets(2, 0); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 363 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 364 | EXPECT_EQ( |
| 365 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 366 | kNumImportantPackets, kUseUnequalProtection, |
| 367 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 368 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 369 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 370 | // Add FEC packet (seq#2) of this first frame to received list (i.e., assume |
| 371 | // the two media packet were lost). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 372 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 373 | this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 374 | true); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 375 | |
| 376 | // Construct media packets for second frame, with sequence number wrap. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 377 | this->media_packets_ = |
Niels Möller | 958288a | 2017-10-02 13:51:36 +0200 | [diff] [blame] | 378 | this->media_packet_generator_.ConstructMediaPackets(3, 32767); |
| 379 | |
| 380 | // Expect 3 media packets for this frame. |
| 381 | EXPECT_EQ(3u, this->media_packets_.size()); |
| 382 | |
| 383 | // No packets lost |
| 384 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 385 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
| 386 | |
| 387 | // Construct media packets for third frame, with sequence number wrap. |
| 388 | this->media_packets_ = |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 389 | this->media_packet_generator_.ConstructMediaPackets(3, 65535); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 390 | |
| 391 | // Expect 3 media packets for this frame. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 392 | EXPECT_EQ(3u, this->media_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 393 | |
| 394 | // Second media packet lost (seq#0). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 395 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 396 | this->media_loss_mask_[1] = 1; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 397 | // Add packets #65535, and #1 to received list. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 398 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 399 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 400 | for (const auto& received_packet : this->received_packets_) { |
| 401 | this->fec_.DecodeFec(*received_packet, |
| 402 | &this->recovered_packets_); |
| 403 | } |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 404 | |
Niels Möller | 958288a | 2017-10-02 13:51:36 +0200 | [diff] [blame] | 405 | // Expect that no decoding is done to get missing packet (seq#0) of third |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 406 | // frame, using old FEC packet (seq#2) from first (old) frame. So number of |
Niels Möller | 958288a | 2017-10-02 13:51:36 +0200 | [diff] [blame] | 407 | // recovered packets is 5 (0 from first frame, three from second frame, and 2 |
| 408 | // for the third frame, with no packets recovered via FEC). |
| 409 | EXPECT_EQ(5u, this->recovered_packets_.size()); |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 410 | EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 411 | } |
| 412 | |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 413 | // Verify we can still recover frame if sequence number wrap occurs within |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 414 | // the frame and FEC packet following wrap is received after media packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 415 | TYPED_TEST(RtpFecTest, FecRecoveryWithSeqNumGapOneFrameRecovery) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 416 | constexpr int kNumImportantPackets = 0; |
| 417 | constexpr bool kUseUnequalProtection = false; |
| 418 | constexpr uint8_t kProtectionFactor = 20; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 419 | |
| 420 | // One frame, with sequence number wrap in media packets. |
| 421 | // -----Frame 1---- |
| 422 | // #65534(media) #65535(media) #0(media) #1(FEC). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 423 | this->media_packets_ = |
| 424 | this->media_packet_generator_.ConstructMediaPackets(3, 65534); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 425 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 426 | EXPECT_EQ( |
| 427 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 428 | kNumImportantPackets, kUseUnequalProtection, |
| 429 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 430 | |
| 431 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 432 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 433 | |
| 434 | // Lose one media packet (seq# 65535). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 435 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 436 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 437 | this->media_loss_mask_[1] = 1; |
| 438 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 439 | // Add FEC packet to received list following the media packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 440 | this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 441 | true); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 442 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 443 | for (const auto& received_packet : this->received_packets_) { |
| 444 | this->fec_.DecodeFec(*received_packet, |
| 445 | &this->recovered_packets_); |
| 446 | } |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 447 | |
| 448 | // Expect 3 media packets in recovered list, and complete recovery. |
| 449 | // Wrap-around won't remove FEC packet, as it follows the wrap. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 450 | EXPECT_EQ(3u, this->recovered_packets_.size()); |
| 451 | EXPECT_TRUE(this->IsRecoveryComplete()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 452 | } |
| 453 | |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 454 | // Sequence number wrap occurs within the ULPFEC packets for the frame. |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 455 | // Same problem will occur if wrap is within media packets but ULPFEC packet is |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 456 | // received before the media packets. This may be improved if timing information |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 457 | // is used to detect old ULPFEC packets. |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 458 | |
| 459 | // TODO(nisse): There's some logic to discard ULPFEC packets at wrap-around, |
| 460 | // however, that is not actually exercised by this test: When the first FEC |
| 461 | // packet is processed, it results in full recovery of one media packet and the |
| 462 | // FEC packet is forgotten. And then the wraparound isn't noticed when the next |
| 463 | // FEC packet is received. We should fix wraparound handling, which currently |
| 464 | // appears broken, and then figure out how to test it properly. |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 465 | using RtpFecTestUlpfecOnly = RtpFecTest<UlpfecForwardErrorCorrection>; |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 466 | TEST_F(RtpFecTestUlpfecOnly, FecRecoveryWithSeqNumGapOneFrameRecovery) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 467 | constexpr int kNumImportantPackets = 0; |
| 468 | constexpr bool kUseUnequalProtection = false; |
| 469 | constexpr uint8_t kProtectionFactor = 200; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 470 | |
| 471 | // 1 frame: 3 media packets and 2 FEC packets. |
| 472 | // Sequence number wrap in FEC packets. |
| 473 | // -----Frame 1---- |
| 474 | // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 475 | this->media_packets_ = |
| 476 | this->media_packet_generator_.ConstructMediaPackets(3, 65532); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 477 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 478 | EXPECT_EQ( |
| 479 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 480 | kNumImportantPackets, kUseUnequalProtection, |
| 481 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 482 | |
| 483 | // Expect 2 FEC packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 484 | EXPECT_EQ(2u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 485 | |
| 486 | // Lose the last two media packets (seq# 65533, 65534). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 487 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 488 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 489 | this->media_loss_mask_[1] = 1; |
| 490 | this->media_loss_mask_[2] = 1; |
| 491 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
| 492 | this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 493 | true); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 494 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 495 | for (const auto& received_packet : this->received_packets_) { |
| 496 | this->fec_.DecodeFec(*received_packet, |
| 497 | &this->recovered_packets_); |
| 498 | } |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 499 | |
| 500 | // The two FEC packets are received and should allow for complete recovery, |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 501 | // but because of the wrap the first FEC packet will be discarded, and only |
| 502 | // one media packet is recoverable. So expect 2 media packets on recovered |
| 503 | // list and no complete recovery. |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 504 | EXPECT_EQ(3u, this->recovered_packets_.size()); |
| 505 | EXPECT_EQ(this->recovered_packets_.size(), this->media_packets_.size()); |
| 506 | EXPECT_TRUE(this->IsRecoveryComplete()); |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // TODO(brandtr): This test mimics the one above, ensuring that the recovery |
| 510 | // strategy of FlexFEC matches the recovery strategy of ULPFEC. Since FlexFEC |
| 511 | // does not share the sequence number space with the media, however, having a |
| 512 | // matching recovery strategy may be suboptimal. Study this further. |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 513 | // TODO(nisse): In this test, recovery based on the first FEC packet fails with |
| 514 | // the log message "The recovered packet had a length larger than a typical IP |
| 515 | // packet, and is thus dropped." This is probably not intended, and needs |
| 516 | // investigation. |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 517 | using RtpFecTestFlexfecOnly = RtpFecTest<FlexfecForwardErrorCorrection>; |
| 518 | TEST_F(RtpFecTestFlexfecOnly, FecRecoveryWithSeqNumGapOneFrameNoRecovery) { |
| 519 | constexpr int kNumImportantPackets = 0; |
| 520 | constexpr bool kUseUnequalProtection = false; |
| 521 | constexpr uint8_t kProtectionFactor = 200; |
| 522 | |
| 523 | // 1 frame: 3 media packets and 2 FEC packets. |
| 524 | // Sequence number wrap in FEC packets. |
| 525 | // -----Frame 1---- |
| 526 | // #65532(media) #65533(media) #65534(media) #65535(FEC) #0(FEC). |
| 527 | this->media_packets_ = |
| 528 | this->media_packet_generator_.ConstructMediaPackets(3, 65532); |
| 529 | |
| 530 | EXPECT_EQ( |
| 531 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 532 | kNumImportantPackets, kUseUnequalProtection, |
| 533 | kFecMaskBursty, &this->generated_fec_packets_)); |
| 534 | |
| 535 | // Expect 2 FEC packets. |
| 536 | EXPECT_EQ(2u, this->generated_fec_packets_.size()); |
| 537 | |
| 538 | // Overwrite the sequence numbers generated by ConstructMediaPackets, |
| 539 | // to make sure that we do have a wrap. |
| 540 | auto it = this->generated_fec_packets_.begin(); |
| 541 | ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 65535); |
| 542 | ++it; |
| 543 | ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 0); |
| 544 | |
| 545 | // Lose the last two media packets (seq# 65533, 65534). |
| 546 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 547 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 548 | this->media_loss_mask_[1] = 1; |
| 549 | this->media_loss_mask_[2] = 1; |
| 550 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
| 551 | this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 552 | true); |
| 553 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 554 | for (const auto& received_packet : this->received_packets_) { |
| 555 | this->fec_.DecodeFec(*received_packet, |
| 556 | &this->recovered_packets_); |
| 557 | } |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 558 | |
| 559 | // The two FEC packets are received and should allow for complete recovery, |
| 560 | // but because of the wrap the first FEC packet will be discarded, and only |
| 561 | // one media packet is recoverable. So expect 2 media packets on recovered |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 562 | // list and no complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 563 | EXPECT_EQ(2u, this->recovered_packets_.size()); |
| 564 | EXPECT_TRUE(this->recovered_packets_.size() != this->media_packets_.size()); |
| 565 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 566 | } |
| 567 | |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 568 | // Verify we can still recover frame if media packets are reordered. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 569 | TYPED_TEST(RtpFecTest, FecRecoveryWithMediaOutOfOrder) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 570 | constexpr int kNumImportantPackets = 0; |
| 571 | constexpr bool kUseUnequalProtection = false; |
| 572 | constexpr uint8_t kProtectionFactor = 20; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 573 | |
| 574 | // One frame: 3 media packets, 1 FEC packet. |
| 575 | // -----Frame 1---- |
| 576 | // #0(media) #1(media) #2(media) #3(FEC). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 577 | this->media_packets_ = |
| 578 | this->media_packet_generator_.ConstructMediaPackets(3, 0); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 579 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 580 | EXPECT_EQ( |
| 581 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 582 | kNumImportantPackets, kUseUnequalProtection, |
| 583 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 584 | |
| 585 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 586 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 587 | |
| 588 | // Lose one media packet (seq# 1). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 589 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 590 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 591 | this->media_loss_mask_[1] = 1; |
| 592 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 593 | |
| 594 | // Reorder received media packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 595 | auto it0 = this->received_packets_.begin(); |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 596 | auto it1 = this->received_packets_.begin(); |
| 597 | it1++; |
| 598 | std::swap(*it0, *it1); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 599 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 600 | for (const auto& received_packet : this->received_packets_) { |
| 601 | this->fec_.DecodeFec(*received_packet, |
| 602 | &this->recovered_packets_); |
| 603 | } |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 604 | |
| 605 | // Expect 3 media packets in recovered list, and complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 606 | EXPECT_EQ(3u, this->recovered_packets_.size()); |
| 607 | EXPECT_TRUE(this->IsRecoveryComplete()); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | // Verify we can still recover frame if FEC is received before media packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 611 | TYPED_TEST(RtpFecTest, FecRecoveryWithFecOutOfOrder) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 612 | constexpr int kNumImportantPackets = 0; |
| 613 | constexpr bool kUseUnequalProtection = false; |
| 614 | constexpr uint8_t kProtectionFactor = 20; |
| 615 | |
| 616 | // One frame: 3 media packets, 1 FEC packet. |
| 617 | // -----Frame 1---- |
| 618 | // #0(media) #1(media) #2(media) #3(FEC). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 619 | this->media_packets_ = |
| 620 | this->media_packet_generator_.ConstructMediaPackets(3, 0); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 621 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 622 | EXPECT_EQ( |
| 623 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 624 | kNumImportantPackets, kUseUnequalProtection, |
| 625 | kFecMaskBursty, &this->generated_fec_packets_)); |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 626 | |
| 627 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 628 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 629 | |
| 630 | // Lose one media packet (seq# 1). |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 631 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 632 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 633 | this->media_loss_mask_[1] = 1; |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 634 | // Add FEC packet to received list before the media packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 635 | this->ReceivedPackets(this->generated_fec_packets_, this->fec_loss_mask_, |
| 636 | true); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 637 | // Add media packets to received list. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 638 | this->ReceivedPackets(this->media_packets_, this->media_loss_mask_, false); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 639 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 640 | for (const auto& received_packet : this->received_packets_) { |
| 641 | this->fec_.DecodeFec(*received_packet, |
| 642 | &this->recovered_packets_); |
| 643 | } |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 644 | |
| 645 | // Expect 3 media packets in recovered list, and complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 646 | EXPECT_EQ(3u, this->recovered_packets_.size()); |
| 647 | EXPECT_TRUE(this->IsRecoveryComplete()); |
marpan@webrtc.org | c836453 | 2014-07-03 16:49:30 +0000 | [diff] [blame] | 648 | } |
| 649 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 650 | // Test 50% protection with random mask type: Two cases are considered: |
| 651 | // a 50% non-consecutive loss which can be fully recovered, and a 50% |
| 652 | // consecutive loss which cannot be fully recovered. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 653 | TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percRandomMask) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 654 | constexpr int kNumImportantPackets = 0; |
| 655 | constexpr bool kUseUnequalProtection = false; |
| 656 | constexpr int kNumMediaPackets = 4; |
| 657 | constexpr uint8_t kProtectionFactor = 255; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 658 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 659 | // Packet Mask for (4,4,0) code, from random mask table. |
| 660 | // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 661 | |
| 662 | // media#0 media#1 media#2 media#3 |
| 663 | // fec#0: 1 1 0 0 |
| 664 | // fec#1: 1 0 1 0 |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 665 | // fec#2: 0 0 1 1 |
| 666 | // fec#3: 0 1 0 1 |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 667 | // |
| 668 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 669 | this->media_packets_ = |
| 670 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 671 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 672 | EXPECT_EQ( |
| 673 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 674 | kNumImportantPackets, kUseUnequalProtection, |
| 675 | kFecMaskRandom, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 676 | |
| 677 | // Expect 4 FEC packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 678 | EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 679 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 680 | // 4 packets lost: 3 media packets (0, 2, 3), and one FEC packet (0) lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 681 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 682 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 683 | this->fec_loss_mask_[0] = 1; |
| 684 | this->media_loss_mask_[0] = 1; |
| 685 | this->media_loss_mask_[2] = 1; |
| 686 | this->media_loss_mask_[3] = 1; |
| 687 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 688 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 689 | for (const auto& received_packet : this->received_packets_) { |
| 690 | this->fec_.DecodeFec(*received_packet, |
| 691 | &this->recovered_packets_); |
| 692 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 693 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 694 | // With media packet#1 and FEC packets #1, #2, #3, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 695 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 696 | this->recovered_packets_.clear(); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 697 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 698 | // 4 consecutive packets lost: media packets 0, 1, 2, 3. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 699 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 700 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 701 | this->media_loss_mask_[0] = 1; |
| 702 | this->media_loss_mask_[1] = 1; |
| 703 | this->media_loss_mask_[2] = 1; |
| 704 | this->media_loss_mask_[3] = 1; |
| 705 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 706 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 707 | for (const auto& received_packet : this->received_packets_) { |
| 708 | this->fec_.DecodeFec(*received_packet, |
| 709 | &this->recovered_packets_); |
| 710 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 711 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 712 | // Cannot get complete recovery for this loss configuration with random mask. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 713 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // Test 50% protection with bursty type: Three cases are considered: |
| 717 | // two 50% consecutive losses which can be fully recovered, and one |
| 718 | // non-consecutive which cannot be fully recovered. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 719 | TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percBurstyMask) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 720 | constexpr int kNumImportantPackets = 0; |
| 721 | constexpr bool kUseUnequalProtection = false; |
| 722 | constexpr int kNumMediaPackets = 4; |
| 723 | constexpr uint8_t kProtectionFactor = 255; |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 724 | |
| 725 | // Packet Mask for (4,4,0) code, from bursty mask table. |
| 726 | // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 0) |
| 727 | |
| 728 | // media#0 media#1 media#2 media#3 |
| 729 | // fec#0: 1 0 0 0 |
| 730 | // fec#1: 1 1 0 0 |
| 731 | // fec#2: 0 1 1 0 |
| 732 | // fec#3: 0 0 1 1 |
| 733 | // |
| 734 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 735 | this->media_packets_ = |
| 736 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 737 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 738 | EXPECT_EQ( |
| 739 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 740 | kNumImportantPackets, kUseUnequalProtection, |
| 741 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 742 | |
| 743 | // Expect 4 FEC packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 744 | EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 745 | |
| 746 | // 4 consecutive packets lost: media packets 0,1,2,3. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 747 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 748 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 749 | this->media_loss_mask_[0] = 1; |
| 750 | this->media_loss_mask_[1] = 1; |
| 751 | this->media_loss_mask_[2] = 1; |
| 752 | this->media_loss_mask_[3] = 1; |
| 753 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 754 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 755 | for (const auto& received_packet : this->received_packets_) { |
| 756 | this->fec_.DecodeFec(*received_packet, |
| 757 | &this->recovered_packets_); |
| 758 | } |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 759 | |
| 760 | // Expect complete recovery for consecutive packet loss <= 50%. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 761 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 762 | this->recovered_packets_.clear(); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 763 | |
| 764 | // 4 consecutive packets lost: media packets 1,2, 3, and FEC packet 0. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 765 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 766 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 767 | this->fec_loss_mask_[0] = 1; |
| 768 | this->media_loss_mask_[1] = 1; |
| 769 | this->media_loss_mask_[2] = 1; |
| 770 | this->media_loss_mask_[3] = 1; |
| 771 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 772 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 773 | for (const auto& received_packet : this->received_packets_) { |
| 774 | this->fec_.DecodeFec(*received_packet, |
| 775 | &this->recovered_packets_); |
| 776 | } |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 777 | |
| 778 | // Expect complete recovery for consecutive packet loss <= 50%. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 779 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 780 | this->recovered_packets_.clear(); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 781 | |
| 782 | // 4 packets lost (non-consecutive loss): media packets 0, 3, and FEC# 0, 3. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 783 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 784 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 785 | this->fec_loss_mask_[0] = 1; |
| 786 | this->fec_loss_mask_[3] = 1; |
| 787 | this->media_loss_mask_[0] = 1; |
| 788 | this->media_loss_mask_[3] = 1; |
| 789 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 790 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 791 | for (const auto& received_packet : this->received_packets_) { |
| 792 | this->fec_.DecodeFec(*received_packet, |
| 793 | &this->recovered_packets_); |
| 794 | } |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 795 | |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 796 | // Cannot get complete recovery for this loss configuration. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 797 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 798 | } |
| 799 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 800 | TYPED_TEST(RtpFecTest, FecRecoveryNoLossUep) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 801 | constexpr int kNumImportantPackets = 2; |
| 802 | constexpr bool kUseUnequalProtection = true; |
| 803 | constexpr int kNumMediaPackets = 4; |
| 804 | constexpr uint8_t kProtectionFactor = 60; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 805 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 806 | this->media_packets_ = |
| 807 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 808 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 809 | EXPECT_EQ( |
| 810 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 811 | kNumImportantPackets, kUseUnequalProtection, |
| 812 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 813 | |
| 814 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 815 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 816 | |
| 817 | // No packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 818 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 819 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 820 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 821 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 822 | for (const auto& received_packet : this->received_packets_) { |
| 823 | this->fec_.DecodeFec(*received_packet, |
| 824 | &this->recovered_packets_); |
| 825 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 826 | |
| 827 | // No packets lost, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 828 | EXPECT_TRUE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 829 | } |
| 830 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 831 | TYPED_TEST(RtpFecTest, FecRecoveryWithLossUep) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 832 | constexpr int kNumImportantPackets = 2; |
| 833 | constexpr bool kUseUnequalProtection = true; |
| 834 | constexpr int kNumMediaPackets = 4; |
| 835 | constexpr uint8_t kProtectionFactor = 60; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 836 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 837 | this->media_packets_ = |
| 838 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 839 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 840 | EXPECT_EQ( |
| 841 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 842 | kNumImportantPackets, kUseUnequalProtection, |
| 843 | kFecMaskBursty, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 844 | |
| 845 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 846 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 847 | |
| 848 | // 1 media packet lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 849 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 850 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 851 | this->media_loss_mask_[3] = 1; |
| 852 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 853 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 854 | for (const auto& received_packet : this->received_packets_) { |
| 855 | this->fec_.DecodeFec(*received_packet, |
| 856 | &this->recovered_packets_); |
| 857 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 858 | |
| 859 | // One packet lost, one FEC packet, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 860 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 861 | this->recovered_packets_.clear(); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 862 | |
| 863 | // 2 media packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 864 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 865 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 866 | this->media_loss_mask_[1] = 1; |
| 867 | this->media_loss_mask_[3] = 1; |
| 868 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 869 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 870 | for (const auto& received_packet : this->received_packets_) { |
| 871 | this->fec_.DecodeFec(*received_packet, |
| 872 | &this->recovered_packets_); |
| 873 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 874 | |
| 875 | // 2 packets lost, one FEC packet, cannot get complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 876 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 877 | } |
| 878 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 879 | // Test 50% protection with random mask type for UEP on. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 880 | TYPED_TEST(RtpFecTest, FecRecoveryWithLoss50percUepRandomMask) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 881 | constexpr int kNumImportantPackets = 1; |
| 882 | constexpr bool kUseUnequalProtection = true; |
| 883 | constexpr int kNumMediaPackets = 4; |
| 884 | constexpr uint8_t kProtectionFactor = 255; |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 885 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 886 | // Packet Mask for (4,4,1) code, from random mask table. |
| 887 | // (kNumMediaPackets = 4; num_fec_packets = 4, kNumImportantPackets = 1) |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 888 | |
| 889 | // media#0 media#1 media#2 media#3 |
| 890 | // fec#0: 1 0 0 0 |
| 891 | // fec#1: 1 1 0 0 |
| 892 | // fec#2: 1 0 1 1 |
| 893 | // fec#3: 0 1 1 0 |
| 894 | // |
| 895 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 896 | this->media_packets_ = |
| 897 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 898 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 899 | EXPECT_EQ( |
| 900 | 0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor, |
| 901 | kNumImportantPackets, kUseUnequalProtection, |
| 902 | kFecMaskRandom, &this->generated_fec_packets_)); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 903 | |
| 904 | // Expect 4 FEC packets. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 905 | EXPECT_EQ(4u, this->generated_fec_packets_.size()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 906 | |
| 907 | // 4 packets lost: 3 media packets and FEC packet#1 lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 908 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 909 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 910 | this->fec_loss_mask_[1] = 1; |
| 911 | this->media_loss_mask_[0] = 1; |
| 912 | this->media_loss_mask_[2] = 1; |
| 913 | this->media_loss_mask_[3] = 1; |
| 914 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 915 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 916 | for (const auto& received_packet : this->received_packets_) { |
| 917 | this->fec_.DecodeFec(*received_packet, |
| 918 | &this->recovered_packets_); |
| 919 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 920 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 921 | // With media packet#3 and FEC packets #0, #1, #3, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 922 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 923 | this->recovered_packets_.clear(); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 924 | |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 925 | // 5 packets lost: 4 media packets and one FEC packet#2 lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 926 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 927 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 928 | this->fec_loss_mask_[2] = 1; |
| 929 | this->media_loss_mask_[0] = 1; |
| 930 | this->media_loss_mask_[1] = 1; |
| 931 | this->media_loss_mask_[2] = 1; |
| 932 | this->media_loss_mask_[3] = 1; |
| 933 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 934 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 935 | for (const auto& received_packet : this->received_packets_) { |
| 936 | this->fec_.DecodeFec(*received_packet, |
| 937 | &this->recovered_packets_); |
| 938 | } |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 939 | |
| 940 | // Cannot get complete recovery for this loss configuration. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 941 | EXPECT_FALSE(this->IsRecoveryComplete()); |
marpan@webrtc.org | b783a55 | 2012-02-04 02:46:35 +0000 | [diff] [blame] | 942 | } |
| 943 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 944 | TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePackets) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 945 | constexpr int kNumImportantPackets = 0; |
| 946 | constexpr bool kUseUnequalProtection = false; |
| 947 | constexpr int kNumMediaPackets = 5; |
| 948 | constexpr uint8_t kProtectionFactor = 60; |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 949 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 950 | this->media_packets_ = |
| 951 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 952 | |
| 953 | // Create a new temporary packet list for generating FEC packets. |
| 954 | // This list should have every other packet removed. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 955 | ForwardErrorCorrection::PacketList protected_media_packets; |
| 956 | DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 957 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 958 | EXPECT_EQ( |
| 959 | 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
| 960 | kNumImportantPackets, kUseUnequalProtection, |
| 961 | kFecMaskBursty, &this->generated_fec_packets_)); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 962 | |
| 963 | // Expect 1 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 964 | EXPECT_EQ(1u, this->generated_fec_packets_.size()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 965 | |
| 966 | // 1 protected media packet lost |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 967 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 968 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 969 | this->media_loss_mask_[2] = 1; |
| 970 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 971 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 972 | for (const auto& received_packet : this->received_packets_) { |
| 973 | this->fec_.DecodeFec(*received_packet, |
| 974 | &this->recovered_packets_); |
| 975 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 976 | |
| 977 | // One packet lost, one FEC packet, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 978 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 979 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 980 | |
| 981 | // Unprotected packet lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 982 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 983 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 984 | this->media_loss_mask_[1] = 1; |
| 985 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 986 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 987 | for (const auto& received_packet : this->received_packets_) { |
| 988 | this->fec_.DecodeFec(*received_packet, |
| 989 | &this->recovered_packets_); |
| 990 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 991 | |
| 992 | // Unprotected packet lost. Recovery not possible. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 993 | EXPECT_FALSE(this->IsRecoveryComplete()); |
| 994 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 995 | |
| 996 | // 2 media packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 997 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 998 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 999 | this->media_loss_mask_[0] = 1; |
| 1000 | this->media_loss_mask_[2] = 1; |
| 1001 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1002 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1003 | for (const auto& received_packet : this->received_packets_) { |
| 1004 | this->fec_.DecodeFec(*received_packet, |
| 1005 | &this->recovered_packets_); |
| 1006 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1007 | |
| 1008 | // 2 protected packets lost, one FEC packet, cannot get complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1009 | EXPECT_FALSE(this->IsRecoveryComplete()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1012 | TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsExtension) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 1013 | constexpr int kNumImportantPackets = 0; |
| 1014 | constexpr bool kUseUnequalProtection = false; |
| 1015 | constexpr int kNumMediaPackets = 21; |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 1016 | uint8_t kProtectionFactor = 127; |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1017 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1018 | this->media_packets_ = |
| 1019 | this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1020 | |
| 1021 | // Create a new temporary packet list for generating FEC packets. |
| 1022 | // This list should have every other packet removed. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1023 | ForwardErrorCorrection::PacketList protected_media_packets; |
| 1024 | DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Zero column insertion will have to extend the size of the packet |
| 1027 | // mask since the number of actual packets are 21, while the number |
| 1028 | // of protected packets are 11. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1029 | EXPECT_EQ( |
| 1030 | 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
| 1031 | kNumImportantPackets, kUseUnequalProtection, |
| 1032 | kFecMaskBursty, &this->generated_fec_packets_)); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1033 | |
| 1034 | // Expect 5 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1035 | EXPECT_EQ(5u, this->generated_fec_packets_.size()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1036 | |
| 1037 | // Last protected media packet lost |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1038 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1039 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1040 | this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
| 1041 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1042 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1043 | for (const auto& received_packet : this->received_packets_) { |
| 1044 | this->fec_.DecodeFec(*received_packet, |
| 1045 | &this->recovered_packets_); |
| 1046 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1047 | |
| 1048 | // One packet lost, one FEC packet, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1049 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 1050 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1051 | |
| 1052 | // Last unprotected packet lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1053 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1054 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1055 | this->media_loss_mask_[kNumMediaPackets - 2] = 1; |
| 1056 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1057 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1058 | for (const auto& received_packet : this->received_packets_) { |
| 1059 | this->fec_.DecodeFec(*received_packet, |
| 1060 | &this->recovered_packets_); |
| 1061 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1062 | |
| 1063 | // Unprotected packet lost. Recovery not possible. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1064 | EXPECT_FALSE(this->IsRecoveryComplete()); |
| 1065 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1066 | |
| 1067 | // 6 media packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1068 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1069 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1070 | this->media_loss_mask_[kNumMediaPackets - 11] = 1; |
| 1071 | this->media_loss_mask_[kNumMediaPackets - 9] = 1; |
| 1072 | this->media_loss_mask_[kNumMediaPackets - 7] = 1; |
| 1073 | this->media_loss_mask_[kNumMediaPackets - 5] = 1; |
| 1074 | this->media_loss_mask_[kNumMediaPackets - 3] = 1; |
| 1075 | this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
| 1076 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1077 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1078 | for (const auto& received_packet : this->received_packets_) { |
| 1079 | this->fec_.DecodeFec(*received_packet, |
| 1080 | &this->recovered_packets_); |
| 1081 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1082 | |
| 1083 | // 5 protected packets lost, one FEC packet, cannot get complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1084 | EXPECT_FALSE(this->IsRecoveryComplete()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1087 | TYPED_TEST(RtpFecTest, FecRecoveryNonConsecutivePacketsWrap) { |
brandtr | d90fa0b | 2016-08-09 06:57:14 -0700 | [diff] [blame] | 1088 | constexpr int kNumImportantPackets = 0; |
| 1089 | constexpr bool kUseUnequalProtection = false; |
| 1090 | constexpr int kNumMediaPackets = 21; |
marpan@webrtc.org | 8866bb1 | 2012-06-05 16:42:20 +0000 | [diff] [blame] | 1091 | uint8_t kProtectionFactor = 127; |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1092 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1093 | this->media_packets_ = this->media_packet_generator_.ConstructMediaPackets( |
| 1094 | kNumMediaPackets, 0xFFFF - 5); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1095 | |
| 1096 | // Create a new temporary packet list for generating FEC packets. |
| 1097 | // This list should have every other packet removed. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1098 | ForwardErrorCorrection::PacketList protected_media_packets; |
| 1099 | DeepCopyEveryNthPacket(this->media_packets_, 2, &protected_media_packets); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1100 | |
| 1101 | // Zero column insertion will have to extend the size of the packet |
| 1102 | // mask since the number of actual packets are 21, while the number |
| 1103 | // of protected packets are 11. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1104 | EXPECT_EQ( |
| 1105 | 0, this->fec_.EncodeFec(protected_media_packets, kProtectionFactor, |
| 1106 | kNumImportantPackets, kUseUnequalProtection, |
| 1107 | kFecMaskBursty, &this->generated_fec_packets_)); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1108 | |
| 1109 | // Expect 5 FEC packet. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1110 | EXPECT_EQ(5u, this->generated_fec_packets_.size()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1111 | |
| 1112 | // Last protected media packet lost |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1113 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1114 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1115 | this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
| 1116 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1117 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1118 | for (const auto& received_packet : this->received_packets_) { |
| 1119 | this->fec_.DecodeFec(*received_packet, |
| 1120 | &this->recovered_packets_); |
| 1121 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1122 | |
| 1123 | // One packet lost, one FEC packet, expect complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1124 | EXPECT_TRUE(this->IsRecoveryComplete()); |
| 1125 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1126 | |
| 1127 | // Last unprotected packet lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1128 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1129 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1130 | this->media_loss_mask_[kNumMediaPackets - 2] = 1; |
| 1131 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1132 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1133 | for (const auto& received_packet : this->received_packets_) { |
| 1134 | this->fec_.DecodeFec(*received_packet, |
| 1135 | &this->recovered_packets_); |
| 1136 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1137 | |
| 1138 | // Unprotected packet lost. Recovery not possible. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1139 | EXPECT_FALSE(this->IsRecoveryComplete()); |
| 1140 | this->recovered_packets_.clear(); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1141 | |
| 1142 | // 6 media packets lost. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1143 | memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_)); |
| 1144 | memset(this->fec_loss_mask_, 0, sizeof(this->fec_loss_mask_)); |
| 1145 | this->media_loss_mask_[kNumMediaPackets - 11] = 1; |
| 1146 | this->media_loss_mask_[kNumMediaPackets - 9] = 1; |
| 1147 | this->media_loss_mask_[kNumMediaPackets - 7] = 1; |
| 1148 | this->media_loss_mask_[kNumMediaPackets - 5] = 1; |
| 1149 | this->media_loss_mask_[kNumMediaPackets - 3] = 1; |
| 1150 | this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
| 1151 | this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1152 | |
nisse | a5f043f | 2017-09-18 07:58:59 -0700 | [diff] [blame] | 1153 | for (const auto& received_packet : this->received_packets_) { |
| 1154 | this->fec_.DecodeFec(*received_packet, |
| 1155 | &this->recovered_packets_); |
| 1156 | } |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1157 | |
| 1158 | // 5 protected packets lost, one FEC packet, cannot get complete recovery. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1159 | EXPECT_FALSE(this->IsRecoveryComplete()); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 1162 | } // namespace webrtc |