From 23da4cf305b9bfff07954711a8a2d9ec040865af Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 13 Apr 2012 14:15:08 +0300 Subject: [PATCH] avcenc: Switch malloc/free callbacks to use pointers instead of ints There is no reason for casting the pointers to ints. This fixes building the code on platforms where pointers are larger than ints, e.g. 64 bit platforms. Change-Id: I910cd207d0908287931c9a96eb270139967e029b --- .../codecs/avc/common/include/avcapi_common.h | 8 +++--- media/libstagefright/codecs/avc/common/src/dpb.cpp | 8 +++--- .../codecs/avc/enc/SoftAVCEncoder.cpp | 8 +++--- .../codecs/avc/enc/src/avcenc_api.cpp | 32 +++++++++++----------- .../codecs/avc/enc/src/bitstream_io.cpp | 4 +-- .../codecs/avc/enc/src/motion_est.cpp | 2 +- .../codecs/avc/enc/src/rate_control.cpp | 8 +++--- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/media/libstagefright/codecs/avc/common/include/avcapi_common.h b/media/libstagefright/codecs/avc/common/include/avcapi_common.h index 3331689054..001c1a1229 100644 --- a/media/libstagefright/codecs/avc/common/include/avcapi_common.h +++ b/media/libstagefright/codecs/avc/common/include/avcapi_common.h @@ -213,15 +213,15 @@ typedef void (*FuctionType_FrameUnbind)(void *userData, int); memory usage. \param "size" "Size of requested memory in bytes." \param "attribute" "Some value specifying types, priority, etc. of the memory." -\return "The address of the allocated memory casted to int" +\return "The address of the allocated memory" */ -typedef int (*FunctionType_Malloc)(void *userData, int32 size, int attribute); +typedef void* (*FunctionType_Malloc)(void *userData, int32 size, int attribute); /** Function pointer to free -\param "mem" "Pointer to the memory to be freed casted to int" +\param "mem" "Pointer to the memory to be freed" \return "void" */ -typedef void (*FunctionType_Free)(void *userData, int mem); +typedef void (*FunctionType_Free)(void *userData, void *mem); /** Debug logging information is returned to the application thru this function. \param "type" "Type of logging message, see definition of AVCLogType." diff --git a/media/libstagefright/codecs/avc/common/src/dpb.cpp b/media/libstagefright/codecs/avc/common/src/dpb.cpp index 2c4c7da478..b5d0dfe06e 100644 --- a/media/libstagefright/codecs/avc/common/src/dpb.cpp +++ b/media/libstagefright/codecs/avc/common/src/dpb.cpp @@ -152,7 +152,7 @@ OSCL_EXPORT_REF AVCStatus AVCConfigureSequence(AVCHandle *avcHandle, AVCCommonOb framesize = (FrameHeightInMbs * PicWidthInMbs); if (video->mblock) { - avcHandle->CBAVC_Free(userData, (uint32)video->mblock); + avcHandle->CBAVC_Free(userData, video->mblock); video->mblock = NULL; } video->mblock = (AVCMacroblock*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCMacroblock) * framesize, DEFAULT_ATTR); @@ -187,7 +187,7 @@ OSCL_EXPORT_REF AVCStatus AVCConfigureSequence(AVCHandle *avcHandle, AVCCommonOb if (video->MbToSliceGroupMap) { - avcHandle->CBAVC_Free(userData, (uint32)video->MbToSliceGroupMap); + avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap); video->MbToSliceGroupMap = NULL; } video->MbToSliceGroupMap = (int*) avcHandle->CBAVC_Malloc(userData, sizeof(uint) * PicSizeInMapUnits * 2, 7/*DEFAULT_ATTR*/); @@ -212,14 +212,14 @@ OSCL_EXPORT_REF AVCStatus CleanUpDPB(AVCHandle *avcHandle, AVCCommonObj *video) { if (dpb->fs[ii] != NULL) { - avcHandle->CBAVC_Free(userData, (int)dpb->fs[ii]); + avcHandle->CBAVC_Free(userData, dpb->fs[ii]); dpb->fs[ii] = NULL; } } #ifndef PV_MEMORY_POOL if (dpb->decoded_picture_buffer) { - avcHandle->CBAVC_Free(userData, (int)dpb->decoded_picture_buffer); + avcHandle->CBAVC_Free(userData, dpb->decoded_picture_buffer); dpb->decoded_picture_buffer = NULL; } #endif diff --git a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp index c6f658daf9..9fedaced2a 100644 --- a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp +++ b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp @@ -131,13 +131,13 @@ inline static void ConvertYUV420SemiPlanarToYUV420Planar( } } -static int32_t MallocWrapper( +static void* MallocWrapper( void *userData, int32_t size, int32_t attrs) { - return reinterpret_cast(malloc(size)); + return malloc(size); } -static void FreeWrapper(void *userData, int32_t ptr) { - free(reinterpret_cast(ptr)); +static void FreeWrapper(void *userData, void* ptr) { + free(ptr); } static int32_t DpbAllocWrapper(void *userData, diff --git a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp index 6d43142961..3631536854 100644 --- a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp +++ b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp @@ -610,32 +610,32 @@ OSCL_EXPORT_REF void PVAVCCleanUpEncoder(AVCHandle *avcHandle) if (encvid->functionPointer != NULL) { - avcHandle->CBAVC_Free(userData, (int)encvid->functionPointer); + avcHandle->CBAVC_Free(userData, encvid->functionPointer); } if (encvid->min_cost) { - avcHandle->CBAVC_Free(userData, (int)encvid->min_cost); + avcHandle->CBAVC_Free(userData, encvid->min_cost); } if (encvid->intraSearch) { - avcHandle->CBAVC_Free(userData, (int)encvid->intraSearch); + avcHandle->CBAVC_Free(userData, encvid->intraSearch); } if (encvid->mot16x16) { - avcHandle->CBAVC_Free(userData, (int)encvid->mot16x16); + avcHandle->CBAVC_Free(userData, encvid->mot16x16); } if (encvid->rateCtrl) { - avcHandle->CBAVC_Free(userData, (int)encvid->rateCtrl); + avcHandle->CBAVC_Free(userData, encvid->rateCtrl); } if (encvid->overrunBuffer) { - avcHandle->CBAVC_Free(userData, (int)encvid->overrunBuffer); + avcHandle->CBAVC_Free(userData, encvid->overrunBuffer); } video = encvid->common; @@ -643,45 +643,45 @@ OSCL_EXPORT_REF void PVAVCCleanUpEncoder(AVCHandle *avcHandle) { if (video->MbToSliceGroupMap) { - avcHandle->CBAVC_Free(userData, (int)video->MbToSliceGroupMap); + avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap); } if (video->mblock != NULL) { - avcHandle->CBAVC_Free(userData, (int)video->mblock); + avcHandle->CBAVC_Free(userData, video->mblock); } if (video->decPicBuf != NULL) { CleanUpDPB(avcHandle, video); - avcHandle->CBAVC_Free(userData, (int)video->decPicBuf); + avcHandle->CBAVC_Free(userData, video->decPicBuf); } if (video->sliceHdr != NULL) { - avcHandle->CBAVC_Free(userData, (int)video->sliceHdr); + avcHandle->CBAVC_Free(userData, video->sliceHdr); } if (video->currPicParams != NULL) { if (video->currPicParams->slice_group_id) { - avcHandle->CBAVC_Free(userData, (int)video->currPicParams->slice_group_id); + avcHandle->CBAVC_Free(userData, video->currPicParams->slice_group_id); } - avcHandle->CBAVC_Free(userData, (int)video->currPicParams); + avcHandle->CBAVC_Free(userData, video->currPicParams); } if (video->currSeqParams != NULL) { - avcHandle->CBAVC_Free(userData, (int)video->currSeqParams); + avcHandle->CBAVC_Free(userData, video->currSeqParams); } if (encvid->bitstream != NULL) { - avcHandle->CBAVC_Free(userData, (int)encvid->bitstream); + avcHandle->CBAVC_Free(userData, encvid->bitstream); } if (video != NULL) { - avcHandle->CBAVC_Free(userData, (int)video); + avcHandle->CBAVC_Free(userData, video); } } - avcHandle->CBAVC_Free(userData, (int)encvid); + avcHandle->CBAVC_Free(userData, encvid); avcHandle->AVCObject = NULL; } diff --git a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp index 75ab51433c..ed9fd8edd3 100644 --- a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp +++ b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp @@ -276,7 +276,7 @@ AVCEnc_Status AVCBitstreamUseOverrunBuffer(AVCEncBitstream* stream, int numExtra if (encvid->overrunBuffer) { encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData, - (int)encvid->overrunBuffer); + encvid->overrunBuffer); } encvid->oBSize = stream->oBSize; @@ -315,7 +315,7 @@ AVCEnc_Status AVCBitstreamUseOverrunBuffer(AVCEncBitstream* stream, int numExtra memcpy(encvid->overrunBuffer, stream->overrunBuffer, stream->write_pos); // free old buffer encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData, - (int)stream->overrunBuffer); + stream->overrunBuffer); // assign pointer to new buffer stream->overrunBuffer = encvid->overrunBuffer; diff --git a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp index f650ef9f5f..00c56c8ca2 100644 --- a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp +++ b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp @@ -176,7 +176,7 @@ void CleanMotionSearchModule(AVCHandle *avcHandle) if (encvid->mvbits_array) { - avcHandle->CBAVC_Free(avcHandle->userData, (int)(encvid->mvbits_array)); + avcHandle->CBAVC_Free(avcHandle->userData, encvid->mvbits_array); encvid->mvbits = NULL; } diff --git a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp index 15b55fb82a..50b764fb3d 100644 --- a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp +++ b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp @@ -300,7 +300,7 @@ void CleanupRateControlModule(AVCHandle *avcHandle) if (rateCtrl->MADofMB) { - avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->MADofMB)); + avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->MADofMB); } if (rateCtrl->pMP) @@ -311,12 +311,12 @@ void CleanupRateControlModule(AVCHandle *avcHandle) { if (rateCtrl->pMP->pRDSamples[i]) { - avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples[i]); + avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples[i]); } } - avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples); + avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples); } - avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->pMP)); + avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP); } return ; -- 2.11.0