SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
qrtplib::RTPPacket Class Reference

#include <rtppacket.h>

+ Collaboration diagram for qrtplib::RTPPacket:

Public Member Functions

 RTPPacket (RTPRawPacket &rawpack)
 
 RTPPacket (uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, unsigned int maxpacksize)
 
 RTPPacket (uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, unsigned int buffersize)
 
virtual ~RTPPacket ()
 
int GetCreationError () const
 
bool HasExtension () const
 
bool HasMarker () const
 
int GetCSRCCount () const
 
uint32_t GetCSRC (int num) const
 
uint8_t GetPayloadType () const
 
uint32_t GetExtendedSequenceNumber () const
 
uint16_t GetSequenceNumber () const
 
void SetExtendedSequenceNumber (uint32_t seq)
 
uint32_t GetTimestamp () const
 
uint32_t GetSSRC () const
 
uint8_tGetPacketData () const
 
uint8_tGetPayloadData () const
 
unsigned int GetPacketLength () const
 
unsigned int GetPayloadLength () const
 
uint16_t GetExtensionID () const
 
uint8_tGetExtensionData () const
 
unsigned int GetExtensionLength () const
 
RTPTime GetReceiveTime () const
 

Private Member Functions

void Clear ()
 
int ParseRawPacket (RTPRawPacket &rawpack)
 
int BuildPacket (uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, unsigned int maxsize)
 

Private Attributes

RTPEndian m_endian
 
int error
 
bool hasextension
 
bool hasmarker
 
int numcsrcs
 
uint8_t payloadtype
 
uint32_t extseqnr
 
uint32_t timestamp
 
uint32_t ssrc
 
uint8_tpacket
 
uint8_tpayload
 
unsigned int packetlength
 
unsigned int payloadlength
 
uint16_t extid
 
uint8_textension
 
unsigned int extensionlength
 
bool externalbuffer
 
RTPTime receivetime
 

Detailed Description

Represents an RTP Packet. The RTPPacket class can be used to parse a RTPRawPacket instance if it represents RTP data. The class can also be used to create a new RTP packet according to the parameters specified by the user.

Definition at line 56 of file rtppacket.h.

Constructor & Destructor Documentation

◆ RTPPacket() [1/3]

qrtplib::RTPPacket::RTPPacket ( RTPRawPacket rawpack)

Creates an RTPPacket instance based upon the data in rawpack, optionally installing a memory manager. Creates an RTPPacket instance based upon the data in rawpack, optionally installing a memory manager. If successful, the data is moved from the raw packet to the RTPPacket instance.

Definition at line 63 of file rtppacket.cpp.

References Clear(), error, and ParseRawPacket().

63  :
64  receivetime(rawpack.GetReceiveTime())
65 {
66  Clear();
67  error = ParseRawPacket(rawpack);
68 }
int ParseRawPacket(RTPRawPacket &rawpack)
Definition: rtppacket.cpp:148
RTPTime receivetime
Definition: rtppacket.h:252
+ Here is the call graph for this function:

◆ RTPPacket() [2/3]

qrtplib::RTPPacket::RTPPacket ( uint8_t  payloadtype,
const void *  payloaddata,
unsigned int  payloadlen,
uint16_t  seqnr,
uint32_t  timestamp,
uint32_t  ssrc,
bool  gotmarker,
uint8_t  numcsrcs,
const uint32_t csrcs,
bool  gotextension,
uint16_t  extensionid,
uint16_t  extensionlen_numwords,
const void *  extensiondata,
unsigned int  maxpacksize 
)

Creates a new buffer for an RTP packet and fills in the fields according to the specified parameters. Creates a new buffer for an RTP packet and fills in the fields according to the specified parameters. If maxpacksize is not equal to zero, an error is generated if the total packet size would exceed maxpacksize. The arguments of the constructor are self-explanatory. Note that the size of a header extension is specified in a number of 32-bit words. A memory manager can be installed.

