1 /*
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 
11 #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"
15 
16 namespace webrtc {
17 
FuzzOneInput(const uint8_t * data,size_t size)18 void 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++]);
23   PacketRouter packet_router;
24   ReceiveSideCongestionController cc(&clock, &packet_router);
25   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;
30   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);
33   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]);
45     i += sizeof(uint8_t);
46   }
47   rbe->Process();
48 }
49 }  // namespace webrtc
50