JRTPLIB  3.11.1
rtcpsdesinfo.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 RTCPSDESINFO_H
38 
39 #define RTCPSDESINFO_H
40 
41 #include "rtpconfig.h"
42 #include "rtperrors.h"
43 #include "rtpdefines.h"
44 #include "rtptypes.h"
45 #include "rtpmemoryobject.h"
46 #include <string.h>
47 #include <list>
48 
49 namespace jrtplib
50 {
51 
53 class JRTPLIB_IMPORTEXPORT RTCPSDESInfo : public RTPMemoryObject
54 {
55 public:
57  RTCPSDESInfo(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr) { for (int i = 0 ; i < RTCP_SDES_NUMITEMS_NONPRIVATE ; i++) nonprivateitems[i].SetMemoryManager(mgr); }
58  virtual ~RTCPSDESInfo() { Clear(); }
59 
61  void Clear();
62 
64  int SetCNAME(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_CNAME-1,s,l); }
65 
67  int SetName(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NAME-1,s,l); }
68 
70  int SetEMail(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,s,l); }
71 
73  int SetPhone(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_PHONE-1,s,l); }
74 
76  int SetLocation(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,s,l); }
77 
79  int SetTool(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_TOOL-1,s,l); }
80 
82  int SetNote(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NOTE-1,s,l); }
83 
84 #ifdef RTP_SUPPORT_SDESPRIV
85 
89  int SetPrivateValue(const uint8_t *prefix,size_t prefixlen,const uint8_t *value,size_t valuelen);
90 
92  int DeletePrivatePrefix(const uint8_t *s,size_t len);
93 #endif // RTP_SUPPORT_SDESPRIV
94 
96  uint8_t *GetCNAME(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_CNAME-1,len); }
97 
99  uint8_t *GetName(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NAME-1,len); }
100 
102  uint8_t *GetEMail(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,len); }
103 
105  uint8_t *GetPhone(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_PHONE-1,len); }
106 
108  uint8_t *GetLocation(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,len); }
109 
111  uint8_t *GetTool(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_TOOL-1,len); }
112 
114  uint8_t *GetNote(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NOTE-1,len); }
115 #ifdef RTP_SUPPORT_SDESPRIV
116 
117  void GotoFirstPrivateValue();
118 
126  bool GetNextPrivateValue(uint8_t **prefix,size_t *prefixlen,uint8_t **value,size_t *valuelen);
127 
135  bool GetPrivateValue(const uint8_t *prefix,size_t prefixlen,uint8_t **value,size_t *valuelen) const;
136 #endif // RTP_SUPPORT_SDESPRIV
137 private:
138  int SetNonPrivateItem(int itemno,const uint8_t *s,size_t l) { if (l > RTCP_SDES_MAXITEMLENGTH) return ERR_RTP_SDES_LENGTHTOOBIG; return nonprivateitems[itemno].SetInfo(s,l); }
139  uint8_t *GetNonPrivateItem(int itemno,size_t *len) const { return nonprivateitems[itemno].GetInfo(len); }
140 
141  class SDESItem : public RTPMemoryObject
142  {
143  public:
144  SDESItem(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr)
145  {
146  str = 0;
147  length = 0;
148  }
149  void SetMemoryManager(RTPMemoryManager *mgr)
150  {
151  RTPMemoryObject::SetMemoryManager(mgr);
152  }
153  ~SDESItem()
154  {
155  if (str)
156  RTPDeleteByteArray(str,GetMemoryManager());
157  }
158  uint8_t *GetInfo(size_t *len) const { *len = length; return str; }
159  int SetInfo(const uint8_t *s,size_t len) { return SetString(&str,&length,s,len); }
160  protected:
161  int SetString(uint8_t **dest,size_t *destlen,const uint8_t *s,size_t len)
162  {
163  if (len <= 0)
164  {
165  if (*dest)
166  RTPDeleteByteArray((*dest),GetMemoryManager());
167  *dest = 0;
168  *destlen = 0;
169  }
170  else
171  {
172  len = (len>RTCP_SDES_MAXITEMLENGTH)?RTCP_SDES_MAXITEMLENGTH:len;
173  uint8_t *str2 = RTPNew(GetMemoryManager(),RTPMEM_TYPE_BUFFER_SDESITEM) uint8_t[len];
174  if (str2 == 0)
175  return ERR_RTP_OUTOFMEM;
176  memcpy(str2,s,len);
177  *destlen = len;
178  if (*dest)
179  RTPDeleteByteArray((*dest),GetMemoryManager());
180  *dest = str2;
181  }
182  return 0;
183  }
184  private:
185  uint8_t *str;
186  size_t length;
187  };
188 
189  SDESItem nonprivateitems[RTCP_SDES_NUMITEMS_NONPRIVATE];
190 
191 #ifdef RTP_SUPPORT_SDESPRIV
192  class SDESPrivateItem : public SDESItem
193  {
194  public:
195  SDESPrivateItem(RTPMemoryManager *mgr) : SDESItem(mgr)
196  {
197  prefixlen = 0;
198  prefix = 0;
199  }
200  ~SDESPrivateItem()
201  {
202  if (prefix)
203  RTPDeleteByteArray(prefix,GetMemoryManager());
204  }
205  uint8_t *GetPrefix(size_t *len) const { *len = prefixlen; return prefix; }
206  int SetPrefix(const uint8_t *s,size_t len) { return SetString(&prefix,&prefixlen,s,len); }
207  private:
208  uint8_t *prefix;
209  size_t prefixlen;
210  };
211 
212  std::list<SDESPrivateItem *> privitems;
213  std::list<SDESPrivateItem *>::const_iterator curitem;
214 #endif // RTP_SUPPORT_SDESPRIV
215 };
216 
217 } // end namespace
218 
219 #endif // RTCPSDESINFO_H
220 
int SetName(const uint8_t *s, size_t l)
Sets the SDES name item to s with length l.
Definition: rtcpsdesinfo.h:67
The class RTCPSDESInfo is a container for RTCP SDES information.
Definition: rtcpsdesinfo.h:53
RTCPSDESInfo(RTPMemoryManager *mgr=0)
Constructs an instance, optionally installing a memory manager.
Definition: rtcpsdesinfo.h:57
int SetEMail(const uint8_t *s, size_t l)
Sets the SDES e-mail item to s with length l.
Definition: rtcpsdesinfo.h:70
int SetTool(const uint8_t *s, size_t l)
Sets the SDES tool item to s with length l.
Definition: rtcpsdesinfo.h:79
#define RTPMEM_TYPE_BUFFER_SDESITEM
Buffer to store an SDES item.
Definition: rtpmemorymanager.h:75
uint8_t * GetCNAME(size_t *len) const
Returns the SDES CNAME item and stores its length in len.
Definition: rtcpsdesinfo.h:96
uint8_t * GetLocation(size_t *len) const
Returns the SDES location item and stores its length in len.
Definition: rtcpsdesinfo.h:108
int SetPhone(const uint8_t *s, size_t l)
Sets the SDES phone item to s with length l.
Definition: rtcpsdesinfo.h:73
int SetLocation(const uint8_t *s, size_t l)
Sets the SDES location item to s with length l.
Definition: rtcpsdesinfo.h:76
uint8_t * GetNote(size_t *len) const
Returns the SDES note item and stores its length in len.
Definition: rtcpsdesinfo.h:114
Definition: rtpfaketransmitter.h:64
A memory manager.
Definition: rtpmemorymanager.h:150
uint8_t * GetTool(size_t *len) const
Returns the SDES tool item and stores its length in len.
Definition: rtcpsdesinfo.h:111
uint8_t * GetEMail(size_t *len) const
Returns the SDES e-mail item and stores its length in len.
Definition: rtcpsdesinfo.h:102
int SetNote(const uint8_t *s, size_t l)
Sets the SDES note item to s with length l.
Definition: rtcpsdesinfo.h:82
uint8_t * GetPhone(size_t *len) const
Returns the SDES phone item and stores its length in len.
Definition: rtcpsdesinfo.h:105
uint8_t * GetName(size_t *len) const
Returns the SDES name item and stores its length in len.
Definition: rtcpsdesinfo.h:99
int SetCNAME(const uint8_t *s, size_t l)
Sets the SDES CNAME item to s with length l.
Definition: rtcpsdesinfo.h:64