danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [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 | */ |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #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" |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 17 | // We decide which header extensions to register by reading two bytes |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 18 | // from the beginning of |data| and interpreting it as a bitmask over |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 19 | // the RTPExtensionType enum. This assert ensures two bytes are enough. |
| 20 | static_assert(kRtpExtensionNumberOfExtensions <= 16, |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 21 | "Insufficient bits read to configure all header extensions. Add " |
| 22 | "an extra byte and update the switches."); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 23 | |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 24 | void FuzzOneInput(const uint8_t* data, size_t size) { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 25 | if (size <= 2) |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 26 | return; |
| 27 | |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 28 | // 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; |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 32 | |
| 33 | RtpPacketReceived::ExtensionManager extensions; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 34 | // Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid. |
| 35 | for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) { |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 36 | 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. |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 41 | extensions.RegisterByType(i, extension_type); |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | RtpPacketReceived packet(&extensions); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 46 | 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(); |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 55 | |
| 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 Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 86 | PlayoutDelay playout; |
| 87 | packet.GetExtension<PlayoutDelayLimits>(&playout); |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 88 | break; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 89 | case kRtpExtensionVideoContentType: |
| 90 | VideoContentType content_type; |
| 91 | packet.GetExtension<VideoContentTypeExtension>(&content_type); |
| 92 | break; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 93 | case kRtpExtensionVideoTiming: |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 94 | VideoSendTiming timing; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 95 | packet.GetExtension<VideoTimingExtension>(&timing); |
| 96 | break; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 97 | 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 Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 107 | case kRtpExtensionMid: { |
| 108 | std::string mid; |
| 109 | packet.GetExtension<RtpMid>(&mid); |
| 110 | break; |
| 111 | } |
katrielc | 36a321d | 2016-07-05 07:20:24 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 114 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 115 | } // namespace webrtc |