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

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

Issue 2110763002: Style updates to ProducerFec/FecReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase + 'git cl format'. 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 namespace webrtc { 21 namespace webrtc {
22 22
23 void VerifyHeader(uint16_t seq_num, 23 void VerifyHeader(uint16_t seq_num,
24 uint32_t timestamp, 24 uint32_t timestamp,
25 int red_pltype, 25 int red_payload_type,
26 int fec_pltype, 26 int fec_payload_type,
27 RedPacket* packet, 27 RedPacket* packet,
28 bool marker_bit) { 28 bool marker_bit) {
29 EXPECT_GT(packet->length(), kRtpHeaderSize); 29 EXPECT_GT(packet->length(), kRtpHeaderSize);
30 EXPECT_TRUE(packet->data() != NULL); 30 EXPECT_TRUE(packet->data() != NULL);
31 uint8_t* data = packet->data(); 31 uint8_t* data = packet->data();
32 // Marker bit not set. 32 // Marker bit not set.
33 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80); 33 EXPECT_EQ(marker_bit ? 0x80 : 0, data[1] & 0x80);
34 EXPECT_EQ(red_pltype, data[1] & 0x7F); 34 EXPECT_EQ(red_payload_type, data[1] & 0x7F);
35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]); 35 EXPECT_EQ(seq_num, (data[2] << 8) + data[3]);
36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) + 36 uint32_t parsed_timestamp = (data[4] << 24) + (data[5] << 16) +
37 (data[6] << 8) + data[7]; 37 (data[6] << 8) + data[7];
38 EXPECT_EQ(timestamp, parsed_timestamp); 38 EXPECT_EQ(timestamp, parsed_timestamp);
39 EXPECT_EQ(static_cast<uint8_t>(fec_pltype), data[kRtpHeaderSize]); 39 EXPECT_EQ(static_cast<uint8_t>(fec_payload_type), data[kRtpHeaderSize]);
40 } 40 }
41 41
42 class ProducerFecTest : public ::testing::Test { 42 class ProducerFecTest : public ::testing::Test {
43 protected: 43 protected:
44 virtual void SetUp() { 44 ProducerFecTest() : producer_(&fec_) {}
45 fec_ = new ForwardErrorCorrection();
46 producer_ = new ProducerFec(fec_);
47 generator_ = new FrameGenerator();
48 }
49 45
50 virtual void TearDown() { 46 ForwardErrorCorrection fec_;
51 delete producer_; 47 ProducerFec producer_;
52 delete fec_; 48 FrameGenerator generator_;
53 delete generator_;
54 }
55 ForwardErrorCorrection* fec_;
56 ProducerFec* producer_;
57 FrameGenerator* generator_;
58 }; 49 };
59 50
60 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us 51 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us
61 // to move past the end of the current FEC packet mask byte without moving to 52 // to move past the end of the current FEC packet mask byte without moving to
62 // the next byte. That likely caused us to repeatedly read from the same byte, 53 // the next byte. That likely caused us to repeatedly read from the same byte,
63 // and if that byte didn't protect packets we would generate empty FEC. 54 // and if that byte didn't protect packets we would generate empty FEC.
64 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) { 55 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) {
65 struct Packet { 56 struct Packet {
66 size_t header_size; 57 size_t header_size;
67 size_t payload_size; 58 size_t payload_size;
68 uint16_t seq_num; 59 uint16_t seq_num;
69 bool marker_bit; 60 bool marker_bit;
70 }; 61 };
71 std::vector<Packet> protected_packets; 62 std::vector<Packet> protected_packets;
72 protected_packets.push_back({15, 3, 41, 0}); 63 protected_packets.push_back({15, 3, 41, 0});
73 protected_packets.push_back({14, 1, 43, 0}); 64 protected_packets.push_back({14, 1, 43, 0});
74 protected_packets.push_back({19, 0, 48, 0}); 65 protected_packets.push_back({19, 0, 48, 0});
75 protected_packets.push_back({19, 0, 50, 0}); 66 protected_packets.push_back({19, 0, 50, 0});
76 protected_packets.push_back({14, 3, 51, 0}); 67 protected_packets.push_back({14, 3, 51, 0});
77 protected_packets.push_back({13, 8, 52, 0}); 68 protected_packets.push_back({13, 8, 52, 0});
78 protected_packets.push_back({19, 2, 53, 0}); 69 protected_packets.push_back({19, 2, 53, 0});
79 protected_packets.push_back({12, 3, 54, 0}); 70 protected_packets.push_back({12, 3, 54, 0});
80 protected_packets.push_back({21, 0, 55, 0}); 71 protected_packets.push_back({21, 0, 55, 0});
81 protected_packets.push_back({13, 3, 57, 1}); 72 protected_packets.push_back({13, 3, 57, 1});
82 FecProtectionParams params = {117, 3, kFecMaskBursty}; 73 FecProtectionParams params = {117, 3, kFecMaskBursty};
83 producer_->SetFecParameters(&params, 0); 74 producer_.SetFecParameters(&params, 0);
84 uint8_t packet[28] = {0}; 75 uint8_t packet[28] = {0};
85 for (Packet p : protected_packets) { 76 for (Packet p : protected_packets) {
86 if (p.marker_bit) { 77 if (p.marker_bit) {
87 packet[1] |= 0x80; 78 packet[1] |= 0x80;
88 } else { 79 } else {
89 packet[1] &= ~0x80; 80 packet[1] &= ~0x80;
90 } 81 }
91 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num); 82 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num);
92 producer_->AddRtpPacketAndGenerateFec(packet, p.payload_size, 83 producer_.AddRtpPacketAndGenerateFec(packet, p.payload_size, p.header_size);
93 p.header_size); 84 uint16_t num_fec_packets = producer_.NumAvailableFecPackets();
94 uint16_t num_fec_packets = producer_->NumAvailableFecPackets();
95 std::vector<RedPacket*> fec_packets;
96 if (num_fec_packets > 0) { 85 if (num_fec_packets > 0) {
97 fec_packets = 86 std::vector<std::unique_ptr<RedPacket>> fec_packets =
98 producer_->GetFecPackets(kRedPayloadType, 99, 100, p.header_size); 87 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, 100,
88 p.header_size);
99 EXPECT_EQ(num_fec_packets, fec_packets.size()); 89 EXPECT_EQ(num_fec_packets, fec_packets.size());
100 } 90 }
101 for (RedPacket* fec_packet : fec_packets) {
102 delete fec_packet;
103 }
104 } 91 }
105 } 92 }
106 93
107 TEST_F(ProducerFecTest, OneFrameFec) { 94 TEST_F(ProducerFecTest, OneFrameFec) {
108 // The number of media packets (|kNumPackets|), number of frames (one for 95 // The number of media packets (|kNumPackets|), number of frames (one for
109 // this test), and the protection factor (|params->fec_rate|) are set to make 96 // this test), and the protection factor (|params->fec_rate|) are set to make
110 // sure the conditions for generating FEC are satisfied. This means: 97 // sure the conditions for generating FEC are satisfied. This means:
111 // (1) protection factor is high enough so that actual overhead over 1 frame 98 // (1) protection factor is high enough so that actual overhead over 1 frame
112 // of packets is within |kMaxExcessOverhead|, and (2) the total number of 99 // of packets is within |kMaxExcessOverhead|, and (2) the total number of
113 // media packets for 1 frame is at least |minimum_media_packets_fec_|. 100 // media packets for 1 frame is at least |minimum_media_packets_fec_|.
114 const int kNumPackets = 4; 101 const int kNumPackets = 4;
115 FecProtectionParams params = {15, 3, kFecMaskRandom}; 102 FecProtectionParams params = {15, 3, kFecMaskRandom};
116 std::list<test::RawRtpPacket*> rtp_packets; 103 std::list<test::RawRtpPacket*> rtp_packets;
117 generator_->NewFrame(kNumPackets); 104 generator_.NewFrame(kNumPackets);
118 producer_->SetFecParameters(&params, 0); // Expecting one FEC packet. 105 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
119 uint32_t last_timestamp = 0; 106 uint32_t last_timestamp = 0;
120 for (int i = 0; i < kNumPackets; ++i) { 107 for (int i = 0; i < kNumPackets; ++i) {
121 test::RawRtpPacket* rtp_packet = generator_->NextPacket(i, 10); 108 test::RawRtpPacket* rtp_packet = generator_.NextPacket(i, 10);
122 rtp_packets.push_back(rtp_packet); 109 rtp_packets.push_back(rtp_packet);
123 EXPECT_EQ(0, producer_->AddRtpPacketAndGenerateFec(rtp_packet->data, 110 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
124 rtp_packet->length, 111 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
125 kRtpHeaderSize));
126 last_timestamp = rtp_packet->header.header.timestamp; 112 last_timestamp = rtp_packet->header.header.timestamp;
127 } 113 }
128 EXPECT_TRUE(producer_->FecAvailable()); 114 EXPECT_TRUE(producer_.FecAvailable());
129 uint16_t seq_num = generator_->NextSeqNum(); 115 uint16_t seq_num = generator_.NextSeqNum();
130 std::vector<RedPacket*> packets = producer_->GetFecPackets(kRedPayloadType, 116 std::vector<std::unique_ptr<RedPacket>> packets =
131 kFecPayloadType, 117 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
132 seq_num, 118 kRtpHeaderSize);
133 kRtpHeaderSize); 119 EXPECT_FALSE(producer_.FecAvailable());
134 EXPECT_FALSE(producer_->FecAvailable());
135 ASSERT_EQ(1u, packets.size()); 120 ASSERT_EQ(1u, packets.size());
136 VerifyHeader(seq_num, last_timestamp, 121 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
137 kRedPayloadType, kFecPayloadType, packets.front(), false); 122 packets.front().get(), false);
138 while (!rtp_packets.empty()) { 123 while (!rtp_packets.empty()) {
139 delete rtp_packets.front(); 124 delete rtp_packets.front();
140 rtp_packets.pop_front(); 125 rtp_packets.pop_front();
141 } 126 }
142 delete packets.front();
143 } 127 }
144 128
145 TEST_F(ProducerFecTest, TwoFrameFec) { 129 TEST_F(ProducerFecTest, TwoFrameFec) {
146 // The number of media packets/frame (|kNumPackets|), the number of frames 130 // The number of media packets/frame (|kNumPackets|), the number of frames
147 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to 131 // (|kNumFrames|), and the protection factor (|params->fec_rate|) are set to
148 // make sure the conditions for generating FEC are satisfied. This means: 132 // make sure the conditions for generating FEC are satisfied. This means:
149 // (1) protection factor is high enough so that actual overhead over 133 // (1) protection factor is high enough so that actual overhead over
150 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of 134 // |kNumFrames| is within |kMaxExcessOverhead|, and (2) the total number of
151 // media packets for |kNumFrames| frames is at least 135 // media packets for |kNumFrames| frames is at least
152 // |minimum_media_packets_fec_|. 136 // |minimum_media_packets_fec_|.
153 const int kNumPackets = 2; 137 const int kNumPackets = 2;
154 const int kNumFrames = 2; 138 const int kNumFrames = 2;
155 139
156 FecProtectionParams params = {15, 3, kFecMaskRandom}; 140 FecProtectionParams params = {15, 3, kFecMaskRandom};
157 std::list<test::RawRtpPacket*> rtp_packets; 141 std::list<test::RawRtpPacket*> rtp_packets;
158 producer_->SetFecParameters(&params, 0); // Expecting one FEC packet. 142 producer_.SetFecParameters(&params, 0); // Expecting one FEC packet.
159 uint32_t last_timestamp = 0; 143 uint32_t last_timestamp = 0;
160 for (int i = 0; i < kNumFrames; ++i) { 144 for (int i = 0; i < kNumFrames; ++i) {
161 generator_->NewFrame(kNumPackets); 145 generator_.NewFrame(kNumPackets);
162 for (int j = 0; j < kNumPackets; ++j) { 146 for (int j = 0; j < kNumPackets; ++j) {
163 test::RawRtpPacket* rtp_packet = 147 test::RawRtpPacket* rtp_packet =
164 generator_->NextPacket(i * kNumPackets + j, 10); 148 generator_.NextPacket(i * kNumPackets + j, 10);
165 rtp_packets.push_back(rtp_packet); 149 rtp_packets.push_back(rtp_packet);
166 EXPECT_EQ(0, producer_->AddRtpPacketAndGenerateFec(rtp_packet->data, 150 EXPECT_EQ(0, producer_.AddRtpPacketAndGenerateFec(
167 rtp_packet->length, 151 rtp_packet->data, rtp_packet->length, kRtpHeaderSize));
168 kRtpHeaderSize));
169 last_timestamp = rtp_packet->header.header.timestamp; 152 last_timestamp = rtp_packet->header.header.timestamp;
170 } 153 }
171 } 154 }
172 EXPECT_TRUE(producer_->FecAvailable()); 155 EXPECT_TRUE(producer_.FecAvailable());
173 uint16_t seq_num = generator_->NextSeqNum(); 156 uint16_t seq_num = generator_.NextSeqNum();
174 std::vector<RedPacket*> packets = producer_->GetFecPackets(kRedPayloadType, 157 std::vector<std::unique_ptr<RedPacket>> packets =
175 kFecPayloadType, 158 producer_.GetFecPacketsAsRed(kRedPayloadType, kFecPayloadType, seq_num,
176 seq_num, 159 kRtpHeaderSize);
177 kRtpHeaderSize); 160 EXPECT_FALSE(producer_.FecAvailable());
178 EXPECT_FALSE(producer_->FecAvailable());
179 ASSERT_EQ(1u, packets.size()); 161 ASSERT_EQ(1u, packets.size());
180 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType, 162 VerifyHeader(seq_num, last_timestamp, kRedPayloadType, kFecPayloadType,
181 packets.front(), false); 163 packets.front().get(), false);
182 while (!rtp_packets.empty()) { 164 while (!rtp_packets.empty()) {
183 delete rtp_packets.front(); 165 delete rtp_packets.front();
184 rtp_packets.pop_front(); 166 rtp_packets.pop_front();
185 } 167 }
186 delete packets.front();
187 } 168 }
188 169
189 TEST_F(ProducerFecTest, BuildRedPacket) { 170 TEST_F(ProducerFecTest, BuildRedPacket) {
190 generator_->NewFrame(1); 171 generator_.NewFrame(1);
191 test::RawRtpPacket* packet = generator_->NextPacket(0, 10); 172 test::RawRtpPacket* packet = generator_.NextPacket(0, 10);
192 std::unique_ptr<RedPacket> red_packet(producer_->BuildRedPacket( 173 std::unique_ptr<RedPacket> red_packet =
193 packet->data, packet->length - kRtpHeaderSize, kRtpHeaderSize, 174 ProducerFec::BuildRedPacket(packet->data, packet->length - kRtpHeaderSize,
194 kRedPayloadType)); 175 kRtpHeaderSize, kRedPayloadType);
195 EXPECT_EQ(packet->length + 1, red_packet->length()); 176 EXPECT_EQ(packet->length + 1, red_packet->length());
196 VerifyHeader(packet->header.header.sequenceNumber, 177 VerifyHeader(packet->header.header.sequenceNumber,
197 packet->header.header.timestamp, 178 packet->header.header.timestamp,
198 kRedPayloadType, 179 kRedPayloadType,
199 packet->header.header.payloadType, 180 packet->header.header.payloadType,
200 red_packet.get(), 181 red_packet.get(),
201 true); // Marker bit set. 182 true); // Marker bit set.
202 for (int i = 0; i < 10; ++i) 183 for (int i = 0; i < 10; ++i)
203 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); 184 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]);
204 delete packet; 185 delete packet;
205 } 186 }
206 187
207 } // namespace webrtc 188 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/producer_fec.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698