Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(997)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc

Issue 2267393002: Generalize FEC unit tests and rename GenerateFec. (pt. 3) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@header_reader_writer-pt2-producer_fec_mini_fixes
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 using ::webrtc::test::fec::RawRtpPacket;
22
23 namespace {
24
25 constexpr uint8_t kFecPayloadType = 96;
26 constexpr uint8_t kRedPayloadType = 97;
27
28 } // namespace
29
21 namespace webrtc { 30 namespace webrtc {
22 31
23 void VerifyHeader(uint16_t seq_num, 32 void VerifyHeader(uint16_t seq_num,
24 uint32_t timestamp, 33 uint32_t timestamp,
25 int red_payload_type, 34 int red_payload_type,
26 int fec_payload_type, 35 int fec_payload_type,
27 RedPacket* packet, 36 RedPacket* packet,
28 bool marker_bit) { 37 bool marker_bit) {
29 EXPECT_GT(packet->length(), kRtpHeaderSize); 38 EXPECT_GT(packet->length(), kRtpHeaderSize);
30 EXPECT_TRUE(packet->data() != NULL); 39 EXPECT_TRUE(packet->data() != NULL);
31 uint8_t* data = packet->data(); 40 uint8_t* data = packet->data();
32 // Marker bit not set. 41 // Marker bit not set.
33 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80); 42 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80);
34 EXPECT_EQ(red_payload_type, data[1] & 0x7F); 43 EXPECT_EQ(red_payload_type, data[1] & 0x7F);
35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]); 44 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]);
36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) + 45 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) +
37 (data[6] << 8) + data[7]; 46 (data[6] << 8) + data[7];
38 EXPECT_EQ(timestamp, parsed_timestamp); 47 EXPECT_EQ(timestamp, parsed_timestamp);
39 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]); 48 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]);
40 } 49 }
41 50
42 class ProducerFecTest : public ::testing::Test { 51 class ProducerFecTest : public ::testing::Test {
43 protected: 52 protected:
44 ProducerFec producer_; 53 ProducerFec producer_;
45 FrameGenerator generator_; 54 test::fec::FrameGenerator generator_;
46 }; 55 };
47 56
48 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us 57 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us
49 // to move past the end of the current FEC packet mask byte without moving to 58 // to move past the end of the current FEC packet mask byte without moving to
50 // the next byte. That likely caused us to repeatedly read from the same byte, 59 // the next byte. That likely caused us to repeatedly read from the same byte,
51 // and if that byte didn't protect packets we would generate empty FEC. 60 // and if that byte didn't protect packets we would generate empty FEC.
52 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) { 61 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) {
53 struct Packet { 62 struct Packet {
54 size_t header_size; 63 size_t header_size;
55 size_t payload_size; 64 size_t payload_size;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 99
91 TEST_F(ProducerFecTest, OneFrameFec) { 100 TEST_F(ProducerFecTest, OneFrameFec) {
92 // The number of media packets (|kNumPackets|), number of frames (one for 101 // 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 102 // this test), and the protection factor (|params->fec_rate|) are set to make
94 // sure the conditions for generating FEC are satisfied. This means: 103 // sure the conditions for generating FEC are satisfied. This means:
95 // (1) protection factor is high enough so that actual overhead over 1 frame 104 // (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 105 // of packets is within |kMaxExcessOverhead|, and (2) the total number of
97 // media packets for 1 frame is at least |minimum_media_packets_fec_|. 106 // media packets for 1 frame is at least |minimum_media_packets_fec_|.
98 const int kNumPackets = 4; 107 const int kNumPackets = 4;
99 FecProtectionParams params = {15, 3, kFecMaskRandom}; 108 FecProtectionParams params = {15, 3, kFecMaskRandom};
100 std::list<test::RawRtpPacket*> rtp_packets; 109 std::list<RawRtpPacket*> rtp_packets;
101 generator_.NewFrame(kNumPackets); 110 generator_.NewFrame(kNumPackets);
102 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet. 111 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
103 uint32_t last_timestamp = 0; 112 uint32_t last_timestamp = 0;
104 for (int i = 0; i < kNumPackets; ++i) { 113 for (int i = 0; i < kNumPackets; ++i) {
105 test::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); 114 RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10);
106 rtp_packets.push_back(rtp_packet); 115 rtp_packets.push_back(rtp_packet);
107 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( 116 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
108 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); 117 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
109 last_timestamp = rtp_packet->header.header.timestamp; 118 last_timestamp = rtp_packet->header.header.timestamp;
110 } 119 }
111 EXPECT_TRUE(producer_.FecAvailable()); 120 EXPECT_TRUE(producer_.FecAvailable());
112 uint16_t seq_num = generator_.NextSeqNum(); 121 uint16_t seq_num = generator_.NextSeqNum();
113 std::vector<std::unique_ptr<RedPacket>> packets = 122 std::vector<std::unique_ptr<RedPacket>> packets =
114 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, 123 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
115 kRtpHeaderSize); 124 kRtpHeaderSize);
(...skipping 12 matching lines...) Expand all
128 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to 137 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to
129 // make sure the conditions for generating FEC are satisfied. This means: 138 // make sure the conditions for generating FEC are satisfied. This means:
130 // (1) protection factor is high enough so that actual overhead over 139 // (1) protection factor is high enough so that actual overhead over
131 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of 140 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of
132 // media packets for |kNumFrames| frames is at least 141 // media packets for |kNumFrames| frames is at least
133 // |minimum_media_packets_fec_|. 142 // |minimum_media_packets_fec_|.
134 const int kNumPackets = 2; 143 const int kNumPackets = 2;
135 const int kNumFrames = 2; 144 const int kNumFrames = 2;
136 145
137 FecProtectionParams params = {15, 3, kFecMaskRandom}; 146 FecProtectionParams params = {15, 3, kFecMaskRandom};
138 std::list<test::RawRtpPacket*> rtp_packets; 147 std::list<RawRtpPacket*> rtp_packets;
139 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet. 148 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
140 uint32_t last_timestamp = 0; 149 uint32_t last_timestamp = 0;
141 for (int i = 0; i < kNumFrames; ++i) { 150 for (int i = 0; i < kNumFrames; ++i) {
142 generator_.NewFrame(kNumPackets); 151 generator_.NewFrame(kNumPackets);
143 for (int j = 0; j < kNumPackets; ++j) { 152 for (int j = 0; j < kNumPackets; ++j) {
144 test::RawRtpPacket* rtp_packet = 153 RawRtpPacket* rtp_packet = generator_.NextPacket(i * kNumPackets + j, 10);
145 generator_.NextPacket(i * kNumPackets + j, 10);
146 rtp_packets.push_back(rtp_packet); 154 rtp_packets.push_back(rtp_packet);
147 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( 155 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
148 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); 156 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
149 last_timestamp = rtp_packet->header.header.timestamp; 157 last_timestamp = rtp_packet->header.header.timestamp;
150 } 158 }
151 } 159 }
152 EXPECT_TRUE(producer_.FecAvailable()); 160 EXPECT_TRUE(producer_.FecAvailable());
153 uint16_t seq_num = generator_.NextSeqNum(); 161 uint16_t seq_num = generator_.NextSeqNum();
154 std::vector<std::unique_ptr<RedPacket>> packets = 162 std::vector<std::unique_ptr<RedPacket>> packets =
155 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, 163 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
156 kRtpHeaderSize); 164 kRtpHeaderSize);
157 EXPECT_FALSE(producer_.FecAvailable()); 165 EXPECT_FALSE(producer_.FecAvailable());
158 ASSERT_EQ(1u, packets.size()); 166 ASSERT_EQ(1u, packets.size());
159 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, 167 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
160 packets.front().get(), false); 168 packets.front().get(), false);
161 while (!rtp_packets.empty()) { 169 while (!rtp_packets.empty()) {
162 delete rtp_packets.front(); 170 delete rtp_packets.front();
163 rtp_packets.pop_front(); 171 rtp_packets.pop_front();
164 } 172 }
165 } 173 }
166 174
167 TEST_F(ProducerFecTest, BuildRedPacket) { 175 TEST_F(ProducerFecTest, BuildRedPacket) {
168 generator_.NewFrame(1); 176 generator_.NewFrame(1);
169 test::RawRtpPacket* packet = generator_.NextPacket(0, 10); 177 RawRtpPacket* packet = generator_.NextPacket(0, 10);
170 std::unique_ptr<RedPacket> red_packet = 178 std::unique_ptr<RedPacket> red_packet =
171 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, 179 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize,
172 kRtpHeaderSize, kRedPayloadType); 180 kRtpHeaderSize, kRedPayloadType);
173 EXPECT_EQ(packet->length + 1, red_packet->length()); 181 EXPECT_EQ(packet->length + 1, red_packet->length());
174 VerifyHeader(packet->header.header.sequenceNumber, 182 VerifyHeader(packet->header.header.sequenceNumber,
175 packet->header.header.timestamp, 183 packet->header.header.timestamp, kRedPayloadType,
176 kRedPayloadType, 184 packet->header.header.payloadType, red_packet.get(),
177 packet->header.header.payloadType,
178 red_packet.get(),
179 true); // Marker bit set. 185 true); // Marker bit set.
180 for (int i = 0; i < 10; ++i) 186 for (int i = 0; i < 10; ++i)
181 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); 187 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]);
182 delete packet; 188 delete packet;
183 } 189 }
184 190
185 } // namespace webrtc 191 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/producer_fec.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698