JRTPLIB  3.11.1
rtpmemorymanager.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 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  JRTPLIB_UNUSED(memtype);
185  if (mgr == 0)
186  operator delete(buffer);
187  else
188  mgr->FreeBuffer(buffer);
189 }
190 
191 #ifdef RTP_HAVE_ARRAYALLOC
192 inline void *operator new[](size_t numbytes, jrtplib::RTPMemoryManager *mgr, int memtype)
193 {
194  if (mgr == 0)
195  return operator new[](numbytes);
196  return mgr->AllocateBuffer(numbytes,memtype);
197 }
198 
199 inline void operator delete[](void *buffer, jrtplib::RTPMemoryManager *mgr, int memtype)
200 {
201  JRTPLIB_UNUSED(memtype);
202  if (mgr == 0)
203  operator delete[](buffer);
204  else
205  mgr->FreeBuffer(buffer);
206 }
207 #endif // RTP_HAVE_ARRAYALLOC
208 
209 namespace jrtplib
210 {
211 
212 inline void RTPDeleteByteArray(uint8_t *buf, RTPMemoryManager *mgr)
213 {
214  if (mgr == 0)
215  delete [] buf;
216  else
217  mgr->FreeBuffer(buf);
218 }
219 
220 template<class ClassName>
221 inline void RTPDelete(ClassName *obj, RTPMemoryManager *mgr)
222 {
223  if (mgr == 0)
224  delete obj;
225  else
226  {
227  obj->~ClassName();
228  mgr->FreeBuffer(obj);
229  }
230 }
231 
232 } // end namespace
233 
234 #define RTPNew(a,b) new(a,b)
235 
236 #else
237 
238 #define RTPNew(a,b) new
239 #define RTPDelete(a,b) delete a
240 #define RTPDeleteByteArray(a,b) delete [] a;
241 
242 #endif // RTP_SUPPORT_MEMORYMANAGEMENT
243 
244 #endif // RTPMEMORYMANAGER_H
245 
Definition: rtpfaketransmitter.h:64
A memory manager.
Definition: rtpmemorymanager.h:150
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.