Definition at line 70 of file rtppacket.cpp.

References BuildPacket(), Clear(), and error.

84  :
85  receivetime(0, 0)
86 {
87  Clear();
90  payloaddata,
91  payloadlen,
92  seqnr,
93  timestamp,
94  ssrc,
95  gotmarker,
96  numcsrcs,
97  csrcs,
98  gotextension,
99  extensionid,
100  extensionlen_numwords,
101  extensiondata,
102  0,
103  maxpacksize);
104 }
uint32_t timestamp
Definition: rtppacket.h:242
int BuildPacket(uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, unsigned int maxsize)
Definition: rtppacket.cpp:264
uint8_t payloadtype
Definition: rtppacket.h:241
RTPTime receivetime
Definition: rtppacket.h:252
+ Here is the call graph for this function:

◆ RTPPacket() [3/3]

qrtplib::RTPPacket::RTPPacket ( uint8_t  payloadtype,
const void *  payloaddata,
unsigned int  payloadlen,
uint16_t  seqnr,
uint32_t  timestamp,
uint32_t  ssrc,
bool  gotmarker,
uint8_t  numcsrcs,
const uint32_t csrcs,
bool  gotextension,
uint16_t  extensionid,
uint16_t  extensionlen_numwords,
const void *  extensiondata,
void *  buffer,
unsigned int  buffersize 
)

This constructor is similar to the other constructor, but here data is stored in an external buffer buffer with size buffersize.

Definition at line 106 of file rtppacket.cpp.

References BuildPacket(), Clear(), ERR_RTP_PACKET_EXTERNALBUFFERNULL, ERR_RTP_PACKET_ILLEGALBUFFERSIZE, and error.

121  :
122  receivetime(0, 0)
123 {
124  Clear();
125  if (buffer == 0)
127  else if (buffersize <= 0)
129  else
130  error = BuildPacket(
131  payloadtype,
132  payloaddata,
133  payloadlen,
134  seqnr,
135  timestamp,
136  ssrc,
137  gotmarker,
138  numcsrcs,
139  csrcs,
140  gotextension,
141  extensionid,
142  extensionlen_numwords,
143  extensiondata,
144  buffer,
145  buffersize);
146 }
#define ERR_RTP_PACKET_ILLEGALBUFFERSIZE
Definition: rtperrors.h:76
uint32_t timestamp
Definition: rtppacket.h:242
int BuildPacket(uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, unsigned int maxsize)
Definition: rtppacket.cpp:264
#define ERR_RTP_PACKET_EXTERNALBUFFERNULL
Definition: rtperrors.h:75
uint8_t payloadtype
Definition: rtppacket.h:241
RTPTime receivetime
Definition: rtppacket.h:252
+ Here is the call graph for this function:

◆ ~RTPPacket()

virtual qrtplib::RTPPacket::~RTPPacket ( )
inlinevirtual

Definition at line 104 of file rtppacket.h.

References externalbuffer, and packet.

105  {
106  if (packet && !externalbuffer)
107  delete[] packet;
108  }
uint8_t * packet
Definition: rtppacket.h:243

Member Function Documentation

◆ BuildPacket()

int qrtplib::RTPPacket::BuildPacket ( uint8_t  payloadtype,
const void *  payloaddata,
unsigned int  payloadlen,
uint16_t  seqnr,
uint32_t  timestamp,
uint32_t  ssrc,
bool  gotmarker,
uint8_t  numcsrcs,
const uint32_t csrcs,
bool  gotextension,
uint16_t  extensionid,
uint16_t  extensionlen_numwords,
const void *  extensiondata,
void *  buffer,
unsigned int  maxsize 
)
private

Definition at line 264 of file rtppacket.cpp.

