OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
| 11 #include <memory> |
| 12 |
10 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
11 #include "webrtc/base/scoped_ptr.h" | |
12 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
13 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" | 15 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" |
14 | 16 |
15 namespace webrtc { | 17 namespace webrtc { |
16 | 18 |
17 void FuzzOneInput(const uint8_t* data, size_t size) { | 19 void FuzzOneInput(const uint8_t* data, size_t size) { |
18 ForwardErrorCorrection fec; | 20 ForwardErrorCorrection fec; |
19 ProducerFec producer(&fec); | 21 ProducerFec producer(&fec); |
20 size_t i = 0; | 22 size_t i = 0; |
21 if (size < 4) | 23 if (size < 4) |
22 return; | 24 return; |
23 FecProtectionParams params = { | 25 FecProtectionParams params = { |
24 data[i++] % 128, static_cast<int>(data[i++] % 10), kFecMaskBursty}; | 26 data[i++] % 128, static_cast<int>(data[i++] % 10), kFecMaskBursty}; |
25 producer.SetFecParameters(¶ms, 0); | 27 producer.SetFecParameters(¶ms, 0); |
26 uint16_t seq_num = data[i++]; | 28 uint16_t seq_num = data[i++]; |
27 | 29 |
28 while (i + 3 < size) { | 30 while (i + 3 < size) { |
29 size_t rtp_header_length = data[i++] % 10 + 12; | 31 size_t rtp_header_length = data[i++] % 10 + 12; |
30 size_t payload_size = data[i++] % 10; | 32 size_t payload_size = data[i++] % 10; |
31 if (i + payload_size + rtp_header_length + 2 > size) | 33 if (i + payload_size + rtp_header_length + 2 > size) |
32 break; | 34 break; |
33 rtc::scoped_ptr<uint8_t[]> packet( | 35 std::unique_ptr<uint8_t[]> packet( |
34 new uint8_t[payload_size + rtp_header_length]); | 36 new uint8_t[payload_size + rtp_header_length]); |
35 memcpy(packet.get(), &data[i], payload_size + rtp_header_length); | 37 memcpy(packet.get(), &data[i], payload_size + rtp_header_length); |
36 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], seq_num++); | 38 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], seq_num++); |
37 i += payload_size + rtp_header_length; | 39 i += payload_size + rtp_header_length; |
38 // Make sure sequence numbers are increasing. | 40 // Make sure sequence numbers are increasing. |
39 const int kRedPayloadType = 98; | 41 const int kRedPayloadType = 98; |
40 rtc::scoped_ptr<RedPacket> red_packet(producer.BuildRedPacket( | 42 std::unique_ptr<RedPacket> red_packet(producer.BuildRedPacket( |
41 packet.get(), payload_size, rtp_header_length, kRedPayloadType)); | 43 packet.get(), payload_size, rtp_header_length, kRedPayloadType)); |
42 const bool protect = data[i++] % 2 == 1; | 44 const bool protect = data[i++] % 2 == 1; |
43 if (protect) { | 45 if (protect) { |
44 producer.AddRtpPacketAndGenerateFec(packet.get(), payload_size, | 46 producer.AddRtpPacketAndGenerateFec(packet.get(), payload_size, |
45 rtp_header_length); | 47 rtp_header_length); |
46 } | 48 } |
47 const size_t num_fec_packets = producer.NumAvailableFecPackets(); | 49 const size_t num_fec_packets = producer.NumAvailableFecPackets(); |
48 if (num_fec_packets > 0) { | 50 if (num_fec_packets > 0) { |
49 std::vector<RedPacket*> fec_packets = | 51 std::vector<RedPacket*> fec_packets = |
50 producer.GetFecPackets(kRedPayloadType, 99, 100, rtp_header_length); | 52 producer.GetFecPackets(kRedPayloadType, 99, 100, rtp_header_length); |
51 RTC_CHECK_EQ(num_fec_packets, fec_packets.size()); | 53 RTC_CHECK_EQ(num_fec_packets, fec_packets.size()); |
52 for (RedPacket* fec_packet : fec_packets) | 54 for (RedPacket* fec_packet : fec_packets) |
53 delete fec_packet; | 55 delete fec_packet; |
54 } | 56 } |
55 } | 57 } |
56 } | 58 } |
57 } // namespace webrtc | 59 } // namespace webrtc |
OLD | NEW |