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 Types | Public Member Functions | Private Attributes | List of all members
qrtplib::RTCPSDESPacket Class Reference

#include <rtcpsdespacket.h>

+ Inheritance diagram for qrtplib::RTCPSDESPacket:
+ Collaboration diagram for qrtplib::RTCPSDESPacket:

Public Types

enum  ItemType {
  None, CNAME, NAME, EMAIL,
  PHONE, LOC, TOOL, NOTE,
  PRIV, Unknown
}
 
- Public Types inherited from qrtplib::RTCPPacket
enum  PacketType {
  SR, RR, SDES, BYE,
  APP, Unknown
}
 

Public Member Functions

 RTCPSDESPacket (uint8_t *data, std::size_t datalen)
 
 ~RTCPSDESPacket ()
 
int GetChunkCount () const
 
bool GotoFirstChunk ()
 
bool GotoNextChunk ()
 
uint32_t GetChunkSSRC () const
 
bool GotoFirstItem ()
 
bool GotoNextItem ()
 
ItemType GetItemType () const
 
std::size_t GetItemLength () const
 
uint8_tGetItemData ()
 
std::size_t GetPRIVPrefixLength () const
 
uint8_tGetPRIVPrefixData ()
 
std::size_t GetPRIVValueLength () const
 
uint8_tGetPRIVValueData ()
 
- Public Member Functions inherited from qrtplib::RTCPPacket
virtual ~RTCPPacket ()
 
bool IsKnownFormat () const
 
PacketType GetPacketType () const
 
uint8_tGetPacketData ()
 
std::size_t GetPacketLength () const
 

Private Attributes

RTPEndian m_endian
 
uint8_tcurrentchunk
 
int curchunknum
 
std::size_t itemoffset
 

Additional Inherited Members

- Protected Member Functions inherited from qrtplib::RTCPPacket
 RTCPPacket (PacketType t, uint8_t *d, std::size_t dlen)
 
- Protected Attributes inherited from qrtplib::RTCPPacket
uint8_tdata
 
std::size_t datalen
 
bool knownformat
 

Detailed Description

Describes an RTCP source description packet.

Definition at line 55 of file rtcpsdespacket.h.

Member Enumeration Documentation

◆ ItemType

Identifies the type of an SDES item.

Enumerator
None 

Used when the iteration over the items has finished.

CNAME 

Used for a CNAME (canonical name) item.

NAME 

Used for a NAME item.

EMAIL 

Used for an EMAIL item.

PHONE 

Used for a PHONE item.

LOC 

Used for a LOC (location) item.

TOOL 

Used for a TOOL item.

NOTE 

Used for a NOTE item.

PRIV 

Used for a PRIV item.

Unknown 

Used when there is an item present, but the type is not recognized.

Definition at line 59 of file rtcpsdespacket.h.

Constructor & Destructor Documentation

◆ RTCPSDESPacket()

qrtplib::RTCPSDESPacket::RTCPSDESPacket ( uint8_t data,
std::size_t  datalen 
)

Creates an instance based on the data in data with length datalen. Creates an instance based on the data in data with length datalen. Since the data pointer is referenced inside the class (no copy of the data is made) one must make sure that the memory it points to is valid as long as the class instance exists.

Definition at line 38 of file rtcpsdespacket.cpp.

References qrtplib::RTCPCommonHeader::count, curchunknum, currentchunk, itemoffset, qrtplib::RTCPPacket::knownformat, qrtplib::RTCPSDESHeader::length, qrtplib::RTCPCommonHeader::padding, and qrtplib::RTCPSDESHeader::sdesid.