References qrtplib::RTPHeader::csrccount, ERR_RTP_PACKET_BADPAYLOADTYPE, ERR_RTP_PACKET_DATAEXCEEDSMAXSIZE, ERR_RTP_PACKET_TOOMANYCSRCS, qrtplib::RTPHeader::extension, extensionlength, externalbuffer, qrtplib::RTPExtensionHeader::extid, extid, extseqnr, hasextension, hasmarker, i, qrtplib::RTPExtensionHeader::length, qrtplib::RTPHeader::marker, numcsrcs, packet, packetlength, qrtplib::RTPHeader::padding, payload, payloadlength, qrtplib::RTPHeader::payloadtype, payloadtype, RTP_MAXCSRCS, RTP_VERSION, qrtplib::RTPHeader::sequencenumber, qrtplib::RTPHeader::ssrc, ssrc, qrtplib::RTPHeader::timestamp, timestamp, and qrtplib::RTPHeader::version.

Referenced by GetReceiveTime(), and RTPPacket().

280 {
281  if (numcsrcs > RTP_MAXCSRCS)
283 
284  if (payloadtype > 127) // high bit should not be used
286  if (payloadtype == 72 || payloadtype == 73) // could cause confusion with rtcp types
288 
289  packetlength = sizeof(RTPHeader);
290  packetlength += sizeof(uint32_t) * ((unsigned int) numcsrcs);
291  if (gotextension)
292  {
293  packetlength += sizeof(RTPExtensionHeader);
294  packetlength += sizeof(uint32_t) * ((unsigned int) extensionlen_numwords);
295  }
296  packetlength += payloadlen;
297 
298  if (maxsize > 0 && packetlength > maxsize)
299  {
300  packetlength = 0;
302  }
303 
304  // Ok, now we'll just fill in...
305 
306  RTPHeader *rtphdr;
307 
308  if (buffer == 0)
309  {
310  packet = new uint8_t[packetlength];
311  externalbuffer = false;
312  }
313  else
314  {
315  packet = (uint8_t *) buffer;
316  externalbuffer = true;
317  }
318 
319  RTPPacket::hasmarker = gotmarker;
320  RTPPacket::hasextension = gotextension;
323  RTPPacket::extseqnr = (uint32_t) seqnr;
326  RTPPacket::payloadlength = payloadlen;
327  RTPPacket::extid = extensionid;
328  RTPPacket::extensionlength = ((unsigned int) extensionlen_numwords) * sizeof(uint32_t);
329 
330  rtphdr = (RTPHeader *) packet;
331  rtphdr->version = RTP_VERSION;
332  rtphdr->padding = 0;
333  if (gotmarker)
334  rtphdr->marker = 1;
335  else
336  rtphdr->marker = 0;
337  if (gotextension)
338  rtphdr->extension = 1;
339  else
340  rtphdr->extension = 0;
341  rtphdr->csrccount = numcsrcs;
342  rtphdr->payloadtype = payloadtype & 127; // make sure high bit isn't set
343  rtphdr->sequencenumber = qToBigEndian(seqnr);
344  rtphdr->timestamp = qToBigEndian(timestamp);
345  rtphdr->ssrc = qToBigEndian(ssrc);
346 
347  uint32_t *curcsrc;
348  int i;
349 
350  curcsrc = (uint32_t *) (packet + sizeof(RTPHeader));
351  for (i = 0; i < numcsrcs; i++, curcsrc++)
352  *curcsrc = qToBigEndian(csrcs[i]);
353 
354  payload = packet + sizeof(RTPHeader) + ((unsigned int) numcsrcs) * sizeof(uint32_t);
355  if (gotextension)
356  {
357  RTPExtensionHeader *rtpexthdr = (RTPExtensionHeader *) payload;
358 
359  rtpexthdr->extid = qToBigEndian(extensionid);
360  rtpexthdr->length = qToBigEndian((uint16_t) extensionlen_numwords);
361 
362  payload += sizeof(RTPExtensionHeader);
363  memcpy(payload, extensiondata, RTPPacket::extensionlength);
364 
366  }
367  memcpy(payload, payloaddata, payloadlen);
368  return 0;
369 }
uint8_t * payload
Definition: rtppacket.h:243
unsigned int extensionlength
Definition: rtppacket.h:248
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t extseqnr
Definition: rtppacket.h:242
uint32_t timestamp
Definition: rtppacket.h:242
#define ERR_RTP_PACKET_TOOMANYCSRCS
Definition: rtperrors.h:78
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned int packetlength
Definition: rtppacket.h:244
uint8_t * packet
Definition: rtppacket.h:243
unsigned short uint16_t
Definition: rtptypes_win.h:44
int32_t i
Definition: decimators.h:244
#define RTP_MAXCSRCS
Definition: rtpdefines.h:38
#define ERR_RTP_PACKET_DATAEXCEEDSMAXSIZE
Definition: rtperrors.h:74
unsigned int payloadlength
Definition: rtppacket.h:244
#define RTP_VERSION
Definition: rtpdefines.h:37
uint8_t payloadtype
Definition: rtppacket.h:241
#define ERR_RTP_PACKET_BADPAYLOADTYPE
Definition: rtperrors.h:73
+ Here is the caller graph for this function:

