1 /* 2 * OMAP3430 support 3 * 4 * Author: Michael Barabanov <michael.barabanov (at) windriver.com> 5 * Author: Srini Gosangi <srini.gosangi (at) windriver.com> 6 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 16 * express or implied. 17 * See the License for the specific language governing permissions 18 */ 19 20 /* ------------------------------------------------------------------ 21 * Copyright (C) 2008 PacketVideo 22 * 23 * Licensed under the Apache License, Version 2.0 (the "License"); 24 * you may not use this file except in compliance with the License. 25 * You may obtain a copy of the License at 26 * 27 * http://www.apache.org/licenses/LICENSE-2.0 28 * 29 * Unless required by applicable law or agreed to in writing, software 30 * distributed under the License is distributed on an "AS IS" BASIS, 31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 32 * express or implied. 33 * See the License for the specific language governing permissions 34 * and limitations under the License. 35 * ------------------------------------------------------------------- 36 */ 37 38 #define LOG_NDEBUG 0 39 #define LOG_TAG "BufferAllocOmap34xx" 40 #include <utils/Log.h> 41 42 #include "buffer_alloc_omap34xx.h" 43 #include "oscl_mem.h" // needed for oscl_malloc / oscl_free 44 45 /* based on test code in pvmi/media_io/pvmiofileoutput/src/pvmi_media_io_fileoutput.cpp */ 46 47 BufferAllocOmap34xx::BufferAllocOmap34xx(): refCount(0), bufferSize(0), maxBuffers(4), numAllocated(0) 48 { 49 } 50 51 BufferAllocOmap34xx::~BufferAllocOmap34xx() 52 { 53 54 } 55 56 OSCL_EXPORT_REF void BufferAllocOmap34xx::addRef() 57 { 58 ++refCount; 59 } 60 61 OSCL_EXPORT_REF void BufferAllocOmap34xx::removeRef() 62 { 63 --refCount; 64 if (refCount <= 0) 65 { 66 LOGV("BufferAllocOmap34xx::removeRef()"); 67 // this->~BufferAllocOmap34xx(); 68 } 69 } 70 71 72 OSCL_EXPORT_REF OsclAny* BufferAllocOmap34xx::allocate() 73 { 74 if (numAllocated < maxBuffers) 75 { 76 OsclAny* ptr = buffer_address[numAllocated]; 77 if (ptr) ++numAllocated; 78 return ptr; 79 } 80 return NULL; 81 } 82 83 OSCL_EXPORT_REF void BufferAllocOmap34xx::deallocate(OsclAny* ptr) 84 { 85 if (ptr) 86 { 87 --numAllocated; 88 } 89 } 90 91 OSCL_EXPORT_REF uint32 BufferAllocOmap34xx::getBufferSize() 92 { 93 return bufferSize; 94 } 95 96 OSCL_EXPORT_REF uint32 BufferAllocOmap34xx::getNumBuffers() 97 { 98 return maxBuffers; 99 } 100 101 102 OSCL_EXPORT_REF bool BufferAllocOmap34xx::queryInterface(const PVUuid& uuid, PVInterface*& aInterface) 103 { 104 aInterface = NULL; // initialize aInterface to NULL in case uuid is not supported 105 106 if (PVMFFixedSizeBufferAllocUUID == uuid) 107 { 108 // Send back ptr to the allocator interface object 109 PVMFFixedSizeBufferAlloc* myInterface = OSCL_STATIC_CAST(PVMFFixedSizeBufferAlloc*, this); 110 refCount++; // increment interface refcount before returning ptr 111 aInterface = OSCL_STATIC_CAST(PVInterface*, myInterface); 112 return true; 113 } 114 return false; 115 } 116