blob: 7582f3a98ab069e86bf6a7ea43707d1fa93f2800 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org12dc1a32013-08-05 16:22:53 +000014#include <stddef.h> // size_t, ptrdiff_t
niklase@google.com470e71d2011-07-07 08:21:25 +000015
danilchapb8b6fbb2015-12-10 05:05:27 -080016#include <map>
17
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010018#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
danilchapb8b6fbb2015-12-10 05:05:27 -080019#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000020#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.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
pbos@webrtc.org2f446732013-04-08 11:08:41 +000026const uint8_t kRtpMarkerBitMask = 0x80;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
wu@webrtc.org822fbd82013-08-15 23:38:54 +000028RtpData* NullObjectRtpData();
29RtpFeedback* NullObjectRtpFeedback();
30RtpAudioFeedback* NullObjectRtpAudioFeedback();
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000031ReceiveStatistics* NullObjectReceiveStatistics();
wu@webrtc.org822fbd82013-08-15 23:38:54 +000032
pbos@webrtc.org62bafae2014-07-08 12:10:51 +000033namespace RtpUtility {
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000034 // 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.com470e71d2011-07-07 08:21:25 +000040 struct Payload
41 {
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000042 char name[RTP_PAYLOAD_NAME_SIZE];
43 bool audio;
niklase@google.com470e71d2011-07-07 08:21:25 +000044 PayloadUnion typeSpecific;
45 };
46
pbos@webrtc.org2f446732013-04-08 11:08:41 +000047 typedef std::map<int8_t, Payload*> PayloadTypeMap;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000048
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000049 // Return the current RTP timestamp from the NTP timestamp
50 // returned by the specified clock.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000051 uint32_t GetCurrentRTP(Clock* clock, uint32_t freq);
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000052
53 // Return the current RTP absolute timestamp.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 uint32_t ConvertNTPTimeToRTP(uint32_t NTPsec,
55 uint32_t NTPfrac,
56 uint32_t freq);
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000057
pbos@webrtc.org2f446732013-04-08 11:08:41 +000058 uint32_t pow2(uint8_t exp);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
marpan@webrtc.org57353a32011-12-16 17:21:09 +000060 // 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.orgf6bb77a2012-01-24 17:16:59 +000067 bool StringCompare(const char* str1,
68 const char* str2,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000069 const uint32_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +000070
sprang@webrtc.org30933902015-03-17 14:33:12 +000071 // Round up to the nearest size that is a multiple of 4.
72 size_t Word32Align(size_t size);
73
pbos@webrtc.org62bafae2014-07-08 12:10:51 +000074 class RtpHeaderParser {
niklase@google.com470e71d2011-07-07 08:21:25 +000075 public:
pbos@webrtc.org62bafae2014-07-08 12:10:51 +000076 RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength);
77 ~RtpHeaderParser();
niklase@google.com470e71d2011-07-07 08:21:25 +000078
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000079 bool RTCP() const;
solenberg@webrtc.orga5fd2f12013-06-26 08:36:07 +000080 bool ParseRtcp(RTPHeader* header) const;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000081 bool Parse(RTPHeader& parsedPacket,
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000082 RtpHeaderExtensionMap* ptrExtensionMap = NULL) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
84 private:
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000085 void ParseOneByteExtensionHeader(
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000086 RTPHeader& parsedPacket,
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000087 const RtpHeaderExtensionMap* ptrExtensionMap,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000088 const uint8_t* ptrRTPDataExtensionEnd,
89 const uint8_t* ptr) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000090
pbos@webrtc.org2f446732013-04-08 11:08:41 +000091 uint8_t ParsePaddingBytes(
92 const uint8_t* ptrRTPDataExtensionEnd,
93 const uint8_t* ptr) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +000094
pbos@webrtc.org2f446732013-04-08 11:08:41 +000095 const uint8_t* const _ptrRTPDataBegin;
96 const uint8_t* const _ptrRTPDataEnd;
niklase@google.com470e71d2011-07-07 08:21:25 +000097 };
stefan@webrtc.org5a098c52014-09-17 11:58:20 +000098} // namespace RtpUtility
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000099} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
101#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_