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