2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
|
|
|
|
|
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <stddef.h> // size_t, ptrdiff_t
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 05:05:27 -08:00
|
|
|
#include <map>
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
|
2015-12-10 05:05:27 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
|
|
|
|
#include "webrtc/typedefs.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
const uint8_t kRtpMarkerBitMask = 0x80;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
RtpData* NullObjectRtpData();
|
|
|
|
|
RtpFeedback* NullObjectRtpFeedback();
|
|
|
|
|
RtpAudioFeedback* NullObjectRtpAudioFeedback();
|
2013-08-21 20:58:21 +00:00
|
|
|
ReceiveStatistics* NullObjectReceiveStatistics();
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2014-07-08 12:10:51 +00:00
|
|
|
namespace RtpUtility {
|
2011-12-01 15:42:31 +00:00
|
|
|
// January 1970, in NTP seconds.
|
|
|
|
|
const uint32_t NTP_JAN_1970 = 2208988800UL;
|
|
|
|
|
|
|
|
|
|
// Magic NTP fractional unit.
|
|
|
|
|
const double NTP_FRAC = 4.294967296E+9;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
struct Payload
|
|
|
|
|
{
|
2012-01-24 17:16:59 +00:00
|
|
|
char name[RTP_PAYLOAD_NAME_SIZE];
|
|
|
|
|
bool audio;
|
2011-07-07 08:21:25 +00:00
|
|
|
PayloadUnion typeSpecific;
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
typedef std::map<int8_t, Payload*> PayloadTypeMap;
|
2012-12-18 15:40:53 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint32_t pow2(uint8_t exp);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-16 17:21:09 +00:00
|
|
|
// Returns true if |newTimestamp| is older than |existingTimestamp|.
|
|
|
|
|
// |wrapped| will be set to true if there has been a wraparound between the
|
|
|
|
|
// two timestamps.
|
|
|
|
|
bool OldTimestamp(uint32_t newTimestamp,
|
|
|
|
|
uint32_t existingTimestamp,
|
|
|
|
|
bool* wrapped);
|
|
|
|
|
|
2012-01-24 17:16:59 +00:00
|
|
|
bool StringCompare(const char* str1,
|
|
|
|
|
const char* str2,
|
2013-04-08 11:08:41 +00:00
|
|
|
const uint32_t length);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-17 14:33:12 +00:00
|
|
|
// Round up to the nearest size that is a multiple of 4.
|
|
|
|
|
size_t Word32Align(size_t size);
|
|
|
|
|
|
2014-07-08 12:10:51 +00:00
|
|
|
class RtpHeaderParser {
|
2011-07-07 08:21:25 +00:00
|
|
|
public:
|
2014-07-08 12:10:51 +00:00
|
|
|
RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength);
|
|
|
|
|
~RtpHeaderParser();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-16 14:31:37 +00:00
|
|
|
bool RTCP() const;
|
2013-06-26 08:36:07 +00:00
|
|
|
bool ParseRtcp(RTPHeader* header) const;
|
2013-05-29 12:12:51 +00:00
|
|
|
bool Parse(RTPHeader& parsedPacket,
|
2011-12-16 14:31:37 +00:00
|
|
|
RtpHeaderExtensionMap* ptrExtensionMap = NULL) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
private:
|
2011-12-16 14:31:37 +00:00
|
|
|
void ParseOneByteExtensionHeader(
|
2013-05-29 12:12:51 +00:00
|
|
|
RTPHeader& parsedPacket,
|
2011-12-16 14:31:37 +00:00
|
|
|
const RtpHeaderExtensionMap* ptrExtensionMap,
|
2013-04-08 11:08:41 +00:00
|
|
|
const uint8_t* ptrRTPDataExtensionEnd,
|
|
|
|
|
const uint8_t* ptr) const;
|
2011-12-16 14:31:37 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint8_t ParsePaddingBytes(
|
|
|
|
|
const uint8_t* ptrRTPDataExtensionEnd,
|
|
|
|
|
const uint8_t* ptr) const;
|
2011-12-16 14:31:37 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
const uint8_t* const _ptrRTPDataBegin;
|
|
|
|
|
const uint8_t* const _ptrRTPDataEnd;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2014-09-17 11:58:20 +00:00
|
|
|
} // namespace RtpUtility
|
2012-02-08 23:41:49 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_
|