jrtplib  3.6.0
rtcpsdespacket.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale 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 #if ! (defined(WIN32) || defined(_WIN32_WCE))
46  #include <netinet/in.h>
47 #endif // WIN32
48 
49 class RTCPCompoundPacket;
50 
52 class RTCPSDESPacket : public RTCPPacket
53 {
54 public:
56  enum ItemType
57  {
58  None,
60  NAME,
63  LOC,
64  TOOL,
65  NOTE,
66  PRIV,
68  };
69 
75  RTCPSDESPacket(uint8_t *data,size_t datalen);
76  ~RTCPSDESPacket() { }
77 
81  int GetChunkCount() const;
82 
87  bool GotoFirstChunk();
88 
93  bool GotoNextChunk();
94 
96  uint32_t GetChunkSSRC() const;
97 
103  bool GotoFirstItem();
104 
109  bool GotoNextItem();
110 
112  ItemType GetItemType() const;
113 
115  size_t GetItemLength() const;
116 
118  uint8_t *GetItemData();
119 
120 #ifdef RTP_SUPPORT_SDESPRIV
121 
124  size_t GetPRIVPrefixLength() const;
125 
129  uint8_t *GetPRIVPrefixData();
130 
134  size_t GetPRIVValueLength() const;
135 
139  uint8_t *GetPRIVValueData();
140 #endif // RTP_SUPPORT_SDESPRIV
141 
142 #ifdef RTPDEBUG
143  void Dump();
144 #endif // RTPDEBUG
145 private:
146  uint8_t *currentchunk;
147  int curchunknum;
148  size_t itemoffset;
149 };
150 
152 {
153  if (!knownformat)
154  return 0;
155  RTCPCommonHeader *hdr = (RTCPCommonHeader *)data;
156  return ((int)hdr->count);
157 }
158 
160 {
161  if (GetChunkCount() == 0)
162  {
163  currentchunk = 0;
164  return false;
165  }
166  currentchunk = data+sizeof(RTCPCommonHeader);
167  curchunknum = 1;
168  itemoffset = sizeof(uint32_t);
169  return true;
170 }
171 
173 {
174  if (!knownformat)
175  return false;
176  if (currentchunk == 0)
177  return false;
178  if (curchunknum == GetChunkCount())
179  return false;
180 
181  size_t offset = sizeof(uint32_t);
182  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+sizeof(uint32_t));
183 
184  while (sdeshdr->sdesid != 0)
185  {
186  offset += sizeof(RTCPSDESHeader);
187  offset += (size_t)(sdeshdr->length);
188  sdeshdr = (RTCPSDESHeader *)(currentchunk+offset);
189  }
190  offset++; // for the zero byte
191  if ((offset&0x03) != 0)
192  offset += (4-(offset&0x03));
193  currentchunk += offset;
194  curchunknum++;
195  itemoffset = sizeof(uint32_t);
196  return true;
197 }
198 
199 inline uint32_t RTCPSDESPacket::GetChunkSSRC() const
200 {
201  if (!knownformat)
202  return 0;
203  if (currentchunk == 0)
204  return 0;
205  uint32_t *ssrc = (uint32_t *)currentchunk;
206  return ntohl(*ssrc);
207 }
208 
210 {
211  if (!knownformat)
212  return false;
213  if (currentchunk == 0)
214  return false;
215  itemoffset = sizeof(uint32_t);
216  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
217  if (sdeshdr->sdesid == 0)
218  return false;
219  return true;
220 }
221 
223 {
224  if (!knownformat)
225  return false;
226  if (currentchunk == 0)
227  return false;
228 
229  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
230  if (sdeshdr->sdesid == 0)
231  return false;
232 
233  size_t offset = itemoffset;
234  offset += sizeof(RTCPSDESHeader);
235  offset += (size_t)(sdeshdr->length);
236  sdeshdr = (RTCPSDESHeader *)(currentchunk+offset);
237  if (sdeshdr->sdesid == 0)
238  return false;
239  itemoffset = offset;
240  return true;
241 }
242 
244 {
245  if (!knownformat)
246  return None;
247  if (currentchunk == 0)
248  return None;
249  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
250  switch (sdeshdr->sdesid)
251  {
252  case 0:
253  return None;
254  case RTCP_SDES_ID_CNAME:
255  return CNAME;
256  case RTCP_SDES_ID_NAME:
257  return NAME;
258  case RTCP_SDES_ID_EMAIL:
259  return EMAIL;
260  case RTCP_SDES_ID_PHONE:
261  return PHONE;
262  case RTCP_SDES_ID_LOCATION:
263  return LOC;
264  case RTCP_SDES_ID_TOOL:
265  return TOOL;
266  case RTCP_SDES_ID_NOTE:
267  return NOTE;
268  case RTCP_SDES_ID_PRIVATE:
269  return PRIV;
270  default:
271  return Unknown;
272  }
273  return Unknown;
274 }
275 
276 inline size_t RTCPSDESPacket::GetItemLength() const
277 {
278  if (!knownformat)
279  return None;
280  if (currentchunk == 0)
281  return None;
282  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
283  if (sdeshdr->sdesid == 0)
284  return 0;
285  return (size_t)(sdeshdr->length);
286 }
287 
289 {
290  if (!knownformat)
291  return 0;
292  if (currentchunk == 0)
293  return 0;
294  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
295  if (sdeshdr->sdesid == 0)
296  return 0;
297  return (currentchunk+itemoffset+sizeof(RTCPSDESHeader));
298 }
299 
300 #ifdef RTP_SUPPORT_SDESPRIV
302 {
303  if (!knownformat)
304  return 0;
305  if (currentchunk == 0)
306  return 0;
307  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
308  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
309  return 0;
310  if (sdeshdr->length == 0)
311  return 0;
312  uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader);
313  size_t prefixlength = (size_t)(*preflen);
314  if (prefixlength > (size_t)((sdeshdr->length)-1))
315  return 0;
316  return prefixlength;
317 }
318 
320 {
321  if (!knownformat)
322  return 0;
323  if (currentchunk == 0)
324  return 0;
325  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
326  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
327  return 0;
328  if (sdeshdr->length == 0)
329  return 0;
330  uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader);
331  size_t prefixlength = (size_t)(*preflen);
332  if (prefixlength > (size_t)((sdeshdr->length)-1))
333  return 0;
334  if (prefixlength == 0)
335  return 0;
336  return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)+1);
337 }
338 
340 {
341  if (!knownformat)
342  return 0;
343  if (currentchunk == 0)
344  return 0;
345  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
346  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
347  return 0;
348  if (sdeshdr->length == 0)
349  return 0;
350  uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader);
351  size_t prefixlength = (size_t)(*preflen);
352  if (prefixlength > (size_t)((sdeshdr->length)-1))
353  return 0;
354  return ((size_t)(sdeshdr->length))-prefixlength-1;
355 }
356 
358 {
359  if (!knownformat)
360  return 0;
361  if (currentchunk == 0)
362  return 0;
363  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset);
364  if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE)
365  return 0;
366  if (sdeshdr->length == 0)
367  return 0;
368  uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader);
369  size_t prefixlength = (size_t)(*preflen);
370  if (prefixlength > (size_t)((sdeshdr->length)-1))
371  return 0;
372  size_t valuelen = ((size_t)(sdeshdr->length))-prefixlength-1;
373  if (valuelen == 0)
374  return 0;
375  return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)+1+prefixlength);
376 }
377 
378 #endif // RTP_SUPPORT_SDESPRIV
379 
380 #endif // RTCPSDESPACKET_H
381 
Used for a NAME item.
Definition: rtcpsdespacket.h:60
ItemType GetItemType() const
Returns the SDES item type of the current item in the current chunk.
Definition: rtcpsdespacket.h:243
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:301
Used for a NOTE item.
Definition: rtcpsdespacket.h:65
Used for a PHONE item.
Definition: rtcpsdespacket.h:62
bool GotoNextItem()
Advances the iteration to the next item in the current chunk.
Definition: rtcpsdespacket.h:222
Used for a PRIV item.
Definition: rtcpsdespacket.h:66
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:47
uint8_t * GetPRIVPrefixData()
If the current item is an SDES PRIV item, this function returns actual data of the prefix string...
Definition: rtcpsdespacket.h:319
size_t GetItemLength() const
Returns the item length of the current item in the current chunk.
Definition: rtcpsdespacket.h:276
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
Describes an RTCP source description packet.
Definition: rtcpsdespacket.h:52
uint32_t GetChunkSSRC() const
Returns the SSRC identifier of the current chunk.
Definition: rtcpsdespacket.h:199
RTCPSDESPacket(uint8_t *data, size_t datalen)
Creates an instance based on the data in data with length datalen.
Used for a CNAME (canonical name) item.
Definition: rtcpsdespacket.h:59
Used when the iteration over the items has finished.
Definition: rtcpsdespacket.h:58
ItemType
Identifies the type of an SDES item.
Definition: rtcpsdespacket.h:56
uint8_t * GetItemData()
Returns the item data of the current item in the current chunk.
Definition: rtcpsdespacket.h:288
bool GotoFirstChunk()
Starts the iteration over the chunks.
Definition: rtcpsdespacket.h:159
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:339
int GetChunkCount() const
Returns the number of SDES chunks in the SDES packet.
Definition: rtcpsdespacket.h:151
bool GotoFirstItem()
Starts the iteration over the SDES items in the current chunk.
Definition: rtcpsdespacket.h:209
bool GotoNextChunk()
Sets the current chunk to the next available chunk.
Definition: rtcpsdespacket.h:172
Used for a TOOL item.
Definition: rtcpsdespacket.h:64
Used for a LOC (location) item.
Definition: rtcpsdespacket.h:63
Used for an EMAIL item.
Definition: rtcpsdespacket.h:61
Used when there is an item present, but the type is not recognized.
Definition: rtcpsdespacket.h:67
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:357