JRTPLIB  3.10.0
rtpmemorymanager.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2016 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 RTPMEMORYMANAGER_H
38 
39 #define RTPMEMORYMANAGER_H
40 
41 #include "rtpconfig.h"
42 #include "rtptypes.h"
43 
45 #define RTPMEM_TYPE_OTHER 0
46 
48 #define RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET 1
49 
51 #define RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET 2
52 
54 #define RTPMEM_TYPE_BUFFER_RTCPAPPPACKET 3
55 
57 #define RTPMEM_TYPE_BUFFER_RTCPBYEPACKET 4
58 
60 #define RTPMEM_TYPE_BUFFER_RTCPBYEREASON 5
61 
63 #define RTPMEM_TYPE_BUFFER_RTCPCOMPOUNDPACKET 6
64 
66 #define RTPMEM_TYPE_BUFFER_RTCPSDESBLOCK 7
67 
69 #define RTPMEM_TYPE_BUFFER_RTPPACKET 8
70 
72 #define RTPMEM_TYPE_BUFFER_RTPPACKETBUILDERBUFFER 9
73 
75 #define RTPMEM_TYPE_BUFFER_SDESITEM 10
76 
78 #define RTPMEM_TYPE_CLASS_ACCEPTIGNOREHASHELEMENT 11
79 
81 #define RTPMEM_TYPE_CLASS_ACCEPTIGNOREPORTINFO 12
82 
84 #define RTPMEM_TYPE_CLASS_DESTINATIONLISTHASHELEMENT 13
85 
87 #define RTPMEM_TYPE_CLASS_MULTICASTHASHELEMENT 14
88 
90 #define RTPMEM_TYPE_CLASS_RTCPAPPPACKET 15
91 
93 #define RTPMEM_TYPE_CLASS_RTCPBYEPACKET 16
94 
96 #define RTPMEM_TYPE_CLASS_RTCPCOMPOUNDPACKETBUILDER 17
97 
99 #define RTPMEM_TYPE_CLASS_RTCPRECEIVERREPORT 18
100 
102 #define RTPMEM_TYPE_CLASS_RTCPRRPACKET 19
103 
105 #define RTPMEM_TYPE_CLASS_RTCPSDESPACKET 20
106 
108 #define RTPMEM_TYPE_CLASS_RTCPSRPACKET 21
109 
111 #define RTPMEM_TYPE_CLASS_RTCPUNKNOWNPACKET 22
112 
114 #define RTPMEM_TYPE_CLASS_RTPADDRESS 23
115 
117 #define RTPMEM_TYPE_CLASS_RTPINTERNALSOURCEDATA 24
118 
120 #define RTPMEM_TYPE_CLASS_RTPPACKET 25
121 
123 #define RTPMEM_TYPE_CLASS_RTPPOLLTHREAD 26
124 
126 #define RTPMEM_TYPE_CLASS_RTPRAWPACKET 27
127 
129 #define RTPMEM_TYPE_CLASS_RTPTRANSMISSIONINFO 28
130 
132 #define RTPMEM_TYPE_CLASS_RTPTRANSMITTER 29
133 
135 #define RTPMEM_TYPE_CLASS_SDESPRIVATEITEM 30
136 
138 #define RTPMEM_TYPE_CLASS_SDESSOURCE 31
139 
141 #define RTPMEM_TYPE_CLASS_SOURCETABLEHASHELEMENT 32
142 
144 #define RTPMEM_TYPE_BUFFER_SRTPDATA 33
145 
146 namespace jrtplib
147 {
148 
150 class JRTPLIB_IMPORTEXPORT RTPMemoryManager
151 {
152 public:
153  RTPMemoryManager() { }
154  virtual ~RTPMemoryManager() { }
155 
163  virtual void *AllocateBuffer(size_t numbytes, int memtype) = 0;
164 
166  virtual void FreeBuffer(void *buffer) = 0;
167 };
168 
169 } // end namespace
170 
171 #ifdef RTP_SUPPORT_MEMORYMANAGEMENT
172 
173 #include <new>
174 
175 inline void *operator new(size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
176 {
177  if (mgr == 0)
178  return operator new(numbytes);
179  return mgr->AllocateBuffer(numbytes,memtype);
180 }
181 
182 inline void operator delete(void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
183 {
184  if (mgr == 0)
185  operator delete(buffer);
186  else
187  mgr->FreeBuffer(buffer);
188 }
189 
190 #ifdef RTP_HAVE_ARRAYALLOC
191 inline void *operator new[](size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
192 {
193  if (mgr == 0)
194  return operator new[](numbytes);
195  return mgr->AllocateBuffer(numbytes,memtype);
196 }
197 
198 inline void operator delete[](void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
199 {
200  if (mgr == 0)
201  operator delete[](buffer);
202  else
203  mgr->FreeBuffer(buffer);
204 }
205 #endif // RTP_HAVE_ARRAYALLOC
206 
207 namespace jrtplib
208 {
209 
210 inline void RTPDeleteByteArray(uint8_t *buf, RTPMemoryManager *mgr)
211 {
212  if (mgr == 0)
213  delete [] buf;
214  else
215  mgr->FreeBuffer(buf);
216 }
217 
218 template<class ClassName>
219 inline void RTPDelete(ClassName *obj, RTPMemoryManager *mgr)
220 {
221  if (mgr == 0)
222  delete obj;
223  else
224  {
225  obj->~ClassName();
226  mgr->FreeBuffer(obj);
227  }
228 }
229 
230 } // end namespace
231 
232 #define RTPNew(a,b) new(a,b)
233 
234 #else
235 
236 #define RTPNew(a,b) new
237 #define RTPDelete(a,b) delete a
238 #define RTPDeleteByteArray(a,b) delete [] a;
239 
240 #endif // RTP_SUPPORT_MEMORYMANAGEMENT
241 
242 #endif // RTPMEMORYMANAGER_H
243 
A memory manager.
Definition: rtpmemorymanager.h:150
virtual void * AllocateBuffer(size_t numbytes, int memtype)=0
Called to allocate numbytes of memory.