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

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: Rebase. Created 4 years, 3 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 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::RawRtpPacket;
29
23 void VerifyHeader(uint16_t seq_num, 30 void VerifyHeader(uint16_t seq_num,
24 uint32_t timestamp, 31 uint32_t timestamp,
25 int red_payload_type, 32 int red_payload_type,
26 int fec_payload_type, 33 int fec_payload_type,
27 RedPacket* packet, 34 RedPacket* packet,
28 bool marker_bit) { 35 bool marker_bit) {
29 EXPECT_GT(packet->length(), kRtpHeaderSize); 36 EXPECT_GT(packet->length(), kRtpHeaderSize);
30 EXPECT_TRUE(packet->data() != NULL); 37 EXPECT_TRUE(packet->data() != NULL);
31 uint8_t* data = packet->data(); 38 uint8_t* data = packet->data();
32 // Marker bit not set. 39 // Marker bit not set.
33 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80); 40 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80);
34 EXPECT_EQ(red_payload_type, data[1] & 0x7F); 41 EXPECT_EQ(red_payload_type, data[1] & 0x7F);
35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]); 42 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]);
36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) + 43 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) +
37 (data[6] << 8) + data[7]; 44 (data[6] << 8) + data[7];
38 EXPECT_EQ(timestamp, parsed_timestamp); 45 EXPECT_EQ(timestamp, parsed_timestamp);
39 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]); 46 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]);
40 } 47 }
41 48
42 class ProducerFecTest : public ::testing::Test { 49 class ProducerFecTest : public ::testing::Test {
43 protected: 50 protected:
44 ProducerFec producer_; 51 ProducerFec producer_;
45 FrameGenerator generator_; 52 test::fec::FrameGenerator generator_;
danilchap 2016/08/23 13:08:50 likely better to add using ::webrtc::test::fec::Fr
brandtr 2016/08/23 14:05:07 Done.
46 }; 53 };
47 54
48 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us 55 // 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 56 // 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, 57 // 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. 58 // and if that byte didn't protect packets we would generate empty FEC.
52 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) { 59 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) {
53 struct Packet { 60 struct Packet {
54 size_t header_size; 61 size_t header_size;
55 size_t payload_size; 62 size_t payload_size;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 97
91 TEST_F(ProducerFecTest, OneFrameFec) { 98 TEST_F(ProducerFecTest, OneFrameFec) {
92 // The number of media packets (|kNumPackets|), number of frames (one for 99 // 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 100 // this test), and the protection factor (|params->fec_rate|) are set to make
94 // sure the conditions for generating FEC are satisfied. This means: 101 // sure the conditions for generating FEC are satisfied. This means:
95 // (1) protection factor is high enough so that actual overhead over 1 frame 102 // (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 103 // of packets is within |kMaxExcessOverhead|, and (2) the total number of
97 // media packets for 1 frame is at least |minimum_media_packets_fec_|. 104 // media packets for 1 frame is at least |minimum_media_packets_fec_|.
98 const int kNumPackets = 4; 105 const int kNumPackets = 4;
99 FecProtectionParams params = {15, 3, kFecMaskRandom}; 106 FecProtectionParams params = {15, 3, kFecMaskRandom};
100 std::list<test::RawRtpPacket*> rtp_packets; 107 std::list<RawRtpPacket*> rtp_packets;
101 generator_.NewFrame(kNumPackets); 108 generator_.NewFrame(kNumPackets);
102 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet. 109 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
103 uint32_t last_timestamp = 0; 110 uint32_t last_timestamp = 0;
104 for (int i = 0; i < kNumPackets; ++i) { 111 for (int i = 0; i < kNumPackets; ++i) {
105 test::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10); 112 RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10);
106 rtp_packets.push_back(rtp_packet); 113 rtp_packets.push_back(rtp_packet);
107 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( 114 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
108 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); 115 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
109 last_timestamp = rtp_packet->header.header.timestamp; 116 last_timestamp = rtp_packet->header.header.timestamp;
110 } 117 }
111 EXPECT_TRUE(producer_.FecAvailable()); 118 EXPECT_TRUE(producer_.FecAvailable());
112 uint16_t seq_num = generator_.NextSeqNum(); 119 uint16_t seq_num = generator_.NextSeqNum();
113 std::vector<std::unique_ptr<RedPacket>> packets = 120 std::vector<std::unique_ptr<RedPacket>> packets =
114 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, 121 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
115 kRtpHeaderSize); 122 kRtpHeaderSize);
(...skipping 12 matching lines...) Expand all
128 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to 135 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to
129 // make sure the conditions for generating FEC are satisfied. This means: 136 // make sure the conditions for generating FEC are satisfied. This means:
130 // (1) protection factor is high enough so that actual overhead over 137 // (1) protection factor is high enough so that actual overhead over
131 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of 138 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of
132 // media packets for |kNumFrames| frames is at least 139 // media packets for |kNumFrames| frames is at least
133 // |minimum_media_packets_fec_|. 140 // |minimum_media_packets_fec_|.
134 const int kNumPackets = 2; 141 const int kNumPackets = 2;
135 const int kNumFrames = 2; 142 const int kNumFrames = 2;
136 143
137 FecProtectionParams params = {15, 3, kFecMaskRandom}; 144 FecProtectionParams params = {15, 3, kFecMaskRandom};
138 std::list<test::RawRtpPacket*> rtp_packets; 145 std::list<RawRtpPacket*> rtp_packets;
139 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet. 146 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
140 uint32_t last_timestamp = 0; 147 uint32_t last_timestamp = 0;
141 for (int i = 0; i < kNumFrames; ++i) { 148 for (int i = 0; i < kNumFrames; ++i) {
142 generator_.NewFrame(kNumPackets); 149 generator_.NewFrame(kNumPackets);
143 for (int j = 0; j < kNumPackets; ++j) { 150 for (int j = 0; j < kNumPackets; ++j) {
144 test::RawRtpPacket* rtp_packet = 151 RawRtpPacket* rtp_packet = generator_.NextPacket(i * kNumPackets + j, 10);
145 generator_.NextPacket(i * kNumPackets + j, 10);
146 rtp_packets.push_back(rtp_packet); 152 rtp_packets.push_back(rtp_packet);
147 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec( 153 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
148 rtp_packet->data, rtp_packet->length, kRtpHeaderSize)); 154 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
149 last_timestamp = rtp_packet->header.header.timestamp; 155 last_timestamp = rtp_packet->header.header.timestamp;
150 } 156 }
151 } 157 }
152 EXPECT_TRUE(producer_.FecAvailable()); 158 EXPECT_TRUE(producer_.FecAvailable());
153 uint16_t seq_num = generator_.NextSeqNum(); 159 uint16_t seq_num = generator_.NextSeqNum();
154 std::vector<std::unique_ptr<RedPacket>> packets = 160 std::vector<std::unique_ptr<RedPacket>> packets =
155 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num, 161 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
156 kRtpHeaderSize); 162 kRtpHeaderSize);
157 EXPECT_FALSE(producer_.FecAvailable()); 163 EXPECT_FALSE(producer_.FecAvailable());
158 ASSERT_EQ(1u, packets.size()); 164 ASSERT_EQ(1u, packets.size());
159 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, 165 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
160 packets.front().get(), false); 166 packets.front().get(), false);
161 while (!rtp_packets.empty()) { 167 while (!rtp_packets.empty()) {
162 delete rtp_packets.front(); 168 delete rtp_packets.front();
163 rtp_packets.pop_front(); 169 rtp_packets.pop_front();
164 } 170 }
165 } 171 }
166 172
167 TEST_F(ProducerFecTest, BuildRedPacket) { 173 TEST_F(ProducerFecTest, BuildRedPacket) {
168 generator_.NewFrame(1); 174 generator_.NewFrame(1);
169 test::RawRtpPacket* packet = generator_.NextPacket(0, 10); 175 RawRtpPacket* packet = generator_.NextPacket(0, 10);
170 std::unique_ptr<RedPacket> red_packet = 176 std::unique_ptr<RedPacket> red_packet =
171 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize, 177 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize,
172 kRtpHeaderSize, kRedPayloadType); 178 kRtpHeaderSize, kRedPayloadType);
173 EXPECT_EQ(packet->length + 1, red_packet->length()); 179 EXPECT_EQ(packet->length + 1, red_packet->length());
174 VerifyHeader(packet->header.header.sequenceNumber, 180 VerifyHeader(packet->header.header.sequenceNumber,
175 packet->header.header.timestamp, 181 packet->header.header.timestamp, kRedPayloadType,
176 kRedPayloadType, 182 packet->header.header.payloadType, red_packet.get(),
177 packet->header.header.payloadType,
178 red_packet.get(),
179 true); // Marker bit set. 183 true); // Marker bit set.
180 for (int i = 0; i < 10; ++i) 184 for (int i = 0; i < 10; ++i)
181 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); 185 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]);
182 delete packet; 186 delete packet;
183 } 187 }
184 188
185 } // namespace webrtc 189 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698