blob: 64bc3ed24718d4311fefe5e85a0d21d3589a39e8 [file] [log] [blame]
brandtr554becd2016-11-06 22:45:15 -08001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <memory>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/rtp_rtcp/include/flexfec_sender.h"
14#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
15#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
16#include "modules/rtp_rtcp/source/byte_io.h"
17#include "system_wrappers/include/clock.h"
brandtr554becd2016-11-06 22:45:15 -080018
19namespace webrtc {
20
21namespace {
22
23constexpr int kFlexfecPayloadType = 123;
24constexpr uint32_t kMediaSsrc = 1234;
25constexpr uint32_t kFlexfecSsrc = 5678;
26const std::vector<RtpExtension> kNoRtpHeaderExtensions;
erikvarga27883732017-05-17 05:08:38 -070027const std::vector<RtpExtensionSize> kNoRtpHeaderExtensionSizes;
brandtr554becd2016-11-06 22:45:15 -080028
29} // namespace
30
31void FuzzOneInput(const uint8_t* data, size_t size) {
32 size_t i = 0;
33 if (size < 5) {
34 return;
35 }
36
37 SimulatedClock clock(1 + data[i++]);
38 FlexfecSender sender(kFlexfecPayloadType, kFlexfecSsrc, kMediaSsrc,
erikvarga27883732017-05-17 05:08:38 -070039 kNoRtpHeaderExtensions, kNoRtpHeaderExtensionSizes,
brandtr48d21a22017-05-30 02:32:12 -070040 nullptr /* rtp_state */, &clock);
brandtr554becd2016-11-06 22:45:15 -080041 FecProtectionParams params = {
42 data[i++], static_cast<int>(data[i++] % 100),
43 data[i++] <= 127 ? kFecMaskRandom : kFecMaskBursty};
44 sender.SetFecParameters(params);
45 uint16_t seq_num = data[i++];
46
47 while (i + 1 < size) {
48 // Everything past the base RTP header (12 bytes) is payload,
49 // from the perspective of FlexFEC.
50 size_t payload_size = data[i++];
51 if (i + kRtpHeaderSize + payload_size >= size)
52 break;
53 std::unique_ptr<uint8_t[]> packet(
54 new uint8_t[kRtpHeaderSize + payload_size]);
55 memcpy(packet.get(), &data[i], kRtpHeaderSize + payload_size);
56 i += kRtpHeaderSize + payload_size;
57 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], seq_num++);
58 ByteWriter<uint32_t>::WriteBigEndian(&packet[8], kMediaSsrc);
59 RtpPacketToSend rtp_packet(nullptr);
60 if (!rtp_packet.Parse(packet.get(), kRtpHeaderSize + payload_size))
61 break;
62 sender.AddRtpPacketAndGenerateFec(rtp_packet);
63 if (sender.FecAvailable()) {
64 std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets =
65 sender.GetFecPackets();
66 }
67 }
68}
69
70} // namespace webrtc