niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ |
| 13 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 14 | #include <stddef.h> // size_t, ptrdiff_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
| 19 | #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
| 20 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 24 | const uint8_t kRtpMarkerBitMask = 0x80; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 26 | RtpData* NullObjectRtpData(); |
| 27 | RtpFeedback* NullObjectRtpFeedback(); |
| 28 | RtpAudioFeedback* NullObjectRtpAudioFeedback(); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 29 | ReceiveStatistics* NullObjectReceiveStatistics(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 30 | |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 31 | namespace RtpUtility { |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 32 | // January 1970, in NTP seconds. |
| 33 | const uint32_t NTP_JAN_1970 = 2208988800UL; |
| 34 | |
| 35 | // Magic NTP fractional unit. |
| 36 | const double NTP_FRAC = 4.294967296E+9; |
| 37 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | struct Payload |
| 39 | { |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 40 | char name[RTP_PAYLOAD_NAME_SIZE]; |
| 41 | bool audio; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | PayloadUnion typeSpecific; |
| 43 | }; |
| 44 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 45 | typedef std::map<int8_t, Payload*> PayloadTypeMap; |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 46 | |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 47 | // Return the current RTP timestamp from the NTP timestamp |
| 48 | // returned by the specified clock. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 49 | uint32_t GetCurrentRTP(Clock* clock, uint32_t freq); |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 50 | |
| 51 | // Return the current RTP absolute timestamp. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 52 | uint32_t ConvertNTPTimeToRTP(uint32_t NTPsec, |
| 53 | uint32_t NTPfrac, |
| 54 | uint32_t freq); |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 55 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 56 | uint32_t pow2(uint8_t exp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
marpan@webrtc.org | 57353a3 | 2011-12-16 17:21:09 +0000 | [diff] [blame] | 58 | // Returns true if |newTimestamp| is older than |existingTimestamp|. |
| 59 | // |wrapped| will be set to true if there has been a wraparound between the |
| 60 | // two timestamps. |
| 61 | bool OldTimestamp(uint32_t newTimestamp, |
| 62 | uint32_t existingTimestamp, |
| 63 | bool* wrapped); |
| 64 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 65 | bool StringCompare(const char* str1, |
| 66 | const char* str2, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 67 | const uint32_t length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 69 | void AssignUWord32ToBuffer(uint8_t* dataBuffer, uint32_t value); |
| 70 | void AssignUWord24ToBuffer(uint8_t* dataBuffer, uint32_t value); |
| 71 | void AssignUWord16ToBuffer(uint8_t* dataBuffer, uint16_t value); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Converts a network-ordered two-byte input buffer to a host-ordered value. |
| 75 | * \param[in] dataBuffer Network-ordered two-byte buffer to convert. |
| 76 | * \return Host-ordered value. |
| 77 | */ |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 78 | uint16_t BufferToUWord16(const uint8_t* dataBuffer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Converts a network-ordered three-byte input buffer to a host-ordered value. |
| 82 | * \param[in] dataBuffer Network-ordered three-byte buffer to convert. |
| 83 | * \return Host-ordered value. |
| 84 | */ |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 85 | uint32_t BufferToUWord24(const uint8_t* dataBuffer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Converts a network-ordered four-byte input buffer to a host-ordered value. |
| 89 | * \param[in] dataBuffer Network-ordered four-byte buffer to convert. |
| 90 | * \return Host-ordered value. |
| 91 | */ |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 92 | uint32_t BufferToUWord32(const uint8_t* dataBuffer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 94 | class RtpHeaderParser { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | public: |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 96 | RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength); |
| 97 | ~RtpHeaderParser(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 99 | bool RTCP() const; |
solenberg@webrtc.org | a5fd2f1 | 2013-06-26 08:36:07 +0000 | [diff] [blame] | 100 | bool ParseRtcp(RTPHeader* header) const; |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 101 | bool Parse(RTPHeader& parsedPacket, |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 102 | RtpHeaderExtensionMap* ptrExtensionMap = NULL) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
| 104 | private: |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 105 | void ParseOneByteExtensionHeader( |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 106 | RTPHeader& parsedPacket, |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 107 | const RtpHeaderExtensionMap* ptrExtensionMap, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 108 | const uint8_t* ptrRTPDataExtensionEnd, |
| 109 | const uint8_t* ptr) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 110 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 111 | uint8_t ParsePaddingBytes( |
| 112 | const uint8_t* ptrRTPDataExtensionEnd, |
| 113 | const uint8_t* ptr) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 114 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 115 | const uint8_t* const _ptrRTPDataBegin; |
| 116 | const uint8_t* const _ptrRTPDataEnd; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | }; |
stefan@webrtc.org | 5a098c5 | 2014-09-17 11:58:20 +0000 | [diff] [blame^] | 118 | } // namespace RtpUtility |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 119 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
| 121 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ |