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