◆ Clear()

void qrtplib::RTPPacket::Clear ( )
private

Definition at line 43 of file rtppacket.cpp.

References error, extension, extensionlength, externalbuffer, extid, extseqnr, hasextension, hasmarker, numcsrcs, packet, packetlength, payload, payloadlength, payloadtype, ssrc, and timestamp.

Referenced by GetReceiveTime(), and RTPPacket().

44 {
45  hasextension = false;
46  hasmarker = false;
47  numcsrcs = 0;
48  payloadtype = 0;
49  extseqnr = 0;
50  timestamp = 0;
51  ssrc = 0;
52  packet = 0;
53  payload = 0;
54  packetlength = 0;
55  payloadlength = 0;
56  extid = 0;
57  extension = 0;
58  extensionlength = 0;
59  error = 0;
60  externalbuffer = false;
61 }
uint8_t * payload
Definition: rtppacket.h:243
unsigned int extensionlength
Definition: rtppacket.h:248
uint8_t * extension
Definition: rtppacket.h:247
uint32_t extseqnr
Definition: rtppacket.h:242
uint32_t timestamp
Definition: rtppacket.h:242
unsigned int packetlength
Definition: rtppacket.h:244
uint8_t * packet
Definition: rtppacket.h:243
unsigned int payloadlength
Definition: rtppacket.h:244
uint8_t payloadtype
Definition: rtppacket.h:241
+ Here is the caller graph for this function:

◆ GetCreationError()

int qrtplib::RTPPacket::GetCreationError ( ) const
inline

If an error occurred in one of the constructors, this function returns the error code.

Definition at line 111 of file rtppacket.h.

References error.

Referenced by qrtplib::RTPPacketBuilder::PrivateBuildPacket(), and qrtplib::RTPSources::ProcessRawPacket().

112  {
113  return error;
114  }
+ Here is the caller graph for this function:

◆ GetCSRC()

uint32_t qrtplib::RTPPacket::GetCSRC ( int  num) const

Returns a specific CSRC identifier. Returns a specific CSRC identifier. The parameter num can go from 0 to GetCSRCCount()-1.

Definition at line 249 of file rtppacket.cpp.

References m_endian, numcsrcs, packet, and qrtplib::RTPEndian::qToHost().

Referenced by GetCSRCCount(), and qrtplib::RTPSources::ProcessRTPPacket().

250 {
251  if (num >= numcsrcs)
252  return 0;
253 
254  uint8_t *csrcpos;
255  uint32_t *csrcval_nbo;
256  uint32_t csrcval_hbo;
257 
258  csrcpos = packet + sizeof(RTPHeader) + num * sizeof(uint32_t);
259  csrcval_nbo = (uint32_t *) csrcpos;
260  csrcval_hbo = m_endian.qToHost(*csrcval_nbo);
261  return csrcval_hbo;
262 }
T qToHost(const T &x) const
Definition: rtpendian.h:27
RTPEndian m_endian
Definition: rtppacket.h:235
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
uint8_t * packet
Definition: rtppacket.h:243
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetCSRCCount()