38  :
39  RTCPPacket(SDES, data, datalength)
40 {
41  knownformat = false;
42  currentchunk = 0;
43  itemoffset = 0;
44  curchunknum = 0;
45 
46  RTCPCommonHeader *hdr = (RTCPCommonHeader *) data;
47  std::size_t len = datalength;
48 
49  if (hdr->padding)
50  {
51  uint8_t padcount = data[datalength - 1];
52  if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37)
53  return;
54  if (((std::size_t) padcount) >= len)
55  return;
56  len -= (std::size_t) padcount;
57  }
58 
59  if (hdr->count == 0)
60  {
61  if (len != sizeof(RTCPCommonHeader))
62  return;
63  }
64  else
65  {
66  int ssrccount = (int) (hdr->count);
67  uint8_t *chunk;
68  int chunkoffset;
69 
70  if (len < sizeof(RTCPCommonHeader))
71  return;
72 
73  len -= sizeof(RTCPCommonHeader);
74  chunk = data + sizeof(RTCPCommonHeader);
75 
76  while ((ssrccount > 0) && (len > 0))
77  {
78  if (len < (sizeof(uint32_t) * 2)) // chunk must contain at least a SSRC identifier
79  return; // and a (possibly empty) item
80 
81  len -= sizeof(uint32_t);
82  chunkoffset = sizeof(uint32_t);
83 
84  bool done = false;
85  while (!done)
86  {
87  if (len < 1) // at least a zero byte (end of item list) should be there
88  return;
89 
90  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (chunk + chunkoffset);
91  if (sdeshdr->sdesid == 0) // end of item list
92  {
93  len--;
94  chunkoffset++;
95 
96  std::size_t r = (chunkoffset & 0x03);
97  if (r != 0)
98  {
99  std::size_t addoffset = 4 - r;
100 
101  if (addoffset > len)
102  return;
103  len -= addoffset;
104  chunkoffset += addoffset;
105  }
106  done = true;
107  }
108  else
109  {
110  if (len < sizeof(RTCPSDESHeader))
111  return;
112 
113  len -= sizeof(RTCPSDESHeader);
114  chunkoffset += sizeof(RTCPSDESHeader);
115 
116  std::size_t itemlen = (std::size_t)(sdeshdr->length);
117  if (itemlen > len)
118  return;
119 
120  len -= itemlen;
121  chunkoffset += itemlen;
122  }
123  }
124 
125  ssrccount--;
126  chunk += chunkoffset;
127  }
128 
129  // check for remaining bytes
130  if (len > 0)
131  return;
132  if (ssrccount > 0)
133  return;
134  }
135 
136  knownformat = true;
137 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
RTCPPacket(PacketType t, uint8_t *d, std::size_t dlen)
Definition: rtcppacket.h:65

◆ ~RTCPSDESPacket()

qrtplib::RTCPSDESPacket::~RTCPSDESPacket ( )
inline

Definition at line 79 of file rtcpsdespacket.h.

80  {
81  }

Member Function Documentation

◆ GetChunkCount()

int qrtplib::RTCPSDESPacket::GetChunkCount ( ) const
inline

Returns the number of SDES chunks in the SDES packet. Returns the number of SDES chunks in the SDES packet. Each chunk has its own SSRC identifier.

Definition at line 154 of file rtcpsdespacket.h.

References qrtplib::RTCPCommonHeader::count.

155 {
156  if (!knownformat)
157  return 0;
158  RTCPCommonHeader *hdr = (RTCPCommonHeader *) data;
159  return ((int) hdr->count);
160 }

◆ GetChunkSSRC()

uint32_t qrtplib::RTCPSDESPacket::GetChunkSSRC ( ) const
inline

Returns the SSRC identifier of the current chunk.

Definition at line 202 of file rtcpsdespacket.h.

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

203 {
204  if (!knownformat)
205  return 0;
206  if (currentchunk == 0)
207  return 0;
208  uint32_t *ssrc = (uint32_t *) currentchunk;
209  return m_endian.qToHost(*ssrc);
210 }
T qToHost(const T &x) const
Definition: rtpendian.h:27
unsigned int uint32_t
Definition: rtptypes_win.h:46
+ Here is the caller graph for this function:

◆ GetItemData()

uint8_t * qrtplib::RTCPSDESPacket::GetItemData ( )
inline

Returns the item data of the current item in the current chunk.

Definition at line 291 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::sdesid.

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

292 {
293  if (!knownformat)
294  return 0;
295  if (currentchunk == 0)
296  return 0;
297  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
298  if (sdeshdr->sdesid == 0)
299  return 0;
300  return (currentchunk + itemoffset + sizeof(RTCPSDESHeader));
301 }
+ Here is the caller graph for this function:

◆ GetItemLength()

std::size_t qrtplib::RTCPSDESPacket::GetItemLength ( ) const
inline

Returns the item length of the current item in the current chunk.

Definition at line 279 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, Unit::None, and qrtplib::RTCPSDESHeader::sdesid.

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

280 {
281  if (!knownformat)
282  return None;
283  if (currentchunk == 0)
284  return None;
285  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
286  if (sdeshdr->sdesid == 0)
287  return 0;
288  return (std::size_t)(sdeshdr->length);
289 }
+ Here is the caller graph for this function:

◆ GetItemType()

RTCPSDESPacket::ItemType qrtplib::RTCPSDESPacket::GetItemType ( ) const
inline

Returns the SDES item type of the current item in the current chunk.

Definition at line 246 of file rtcpsdespacket.h.

References Unit::None, RTCP_SDES_ID_CNAME, RTCP_SDES_ID_EMAIL, RTCP_SDES_ID_LOCATION, RTCP_SDES_ID_NAME, RTCP_SDES_ID_NOTE, RTCP_SDES_ID_PHONE, RTCP_SDES_ID_PRIVATE, RTCP_SDES_ID_TOOL, and qrtplib::RTCPSDESHeader::sdesid.

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

