JRTPLIB  3.11.2 (development version)
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  JRTPLIB_NO_COPY(RTCPSDESInfo)
56 public:
58  RTCPSDESInfo(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr) { for (int i = 0 ; i < RTCP_SDES_NUMITEMS_NONPRIVATE ; i++) nonprivateitems[i].SetMemoryManager(mgr); }
59  virtual ~RTCPSDESInfo() { Clear(); }
60 
62  void Clear();
63 
65  int SetCNAME(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_CNAME-1,s,l); }
66 
68  int SetName(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NAME-1,s,l); }
69 
71  int SetEMail(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,s,l); }
72 
74  int SetPhone(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_PHONE-1,s,l); }
75 
77  int SetLocation(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,s,l); }
78 
80  int SetTool(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_TOOL-1,s,l); }
81 
83  int SetNote(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NOTE-1,s,l); }
84 
85 #ifdef RTP_SUPPORT_SDESPRIV
90  int SetPrivateValue(const uint8_t *prefix,size_t prefixlen,const uint8_t *value,size_t valuelen);
91 
93  int DeletePrivatePrefix(const uint8_t *s,size_t len);
94 #endif // RTP_SUPPORT_SDESPRIV
95 
97  uint8_t *GetCNAME(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_CNAME-1,len); }
98 
100  uint8_t *GetName(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NAME-1,len); }
101 
103  uint8_t *GetEMail(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,len); }
104 
106  uint8_t *GetPhone(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_PHONE-1,len); }
107 
109  uint8_t *GetLocation(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,len); }
110 
112  uint8_t *GetTool(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_TOOL-1,len); }
113 
115  uint8_t *GetNote(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NOTE-1,len); }
116 #ifdef RTP_SUPPORT_SDESPRIV
119 
127  bool GetNextPrivateValue(uint8_t **prefix,size_t *prefixlen,uint8_t **value,size_t *valuelen);
128 
136  bool GetPrivateValue(const uint8_t *prefix,size_t prefixlen,uint8_t **value,size_t *valuelen) const;
137 #endif // RTP_SUPPORT_SDESPRIV
138 private:
139  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); }
140  uint8_t *GetNonPrivateItem(int itemno,size_t *len) const { return nonprivateitems[itemno].GetInfo(len); }
141 
142  class SDESItem : public RTPMemoryObject
143  {
144  public:
145  SDESItem(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr)
146  {
147  str = 0;
148  length = 0;
149  }
150  void SetMemoryManager(RTPMemoryManager *mgr)
151  {
152  RTPMemoryObject::SetMemoryManager(mgr);
153  }
154  ~SDESItem()
155  {
156  if (str)
157  RTPDeleteByteArray(str,GetMemoryManager());
158  }
159  uint8_t *GetInfo(size_t *len) const { *len = length; return str; }
160  int SetInfo(const uint8_t *s,size_t len) { return SetString(&str,&length,s,len); }
161  protected:
162  int SetString(uint8_t **dest,size_t *destlen,const uint8_t *s,size_t len)
163  {
164  if (len <= 0)
165  {
166  if (*dest)
167  RTPDeleteByteArray((*dest),GetMemoryManager());
168  *dest = 0;
169  *destlen = 0;
170  }
171  else
172  {
173  len = (len>RTCP_SDES_MAXITEMLENGTH)?RTCP_SDES_MAXITEMLENGTH:len;
174  uint8_t *str2 = RTPNew(GetMemoryManager(),RTPMEM_TYPE_BUFFER_SDESITEM) uint8_t[len];
175  if (str2 == 0)
176  return ERR_RTP_OUTOFMEM;
177  memcpy(str2,s,len);
178  *destlen = len;
179  if (*dest)
180  RTPDeleteByteArray((*dest),GetMemoryManager());
181  *dest = str2;
182  }
183  return 0;
184  }
185  private:
186  uint8_t *str;
187  size_t length;
188  };
189 
190  SDESItem nonprivateitems[RTCP_SDES_NUMITEMS_NONPRIVATE];
191 
192 #ifdef RTP_SUPPORT_SDESPRIV
193  class SDESPrivateItem : public SDESItem
194  {
195  public:
196  SDESPrivateItem(RTPMemoryManager *mgr) : SDESItem(mgr)
197  {
198  prefixlen = 0;
199  prefix = 0;
200  }
201  ~SDESPrivateItem()
202  {
203  if (prefix)
204  RTPDeleteByteArray(prefix,GetMemoryManager());
205  }
206  uint8_t *GetPrefix(size_t *len) const { *len = prefixlen; return prefix; }
207  int SetPrefix(const uint8_t *s,size_t len) { return SetString(&prefix,&prefixlen,s,len); }
208  private:
209  uint8_t *prefix;
210  size_t prefixlen;
211  };
212 
213  std::list<SDESPrivateItem *> privitems;
214  std::list<SDESPrivateItem *>::const_iterator curitem;
215 #endif // RTP_SUPPORT_SDESPRIV
216 };
217 
218 } // end namespace
219 
220 #endif // RTCPSDESINFO_H
221 
The class RTCPSDESInfo is a container for RTCP SDES information.
Definition: rtcpsdesinfo.h:54
uint8_t * GetLocation(size_t *len) const
Returns the SDES location item and stores its length in len.
Definition: rtcpsdesinfo.h:109
int SetPhone(const uint8_t *s, size_t l)
Sets the SDES phone item to s with length l.
Definition: rtcpsdesinfo.h:74
int SetTool(const uint8_t *s, size_t l)
Sets the SDES tool item to s with length l.
Definition: rtcpsdesinfo.h:80
uint8_t * GetCNAME(size_t *len) const
Returns the SDES CNAME item and stores its length in len.
Definition: rtcpsdesinfo.h:97
int SetEMail(const uint8_t *s, size_t l)
Sets the SDES e-mail item to s with length l.
Definition: rtcpsdesinfo.h:71
uint8_t * GetNote(size_t *len) const
Returns the SDES note item and stores its length in len.
Definition: rtcpsdesinfo.h:115
bool GetNextPrivateValue(uint8_t **prefix, size_t *prefixlen, uint8_t **value, size_t *valuelen)
Returns SDES priv item information.
void GotoFirstPrivateValue()
Starts the iteration over the stored SDES private item prefixes and their associated values.
int DeletePrivatePrefix(const uint8_t *s, size_t len)
Deletes the entry for the prefix specified by s with length len.
int SetName(const uint8_t *s, size_t l)
Sets the SDES name item to s with length l.
Definition: rtcpsdesinfo.h:68
int SetNote(const uint8_t *s, size_t l)
Sets the SDES note item to s with length l.
Definition: rtcpsdesinfo.h:83
int SetPrivateValue(const uint8_t *prefix, size_t prefixlen, const uint8_t *value, size_t valuelen)
Sets the entry for the prefix string specified by prefix with length prefixlen to contain the value s...
uint8_t * GetEMail(size_t *len) const
Returns the SDES e-mail item and stores its length in len.
Definition: rtcpsdesinfo.h:103
uint8_t * GetPhone(size_t *len) const
Returns the SDES phone item and stores its length in len.
Definition: rtcpsdesinfo.h:106
uint8_t * GetTool(size_t *len) const
Returns the SDES tool item and stores its length in len.
Definition: rtcpsdesinfo.h:112
int SetCNAME(const uint8_t *s, size_t l)
Sets the SDES CNAME item to s with length l.
Definition: rtcpsdesinfo.h:65
bool GetPrivateValue(const uint8_t *prefix, size_t prefixlen, uint8_t **value, size_t *valuelen) const
Returns SDES priv item information.
uint8_t * GetName(size_t *len) const
Returns the SDES name item and stores its length in len.
Definition: rtcpsdesinfo.h:100
void Clear()
Clears all SDES information.
int SetLocation(const uint8_t *s, size_t l)
Sets the SDES location item to s with length l.
Definition: rtcpsdesinfo.h:77
RTCPSDESInfo(RTPMemoryManager *mgr=0)
Constructs an instance, optionally installing a memory manager.
Definition: rtcpsdesinfo.h:58
A memory manager.
Definition: rtpmemorymanager.h:151
#define RTPMEM_TYPE_BUFFER_SDESITEM
Buffer to store an SDES item.
Definition: rtpmemorymanager.h:75