JRTPLIB  3.11.1
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 #ifdef RTP_SUPPORT_NETINET_IN
46  #include <netinet/in.h>
47 #endif // RTP_SUPPORT_NETINET_IN
48 
49 namespace jrtplib
50 {
51 
52  class RTCPCompoundPacket;
53 
55 class JRTPLIB_IMPORTEXPORT RTCPSDESPacket : public RTCPPacket
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,size_t datalen);
79  ~RTCPSDESPacket() { }
80 
84  int GetChunkCount() const;
85 
90  bool GotoFirstChunk();
91 
96  bool GotoNextChunk();
97 
99  uint32_t GetChunkSSRC() const;
100 
106  bool GotoFirstItem();
107 
112  bool GotoNextItem();
113 
115  ItemType GetItemType() const;
116 
118  size_t GetItemLength() const;
119 
121  uint8_t *GetItemData();
122 
123 #ifdef RTP_SUPPORT_SDESPRIV
124 
127  size_t GetPRIVPrefixLength() const;
128 
132  uint8_t *GetPRIVPrefixData();
133 
137  size_t GetPRIVValueLength() const;
138 
142  uint8_t *GetPRIVValueData();
143 #endif // RTP_SUPPORT_SDESPRIV
144 
145 #ifdef RTPDEBUG
146  void Dump();
147 #endif // RTPDEBUG
148 private:
149  uint8_t *currentchunk;
150  int curchunknum;
151  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  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 += (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 
202 inline uint32_t RTCPSDESPacket::GetChunkSSRC() const
203 {
204  if (!knownformat)
205  return 0;
206  if (currentchunk == 0)
207  return 0;
208  uint32_t *ssrc = (uint32_t *)currentchunk;
209  return ntohl(*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  size_t offset = itemoffset;
237  offset += sizeof(RTCPSDESHeader);
238  offset += (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;
265  case RTCP_SDES_ID_LOCATION:
266  return LOC;
267  case RTCP_SDES_ID_TOOL:
268  return TOOL;
269  case RTCP_SDES_ID_NOTE:
270  return NOTE;
271  case RTCP_SDES_ID_PRIVATE:
272  return PRIV;
273  default:
274  return Unknown;
275  }
276  return Unknown;
277 }
278 
279 inline 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 (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
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  size_t prefixlength = (size_t)(*preflen);
317  if (prefixlength > (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  size_t prefixlength = (size_t)(*preflen);
335  if (prefixlength > (size_t)((sdeshdr->length)-1))
336  return 0;
337  if (prefixlength == 0)
338  return 0;
339  return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)+1);
340 }
341 
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  size_t prefixlength = (size_t)(*preflen);
355  if (prefixlength > (size_t)((sdeshdr->length)-1))
356  return 0;
357  return ((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  size_t prefixlength = (size_t)(*preflen);
373  if (prefixlength > (size_t)((sdeshdr->length)-1))
374  return 0;
375  size_t valuelen = ((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 
int GetChunkCount() const
Returns the number of SDES chunks in the SDES packet.
Definition: rtcpsdespacket.h:154
ItemType GetItemType() const
Returns the SDES item type of the current item in the current chunk.
Definition: rtcpsdespacket.h:246
Used for a PHONE item.
Definition: rtcpsdespacket.h:65
bool GotoNextItem()
Advances the iteration to the next item in the current chunk.
Definition: rtcpsdespacket.h:225
Used for an EMAIL item.
Definition: rtcpsdespacket.h:64
Used when the iteration over the items has finished.
Definition: rtcpsdespacket.h:61
bool GotoFirstChunk()
Starts the iteration over the chunks.
Definition: rtcpsdespacket.h:162
uint32_t GetChunkSSRC() const
Returns the SSRC identifier of the current chunk.
Definition: rtcpsdespacket.h:202
ItemType
Identifies the type of an SDES item.
Definition: rtcpsdespacket.h:59
Used for a CNAME (canonical name) item.
Definition: rtcpsdespacket.h:62
Used for a PRIV item.
Definition: rtcpsdespacket.h:69
Used for a LOC (location) item.
Definition: rtcpsdespacket.h:66
size_t GetPRIVValueLength() const
If the current item is an SDES PRIV item, this function returns the length of the value string of the...
Definition: rtcpsdespacket.h:342
Definition: rtpfaketransmitter.h:64
Used for a NAME item.
Definition: rtcpsdespacket.h:63
bool GotoNextChunk()
Sets the current chunk to the next available chunk.
Definition: rtcpsdespacket.h:175
bool GotoFirstItem()
Starts the iteration over the SDES items in the current chunk.
Definition: rtcpsdespacket.h:212
size_t GetPRIVPrefixLength() const
If the current item is an SDES PRIV item, this function returns the length of the prefix string of th...
Definition: rtcpsdespacket.h:304
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:50
uint8_t * GetPRIVPrefixData()
If the current item is an SDES PRIV item, this function returns actual data of the prefix string...
Definition: rtcpsdespacket.h:322
size_t GetItemLength() const
Returns the item length of the current item in the current chunk.
Definition: rtcpsdespacket.h:279
uint8_t * GetPRIVValueData()
If the current item is an SDES PRIV item, this function returns actual value data of the private item...
Definition: rtcpsdespacket.h:360
Describes an RTCP source description packet.
Definition: rtcpsdespacket.h:55
uint8_t * GetItemData()
Returns the item data of the current item in the current chunk.
Definition: rtcpsdespacket.h:291
Used for a NOTE item.
Definition: rtcpsdespacket.h:68
Used for a TOOL item.
Definition: rtcpsdespacket.h:67