From: Jihae Yi Date: Fri, 28 Aug 2015 07:46:58 +0000 (+0900) Subject: Revert "use aligned_alloc() instead of _aligned_malloc_normal_buffer_type()" X-Git-Tag: submit/tizen/20150828.091521^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3e8bdb27a4d7da1926e96f985a04ec6cfc97c43;p=platform%2Fcore%2Fapi%2Fmediatool.git Revert "use aligned_alloc() instead of _aligned_malloc_normal_buffer_type()" This reverts commit f946bff293e0832e5069c7019c2641f463fc5ec3. Change-Id: I8effab8523d02ddac3d2d82d0b1e6ae12cc5f24d --- diff --git a/src/media_packet.c b/src/media_packet.c index e2e4da6..0748503 100755 --- a/src/media_packet.c +++ b/src/media_packet.c @@ -31,8 +31,9 @@ static int _pkt_alloc_buffer(media_packet_s* pkt); static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt); static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt); static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_type); +static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment); +static void _aligned_free_normal_buffer_type (void* buffer_ptr); -#define ALIGNMENT 16 /* 16 bytes alignment */ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet) { @@ -285,7 +286,7 @@ int _pkt_alloc_buffer(media_packet_s* pkt) { buffersize = _pkt_calculate_video_buffer_size(pkt); // 16bytes aligned malloc - pkt->data = aligned_alloc(ALIGNMENT, (size_t)buffersize); + pkt->data = _aligned_malloc_normal_buffer_type(buffersize, 16); if (!pkt->data) { return MEDIA_PACKET_ERROR_OUT_OF_MEMORY; @@ -1346,7 +1347,7 @@ int media_packet_destroy(media_packet_h packet) { if(handle->data) { - free(handle->data); + _aligned_free_normal_buffer_type(handle->data); handle->data = NULL; } } @@ -1425,3 +1426,42 @@ static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_ty return tbm_format; } + +static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment) +{ + unsigned char* buffer_ptr; + unsigned char* temp_ptr; + + if((temp_ptr = (unsigned char*)malloc(size + alignment)) != NULL) + { + buffer_ptr = (unsigned char*)((unsigned long int)(temp_ptr + alignment - 1) & (~(unsigned long int)(alignment -1))); + + if(buffer_ptr == temp_ptr) + { + buffer_ptr += alignment; + } + + *(buffer_ptr - 1) = (unsigned char)(buffer_ptr - temp_ptr); + return (void*)buffer_ptr; + } + + return NULL; +} + +static void _aligned_free_normal_buffer_type (void* buffer_ptr) +{ + unsigned char* ptr; + if (buffer_ptr == NULL) + return; + + ptr = (unsigned char*)buffer_ptr; + + // *(ptr - 1) holds the offset to the real allocated block + // we sub that offset os we free the real pointer + ptr -= *(ptr - 1); + + // Free the memory + free(ptr); + ptr = NULL; +} +