247 {
248  if (!knownformat)
249  return None;
250  if (currentchunk == 0)
251  return None;
252  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
253  switch (sdeshdr->sdesid)
254  {
255  case 0:
256  return None;
257  case RTCP_SDES_ID_CNAME:
258  return CNAME;
259  case RTCP_SDES_ID_NAME:
260  return NAME;
261  case RTCP_SDES_ID_EMAIL:
262  return EMAIL;
263  case RTCP_SDES_ID_PHONE:
264  return PHONE;
266  return LOC;
267  case RTCP_SDES_ID_TOOL:
268  return TOOL;
269  case RTCP_SDES_ID_NOTE:
270  return NOTE;
272  return PRIV;
273  default:
274  return Unknown;
275  }
276  return Unknown;
277 }
#define RTCP_SDES_ID_EMAIL
Definition: rtpdefines.h:58
#define RTCP_SDES_ID_LOCATION
Definition: rtpdefines.h:60
#define RTCP_SDES_ID_NOTE
Definition: rtpdefines.h:62
#define RTCP_SDES_ID_TOOL
Definition: rtpdefines.h:61
#define RTCP_SDES_ID_CNAME
Definition: rtpdefines.h:56
#define RTCP_SDES_ID_NAME
Definition: rtpdefines.h:57
#define RTCP_SDES_ID_PHONE
Definition: rtpdefines.h:59
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
+ Here is the caller graph for this function:

◆ GetPRIVPrefixData()

uint8_t * qrtplib::RTCPSDESPacket::GetPRIVPrefixData ( )
inline

If the current item is an SDES PRIV item, this function returns actual data of the prefix string.

Definition at line 322 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, RTCP_SDES_ID_PRIVATE, and qrtplib::RTCPSDESHeader::sdesid.

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

323 {
324  if (!knownformat)
325  return 0;
326  if (currentchunk == 0)
327  return 0;
328  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
329  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
330  return 0;
331  if (sdeshdr->length == 0)
332  return 0;
333  uint8_t *preflen = currentchunk + itemoffset + sizeof(RTCPSDESHeader);
334  std::size_t prefixlength = (std::size_t)(*preflen);
335  if (prefixlength > (std::size_t)((sdeshdr->length) - 1))
336  return 0;
337  if (prefixlength == 0)
338  return 0;
339  return (currentchunk + itemoffset + sizeof(RTCPSDESHeader) + 1);
340 }
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
+ Here is the caller graph for this function:

◆ GetPRIVPrefixLength()

std::size_t qrtplib::RTCPSDESPacket::GetPRIVPrefixLength ( ) const
inline

If the current item is an SDES PRIV item, this function returns the length of the prefix string of the private item.

Definition at line 304 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, RTCP_SDES_ID_PRIVATE, and qrtplib::RTCPSDESHeader::sdesid.

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

305 {
306  if (!knownformat)
307  return 0;
308  if (currentchunk == 0)
309  return 0;
310  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
311  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
312  return 0;
313  if (sdeshdr->length == 0)
314  return 0;
315  uint8_t *preflen = currentchunk + itemoffset + sizeof(RTCPSDESHeader);
316  std::size_t prefixlength = (std::size_t)(*preflen);
317  if (prefixlength > (std::size_t)((sdeshdr->length) - 1))
318  return 0;
319  return prefixlength;
320 }
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
+ Here is the caller graph for this function:

◆ GetPRIVValueData()

uint8_t * qrtplib::RTCPSDESPacket::GetPRIVValueData ( )
inline

If the current item is an SDES PRIV item, this function returns actual value data of the private item.

Definition at line 360 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, RTCP_SDES_ID_PRIVATE, and qrtplib::RTCPSDESHeader::sdesid.

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

361 {
362  if (!knownformat)
363  return 0;
364  if (currentchunk == 0)
365  return 0;
366  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
367  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
368  return 0;
369  if (sdeshdr->length == 0)
370  return 0;
371  uint8_t *preflen = currentchunk + itemoffset + sizeof(RTCPSDESHeader);
372  std::size_t prefixlength = (std::size_t)(*preflen);
373  if (prefixlength > (std::size_t)((sdeshdr->length) - 1))
374  return 0;
375  std::size_t valuelen = ((std::size_t)(sdeshdr->length)) - prefixlength - 1;
376  if (valuelen == 0)
377  return 0;
378  return (currentchunk + itemoffset + sizeof(RTCPSDESHeader) + 1 + prefixlength);
379 }
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
+ Here is the caller graph for this function:

◆ GetPRIVValueLength()

std::size_t qrtplib::RTCPSDESPacket::GetPRIVValueLength ( ) const
inline

If the current item is an SDES PRIV item, this function returns the length of the value string of the private item.

Definition at line 342 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, RTCP_SDES_ID_PRIVATE, and qrtplib::RTCPSDESHeader::sdesid.

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

