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 #include <memory> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/base/basictypes.h" | 16 #include "webrtc/base/basictypes.h" |
17 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
19 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" | 19 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
20 #include "webrtc/modules/rtp_rtcp/source/flexfec_header_reader_writer.h" | |
20 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 21 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
21 #include "webrtc/modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" | 22 #include "webrtc/modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. | 28 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
28 constexpr size_t kTransportOverhead = 28; | 29 constexpr size_t kTransportOverhead = 28; |
29 | 30 |
30 constexpr uint32_t kMediaSsrc = 83542; | 31 constexpr uint32_t kMediaSsrc = 83542; |
32 constexpr uint32_t kFlexfecSsrc = 43245; | |
31 | 33 |
32 // Deep copies |src| to |dst|, but only keeps every Nth packet. | 34 // Deep copies |src| to |dst|, but only keeps every Nth packet. |
33 void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, | 35 void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, |
34 int n, | 36 int n, |
35 ForwardErrorCorrection::PacketList* dst) { | 37 ForwardErrorCorrection::PacketList* dst) { |
36 RTC_DCHECK_GT(n, 0); | 38 RTC_DCHECK_GT(n, 0); |
37 int i = 0; | 39 int i = 0; |
38 for (const auto& packet : src) { | 40 for (const auto& packet : src) { |
39 if (i % n == 0) { | 41 if (i % n == 0) { |
40 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); | 42 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 bool RtpFecTest<ForwardErrorCorrectionType>::IsRecoveryComplete() { | 148 bool RtpFecTest<ForwardErrorCorrectionType>::IsRecoveryComplete() { |
147 // We must have equally many recovered packets as original packets. | 149 // We must have equally many recovered packets as original packets. |
148 if (recovered_packets_.size() != media_packets_.size()) { | 150 if (recovered_packets_.size() != media_packets_.size()) { |
149 return false; | 151 return false; |
150 } | 152 } |
151 | 153 |
152 // All recovered packets must be identical to the corresponding | 154 // All recovered packets must be identical to the corresponding |
153 // original packets. | 155 // original packets. |
154 using PacketPtr = std::unique_ptr<ForwardErrorCorrection::Packet>; | 156 using PacketPtr = std::unique_ptr<ForwardErrorCorrection::Packet>; |
155 using RecoveredPacketPtr = | 157 using RecoveredPacketPtr = |
156 std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>; | 158 std::unique_ptr<ForwardErrorCorrection::RecoveredPacket>; |
157 auto cmp = [](const PacketPtr& media_packet, | 159 auto cmp = [](const PacketPtr& media_packet, |
158 const RecoveredPacketPtr& recovered_packet) { | 160 const RecoveredPacketPtr& recovered_packet) { |
159 if (media_packet->length != recovered_packet->pkt->length) { | 161 if (media_packet->length != recovered_packet->pkt->length) { |
160 return false; | 162 return false; |
161 } | 163 } |
162 if (memcmp(media_packet->data, | 164 if (memcmp(media_packet->data, recovered_packet->pkt->data, |
163 recovered_packet->pkt->data, | |
164 media_packet->length) != 0) { | 165 media_packet->length) != 0) { |
165 return false; | 166 return false; |
166 } | 167 } |
167 return true; | 168 return true; |
168 }; | 169 }; |
169 return std::equal(media_packets_.cbegin(), media_packets_.cend(), | 170 return std::equal(media_packets_.cbegin(), media_packets_.cend(), |
170 recovered_packets_.cbegin(), cmp); | 171 recovered_packets_.cbegin(), cmp); |
171 } | 172 } |
172 | 173 |
173 // Define gTest typed test to loop over both ULPFEC and FlexFEC. | 174 // Define gTest typed test to loop over both ULPFEC and FlexFEC. |
174 // Since the tests now are parameterized, we need to access | 175 // Since the tests now are parameterized, we need to access |
175 // member variables using |this|, thereby enforcing runtime | 176 // member variables using |this|, thereby enforcing runtime |
176 // resolution. | 177 // resolution. |
177 | 178 |
179 class FlexfecForwardErrorCorrection : public ForwardErrorCorrection { | |
180 public: | |
181 FlexfecForwardErrorCorrection() | |
182 : ForwardErrorCorrection( | |
183 std::unique_ptr<FecHeaderReader>(new FlexfecHeaderReader()), | |
184 std::unique_ptr<FecHeaderWriter>(new FlexfecHeaderWriter())) {} | |
185 }; | |
186 | |
178 class UlpfecForwardErrorCorrection : public ForwardErrorCorrection { | 187 class UlpfecForwardErrorCorrection : public ForwardErrorCorrection { |
179 public: | 188 public: |
180 UlpfecForwardErrorCorrection() | 189 UlpfecForwardErrorCorrection() |
181 : ForwardErrorCorrection( | 190 : ForwardErrorCorrection( |
182 std::unique_ptr<FecHeaderReader>(new UlpfecHeaderReader()), | 191 std::unique_ptr<FecHeaderReader>(new UlpfecHeaderReader()), |
183 std::unique_ptr<FecHeaderWriter>(new UlpfecHeaderWriter())) {} | 192 std::unique_ptr<FecHeaderWriter>(new UlpfecHeaderWriter())) {} |
184 }; | 193 }; |
185 | 194 |
186 using FecTypes = Types<UlpfecForwardErrorCorrection>; | 195 using FecTypes = |
196 Types<FlexfecForwardErrorCorrection, UlpfecForwardErrorCorrection>; | |
187 TYPED_TEST_CASE(RtpFecTest, FecTypes); | 197 TYPED_TEST_CASE(RtpFecTest, FecTypes); |
188 | 198 |
189 TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { | 199 TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { |
190 constexpr int kNumImportantPackets = 0; | 200 constexpr int kNumImportantPackets = 0; |
191 constexpr bool kUseUnequalProtection = false; | 201 constexpr bool kUseUnequalProtection = false; |
192 constexpr int kNumMediaPackets = 4; | 202 constexpr int kNumMediaPackets = 4; |
193 constexpr uint8_t kProtectionFactor = 60; | 203 constexpr uint8_t kProtectionFactor = 60; |
194 | 204 |
195 this->media_packets_ = | 205 this->media_packets_ = |
196 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); | 206 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 this->media_loss_mask_[kNumMediaPackets - 1] = 1; | 953 this->media_loss_mask_[kNumMediaPackets - 1] = 1; |
944 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); | 954 this->NetworkReceivedPackets(this->media_loss_mask_, this->fec_loss_mask_); |
945 | 955 |
946 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, | 956 EXPECT_EQ(0, this->fec_.DecodeFec(&this->received_packets_, |
947 &this->recovered_packets_)); | 957 &this->recovered_packets_)); |
948 | 958 |
949 // 5 protected packets lost, one FEC packet, cannot get complete recovery. | 959 // 5 protected packets lost, one FEC packet, cannot get complete recovery. |
950 EXPECT_FALSE(this->IsRecoveryComplete()); | 960 EXPECT_FALSE(this->IsRecoveryComplete()); |
951 } | 961 } |
952 | 962 |
963 // 'using' directive needed for compiler to be happy. | |
964 using RtpFecTestWithFlexfec = RtpFecTest<FlexfecForwardErrorCorrection>; | |
965 TEST_F(RtpFecTestWithFlexfec, | |
966 FecRecoveryWithLossAndDifferentMediaAndFlexfecSsrcs) { | |
967 constexpr int kNumImportantPackets = 0; | |
968 constexpr bool kUseUnequalProtection = false; | |
969 constexpr int kNumMediaPackets = 4; | |
970 constexpr uint8_t kProtectionFactor = 60; | |
971 | |
972 media_packets_ = | |
973 media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); | |
974 | |
975 EXPECT_EQ(0, fec_.EncodeFec(media_packets_, kProtectionFactor, | |
976 kNumImportantPackets, kUseUnequalProtection, | |
977 kFecMaskBursty, &generated_fec_packets_)); | |
978 | |
979 // Expect 1 FEC packet. | |
980 EXPECT_EQ(1u, generated_fec_packets_.size()); | |
981 | |
982 // 1 media packet lost | |
983 memset(media_loss_mask_, 0, sizeof(media_loss_mask_)); | |
984 memset(fec_loss_mask_, 0, sizeof(fec_loss_mask_)); | |
985 media_loss_mask_[3] = 1; | |
986 NetworkReceivedPackets(media_loss_mask_, fec_loss_mask_); | |
987 | |
988 // Simulate FlexFEC packet received on different SSRC. | |
danilchap
2016/09/06 09:40:53
Why do you need to simulate?
Does it mean EncodeFe
brandtr
2016/09/07 08:21:14
That's right. EncodeFec is oblivious to if the FEC
| |
989 auto it = received_packets_.begin(); | |
990 it++; | |
991 it++; | |
992 it++; // Now at the FEC packet. | |
993 (*it)->ssrc = kFlexfecSsrc; | |
994 | |
995 EXPECT_EQ(0, fec_.DecodeFec(&received_packets_, &recovered_packets_)); | |
996 | |
997 // One packet lost, one FEC packet, expect complete recovery. | |
998 EXPECT_TRUE(IsRecoveryComplete()); | |
999 recovered_packets_.clear(); | |
1000 } | |
1001 | |
953 } // namespace webrtc | 1002 } // namespace webrtc |
OLD | NEW |