1 /*
2  *  Copyright (c) 2012 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 #ifndef MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
12 #define MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
13 
14 #include <cstring>
15 #include <map>
16 
17 #include "modules/rtp_rtcp/include/receive_statistics.h"
18 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
19 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
20 #include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
21 #include "rtc_base/deprecation.h"
22 #include "typedefs.h"  // NOLINT(build/include)
23 
24 namespace webrtc {
25 
26 const uint8_t kRtpMarkerBitMask = 0x80;
27 
28 RtpFeedback* NullObjectRtpFeedback();
29 
30 namespace RtpUtility {
31 
32 struct Payload {
PayloadPayload33   Payload(const char* name, const PayloadUnion& pu) : typeSpecific(pu) {
34     std::strncpy(this->name, name, sizeof(this->name) - 1);
35     this->name[sizeof(this->name) - 1] = '\0';
36   }
37   char name[RTP_PAYLOAD_NAME_SIZE];
38   PayloadUnion typeSpecific;
39 };
40 
41 bool StringCompare(const char* str1, const char* str2, const uint32_t length);
42 
43 // Round up to the nearest size that is a multiple of 4.
44 size_t Word32Align(size_t size);
45 
46 class RtpHeaderParser {
47  public:
48   RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength);
49   ~RtpHeaderParser();
50 
51   bool RTCP() const;
52   bool ParseRtcp(RTPHeader* header) const;
53   bool Parse(RTPHeader* parsedPacket,
54              RtpHeaderExtensionMap* ptrExtensionMap = nullptr,
55              bool secured = false) const;
56 
57  private:
58   void ParseOneByteExtensionHeader(RTPHeader* parsedPacket,
59                                    const RtpHeaderExtensionMap* ptrExtensionMap,
60                                    const uint8_t* ptrRTPDataExtensionEnd,
61                                    const uint8_t* ptr) const;
62 
63   const uint8_t* const _ptrRTPDataBegin;
64   const uint8_t* const _ptrRTPDataEnd;
65 };
66 }  // namespace RtpUtility
67 }  // namespace webrtc
68 
69 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
70