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 <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
17 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" | 17 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
19 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" | 19 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
| 23 namespace { |
| 24 constexpr uint8_t kFecPayloadType = 96; |
| 25 constexpr uint8_t kRedPayloadType = 97; |
| 26 } // namespace |
| 27 |
| 28 using ::webrtc::test::fec::FrameGenerator; |
| 29 using ::webrtc::test::fec::RawRtpPacket; |
| 30 |
23 void VerifyHeader(uint16_t seq_num, | 31 void VerifyHeader(uint16_t seq_num, |
24 uint32_t timestamp, | 32 uint32_t timestamp, |
25 int red_payload_type, | 33 int red_payload_type, |
26 int fec_payload_type, | 34 int fec_payload_type, |
27 RedPacket* packet, | 35 RedPacket* packet, |
28 bool marker_bit) { | 36 bool marker_bit) { |
29 EXPECT_GT(packet->length(), kRtpHeaderSize); | 37 EXPECT_GT(packet->length(), kRtpHeaderSize); |
30 EXPECT_TRUE(packet->data() != NULL); | 38 EXPECT_TRUE(packet->data() != NULL); |
31 uint8_t* data = packet->data(); | 39 uint8_t* data = packet->data(); |
32 // Marker bit not set. | 40 // Marker bit not set. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 98 |
91 TEST_F(ProducerFecTest, OneFrameFec) { | 99 TEST_F(ProducerFecTest, OneFrameFec) { |
92 // The number of media packets (|kNumPackets|), number of frames (one for | 100 // The number of media packets (|kNumPackets|), number of frames (one for |
93 // this test), and the protection factor (|params->fec_rate|) are set to make | 101 // this test), and the protection factor (|params->fec_rate|) are set to make |
94 // sure the conditions for generating FEC are satisfied. This means: | 102 // sure the conditions for generating FEC are satisfied. This means: |
95 // (1) protection factor is high enough so that actual overhead over 1 frame | 103 // (1) protection factor is high enough so that actual overhead over 1 frame |
96 // of packets is within |kMaxExcessOverhead|, and (2) the total number of | 104 // of packets is within |kMaxExcessOverhead|, and (2) the total number of |
97 // media packets for 1 frame is at least |minimum_media_packets_fec_|. | 105 // media packets for 1 frame is at least |minimum_media_packets_fec_|. |
98 const int kNumPackets = 4; | 106 const int kNumPackets = 4; |
99 FecProtectionParams params = {15, 3, kFecMaskRandom}; | 107 FecProtectionParams params = {15, 3, kFecMaskRandom}; |
100 std::list<test::RawRtpPacket*> rtp_packets; | 108 std::list<RawRtpPacket*> rtp_packets; |
101 generator_.NewFrame(kNumPackets); | 109 generator_.NewFrame(kNumPackets); |
102 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. | 110 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. |
103 uint32_t last_timestamp = 0; | 111 uint32_t last_timestamp = 0; |
104 for (int i = 0; i < kNumPackets; ++i) { | 112 for (int i = 0; i < kNumPackets; ++i) { |
105 test::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); | 113 RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); |
106 rtp_packets.push_back(rtp_packet); | 114 rtp_packets.push_back(rtp_packet); |
107 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( | 115 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( |
108 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); | 116 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); |
109 last_timestamp = rtp_packet->header.header.timestamp; | 117 last_timestamp = rtp_packet->header.header.timestamp; |
110 } | 118 } |
111 EXPECT_TRUE(producer_.FecAvailable()); | 119 EXPECT_TRUE(producer_.FecAvailable()); |
112 uint16_t seq_num = generator_.NextSeqNum(); | 120 uint16_t seq_num = generator_.NextSeqNum(); |
113 std::vector<std::unique_ptr<RedPacket>> packets = | 121 std::vector<std::unique_ptr<RedPacket>> packets = |
114 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, | 122 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, |
115 kRtpHeaderSize); | 123 kRtpHeaderSize); |
(...skipping 12 matching lines...) Expand all Loading... |
128 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to | 136 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to |
129 // make sure the conditions for generating FEC are satisfied. This means: | 137 // make sure the conditions for generating FEC are satisfied. This means: |
130 // (1) protection factor is high enough so that actual overhead over | 138 // (1) protection factor is high enough so that actual overhead over |
131 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of | 139 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of |
132 // media packets for |kNumFrames| frames is at least | 140 // media packets for |kNumFrames| frames is at least |
133 // |minimum_media_packets_fec_|. | 141 // |minimum_media_packets_fec_|. |
134 const int kNumPackets = 2; | 142 const int kNumPackets = 2; |
135 const int kNumFrames = 2; | 143 const int kNumFrames = 2; |
136 | 144 |
137 FecProtectionParams params = {15, 3, kFecMaskRandom}; | 145 FecProtectionParams params = {15, 3, kFecMaskRandom}; |
138 std::list<test::RawRtpPacket*> rtp_packets; | 146 std::list<RawRtpPacket*> rtp_packets; |
139 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. | 147 producer_.SetFecParameters(¶ms, 0); // Expecting one FEC packet. |
140 uint32_t last_timestamp = 0; | 148 uint32_t last_timestamp = 0; |
141 for (int i = 0; i < kNumFrames; ++i) { | 149 for (int i = 0; i < kNumFrames; ++i) { |
142 generator_.NewFrame(kNumPackets); | 150 generator_.NewFrame(kNumPackets); |
143 for (int j = 0; j < kNumPackets; ++j) { | 151 for (int j = 0; j < kNumPackets; ++j) { |
144 test::RawRtpPacket* rtp_packet = | 152 RawRtpPacket* rtp_packet = generator_.NextPacket(i * kNumPackets + j, 10); |
145 generator_.NextPacket(i * kNumPackets + j, 10); | |
146 rtp_packets.push_back(rtp_packet); | 153 rtp_packets.push_back(rtp_packet); |
147 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( | 154 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( |
148 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); | 155 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); |
149 last_timestamp = rtp_packet->header.header.timestamp; | 156 last_timestamp = rtp_packet->header.header.timestamp; |
150 } | 157 } |
151 } | 158 } |
152 EXPECT_TRUE(producer_.FecAvailable()); | 159 EXPECT_TRUE(producer_.FecAvailable()); |
153 uint16_t seq_num = generator_.NextSeqNum(); | 160 uint16_t seq_num = generator_.NextSeqNum(); |
154 std::vector<std::unique_ptr<RedPacket>> packets = | 161 std::vector<std::unique_ptr<RedPacket>> packets = |
155 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, | 162 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, |
156 kRtpHeaderSize); | 163 kRtpHeaderSize); |
157 EXPECT_FALSE(producer_.FecAvailable()); | 164 EXPECT_FALSE(producer_.FecAvailable()); |
158 ASSERT_EQ(1u, packets.size()); | 165 ASSERT_EQ(1u, packets.size()); |
159 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, | 166 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, |
160 packets.front().get(), false); | 167 packets.front().get(), false); |
161 while (!rtp_packets.empty()) { | 168 while (!rtp_packets.empty()) { |
162 delete rtp_packets.front(); | 169 delete rtp_packets.front(); |
163 rtp_packets.pop_front(); | 170 rtp_packets.pop_front(); |
164 } | 171 } |
165 } | 172 } |
166 | 173 |
167 TEST_F(ProducerFecTest, BuildRedPacket) { | 174 TEST_F(ProducerFecTest, BuildRedPacket) { |
168 generator_.NewFrame(1); | 175 generator_.NewFrame(1); |
169 test::RawRtpPacket* packet = generator_.NextPacket(0, 10); | 176 RawRtpPacket* packet = generator_.NextPacket(0, 10); |
170 std::unique_ptr<RedPacket> red_packet = | 177 std::unique_ptr<RedPacket> red_packet = |
171 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, | 178 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, |
172 kRtpHeaderSize, kRedPayloadType); | 179 kRtpHeaderSize, kRedPayloadType); |
173 EXPECT_EQ(packet->length + 1, red_packet->length()); | 180 EXPECT_EQ(packet->length + 1, red_packet->length()); |
174 VerifyHeader(packet->header.header.sequenceNumber, | 181 VerifyHeader(packet->header.header.sequenceNumber, |
175 packet->header.header.timestamp, | 182 packet->header.header.timestamp, kRedPayloadType, |
176 kRedPayloadType, | 183 packet->header.header.payloadType, red_packet.get(), |
177 packet->header.header.payloadType, | |
178 red_packet.get(), | |
179 true); // Marker bit set. | 184 true); // Marker bit set. |
180 for (int i = 0; i < 10; ++i) | 185 for (int i = 0; i < 10; ++i) |
181 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); | 186 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); |
182 delete packet; | 187 delete packet; |
183 } | 188 } |
184 | 189 |
185 TEST_F(ProducerFecTest, BuildRedPacketWithEmptyPayload) { | 190 TEST_F(ProducerFecTest, BuildRedPacketWithEmptyPayload) { |
186 constexpr size_t kNumFrames = 1; | 191 constexpr size_t kNumFrames = 1; |
187 constexpr size_t kPayloadLength = 0; | 192 constexpr size_t kPayloadLength = 0; |
188 constexpr size_t kRedForFecHeaderLength = 1; | 193 constexpr size_t kRedForFecHeaderLength = 1; |
189 | 194 |
190 generator_.NewFrame(kNumFrames); | 195 generator_.NewFrame(kNumFrames); |
191 std::unique_ptr<test::RawRtpPacket> packet( | 196 std::unique_ptr<RawRtpPacket> packet( |
192 generator_.NextPacket(0, kPayloadLength)); | 197 generator_.NextPacket(0, kPayloadLength)); |
193 std::unique_ptr<RedPacket> red_packet = | 198 std::unique_ptr<RedPacket> red_packet = |
194 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, | 199 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, |
195 kRtpHeaderSize, kRedPayloadType); | 200 kRtpHeaderSize, kRedPayloadType); |
196 EXPECT_EQ(packet->length + kRedForFecHeaderLength, red_packet->length()); | 201 EXPECT_EQ(packet->length + kRedForFecHeaderLength, red_packet->length()); |
197 VerifyHeader(packet->header.header.sequenceNumber, | 202 VerifyHeader(packet->header.header.sequenceNumber, |
198 packet->header.header.timestamp, kRedPayloadType, | 203 packet->header.header.timestamp, kRedPayloadType, |
199 packet->header.header.payloadType, red_packet.get(), | 204 packet->header.header.payloadType, red_packet.get(), |
200 true); // Marker bit set. | 205 true); // Marker bit set. |
201 } | 206 } |
202 | 207 |
203 } // namespace webrtc | 208 } // namespace webrtc |
OLD | NEW |