blob: 7cf65cf655b1ab8a93b7ce5ebaa9eedceef46db9 [file] [log] [blame]
danilchap1edb7ab2016-04-20 05:25:10 -07001/*
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 */
katrielc36a321d2016-07-05 07:20:24 -070010
11#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
12#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
danilchap1edb7ab2016-04-20 05:25:10 -070013#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
14
15namespace webrtc {
16
katrielc36a321d2016-07-05 07:20:24 -070017// We decide which header extensions to register by reading one byte
18// from the beginning of |data| and interpreting it as a bitmask over
19// the RTPExtensionType enum. This assert ensures one byte is enough.
20static_assert(kRtpExtensionNumberOfExtensions <= 8,
21 "Insufficient bits read to configure all header extensions. Add "
22 "an extra byte and update the switches.");
danilchap1edb7ab2016-04-20 05:25:10 -070023
katrielc36a321d2016-07-05 07:20:24 -070024void FuzzOneInput(const uint8_t* data, size_t size) {
25 if (size <= 1)
26 return;
27
28 // Don't use the configuration byte as part of the packet.
29 std::bitset<8> extensionMask(data[0]);
30 data++;
31 size--;
32
33 RtpPacketReceived::ExtensionManager extensions;
34 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) {
35 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
36 if (extensionMask[i] && extension_type != kRtpExtensionNone) {
37 // Extensions are registered with an ID, which you signal to the
38 // peer so they know what to expect. This code only cares about
39 // parsing so the value of the ID isn't relevant; we use i.
40 extensions.Register(extension_type, i);
41 }
42 }
43
44 RtpPacketReceived packet(&extensions);
danilchap1edb7ab2016-04-20 05:25:10 -070045 packet.Parse(data, size);
46
47 // Call packet accessors because they have extra checks.
48 packet.Marker();
49 packet.PayloadType();
50 packet.SequenceNumber();
51 packet.Timestamp();
52 packet.Ssrc();
53 packet.Csrcs();
katrielc36a321d2016-07-05 07:20:24 -070054
55 // Each extension has its own getter. It is supported behaviour to
56 // call GetExtension on an extension which was not registered, so we
57 // don't check the bitmask here.
58 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) {
59 switch (static_cast<RTPExtensionType>(i)) {
60 case kRtpExtensionNone:
61 case kRtpExtensionNumberOfExtensions:
62 break;
63 case kRtpExtensionTransmissionTimeOffset:
64 int32_t offset;
65 packet.GetExtension<TransmissionOffset>(&offset);
66 break;
67 case kRtpExtensionAudioLevel:
68 bool voice_activity;
69 uint8_t audio_level;
70 packet.GetExtension<AudioLevel>(&voice_activity, &audio_level);
71 break;
72 case kRtpExtensionAbsoluteSendTime:
73 uint32_t sendtime;
74 packet.GetExtension<AbsoluteSendTime>(&sendtime);
75 break;
76 case kRtpExtensionVideoRotation:
77 uint8_t rotation;
78 packet.GetExtension<VideoOrientation>(&rotation);
79 break;
80 case kRtpExtensionTransportSequenceNumber:
81 uint16_t seqnum;
82 packet.GetExtension<TransportSequenceNumber>(&seqnum);
83 break;
84 case kRtpExtensionPlayoutDelay:
Danil Chapovalov08b03512016-09-07 15:08:13 +020085 PlayoutDelay playout;
86 packet.GetExtension<PlayoutDelayLimits>(&playout);
katrielc36a321d2016-07-05 07:20:24 -070087 break;
ilnik00d802b2017-04-11 10:34:31 -070088 case kRtpExtensionVideoContentType:
89 VideoContentType content_type;
90 packet.GetExtension<VideoContentTypeExtension>(&content_type);
91 break;
katrielc36a321d2016-07-05 07:20:24 -070092 }
93 }
danilchap1edb7ab2016-04-20 05:25:10 -070094}
danilchap1edb7ab2016-04-20 05:25:10 -070095} // namespace webrtc