Revert "use aligned_alloc() instead of _aligned_malloc_normal_buffer_type()" 26/47026/1 tizen_3.0.m1_mobile tizen_3.0.m1_tv accepted/tizen/mobile/20150829.030043 accepted/tizen/tv/20150829.030831 accepted/tizen/wearable/20150829.031433 submit/tizen/20150828.091521 submit/tizen_common/20151015.190624 submit/tizen_common/20151019.135620 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release tizen_3.0.m2.a1_mobile_release tizen_3.0.m2.a1_tv_release
authorJihae Yi <jihae.yi@samsung.com>
Fri, 28 Aug 2015 07:46:58 +0000 (16:46 +0900)
committerJihae Yi <jihae.yi@samsung.com>
Fri, 28 Aug 2015 07:47:43 +0000 (16:47 +0900)
This reverts commit f946bff293e0832e5069c7019c2641f463fc5ec3.

Change-Id: I8effab8523d02ddac3d2d82d0b1e6ae12cc5f24d

src/media_packet.c

index e2e4da6d1a4638610dafa49464807a9ab058e074..0748503eb31cff7ab6d12af4c7c6c55a7deea88a 100755 (executable)
@@ -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;
+}
+