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

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

Issue 1522463002: Add FEC producer fuzzing and a unittest for one of the issues found. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added comment Created 5 years 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 <vector>
12 13
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
14 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" 16 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h"
15 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
16 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" 18 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h"
17 19
18 namespace webrtc { 20 namespace webrtc {
19 21
20 void VerifyHeader(uint16_t seq_num, 22 void VerifyHeader(uint16_t seq_num,
21 uint32_t timestamp, 23 uint32_t timestamp,
22 int red_pltype, 24 int red_pltype,
23 int fec_pltype, 25 int fec_pltype,
(...skipping 23 matching lines...) Expand all
47 virtual void TearDown() { 49 virtual void TearDown() {
48 delete producer_; 50 delete producer_;
49 delete fec_; 51 delete fec_;
50 delete generator_; 52 delete generator_;
51 } 53 }
52 ForwardErrorCorrection* fec_; 54 ForwardErrorCorrection* fec_;
53 ProducerFec* producer_; 55 ProducerFec* producer_;
54 FrameGenerator* generator_; 56 FrameGenerator* generator_;
55 }; 57 };
56 58
59 // Verifies bug found via fuzzing, where a gap in the packet sequence caused us
60 // to move past the end of the current FEC packet mask byte without moving to
61 // the next byte. That likely caused us to repeatedly read from the same byte,
62 // and if that byte didn't protect packets we would generate empty FEC.
63 TEST_F(ProducerFecTest, NoEmptyFecWithSeqNumGaps) {
64 struct Packet {
65 size_t header_size;
66 size_t payload_size;
67 uint16_t seq_num;
68 bool marker_bit;
69 };
70 std::vector<Packet> protected_packets;
71 protected_packets.push_back({15, 3, 41, 0});
72 protected_packets.push_back({14, 1, 43, 0});
73 protected_packets.push_back({19, 0, 48, 0});
74 protected_packets.push_back({19, 0, 50, 0});
75 protected_packets.push_back({14, 3, 51, 0});
76 protected_packets.push_back({13, 8, 52, 0});
77 protected_packets.push_back({19, 2, 53, 0});
78 protected_packets.push_back({12, 3, 54, 0});
79 protected_packets.push_back({21, 0, 55, 0});
80 protected_packets.push_back({13, 3, 57, 1});
81 FecProtectionParams params = {117, 0, 3, kFecMaskBursty};
82 producer_->SetFecParameters(&params, 0);
83 uint8_t packet[28] = {0};
84 for (Packet p : protected_packets) {
85 if (p.marker_bit) {
86 packet[1] |= 0x80;
87 } else {
88 packet[1] &= ~0x80;
89 }
90 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], p.seq_num);
91 producer_->AddRtpPacketAndGenerateFec(packet, p.payload_size,
92 p.header_size);
93 uint16_t num_fec_packets = producer_->NumAvailableFecPackets();
94 std::vector<RedPacket*> fec_packets;
95 if (num_fec_packets > 0) {
96 fec_packets =
97 producer_->GetFecPackets(kRedPayloadType, 99, 100, p.header_size);
98 EXPECT_EQ(num_fec_packets, fec_packets.size());
99 }
100 for (RedPacket* fec_packet : fec_packets) {
101 delete fec_packet;
102 }
103 }
104 }
105
57 TEST_F(ProducerFecTest, OneFrameFec) { 106 TEST_F(ProducerFecTest, OneFrameFec) {
58 // The number of media packets (|kNumPackets|), number of frames (one for 107 // The number of media packets (|kNumPackets|), number of frames (one for
59 // this test), and the protection factor (|params->fec_rate|) are set to make 108 // this test), and the protection factor (|params->fec_rate|) are set to make
60 // sure the conditions for generating FEC are satisfied. This means: 109 // sure the conditions for generating FEC are satisfied. This means:
61 // (1) protection factor is high enough so that actual overhead over 1 frame 110 // (1) protection factor is high enough so that actual overhead over 1 frame
62 // of packets is within |kMaxExcessOverhead|, and (2) the total number of 111 // of packets is within |kMaxExcessOverhead|, and (2) the total number of
63 // media packets for 1 frame is at least |minimum_media_packets_fec_|. 112 // media packets for 1 frame is at least |minimum_media_packets_fec_|.
64 const int kNumPackets = 4; 113 const int kNumPackets = 4;
65 FecProtectionParams params = {15, false, 3}; 114 FecProtectionParams params = {15, false, 3};
66 std::list<RtpPacket*> rtp_packets; 115 std::list<RtpPacket*> rtp_packets;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 kRedPayloadType, 196 kRedPayloadType,
148 packet->header.header.payloadType, 197 packet->header.header.payloadType,
149 red_packet.get(), 198 red_packet.get(),
150 true); // Marker bit set. 199 true); // Marker bit set.
151 for (int i = 0; i < 10; ++i) 200 for (int i = 0; i < 10; ++i)
152 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]); 201 EXPECT_EQ(i, red_packet->data()[kRtpHeaderSize + 1 + i]);
153 delete packet; 202 delete packet;
154 } 203 }
155 204
156 } // namespace webrtc 205 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/forward_error_correction.cc ('k') | webrtc/test/fuzzers/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698