Bayonne2 / Common C++ 2 Framework: rtppkt.h Source File

Bayonne2 / Common C++ 2 Framework
rtppkt.h
Go to the documentation of this file.
1 // Copyright (C) 2002 Federico Montesino Pouzols <fedemp@altern.org>.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
38 #ifndef CCXX_RTP_RTPPKT_H_
39 #define CCXX_RTP_RTPPKT_H_
40 
41 #include <ccrtp/base.h>
42 #include <ccrtp/formats.h>
43 #include <ccrtp/CryptoContext.h>
44 
45 #ifdef CCXX_NAMESPACES
46 namespace ost {
47 #endif
48 
73 class CryptoContext;
74 
75  class __EXPORT RTPPacket
76 {
77 private:
78  struct RTPFixedHeader;
79  struct RTPHeaderExt;
80 
81 public:
94  RTPPacket(const unsigned char* const block, size_t len,
95  bool duplicate = false);
96 
108  RTPPacket(size_t hdrlen, size_t plen, uint8 paddinglen, CryptoContext* pcc= NULL);
109 
116  inline uint32
117   getHeaderSize() const
118 { return hdrSize; }
119 
123  inline const uint8* const
124   getPayload() const
125 { return (uint8*)(buffer + getHeaderSize()); }
126 
130  inline uint32
131   getPayloadSize() const
132 { return payloadSize; }
133 
137  inline PayloadType
138   getPayloadType() const
139 { return static_cast<PayloadType >(getHeader()->payload); }
140 
144  inline uint16
145   getSeqNum() const
146 { return cachedSeqNum; }
147 
151  inline uint32
152   getTimestamp() const
153 { return cachedTimestamp; }
154 
158  inline uint8
159   getProtocolVersion() const
160 { return getHeader()->version; }
161 
166  inline bool
167   isPadded() const
168 { return getHeader()->padding; }
169 
176  inline uint8
177   getPaddingSize() const
178 { return buffer[total - 1]; }
179 
186  inline bool
187   isMarked() const
188 { return getHeader()->marker; }
189 
195  inline bool
196   isExtended() const
197 { return getHeader()->extension; }
198 
203  inline uint16
204   getCSRCsCount() const
205 { return getHeader()->cc; }
206 
214  inline const uint32*
215   getCSRCs() const
216 { return static_cast<const uint32*>(&(getHeader()->sources[1])); }
217 
230  inline uint16
231   getHdrExtUndefined() const
232 { return (isExtended()? getHeaderExt()->undefined : 0); }
233 
245  inline uint32
246   getHdrExtSize() const
247 { return (isExtended()?
248  (static_cast<uint32>(ntohs(getHeaderExt()->length)) << 2) :
249  0); }
250 
257  inline const unsigned char*
258   getHdrExtContent() const
259 { return (isExtended() ?
260  (reinterpret_cast<const unsigned char*>(getHeaderExt()) +
261  sizeof(RTPHeaderExt)) :
262  NULL); }
263 
270  inline const unsigned char* const
271   getRawPacket() const
272 { return buffer; }
273 
280  inline uint32
281   getRawPacketSize() const
282 { return total; }
283 
284  inline uint32
285   getRawPacketSizeSrtp() const
286 { return total + srtpLength; }
287 
288  inline size_t
289   getSizeOfFixedHeader() const
290 { return sizeof(RTPFixedHeader); }
291 
303  void reComputePayLength(bool padding);
304 
305 protected:
309   inline virtual ~RTPPacket()
310  { endPacket(); }
311 
315  void
316  endPacket();
317 
323  inline RTPFixedHeader*
324   getHeader() const
325 { return reinterpret_cast<RTPFixedHeader*>(buffer); }
326 
327  inline void
328   setExtension(bool e)
329  { getHeader()->extension = e; }
330 
338  inline const RTPHeaderExt*
339   getHeaderExt() const
340 {
341  uint32 fixsize = sizeof(RTPFixedHeader) + (getHeader()->cc << 2);
342  return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
343  }
344 
350  inline uint32
351   getRawTimestamp() const
352 { return ntohl(getHeader()->timestamp); }
353 
354  inline void
355   setbuffer(const void* src, size_t len, size_t pos)
356  { memcpy(buffer + pos,src,len); }
357 
359   uint16 cachedSeqNum;
361   uint32 cachedTimestamp;
362 
369   uint32 srtpDataOffset;
370 
376   int32 srtpLength;
377 
379   uint32 total;
380 
382   uint32 payloadSize;
383 
384 private:
386   unsigned char* buffer;
388   uint32 hdrSize;
390   bool duplicated;
391 
392 #ifdef CCXX_PACKED
393 #pragma pack(1)
394 #endif
395 
405   struct RTPFixedHeader
406  {
407 #if __BYTE_ORDER == __BIG_ENDIAN
408  unsigned char version:2;
410   unsigned char padding:1;
411   unsigned char extension:1;
412   unsigned char cc:4;
413   unsigned char marker:1;
414   unsigned char payload:7;
415 #else
416  unsigned char cc:4;
418  unsigned char extension:1;
419  unsigned char padding:1;
420  unsigned char version:2;
421  unsigned char payload:7;
422  unsigned char marker:1;
423 #endif
424   uint16 sequence;
425   uint32 timestamp;
426   uint32 sources[1];
427  };
428 
437 public:
438   struct RFC2833Payload
439  {
440 #if __BYTE_ORDER == __BIG_ENDIAN
441   uint8 event : 8;
442   bool ebit : 1;
443   bool rbit : 1;
444   uint8 vol : 6;
445   uint16 duration : 16;
446 #else
447  uint8 event : 8;
448  uint8 vol : 6;
449  bool rbit : 1;
450  bool ebit : 1;
451  uint16 duration : 16;
452 #endif
453  };
454 
455 private:
463   struct RTPHeaderExt
464  {
465   uint16 undefined;
466   uint16 length;
467  };
468 #ifdef CCXX_PACKED
469 #pragma pack()
470 #endif
471 
472  /* definitions for access to most common 2833 fields... */
473 
474 public:
480   inline struct RFC2833Payload *getRaw2833Payload(void)
481  {return (struct RFC2833Payload *)getPayload();}
482 
488   inline uint16 get2833Duration(void)
489  {return ntohs(getRaw2833Payload()->duration);}
490 
496   inline void set2833Duration(uint16 timestamp)
497  {getRaw2833Payload()->duration = htons(timestamp);}
498 };
499 
510  class __EXPORT OutgoingRTPPkt : public RTPPacket
511 {
512 public:
539  OutgoingRTPPkt(const uint32* const csrcs, uint16 numcsrc,
540  const unsigned char* const hdrext, uint32 hdrextlen,
541  const unsigned char* const data, size_t datalen,
542  uint8 paddinglen= 0, CryptoContext* pcc= NULL);
543 
564  OutgoingRTPPkt(const uint32* const csrcs, uint16 numcsrc,
565  const unsigned char* const data, size_t datalen,
566  uint8 paddinglen= 0, CryptoContext* pcc= NULL);
567 
584  OutgoingRTPPkt(const unsigned char* const data, size_t datalen,
585  uint8 paddinglen= 0, CryptoContext* pcc= NULL);
586 
587   ~OutgoingRTPPkt()
588  { }
589 
593  inline void
594   setPayloadType(PayloadType pt)
595  { getHeader()->payload = pt; }
596 
602  inline void
603   setSeqNum(uint16 seq)
604  {
605  cachedSeqNum = seq;
606  getHeader()->sequence = htons(seq);
607  }
608 
612  inline void
613   setTimestamp(uint32 pts)
614  {
615  cachedTimestamp = pts;
616  getHeader()->timestamp = htonl(pts);
617  }
618 
625  inline void
626   setSSRC(uint32 ssrc) const
627 { getHeader()->sources[0] = htonl(ssrc); }
628 
636  inline void
637   setSSRCNetwork(uint32 ssrc) const
638 { getHeader()->sources[0] = ssrc; }
639 
647  inline void
648   setMarker(bool mark)
649  { getHeader()->marker = mark; }
650 
657  void protect(uint32 ssrc, CryptoContext* pcc);
658 
662  inline bool
663   operator==(const OutgoingRTPPkt &p) const
664 { return ( this->getSeqNum() == p.getSeqNum() ); }
665 
669  inline bool
670   operator!=(const OutgoingRTPPkt &p) const
671 { return ( this->getSeqNum() != p.getSeqNum() ); }
672 
673 private:
678  OutgoingRTPPkt(const OutgoingRTPPkt &o);
679 
684  OutgoingRTPPkt&
685  operator=(const OutgoingRTPPkt &o);
686 
691  void setCSRCArray(const uint32* const csrcs, uint16 numcsrc);
692 
693 };
694 
707  class __EXPORT IncomingRTPPkt : public RTPPacket
708 {
709 public:
722  IncomingRTPPkt(const unsigned char* block, size_t len);
723 
724   ~IncomingRTPPkt()
725  { }
726 
732  inline bool
733   isHeaderValid()
734  { return headerValid; }
735 
742  inline uint32
743   getSSRC() const
744 { return cachedSSRC; }
745 
756  int32
757  unprotect(CryptoContext* pcc);
758 
763  inline bool
764   operator==(const IncomingRTPPkt &p) const
765 { return ( (this->getSeqNum() == p.getSeqNum()) &&
766  (this->getSSRC() == p.getSSRC()) ); }
767 
772  inline bool
773   operator!=(const IncomingRTPPkt &p) const
774 { return !( *this == p ); }
775 
776 private:
781  IncomingRTPPkt(const IncomingRTPPkt &ip);
782 
787  IncomingRTPPkt&
788  operator=(const IncomingRTPPkt &ip);
789 
791   bool headerValid;
793   uint32 cachedSSRC;
794  // Masks for RTP header validation: types matching RTCP SR or
795  // RR must be rejected to avoid accepting misaddressed RTCP
796  // packets.
797   static const uint16 RTP_INVALID_PT_MASK;
798   static const uint16 RTP_INVALID_PT_VALUE;
799 };
800  // rtppacket
802 
803 #ifdef CCXX_NAMESPACES
804 }
805 #endif
806 
807 #endif // ndef CCXX_RTP_RTPPKT_H_
808 
RTPPacket::RTPHeaderExt
Fixed component of the variable-length header extension, appended to the fixed header, after the CSRC list, when X == 1.
Definition: rtppkt.h:463
RTPPacket::total
uint32 total
total length, including header, payload and padding
Definition: rtppkt.h:379
RTPPacket::isPadded
bool isPadded() const
Ask whether the packet contains padding bytes at the end.
Definition: rtppkt.h:167
OutgoingRTPPkt::setMarker
void setMarker(bool mark)
Specify the value of the marker bit.
Definition: rtppkt.h:648
RTPPacket::getSizeOfFixedHeader
size_t getSizeOfFixedHeader() const
Definition: rtppkt.h:289
IncomingRTPPkt::~IncomingRTPPkt
~IncomingRTPPkt()
Definition: rtppkt.h:724
RTPPacket
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition: rtppkt.h:75
RTPPacket::RTPHeaderExt::undefined
uint16 undefined
to be defined
Definition: rtppkt.h:465
CryptoContext
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:76
RTPPacket::getPayloadType
PayloadType getPayloadType() const
Definition: rtppkt.h:138
IncomingRTPPkt
RTP packets received from other participants.
Definition: rtppkt.h:707
RTPPacket::getRawTimestamp
uint32 getRawTimestamp() const
Obtain the absolute timestamp carried in the packet header.
Definition: rtppkt.h:351
RTPPacket::getCSRCs
const uint32 * getCSRCs() const
Get the 32-bit identifiers of the contributing sources for the packet as an array, of length getCSRCsCount().
Definition: rtppkt.h:215
OutgoingRTPPkt::~OutgoingRTPPkt
~OutgoingRTPPkt()
Definition: rtppkt.h:587
IncomingRTPPkt::getSSRC
uint32 getSSRC() const
Get synchronization source numeric identifier.
Definition: rtppkt.h:743
OutgoingRTPPkt::setSeqNum
void setSeqNum(uint16 seq)
Sets the sequence number in the header.
Definition: rtppkt.h:603
RTPPacket::buffer
unsigned char * buffer
packet in memory
Definition: rtppkt.h:386
OutgoingRTPPkt::setSSRCNetwork
void setSSRCNetwork(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:637
IncomingRTPPkt::RTP_INVALID_PT_VALUE
static const uint16 RTP_INVALID_PT_VALUE
Definition: rtppkt.h:798
RTPPacket::getTimestamp
uint32 getTimestamp() const
Definition: rtppkt.h:152
RTPPacket::getHdrExtSize
uint32 getHdrExtSize() const
Get the length (in octets) of the data contained in the header extension.
Definition: rtppkt.h:246
RTPPacket::getHeaderExt
const RTPHeaderExt * getHeaderExt() const
Get a pointer to RTPHeaderExt pointing after the RTP header (fixed part plus contributing sources)...
Definition: rtppkt.h:339
IncomingRTPPkt::isHeaderValid
bool isHeaderValid()
Get validity of this packet.
Definition: rtppkt.h:733
RTPPacket::getPayload
const uint8 *const getPayload() const
Definition: rtppkt.h:124
RTPPacket::duplicated
bool duplicated
whether the object was contructed with duplicated = true
Definition: rtppkt.h:390
OutgoingRTPPkt::operator!=
bool operator!=(const OutgoingRTPPkt &p) const
Outgoing packets are not equal if their sequence numbers differ.
Definition: rtppkt.h:670
RTPPacket::getHdrExtContent
const unsigned char * getHdrExtContent() const
Get the content of the header extension.
Definition: rtppkt.h:258
RTPPacket::getHdrExtUndefined
uint16 getHdrExtUndefined() const
Get the first 16 bits (in network order) of the header of the RTP header extension.
Definition: rtppkt.h:231
RTPPacket::srtpDataOffset
uint32 srtpDataOffset
Offset into packet memory pointing to area for SRTP data.
Definition: rtppkt.h:369
RTPPacket::getHeader
RTPFixedHeader * getHeader() const
Return low level structure for the header of the packet.
Definition: rtppkt.h:324
OutgoingRTPPkt::operator==
bool operator==(const OutgoingRTPPkt &p) const
Outgoing packets are equal if their sequence numbers match.
Definition: rtppkt.h:663
RTPPacket::getProtocolVersion
uint8 getProtocolVersion() const
Definition: rtppkt.h:159
OutgoingRTPPkt::setSSRC
void setSSRC(uint32 ssrc) const
Set synchronization source numeric identifier.
Definition: rtppkt.h:626
RTPPacket::cachedTimestamp
uint32 cachedTimestamp
Packet timestamp in host order (includes initial shift).
Definition: rtppkt.h:361
RTPPacket::getSeqNum
uint16 getSeqNum() const
Definition: rtppkt.h:145
RTPPacket::~RTPPacket
virtual ~RTPPacket()
Destructor, free the buffer provided in the constructor.
Definition: rtppkt.h:309
RTPPacket::getRawPacketSize
uint32 getRawPacketSize() const
Get the raw packet length, including header, extension, payload and padding.
Definition: rtppkt.h:281
RTPPacket::isExtended
bool isExtended() const
Ask whether the packet contains header extensions.
Definition: rtppkt.h:196
IncomingRTPPkt::operator==
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:764
RTPPacket::RTPHeaderExt::length
uint16 length
number of 32-bit words in the extension
Definition: rtppkt.h:466
IncomingRTPPkt::RTP_INVALID_PT_MASK
static const uint16 RTP_INVALID_PT_MASK
Definition: rtppkt.h:797
RTPPacket::set2833Duration
void set2833Duration(uint16 timestamp)
Set 2833 duration field.
Definition: rtppkt.h:496
RTPPacket::getRawPacket
const unsigned char *const getRawPacket() const
Get the raw packet as it will be sent through the network.
Definition: rtppkt.h:271
RTPPacket::get2833Duration
uint16 get2833Duration(void)
Fetch 2833 duration field.
Definition: rtppkt.h:488
IncomingRTPPkt::cachedSSRC
uint32 cachedSSRC
SSRC 32-bit identifier in host order.
Definition: rtppkt.h:793
RTPPacket::getPaddingSize
uint8 getPaddingSize() const
Get the number of octets padding the end of the payload section.
Definition: rtppkt.h:177
RTPPacket::getRaw2833Payload
struct RFC2833Payload * getRaw2833Payload(void)
Fetch a raw 2833 packet.
Definition: rtppkt.h:480
__EXPORT
#define __EXPORT
Definition: audio2.h:51
RTPPacket::getPayloadSize
uint32 getPayloadSize() const
Definition: rtppkt.h:131
RTPPacket::RTPFixedHeader
RTP fixed header as it is send through the network.
Definition: rtppkt.h:405
IncomingRTPPkt::headerValid
bool headerValid
Header validity, checked at construction time.
Definition: rtppkt.h:791
base.h
Base elements for RTP stacks: constants, types and global functions.
RTPPacket::getCSRCsCount
uint16 getCSRCsCount() const
Get the number of contributing sources specified in the packet header.
Definition: rtppkt.h:204
OutgoingRTPPkt::setTimestamp
void setTimestamp(uint32 pts)
Definition: rtppkt.h:613
OutgoingRTPPkt::setPayloadType
void setPayloadType(PayloadType pt)
Definition: rtppkt.h:594
RTPPacket::setbuffer
void setbuffer(const void *src, size_t len, size_t pos)
Definition: rtppkt.h:355
RTPPacket::isMarked
bool isMarked() const
Ask whether the packet is marked (for isntance, is a new talk spurt in some audio profiles)...
Definition: rtppkt.h:187
RTPPacket::RTPFixedHeader::sequence
uint16 sequence
sequence number
Definition: rtppkt.h:424
IncomingRTPPkt::operator!=
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:773
RTPPacket::getRawPacketSizeSrtp
uint32 getRawPacketSizeSrtp() const
Definition: rtppkt.h:285
RTPPacket::RFC2833Payload
a structure defining RFC2833 Telephony events.
Definition: rtppkt.h:438
RTPPacket::setExtension
void setExtension(bool e)
Definition: rtppkt.h:328
formats.h
Payload types and formats.
RTPPacket::hdrSize
uint32 hdrSize
size of the header, including contributing sources and extensions
Definition: rtppkt.h:388
RTPPacket::srtpLength
int32 srtpLength
Lebgth of additional SRTP data.
Definition: rtppkt.h:376
RTPPacket::cachedSeqNum
uint16 cachedSeqNum
Packet sequence number in host order.
Definition: rtppkt.h:359
RTPPacket::getHeaderSize
uint32 getHeaderSize() const
Get the length of the header, including contributing sources identifiers and header extension...
Definition: rtppkt.h:117
OutgoingRTPPkt
RTP packets being sent.
Definition: rtppkt.h:510
RTPPacket::payloadSize
uint32 payloadSize
note: payload (not full packet) size.
Definition: rtppkt.h:382
RTPPacket::RTPFixedHeader::timestamp
uint32 timestamp
timestamp
Definition: rtppkt.h:425
PayloadType
uint8 PayloadType
RTP payload type numeric identifier.
Definition: formats.h:65

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /