[libmm-utility] optimize & improve mm-utility 92/42792/3 submit/tizen/20150703.010515
authorJi Yong Min <jiyong.min@samsung.com>
Thu, 2 Jul 2015 09:39:59 +0000 (18:39 +0900)
committerJi Yong Min <jiyong.min@samsung.com>
Thu, 2 Jul 2015 09:58:57 +0000 (18:58 +0900)
- Add to support NV12 format for encoding/decoding
- Add TTRACE performance check
- Modify to run transform repeatly
- Remove warning code

Change-Id: I62261a496f5564b6a952ffd12139b9f3ea2a24f9
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
configure.ac [changed mode: 0644->0755]
imgp/Makefile.am
imgp/include/mm_util_imgp.h
imgp/include/mm_util_imgp_internal.h
imgp/mm_util_imgp.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/Makefile.am [changed mode: 0644->0755]
jpeg/include/mm_util_jpeg.h
jpeg/mm_util_jpeg.c
packaging/libmm-utility.spec

old mode 100644 (file)
new mode 100755 (executable)
index f90a656..ddbe7d0
@@ -61,6 +61,9 @@ PKG_CHECK_MODULES(SYSTEMINFO, capi-system-info)
 AC_SUBST(SYSTEMINFO_CFLAGS)
 AC_SUBST(SYSTEMINFO_LIBS)
 
+PKG_CHECK_MODULES(TTRACE, [ttrace], AC_DEFINE(ENABLE_TTRACE, 1, [ttrace available]))
+AC_SUBST(TTRACE)
+
 #tz-platform-config lib
 PKG_CHECK_MODULES(TZ_PLATFORM_CONFIG, libtzplatform-config)
 AC_SUBST(TZ_PLATFORM_CONFIG_CFLAGS)
index 4196028e603c4c2d54e81df5876a1dbb03531950..125acbc933dc4b717856a32bb0ce9304b21fc9a9 100755 (executable)
@@ -34,7 +34,7 @@ libmmutil_imgp_la_LIBADD = $(MMCOMMON_LIBS) \
                            $(TBM_LIBS) \
                            $(MMLOG_LIBS)
 
-libmmutil_imgp_la_CFLAGS += -lcapi-media-tool $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x0100 -DMMF_DEBUG_PREFIX=\"MMF-IMAGE\" -DLIBPREFIX=\"$(libdir)\"
+libmmutil_imgp_la_CFLAGS += -lcapi-media-tool -lttrace $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x0100 -DMMF_DEBUG_PREFIX=\"MMF-IMAGE\" -DLIBPREFIX=\"$(libdir)\"
 
 pcfiles = mmutil-imgp.pc
 pkgconfigdir = $(libdir)/pkgconfig
index 62ca1adbe58b1f00a3fed3c2c1d1b941c922e867..8aeb1714d83b0148bbe7697247f33c1bc88b6b72 100755 (executable)
@@ -249,7 +249,7 @@ mm_util_destroy(MMHandleType MMHandle);
  * @since       R1, 1.0
  */
 int
-mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
                            unsigned char *dst, mm_util_img_format dst_format);
 
 
@@ -270,7 +270,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
  * @since       R1, 1.0
  */
 int
-mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
                      unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height);
 
 
@@ -292,7 +292,7 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
  * @since       R1, 1.0
  */
 int
-mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
                      unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle);
 
 /**
@@ -315,7 +315,7 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
  * @since       R1, 1.0
  */
 int
-mm_util_crop_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
                      unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_width, unsigned int *crop_dest_height, unsigned char *dst);
 
 #ifdef __cplusplus
index 75d23048481d8361cc7b74a7d03051ff5cd3c15d..037be072f10fa12dfef7a35e25d16c27b9bbabb6 100755 (executable)
@@ -157,6 +157,7 @@ typedef struct
        bool hardware_acceleration;
        mm_util_cb_s *_util_cb;
        bool is_completed;
+       bool is_finish;
 
        tbm_bufmgr tbm;
        tbm_bo src_bo;
@@ -176,8 +177,6 @@ typedef struct
        /* Dst paramters */
        guint dst_buf_size;
 
-       /* Properties */
-
        /* DRM/GEM information */
        guint src_buf_idx;
        guint dst_buf_idx;
index 3557b748ccad20b8545cbfd8b0979949f5b7b614..79c87c06c009ea94d767993382ca6cddfeda2979 100755 (executable)
 #include "mm_util_imgp_internal.h"
 #include <gmodule.h>
 #include <mm_error.h>
-
-#define MM_UTIL_ROUND_UP_2(num)  (((num)+1)&~1)
-#define MM_UTIL_ROUND_UP_4(num)  (((num)+3)&~3)
-#define MM_UTIL_ROUND_UP_8(num)  (((num)+7)&~7)
-#define MM_UTIL_ROUND_UP_16(num)  (((num)+15)&~15)
+#ifdef ENABLE_TTRACE
+#include <ttrace.h>
+#define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
+#define TTRACE_END() traceEnd(TTRACE_TAG_IMAGE)
+#else //ENABLE_TTRACE
+#define TTRACE_BEGIN(NAME)
+#define TTRACE_END()
+#endif //ENABLE_TTRACE
+
+#define MM_UTIL_ROUND_UP_2(num) (((num)+1)&~1)
+#define MM_UTIL_ROUND_UP_4(num) (((num)+3)&~3)
+#define MM_UTIL_ROUND_UP_8(num) (((num)+7)&~7)
+#define MM_UTIL_ROUND_UP_16(num) (((num)+15)&~15)
 #define GEN_MASK(x) ((1<<(x))-1)
 #define ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x))
 #define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x))
@@ -45,6 +53,16 @@ check_valid_picture_size(int width, int height)
        return MM_ERROR_IMAGE_INVALID_VALUE;
 }
 
+static void
+__mm_destroy_temp_buffer(unsigned char *buffer[])
+{
+       int i = 0;
+       for(i=0; i < 4; i++) {
+               if (buffer[i] != NULL)
+                       free(buffer[i]);
+       }
+}
+
 static gboolean
 _mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format )
 {
@@ -84,10 +102,10 @@ _mm_gst_can_resize_format(char* __format_label)
                || strcmp(__format_label, "UYVY") == 0 ||strcmp(__format_label, "Y800") == 0 || strcmp(__format_label, "I420") == 0 || strcmp(__format_label, "YV12") == 0
                || strcmp(__format_label, "RGB888") == 0 || strcmp(__format_label, "RGB565") == 0 || strcmp(__format_label, "BGR888") == 0 || strcmp(__format_label, "RGBA8888") == 0
                || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ||strcmp(__format_label, "RGBX") == 0
-               || strcmp(__format_label, "XRGB") == 0 ||strcmp(__format_label, "BGRX") == 0 ||strcmp(__format_label, "XBGR") == 0 ||strcmp(__format_label, "Y444") == 0
-               || strcmp(__format_label, "Y42B") == 0 ||strcmp(__format_label, "YUY2") == 0 ||strcmp(__format_label, "YUYV") == 0 ||strcmp(__format_label, "UYVY") == 0
-               || strcmp(__format_label, "Y41B") == 0 ||strcmp(__format_label, "Y16") == 0 ||strcmp(__format_label, "Y800") == 0 ||strcmp(__format_label, "Y8") == 0
-               || strcmp(__format_label, "GREY") == 0 ||strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
+               ||strcmp(__format_label, "XRGB") == 0 ||strcmp(__format_label, "BGRX") == 0 ||strcmp(__format_label, "XBGR") == 0 ||strcmp(__format_label, "Y444") == 0
+               ||strcmp(__format_label, "Y42B") == 0 ||strcmp(__format_label, "YUY2") == 0 ||strcmp(__format_label, "YUYV") == 0 ||strcmp(__format_label, "UYVY") == 0
+               ||strcmp(__format_label, "Y41B") == 0 ||strcmp(__format_label, "Y16") == 0 ||strcmp(__format_label, "Y800") == 0 ||strcmp(__format_label, "Y8") == 0
+               ||strcmp(__format_label, "GREY") == 0 ||strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
 
                _bool=TRUE;
        }
@@ -425,6 +443,12 @@ _mm_util_imgp_process(GModule *module)
        return mm_util_imgp_func;
 }
 
+static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, int err, void* userdata)
+{
+       debug_log("==> finalize callback func is called [%d] \n", err);
+       return MEDIA_PACKET_FINALIZE;
+}
+
 static int
 _mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s)
 {
@@ -596,10 +620,42 @@ _mm_util_handle_init(mm_util_s *handle)
        handle->dst_width = 0;
        handle->dst_height = 0;
        handle->is_completed = FALSE;
+       handle->is_finish = FALSE;
+
+       handle->set_convert = FALSE;
+       handle->set_crop = FALSE;
+       handle->set_resize = FALSE;
+       handle->set_rotate = FALSE;
 
        return ret;
 }
 
+static int
+_mm_util_handle_refresh(mm_util_s *handle)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!handle) {
+               debug_error("[ERROR] - handle");
+               return MM_ERROR_IMAGE_INTERNAL;
+       }
+
+       /* restore original settings */
+       if (handle->set_rotate && (handle->set_crop || handle->set_resize)) {
+               if ((handle->dst_rotation == MM_UTIL_ROTATION_90) || (handle->dst_rotation == MM_UTIL_ROTATION_270)) {
+                       unsigned int temp = 0;
+                       temp = handle->dst_width;
+                       handle->dst_width = handle->dst_height;
+                       handle->dst_height = temp;
+               }
+       }
+
+       handle->is_completed = FALSE;
+
+       handle->dst_packet = NULL;
+
+       return ret;
+}
 
 media_format_mimetype_e
 _mm_util_mapping_imgp_format_to_mime(mm_util_img_format format)
@@ -743,27 +799,40 @@ _mm_util_thread_repeate(gpointer data)
                return NULL;
        }
 
-       media_packet_h pop_data = (media_packet_h) g_async_queue_pop(handle->queue);
+       g_mutex_lock (handle->thread_mutex);
 
-       if(!pop_data) {
-               debug_error("[NULL] Queue data");
-       } else {
-               ret = _mm_util_transform_exec(handle, pop_data); /* Need to block */
-               if(ret == MM_ERROR_NONE) {
-                       debug_log("Success - transform_exec");
-               } else{
-                       debug_error("Error - transform_exec");
+       while (!handle->is_finish) {
+               debug_log("waiting...");
+               g_cond_wait(handle->thread_cond, handle->thread_mutex);
+               debug_log("<=== get run transform thread signal");
+               g_mutex_unlock (handle->thread_mutex);
+
+               if (handle->is_finish) {
+                       debug_log("exit loop");
+                       break;
                }
-               if(handle->_util_cb->completed_cb) {
-                       debug_log("completed_cb");
-                       handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data);
-                       debug_log("completed_cb %p", &handle->dst);
+
+               media_packet_h pop_data = (media_packet_h) g_async_queue_pop(handle->queue);
+
+               if(!pop_data) {
+                       debug_error("[NULL] Queue data");
+               } else {
+                       ret = _mm_util_transform_exec(handle, pop_data); /* Need to block */
+                       if(ret == MM_ERROR_NONE) {
+                               debug_log("Success - transform_exec");
+                       } else{
+                               debug_error("Error - transform_exec");
+                       }
+                       if(handle->_util_cb->completed_cb) {
+                               debug_log("completed_cb");
+                               handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data);
+                               debug_log("completed_cb %p", &handle->dst);
+                       }
                }
+
+               _mm_util_handle_refresh(handle);
        }
 
-       g_cond_signal(handle->thread_cond);
-       debug_log("===> send completed signal");
-       g_mutex_unlock (handle->thread_mutex);
        debug_log("exit thread");
 
        return NULL;
@@ -811,6 +880,11 @@ _mm_util_create_thread(mm_util_s *handle)
 int _mm_util_processing(mm_util_s *handle)
 {
        int ret = MM_ERROR_NONE;
+       unsigned char *dst_buf[4] = {NULL,};
+       unsigned int dst_buf_size = 0;
+       unsigned int src_width = 0, src_height = 0;
+       mm_util_img_format src_format;
+       unsigned int src_index = 0, dst_index = 0;
 
        if(handle == NULL) {
                debug_error ("Invalid arguments [tag null]\n");
@@ -849,51 +923,127 @@ int _mm_util_processing(mm_util_s *handle)
 
        debug_log("src: %p, dst: %p", handle->src, handle->dst);
 
-       if(handle->src_format == handle->dst_format) {
-               if(handle->start_x == -1 && handle->start_y == -1) {
-                       if(handle->dst_rotation != MM_UTIL_ROTATION_NONE) {
-                               ret = mm_util_rotate_image(handle->src, handle->src_width, handle->src_height,handle->src_format, handle->dst, &handle->dst_width, &handle->dst_height, handle->dst_rotation);
-                               if (ret != MM_ERROR_NONE) {
-                                       IMGP_FREE(handle->src);
-                                       IMGP_FREE(handle->dst);
-                                       debug_error("mm_util_rotate_image failed");
-                                       return MM_ERROR_IMAGE_INTERNAL;
-                               }
-                       } else {
-                               ret = mm_util_resize_image(handle->src, handle->src_width, handle->src_height,handle->src_format, handle->dst, &handle->dst_width, &handle->dst_height);
-                               if (ret != MM_ERROR_NONE) {
-                                       debug_error("mm_util_resize_image failed");
-                                       return MM_ERROR_IMAGE_INTERNAL;
-                               }
-                       }
-               } else {
-                       ret = mm_util_crop_image(handle->src, handle->src_width, handle->src_height, handle->src_format,
-                       handle->start_x, handle->start_y, &handle->dst_width, &handle->dst_height, handle->dst);
-                       if (ret != MM_ERROR_NONE) {
-                               IMGP_FREE(handle->src);
-                               IMGP_FREE(handle->dst);
-                               debug_error("mm_util_crop_image failed");
-                               return MM_ERROR_IMAGE_INTERNAL;
-                       }
+       dst_buf[src_index] = g_malloc(handle->src_buf_size);
+       src_width = handle->src_width;
+       src_height = handle->src_height;
+       src_format = handle->src_format;
+       if (dst_buf[src_index] == NULL) {
+               debug_error ("[multi func] memory allocation error");
+               IMGP_FREE(handle->src);
+               IMGP_FREE(handle->dst);
+               return MM_ERROR_IMAGE_INTERNAL;
+       }
+       memcpy(dst_buf[src_index], handle->src, handle->src_buf_size);
+       if (handle->set_crop) {
+               dst_index++;
+               mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
+               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               if (dst_buf[dst_index] == NULL) {
+                       debug_error ("[multi func] memory allocation error");
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       return MM_ERROR_IMAGE_INTERNAL;
                }
-       } else if(handle->src_format != handle->dst_format){
-               if((handle->src_width == handle->dst_width) && (handle->src_height == handle->dst_height)) {
-                       if(handle->start_x == -1 && handle->start_y == -1) {
-                               ret = mm_util_convert_colorspace(handle->src, handle->src_width, handle->src_height,handle->src_format, handle->dst, handle->dst_format);
-                               if (ret != MM_ERROR_NONE) {
-                                       IMGP_FREE(handle->src);
-                                       IMGP_FREE(handle->dst);
-                                       debug_error("mm_util_convert_colorspace failed");
-                                       return MM_ERROR_IMAGE_INTERNAL;
-                               }
+               ret = mm_util_crop_image(dst_buf[src_index], src_width, src_height, src_format,
+               handle->start_x, handle->start_y, &handle->dst_width, &handle->dst_height, dst_buf[dst_index]);
+               if (ret != MM_ERROR_NONE) {
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       debug_error("mm_util_crop_image failed");
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               src_index = dst_index;
+               src_width = handle->dst_width;
+               src_height = handle->dst_height;
+       } else if (handle->set_resize) {
+               dst_index++;
+               mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
+               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               if (dst_buf[dst_index] == NULL) {
+                       debug_error ("[multi func] memory allocation error");
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               ret = mm_util_resize_image(dst_buf[src_index], src_width, src_height,src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height);
+               if (ret != MM_ERROR_NONE) {
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       debug_error("mm_util_resize_image failed");
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               src_index = dst_index;
+               src_width = handle->dst_width;
+               src_height = handle->dst_height;
+       }
+
+       if (handle->set_convert) {
+               dst_index++;
+               mm_util_get_image_size(handle->dst_format, handle->dst_width, handle->dst_height, &dst_buf_size);
+               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               if (dst_buf[dst_index] == NULL) {
+                       debug_error ("[multi func] memory allocation error");
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               ret = mm_util_convert_colorspace(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], handle->dst_format);
+               if (ret != MM_ERROR_NONE) {
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       debug_error("mm_util_convert_colorspace failed");
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               src_index = dst_index;
+               src_format = handle->dst_format;
+       }
+
+       if (handle->set_rotate) {
+               dst_index++;
+               if(handle->set_resize || handle->set_crop) {
+                       unsigned int temp_swap = 0;
+                       switch(handle->dst_rotation) {
+                               case  MM_UTIL_ROTATION_90:
+                               case MM_UTIL_ROTATION_270:
+                                       temp_swap = handle->dst_width;
+                                       handle->dst_width  = handle->dst_height;
+                                       handle->dst_height = temp_swap;
+                                       break;
                        }
-               } else {
+               }
+               mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
+               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               if (dst_buf[dst_index] == NULL) {
+                       debug_error ("[multi func] memory allocation error");
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
-                       debug_error("[Error] Not supported");
-                       return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+                       __mm_destroy_temp_buffer(dst_buf);
+                       return MM_ERROR_IMAGE_INTERNAL;
                }
+               ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height, handle->dst_rotation);
+               if (ret != MM_ERROR_NONE) {
+                       IMGP_FREE(handle->src);
+                       IMGP_FREE(handle->dst);
+                       __mm_destroy_temp_buffer(dst_buf);
+                       debug_error("mm_util_rotate_image failed");
+                       return MM_ERROR_IMAGE_INTERNAL;
+               }
+               src_index = dst_index;
+               src_width = handle->dst_width;
+               src_height = handle->dst_height;
+       }
+
+       if (dst_buf[dst_index] != NULL && dst_buf_size != 0) {
+               memcpy(handle->dst, dst_buf[dst_index], dst_buf_size);
+               handle->dst_buf_size = dst_buf_size;
        }
+       __mm_destroy_temp_buffer(dst_buf);
 
        return ret;
 }
@@ -906,6 +1056,7 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
        media_format_h dst_fmt;
        media_format_mimetype_e src_mimetype;
        int src_width, src_height, src_avg_bps, src_max_bps;
+       unsigned int dst_width = 0, dst_height = 0;
        uint64_t size = 0;
 
        g_mutex_lock (handle->thread_mutex);
@@ -929,6 +1080,7 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
                        handle->src_height = src_height;
                } else {
                        debug_error("[Error] handle->src");
+                       media_format_unref(src_fmt);
                        return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                }
 
@@ -940,28 +1092,46 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
                }
 
                if(handle->dst_format == -1) {
+                       debug_log("dst format is changed");
                        handle->dst_format = handle->src_format;
                        handle->dst_format_mime = src_mimetype;
                }
 
                debug_log("src: %p handle->src_packet: %p (%d),(%d X %d)", src_packet, handle->src_packet, handle->src_packet, handle->src_width, handle->src_height);
-               if(handle->dst_width ==0 && handle->dst_height ==0) {
-                       switch(handle->dst_rotation) {
-                               case  MM_UTIL_ROTATION_90:
-                               case MM_UTIL_ROTATION_270:
-                                       handle->dst_width  = handle->src_height;
-                                       handle->dst_height = handle->src_width;
-                                       break;
-                               case MM_UTIL_ROTATION_NONE:
-                               case MM_UTIL_ROTATION_180:
-                               case MM_UTIL_ROTATION_FLIP_HORZ:
-                               case MM_UTIL_ROTATION_FLIP_VERT:
-                                       handle->dst_width  = handle->src_width;
-                                       handle->dst_height = handle->src_height;
-                                       break;
+               if (handle->set_rotate) {
+                       if ((handle->set_crop) || (handle->set_resize)) {
+                               switch(handle->dst_rotation) {
+                                       case MM_UTIL_ROTATION_90:
+                                       case MM_UTIL_ROTATION_270:
+                                               dst_width = handle->dst_height;
+                                               dst_height = handle->dst_width;
+                                               break;
+                                       default:
+                                               dst_width = handle->dst_width;
+                                               dst_height = handle->dst_height;
+                                               break;
+                               }
+                       } else {
+                               switch(handle->dst_rotation) {
+                                       case MM_UTIL_ROTATION_90:
+                                       case MM_UTIL_ROTATION_270:
+                                               dst_width = handle->dst_width  = handle->src_height;
+                                               dst_height = handle->dst_height = handle->src_width;
+                                               break;
+                                       case MM_UTIL_ROTATION_NONE:
+                                       case MM_UTIL_ROTATION_180:
+                                       case MM_UTIL_ROTATION_FLIP_HORZ:
+                                       case MM_UTIL_ROTATION_FLIP_VERT:
+                                               dst_width = handle->dst_width  = handle->src_width;
+                                               dst_height = handle->dst_height = handle->src_height;
+                                               break;
+                               }
                        }
+               } else {
+                       dst_width = handle->dst_width  = handle->src_width;
+                       dst_height = handle->dst_height = handle->src_height;
                }
-               debug_log("dst (%d X %d)", handle->dst_width, handle->dst_height);
+               debug_log("dst (%d X %d)", dst_width, dst_height);
                if(media_format_make_writable(src_fmt, &dst_fmt) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        debug_error("[Error] Writable - dst format");
@@ -975,14 +1145,14 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
-               if(media_format_set_video_width(dst_fmt, handle->dst_width) != MEDIA_FORMAT_ERROR_NONE) {
+               if(media_format_set_video_width(dst_fmt, dst_width) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
                        debug_error("[Error] Set - video width");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
-               if(media_format_set_video_height(dst_fmt, handle->dst_height) != MEDIA_FORMAT_ERROR_NONE) {
+               if(media_format_set_video_height(dst_fmt, dst_height) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
                        debug_error("[Error] Set - video height");
@@ -1003,22 +1173,27 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
-               if(media_packet_create_alloc(dst_fmt, (media_packet_finalize_cb)NULL, NULL, &handle->dst_packet) != MM_ERROR_NONE) {
-                       debug_error("Imedia_packet_get_format)");
+               if(media_packet_create_alloc(dst_fmt, (media_packet_finalize_cb)_mm_util_transform_packet_finalize_callback, NULL, &handle->dst_packet) != MM_ERROR_NONE) {
+                       debug_error("[Error] Create allocation memory");
+                       media_format_unref(src_fmt);
+                       media_format_unref(dst_fmt);
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                } else {
                        debug_log("Success - dst media packet");
                        if(media_packet_get_buffer_size(handle->dst_packet, &size) != MM_ERROR_NONE) {
                                debug_error("Imedia_packet_get_format)");
+                               media_format_unref(src_fmt);
+                               media_format_unref(dst_fmt);
                                return MM_ERROR_IMAGE_INVALID_VALUE;
                        }
                        handle->dst_buf_size = (guint)size;
                        debug_log("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
                                handle->src_packet, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
-                               handle->dst_packet, handle->dst_format,handle->dst_width, handle->dst_height, handle->dst_buf_size);
+                               handle->dst_packet, handle->dst_format,dst_width, dst_height, handle->dst_buf_size);
                }
        }else {
                debug_error("%d %d", src_width, src_height);
+               media_format_unref(src_fmt);
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1049,6 +1224,12 @@ _mm_util_handle_finalize(mm_util_s *handle)
        /* g_thread_exit(handle->thread); */
        if(handle->_MMHandle) {
                if(handle->thread) {
+                       g_mutex_lock (handle->thread_mutex);
+                       handle->is_finish = TRUE;
+                       g_cond_signal(handle->thread_cond);
+                       debug_log("===> send signal(finish) to transform_thread");
+                       g_mutex_unlock (handle->thread_mutex);
+
                        g_thread_join(handle->thread);
                }
        }
@@ -1077,8 +1258,11 @@ mm_util_create(MMHandleType* MMHandle)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:CREATE");
+
        if(MMHandle == NULL) {
                debug_error ("Invalid arguments [tag null]\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1092,12 +1276,14 @@ mm_util_create(MMHandleType* MMHandle)
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_util_handle_init failed");
                IMGP_FREE(handle);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        ret = _mm_util_create_thread(handle);
        if(ret != MM_ERROR_NONE) {
                debug_error("ERROR - Create thread");
+               TTRACE_END();
                return ret;
        } else {
                debug_log("Success -_mm_util_create_thread");
@@ -1106,6 +1292,7 @@ mm_util_create(MMHandleType* MMHandle)
        *MMHandle = (MMHandleType)handle;
 
        handle->_MMHandle = 0;
+       TTRACE_END();
        return ret;
 }
 
@@ -1115,13 +1302,17 @@ mm_util_set_hardware_acceleration(MMHandleType MMHandle, bool mode)
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:SET_HARDWARE_ACCELERATION");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
        handle->hardware_acceleration = mode;
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1131,15 +1322,19 @@ mm_util_set_colorspace_convert(MMHandleType MMHandle, mm_util_img_format colorsp
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:SET_HARDWARE_ACCELERATION");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
+       handle->set_convert = TRUE;
        handle->dst_format = colorspace;
        handle->dst_format_mime = _mm_util_mapping_imgp_format_to_mime(colorspace);
        debug_log("imgp fmt: %d mimetype: %d", handle->dst_format, handle->dst_format_mime);
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1149,14 +1344,18 @@ mm_util_set_resolution(MMHandleType MMHandle, unsigned int width, unsigned int h
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:SET_RESOLUTION");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
+       handle->set_resize = TRUE;
        handle->dst_width = width;
        handle->dst_height = height;
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1166,21 +1365,18 @@ mm_util_set_rotation(MMHandleType MMHandle, mm_util_img_rotate_type rotation)
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:SET_ROTATION");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
-       if(rotation == MM_UTIL_ROTATE_0 || rotation == MM_UTIL_ROTATE_180 || rotation == MM_UTIL_ROTATE_FLIP_HORZ || rotation == MM_UTIL_ROTATE_FLIP_VERT) {
-               handle->dst_width = handle->src_width;
-               handle->dst_height = handle->src_height;
-       } else if(rotation == MM_UTIL_ROTATE_90 || rotation == MM_UTIL_ROTATE_270) {
-               handle->dst_width = handle->src_height;
-               handle->dst_height = handle->src_width;
-       }
-
+       handle->set_rotate = TRUE;
        handle->dst_rotation = rotation;
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1190,19 +1386,24 @@ mm_util_set_crop_area(MMHandleType MMHandle, unsigned int start_x, unsigned int
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:SET_CROP_AREA");
+
        unsigned int dest_width = end_x -start_x;
        unsigned int dest_height = end_y - start_y;
 
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
+       handle->set_crop = TRUE;
        handle->start_x = start_x;
        handle->start_y = start_y;
        handle->dst_width = dest_width;
        handle->dst_height = dest_height;
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1212,13 +1413,17 @@ mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_comp
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:TRANSFORM");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
        if(!src_packet) {
                debug_error("[ERROR] - src_packet");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        } else {
                debug_log("src: %p", src_packet);
@@ -1226,9 +1431,11 @@ mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_comp
 
        if(!completed_callback) {
                debug_error("[ERROR] - completed_callback");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
+       IMGP_FREE(handle->_util_cb);
        handle->_util_cb = (mm_util_cb_s *)malloc(sizeof(mm_util_cb_s));
        if(handle->_util_cb) {
                handle->_util_cb->completed_cb= completed_callback;
@@ -1244,12 +1451,12 @@ mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_comp
                g_async_queue_push (handle->queue, GINT_TO_POINTER(src_packet));
 
                g_mutex_lock (handle->thread_mutex);
-               debug_log("waiting...");
-               g_cond_wait(handle->thread_cond, handle->thread_mutex);
-               debug_log("<=== get completed / cancel signal");
+               g_cond_signal(handle->thread_cond);
+               debug_log("===> send signal to transform_thread");
                g_mutex_unlock (handle->thread_mutex);
        }
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1260,19 +1467,24 @@ mm_util_transform_is_completed(MMHandleType MMHandle, bool *is_completed)
 
        mm_util_s *handle = (mm_util_s *) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:TRANSFORM_IS_COMPLETED");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if (!is_completed) {
                debug_error("[ERROR] - is_completed");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        *is_completed = handle->is_completed;
        debug_log("[Transform....] %d", *is_completed);
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1282,35 +1494,45 @@ mm_util_destroy(MMHandleType MMHandle)
        int ret = MM_ERROR_NONE;
        mm_util_s *handle = (mm_util_s*) MMHandle;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:DESTROY");
+
        if (!handle) {
                debug_error("[ERROR] - handle");
+               TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
 
        /* Close */
        if(_mm_util_handle_finalize(handle) != MM_ERROR_NONE) {
                debug_error("_mm_util_handle_finalize)");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        IMGP_FREE(handle->_util_cb);
        IMGP_FREE(handle);
+       debug_log("Success - Destroy Handle");
 
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format)
+mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:CONVERT_COLORSPACE");
+
        if(!src || !dst) {
                debug_error("invalid mm_util_convert_colorspace\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) || (dst_format < MM_UTIL_IMG_FMT_YUV420) || (dst_format > MM_UTIL_IMG_FMT_NUM) ) {
                debug_error("#ERROR# src_format: %d || dst_format:%d value ", src_format, dst_format);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1318,6 +1540,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
 
        if(_mm_cannot_convert_format(src_format, dst_format)) {
                debug_error("#ERROR# Cannot Support Image Format Convert");
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
@@ -1326,6 +1549,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
        if(_imgp_info_s == NULL) {
                debug_error("ERROR - alloc handle");
+               TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        IMGPInfoFunc _mm_util_imgp_func = NULL;
@@ -1351,6 +1575,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_set_imgp_info_s failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
        debug_log("Sucess _mm_set_imgp_info_s");
@@ -1365,11 +1590,13 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
                {
                        debug_error("image processing failed");
                        _mm_util_imgp_finalize(_module, _imgp_info_s);
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
        }else {
                debug_error("g_module_symbol failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1382,32 +1609,42 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
        ret = _mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_util_imgp_finalize failed");
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
+
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height)
+mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height)
 {
        int ret = MM_ERROR_NONE;
+
+       TTRACE_BEGIN("MM_UTILITY:IMGP:RESIZE_IMAGE");
+
        if(!src || !dst) {
                debug_error("invalid argument\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
                debug_error("#ERROR# src_format value ");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( !dst_width || !dst_height ) {
                debug_error("#ERROR# dst width/height buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( !src_width || !src_height) {
                debug_error("#ERROR# src_width || src_height valuei is 0 ");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1416,6 +1653,7 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
        if(_imgp_info_s == NULL) {
                debug_error("ERROR - alloc handle");
+               TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        IMGPInfoFunc _mm_util_imgp_func = NULL;
@@ -1443,6 +1681,7 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_set_imgp_info_s failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
        debug_log("Sucess _mm_set_imgp_info_s");
@@ -1451,6 +1690,7 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
                if(_mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) {
                        debug_error("[%s][%05d] #RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
                        _mm_util_imgp_finalize(_module, _imgp_info_s);
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
                }
        }
@@ -1465,11 +1705,13 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
                {
                        debug_error("image processing failed");
                        _mm_util_imgp_finalize(_module, _imgp_info_s);
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
        }else {
                debug_error("g_module_symbol failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1485,38 +1727,48 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
        ret = _mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_util_imgp_finalize failed");
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
+
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
+mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:ROTATE_IMAGE");
+
        if(!src || !dst) {
                debug_error("invalid argument\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
                debug_error("#ERROR# src_format value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( !dst_width || !dst_height ) {
                debug_error("#ERROR# dst width/height buffer is NUL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( !src_width || !src_height) {
                debug_error("#ERROR# src_width || src_height value is 0 ");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (angle < MM_UTIL_ROTATE_0) || (angle > MM_UTIL_ROTATE_NUM) ) {
                debug_error("#ERROR# angle vaule");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1526,6 +1778,7 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
        if(_imgp_info_s == NULL) {
                debug_error("ERROR - alloc handle");
+               TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        unsigned int dst_size=0;
@@ -1552,6 +1805,7 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
        if(ret != MM_ERROR_NONE) {
                debug_error("dst_width || dest_height size Error");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1560,6 +1814,7 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_set_imgp_info_s failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
        debug_log("Sucess _mm_set_imgp_info_s");
@@ -1568,6 +1823,7 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
                if(_mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) {
                        debug_error("[%s][%05d] #gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
                        _mm_util_imgp_finalize(_module, _imgp_info_s);
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
                }
        }
@@ -1580,11 +1836,13 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
                if (ret!= MM_ERROR_NONE)        {
                        debug_error("image processing failed");
                        _mm_util_imgp_finalize(_module, _imgp_info_s);
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
                }
        }else {
                debug_error("g_module_symbol failed");
                _mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
@@ -1600,29 +1858,37 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
        ret = _mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
                debug_error("_mm_util_imgp_finalize failed");
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
+
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_crop_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
 unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_width, unsigned int *crop_dest_height, unsigned char *dst)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:CROP_IMAGE");
+
        if (!src || !dst) {
                debug_error("invalid argument\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
                debug_error("#ERROR# src_format value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (crop_start_x +*crop_dest_width > src_width) || (crop_start_y +*crop_dest_height > src_height) ) {
                debug_error("#ERROR# dest width | height value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1663,6 +1929,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi
                        debug_log("Not supported format");
        }
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1675,8 +1942,11 @@ mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned i
        int size, w2, h2, size2;
        int stride, stride2;
 
+       TTRACE_BEGIN("MM_UTILITY:IMGP:GET_SIZE");
+
        if (!imgsize) {
                debug_error("imgsize can't be null\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
@@ -1685,6 +1955,7 @@ mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned i
 
        if (check_valid_picture_size(width, height) < 0) {
                debug_error("invalid width and height\n");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1752,9 +2023,11 @@ mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned i
 
                default:
                        debug_error("Not supported format\n");
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
        debug_log("format: %d, *imgsize: %d\n", format, *imgsize);
 
+       TTRACE_END();
        return ret;
 }
index e0e4a1747c7ddc4bf2fca0c3996cfd092f73d402..b63da396a47c6f1403811967a640aa04e7587808 100755 (executable)
 MMHandleType MMHandle = 0;
 bool completed = false;
 
+
+int packet_finalize_callback(media_packet_h packet, int err, void* userdata)
+{
+       debug_log("==> finalize callback func is called [%d] \n", err);
+       return MEDIA_PACKET_FINALIZE;
+}
+
 bool
 transform_completed_cb(media_packet_h *packet, int error, void *user_param)
 {
@@ -156,7 +163,7 @@ int main(int argc, char *argv[])
                debug_error("media_format_create failed...");
        }
 
-       ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)NULL, NULL, &src_packet);
+       ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)packet_finalize_callback, NULL, &src_packet);
        if(ret == MM_ERROR_NONE) {
                debug_log("Success - Create Media Packet(%p)", src_packet);
                uint64_t size =0;
old mode 100644 (file)
new mode 100755 (executable)
index eebebc5..59ecb7f
@@ -16,7 +16,7 @@ libmmutil_jpeg_la_CFLAGS = -I$(srcdir)/include \
                                $(SYSTEMINFO_CFLAGS) \
                                $(srcdir)/../imgp/libmmutil_imgp.la
 
-libmmutil_jpeg_la_LIBADD = $(MMCOMMON_LIBS) -ljpeg -ldl -lexif\
+libmmutil_jpeg_la_LIBADD = $(MMCOMMON_LIBS) -ljpeg -ldl -lexif -lttrace\
                                $(GLIB_LIBS) \
                                $(GMODULE_LIBS) \
                                $(SYSTEMINFO_LIBS)\
index 532d146a0b99c0ba46479961ec8073df305f1103..8eaf652b5313f28c73ba433bab4b9bbaf92a115a 100755 (executable)
@@ -99,7 +99,7 @@ typedef struct
  * @since       R1, 1.0
  */
 int
-mm_util_jpeg_encode_to_file (char *filename, void *src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality);
+mm_util_jpeg_encode_to_file (const char *filename, void *src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality);
 
 
 /**
@@ -135,7 +135,7 @@ mm_util_jpeg_encode_to_memory (void **mem, int *size, void *src, int width, int
  * @since       R1, 1.0
  */
 int
-mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, char *filename, mm_util_jpeg_yuv_format fmt);
+mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt);
 
 
 /**
@@ -168,7 +168,7 @@ mm_util_decode_from_jpeg_memory (mm_util_jpeg_yuv_data *decoded, void *src, int
  * @since       R1, 1.0
  */
 int
-mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale);
+mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale);
 
 /**
  * This function extracts yuv data from jpeg buffer with downscale decode option
index 44193f1a0a65dbfd6d242f0a838b312885b57b0e..2c38c266783529d47134e8d2e7c8094b06615798 100755 (executable)
 #include <mm_attrs_private.h>
 #include "mm_util_jpeg.h"
 #include "mm_util_imgp.h"
+#ifdef ENABLE_TTRACE
+#include <ttrace.h>
+#define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
+#define TTRACE_END() traceEnd(TTRACE_TAG_IMAGE)
+#else //ENABLE_TTRACE
+#define TTRACE_BEGIN(NAME)
+#define TTRACE_END()
+#endif //ENABLE_TTRACE
+
 #ifndef YUV420_SIZE
 #define YUV420_SIZE(width, height)     (width*height*3>>1)
 #endif
@@ -874,7 +883,6 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                debug_error("We can't encode the IMAGE format");
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
-
        return iErrorCode;
 }
 
@@ -1315,27 +1323,33 @@ static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,Exif
 }
 
 EXPORT_API int
-mm_util_jpeg_encode_to_file(char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
+mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_FILE");
+
        if( !filename || !src) {
                debug_error("#ERROR# filename || src buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (width <= 0) || (height <= 0)) {
                debug_error("#ERROR# src_width || src_height value ");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (quality < 1 ) || (quality>100) ) {
                debug_error("#ERROR# quality vaule");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1354,17 +1368,21 @@ mm_util_jpeg_encode_to_file(char *filename, void* src, int width, int height, mm
                if(dst) {
                        ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret =mm_image_encode_to_jpeg_file_with_libjpeg(filename, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       free(dst); dst=NULL;
+                       free(dst);
+                       dst=NULL;
                } else {
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                }
        } else if(fmt == MM_UTIL_JPEG_FMT_NV21) {
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else {
                ret = mm_image_encode_to_jpeg_file_with_libjpeg(filename, src, width, height, fmt, quality);
        }
        debug_log("#END# libjpeg, Success!! ret: %d", ret);
 #endif
+       TTRACE_END();
        return ret;
 }
 
@@ -1373,23 +1391,29 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_MEMORY");
+
        if( !mem || !size || !src) {
                debug_error("#ERROR# filename ||size ||  src buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (width <= 0) || (height <= 0)) {
                debug_error("#ERROR# src_width || src_height value ");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(  (quality < 1 ) || (quality>100) ) {
                debug_error("#ERROR# quality vaule");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1407,34 +1431,43 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h
                if(dst) {
                        ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret = mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       free(dst); dst=NULL;
+                       free(dst);
+                       dst=NULL;
                } else {
+                       TTRACE_END();
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                }
        } else if(fmt == MM_UTIL_JPEG_FMT_NV21) {
+               TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else {
                ret = mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, src, width, height, fmt, quality);
        }
 #endif /* LIBJPEG_TURBO */
        debug_log("#END# libjpeg, Success!! ret: %d", ret);
+
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, char *filename, mm_util_jpeg_yuv_format fmt)
+mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt)
 {
        int ret = MM_ERROR_NONE;
 
        mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE");
+
        if( !decoded || !filename) {
                debug_error("#ERROR# decoded || filename buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1446,6 +1479,7 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, char *filename, mm
                fclose(fp);
        } else {
                debug_error("[fp] file open [%s] \t %s", filename, strerror(errno));
+               TTRACE_END();
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
@@ -1457,7 +1491,37 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, char *filename, mm
                debug_log("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
                #else
                debug_log("#START# libjpeg");
-               ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
+               if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+                       unsigned int dst_size = 0;
+                       ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
+                       if (ret == MM_ERROR_NONE) {
+                               int err = MM_ERROR_NONE;
+                               err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
+                               unsigned char *dst = NULL;
+                               dst = malloc(dst_size);
+                               if(dst) {
+                                       ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
+                                       free(decoded->data);
+                                       decoded->data = malloc(dst_size);
+                                       if (decoded->data == NULL) {
+                                               debug_log("memory allocation failed");
+                                               TTRACE_END();
+                                               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                                       }
+                                       memcpy(decoded->data, dst, dst_size);
+                                       decoded->size = dst_size;
+                                       free(dst);
+                                       dst=NULL;
+                               } else {
+                                       debug_log("memory allocation failed");
+                                       TTRACE_END();
+                                       return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                               }
+                       }
+               } else {
+                       ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
+               }
+
                debug_log("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
                debug_log("#End# libjpeg, Success!! ret: %d", ret);
                #endif
@@ -1475,6 +1539,7 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, char *filename, mm
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1483,20 +1548,25 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_MEMORY");
+
        mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
 
        if( !decoded || !src) {
                debug_error("#ERROR# decoded || src buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(size < 0) {
                debug_error("#ERROR# size");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1509,32 +1579,69 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s
 
        #else
        debug_log("#START# libjpeg");
-       ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
+       if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+               unsigned int dst_size = 0;
+               unsigned char *dst = NULL;
+
+               ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, MM_UTIL_IMG_FMT_YUV420, downscale);
+               if (ret == MM_ERROR_NONE) {
+                       int err = MM_ERROR_NONE;
+                       err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
+                       dst = malloc(dst_size);
+                       if(dst) {
+                               ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
+                               free(decoded->data);
+                               decoded->data = malloc(dst_size);
+                               if (decoded->data == NULL) {
+                                       debug_log("memory allocation failed");
+                                       TTRACE_END();
+                                       return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                               }
+                               memcpy(decoded->data, dst, dst_size);
+                               decoded->size = dst_size;
+                               free(dst);
+                               dst=NULL;
+                       } else {
+                               debug_log("memory allocation failed");
+                               TTRACE_END();
+                               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                       }
+               }
+       } else {
+               ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
+       }
 
        debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
        debug_log("#END# libjpeg, Success!! ret: %d", ret);
        #endif
+
+       TTRACE_END();
        return ret;
 }
 
 EXPORT_API int
-mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
+mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE_WITH_DOWNSCALE");
+
        if( !decoded || !filename) {
                debug_error("#ERROR# decoded || filename buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
                 && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1553,7 +1660,37 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, cha
                debug_log("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
                #else
                debug_log("#START# libjpeg");
-               ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
+               if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+                       unsigned int dst_size = 0;
+                       ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
+                       if (ret == MM_ERROR_NONE) {
+                               int err = MM_ERROR_NONE;
+                               err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
+                               unsigned char *dst = NULL;
+                               dst = malloc(dst_size);
+                               if(dst) {
+                                       ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
+                                       free(decoded->data);
+                                       decoded->data = malloc(dst_size);
+                                       if (decoded->data == NULL) {
+                                               debug_log("memory allocation failed");
+                                               TTRACE_END();
+                                               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                                       }
+                                       memcpy(decoded->data, dst, dst_size);
+                                       decoded->size = dst_size;
+                                       free(dst);
+                                       dst=NULL;
+                               } else {
+                                       debug_log("memory allocation failed");
+                                       TTRACE_END();
+                                       return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                               }
+                       }
+               } else {
+                       ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
+               }
+
                debug_log("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
                debug_log("#End# libjpeg, Success!! ret: %d", ret);
                #endif
@@ -1571,6 +1708,7 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, cha
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
+       TTRACE_END();
        return ret;
 }
 
@@ -1579,24 +1717,30 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v
 {
        int ret = MM_ERROR_NONE;
 
+       TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_MEMORY_WITH_DOWNSCALE");
+
        if( !decoded || !src) {
                debug_error("#ERROR# decoded || src buffer is NULL");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(size < 0) {
                debug_error("#ERROR# size");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
                 && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
                debug_error("#ERROR# fmt value");
+               TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -1609,11 +1753,42 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v
 
        #else
        debug_log("#START# libjpeg");
-       ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
+       if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+               unsigned int dst_size = 0;
+               unsigned char *dst = NULL;
+
+               ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, MM_UTIL_IMG_FMT_YUV420, downscale);
+               if (ret == MM_ERROR_NONE) {
+                       int err = MM_ERROR_NONE;
+                       err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
+                       dst = malloc(dst_size);
+                       if(dst) {
+                               ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
+                               free(decoded->data);
+                               decoded->data = malloc(dst_size);
+                               if (decoded->data == NULL) {
+                                       debug_log("memory allocation failed");
+                                       TTRACE_END();
+                                       return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                               }
+                               memcpy(decoded->data, dst, dst_size);
+                               decoded->size = dst_size;
+                               free(dst);
+                               dst=NULL;
+                       } else {
+                               debug_log("memory allocation failed");
+                               TTRACE_END();
+                               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+                       }
+               }
+       } else {
+               ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
+       }
 
        debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
        debug_log("#END# libjpeg, Success!! ret: %d", ret);
        #endif
 
+       TTRACE_END();
        return ret;
 }
index f6ee4d4d2fdde683b17d98359fe5fb0e6282607d..143816b075c63f8df185e37b770411bf0622fa84 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.10
+Version:    0.11
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(capi-media-tool)
 BuildRequires:  pkgconfig(libtbm)
 BuildRequires:  pkgconfig(libexif)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(ttrace)
 BuildRoot:  %{_tmppath}/%{name}-%{version}-build
 
 %description
@@ -45,7 +46,10 @@ cp %{SOURCE1001} .
 
 %build
 mkdir -p m4
-CFLAGS="$CFLAGS -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" -D_MM_PROJECT_FLOATER" \
+export CFLAGS+=" -Wextra -Wno-array-bounds"
+export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow"
+export CFLAGS+=" -Wwrite-strings -Wswitch-default"
+CFLAGS="$CFLAGS -DENABLE_TTRACE -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" -D_MM_PROJECT_FLOATER" \
 LDFLAGS="$LDFLAGS -Wl,--rpath=%{_libdir} -Wl,--hash-style=both -Wl,--as-needed" \
 %reconfigure
 %__make %{?_smp_mflags}