blob: 084c8c300ad491fac6064d5605f6897c12835a00 [file] [log] [blame]
stefanbded44b2016-07-18 09:26:06 -07001/*
2 * Copyright (c) 2015 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
12#include "modules/pacing/packet_router.h"
13#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
14#include "modules/rtp_rtcp/source/byte_io.h"
stefanbded44b2016-07-18 09:26:06 -070015
16namespace webrtc {
17
stefanbded44b2016-07-18 09:26:06 -070018void FuzzOneInput(const uint8_t* data, size_t size) {
19 size_t i = 0;
20 if (size < sizeof(int64_t) + sizeof(uint8_t) + sizeof(uint32_t))
21 return;
22 SimulatedClock clock(data[i++]);
nisse0245da02016-11-30 03:35:20 -080023 PacketRouter packet_router;
Niels Möller245f17e2017-08-21 10:45:07 +020024 ReceiveSideCongestionController cc(&clock, &packet_router);
stefanbded44b2016-07-18 09:26:06 -070025 RemoteBitrateEstimator* rbe = cc.GetRemoteBitrateEstimator(true);
26 RTPHeader header;
27 header.ssrc = ByteReader<uint32_t>::ReadBigEndian(&data[i]);
28 i += sizeof(uint32_t);
29 header.extension.hasTransportSequenceNumber = true;
Stefan Holmerd7e25132017-11-23 10:36:11 +010030 int64_t arrival_time_ms = std::min<int64_t>(
31 std::max<int64_t>(ByteReader<int64_t>::ReadBigEndian(&data[i]), 0),
32 std::numeric_limits<int64_t>::max() / 2);
stefanbded44b2016-07-18 09:26:06 -070033 i += sizeof(int64_t);
34 const size_t kMinPacketSize =
35 sizeof(size_t) + sizeof(uint16_t) + sizeof(uint8_t);
36 while (i + kMinPacketSize < size) {
37 size_t payload_size = ByteReader<size_t>::ReadBigEndian(&data[i]) % 1500;
38 i += sizeof(size_t);
39 header.extension.transportSequenceNumber =
40 ByteReader<uint16_t>::ReadBigEndian(&data[i]);
41 i += sizeof(uint16_t);
42 rbe->IncomingPacket(arrival_time_ms, payload_size, header);
43 clock.AdvanceTimeMilliseconds(5);
44 arrival_time_ms += ByteReader<uint8_t>::ReadBigEndian(&data[i]);
Stefan Holmerd7e25132017-11-23 10:36:11 +010045 i += sizeof(uint8_t);
stefanbded44b2016-07-18 09:26:06 -070046 }
47 rbe->Process();
48}
49} // namespace webrtc