int qrtplib::RTPPacket::GetCSRCCount ( ) const
inline

Returns the number of CSRCs contained in this packet.

Definition at line 129 of file rtppacket.h.

References GetCSRC(), and numcsrcs.

Referenced by qrtplib::RTPSources::ProcessRTPPacket().

130  {
131  return numcsrcs;
132  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExtendedSequenceNumber()

uint32_t qrtplib::RTPPacket::GetExtendedSequenceNumber ( ) const
inline

Returns the extended sequence number of the packet. Returns the extended sequence number of the packet. When the packet is just received, only the low $16$ bits will be set. The high 16 bits can be filled in later.

Definition at line 149 of file rtppacket.h.

References extseqnr.

Referenced by qrtplib::RTPSourceStats::ProcessPacket(), and qrtplib::RTPInternalSourceData::ProcessRTPPacket().

150  {
151  return extseqnr;
152  }
uint32_t extseqnr
Definition: rtppacket.h:242
+ Here is the caller graph for this function:

◆ GetExtensionData()

uint8_t* qrtplib::RTPPacket::GetExtensionData ( ) const
inline

Returns the length of the header extension data.

Definition at line 209 of file rtppacket.h.

References extension.

210  {
211  return extension;
212  }
uint8_t * extension
Definition: rtppacket.h:247

◆ GetExtensionID()

uint16_t qrtplib::RTPPacket::GetExtensionID ( ) const
inline

If a header extension is present, this function returns the extension identifier.

Definition at line 203 of file rtppacket.h.

References extid.

204  {
205  return extid;
206  }

◆ GetExtensionLength()

unsigned int qrtplib::RTPPacket::GetExtensionLength ( ) const
inline

Returns the length of the header extension data.

Definition at line 215 of file rtppacket.h.

References extensionlength.

216  {
217  return extensionlength;
218  }
unsigned int extensionlength
Definition: rtppacket.h:248

◆ GetPacketData()

uint8_t* qrtplib::RTPPacket::GetPacketData ( ) const
inline

Returns a pointer to the data of the entire packet.

Definition at line 179 of file rtppacket.h.

References packet.

180  {
181  return packet;
182  }
uint8_t * packet
Definition: rtppacket.h:243

◆ GetPacketLength()

unsigned int qrtplib::RTPPacket::GetPacketLength ( ) const
inline

Returns the length of the entire packet.

Definition at line 191 of file rtppacket.h.

References packetlength.

Referenced by qrtplib::RTPPacketBuilder::PrivateBuildPacket().

192  {
193  return packetlength;
194  }
unsigned int packetlength
Definition: rtppacket.h:244
+ Here is the caller graph for this function:

◆ GetPayloadData()

uint8_t* qrtplib::RTPPacket::GetPayloadData ( ) const
inline

Returns a pointer to the actual payload data.

Definition at line 185 of file rtppacket.h.

References payload.

186  {
187  return payload;
188  }
uint8_t * payload
Definition: rtppacket.h:243

◆ GetPayloadLength()

unsigned int qrtplib::RTPPacket::GetPayloadLength ( ) const
inline

Returns the payload length.

Definition at line 197 of file rtppacket.h.

References payloadlength.

Referenced by qrtplib::RTPPacketBuilder::PrivateBuildPacket().

198  {
199  return payloadlength;
200  }
unsigned int payloadlength
Definition: rtppacket.h:244
+ Here is the caller graph for this function:

◆ GetPayloadType()

uint8_t qrtplib::RTPPacket::GetPayloadType ( ) const
inline

Returns the payload type of the packet.

Definition at line 140 of file rtppacket.h.

References payloadtype.

141  {
142  return payloadtype;
143  }
uint8_t payloadtype
Definition: rtppacket.h:241

◆ GetReceiveTime()

RTPTime qrtplib::RTPPacket::GetReceiveTime ( ) const
inline

Returns the time at which this packet was received. When an RTPPacket instance is created from an RTPRawPacket instance, the raw packet's reception time is stored in the RTPPacket instance. This function then retrieves that time.

Definition at line 225 of file rtppacket.h.

References BuildPacket(), Clear(), ParseRawPacket(), and receivetime.

226  {
227  return receivetime;
228  }
RTPTime receivetime
Definition: rtppacket.h:252
+ Here is the call graph for this function:

◆ GetSequenceNumber()

uint16_t qrtplib::RTPPacket::GetSequenceNumber ( ) const
inline

Returns the sequence number of this packet.

Definition at line 155 of file rtppacket.h.

References extseqnr.

156  {
157  return (uint16_t) (extseqnr & 0x0000FFFF);
158  }
uint32_t extseqnr
Definition: rtppacket.h:242
unsigned short uint16_t
Definition: rtptypes_win.h:44

◆ GetSSRC()

uint32_t qrtplib::RTPPacket::GetSSRC ( ) const
inline

Returns the SSRC identifier stored in this packet.

Definition at line 173 of file rtppacket.h.

References ssrc.

Referenced by qrtplib::RTPSources::ProcessRTPPacket().

174  {
175  return ssrc;
176  }
+ Here is the caller graph for this function:

◆ GetTimestamp()

uint32_t qrtplib::RTPPacket::GetTimestamp ( ) const
inline

Returns the timestamp of this packet.

Definition at line 167 of file rtppacket.h.

References timestamp.

Referenced by qrtplib::RTPSourceStats::ProcessPacket().

168  {
169  return timestamp;
170  }
uint32_t timestamp
Definition: rtppacket.h:242
+ Here is the caller graph for this function:

◆ HasExtension()

bool qrtplib::RTPPacket::HasExtension ( ) const
inline

Returns true if the RTP packet has a header extension and false otherwise.

Definition at line 117 of file rtppacket.h.

References hasextension.

118  {
119  return hasextension;
120  }

◆ HasMarker()

bool qrtplib::RTPPacket::HasMarker ( ) const
inline

Returns true if the marker bit was set and false otherwise.

Definition at line 123 of file rtppacket.h.

References hasmarker.

124  {
125  return hasmarker;
126  }

◆ ParseRawPacket()

int qrtplib::RTPPacket::ParseRawPacket ( RTPRawPacket rawpack)
private

Definition at line 148 of file rtppacket.cpp.

References qrtplib::RTPHeader::csrccount, ERR_RTP_PACKET_INVALIDPACKET, qrtplib::RTPHeader::extension, extension, extensionlength, qrtplib::RTPExtensionHeader::extid, extid, extseqnr, qrtplib::RTPRawPacket::GetData(), qrtplib::RTPRawPacket::GetDataLength(), hasextension, hasmarker, qrtplib::RTPRawPacket::IsRTP(), qrtplib::RTPExtensionHeader::length, m_endian, qrtplib::RTPHeader::marker, numcsrcs, packet, packetlength, qrtplib::RTPHeader::padding, payload, payloadlength, qrtplib::RTPHeader::payloadtype, payloadtype, qrtplib::RTPEndian::qToHost(), RTP_RTCPTYPE_RR, RTP_RTCPTYPE_SR, RTP_VERSION, qrtplib::RTPHeader::sequencenumber, qrtplib::RTPHeader::ssrc, ssrc, qrtplib::RTPHeader::timestamp, timestamp, and qrtplib::RTPHeader::version.

Referenced by GetReceiveTime(), and RTPPacket().

149 {
150  uint8_t *packetbytes;
151  unsigned int packetlen;
153  RTPHeader *rtpheader;
154  bool marker;
155  int csrccount;
156  bool hasextension;
157  int payloadoffset, payloadlength;
158  int numpadbytes;
159  RTPExtensionHeader *rtpextheader;
160 
161  if (!rawpack.IsRTP()) // If we didn't receive it on the RTP port, we'll ignore it
163 
164  // The length should be at least the size of the RTP header
165  packetlen = rawpack.GetDataLength();
166  if (packetlen < sizeof(RTPHeader))
168 
169  packetbytes = (uint8_t *) rawpack.GetData();
170  rtpheader = (RTPHeader *) packetbytes;
171 
172  // The version number should be correct
173  if (rtpheader->version != RTP_VERSION)
175 
176  // We'll check if this is possibly a RTCP packet. For this to be possible
177  // the marker bit and payload type combined should be either an SR or RR
178  // identifier
179  marker = (rtpheader->marker == 0) ? false : true;
180  payloadtype = rtpheader->payloadtype;
181  if (marker)
182  {
183  if (payloadtype == (RTP_RTCPTYPE_SR & 127)) // don't check high bit (this was the marker!!)
185  if (payloadtype == (RTP_RTCPTYPE_RR & 127))
187  }
188 
189  csrccount = rtpheader->csrccount;
190  payloadoffset = sizeof(RTPHeader) + (int) (csrccount * sizeof(uint32_t));
191 
192  if (rtpheader->padding) // adjust payload length to take padding into account
193  {
194  numpadbytes = (int) packetbytes[packetlen - 1]; // last byte contains number of padding bytes
195  if (numpadbytes <= 0)
197  }
198  else
199  numpadbytes = 0;
200 
201  hasextension = (rtpheader->extension == 0) ? false : true;
202  if (hasextension) // got header extension
203  {
204  rtpextheader = (RTPExtensionHeader *) (packetbytes + payloadoffset);
205  payloadoffset += sizeof(RTPExtensionHeader);
206 
207  uint16_t exthdrlen = m_endian.qToHost(rtpextheader->length);
208  payloadoffset += ((int) exthdrlen) * sizeof(uint32_t);
209  }
210  else
211  {
212  rtpextheader = 0;
213  }
214 
215  payloadlength = packetlen - numpadbytes - payloadoffset;
216  if (payloadlength < 0)
218 
219  // Now, we've got a valid packet, so we can create a new instance of RTPPacket
220  // and fill in the members
221 
223  if (hasextension)
224  {
225  RTPPacket::extid = m_endian.qToHost(rtpextheader->extid);
226  RTPPacket::extensionlength = ((int) m_endian.qToHost(rtpextheader->length)) * sizeof(uint32_t);
227  RTPPacket::extension = ((uint8_t *) rtpextheader) + sizeof(RTPExtensionHeader);
228  }
229 
230  RTPPacket::hasmarker = marker;
231  RTPPacket::numcsrcs = csrccount;
233 
234  // Note: we don't fill in the EXTENDED sequence number here, since we
235  // don't have information about the source here. We just fill in the low
236  // 16 bits
237  RTPPacket::extseqnr = (uint32_t) m_endian.qToHost(rtpheader->sequencenumber);
238 
239  RTPPacket::timestamp = m_endian.qToHost(rtpheader->timestamp);
240  RTPPacket::ssrc = m_endian.qToHost(rtpheader->ssrc);
241  RTPPacket::packet = packetbytes;
242  RTPPacket::payload = packetbytes + payloadoffset;
243  RTPPacket::packetlength = packetlen;
245 
246  return 0;
247 }
uint8_t * payload
Definition: rtppacket.h:243
#define ERR_RTP_PACKET_INVALIDPACKET
Definition: rtperrors.h:77
T qToHost(const T &x) const
Definition: rtpendian.h:27
unsigned int extensionlength
Definition: rtppacket.h:248
RTPEndian m_endian
Definition: rtppacket.h:235
uint8_t * extension
Definition: rtppacket.h:247
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define RTP_RTCPTYPE_RR
Definition: rtpdefines.h:51
uint32_t extseqnr
Definition: rtppacket.h:242
uint32_t timestamp
Definition: rtppacket.h:242
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned int packetlength
Definition: rtppacket.h:244
uint8_t * packet
Definition: rtppacket.h:243
unsigned short uint16_t
Definition: rtptypes_win.h:44
#define RTP_RTCPTYPE_SR
Definition: rtpdefines.h:50
unsigned int payloadlength
Definition: rtppacket.h:244
#define RTP_VERSION
Definition: rtpdefines.h:37
uint8_t payloadtype
Definition: rtppacket.h:241
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetExtendedSequenceNumber()

void qrtplib::RTPPacket::SetExtendedSequenceNumber ( uint32_t  seq)
inline

Sets the extended sequence number of this packet to seq.

Definition at line 161 of file rtppacket.h.

References extseqnr.

Referenced by qrtplib::RTPSourceStats::ProcessPacket().

162  {
163  extseqnr = seq;
164  }
uint32_t extseqnr
Definition: rtppacket.h:242
+ Here is the caller graph for this function:

Member Data Documentation

◆ error

int qrtplib::RTPPacket::error
private

Definition at line 236 of file rtppacket.h.

Referenced by Clear(), GetCreationError(), and RTPPacket().

◆ extension

uint8_t* qrtplib::RTPPacket::extension
private

Definition at line 247 of file rtppacket.h.

Referenced by Clear(), GetExtensionData(), and ParseRawPacket().

◆ extensionlength

unsigned int qrtplib::RTPPacket::extensionlength
private

Definition at line 248 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetExtensionLength(), and ParseRawPacket().

◆ externalbuffer

bool qrtplib::RTPPacket::externalbuffer
private

Definition at line 250 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), and ~RTPPacket().

