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 | |
danilchap | b8b6fbb | 2015-12-10 05:05:27 -0800 | [diff] [blame^] | 16 | #include <map> |
| 17 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 18 | #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
danilchap | b8b6fbb | 2015-12-10 05:05:27 -0800 | [diff] [blame^] | 19 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
| 21 | #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
| 22 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 26 | const uint8_t kRtpMarkerBitMask = 0x80; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 28 | RtpData* NullObjectRtpData(); |
| 29 | RtpFeedback* NullObjectRtpFeedback(); |
| 30 | RtpAudioFeedback* NullObjectRtpAudioFeedback(); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 31 | ReceiveStatistics* NullObjectReceiveStatistics(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 32 | |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 33 | namespace RtpUtility { |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 34 | // January 1970, in NTP seconds. |
| 35 | const uint32_t NTP_JAN_1970 = 2208988800UL; |
| 36 | |
| 37 | // Magic NTP fractional unit. |
| 38 | const double NTP_FRAC = 4.294967296E+9; |
| 39 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | struct Payload |
| 41 | { |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 42 | char name[RTP_PAYLOAD_NAME_SIZE]; |
| 43 | bool audio; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | PayloadUnion typeSpecific; |
| 45 | }; |
| 46 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 47 | typedef std::map<int8_t, Payload*> PayloadTypeMap; |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 48 | |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 49 | // Return the current RTP timestamp from the NTP timestamp |
| 50 | // returned by the specified clock. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 51 | uint32_t GetCurrentRTP(Clock* clock, uint32_t freq); |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 52 | |
| 53 | // Return the current RTP absolute timestamp. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 54 | uint32_t ConvertNTPTimeToRTP(uint32_t NTPsec, |
| 55 | uint32_t NTPfrac, |
| 56 | uint32_t freq); |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 57 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 58 | uint32_t pow2(uint8_t exp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
marpan@webrtc.org | 57353a3 | 2011-12-16 17:21:09 +0000 | [diff] [blame] | 60 | // Returns true if |newTimestamp| is older than |existingTimestamp|. |
| 61 | // |wrapped| will be set to true if there has been a wraparound between the |
| 62 | // two timestamps. |
| 63 | bool OldTimestamp(uint32_t newTimestamp, |
| 64 | uint32_t existingTimestamp, |
| 65 | bool* wrapped); |
| 66 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 67 | bool StringCompare(const char* str1, |
| 68 | const char* str2, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 69 | const uint32_t length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
sprang@webrtc.org | 3093390 | 2015-03-17 14:33:12 +0000 | [diff] [blame] | 71 | // Round up to the nearest size that is a multiple of 4. |
| 72 | size_t Word32Align(size_t size); |
| 73 | |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 74 | class RtpHeaderParser { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | public: |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 76 | RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength); |
| 77 | ~RtpHeaderParser(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 79 | bool RTCP() const; |
solenberg@webrtc.org | a5fd2f1 | 2013-06-26 08:36:07 +0000 | [diff] [blame] | 80 | bool ParseRtcp(RTPHeader* header) const; |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 81 | bool Parse(RTPHeader& parsedPacket, |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 82 | RtpHeaderExtensionMap* ptrExtensionMap = NULL) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
| 84 | private: |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 85 | void ParseOneByteExtensionHeader( |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 86 | RTPHeader& parsedPacket, |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 87 | const RtpHeaderExtensionMap* ptrExtensionMap, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 88 | const uint8_t* ptrRTPDataExtensionEnd, |
| 89 | const uint8_t* ptr) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 90 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 91 | uint8_t ParsePaddingBytes( |
| 92 | const uint8_t* ptrRTPDataExtensionEnd, |
| 93 | const uint8_t* ptr) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 95 | const uint8_t* const _ptrRTPDataBegin; |
| 96 | const uint8_t* const _ptrRTPDataEnd; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | }; |
stefan@webrtc.org | 5a098c5 | 2014-09-17 11:58:20 +0000 | [diff] [blame] | 98 | } // namespace RtpUtility |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 99 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
| 101 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ |