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/forward_error_correction.h" | 20 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. | 27 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
27 constexpr size_t kTransportOverhead = 28; | 28 constexpr size_t kTransportOverhead = 28; |
28 | 29 |
29 constexpr uint32_t kMediaSsrc = 83542; | 30 constexpr uint32_t kMediaSsrc = 83542; |
30 | 31 |
31 // Deep copies |src| to |dst|, but only keeps every Nth packet. | 32 // Deep copies |src| to |dst|, but only keeps every Nth packet. |
32 void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, | 33 void DeepCopyEveryNthPacket(const ForwardErrorCorrection::PacketList& src, |
33 int n, | 34 int n, |
34 ForwardErrorCorrection::PacketList* dst) { | 35 ForwardErrorCorrection::PacketList* dst) { |
35 RTC_DCHECK_GT(n, 0); | 36 RTC_DCHECK_GT(n, 0); |
36 int i = 0; | 37 int i = 0; |
37 for (const auto& packet : src) { | 38 for (const auto& packet : src) { |
38 if (i % n == 0) { | 39 if (i % n == 0) { |
39 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); | 40 dst->emplace_back(new ForwardErrorCorrection::Packet(*packet)); |
40 } | 41 } |
41 ++i; | 42 ++i; |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 using ::testing::Types; | 48 using ::testing::Types; |
48 | 49 |
| 50 // Subclass ForwardErrorCorrection to use gTest typed tests. |
| 51 class UlpfecForwardErrorCorrection : public ForwardErrorCorrection { |
| 52 public: |
| 53 UlpfecForwardErrorCorrection() |
| 54 : ForwardErrorCorrection( |
| 55 std::unique_ptr<FecHeaderReader>(new UlpfecHeaderReader()), |
| 56 std::unique_ptr<FecHeaderWriter>(new UlpfecHeaderWriter())) {} |
| 57 }; |
| 58 |
49 template <typename ForwardErrorCorrectionType> | 59 template <typename ForwardErrorCorrectionType> |
50 class RtpFecTest : public ::testing::Test { | 60 class RtpFecTest : public ::testing::Test { |
51 protected: | 61 protected: |
52 RtpFecTest() | 62 RtpFecTest() |
53 : random_(0xabcdef123456), | 63 : random_(0xabcdef123456), |
54 media_packet_generator_( | 64 media_packet_generator_( |
55 kRtpHeaderSize, // Minimum packet size. | 65 kRtpHeaderSize, // Minimum packet size. |
56 IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead - | 66 IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead - |
57 fec_.MaxPacketOverhead(), // Maximum packet size. | 67 fec_.MaxPacketOverhead(), // Maximum packet size. |
58 kMediaSsrc, | 68 kMediaSsrc, |
(...skipping 20 matching lines...) Expand all Loading... |
79 ForwardErrorCorrectionType fec_; | 89 ForwardErrorCorrectionType fec_; |
80 | 90 |
81 Random random_; | 91 Random random_; |
82 test::fec::MediaPacketGenerator media_packet_generator_; | 92 test::fec::MediaPacketGenerator media_packet_generator_; |
83 | 93 |
84 ForwardErrorCorrection::PacketList media_packets_; | 94 ForwardErrorCorrection::PacketList media_packets_; |
85 std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_; | 95 std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_; |
86 ForwardErrorCorrection::ReceivedPacketList received_packets_; | 96 ForwardErrorCorrection::ReceivedPacketList received_packets_; |
87 ForwardErrorCorrection::RecoveredPacketList recovered_packets_; | 97 ForwardErrorCorrection::RecoveredPacketList recovered_packets_; |
88 | 98 |
89 int media_loss_mask_[ForwardErrorCorrection::kMaxMediaPackets]; | 99 int media_loss_mask_[kUlpfecMaxMediaPackets]; |
90 int fec_loss_mask_[ForwardErrorCorrection::kMaxMediaPackets]; | 100 int fec_loss_mask_[kUlpfecMaxMediaPackets]; |
91 }; | 101 }; |
92 | 102 |
93 // Define gTest typed test to loop over both ULPFEC and FlexFEC. | 103 // Define gTest typed test to loop over both ULPFEC and FlexFEC. |
94 // Since the tests now are parameterized, we need to access | 104 // Since the tests now are parameterized, we need to access |
95 // member variables using |this|, thereby enforcing runtime | 105 // member variables using |this|, thereby enforcing runtime |
96 // resolution. | 106 // resolution. |
97 using FecTypes = Types<ForwardErrorCorrection>; | 107 using FecTypes = Types<UlpfecForwardErrorCorrection>; |
98 TYPED_TEST_CASE(RtpFecTest, FecTypes); | 108 TYPED_TEST_CASE(RtpFecTest, FecTypes); |
99 | 109 |
100 TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { | 110 TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { |
101 constexpr int kNumImportantPackets = 0; | 111 constexpr int kNumImportantPackets = 0; |
102 constexpr bool kUseUnequalProtection = false; | 112 constexpr bool kUseUnequalProtection = false; |
103 constexpr int kNumMediaPackets = 4; | 113 constexpr int kNumMediaPackets = 4; |
104 constexpr uint8_t kProtectionFactor = 60; | 114 constexpr uint8_t kProtectionFactor = 60; |
105 | 115 |
106 this->media_packets_ = | 116 this->media_packets_ = |
107 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); | 117 this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets); |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 } | 943 } |
934 packet_idx++; | 944 packet_idx++; |
935 // Sequence number of FEC packets are defined as increment by 1 from | 945 // Sequence number of FEC packets are defined as increment by 1 from |
936 // last media packet in frame. | 946 // last media packet in frame. |
937 if (is_fec) | 947 if (is_fec) |
938 fec_seq_num++; | 948 fec_seq_num++; |
939 } | 949 } |
940 } | 950 } |
941 | 951 |
942 } // namespace webrtc | 952 } // namespace webrtc |
OLD | NEW |