brandtr | 554becd | 2016-11-06 22:45:15 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 13 | #include "webrtc/modules/rtp_rtcp/include/flexfec_sender.h" |
| 14 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 15 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
| 16 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 17 | #include "webrtc/system_wrappers/include/clock.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | constexpr int kFlexfecPayloadType = 123; |
| 24 | constexpr uint32_t kMediaSsrc = 1234; |
| 25 | constexpr uint32_t kFlexfecSsrc = 5678; |
| 26 | const std::vector<RtpExtension> kNoRtpHeaderExtensions; |
| 27 | |
| 28 | } // namespace |
| 29 | |
| 30 | void FuzzOneInput(const uint8_t* data, size_t size) { |
| 31 | size_t i = 0; |
| 32 | if (size < 5) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | SimulatedClock clock(1 + data[i++]); |
| 37 | FlexfecSender sender(kFlexfecPayloadType, kFlexfecSsrc, kMediaSsrc, |
| 38 | kNoRtpHeaderExtensions, &clock); |
| 39 | FecProtectionParams params = { |
| 40 | data[i++], static_cast<int>(data[i++] % 100), |
| 41 | data[i++] <= 127 ? kFecMaskRandom : kFecMaskBursty}; |
| 42 | sender.SetFecParameters(params); |
| 43 | uint16_t seq_num = data[i++]; |
| 44 | |
| 45 | while (i + 1 < size) { |
| 46 | // Everything past the base RTP header (12 bytes) is payload, |
| 47 | // from the perspective of FlexFEC. |
| 48 | size_t payload_size = data[i++]; |
| 49 | if (i + kRtpHeaderSize + payload_size >= size) |
| 50 | break; |
| 51 | std::unique_ptr<uint8_t[]> packet( |
| 52 | new uint8_t[kRtpHeaderSize + payload_size]); |
| 53 | memcpy(packet.get(), &data[i], kRtpHeaderSize + payload_size); |
| 54 | i += kRtpHeaderSize + payload_size; |
| 55 | ByteWriter<uint16_t>::WriteBigEndian(&packet[2], seq_num++); |
| 56 | ByteWriter<uint32_t>::WriteBigEndian(&packet[8], kMediaSsrc); |
| 57 | RtpPacketToSend rtp_packet(nullptr); |
| 58 | if (!rtp_packet.Parse(packet.get(), kRtpHeaderSize + payload_size)) |
| 59 | break; |
| 60 | sender.AddRtpPacketAndGenerateFec(rtp_packet); |
| 61 | if (sender.FecAvailable()) { |
| 62 | std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets = |
| 63 | sender.GetFecPackets(); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | } // namespace webrtc |