2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08: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.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MEDIA_BASE_RTPUTILS_H_
|
|
|
|
|
#define MEDIA_BASE_RTPUTILS_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/byteorder.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-01-14 17:14:54 -08:00
|
|
|
namespace rtc {
|
|
|
|
|
struct PacketTimeUpdateParams;
|
|
|
|
|
} // namespace rtc
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
const size_t kMinRtpPacketLen = 12;
|
|
|
|
|
const size_t kMaxRtpPacketLen = 2048;
|
|
|
|
|
const size_t kMinRtcpPacketLen = 4;
|
|
|
|
|
|
|
|
|
|
struct RtpHeader {
|
|
|
|
|
int payload_type;
|
|
|
|
|
int seq_num;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t timestamp;
|
|
|
|
|
uint32_t ssrc;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum RtcpTypes {
|
|
|
|
|
kRtcpTypeSR = 200, // Sender report payload type.
|
|
|
|
|
kRtcpTypeRR = 201, // Receiver report payload type.
|
|
|
|
|
kRtcpTypeSDES = 202, // SDES payload type.
|
|
|
|
|
kRtcpTypeBye = 203, // BYE payload type.
|
|
|
|
|
kRtcpTypeApp = 204, // APP payload type.
|
|
|
|
|
kRtcpTypeRTPFB = 205, // Transport layer Feedback message payload type.
|
|
|
|
|
kRtcpTypePSFB = 206, // Payload-specific Feedback message payload type.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool GetRtpPayloadType(const void* data, size_t len, int* value);
|
|
|
|
|
bool GetRtpSeqNum(const void* data, size_t len, int* value);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
bool GetRtpTimestamp(const void* data, size_t len, uint32_t* value);
|
|
|
|
|
bool GetRtpSsrc(const void* data, size_t len, uint32_t* value);
|
2013-07-10 00:45:36 +00:00
|
|
|
bool GetRtpHeaderLen(const void* data, size_t len, size_t* value);
|
|
|
|
|
bool GetRtcpType(const void* data, size_t len, int* value);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
bool GetRtcpSsrc(const void* data, size_t len, uint32_t* value);
|
2013-07-10 00:45:36 +00:00
|
|
|
bool GetRtpHeader(const void* data, size_t len, RtpHeader* header);
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
bool SetRtpSsrc(void* data, size_t len, uint32_t value);
|
2013-07-10 00:45:36 +00:00
|
|
|
// Assumes version 2, no padding, no extensions, no csrcs.
|
|
|
|
|
bool SetRtpHeader(void* data, size_t len, const RtpHeader& header);
|
|
|
|
|
|
2014-06-19 23:54:12 +00:00
|
|
|
bool IsRtpPacket(const void* data, size_t len);
|
2015-02-17 20:36:28 +00:00
|
|
|
|
|
|
|
|
// True if |payload type| is 0-127.
|
|
|
|
|
bool IsValidRtpPayloadType(int payload_type);
|
|
|
|
|
|
2017-06-01 13:22:42 -07:00
|
|
|
// True if |size| is appropriate for the indicated packet type.
|
|
|
|
|
bool IsValidRtpRtcpPacketSize(bool rtcp, size_t size);
|
|
|
|
|
|
|
|
|
|
// TODO(zstein): Consider using an enum instead of a bool to differentiate
|
|
|
|
|
// between RTP and RTCP.
|
|
|
|
|
// Returns "RTCP" or "RTP" according to |rtcp|.
|
|
|
|
|
const char* RtpRtcpStringLiteral(bool rtcp);
|
|
|
|
|
|
2016-01-14 17:14:54 -08:00
|
|
|
// Verifies that a packet has a valid RTP header.
|
|
|
|
|
bool ValidateRtpHeader(const uint8_t* rtp,
|
|
|
|
|
size_t length,
|
|
|
|
|
size_t* header_length);
|
|
|
|
|
|
|
|
|
|
// Helper method which updates the absolute send time extension if present.
|
|
|
|
|
bool UpdateRtpAbsSendTimeExtension(uint8_t* rtp,
|
|
|
|
|
size_t length,
|
|
|
|
|
int extension_id,
|
|
|
|
|
uint64_t time_us);
|
|
|
|
|
|
|
|
|
|
// Applies specified |options| to the packet. It updates the absolute send time
|
|
|
|
|
// extension header if it is present present then updates HMAC.
|
|
|
|
|
bool ApplyPacketOptions(uint8_t* data,
|
|
|
|
|
size_t length,
|
|
|
|
|
const rtc::PacketTimeUpdateParams& packet_time_params,
|
|
|
|
|
uint64_t time_us);
|
|
|
|
|
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MEDIA_BASE_RTPUTILS_H_
|