343 {
344  if (!knownformat)
345  return 0;
346  if (currentchunk == 0)
347  return 0;
348  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
349  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
350  return 0;
351  if (sdeshdr->length == 0)
352  return 0;
353  uint8_t *preflen = currentchunk + itemoffset + sizeof(RTCPSDESHeader);
354  std::size_t prefixlength = (std::size_t)(*preflen);
355  if (prefixlength > (std::size_t)((sdeshdr->length) - 1))
356  return 0;
357  return ((std::size_t)(sdeshdr->length)) - prefixlength - 1;
358 }
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
+ Here is the caller graph for this function:

◆ GotoFirstChunk()

bool qrtplib::RTCPSDESPacket::GotoFirstChunk ( )
inline

Starts the iteration over the chunks. Starts the iteration. If no SDES chunks are present, the function returns false. Otherwise, it returns true and sets the current chunk to be the first chunk.

Definition at line 162 of file rtcpsdespacket.h.

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

163 {
164  if (GetChunkCount() == 0)
165  {
166  currentchunk = 0;
167  return false;
168  }
169  currentchunk = data + sizeof(RTCPCommonHeader);
170  curchunknum = 1;
171  itemoffset = sizeof(uint32_t);
172  return true;
173 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
+ Here is the caller graph for this function:

◆ GotoFirstItem()

bool qrtplib::RTCPSDESPacket::GotoFirstItem ( )
inline

Starts the iteration over the SDES items in the current chunk. Starts the iteration over the SDES items in the current chunk. If no SDES items are present, the function returns false. Otherwise, the function sets the current item to be the first one and returns true.

Definition at line 212 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::sdesid.

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

213 {
214  if (!knownformat)
215  return false;
216  if (currentchunk == 0)
217  return false;
218  itemoffset = sizeof(uint32_t);
219  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
220  if (sdeshdr->sdesid == 0)
221  return false;
222  return true;
223 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
+ Here is the caller graph for this function:

◆ GotoNextChunk()

bool qrtplib::RTCPSDESPacket::GotoNextChunk ( )
inline

Sets the current chunk to the next available chunk. Sets the current chunk to the next available chunk. If no next chunk is present, this function returns false, otherwise it returns true.

Definition at line 175 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, and qrtplib::RTCPSDESHeader::sdesid.

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

176 {
177  if (!knownformat)
178  return false;
179  if (currentchunk == 0)
180  return false;
181  if (curchunknum == GetChunkCount())
182  return false;
183 
184  std::size_t offset = sizeof(uint32_t);
185  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + sizeof(uint32_t));
186 
187  while (sdeshdr->sdesid != 0)
188  {
189  offset += sizeof(RTCPSDESHeader);
190  offset += (std::size_t)(sdeshdr->length);
191  sdeshdr = (RTCPSDESHeader *) (currentchunk + offset);
192  }
193  offset++; // for the zero byte
194  if ((offset & 0x03) != 0)
195  offset += (4 - (offset & 0x03));
196  currentchunk += offset;
197  curchunknum++;
198  itemoffset = sizeof(uint32_t);
199  return true;
200 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
+ Here is the caller graph for this function:

◆ GotoNextItem()

bool qrtplib::RTCPSDESPacket::GotoNextItem ( )
inline

Advances the iteration to the next item in the current chunk. If there's another item in the chunk, the current item is set to be the next one and the function returns true. Otherwise, the function returns false.

Definition at line 225 of file rtcpsdespacket.h.

References qrtplib::RTCPSDESHeader::length, and qrtplib::RTCPSDESHeader::sdesid.

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

226 {
227  if (!knownformat)
228  return false;
229  if (currentchunk == 0)
230  return false;
231 
232  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (currentchunk + itemoffset);
233  if (sdeshdr->sdesid == 0)
234  return false;
235 
236  std::size_t offset = itemoffset;
237  offset += sizeof(RTCPSDESHeader);
238  offset += (std::size_t)(sdeshdr->length);
239  sdeshdr = (RTCPSDESHeader *) (currentchunk + offset);
240  if (sdeshdr->sdesid == 0)
241  return false;
242  itemoffset = offset;
243  return true;
244 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ curchunknum

int qrtplib::RTCPSDESPacket::curchunknum
private

Definition at line 150 of file rtcpsdespacket.h.

Referenced by RTCPSDESPacket().

◆ currentchunk

uint8_t* qrtplib::RTCPSDESPacket::currentchunk
private

Definition at line 149 of file rtcpsdespacket.h.

Referenced by RTCPSDESPacket().

◆ itemoffset

std::size_t qrtplib::RTCPSDESPacket::itemoffset
private

Definition at line 151 of file rtcpsdespacket.h.

Referenced by RTCPSDESPacket().

◆ m_endian

RTPEndian qrtplib::RTCPSDESPacket::m_endian
private

Definition at line 148 of file rtcpsdespacket.h.


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