1 // Copyright (C) 2002-2015 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 Lesser General Public License
14 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP. If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36
37 #ifndef CCXX_RTP_RTPPKT_H_
38 #define CCXX_RTP_RTPPKT_H_
39
43
44 NAMESPACE_COMMONCPP
45
71
73 {
74 private:
77
78 public:
91 RTPPacket(
const unsigned char*
const block,
size_t len,
92 bool duplicate = false);
93
106
113 inline uint32
115 { return hdrSize; }
116
120 inline const uint8* const
122 { return (uint8*)(buffer + getHeaderSize()); }
123
127 inline uint32
129 { return payloadSize; }
130
136 {
return static_cast<PayloadType >(getHeader()->payload); }
137
141 inline uint16
143 { return cachedSeqNum; }
144
148 inline uint32
150 { return cachedTimestamp; }
151
155 inline uint8
157 { return getHeader()->version; }
158
163 inline bool
165 { return getHeader()->padding; }
166
173 inline uint8
175 { return buffer[total - 1]; }
176
183 inline bool
185 { return getHeader()->marker; }
186
192 inline bool
194 { return getHeader()->extension; }
195
200 inline uint16
202 { return getHeader()->cc; }
203
211 inline const uint32*
213 { return static_cast<const uint32*>(&(getHeader()->sources[1])); }
214
227 inline uint16
229 { return (isExtended()? getHeaderExt()->undefined : 0); }
230
242 inline uint32
244 { return (isExtended()?
245 (static_cast<uint32>(ntohs(getHeaderExt()->length)) << 2) :
246 0); }
247
254 inline const unsigned char*
256 { return (isExtended() ?
257 (reinterpret_cast<const unsigned char*>(getHeaderExt()) +
259 NULL); }
260
267 inline const unsigned char* const
269 { return buffer; }
270
277 inline uint32
279 { return total; }
280
281 inline uint32
283 { return total + srtpLength; }
284
285 inline size_t
288
300 void reComputePayLength(bool padding);
301
302 protected:
307 { endPacket(); }
308
312 void
313 endPacket();
314
320 inline RTPFixedHeader*
323
324 inline void
326 { getHeader()->extension = e; }
327
335 inline const RTPHeaderExt*
337 {
339 return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
340 }
341
347 inline uint32
349 { return ntohl(getHeader()->timestamp); }
350
351 inline void
353 { memcpy(buffer + pos,src,len); }
354
359
367
374
377
380
381 private:
388
389 #ifdef CCXX_PACKED
390 #pragma pack(1)
391 #endif
392
403 {
404 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
405 unsigned char version:2;
407 unsigned char padding:1;
408 unsigned char extension:1;
409 unsigned char cc:4;
410 unsigned char marker:1;
411 unsigned char payload:7;
412 #else
413 unsigned char cc:4;
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;
420 #endif
424 };
425
434 public:
436 {
437 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
438 uint8 event : 8;
439 bool ebit : 1;
440 bool rbit : 1;
441 uint8 vol : 6;
442 uint16 duration : 16;
443 #else
448 uint16 duration : 16;
449 #endif
450 };
451
452 private:
461 {
464 };
465 #ifdef CCXX_PACKED
466 #pragma pack()
467 #endif
468
469 /* definitions for access to most common 2833 fields... */
470
471 public:
479
486 {return ntohs(getRaw2833Payload()->duration);}
487
494 {getRaw2833Payload()->duration = htons(timestamp);}
495 };
496
508 {
509 public:
537 const unsigned char* const hdrext, uint32 hdrextlen,
538 const unsigned char* const data, size_t datalen,
540
562 const unsigned char* const data, size_t datalen,
564
583
585 { }
586
590 inline void
593
599 inline void
601 {
602 cachedSeqNum = seq;
604 }
605
609 inline void
611 {
612 cachedTimestamp = pts;
614 }
615
622 inline void
625
633 inline void
636
644 inline void
647
655
659 inline bool
662
666 inline bool
669
670 private:
676
683
688 void setCSRCArray(const uint32* const csrcs, uint16 numcsrc);
689
690 };
691
705 {
706 public:
720
722 { }
723
729 inline bool
731 { return headerValid; }
732
739 inline uint32
741 { return cachedSSRC; }
742
753 int32
755
760 inline bool
763 (this->getSSRC() == p.
getSSRC()) ); }
764
769 inline bool
771 { return !( *this == p ); }
772
773 private:
779
786
791 // Masks for RTP header validation: types matching RTCP SR or
792 // RR must be rejected to avoid accepting misaddressed RTCP
793 // packets.
796 };
797 // rtppacket
799
800 END_NAMESPACE
801
802 #endif // ndef CCXX_RTP_RTPPKT_H_
803
uint32 total
total length, including header, payload and padding
bool isPadded() const
Ask whether the packet contains padding bytes at the end.
void setMarker(bool mark)
Specify the value of the marker bit.
size_t getSizeOfFixedHeader() const
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
The implementation for a SRTP cryptographic context.
PayloadType getPayloadType() const
RTP packets received from other participants.
uint32 getRawTimestamp() const
Obtain the absolute timestamp carried in the packet header.
const uint32 * getCSRCs() const
Get the 32-bit identifiers of the contributing sources for the packet as an array, of length getCSRCsCount().
uint32 getSSRC() const
Get synchronization source numeric identifier.
void setSeqNum(uint16 seq)
Sets the sequence number in the header.
unsigned char * buffer
packet in memory
void setSSRCNetwork(uint32 ssrc) const
Set synchronization source numeric identifier.
static const uint16 RTP_INVALID_PT_VALUE
uint32 getTimestamp() const
uint32 getHdrExtSize() const
Get the length (in octets) of the data contained in the header extension.
const RTPHeaderExt * getHeaderExt() const
Get a pointer to RTPHeaderExt pointing after the RTP header (fixed part plus contributing sources)...
bool isHeaderValid()
Get validity of this packet.
const uint8 *const getPayload() const
bool duplicated
whether the object was contructed with duplicated = true
bool operator!=(const OutgoingRTPPkt &p) const
Outgoing packets are not equal if their sequence numbers differ.
const unsigned char * getHdrExtContent() const
Get the content of the header extension.
uint16 getHdrExtUndefined() const
Get the first 16 bits (in network order) of the header of the RTP header extension.
uint32 srtpDataOffset
Offset into packet memory pointing to area for SRTP data.
RTPFixedHeader * getHeader() const
Return low level structure for the header of the packet.
bool operator==(const OutgoingRTPPkt &p) const
Outgoing packets are equal if their sequence numbers match.
uint8 getProtocolVersion() const
void setSSRC(uint32 ssrc) const
Set synchronization source numeric identifier.
uint32 cachedTimestamp
Packet timestamp in host order (includes initial shift).
virtual ~RTPPacket()
Destructor, free the buffer provided in the constructor.
uint32 getRawPacketSize() const
Get the raw packet length, including header, extension, payload and padding.
bool isExtended() const
Ask whether the packet contains header extensions.
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...
static const uint16 RTP_INVALID_PT_MASK
void set2833Duration(uint16 timestamp)
Set 2833 duration field.
const unsigned char *const getRawPacket() const
Get the raw packet as it will be sent through the network.
uint16 get2833Duration(void)
Fetch 2833 duration field.
uint32 cachedSSRC
SSRC 32-bit identifier in host order.
uint8 getPaddingSize() const
Get the number of octets padding the end of the payload section.
struct RFC2833Payload * getRaw2833Payload(void)
Fetch a raw 2833 packet.
uint32 getPayloadSize() const
bool headerValid
Header validity, checked at construction time.
Base elements for RTP stacks: constants, types and global functions.
uint16 getCSRCsCount() const
Get the number of contributing sources specified in the packet header.
void setTimestamp(uint32 pts)
void setPayloadType(PayloadType pt)
void setbuffer(const void *src, size_t len, size_t pos)
bool isMarked() const
Ask whether the packet is marked (for isntance, is a new talk spurt in some audio profiles)...
bool operator!=(const IncomingRTPPkt &p) const
Two incoming packets are not equal if they come from different sources or have different sequence num...
uint32 getRawPacketSizeSrtp() const
a structure defining RFC2833 Telephony events.
void setExtension(bool e)
uint32 hdrSize
size of the header, including contributing sources and extensions
int32 srtpLength
Lebgth of additional SRTP data.
uint16 cachedSeqNum
Packet sequence number in host order.
uint32 getHeaderSize() const
Get the length of the header, including contributing sources identifiers and header extension...
uint32 payloadSize
note: payload (not full packet) size.
uint8 PayloadType
RTP payload type numeric identifier.