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.
rtcpsdespacket.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31  */
32 
37 #ifndef RTCPSDESPACKET_H
38 
39 #define RTCPSDESPACKET_H
40 
41 #include "rtpconfig.h"
42 #include "rtcppacket.h"
43 #include "rtpstructs.h"
44 #include "rtpdefines.h"
45 #include "rtpendian.h"
46 
47 #include "export.h"
48 
49 namespace qrtplib
50 {
51 
52 class RTCPCompoundPacket;
53 
56 {
57 public:
59  enum ItemType
60  {
61  None,
63  NAME,
66  LOC,
67  TOOL,
68  NOTE,
69  PRIV,
70  Unknown
71  };
72 
78  RTCPSDESPacket(uint8_t *data, std::size_t datalen);
80  {
81  }
82 
86  int GetChunkCount() const;
87 
92  bool GotoFirstChunk();
93 
98  bool GotoNextChunk();
99 
101  uint32_t GetChunkSSRC() const;
102 
108  bool GotoFirstItem();
109 
114  bool GotoNextItem();
115 
117  ItemType GetItemType() const;
118 
120  std::size_t GetItemLength() const;
121 
123  uint8_t *GetItemData();
124 
125 #ifdef RTP_SUPPORT_SDESPRIV
126 
129  std::size_t GetPRIVPrefixLength() const;
130 
134  uint8_t *GetPRIVPrefixData();
135 
139  std::size_t GetPRIVValueLength() const;
140 
144  uint8_t *GetPRIVValueData();
145 #endif // RTP_SUPPORT_SDESPRIV
146 
147 private:
151  std::size_t itemoffset;
152 };
153 
155 {
156  if (!knownformat)
157  return 0;
158  RTCPCommonHeader *hdr = (RTCPCommonHeader *) data;
159  return ((int) hdr->count);
160 }
161 
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 }
174 
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 }
201 
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 }
211 
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 }
224 
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 }
245 
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 }
278 
279 inline std::size_t RTCPSDESPacket::GetItemLength() const
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 }
290 
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 }
302 
303 #ifdef RTP_SUPPORT_SDESPRIV
304 inline std::size_t RTCPSDESPacket::GetPRIVPrefixLength() const
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 }
321 
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 }
341 
342 inline std::size_t RTCPSDESPacket::GetPRIVValueLength() const
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 }
359 
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 }
380 
381 #endif // RTP_SUPPORT_SDESPRIV
382 
383 } // end namespace
384 
385 #endif // RTCPSDESPACKET_H
386 
#define RTCP_SDES_ID_EMAIL
Definition: rtpdefines.h:58
#define RTCP_SDES_ID_LOCATION
Definition: rtpdefines.h:60
std::size_t GetPRIVValueLength() const
std::size_t GetItemLength() const
std::size_t GetPRIVPrefixLength() const
#define RTCP_SDES_ID_NOTE
Definition: rtpdefines.h:62
uint32_t GetChunkSSRC() const
#define QRTPLIB_API
Definition: export.h:112
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
ItemType GetItemType() const
#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