rtpmemorymanager.h

Go to the documentation of this file.
00001 /*
00002 
00003   This file is a part of JRTPLIB
00004   Copyright (c) 1999-2007 Jori Liesenborgs
00005 
00006   Contact: jori.liesenborgs@gmail.com
00007 
00008   This library was developed at the "Expertisecentrum Digitale Media"
00009   (http://www.edm.uhasselt.be), a research center of the Hasselt University
00010   (http://www.uhasselt.be). The library is based upon work done for 
00011   my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
00012 
00013   Permission is hereby granted, free of charge, to any person obtaining a
00014   copy of this software and associated documentation files (the "Software"),
00015   to deal in the Software without restriction, including without limitation
00016   the rights to use, copy, modify, merge, publish, distribute, sublicense,
00017   and/or sell copies of the Software, and to permit persons to whom the
00018   Software is furnished to do so, subject to the following conditions:
00019 
00020   The above copyright notice and this permission notice shall be included
00021   in all copies or substantial portions of the Software.
00022 
00023   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00024   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00026   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00028   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00029   IN THE SOFTWARE.
00030 
00031 */
00032 
00037 #ifndef RTPMEMORYMANAGER_H
00038 
00039 #define RTPMEMORYMANAGER_H
00040 
00041 #include "rtpconfig.h"
00042 #include "rtptypes.h"
00043 
00045 #define RTPMEM_TYPE_OTHER                                                       0
00046 
00048 #define RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET                                    1
00049 
00051 #define RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET                                   2
00052 
00054 #define RTPMEM_TYPE_BUFFER_RTCPAPPPACKET                                        3
00055 
00057 #define RTPMEM_TYPE_BUFFER_RTCPBYEPACKET                                        4
00058 
00060 #define RTPMEM_TYPE_BUFFER_RTCPBYEREASON                                        5
00061 
00063 #define RTPMEM_TYPE_BUFFER_RTCPCOMPOUNDPACKET                                   6
00064 
00066 #define RTPMEM_TYPE_BUFFER_RTCPSDESBLOCK                                        7
00067 
00069 #define RTPMEM_TYPE_BUFFER_RTPPACKET                                            8
00070 
00072 #define RTPMEM_TYPE_BUFFER_RTPPACKETBUILDERBUFFER                               9
00073 
00075 #define RTPMEM_TYPE_BUFFER_SDESITEM                                             10
00076 
00078 #define RTPMEM_TYPE_CLASS_ACCEPTIGNOREHASHELEMENT                               11
00079 
00081 #define RTPMEM_TYPE_CLASS_ACCEPTIGNOREPORTINFO                                  12
00082 
00084 #define RTPMEM_TYPE_CLASS_DESTINATIONLISTHASHELEMENT                            13
00085 
00087 #define RTPMEM_TYPE_CLASS_MULTICASTHASHELEMENT                                  14
00088 
00090 #define RTPMEM_TYPE_CLASS_RTCPAPPPACKET                                         15
00091 
00093 #define RTPMEM_TYPE_CLASS_RTCPBYEPACKET                                         16
00094 
00096 #define RTPMEM_TYPE_CLASS_RTCPCOMPOUNDPACKETBUILDER                             17
00097 
00099 #define RTPMEM_TYPE_CLASS_RTCPRECEIVERREPORT                                    18
00100 
00102 #define RTPMEM_TYPE_CLASS_RTCPRRPACKET                                          19
00103 
00105 #define RTPMEM_TYPE_CLASS_RTCPSDESPACKET                                        20
00106 
00108 #define RTPMEM_TYPE_CLASS_RTCPSRPACKET                                          21
00109 
00111 #define RTPMEM_TYPE_CLASS_RTCPUNKNOWNPACKET                                     22
00112 
00114 #define RTPMEM_TYPE_CLASS_RTPADDRESS                                            23
00115 
00117 #define RTPMEM_TYPE_CLASS_RTPINTERNALSOURCEDATA                                 24
00118 
00120 #define RTPMEM_TYPE_CLASS_RTPPACKET                                             25
00121 
00123 #define RTPMEM_TYPE_CLASS_RTPPOLLTHREAD                                         26
00124 
00126 #define RTPMEM_TYPE_CLASS_RTPRAWPACKET                                          27
00127 
00129 #define RTPMEM_TYPE_CLASS_RTPTRANSMISSIONINFO                                   28
00130 
00132 #define RTPMEM_TYPE_CLASS_RTPTRANSMITTER                                        29
00133 
00135 #define RTPMEM_TYPE_CLASS_SDESPRIVATEITEM                                       30
00136 
00138 #define RTPMEM_TYPE_CLASS_SDESSOURCE                                            31
00139 
00141 #define RTPMEM_TYPE_CLASS_SOURCETABLEHASHELEMENT                                32
00142 
00144 class RTPMemoryManager
00145 {
00146 public: 
00147         RTPMemoryManager()                                                                      { }
00148         virtual ~RTPMemoryManager()                                                             { }
00149         
00157         virtual void *AllocateBuffer(size_t numbytes, int memtype) = 0;
00158 
00160         virtual void FreeBuffer(void *buffer) = 0;
00161 };
00162 
00163 #ifdef RTP_SUPPORT_MEMORYMANAGEMENT     
00164 
00165 #include <new>
00166 
00167 inline void *operator new(size_t numbytes, RTPMemoryManager *mgr, int memtype)
00168 {
00169         if (mgr == 0)
00170                 return operator new(numbytes);
00171         return mgr->AllocateBuffer(numbytes,memtype);
00172 }
00173 
00174 inline void operator delete(void *buffer, RTPMemoryManager *mgr, int memtype)
00175 {
00176         if (mgr == 0)
00177                 operator delete(buffer);
00178         else
00179                 mgr->FreeBuffer(buffer);
00180 }
00181 
00182 #if defined(WIN32) || defined(_WIN32_WCE)
00183 #if _MSC_VER >= 1300
00184 inline void *operator new[](size_t numbytes, RTPMemoryManager *mgr, int memtype)
00185 {
00186         if (mgr == 0)
00187                 return operator new[](numbytes);
00188         return mgr->AllocateBuffer(numbytes,memtype);
00189 }
00190 
00191 inline void operator delete[](void *buffer, RTPMemoryManager *mgr, int memtype)
00192 {
00193         if (mgr == 0)
00194                 operator delete[](buffer);
00195         else
00196                 mgr->FreeBuffer(buffer);
00197 }
00198 #endif // _MSC_VER >= 1300
00199 #else
00200 inline void *operator new[](size_t numbytes, RTPMemoryManager *mgr, int memtype)
00201 {
00202         if (mgr == 0)
00203                 return operator new[](numbytes);
00204         return mgr->AllocateBuffer(numbytes,memtype);
00205 }
00206 
00207 inline void operator delete[](void *buffer, RTPMemoryManager *mgr, int memtype)
00208 {
00209         if (mgr == 0)
00210                 operator delete[](buffer);
00211         else
00212                 mgr->FreeBuffer(buffer);
00213 }
00214 #endif // WIN32 || _WIN32_WCE
00215 
00216 inline void RTPDeleteByteArray(uint8_t *buf, RTPMemoryManager *mgr)
00217 {
00218         if (mgr == 0)
00219                 delete [] buf;
00220         else
00221                 mgr->FreeBuffer(buf);
00222 }
00223 
00224 template<class ClassName> 
00225 inline void RTPDelete(ClassName *obj, RTPMemoryManager *mgr)
00226 {
00227         if (mgr == 0)
00228                 delete obj;
00229         else
00230         {
00231                 obj->~ClassName();
00232                 mgr->FreeBuffer(obj);
00233         }
00234 }
00235 
00236 #define RTPNew(a,b)                     new(a,b)
00237 
00238 #else
00239 
00240 #define RTPNew(a,b)                     new
00241 #define RTPDelete(a,b)                  delete a
00242 #define RTPDeleteByteArray(a,b)         delete [] a;
00243 
00244 #endif // RTP_SUPPORT_MEMORYMANAGEMENT
00245 
00246 #endif // RTPMEMORYMANAGER_H
00247 

Generated on Thu Feb 8 16:22:05 2007 for jrtplib by  doxygen 1.5.1