jrtplib  3.6.0
rtpmemorymanager.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 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 
145 {
146 public:
147  RTPMemoryManager() { }
148  virtual ~RTPMemoryManager() { }
149 
157  virtual void *AllocateBuffer(size_t numbytes, int memtype) = 0;
158 
160  virtual void FreeBuffer(void *buffer) = 0;
161 };
162 
163 #ifdef RTP_SUPPORT_MEMORYMANAGEMENT
164 
165 #include <new>
166 
167 inline void *operator new(size_t numbytes, RTPMemoryManager *mgr, int memtype)
168 {
169  if (mgr == 0)
170  return operator new(numbytes);
171  return mgr->AllocateBuffer(numbytes,memtype);
172 }
173 
174 inline void operator delete(void *buffer, RTPMemoryManager *mgr, int memtype)
175 {
176  if (mgr == 0)
177  operator delete(buffer);
178  else
179  mgr->FreeBuffer(buffer);
180 }
181 
182 #if defined(WIN32) || defined(_WIN32_WCE)
183 #if _MSC_VER >= 1300
184 inline void *operator new[](size_t numbytes, RTPMemoryManager *mgr, int memtype)
185 {
186  if (mgr == 0)
187  return operator new[](numbytes);
188  return mgr->AllocateBuffer(numbytes,memtype);
189 }
190 
191 inline void operator delete[](void *buffer, RTPMemoryManager *mgr, int memtype)
192 {
193  if (mgr == 0)
194  operator delete[](buffer);
195  else
196  mgr->FreeBuffer(buffer);
197 }
198 #endif // _MSC_VER >= 1300
199 #else
200 inline void *operator new[](size_t numbytes, RTPMemoryManager *mgr, int memtype)
201 {
202  if (mgr == 0)
203  return operator new[](numbytes);
204  return mgr->AllocateBuffer(numbytes,memtype);
205 }
206 
207 inline void operator delete[](void *buffer, RTPMemoryManager *mgr, int memtype)
208 {
209  if (mgr == 0)
210  operator delete[](buffer);
211  else
212  mgr->FreeBuffer(buffer);
213 }
214 #endif // WIN32 || _WIN32_WCE
215 
216 inline void RTPDeleteByteArray(uint8_t *buf, RTPMemoryManager *mgr)
217 {
218  if (mgr == 0)
219  delete [] buf;
220  else
221  mgr->FreeBuffer(buf);
222 }
223 
224 template<class ClassName>
225 inline void RTPDelete(ClassName *obj, RTPMemoryManager *mgr)
226 {
227  if (mgr == 0)
228  delete obj;
229  else
230  {
231  obj->~ClassName();
232  mgr->FreeBuffer(obj);
233  }
234 }
235 
236 #define RTPNew(a,b) new(a,b)
237 
238 #else
239 
240 #define RTPNew(a,b) new
241 #define RTPDelete(a,b) delete a
242 #define RTPDeleteByteArray(a,b) delete [] a;
243 
244 #endif // RTP_SUPPORT_MEMORYMANAGEMENT
245 
246 #endif // RTPMEMORYMANAGER_H
247 
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.
A memory manager.
Definition: rtpmemorymanager.h:144