PVMp4FFComposerPort::~PVMp4FFComposerPort() { if (memfrag_sps) { for (uint32 i = 0; i < iNode->memvector_sps.size(); i++) { OSCL_FREE(iNode->memvector_sps[i]->ptr); } while (!iNode->memvector_sps.empty()) { if (iNode->memvector_sps.front()) { OSCL_FREE(iNode->memvector_sps.front()); } iNode->memvector_sps.erase(&iNode->memvector_sps.front()); } } if (memfrag_pps) { for (uint32 i = 0; i < iNode->memvector_pps.size(); i++) { OSCL_FREE(iNode->memvector_pps[i]->ptr); } while (!iNode->memvector_pps.empty()) { if (iNode->memvector_pps.front()) { OSCL_FREE(iNode->memvector_pps.front()); } iNode->memvector_pps.erase(&iNode->memvector_pps.front()); } } if (iNode->textdecodervector.size() > 0) { while (!iNode->textdecodervector.empty()) { if (iNode->textdecodervector.front()) { OSCL_DELETE(iNode->textdecodervector.front()); } iNode->textdecodervector.erase(&iNode->textdecodervector.front()); } } Disconnect(); ClearMsgQueues(); // we need to clear the activity handler, since otherwise the PvmfPortBaseImpl destructor // ends up calling back onto our HandlePortActivity method, which no longer exists because // this objects's destructor has already been called. SetActivityHandler(NULL); }
bool AVCSampleEntry::createDecoderSpecificInfo(MP4_FF_FILE *fp) { uint32 numSPS = getNumSequenceParamSets(); uint32 numPPS = getNumPictureParamSets(); uint32 totalSPSLen = getTotalSeqParameterSetLength(); uint32 totalPPSLen = getTotalPictureParameterSetLength(); uint32 len = (numSPS * 2) + (numPPS * 2) + totalSPSLen + totalPPSLen; if ((int32)len > 0) { PV_MP4_FF_NEW(fp->auditCB, DecoderSpecificInfo, (fp, true), _decoderSpecificInfo); uint8* info = (uint8*)(oscl_malloc(sizeof(uint8) * len)); if (!info) return false; // malloc failed (unlikely) uint8* destPtr = info; if (numSPS > 0) { for (uint32 i = 0; i < numSPS; i++) { uint16 len = 0; uint8* ptr = NULL; if (getSequenceParamSet(i, len, ptr) == false) { OSCL_FREE(info); return false; } oscl_memcpy(destPtr, &len, sizeof(uint16)); destPtr += sizeof(uint16); oscl_memcpy(destPtr, ptr, len); destPtr += len; } } if (numPPS > 0) { for (uint32 i = 0; i < numPPS; i++) { uint16 len = 0; uint8* ptr = NULL; if (getPictureParamSet(i, len, ptr) == false) { OSCL_FREE(info); return false; } oscl_memcpy(destPtr, &len, sizeof(uint16)); destPtr += sizeof(uint16); oscl_memcpy(destPtr, ptr, len); destPtr += len; } } _decoderSpecificInfo->setInfoSize(len); _decoderSpecificInfo->setInfo(info); } return true; }
OSCL_EXPORT_REF void ThreadSafeMemPoolFixedChunkAllocator::destroymempool() { // If ref count reaches 0 then destroy this object if (iRefCount <= 0) { #if OSCL_MEM_CHECK_ALL_MEMPOOL_CHUNKS_ARE_RETURNED // Assert if all of the chunks were not returned OSCL_ASSERT(iFreeMemChunkList.size() == iNumChunk); #endif iFreeMemChunkList.clear(); if (iMemPool) { if (iMemPoolAllocator) { iMemPoolAllocator->deallocate(iMemPool); } else { OSCL_FREE(iMemPool); } iMemPool = NULL; } } }
// Destructor PVA_FF_FontRecord::~PVA_FF_FontRecord() { if (_pFontName) { OSCL_FREE(_pFontName); _pFontName = NULL; } }
int32 OsclFileCache::Open(uint32 mode, uint32 size) //Called to open the cache for a newly opened file. //The NativeOpen was just called prior to this and was successful. { //should not be called with zero-size cache. OSCL_ASSERT(size > 0); //Save the mode _mode = mode; //open logger object only if logging is enabled on this //file if (iContainer.iLogger) iLogger = PVLogger::GetLoggerObject("OsclFileCache"); else iLogger = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open mode %d size %d", this, mode, size)); // Create the movable cache. // Re-allocate it if the size has changed. if (_movableCache.pBuffer && size != _movableCache.capacity) { OSCL_FREE(_movableCache.pBuffer); _movableCache.pBuffer = NULL; } if (!_movableCache.pBuffer && size > 0) { _movableCache.pBuffer = (uint8*)OSCL_MALLOC(size); } if (!_movableCache.pBuffer) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open ERROR no memory %d", this)); return (-1);//error } _movableCache.capacity = _movableCache.usableSize = size; _movableCache.filePosition = 0; _movableCache.updateStart = _movableCache.updateEnd = 0; _movableCache.currentPos = _movableCache.endPos = 0; //Position the cache at zero. SetCachePosition(0); //get initial file size & native position PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open CallingNativeSize", this)); _fileSize = iContainer.CallNativeSize(); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open CallingNativeTell", this)); _nativePosition = iContainer.CallNativeTell(); return 0; }
int32 OsclFileCache::UpdateFixedCaches() //Process any queued requests to remove or add fixed caches. { int32 error = 0; if (iContainer.iRemoveFixedCache.size()) { for (uint32 i = 0; i < iContainer.iRemoveFixedCache.size(); i++) { for (uint32 j = 0; j < _fixedCaches.size(); j++) { if (_fixedCaches[j].filePosition < iContainer.iRemoveFixedCache[i]) { //fixed cache list is sorted, so we can end search now. break; } else if (_fixedCaches[j].filePosition == iContainer.iRemoveFixedCache[i]) { //found it if (_fixedCaches[j].IsUpdated()) { int32 result = _fixedCaches[j].WriteUpdatesToFile(); if (result != 0) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::UpdateFixedCaches ERROR in WriteUpdatesToFile", this)); error = result; } } if (_fixedCaches[j].pBuffer) { OSCL_FREE(_fixedCaches[j].pBuffer); _fixedCaches[j].pBuffer = NULL; } _fixedCaches.erase(&_fixedCaches[j]); break; } } } iContainer.iRemoveFixedCache.clear(); } if (iContainer.iAddFixedCache.size()) { for (uint32 i = 0; i < iContainer.iAddFixedCache.size(); i++) { if (!AddFixedCache(iContainer.iAddFixedCache[i])) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::UpdateFixedCaches ERROR in AddFixedCache", this)); error = (-1); } } iContainer.iAddFixedCache.clear(); } return error; }
OSCL_EXPORT_REF PVMFOMXDecPort::~PVMFOMXDecPort() { if (iTrackConfig != NULL) { OSCL_FREE(iTrackConfig); iTrackConfigSize = 0; } Disconnect(); ClearMsgQueues(); }
// Destructor PVA_FF_TextSampleEntry::~PVA_FF_TextSampleEntry() { if (_pBackgroundRGBA) { OSCL_FREE(_pBackgroundRGBA); _pBackgroundRGBA = NULL; } PV_MP4_FF_DELETE(NULL, PVA_FF_BoxRecord, _pBoxRecord); PV_MP4_FF_DELETE(NULL, PVA_FF_StyleRecord, _pStyleRecord); PV_MP4_FF_DELETE(NULL, PVA_FF_FontTableAtom, _pFontTableAtom); }
void OsclFileCache::Close() { //flush any cache updates SetCachePosition(0); //free the memory for cache buffer if (_pCacheBufferStart) { OSCL_FREE(_pCacheBufferStart); _pCacheBufferStart = NULL; } }
OSCL_EXPORT_REF void ThreadSafeMemPoolFixedChunkAllocator::Delete() { this->~ThreadSafeMemPoolFixedChunkAllocator(); if (iMemPoolAllocator) { iMemPoolAllocator->deallocate(this); } else { OSCL_FREE(this); } }
void OsclFileCache::Close() { //flush any cache updates & free the buffers if (_movableCache.pBuffer) { _movableCache.WriteUpdatesToFile(); OSCL_FREE(_movableCache.pBuffer); _movableCache.pBuffer = NULL; _movableCache.capacity = _movableCache.usableSize = 0; } for (uint32 i = 0; i < _fixedCaches.size(); i++) { _fixedCaches[i].WriteUpdatesToFile(); if (_fixedCaches[i].pBuffer) { OSCL_FREE(_fixedCaches[i].pBuffer); _fixedCaches[i].pBuffer = NULL; _fixedCaches[i].capacity = _fixedCaches[i].usableSize = 0; } } _fixedCaches.clear(); }
int32 OsclFileCache::Open(uint32 mode, uint32 size) //Called to open the cache for a newly opened file. //The NativeOpen was just called prior to this and was successful. { //should not be called with zero-size cache. OSCL_ASSERT(size > 0); //Save the open parameters _cacheSize = size; _mode = mode; //open logger object only if logging is enabled on this //file if (iContainer.iLogger) iLogger = PVLogger::GetLoggerObject("OsclFileCache"); else iLogger = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open mode %d size %d", this, mode, size)); // allocate memory for cache // free any old buffer since its size may be different if (_pCacheBufferStart) { OSCL_FREE(_pCacheBufferStart); _pCacheBufferStart = NULL; } _pCacheBufferStart = (uint8*)OSCL_MALLOC(_cacheSize); if (!_pCacheBufferStart) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Open ERROR no memory %d", this)); return (-1);//error } //initialise the cache variables SetCachePosition(0); //get initial file size & native position _fileSize = iContainer.CallNativeSize(); _nativePosition = iContainer.CallNativeTell(); return 0; }
void OsclMemPoolResizableAllocator::destroyallmempoolbuffers() { while (iMemPoolBufferList.empty() == false) { MemPoolBufferInfo* bufferinfo = iMemPoolBufferList[0]; // Check the buffer OSCL_ASSERT(bufferinfo != NULL); OSCL_ASSERT(bufferinfo->iBufferPreFence == OSCLMEMPOOLRESIZABLEALLOCATOR_PREFENCE_PATTERN); OSCL_ASSERT(bufferinfo->iBufferPostFence == OSCLMEMPOOLRESIZABLEALLOCATOR_POSTFENCE_PATTERN); OSCL_ASSERT(bufferinfo->iNumOutstanding == 0); // Free the memory if (iMemPoolBufferAllocator) { iMemPoolBufferAllocator->deallocate((OsclAny*)bufferinfo); } else { OSCL_FREE((OsclAny*)bufferinfo); } iMemPoolBufferList.erase(iMemPoolBufferList.begin()); } }
// Destructor PVA_FF_DecoderSpecificInfo::~PVA_FF_DecoderSpecificInfo() { OSCL_FREE(_pinfo); _pinfo = NULL; }
OSCL_EXPORT_REF OsclAny* OsclMemPoolResizableAllocator::allocate(const uint32 aNumBytes) { MemPoolBlockInfo* freeblock = NULL; uint32 alignednumbytes = oscl_mem_aligned_size(aNumBytes); if (aNumBytes == 0) { OSCL_LEAVE(OsclErrArgument); // OSCL_UNUSED_RETURN(NULL); This statement was removed to avoid compiler warning for Unreachable Code } // Find a free block that would accomodate the requested size with a block info header freeblock = findfreeblock(alignednumbytes + iBlockInfoAlignedSize); if (freeblock == NULL) { //We could not find a free buffer of requested size. This could be due to: //1) We have not created even a single parent chunk (or in other words this is the first allocation) //2) We are out of memory and might need to expand // Check if the requested size is bigger than the specified buffer size // Some of the users of this allocator, count on the allocator to expand beyond the original size // specified in the constructor. These users do NOT use setMaxSzForNewMemPoolBuffer to control expansion size. // If they did then it is wrong usage and we fail the allocation. // For example the allocator was intialized with 200KB size, // and overtime a request is made for say 300KB. Users of the allocator expect the allocator to do one of the following: // 1) If iMemPoolBufferNumLimit has been set and it has been reached then see // if one of older blocks can be freed up and we allocate a new block of 300KB. If we cannot then alloc will fail. // 2) If iMemPoolBufferNumLimit has not set then simply allocate a new block of 300 KB. Note that if iMemPoolBufferNumLimit // is not set allocator expands indefinitely. if (alignednumbytes > iMemPoolBufferSize) { if (iMaxNewMemPoolBufferSz != 0) { //wrong usage - fail allocation if (iEnableNullPtrReturn) { return NULL; } else { // Leave with resource limitation OSCL_LEAVE(OsclErrNoResources); } } // Would need to create a new buffer to accomodate this request // Check if another buffer can be created if (iMemPoolBufferNumLimit > 0 && iMemPoolBufferList.size() >= iMemPoolBufferNumLimit) { // Check if there is a memory pool buffer that has no outstanding buffers // If present then remove it so a new one can be added bool emptybufferfound = false; for (uint32 j = 0; j < iMemPoolBufferList.size(); ++j) { if (iMemPoolBufferList[j]->iNumOutstanding == 0) { // Free the memory if (iMemPoolBufferAllocator) { iMemPoolBufferAllocator->deallocate((OsclAny*)iMemPoolBufferList[j]); } else { OSCL_FREE((OsclAny*)iMemPoolBufferList[j]); } // Remove the mempool buffer from the list iMemPoolBufferList.erase(iMemPoolBufferList.begin() + j); emptybufferfound = true; break; } } // Need to leave and return if empty buffer not found if (!emptybufferfound) { if (iEnableNullPtrReturn) { return NULL; } else { // Leave with resource limitation OSCL_LEAVE(OsclErrNoResources); } } // Continue on to create a new buffer OSCL_ASSERT(iMemPoolBufferList.size() < iMemPoolBufferNumLimit); } // Determine the size of memory pool buffer and create one uint32 buffersize = alignednumbytes + iBufferInfoAlignedSize; if (iExpectedNumBlocksPerBuffer > 0) { buffersize += (iExpectedNumBlocksPerBuffer * iBlockInfoAlignedSize); } else { buffersize += (OSCLMEMPOOLRESIZABLEALLOCATOR_DEFAULT_NUMBLOCKPERBUFFER * iBlockInfoAlignedSize); } MemPoolBufferInfo* newbuffer = addnewmempoolbuffer(buffersize); OSCL_ASSERT(newbuffer != NULL); OSCL_ASSERT(newbuffer->iNextFreeBlock != NULL); freeblock = (MemPoolBlockInfo*)(newbuffer->iNextFreeBlock); OSCL_ASSERT(freeblock != NULL); OSCL_ASSERT(freeblock->iBlockSize >= alignednumbytes); } else { // Check if another buffer can be created if (iMemPoolBufferNumLimit > 0 && iMemPoolBufferList.size() >= iMemPoolBufferNumLimit) { if (iEnableNullPtrReturn) { return NULL; } else { // Leave with resource limitation OSCL_LEAVE(OsclErrNoResources); } } // Determine the size of memory pool buffer and create one // By default this allocator expands by iMemPoolBufferSize. // iMaxNewMemPoolBufferSz could specify the amount by which this allocator expands. // setMaxSzForNewMemPoolBuffer API can be used to control the expansion size. uint32 expansion_size = iMemPoolBufferSize; if (iMaxNewMemPoolBufferSz != 0) { expansion_size = iMaxNewMemPoolBufferSz; } //if alignednumbytes is larger than expansion_size, we cannot satisfy the request, so fail the allocation if (alignednumbytes > expansion_size) { if (iEnableNullPtrReturn) { return NULL; } else { // Leave with resource limitation OSCL_LEAVE(OsclErrNoResources); } } uint32 buffersize = oscl_mem_aligned_size(expansion_size) + iBufferInfoAlignedSize; if (iExpectedNumBlocksPerBuffer > 0) { buffersize += (iExpectedNumBlocksPerBuffer * iBlockInfoAlignedSize); } else { buffersize += (OSCLMEMPOOLRESIZABLEALLOCATOR_DEFAULT_NUMBLOCKPERBUFFER * iBlockInfoAlignedSize); } MemPoolBufferInfo* newbuffer = addnewmempoolbuffer(buffersize); OSCL_ASSERT(newbuffer != NULL); OSCL_ASSERT(newbuffer->iNextFreeBlock != NULL); freeblock = (MemPoolBlockInfo*)(newbuffer->iNextFreeBlock); OSCL_ASSERT(freeblock != NULL); OSCL_ASSERT(freeblock->iBlockSize >= alignednumbytes); } } // Use the free block and return the buffer pointer OsclAny* bufptr = allocateblock(*freeblock, alignednumbytes); if (bufptr) { addRef(); ++(freeblock->iParentBuffer->iNumOutstanding); } return bufptr; }