From f53459f2141d22a9034c47e04efc39780b197805 Mon Sep 17 00:00:00 2001 From: Ji Yong Min Date: Wed, 29 Jul 2015 22:13:05 +0900 Subject: [PATCH] Fix build warning & deadlock problem of thread Change-Id: Ie9d62b56e47127a30028db37ae280890a2f976fc Signed-off-by: Jiyong Min --- imgp/include/mm_util_imgp_internal.h | 5 +- imgp/mm_util_imgp.c | 465 ++++++++++++--------------- imgp/test/mm_util_imgp_testsuite.c | 3 - jpeg/mm_util_jpeg.c | 70 ++-- jpeg/test/mm_util_jpeg_testsuite.c | 15 +- packaging/libmm-utility.spec | 3 +- 6 files changed, 263 insertions(+), 298 deletions(-) diff --git a/imgp/include/mm_util_imgp_internal.h b/imgp/include/mm_util_imgp_internal.h index 037be07..9baad28 100755 --- a/imgp/include/mm_util_imgp_internal.h +++ b/imgp/include/mm_util_imgp_internal.h @@ -153,7 +153,6 @@ typedef struct unsigned int dst_width; unsigned int dst_height; mm_util_rotation_e dst_rotation; - unsigned int _MMHandle; bool hardware_acceleration; mm_util_cb_s *_util_cb; bool is_completed; @@ -182,8 +181,8 @@ typedef struct guint dst_buf_idx; /* for multi instance */ - GCond* thread_cond; - GMutex *thread_mutex; + GCond thread_cond; + GMutex thread_mutex; GThread* thread; GAsyncQueue *queue; } mm_util_s; diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 79c87c0..fdd0ea1 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -43,9 +43,9 @@ #define GST "gstcs" typedef gboolean(*IMGPInfoFunc) (imgp_info_s*, const unsigned char*, unsigned char*, imgp_plugin_type_e); +static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet); -static int -check_valid_picture_size(int width, int height) +static int check_valid_picture_size(int width, int height) { if((int)width>0 && (int)height>0 && (width+128)*(unsigned long long)(height+128) < INT_MAX/4) { return MM_ERROR_NONE; @@ -53,8 +53,7 @@ check_valid_picture_size(int width, int height) return MM_ERROR_IMAGE_INVALID_VALUE; } -static void -__mm_destroy_temp_buffer(unsigned char *buffer[]) +static void __mm_destroy_temp_buffer(unsigned char *buffer[]) { int i = 0; for(i=0; i < 4; i++) { @@ -63,8 +62,7 @@ __mm_destroy_temp_buffer(unsigned char *buffer[]) } } -static gboolean -_mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format ) +static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format ) { gboolean _bool=FALSE; debug_log("src_format: %d, dst_format:%d", src_format, dst_format); @@ -93,8 +91,7 @@ _mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_ return _bool; } -static gboolean -_mm_gst_can_resize_format(char* __format_label) +static gboolean __mm_gst_can_resize_format(char* __format_label) { gboolean _bool = FALSE; debug_log("Format label: %s",__format_label); @@ -112,8 +109,7 @@ _mm_gst_can_resize_format(char* __format_label) return _bool; } -static gboolean -_mm_gst_can_rotate_format(const char* __format_label) +static gboolean __mm_gst_can_rotate_format(const char* __format_label) { gboolean _bool = FALSE; debug_log("Format label: %s boolean: %d",__format_label, _bool); @@ -126,8 +122,7 @@ _mm_gst_can_rotate_format(const char* __format_label) return _bool; } -static gboolean -_mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format ) +static gboolean __mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format ) { gboolean _bool=FALSE; debug_log("src_format: %d, dst_format:%d", src_format, dst_format); @@ -179,8 +174,7 @@ _mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_ return _bool; } -static gboolean -_mm_select_resize_plugin(mm_util_img_format _format) +static gboolean __mm_select_resize_plugin(mm_util_img_format _format) { gboolean _bool = FALSE; debug_log("_format: %d", _format); @@ -192,8 +186,7 @@ _mm_select_resize_plugin(mm_util_img_format _format) return _bool; } -static gboolean -_mm_select_rotate_plugin(mm_util_img_format _format, unsigned int width, unsigned int height, mm_util_img_rotate_type angle) +static gboolean __mm_select_rotate_plugin(mm_util_img_format _format, unsigned int width, unsigned int height, mm_util_img_rotate_type angle) { debug_log("_format: %d (angle: %d)", _format, angle); @@ -205,8 +198,7 @@ _mm_select_rotate_plugin(mm_util_img_format _format, unsigned int width, unsigne return FALSE; } -static int -_mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle) +static int __mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle) { int ret = MM_ERROR_NONE; @@ -252,8 +244,7 @@ _mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, un return ret; } -static int -_mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, mm_util_img_format dst_format) +static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, mm_util_img_format dst_format) { int ret = MM_ERROR_NONE; char *src_fmt_lable = NULL; @@ -265,40 +256,40 @@ _mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, switch(src_format) { case MM_UTIL_IMG_FMT_YUV420: - src_fmt_lable = "YV12"; + src_fmt_lable = (char *)"YV12"; break; case MM_UTIL_IMG_FMT_YUV422: - src_fmt_lable = "Y42B"; + src_fmt_lable = (char *)"Y42B"; break; case MM_UTIL_IMG_FMT_I420: - src_fmt_lable = "I420"; + src_fmt_lable = (char *)"I420"; break; case MM_UTIL_IMG_FMT_NV12: - src_fmt_lable = "NV12"; + src_fmt_lable = (char *)"NV12"; break; case MM_UTIL_IMG_FMT_UYVY: - src_fmt_lable = "UYVY"; + src_fmt_lable = (char *)"UYVY"; break; case MM_UTIL_IMG_FMT_YUYV: - src_fmt_lable = "YUYV"; + src_fmt_lable = (char *)"YUYV"; break; case MM_UTIL_IMG_FMT_RGB565: - src_fmt_lable = "RGB565"; + src_fmt_lable = (char *)"RGB565"; break; case MM_UTIL_IMG_FMT_RGB888: - src_fmt_lable = "RGB888"; + src_fmt_lable = (char *)"RGB888"; break; case MM_UTIL_IMG_FMT_ARGB8888: - src_fmt_lable = "ARGB8888"; + src_fmt_lable = (char *)"ARGB8888"; break; case MM_UTIL_IMG_FMT_BGRA8888: - src_fmt_lable = "BGRA8888"; + src_fmt_lable = (char *)"BGRA8888"; break; case MM_UTIL_IMG_FMT_RGBA8888: - src_fmt_lable = "RGBA8888"; + src_fmt_lable = (char *)"RGBA8888"; break; case MM_UTIL_IMG_FMT_BGRX8888: - src_fmt_lable = "BGRX"; + src_fmt_lable = (char *)"BGRX"; break; default: debug_log("[%d] Not supported format", src_fmt_lable); @@ -307,40 +298,40 @@ _mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, switch(dst_format) { case MM_UTIL_IMG_FMT_YUV420: - dst_fmt_lable = "YV12"; + dst_fmt_lable = (char *)"YV12"; break; case MM_UTIL_IMG_FMT_YUV422: - dst_fmt_lable = "Y42B"; + dst_fmt_lable = (char *)"Y42B"; break; case MM_UTIL_IMG_FMT_I420: - dst_fmt_lable = "I420"; + dst_fmt_lable = (char *)"I420"; break; case MM_UTIL_IMG_FMT_NV12: - dst_fmt_lable = "NV12"; + dst_fmt_lable = (char *)"NV12"; break; case MM_UTIL_IMG_FMT_UYVY: - dst_fmt_lable = "UYVY"; + dst_fmt_lable = (char *)"UYVY"; break; case MM_UTIL_IMG_FMT_YUYV: - dst_fmt_lable = "YUYV"; + dst_fmt_lable = (char *)"YUYV"; break; case MM_UTIL_IMG_FMT_RGB565: - dst_fmt_lable = "RGB565"; + dst_fmt_lable = (char *)"RGB565"; break; case MM_UTIL_IMG_FMT_RGB888: - dst_fmt_lable = "RGB888"; + dst_fmt_lable = (char *)"RGB888"; break; case MM_UTIL_IMG_FMT_ARGB8888: - dst_fmt_lable = "ARGB8888"; + dst_fmt_lable = (char *)"ARGB8888"; break; case MM_UTIL_IMG_FMT_BGRA8888: - dst_fmt_lable = "BGRA8888"; + dst_fmt_lable = (char *)"BGRA8888"; break; case MM_UTIL_IMG_FMT_RGBA8888: - dst_fmt_lable = "RGBA8888"; + dst_fmt_lable = (char *)"RGBA8888"; break; case MM_UTIL_IMG_FMT_BGRX8888: - dst_fmt_lable = "BGRX"; + dst_fmt_lable = (char *)"BGRX"; break; default: debug_error("[%d] Not supported format", dst_format); @@ -374,16 +365,16 @@ _mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, return ret; } -static int -_mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, unsigned int src_width, unsigned int src_height, mm_util_img_format dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle) +static int __mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, unsigned int src_width, unsigned int src_height, mm_util_img_format dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle) { int ret = MM_ERROR_NONE; + if(_imgp_info_s == NULL) { debug_error("_imgp_info_s is NULL"); return MM_ERROR_IMAGE_INVALID_VALUE; } - ret=_mm_set_format_label(_imgp_info_s, src_format, dst_format); + ret = __mm_set_format_label(_imgp_info_s, src_format, dst_format); if(ret != MM_ERROR_NONE) { debug_error("[input] mm_set_format_label error"); return MM_ERROR_IMAGE_INVALID_VALUE; @@ -405,8 +396,7 @@ _mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, u return ret; } -static GModule * -_mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e) +static GModule * __mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e) { GModule *module = NULL; debug_log("#Start dlopen#"); @@ -425,8 +415,7 @@ _mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e) return module; } -static IMGPInfoFunc -_mm_util_imgp_process(GModule *module) +static IMGPInfoFunc __mm_util_imgp_process(GModule *module) { IMGPInfoFunc mm_util_imgp_func = NULL; @@ -435,7 +424,7 @@ _mm_util_imgp_process(GModule *module) return NULL; } - debug_log("#_mm_util_imgp_process#"); + debug_log("#__mm_util_imgp_process#"); g_module_symbol(module, IMGP_FUNC_NAME, (gpointer*)&mm_util_imgp_func); debug_log("mm_util_imgp_func: %p", mm_util_imgp_func); @@ -449,8 +438,7 @@ static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, in return MEDIA_PACKET_FINALIZE; } -static int -_mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) +static int __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) { int ret = MM_ERROR_NONE; @@ -471,12 +459,11 @@ _mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) return ret; } -static int -_mm_util_crop_rgba32(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, +static int __mm_util_crop_rgba32(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; - int i; + unsigned int idx = 0; int src_bytesperline = src_width * 4; int dst_bytesperline = crop_dest_width * 4; @@ -484,7 +471,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height); src += crop_start_y * src_bytesperline + 4 * crop_start_x; - for (i = 0; i < crop_dest_height; i++) { + for (idx = 0; idx < crop_dest_height; idx++) { memcpy(dst, src, dst_bytesperline); src += src_bytesperline; dst += dst_bytesperline; @@ -493,12 +480,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid return ret; } -static int -_mm_util_crop_rgb888(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, +static int __mm_util_crop_rgb888(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; - int i; + unsigned int idx = 0; int src_bytesperline = src_width * 3; int dst_bytesperline = crop_dest_width * 3; @@ -506,7 +492,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height); src += crop_start_y * src_bytesperline + 3 * crop_start_x; - for (i = 0; i < crop_dest_height; i++) { + for (idx = 0; idx < crop_dest_height; idx++) { memcpy(dst, src, dst_bytesperline); src += src_bytesperline; dst += dst_bytesperline; @@ -515,12 +501,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid return ret; } -static int -_mm_util_crop_rgb565(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, +static int __mm_util_crop_rgb565(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; - int i; + unsigned int idx = 0; int src_bytesperline = src_width * 2; int dst_bytesperline = crop_dest_width * 2; @@ -528,7 +513,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height); src += crop_start_y * src_bytesperline + 2 * crop_start_x; - for (i = 0; i < crop_dest_height; i++) { + for (idx = 0; idx < crop_dest_height; idx++) { memcpy(dst, src, dst_bytesperline); src += src_bytesperline; dst += dst_bytesperline; @@ -537,12 +522,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid return ret; } -static int -_mm_util_crop_yuv420(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, +static int __mm_util_crop_yuv420(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; - int i; + unsigned int idx = 0; int start_x = crop_start_x; int start_y = crop_start_y; debug_log("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n", @@ -550,7 +534,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid const unsigned char *_src = src + start_y * src_width + start_x; /* Y */ - for (i = 0; i < crop_dest_height; i++) { + for (idx = 0; idx < crop_dest_height; idx++) { memcpy(dst, _src, crop_dest_width); _src += src_width; dst += crop_dest_width; @@ -558,7 +542,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid /* U */ _src = src + src_height * src_width + (start_y / 2) * src_width / 2 + start_x / 2; - for (i = 0; i < crop_dest_height / 2; i++) { + for (idx = 0; idx < crop_dest_height / 2; idx++) { memcpy(dst, _src, crop_dest_width / 2); _src += src_width / 2; dst += crop_dest_width / 2; @@ -566,7 +550,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid /* V */ _src = src + src_height * src_width * 5 / 4 + (start_y / 2) * src_width / 2 + start_x / 2; - for (i = 0; i < crop_dest_height / 2; i++) { + for (idx = 0; idx < crop_dest_height / 2; idx++) { memcpy(dst, _src, crop_dest_width / 2); _src += src_width / 2; dst += crop_dest_width / 2; @@ -575,8 +559,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid return ret; } -static bool -_mm_util_check_resolution(unsigned int width, unsigned int height) +static bool __mm_util_check_resolution(unsigned int width, unsigned int height) { if(width == 0) { @@ -593,8 +576,7 @@ _mm_util_check_resolution(unsigned int width, unsigned int height) return true; } -static int -_mm_util_handle_init(mm_util_s *handle) +static int __mm_util_handle_init(mm_util_s *handle) { int ret = MM_ERROR_NONE; @@ -607,7 +589,7 @@ _mm_util_handle_init(mm_util_s *handle) handle->src = 0; handle->dst = 0; handle->drm_fd = -1; - handle->dst_format = -1; + handle->dst_format = MM_UTIL_IMG_FMT_NUM; handle->dst_format_mime = -1; handle->src_buf_idx = 0; handle->dst_buf_idx = 0; @@ -630,8 +612,7 @@ _mm_util_handle_init(mm_util_s *handle) return ret; } -static int -_mm_util_handle_refresh(mm_util_s *handle) +static int __mm_util_handle_refresh(mm_util_s *handle) { int ret = MM_ERROR_NONE; @@ -657,8 +638,7 @@ _mm_util_handle_refresh(mm_util_s *handle) return ret; } -media_format_mimetype_e -_mm_util_mapping_imgp_format_to_mime(mm_util_img_format format) +static media_format_mimetype_e __mm_util_mapping_imgp_format_to_mime(mm_util_img_format format) { media_format_mimetype_e mimetype = -1; @@ -696,24 +676,21 @@ _mm_util_mapping_imgp_format_to_mime(mm_util_img_format format) case MM_UTIL_IMG_FMT_ARGB8888 : mimetype = MEDIA_FORMAT_ARGB; break; - case MM_UTIL_IMG_FMT_BGRA8888 : - case MM_UTIL_IMG_FMT_BGRX8888 : - case MM_UTIL_IMG_FMT_NV61 : - case MM_UTIL_IMG_FMT_NUM : - mimetype = -1; - debug_error("Not Supported Format"); - break; case MM_UTIL_IMG_FMT_NV12_TILED : mimetype = MEDIA_FORMAT_NV12T; break; + default: + mimetype = -1; + debug_error("Not Supported Format [%d]", format); + break; } debug_log("imgp fmt: %d mimetype fmt: %d", format, mimetype); + return mimetype; } -mm_util_img_format -_mm_util_mapping_mime_format_to_imgp(media_format_mimetype_e mimetype) +static mm_util_img_format __mm_util_mapping_mime_format_to_imgp(media_format_mimetype_e mimetype) { mm_util_img_format format = -1; @@ -751,73 +728,50 @@ _mm_util_mapping_mime_format_to_imgp(media_format_mimetype_e mimetype) case MEDIA_FORMAT_ARGB : format = MM_UTIL_IMG_FMT_ARGB8888; break; - case MEDIA_FORMAT_NV21 : - case MEDIA_FORMAT_H261 : - case MEDIA_FORMAT_H263 : - case MEDIA_FORMAT_H263P : - case MEDIA_FORMAT_H264_SP : - case MEDIA_FORMAT_H264_MP : - case MEDIA_FORMAT_H264_HP : - case MEDIA_FORMAT_MJPEG : - case MEDIA_FORMAT_MPEG1 : - case MEDIA_FORMAT_MPEG2_SP : - case MEDIA_FORMAT_MPEG2_MP : - case MEDIA_FORMAT_MPEG2_HP : - case MEDIA_FORMAT_MPEG4_SP : - case MEDIA_FORMAT_MPEG4_ASP : - case MEDIA_FORMAT_L16: - case MEDIA_FORMAT_PCM : - case MEDIA_FORMAT_PCMA : - case MEDIA_FORMAT_ALAW : - case MEDIA_FORMAT_PCMU : - case MEDIA_FORMAT_ULAW : - case MEDIA_FORMAT_AMR : - case MEDIA_FORMAT_G729 : - case MEDIA_FORMAT_AAC: - case MEDIA_FORMAT_MP3: - case MEDIA_FORMAT_MAX : - format = -1; - debug_error("Not Supported Format"); - break; case MEDIA_FORMAT_NV12T : format = MM_UTIL_IMG_FMT_NV12_TILED; break; + default: + format = -1; + debug_error("Not Supported Format [%d]", mimetype); + break; } + debug_log("mimetype: %d imgp fmt: %d", mimetype, format); + return format; } - -gpointer -_mm_util_thread_repeate(gpointer data) +gpointer _mm_util_thread_repeate(gpointer data) { mm_util_s* handle = (mm_util_s*) data; int ret = MM_ERROR_NONE; + gint64 end_time = 0; if (!handle) { debug_error("[ERROR] - handle"); return NULL; } - g_mutex_lock (handle->thread_mutex); - while (!handle->is_finish) { + end_time = g_get_monotonic_time() + 1 * G_TIME_SPAN_SECOND; debug_log("waiting..."); - g_cond_wait(handle->thread_cond, handle->thread_mutex); + g_mutex_lock (&(handle->thread_mutex)); + g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time); debug_log("<=== get run transform thread signal"); - g_mutex_unlock (handle->thread_mutex); + g_mutex_unlock (&(handle->thread_mutex)); if (handle->is_finish) { debug_log("exit loop"); break; } - media_packet_h pop_data = (media_packet_h) g_async_queue_pop(handle->queue); + media_packet_h pop_data = (media_packet_h) g_async_queue_try_pop(handle->queue); if(!pop_data) { debug_error("[NULL] Queue data"); } else { - ret = _mm_util_transform_exec(handle, pop_data); /* Need to block */ + ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */ if(ret == MM_ERROR_NONE) { debug_log("Success - transform_exec"); } else{ @@ -828,9 +782,9 @@ _mm_util_thread_repeate(gpointer data) 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); + __mm_util_handle_refresh(handle); + } } debug_log("exit thread"); @@ -838,8 +792,7 @@ _mm_util_thread_repeate(gpointer data) return NULL; } -int -_mm_util_create_thread(mm_util_s *handle) +static int __mm_util_create_thread(mm_util_s *handle) { int ret = MM_ERROR_NONE; @@ -848,11 +801,7 @@ _mm_util_create_thread(mm_util_s *handle) return MM_ERROR_IMAGE_INVALID_VALUE; } - if(!handle->thread_mutex) { - handle->thread_mutex = g_mutex_new(); - } else { - debug_error("ERROR - thread_mutex is already created"); - } + g_mutex_init(&(handle->thread_mutex)); /*These are a communicator for thread*/ if(!handle->queue) { @@ -861,11 +810,7 @@ _mm_util_create_thread(mm_util_s *handle) debug_error("ERROR - async queue is already created"); } - if(!handle->thread_cond) { - handle->thread_cond = g_cond_new(); - } else { - debug_error("thread cond is already created"); - } + g_cond_init(&(handle->thread_cond)); /*create threads*/ handle->thread = g_thread_new("transform_thread", (GThreadFunc)_mm_util_thread_repeate, (gpointer)handle); @@ -877,7 +822,7 @@ _mm_util_create_thread(mm_util_s *handle) return ret; } -int _mm_util_processing(mm_util_s *handle) +static int __mm_util_processing(mm_util_s *handle) { int ret = MM_ERROR_NONE; unsigned char *dst_buf[4] = {NULL,}; @@ -1015,6 +960,8 @@ int _mm_util_processing(mm_util_s *handle) handle->dst_width = handle->dst_height; handle->dst_height = temp_swap; break; + default: + break; } } mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size); @@ -1048,8 +995,7 @@ int _mm_util_processing(mm_util_s *handle) return ret; } -int -_mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) +static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) { int ret = MM_ERROR_NONE; media_format_h src_fmt; @@ -1059,8 +1005,6 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) unsigned int dst_width = 0, dst_height = 0; uint64_t size = 0; - g_mutex_lock (handle->thread_mutex); - if(media_packet_get_format(src_packet, &src_fmt) != MM_ERROR_NONE) { debug_error("Imedia_packet_get_format)"); return MM_ERROR_IMAGE_INVALID_VALUE; @@ -1070,12 +1014,12 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) debug_log("[Fotmat: %d] W x H : %d x %d", src_mimetype, src_width, src_height); } - if(_mm_util_check_resolution(src_width, src_height)) { + if(__mm_util_check_resolution(src_width, src_height)) { /* src */ handle->src_packet = src_packet; debug_log("src_packet: %p handle->src_packet: %p 0x%2x [W X H] %d X %d", src_packet, handle->src_packet, src_fmt, src_width, src_height); if(handle->src_packet) { - handle->src_format = _mm_util_mapping_mime_format_to_imgp(src_mimetype); + handle->src_format = __mm_util_mapping_mime_format_to_imgp(src_mimetype); handle->src_width = src_width; handle->src_height = src_height; } else { @@ -1091,7 +1035,7 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) debug_error("Error buffer size"); } - if(handle->dst_format == -1) { + if(handle->dst_format == MM_UTIL_IMG_FMT_NUM) { debug_log("dst format is changed"); handle->dst_format = handle->src_format; handle->dst_format_mime = src_mimetype; @@ -1125,11 +1069,19 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) dst_width = handle->dst_width = handle->src_width; dst_height = handle->dst_height = handle->src_height; break; + default: + debug_error("[Error] Wrong dst_rotation"); + break; } } } else { - dst_width = handle->dst_width = handle->src_width; - dst_height = handle->dst_height = handle->src_height; + if ((handle->set_crop) || (handle->set_resize)) { + dst_width = handle->dst_width; + dst_height = handle->dst_height; + } else { + dst_width = handle->dst_width = handle->src_width; + dst_height = handle->dst_height = handle->src_height; + } } debug_log("dst (%d X %d)", dst_width, dst_height); if(media_format_make_writable(src_fmt, &dst_fmt) != MEDIA_FORMAT_ERROR_NONE) { @@ -1197,10 +1149,10 @@ _mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet) return MM_ERROR_IMAGE_INVALID_VALUE; } - ret = _mm_util_processing(handle); + ret = __mm_util_processing(handle); if(ret != MM_ERROR_NONE) { - debug_error("_mm_util_processing failed"); + debug_error("__mm_util_processing failed"); IMGP_FREE(handle); return MM_ERROR_IMAGE_INVALID_VALUE; } @@ -1222,16 +1174,14 @@ _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); - } + if(handle->thread) { + handle->is_finish = TRUE; + g_mutex_lock (&(handle->thread_mutex)); + 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); } if(handle->queue) { @@ -1239,22 +1189,16 @@ _mm_util_handle_finalize(mm_util_s *handle) handle->queue = NULL; } - if(handle->thread_mutex) { - g_mutex_free (handle->thread_mutex); - handle->thread_mutex = NULL; - } + g_mutex_clear(&(handle->thread_mutex)); + + g_cond_clear(&(handle->thread_cond)); - if(handle->thread_cond) { - g_cond_free (handle->thread_cond); - handle->thread_cond = NULL; - } debug_log("Success - Finalize Handle"); return ret; } -int -mm_util_create(MMHandleType* MMHandle) +int mm_util_create(MMHandleType* MMHandle) { int ret = MM_ERROR_NONE; @@ -1272,7 +1216,7 @@ mm_util_create(MMHandleType* MMHandle) ret = MM_ERROR_IMAGE_INTERNAL; } - ret = _mm_util_handle_init (handle); + ret = __mm_util_handle_init (handle); if(ret != MM_ERROR_NONE) { debug_error("_mm_util_handle_init failed"); IMGP_FREE(handle); @@ -1280,24 +1224,22 @@ mm_util_create(MMHandleType* MMHandle) return MM_ERROR_IMAGE_INVALID_VALUE; } - ret = _mm_util_create_thread(handle); + 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"); + debug_log("Success -__mm_util_create_thread"); } *MMHandle = (MMHandleType)handle; - handle->_MMHandle = 0; TTRACE_END(); return ret; } -int -mm_util_set_hardware_acceleration(MMHandleType MMHandle, bool mode) +int mm_util_set_hardware_acceleration(MMHandleType MMHandle, bool mode) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s *) MMHandle; @@ -1316,8 +1258,7 @@ mm_util_set_hardware_acceleration(MMHandleType MMHandle, bool mode) return ret; } -int -mm_util_set_colorspace_convert(MMHandleType MMHandle, mm_util_img_format colorspace) +int mm_util_set_colorspace_convert(MMHandleType MMHandle, mm_util_img_format colorspace) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s *) MMHandle; @@ -1331,15 +1272,14 @@ mm_util_set_colorspace_convert(MMHandleType MMHandle, mm_util_img_format colorsp handle->set_convert = TRUE; handle->dst_format = colorspace; - handle->dst_format_mime = _mm_util_mapping_imgp_format_to_mime(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; } -int -mm_util_set_resolution(MMHandleType MMHandle, unsigned int width, unsigned int height) +int mm_util_set_resolution(MMHandleType MMHandle, unsigned int width, unsigned int height) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s *) MMHandle; @@ -1359,8 +1299,7 @@ mm_util_set_resolution(MMHandleType MMHandle, unsigned int width, unsigned int h return ret; } -int -mm_util_set_rotation(MMHandleType MMHandle, mm_util_img_rotate_type rotation) +int 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; @@ -1380,8 +1319,7 @@ mm_util_set_rotation(MMHandleType MMHandle, mm_util_img_rotate_type rotation) return ret; } -int -mm_util_set_crop_area(MMHandleType MMHandle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) +int mm_util_set_crop_area(MMHandleType MMHandle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s *) MMHandle; @@ -1407,8 +1345,7 @@ mm_util_set_crop_area(MMHandleType MMHandle, unsigned int start_x, unsigned int return ret; } -int -mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_completed_callback completed_callback, void * user_data) +int mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_completed_callback completed_callback, void * user_data) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s *) MMHandle; @@ -1444,24 +1381,20 @@ mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_comp debug_error("[ERROR] _util_cb_s"); } - handle->_MMHandle++; - if(handle->queue) { debug_log("g_async_queue_push"); g_async_queue_push (handle->queue, GINT_TO_POINTER(src_packet)); - - g_mutex_lock (handle->thread_mutex); - g_cond_signal(handle->thread_cond); + g_mutex_lock (&(handle->thread_mutex)); + g_cond_signal(&(handle->thread_cond)); debug_log("===> send signal to transform_thread"); - g_mutex_unlock (handle->thread_mutex); + g_mutex_unlock (&(handle->thread_mutex)); } TTRACE_END(); return ret; } -int -mm_util_transform_is_completed(MMHandleType MMHandle, bool *is_completed) +int mm_util_transform_is_completed(MMHandleType MMHandle, bool *is_completed) { int ret = MM_ERROR_NONE; @@ -1488,8 +1421,7 @@ mm_util_transform_is_completed(MMHandleType MMHandle, bool *is_completed) return ret; } -int -mm_util_destroy(MMHandleType MMHandle) +int mm_util_destroy(MMHandleType MMHandle) { int ret = MM_ERROR_NONE; mm_util_s *handle = (mm_util_s*) MMHandle; @@ -1517,8 +1449,7 @@ mm_util_destroy(MMHandleType MMHandle) return ret; } -EXPORT_API int -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) +EXPORT_API int 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; @@ -1538,7 +1469,7 @@ mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, uns debug_log("#START#"); - if(_mm_cannot_convert_format(src_format, dst_format)) { + 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; @@ -1557,45 +1488,46 @@ mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, uns imgp_plugin_type_e _imgp_plugin_type_e = 0; /* Initialize */ - if(_mm_select_convert_plugin(src_format, dst_format)) { + if(__mm_select_convert_plugin(src_format, dst_format)) { _imgp_plugin_type_e = IMGP_NEON; }else { _imgp_plugin_type_e = IMGP_GSTCS; } debug_log("plugin type: %d", _imgp_plugin_type_e); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); - debug_log("_mm_util_imgp_init: %p", _module); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + debug_log("__mm_util_imgp_initialize: %p", _module); if(_module == NULL) { /* when IMGP_NEON is NULL */ _imgp_plugin_type_e = IMGP_GSTCS; debug_log("You use %s module", PATH_GSTCS_LIB); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); } debug_log("mm_util_imgp_func: %p", _module); - ret=_mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0); + + ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0); if(ret != MM_ERROR_NONE) { - debug_error("_mm_set_imgp_info_s failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + 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"); + debug_log("Sucess __mm_set_imgp_info_s"); /* image processing */ - _mm_util_imgp_func = _mm_util_imgp_process(_module); - debug_log("Sucess _mm_util_imgp_process"); + _mm_util_imgp_func = __mm_util_imgp_process(_module); + debug_log("Sucess __mm_util_imgp_process"); if(_mm_util_imgp_func) { ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_CSC); if (ret != MM_ERROR_NONE) { debug_error("image processing failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + __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); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_INVALID_VALUE; } @@ -1606,9 +1538,9 @@ mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, uns debug_log("#Success# dst"); /* Finalize */ - ret = _mm_util_imgp_finalize(_module, _imgp_info_s); + ret = __mm_util_imgp_finalize(_module, _imgp_info_s); if(ret != MM_ERROR_NONE) { - debug_error("_mm_util_imgp_finalize failed"); + debug_error("__mm_util_imgp_finalize failed"); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } @@ -1617,8 +1549,7 @@ mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, uns return ret; } -EXPORT_API int -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) +EXPORT_API int 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; @@ -1661,56 +1592,57 @@ mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned imgp_plugin_type_e _imgp_plugin_type_e = 0; /* Initialize */ - if(_mm_select_resize_plugin(src_format)) { + if(__mm_select_resize_plugin(src_format)) { _imgp_plugin_type_e = IMGP_NEON; }else { _imgp_plugin_type_e = IMGP_GSTCS; } debug_log("plugin type: %d", _imgp_plugin_type_e); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); - debug_log("_mm_util_imgp_init: %p", _module); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + debug_log("__mm_util_imgp_initialize: %p", _module); if(_module == NULL) /* when IMGP_NEON is NULL */ { _imgp_plugin_type_e = IMGP_GSTCS; debug_log("You use %s module", PATH_GSTCS_LIB); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); } - debug_log("_mm_set_imgp_info_s"); - ret=_mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0); - debug_log("_mm_set_imgp_info_s ret: %d", ret); + + debug_log("__mm_set_imgp_info_s"); + ret =__mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0); + debug_log("__mm_set_imgp_info_s ret: %d", ret); if(ret != MM_ERROR_NONE) { - debug_error("_mm_set_imgp_info_s failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + 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"); + debug_log("Sucess __mm_set_imgp_info_s"); if(g_strrstr(g_module_name (_module), GST)) { - if(_mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) { + 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); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } } /* image processing */ - _mm_util_imgp_func = _mm_util_imgp_process(_module); - debug_log("Sucess _mm_util_imgp_process"); + _mm_util_imgp_func = __mm_util_imgp_process(_module); + debug_log("Sucess __mm_util_imgp_process"); if(_mm_util_imgp_func) { ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_RSZ); debug_log("_mm_util_imgp_func, ret: %d", ret); if (ret != MM_ERROR_NONE) { debug_error("image processing failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + __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); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_INVALID_VALUE; } @@ -1724,9 +1656,9 @@ mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned *dst_height = _imgp_info_s->dst_height; /* Finalize */ - ret = _mm_util_imgp_finalize(_module, _imgp_info_s); + ret = __mm_util_imgp_finalize(_module, _imgp_info_s); if(ret != MM_ERROR_NONE) { - debug_error("_mm_util_imgp_finalize failed"); + debug_error("__mm_util_imgp_finalize failed"); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } @@ -1735,8 +1667,7 @@ mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned return ret; } -EXPORT_API int -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) +EXPORT_API int 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; @@ -1787,61 +1718,63 @@ mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned imgp_plugin_type_e _imgp_plugin_type_e = 0; /* Initialize */ - if( _mm_select_rotate_plugin(src_format, src_width, src_height, angle)) { + if( __mm_select_rotate_plugin(src_format, src_width, src_height, angle)) { _imgp_plugin_type_e = IMGP_NEON; }else { _imgp_plugin_type_e = IMGP_GSTCS; } debug_log("plugin type: %d", _imgp_plugin_type_e); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); - debug_log("_mm_util_imgp_func: %p", _module); + + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + debug_log("__mm_util_imgp_initialize: %p", _module); if(_module == NULL) { /* when IMGP_NEON is NULL */ _imgp_plugin_type_e = IMGP_GSTCS; debug_log("You use %s module", PATH_GSTCS_LIB); - _module = _mm_util_imgp_initialize(_imgp_plugin_type_e); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); } - debug_log("_mm_set_imgp_info_s"); - ret=_mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle); + + debug_log("__mm_confirm_dst_width_height"); + ret = __mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle); if(ret != MM_ERROR_NONE) { debug_error("dst_width || dest_height size Error"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_INVALID_VALUE; } - ret=_mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle); - debug_log("_mm_set_imgp_info_s"); + ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle); + debug_log("__mm_set_imgp_info_s"); if(ret != MM_ERROR_NONE) { - debug_error("_mm_set_imgp_info_s failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + 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"); + debug_log("Sucess __mm_set_imgp_info_s"); if(g_strrstr(g_module_name (_module), GST)) { - if(_mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) { + 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); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } } /* image processing */ - _mm_util_imgp_func = _mm_util_imgp_process(_module); - debug_log("Sucess _mm_util_imgp_process"); + _mm_util_imgp_func = __mm_util_imgp_process(_module); + debug_log("Sucess __mm_util_imgp_process"); if(_mm_util_imgp_func) { ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_ROT); if (ret!= MM_ERROR_NONE) { debug_error("image processing failed"); - _mm_util_imgp_finalize(_module, _imgp_info_s); + __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); + __mm_util_imgp_finalize(_module, _imgp_info_s); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } @@ -1855,9 +1788,9 @@ mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned *dst_height = _imgp_info_s->dst_height; /* Finalize */ - ret = _mm_util_imgp_finalize(_module, _imgp_info_s); + ret = __mm_util_imgp_finalize(_module, _imgp_info_s); if(ret != MM_ERROR_NONE) { - debug_error("_mm_util_imgp_finalize failed"); + debug_error("__mm_util_imgp_finalize failed"); TTRACE_END(); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } @@ -1866,8 +1799,7 @@ mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned return ret; } -EXPORT_API int -mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, +EXPORT_API int 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; @@ -1894,18 +1826,18 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi switch (src_format) { case MM_UTIL_IMG_FMT_RGB888: { - ret = _mm_util_crop_rgb888(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); + ret = __mm_util_crop_rgb888(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); break; } case MM_UTIL_IMG_FMT_RGB565: { - ret = _mm_util_crop_rgb565(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); + ret = __mm_util_crop_rgb565(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); break; } case MM_UTIL_IMG_FMT_ARGB8888: case MM_UTIL_IMG_FMT_BGRA8888: case MM_UTIL_IMG_FMT_RGBA8888: case MM_UTIL_IMG_FMT_BGRX8888: { - ret = _mm_util_crop_rgba32(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); + ret = __mm_util_crop_rgba32(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); break; } case MM_UTIL_IMG_FMT_I420: @@ -1922,7 +1854,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi debug_log("Image isplay is suceeded when YUV crop height value %d ",*crop_dest_height); } - ret = _mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); + ret = __mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst); break; } default: @@ -1933,8 +1865,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi return ret; } -EXPORT_API int -mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize) +EXPORT_API int mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize) { int ret = MM_ERROR_NONE; unsigned char x_chroma_shift = 0; diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index b63da39..df9d181 100755 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -89,9 +89,6 @@ transform_completed_cb(media_packet_h *packet, int error, void *user_param) IMGP_FREE(output_fmt); } else { debug_error("[ERROR] complete cb"); - GThread * destroy_thread = g_thread_new(NULL, mm_util_destroy, MMHandle); - return_val_if_fail(destroy_thread, FALSE); - g_thread_unref(destroy_thread); } completed = true; diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c index 3ccd61e..66f3597 100755 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -245,9 +245,9 @@ _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, uns } static int -mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, char *pFileName, mm_util_jpeg_yuv_format input_fmt) +mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; tjhandle dhandle=NULL; unsigned char *srcBuf=NULL; int jpegSize; @@ -295,7 +295,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decode static int mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; tjhandle dhandle=NULL; unsigned char *srcBuf=NULL; int TD_BU=0; @@ -376,7 +376,7 @@ _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsigned char **ds static int mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; tjhandle chandle=NULL; unsigned char *dstBuf=NULL; unsigned long size=0; @@ -419,7 +419,7 @@ mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int w static int mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int *csize, void *rawdata, int w, int h, mm_util_jpeg_yuv_format fmt,int quality) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; tjhandle chandle=NULL; int TD_BU=0; @@ -495,8 +495,7 @@ my_error_exit (j_common_ptr cinfo) longjmp(myerr->setjmp_buffer, 1); /* Return control to the setjmp point */ } -static int -mm_image_encode_to_jpeg_file_with_libjpeg(char *pFileName, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) +static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) { int iErrorCode = MM_ERROR_NONE; @@ -671,8 +670,10 @@ mm_image_encode_to_jpeg_file_with_libjpeg(char *pFileName, void *rawdata, int wi iRowStride = width * 4; } + JSAMPLE *image_buffer = (JSAMPLE *)rawdata; while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride]; + //row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride]; + row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride]; jpeg_write_scanlines(&cinfo, row_pointer, 1); } debug_log("while"); @@ -685,7 +686,7 @@ mm_image_encode_to_jpeg_file_with_libjpeg(char *pFileName, void *rawdata, int wi debug_error("We can't encode the IMAGE format"); return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT; } - fsync((int)fpWriter); + fsync((int)(fpWriter->_fileno)); debug_log("[fsync] FILE"); fclose(fpWriter); return iErrorCode; @@ -694,7 +695,7 @@ mm_image_encode_to_jpeg_file_with_libjpeg(char *pFileName, void *rawdata, int wi static int mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt,int quality) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; JSAMPROW y[16],cb[16],cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */ JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */ @@ -869,8 +870,10 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat iRowStride = width * 4; } + JSAMPLE *image_buffer = (JSAMPLE *)rawdata; while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride]; + //row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride]; + row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride]; jpeg_write_scanlines(&cinfo, row_pointer, 1); } debug_log("while"); @@ -889,14 +892,14 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat } static int -mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, char *pFileName, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale) +mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale) { - int iErrorCode = MM_ERROR_NONE; - FILE *infile = NULL; + int iErrorCode = MM_ERROR_NONE; + FILE *infile = NULL; struct jpeg_decompress_struct dinfo; struct my_error_mgr_s jerr; JSAMPARRAY buffer; /* Output row buffer */ - int row_stride = 0, state = 0; /* physical row width in output buffer */ + int row_stride = 0; /* physical row width in output buffer */ JSAMPROW image, u_image, v_image; JSAMPROW row; /* point to buffer[0] */ @@ -1063,6 +1066,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data } } }else if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 ||input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) { + int state = 0; /* while (scan lines remain to be read) jpeg_read_scanlines(...); */ while (dinfo.output_scanline < dinfo.output_height) { /* jpeg_read_scanlines expects an array of pointers to scanlines. Here the array is only one element long, but you could ask formore than one scanline at a time if that's more convenient. */ @@ -1088,11 +1092,11 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data static int mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale) { - int iErrorCode = MM_ERROR_NONE; + int iErrorCode = MM_ERROR_NONE; struct jpeg_decompress_struct dinfo; struct my_error_mgr_s jerr; JSAMPARRAY buffer; /* Output row buffer */ - int row_stride = 0, state = 0; /* physical row width in output buffer */ + int row_stride = 0; /* physical row width in output buffer */ JSAMPROW image, u_image, v_image; JSAMPROW row; /* point to buffer[0] */ @@ -1252,6 +1256,7 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da } } } else if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 ||input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) { + int state = 0; while (dinfo.output_scanline < dinfo.output_height) { /* jpeg_read_scanlines expects an array of pointers to scanlines. Here the array is only one element long, but you could ask formore than one scanline at a time if that's more convenient. */ jpeg_read_scanlines(&dinfo, buffer, 1); @@ -1260,7 +1265,6 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da state += row_stride; } debug_log("jpeg_read_scanlines"); - } /* Finish decompression */ @@ -1276,6 +1280,7 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da return iErrorCode; } +#if 0 static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,ExifFormat format, unsigned long components, unsigned char* data) { ExifData *ed = (ExifData *)exif; @@ -1323,6 +1328,7 @@ static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,Exif return 0; } +#endif EXPORT_API int mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) @@ -1369,7 +1375,7 @@ mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int heig dst = malloc(dst_size); 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); + ret = mm_image_encode_to_jpeg_file_with_libjpeg(filename, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality); free(dst); dst=NULL; } else { @@ -1434,7 +1440,7 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h 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; + dst = NULL; } else { TTRACE_END(); return MM_ERROR_IMAGE_NO_FREE_SPACE; @@ -1475,8 +1481,12 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena FILE *fp = fopen(filename, "rb"); unsigned char magic[2] = {0}; + size_t read_size = 0; if(fp) { - fread((void *)magic, 1, 2, fp); + read_size = fread((void *)magic, 1, 2, fp); + if (read_size > 0) + debug_log("Success fread"); + debug_log("%x %x", magic[0], magic[1]); fclose(fp); } else { @@ -1499,6 +1509,9 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena 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); + if (err != MM_ERROR_NONE) + debug_error("fail mm_util_get_image_size"); + unsigned char *dst = NULL; dst = malloc(dst_size); if(dst) { @@ -1589,6 +1602,9 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s 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); + if (err != MM_ERROR_NONE) + debug_error("fail mm_util_get_image_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); @@ -1649,8 +1665,12 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con FILE *fp = fopen(filename, "rb"); unsigned char magic[2] = {0}; + size_t read_size = 0; if(fp) { - fread((void *)magic, 1, 2, fp); + read_size = fread((void *)magic, 1, 2, fp); + if (read_size > 0) + debug_log("Success fread"); + debug_log("%x %x", magic[0], magic[1]); fclose(fp); } @@ -1668,6 +1688,9 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con 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); + if (err != MM_ERROR_NONE) + debug_error("fail mm_util_get_image_size"); + unsigned char *dst = NULL; dst = malloc(dst_size); if(dst) { @@ -1763,6 +1786,9 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v 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); + if (err != MM_ERROR_NONE) + debug_error("fail mm_util_get_image_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); diff --git a/jpeg/test/mm_util_jpeg_testsuite.c b/jpeg/test/mm_util_jpeg_testsuite.c index 09d9395..0f91471 100755 --- a/jpeg/test/mm_util_jpeg_testsuite.c +++ b/jpeg/test/mm_util_jpeg_testsuite.c @@ -101,7 +101,7 @@ static int _read_file(char *file_name, void **data, int *data_size) } -static int _write_file(char *file_name, void *data, int data_size) +static int _write_file(const char *file_name, void *data, int data_size) { FILE *fp = NULL; @@ -165,6 +165,17 @@ int main(int argc, char *argv[]) } else { ret = MM_ERROR_IMAGE_INTERNAL; } + } else if (!strcmp("enc2file", argv[1])) { + if (_read_file(argv[2], &src, &src_size)) { + width = atoi(argv[3]); + height = atoi(argv[4]); + quality = atoi(argv[5]); + fmt = atoi(argv[6]); + + ret = mm_util_jpeg_encode_to_file(ENCODE_RESULT_PATH, src, width, height, fmt, quality); + } else { + ret = MM_ERROR_IMAGE_INTERNAL; + } } else if (!strcmp("decode", argv[1])) { if (_read_file(argv[2], &src, &src_size)) { fmt = atoi(argv[3]); @@ -211,7 +222,7 @@ int main(int argc, char *argv[]) if(decoded_data.data) { fprintf(stderr, "\t##Decoded data##: %p\t width: %d\t height:%d\t size: %d\n", decoded_data.data, decoded_data.width, decoded_data.height, decoded_data.size); - char filename[BUFFER_SIZE]; + char filename[BUFFER_SIZE] = {0, }; memset(filename, 0, BUFFER_SIZE); if(fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) { snprintf(filename, BUFFER_SIZE, "%s%s", DECODE_RESULT_PATH, "rgb"); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 62a8e6a..c3382f4 100755 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.12 +Version: 0.13 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -49,6 +49,7 @@ mkdir -p m4 export CFLAGS+=" -Wextra -Wno-array-bounds" export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow" export CFLAGS+=" -Wwrite-strings -Wswitch-default" +export CFLAGS+=" -Werror" 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 -- 2.34.1