blob: c89cb46dee0fc5a43f185d8b43dd725f11a25324 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
12#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
13#include "modules/rtp_rtcp/source/rtp_packet_received.h"
danilchap1edb7ab2016-04-20 05:25:10 -070014
15namespace webrtc {
16
danilchapef8d7732017-04-19 02:59:48 -070017// We decide which header extensions to register by reading two bytes
katrielc36a321d2016-07-05 07:20:24 -070018// from the beginning of |data| and interpreting it as a bitmask over
danilchapef8d7732017-04-19 02:59:48 -070019// the RTPExtensionType enum. This assert ensures two bytes are enough.
20static_assert(kRtpExtensionNumberOfExtensions <= 16,
katrielc36a321d2016-07-05 07:20:24 -070021 "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) {
danilchapef8d7732017-04-19 02:59:48 -070025 if (size <= 2)
katrielc36a321d2016-07-05 07:20:24 -070026 return;
27
danilchapef8d7732017-04-19 02:59:48 -070028 // Don't use the configuration bytes as part of the packet.
29 std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data));
30 data += 2;
31 size -= 2;
katrielc36a321d2016-07-05 07:20:24 -070032
33 RtpPacketReceived::ExtensionManager extensions;
danilchapef8d7732017-04-19 02:59:48 -070034 // Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid.
35 for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) {
katrielc36a321d2016-07-05 07:20:24 -070036 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
37 if (extensionMask[i] && extension_type != kRtpExtensionNone) {
38 // Extensions are registered with an ID, which you signal to the
39 // peer so they know what to expect. This code only cares about
40 // parsing so the value of the ID isn't relevant; we use i.
danilchapef8d7732017-04-19 02:59:48 -070041 extensions.RegisterByType(i, extension_type);
katrielc36a321d2016-07-05 07:20:24 -070042 }
43 }
44
45 RtpPacketReceived packet(&extensions);
danilchap1edb7ab2016-04-20 05:25:10 -070046 packet.Parse(data, size);
47
48 // Call packet accessors because they have extra checks.
49 packet.Marker();
50 packet.PayloadType();
51 packet.SequenceNumber();
52 packet.Timestamp();
53 packet.Ssrc();
54 packet.Csrcs();
katrielc36a321d2016-07-05 07:20:24 -070055
56 // Each extension has its own getter. It is supported behaviour to
57 // call GetExtension on an extension which was not registered, so we
58 // don't check the bitmask here.
59 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) {
60 switch (static_cast<RTPExtensionType>(i)) {
61 case kRtpExtensionNone:
62 case kRtpExtensionNumberOfExtensions:
63 break;
64 case kRtpExtensionTransmissionTimeOffset:
65 int32_t offset;
66 packet.GetExtension<TransmissionOffset>(&offset);
67 break;
68 case kRtpExtensionAudioLevel:
69 bool voice_activity;
70 uint8_t audio_level;
71 packet.GetExtension<AudioLevel>(&voice_activity, &audio_level);
72 break;
73 case kRtpExtensionAbsoluteSendTime:
74 uint32_t sendtime;
75 packet.GetExtension<AbsoluteSendTime>(&sendtime);
76 break;
77 case kRtpExtensionVideoRotation:
78 uint8_t rotation;
79 packet.GetExtension<VideoOrientation>(&rotation);
80 break;
81 case kRtpExtensionTransportSequenceNumber:
82 uint16_t seqnum;
83 packet.GetExtension<TransportSequenceNumber>(&seqnum);
84 break;
85 case kRtpExtensionPlayoutDelay:
Danil Chapovalov08b03512016-09-07 15:08:13 +020086 PlayoutDelay playout;
87 packet.GetExtension<PlayoutDelayLimits>(&playout);
katrielc36a321d2016-07-05 07:20:24 -070088 break;
ilnik00d802b2017-04-11 10:34:31 -070089 case kRtpExtensionVideoContentType:
90 VideoContentType content_type;
91 packet.GetExtension<VideoContentTypeExtension>(&content_type);
92 break;
ilnik04f4d122017-06-19 07:18:55 -070093 case kRtpExtensionVideoTiming:
ilnik2edc6842017-07-06 03:06:50 -070094 VideoSendTiming timing;
ilnik04f4d122017-06-19 07:18:55 -070095 packet.GetExtension<VideoTimingExtension>(&timing);
96 break;
danilchapef8d7732017-04-19 02:59:48 -070097 case kRtpExtensionRtpStreamId: {
98 std::string rsid;
99 packet.GetExtension<RtpStreamId>(&rsid);
100 break;
101 }
102 case kRtpExtensionRepairedRtpStreamId: {
103 std::string rsid;
104 packet.GetExtension<RepairedRtpStreamId>(&rsid);
105 break;
106 }
Steve Antona3251dd2017-07-21 09:58:31 -0700107 case kRtpExtensionMid: {
108 std::string mid;
109 packet.GetExtension<RtpMid>(&mid);
110 break;
111 }
katrielc36a321d2016-07-05 07:20:24 -0700112 }
113 }
danilchap1edb7ab2016-04-20 05:25:10 -0700114}
danilchap1edb7ab2016-04-20 05:25:10 -0700115} // namespace webrtc