38#ifndef CCXX_RTP_RTPPKT_H_
39#define CCXX_RTP_RTPPKT_H_
76 struct RTPFixedHeader;
92 RTPPacket(
const unsigned char*
const block,
size_t len,
93 bool duplicate =
false);
121 inline const uint8*
const
123 {
return (uint8*)(buffer + getHeaderSize()); }
130 {
return payloadSize; }
137 {
return static_cast<PayloadType>(getHeader()->payload); }
144 {
return cachedSeqNum; }
151 {
return cachedTimestamp; }
158 {
return getHeader()->version; }
166 {
return getHeader()->padding; }
176 {
return buffer[total - 1]; }
186 {
return getHeader()->marker; }
195 {
return getHeader()->extension; }
203 {
return getHeader()->cc; }
214 {
return static_cast<const uint32*
>(&(getHeader()->sources[1])); }
230 {
return (isExtended()? getHeaderExt()->undefined : 0); }
245 {
return (isExtended()?
246 (
static_cast<uint32
>(ntohs(getHeaderExt()->length)) << 2) :
255 inline const unsigned char*
257 {
return (isExtended() ?
258 (
reinterpret_cast<const unsigned char*
>(getHeaderExt()) +
259 sizeof(RTPHeaderExt)) :
268 inline const unsigned char*
const
284 {
return total + srtpLength; }
288 {
return sizeof(RTPFixedHeader); }
321 inline RTPFixedHeader*
323 {
return reinterpret_cast<RTPFixedHeader*
>(buffer); }
327 { getHeader()->extension = e; }
336 inline const RTPHeaderExt*
339 uint32 fixsize =
sizeof(RTPFixedHeader) + (getHeader()->cc << 2);
340 return (
reinterpret_cast<RTPHeaderExt*
>(buffer + fixsize));
350 {
return ntohl(getHeader()->timestamp); }
354 { memcpy(buffer + pos,src,len); }
384 unsigned char* buffer;
403 struct RTPFixedHeader
405#if __BYTE_ORDER == __BIG_ENDIAN
407 unsigned char version:2;
408 unsigned char padding:1;
409 unsigned char extension:1;
411 unsigned char marker:1;
412 unsigned char payload:7;
416 unsigned char extension:1;
417 unsigned char padding:1;
418 unsigned char version:2;
419 unsigned char payload:7;
420 unsigned char marker:1;
438#if __BYTE_ORDER == __BIG_ENDIAN
449 uint16 duration : 16;
487 {
return ntohs(getRaw2833Payload()->duration);}
495 {getRaw2833Payload()->duration = htons(timestamp);}
538 const unsigned char*
const hdrext, uint32 hdrextlen,
539 const unsigned char*
const data,
size_t datalen,
563 const unsigned char*
const data,
size_t datalen,
593 { getHeader()->payload = pt; }
604 getHeader()->sequence = htons(seq);
613 cachedTimestamp = pts;
614 getHeader()->timestamp = htonl(pts);
625 { getHeader()->sources[0] = htonl(ssrc); }
636 { getHeader()->sources[0] = ssrc; }
647 { getHeader()->marker = mark; }
662 {
return ( this->getSeqNum() == p.
getSeqNum() ); }
669 {
return ( this->getSeqNum() != p.
getSeqNum() ); }
689 void setCSRCArray(
const uint32*
const csrcs, uint16 numcsrc);
732 {
return headerValid; }
742 {
return cachedSSRC; }
763 {
return ( (this->getSeqNum() == p.
getSeqNum()) &&
764 (this->getSSRC() == p.
getSSRC()) ); }
772 {
return !( *
this == p ); }
795 static const uint16 RTP_INVALID_PT_MASK;
796 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:83
RTP packets received from other participants.
Definition: rtppkt.h:706
~IncomingRTPPkt()
Definition: rtppkt.h:722
int32 unprotect(CryptoContext *pcc)
Unprotect a received packet.
uint32 getSSRC() const
Get synchronization source numeric identifier.
Definition: rtppkt.h:741
bool isHeaderValid()
Get validity of this packet.
Definition: rtppkt.h:731
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:771
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:762
IncomingRTPPkt(const unsigned char *block, size_t len)
Build an RTP packet object from a data buffer.
RTP packets being sent.
Definition: rtppkt.h:509
void setSSRCNetwork(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:635
void setMarker(bool mark)
Specify the value of the marker bit.
Definition: rtppkt.h:646
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:611
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:601
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:592
bool operator!=(const OutgoingRTPPkt &p) const
Outgoing packets are not equal if their sequence numbers differ.
Definition: rtppkt.h:668
bool operator==(const OutgoingRTPPkt &p) const
Outgoing packets are equal if their sequence numbers match.
Definition: rtppkt.h:661
void setSSRC(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:624
~OutgoingRTPPkt()
Definition: rtppkt.h:585
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition: rtppkt.h:74
size_t getSizeOfFixedHeader() const
Definition: rtppkt.h:287
int32 srtpLength
Lebgth of additional SRTP data.
Definition: rtppkt.h:374
uint32 srtpDataOffset
Offset into packet memory pointing to area for SRTP data.
Definition: rtppkt.h:367
uint8 getProtocolVersion() const
Definition: rtppkt.h:157
uint32 payloadSize
note: payload (not full packet) size.
Definition: rtppkt.h:380
void endPacket()
Free memory allocated for the packet.
uint32 getRawPacketSizeSrtp() const
Definition: rtppkt.h:283
uint8 getPaddingSize() const
Get the number of octets padding the end of the payload section.
Definition: rtppkt.h:175
uint32 getTimestamp() const
Definition: rtppkt.h:150
PayloadType getPayloadType() const
Definition: rtppkt.h:136
void setbuffer(const void *src, size_t len, size_t pos)
Definition: rtppkt.h:353
const unsigned char *const getRawPacket() const
Get the raw packet as it will be sent through the network.
Definition: rtppkt.h:269
const uint8 *const getPayload() const
Definition: rtppkt.h:122
bool isMarked() const
Ask whether the packet is marked (for isntance, is a new talk spurt in some audio profiles).
Definition: rtppkt.h:185
bool isPadded() const
Ask whether the packet contains padding bytes at the end.
Definition: rtppkt.h:165
uint16 getHdrExtUndefined() const
Get the first 16 bits (in network order) of the header of the RTP header extension.
Definition: rtppkt.h:229
uint32 getRawPacketSize() const
Get the raw packet length, including header, extension, payload and padding.
Definition: rtppkt.h:279
uint32 cachedTimestamp
Packet timestamp in host order (includes initial shift).
Definition: rtppkt.h:359
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:244
uint32 getHeaderSize() const
Get the length of the header, including contributing sources identifiers and header extension,...
Definition: rtppkt.h:115
bool isExtended() const
Ask whether the packet contains header extensions.
Definition: rtppkt.h:194
uint16 getSeqNum() const
Definition: rtppkt.h:143
RTPFixedHeader * getHeader() const
Return low level structure for the header of the packet.
Definition: rtppkt.h:322
void set2833Duration(uint16 timestamp)
Set 2833 duration field.
Definition: rtppkt.h:494
const RTPHeaderExt * getHeaderExt() const
Get a pointer to RTPHeaderExt pointing after the RTP header (fixed part plus contributing sources).
Definition: rtppkt.h:337
uint32 getRawTimestamp() const
Obtain the absolute timestamp carried in the packet header.
Definition: rtppkt.h:349
const uint32 * getCSRCs() const
Get the 32-bit identifiers of the contributing sources for the packet as an array,...
Definition: rtppkt.h:213
void setExtension(bool e)
Definition: rtppkt.h:326
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:129
uint16 get2833Duration(void)
Fetch 2833 duration field.
Definition: rtppkt.h:486
uint16 cachedSeqNum
Packet sequence number in host order.
Definition: rtppkt.h:357
uint32 total
total length, including header, payload and padding
Definition: rtppkt.h:377
uint16 getCSRCsCount() const
Get the number of contributing sources specified in the packet header.
Definition: rtppkt.h:202
const unsigned char * getHdrExtContent() const
Get the content of the header extension.
Definition: rtppkt.h:256
virtual ~RTPPacket()
Destructor, free the buffer provided in the constructor.
Definition: rtppkt.h:307
struct RFC2833Payload * getRaw2833Payload(void)
Fetch a raw 2833 packet.
Definition: rtppkt.h:478
uint8 PayloadType
RTP payload type numeric identifier.
Definition: formats.h:63
a structure defining RFC2833 Telephony events.
Definition: rtppkt.h:437
uint16 duration
Definition: rtppkt.h:443
uint8 event
Definition: rtppkt.h:439
uint8 vol
Definition: rtppkt.h:442
bool rbit
Definition: rtppkt.h:441
bool ebit
Definition: rtppkt.h:440