1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 // -*- c++ -*- 19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 20 21 // P V M F _ M E M P O O L 22 23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 24 25 26 27 /*! \file pvmf_mempool.h 28 \brief This file contains the implementation of memory pool allocator 29 */ 30 31 32 #ifndef PVMF_MEMPOOL_H_INCLUDED 33 #define PVMF_MEMPOOL_H_INCLUDED 34 35 #ifndef OSCL_MEM_H_INCLUDED 36 #include "oscl_mem.h" 37 #endif 38 39 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED 40 #include "oscl_mem_mempool.h" 41 #endif 42 43 #ifndef OSCL_DEFALLOC_H_INCLUDED 44 #include "oscl_defalloc.h" 45 #endif 46 47 #ifndef OSCL_VECTOR_H_INCLUDED 48 #include "oscl_vector.h" 49 #endif 50 51 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED 52 #include "oscl_string_containers.h" 53 #endif 54 55 #ifndef PVLOGGER_H_INCLUDED 56 #include "pvlogger.h" 57 #endif 58 59 #ifndef PVMF_MEDIA_CMD_H_INCLUDED 60 #include "pvmf_media_cmd.h" 61 #endif 62 63 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 64 #include "pvmf_media_data.h" 65 #endif 66 67 class PVMFMemPoolFixedChunkAllocator : public OsclMemPoolFixedChunkAllocator 68 { 69 public: 70 /** This API throws an exception when the memory allocation for pool fails 71 * If numchunk and chunksize parameters are not set, memory pool of 1 chunk will be created in the first call to allocate. 72 * The chunk size will be set to the n passed in for allocate(). 73 * If numchunk parameter is set to 0, the memory pool will use 1 for numchunk. 74 * 75 * @return void 76 * 77 */ 78 OSCL_IMPORT_REF PVMFMemPoolFixedChunkAllocator(const char* name = NULL, const uint32 numchunk = 1, const uint32 chunksize = 0, Oscl_DefAlloc* gen_alloc = NULL); 79 80 OSCL_IMPORT_REF virtual ~PVMFMemPoolFixedChunkAllocator(); 81 82 /** This API throws an exception when n is greater than the fixed chunk size or there are no free chunk available in the pool. 83 * If the memory pool hasn't been created yet, the pool will be created with chunk size equal to n so n must be greater than 0. Exception will be thrown if memory allocation for the memory pool fails. 84 * 85 * @return pointer to available chunk from memory pool 86 * 87 */ 88 OSCL_IMPORT_REF OsclAny* allocate(const uint32 n); 89 90 /** This API throws an exception when the pointer p passed in is not part of the memory pool. 91 * Exception will be thrown if the memory pool is not set up yet. 92 * 93 * @return void 94 * 95 */ 96 OSCL_IMPORT_REF void deallocate(OsclAny* p); 97 98 OSCL_IMPORT_REF void LogMediaDataInfo(PVMFSharedMediaDataPtr aMediaData); 99 100 OSCL_IMPORT_REF void LogMediaCmdInfo(PVMFSharedMediaCmdPtr aMediaCmd); 101 102 private: 103 void createmempool(); 104 105 OSCL_HeapString<OsclMemAllocator> iName; 106 PVLogger* iDatapathLogger; 107 OsclErrorTrapImp* iOsclErrorTrapImp; 108 }; 109 110 #endif 111 112 /*! @} */ 113