sipxmedialib  Version 3.3
MpRtpBuf.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2012 SIPez LLC. All rights reserved.
3 //
4 //
5 // $$
7 
8 #ifndef _INCLUDED_MPRTPBUF_H /* [ */
9 #define _INCLUDED_MPRTPBUF_H
10 
11 // SYSTEM INCLUDES
12 #ifdef __pingtel_on_posix__ // [
13 # include <netinet/in.h>
14 #endif // __pigntel_on_posix__ ]
15 
16 #ifdef WIN32
17 # include <winsock2.h>
18 #endif
19 
20 // APPLICATION INCLUDES
21 #include <sdp/SdpCodec.h>
22 #include <mp/MpUdpBuf.h>
23 //#include <mp/MpTypes.h>
24 #include <mp/RtpHeader.h>
25 #include <mp/MpMisc.h>
26 
27 // MACROS
28 // EXTERNAL FUNCTIONS
29 // EXTERNAL VARIABLES
30 // CONSTANTS
31 // STRUCTS
32 // TYPEDEFS
33 // DEFINES
34 
36 
40 struct MpRtpBuf : public MpUdpBuf
41 {
42  friend class MpRtpBufPtr;
43 
44 /* //////////////////////////// PUBLIC //////////////////////////////////// */
45 public:
46 
49 
50 /* ============================ CREATORS ================================== */
52 
53 
54 
56 
57 /* ============================ MANIPULATORS ============================== */
59 
60 
62 
65  bool setPayloadSize(int payloadSize)
66  {
67  if(!mpData.isValid())
68  {
70  }
71  return mpData->setDataSize(payloadSize);
72  }
73 
75 
78  void setRtpVersion(uint8_t version)
79  { mRtpHeader.vpxcc = ( (version<<RTP_V_SHIFT)&RTP_V_MASK)
80  | (mRtpHeader.vpxcc&(~RTP_V_MASK));}
81 
83 
87  { mRtpHeader.vpxcc |= 1<<RTP_P_SHIFT;}
88 
90 
95 
97 
101  { mRtpHeader.vpxcc |= 1<<RTP_X_SHIFT;}
102 
104 
108  { mRtpHeader.vpxcc &= ~RTP_X_MASK;}
109 
111 
114  void setRtpCSRCCount(uint8_t csrcCount)
115  { mRtpHeader.vpxcc = ( (csrcCount<<RTP_CC_SHIFT)&RTP_CC_MASK)
116  | (mRtpHeader.vpxcc&(~RTP_CC_MASK));}
117 
119 
123  { mRtpHeader.mpt |= 1<<RTP_M_SHIFT;}
124 
125 
127 
131  { mRtpHeader.mpt &= ~RTP_M_MASK;}
132 
134 
137  void setRtpPayloadType(uint8_t type)
138  { mRtpHeader.mpt = ( (type<<RTP_PT_SHIFT)&RTP_PT_MASK)
139  | (mRtpHeader.mpt&(~RTP_PT_MASK));}
140 
142 
145  void setRtpSequenceNumber(RtpSeq sequenceNumber)
146  { mRtpHeader.seq = htons(sequenceNumber);}
147 
149 
153  { mRtpHeader.timestamp = htonl(timestamp);}
154 
156 
160  { mRtpHeader.ssrc = htonl(ssrc);}
161 
163 
164 /* ============================ ACCESSORS ================================= */
166 
167 
169  unsigned getPayloadSize() const {return mpData->getDataSize();}
170 
173 
175  const RtpHeader &getRtpHeader() const {return mRtpHeader;}
176 
179 
181  const RtpSRC *getRtpCSRCs() const {return mRtpCSRCs;}
182 
184 
191  uint8_t getRtpVersion() const
192  {return (mRtpHeader.vpxcc&RTP_V_MASK) >> RTP_V_SHIFT;}
193 
195 
200  uint8_t getRtpCSRCCount() const {return mRtpHeader.vpxcc & RTP_CC_MASK;}
201 
203 
217  uint8_t getRtpPayloadType() const
218  {return (mRtpHeader.mpt&RTP_PT_MASK) >> RTP_PT_SHIFT;}
219 
221  SdpCodec::SdpCodecTypes getCodecId() const { return(mInternalCodecId); };
222  /*
223  * Note this must be set by the RTP Input connection as the bufer maintains no
224  * codec mapping capablity.
225  */
226 
228  void setCodecId(SdpCodec::SdpCodecTypes codecId) { mInternalCodecId = codecId; };
229 
231 
241  RtpSeq getRtpSequenceNumber() const {return ntohs(mRtpHeader.seq);}
242 
244 
255 
257 
267  RtpSRC getRtpSSRC() const {return ntohl(mRtpHeader.ssrc);}
268 
270 
271 /* ============================ INQUIRY =================================== */
273 
274 
276 
286  bool isRtpPadding() const
287  {return (mRtpHeader.vpxcc&RTP_P_MASK) == (1<<RTP_P_SHIFT);}
288 
290 
295  bool isRtpExtension() const
296  {return (mRtpHeader.vpxcc&RTP_X_MASK) == (1<<RTP_X_SHIFT);}
297 
299 
307  bool isRtpMarker() const
308  {return (mRtpHeader.mpt&RTP_M_MASK) == (1<<RTP_M_SHIFT);}
309 
311 
312 /* //////////////////////////// PROTECTED ///////////////////////////////// */
313 protected:
314 
316 
319  SdpCodec::SdpCodecTypes mInternalCodecId;
320 
322 
324  void init();
325 
326 /* //////////////////////////// PRIVATE /////////////////////////////////// */
327 private:
328 
330  MpRtpBuf(const MpBuf &);
335  MpRtpBuf &operator=(const MpBuf &);
340 };
341 
343 
348 class MpRtpBufPtr : public MpUdpBufPtr {
349 
350 /* //////////////////////////// PUBLIC //////////////////////////////////// */
351 public:
352 
353 /* ============================ CREATORS ================================== */
355 
356 
359 
360 
362 
363 
365 
366 
367 
368 /* ============================ MANIPULATORS ============================== */
370 
371 
372 
373 
374 
375 /* ============================ ACCESSORS ================================= */
377 
378 
381 
382 
384 
385 
386 
387 /* ============================ INQUIRY =================================== */
389 
390 
391 
392 
393 
394 /* //////////////////////////// PROTECTED ///////////////////////////////// */
395 protected:
396 
397 
398 /* //////////////////////////// PRIVATE /////////////////////////////////// */
399 private:
400 
401 };
402 
403 #endif /* ] _INCLUDED_MPRTPBUF_H */
#define RTP_CC_MASK
Mask for CCSRC bits in RtpHeader::vpxcc.
Definition: RtpHeader.h:32
RtpSRC ssrc
SSRC (Big Endian!)
Definition: RtpHeader.h:48
#define MPBUF_TYPECHECKED_COPY(classname, buffer_type, base_classname)
Copy object from base type with type check.
Definition: MpBuf.h:407
#define RTP_CC_SHIFT
Shift for CCSRC bits in RtpHeader::vpxcc.
Definition: RtpHeader.h:33
RtpSeq getRtpSequenceNumber() const
Get Sequence Number of this packet.
Definition: MpRtpBuf.h:241
SdpCodec::SdpCodecTypes getCodecId() const
Get the internal codec ID for this RTP packet&#39;s payload.
Definition: MpRtpBuf.h:221
Buffer for raw UDP packet.
Definition: MpUdpBuf.h:37
SdpCodec::SdpCodecTypes mInternalCodecId
Internal codec ID for this packets payload ID.
Definition: MpRtpBuf.h:319
static MpBufPool * smpDefaultPool
Default pool for MpDataBuf objects.
Definition: MpRtpBuf.h:48
MpRtpBuf(const MpBuf &)
Disable copy (and other) constructor.
RtpSRC mRtpCSRCs[RTP_MAX_CSRCS]
CSRCs list of RTP packet.
Definition: MpRtpBuf.h:321
MpArrayBufPtr mpData
Payload data.
Definition: MpDataBuf.h:93
#define MPBUFDATA_FROM_BASE_CONSTRUCTOR(classname, buffer_type, base_classname)
This constructor owns MpBuf object.
Definition: MpDataBuf.h:18
unsigned getPayloadSize() const
Get current size of payload data.
Definition: MpRtpBuf.h:169
#define RTP_PT_SHIFT
Shift for Payload Type bits in RtpHeader::mpt.
Definition: RtpHeader.h:38
MpRtpBuf & operator=(const MpBuf &)
Disable assignment operator.
void setCodecId(SdpCodec::SdpCodecTypes codecId)
Set the internal codec ID for this packet&#39;s payload.
Definition: MpRtpBuf.h:228
void disableRtpExtension()
Clear extension bit in RTP header.
Definition: MpRtpBuf.h:107
Smart pointer to MpRtpBuf.
Definition: MpRtpBuf.h:348
RtpSRC * getRtpCSRCs()
Get direct access to RtpHeader structure.
Definition: MpRtpBuf.h:178
RtpHeader mRtpHeader
Definition: MpRtpBuf.h:315
#define RTP_V_MASK
Mask for Version bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:26
uint8_t getRtpVersion() const
Get RTP version of this packet. Should be equal to 2.
Definition: MpRtpBuf.h:191
#define RTP_PT_MASK
Mask for Payload Type bits in RtpHeader::mpt.
Definition: RtpHeader.h:37
void init()
This is called in place of constructor.
Definition: MpRtpBuf.cpp:35
#define RTP_MAX_CSRCS
Maximum number of CSRCs in RTP packet.
Definition: RtpHeader.h:40
struct __MpGlobals MpMisc
Definition: MpMisc.cpp:101
#define RTP_M_SHIFT
Shift for Marker bit in RtpHeader::mpt.
Definition: RtpHeader.h:36
#define RTP_X_SHIFT
Shift for Extension bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:31
int profileFlowgraphPoolUsage()
Syslog a histigram of buffers used by flowgraph.
Definition: MpBufPool.cpp:253
uint32_t RtpTimestamp
RTP timestamp.
Definition: MpTypes.h:60
Smart pointer to MpUdpBuf.
Definition: MpUdpBuf.h:142
Buffer for RTP packet data.
Definition: MpRtpBuf.h:40
#define RTP_P_MASK
Mask for Padding bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:28
void enableRtpMarker()
Set marker bit in RTP header.
Definition: MpRtpBuf.h:122
uint16_t RtpSeq
RTP sequence number.
Definition: MpTypes.h:59
#define MPBUF_MEMBER_ACCESS_OPERATOR(classname)
Return pointer to buffer.
Definition: MpBuf.h:417
void enableRtpPadding()
Set padding bit in RTP header.
Definition: MpRtpBuf.h:86
interface rtpts_t rtpts_t ssrc_t ssrc
Definition: ISetSenderStatistics.h:68
#define MPBUF_CONST_MEMBER_ACCESS_OPERATOR(classname)
Return readonly pointer to buffer.
Definition: MpBuf.h:422
RTP header as described in RFC 3550.
Definition: RtpHeader.h:43
void setRtpTimestamp(RtpTimestamp timestamp)
Set Timestamp of this packet.
Definition: MpRtpBuf.h:152
#define RTP_X_MASK
Mask for Extension bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:30
void setRtpSSRC(RtpSRC ssrc)
Set SSRC of this packet.
Definition: MpRtpBuf.h:159
#define RTP_V_SHIFT
Shift for Version bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:27
uint8_t getRtpPayloadType() const
Get Payload Type of this packet.
Definition: MpRtpBuf.h:217
uint8_t getRtpCSRCCount() const
Get CSRC Count for this packet.
Definition: MpRtpBuf.h:200
bool isRtpMarker() const
Check marker bit in RTP header.
Definition: MpRtpBuf.h:307
void setRtpVersion(uint8_t version)
Set RTP version of this packet.
Definition: MpRtpBuf.h:78
uint8_t vpxcc
Version, Padding, Extension and CSRC Count bits.
Definition: RtpHeader.h:44
void disableRtpMarker()
Clear marker bit in RTP header.
Definition: MpRtpBuf.h:130
void disableRtpPadding()
Clear padding bit in RTP header.
Definition: MpRtpBuf.h:93
bool isRtpExtension() const
Check extension bit in RTP header.
Definition: MpRtpBuf.h:295
bool isRtpPadding() const
Check padding bit in RTP header.
Definition: MpRtpBuf.h:286
void setRtpSequenceNumber(RtpSeq sequenceNumber)
Set Sequence Number of this packet.
Definition: MpRtpBuf.h:145
void setRtpPayloadType(uint8_t type)
Set Payload Type of this packet.
Definition: MpRtpBuf.h:137
uint32_t RtpSRC
RTP SSRC or CSRC identifier.
Definition: MpTypes.h:61
const RtpHeader & getRtpHeader() const
Get read-only direct access to RtpHeader structure.
Definition: MpRtpBuf.h:175
uint8_t mpt
Marker and Payload Type bits.
Definition: RtpHeader.h:45
#define RTP_M_MASK
Mask for Marker bit in RtpHeader::mpt.
Definition: RtpHeader.h:35
RtpSeq seq
Sequence Number (Big Endian!)
Definition: RtpHeader.h:46
Base class for all media buffers.
Definition: MpBuf.h:74
bool isValid() const
Can this pointer be dereferenced? Use this function instead of NULL comparison.
Definition: MpBuf.h:365
#define RTP_P_SHIFT
Shift for Padding bit in RtpHeader::vpxcc.
Definition: RtpHeader.h:29
void enableRtpExtension()
Set extension bit in RTP header.
Definition: MpRtpBuf.h:100
MpBufPool * RtpPool
Memory pool for RTP data buffers.
Definition: MpMisc.h:70
RtpTimestamp getRtpTimestamp() const
Get Timestamp of this packet.
Definition: MpRtpBuf.h:254
bool setPayloadSize(int payloadSize)
Set number of bytes in payload data.
Definition: MpRtpBuf.h:65
#define MPBUF_DEFAULT_CONSTRUCTOR(classname)
Default constructor - construct invalid pointer.
Definition: MpBuf.h:387
RtpSRC getRtpSSRC() const
Get SSRC of this packet.
Definition: MpRtpBuf.h:267
Pool of buffers.
Definition: MpBufPool.h:32
Begin of the MpRtpBuf type.
Definition: MpBuf.h:55
const RtpSRC * getRtpCSRCs() const
Get read-only direct access to RtpHeader structure.
Definition: MpRtpBuf.h:181
RtpHeader & getRtpHeader()
Get direct access to RtpHeader structure.
Definition: MpRtpBuf.h:172
RtpTimestamp timestamp
Timestamp (Big Endian!)
Definition: RtpHeader.h:47
void setRtpCSRCCount(uint8_t csrcCount)
Set CSRC Count for this packet.
Definition: MpRtpBuf.h:114