◆ extid

uint16_t qrtplib::RTPPacket::extid
private

Definition at line 246 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetExtensionID(), and ParseRawPacket().

◆ extseqnr

uint32_t qrtplib::RTPPacket::extseqnr
private

◆ hasextension

bool qrtplib::RTPPacket::hasextension
private

Definition at line 238 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), HasExtension(), and ParseRawPacket().

◆ hasmarker

bool qrtplib::RTPPacket::hasmarker
private

Definition at line 238 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), HasMarker(), and ParseRawPacket().

◆ m_endian

RTPEndian qrtplib::RTPPacket::m_endian
private

Definition at line 235 of file rtppacket.h.

Referenced by GetCSRC(), and ParseRawPacket().

◆ numcsrcs

int qrtplib::RTPPacket::numcsrcs
private

Definition at line 239 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetCSRC(), GetCSRCCount(), and ParseRawPacket().

◆ packet

uint8_t* qrtplib::RTPPacket::packet
private

Definition at line 243 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetCSRC(), GetPacketData(), ParseRawPacket(), and ~RTPPacket().

◆ packetlength

unsigned int qrtplib::RTPPacket::packetlength
private

Definition at line 244 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetPacketLength(), and ParseRawPacket().

◆ payload

uint8_t * qrtplib::RTPPacket::payload
private

Definition at line 243 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetPayloadData(), and ParseRawPacket().

◆ payloadlength

unsigned int qrtplib::RTPPacket::payloadlength
private

Definition at line 244 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetPayloadLength(), and ParseRawPacket().

◆ payloadtype

uint8_t qrtplib::RTPPacket::payloadtype
private

Definition at line 241 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetPayloadType(), and ParseRawPacket().

◆ receivetime

RTPTime qrtplib::RTPPacket::receivetime
private

Definition at line 252 of file rtppacket.h.

Referenced by GetReceiveTime().

◆ ssrc

uint32_t qrtplib::RTPPacket::ssrc
private

Definition at line 242 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetSSRC(), and ParseRawPacket().

◆ timestamp

uint32_t qrtplib::RTPPacket::timestamp
private

Definition at line 242 of file rtppacket.h.

Referenced by BuildPacket(), Clear(), GetTimestamp(), and ParseRawPacket().


The documentation for this class was generated from the following files: