37 #ifndef CCXX_RTP_RTPPKT_H_
38 #define CCXX_RTP_RTPPKT_H_
75 struct RTPFixedHeader;
91 RTPPacket(
const unsigned char*
const block,
size_t len,
92 bool duplicate =
false);
120 inline const uint8*
const
122 {
return (uint8*)(buffer + getHeaderSize()); }
129 {
return payloadSize; }
136 {
return static_cast<PayloadType>(getHeader()->payload); }
143 {
return cachedSeqNum; }
150 {
return cachedTimestamp; }
157 {
return getHeader()->version; }
165 {
return getHeader()->padding; }
175 {
return buffer[total - 1]; }
185 {
return getHeader()->marker; }
194 {
return getHeader()->extension; }
202 {
return getHeader()->cc; }
213 {
return static_cast<const uint32*
>(&(getHeader()->sources[1])); }
229 {
return (isExtended()? getHeaderExt()->undefined : 0); }
244 {
return (isExtended()?
245 (
static_cast<uint32
>(ntohs(getHeaderExt()->length)) << 2) :
254 inline const unsigned char*
256 {
return (isExtended() ?
257 (
reinterpret_cast<const unsigned char*
>(getHeaderExt()) +
258 sizeof(RTPHeaderExt)) :
267 inline const unsigned char*
const
283 {
return total + srtpLength; }
287 {
return sizeof(RTPFixedHeader); }
320 inline RTPFixedHeader*
322 {
return reinterpret_cast<RTPFixedHeader*
>(buffer); }
326 { getHeader()->extension = e; }
335 inline const RTPHeaderExt*
338 uint32 fixsize =
sizeof(RTPFixedHeader) + (getHeader()->cc << 2);
339 return (
reinterpret_cast<RTPHeaderExt*
>(buffer + fixsize));
349 {
return ntohl(getHeader()->timestamp); }
353 { memcpy(buffer + pos,src,len); }
383 unsigned char* buffer;
402 struct RTPFixedHeader
404 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
406 unsigned char version:2;
407 unsigned char padding:1;
408 unsigned char extension:1;
410 unsigned char marker:1;
411 unsigned char payload:7;
415 unsigned char extension:1;
416 unsigned char padding:1;
417 unsigned char version:2;
418 unsigned char payload:7;
419 unsigned char marker:1;
437 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
442 uint16 duration : 16;
486 {
return ntohs(getRaw2833Payload()->duration);}
494 {getRaw2833Payload()->duration = htons(timestamp);}
537 const unsigned char*
const hdrext, uint32 hdrextlen,
538 const unsigned char*
const data,
size_t datalen,
562 const unsigned char*
const data,
size_t datalen,
592 { getHeader()->payload = pt; }
603 getHeader()->sequence = htons(seq);
612 cachedTimestamp = pts;
613 getHeader()->timestamp = htonl(pts);
624 { getHeader()->sources[0] = htonl(ssrc); }
635 { getHeader()->sources[0] = ssrc; }
646 { getHeader()->marker = mark; }
661 {
return ( this->getSeqNum() == p.
getSeqNum() ); }
668 {
return ( this->getSeqNum() != p.
getSeqNum() ); }
688 void setCSRCArray(
const uint32*
const csrcs, uint16 numcsrc);
731 {
return headerValid; }
741 {
return cachedSSRC; }
762 {
return ( (this->getSeqNum() == p.
getSeqNum()) &&
763 (this->getSSRC() == p.
getSSRC()) ); }
771 {
return !( *
this == p ); }
794 static const uint16 RTP_INVALID_PT_MASK;
795 static const uint16 RTP_INVALID_PT_VALUE;
Base elements for RTP stacks: constants, types and global functions.
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:82
RTP packets received from other participants.
Definition: rtppkt.h:705
~IncomingRTPPkt()
Definition: rtppkt.h:721
int32 unprotect(CryptoContext *pcc)
Unprotect a received packet.
uint32 getSSRC() const
Get synchronization source numeric identifier.
Definition: rtppkt.h:740
bool isHeaderValid()
Get validity of this packet.
Definition: rtppkt.h:730
bool operator!=(const IncomingRTPPkt &p) const
Two incoming packets are not equal if they come from different sources or have different sequence num...
Definition: rtppkt.h:770
bool operator==(const IncomingRTPPkt &p) const
Two incoming packets are equal if they come from sources with the same SSRC and have the same sequenc...
Definition: rtppkt.h:761
IncomingRTPPkt(const unsigned char *block, size_t len)
Build an RTP packet object from a data buffer.
RTP packets being sent.
Definition: rtppkt.h:508
void setSSRCNetwork(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:634
void setMarker(bool mark)
Specify the value of the marker bit.
Definition: rtppkt.h:645
void protect(uint32 ssrc, CryptoContext *pcc)
Called packet is setup.
OutgoingRTPPkt(const uint32 *const csrcs, uint16 numcsrc, const unsigned char *const hdrext, uint32 hdrextlen, const unsigned char *const data, size_t datalen, uint8 paddinglen=0, CryptoContext *pcc=NULL)
Construct a new packet to be sent, containing several contributing source identifiers,...
void setTimestamp(uint32 pts)
Definition: rtppkt.h:610
OutgoingRTPPkt(const uint32 *const csrcs, uint16 numcsrc, const unsigned char *const data, size_t datalen, uint8 paddinglen=0, CryptoContext *pcc=NULL)
Construct a new packet to be sent, containing several contributing source identifiers and payload.
void setSeqNum(uint16 seq)
Definition: rtppkt.h:600
OutgoingRTPPkt(const unsigned char *const data, size_t datalen, uint8 paddinglen=0, CryptoContext *pcc=NULL)
Construct a new packet (fast variant, with no contributing sources and no header extension) to be sen...
void setPayloadType(PayloadType pt)
Definition: rtppkt.h:591
bool operator!=(const OutgoingRTPPkt &p) const
Outgoing packets are not equal if their sequence numbers differ.
Definition: rtppkt.h:667
bool operator==(const OutgoingRTPPkt &p) const
Outgoing packets are equal if their sequence numbers match.
Definition: rtppkt.h:660
void setSSRC(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:623
~OutgoingRTPPkt()
Definition: rtppkt.h:584
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition: rtppkt.h:73
size_t getSizeOfFixedHeader() const
Definition: rtppkt.h:286
int32 srtpLength
Lebgth of additional SRTP data.
Definition: rtppkt.h:373
uint32 srtpDataOffset
Offset into packet memory pointing to area for SRTP data.
Definition: rtppkt.h:366
uint8 getProtocolVersion() const
Definition: rtppkt.h:156
uint32 payloadSize
note: payload (not full packet) size.
Definition: rtppkt.h:379
void endPacket()
Free memory allocated for the packet.
uint32 getRawPacketSizeSrtp() const
Definition: rtppkt.h:282
const uint8 *const getPayload() const
Definition: rtppkt.h:121
uint8 getPaddingSize() const
Get the number of octets padding the end of the payload section.
Definition: rtppkt.h:174
uint32 getTimestamp() const
Definition: rtppkt.h:149
PayloadType getPayloadType() const
Definition: rtppkt.h:135
void setbuffer(const void *src, size_t len, size_t pos)
Definition: rtppkt.h:352
bool isMarked() const
Ask whether the packet is marked (for isntance, is a new talk spurt in some audio profiles).
Definition: rtppkt.h:184
bool isPadded() const
Ask whether the packet contains padding bytes at the end.
Definition: rtppkt.h:164
uint16 getHdrExtUndefined() const
Get the first 16 bits (in network order) of the header of the RTP header extension.
Definition: rtppkt.h:228
uint32 getRawPacketSize() const
Get the raw packet length, including header, extension, payload and padding.
Definition: rtppkt.h:278
uint32 cachedTimestamp
Packet timestamp in host order (includes initial shift).
Definition: rtppkt.h:358
RTPPacket(const unsigned char *const block, size_t len, bool duplicate=false)
Constructor, construct a packet object given the memory zone its content (header and payload) is stor...
uint32 getHdrExtSize() const
Get the length (in octets) of the data contained in the header extension.
Definition: rtppkt.h:243
uint32 getHeaderSize() const
Get the length of the header, including contributing sources identifiers and header extension,...
Definition: rtppkt.h:114
bool isExtended() const
Ask whether the packet contains header extensions.
Definition: rtppkt.h:193
uint16 getSeqNum() const
Definition: rtppkt.h:142
void set2833Duration(uint16 timestamp)
Set 2833 duration field.
Definition: rtppkt.h:493
RTPFixedHeader * getHeader() const
Return low level structure for the header of the packet.
Definition: rtppkt.h:321
uint32 getRawTimestamp() const
Obtain the absolute timestamp carried in the packet header.
Definition: rtppkt.h:348
void setExtension(bool e)
Definition: rtppkt.h:325
struct RFC2833Payload * getRaw2833Payload(void)
Fetch a raw 2833 packet.
Definition: rtppkt.h:477
RTPPacket(size_t hdrlen, size_t plen, uint8 paddinglen, CryptoContext *pcc=NULL)
Construct a packet object without specifying its real content yet.
void reComputePayLength(bool padding)
Re-compute payload length.
uint32 getPayloadSize() const
Definition: rtppkt.h:128
const RTPHeaderExt * getHeaderExt() const
Get a pointer to RTPHeaderExt pointing after the RTP header (fixed part plus contributing sources).
Definition: rtppkt.h:336
uint16 get2833Duration(void)
Fetch 2833 duration field.
Definition: rtppkt.h:485
uint16 cachedSeqNum
Packet sequence number in host order.
Definition: rtppkt.h:356
uint32 total
total length, including header, payload and padding
Definition: rtppkt.h:376
uint16 getCSRCsCount() const
Get the number of contributing sources specified in the packet header.
Definition: rtppkt.h:201
virtual ~RTPPacket()
Destructor, free the buffer provided in the constructor.
Definition: rtppkt.h:306
const unsigned char *const getRawPacket() const
Get the raw packet as it will be sent through the network.
Definition: rtppkt.h:268
const uint32 * getCSRCs() const
Get the 32-bit identifiers of the contributing sources for the packet as an array,...
Definition: rtppkt.h:212
const unsigned char * getHdrExtContent() const
Get the content of the header extension.
Definition: rtppkt.h:255
uint8 PayloadType
RTP payload type numeric identifier.
Definition: formats.h:62
a structure defining RFC2833 Telephony events.
Definition: rtppkt.h:436
uint16 duration
Definition: rtppkt.h:448
uint8 event
Definition: rtppkt.h:444
uint8 vol
Definition: rtppkt.h:445
bool rbit
Definition: rtppkt.h:446
bool ebit
Definition: rtppkt.h:447