JRTPLIB  3.9.0
rtpmemorymanager.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2011 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 
143 namespace jrtplib
144 {
145 
148 {
149 public:
150  RTPMemoryManager() { }
151  virtual ~RTPMemoryManager() { }
152 
160  virtual void *AllocateBuffer(size_t numbytes, int memtype) = 0;
161 
163  virtual void FreeBuffer(void *buffer) = 0;
164 };
165 
166 } // end namespace
167 
168 #ifdef RTP_SUPPORT_MEMORYMANAGEMENT
169 
170 #include <new>
171 
172 inline void *operator new(size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
173 {
174  if (mgr == 0)
175  return operator new(numbytes);
176  return mgr->AllocateBuffer(numbytes,memtype);
177 }
178 
179 inline void operator delete(void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
180 {
181  if (mgr == 0)
182  operator delete(buffer);
183  else
184  mgr->FreeBuffer(buffer);
185 }
186 
187 #if defined(WIN32) || defined(_WIN32_WCE)
188 #if _MSC_VER >= 1300
189 inline void *operator new[](size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
190 {
191  if (mgr == 0)
192  return operator new[](numbytes);
193  return mgr->AllocateBuffer(numbytes,memtype);
194 }
195 
196 inline void operator delete[](void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
197 {
198  if (mgr == 0)
199  operator delete[](buffer);
200  else
201  mgr->FreeBuffer(buffer);
202 }
203 #endif // _MSC_VER >= 1300
204 #else
205 inline void *operator new[](size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
206 {
207  if (mgr == 0)
208  return operator new[](numbytes);
209  return mgr->AllocateBuffer(numbytes,memtype);
210 }
211 
212 inline void operator delete[](void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
213 {
214  if (mgr == 0)
215  operator delete[](buffer);
216  else
217  mgr->FreeBuffer(buffer);
218 }
219 #endif // WIN32 || _WIN32_WCE
220 
221 namespace jrtplib
222 {
223 
224 inline void RTPDeleteByteArray(uint8_t *buf, RTPMemoryManager *mgr)
225 {
226  if (mgr == 0)
227  delete [] buf;
228  else
229  mgr->FreeBuffer(buf);
230 }
231 
232 template<class ClassName>
233 inline void RTPDelete(ClassName *obj, RTPMemoryManager *mgr)
234 {
235  if (mgr == 0)
236  delete obj;
237  else
238  {
239  obj->~ClassName();
240  mgr->FreeBuffer(obj);
241  }
242 }
243 
244 } // end namespace
245 
246 #define RTPNew(a,b) new(a,b)
247 
248 #else
249 
250 #define RTPNew(a,b) new
251 #define RTPDelete(a,b) delete a
252 #define RTPDeleteByteArray(a,b) delete [] a;
253 
254 #endif // RTP_SUPPORT_MEMORYMANAGEMENT
255 
256 #endif // RTPMEMORYMANAGER_H
257 
A memory manager.
Definition: rtpmemorymanager.h:147
virtual void FreeBuffer(void *buffer)=0
Frees the previously allocated memory block buffer.
virtual void * AllocateBuffer(size_t numbytes, int memtype)=0
Called to allocate numbytes of memory.