From: Jiyong Min Date: Mon, 23 Oct 2017 08:22:21 +0000 (+0900) Subject: Replace thread creation before pushing data to async_queue after pushing data to... X-Git-Tag: submit/tizen/20171024.105208^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae0cff4d57ecb52d0e3d90a41c056e7b7df5dcab;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Replace thread creation before pushing data to async_queue after pushing data to async_queue. (Fix callback not invoked because thread finish with no data) Change-Id: Id6109637cac8900ff95ad20feef64c037592b284 Signed-off-by: Jiyong Min --- diff --git a/imgp/include/mm_util_imgp_internal.h b/imgp/include/mm_util_imgp_internal.h index 9e18a6d..4abb74b 100755 --- a/imgp/include/mm_util_imgp_internal.h +++ b/imgp/include/mm_util_imgp_internal.h @@ -161,8 +161,6 @@ typedef struct { guint dst_buf_size; /* for multi instance */ - 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 a8e19d6..174a871 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -743,6 +743,15 @@ static int __mm_util_handle_init(mm_util_s *handle) handle->set_resize = FALSE; handle->set_rotate = FALSE; + /*These are a communicator for thread*/ + if (!handle->queue) + handle->queue = g_async_queue_new(); + + if (handle->queue == NULL) { + mm_util_error("g_async_queue_new failed"); + return MM_UTIL_ERROR_INVALID_OPERATION; + } + return ret; } @@ -880,7 +889,7 @@ gpointer _mm_util_thread_repeate(gpointer data) { mm_util_s *handle = (mm_util_s *) data; int ret = MM_UTIL_ERROR_NONE; - gint64 end_time = 0; + media_packet_h pop_data = NULL; if (!handle) { mm_util_error("[ERROR] - handle"); @@ -888,44 +897,31 @@ gpointer _mm_util_thread_repeate(gpointer data) } while (!handle->is_finish) { - end_time = g_get_monotonic_time() + 1 * G_TIME_SPAN_SECOND; mm_util_debug("waiting..."); - g_mutex_lock(&(handle->thread_mutex)); - if (!g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time)) { - mm_util_debug("exit loop"); - g_mutex_unlock(&(handle->thread_mutex)); - break; - } - mm_util_debug("<=== get run transform thread signal"); - g_mutex_unlock(&(handle->thread_mutex)); + pop_data = (media_packet_h) g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND); + mm_util_debug("get from data or timeout"); - if (handle->is_finish) { - mm_util_debug("exit loop"); - break; + if (pop_data == NULL) { + mm_util_error("The data is null"); + continue; } - media_packet_h pop_data = (media_packet_h) g_async_queue_try_pop(handle->queue); - - if (!pop_data) { - mm_util_error("[NULL] Queue data"); - } else { - ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */ - if (ret == MM_UTIL_ERROR_NONE) - mm_util_debug("Success - transform_exec"); - else - mm_util_error("Error - transform_exec"); - - if (handle->_util_cb->completed_cb) { - mm_util_debug("completed_cb"); - handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data); - mm_util_debug("completed_cb %p", &handle->dst); - } + ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */ + if (ret == MM_UTIL_ERROR_NONE) + mm_util_debug("Success - transform_exec"); + else + mm_util_error("Error - transform_exec"); - __mm_util_handle_refresh(handle); + if (handle->_util_cb->completed_cb) { + mm_util_debug("completed_cb"); + handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data); + mm_util_debug("completed_cb %p", &handle->dst); } + __mm_util_handle_refresh(handle); } mm_util_debug("exit thread"); + handle->thread = NULL; return NULL; } @@ -939,15 +935,10 @@ static int __mm_util_create_thread(mm_util_s *handle) return MM_UTIL_ERROR_INVALID_PARAMETER; } - g_mutex_init(&(handle->thread_mutex)); - - /*These are a communicator for thread*/ - if (!handle->queue) - handle->queue = g_async_queue_new(); - else - mm_util_error("ERROR - async queue is already created"); - - g_cond_init(&(handle->thread_cond)); + if (handle->thread) { + mm_util_error("Thread is already created"); + return MM_UTIL_ERROR_NONE; + } /*create threads*/ handle->thread = g_thread_new("transform_thread", (GThreadFunc)_mm_util_thread_repeate, (gpointer)handle); @@ -956,6 +947,8 @@ static int __mm_util_create_thread(mm_util_s *handle) return MM_UTIL_ERROR_INVALID_OPERATION; } + mm_util_debug("New thread is created"); + return ret; } @@ -1295,11 +1288,6 @@ _mm_util_handle_finalize(mm_util_s *handle) /* g_thread_exit(handle->thread); */ if (handle->thread) { handle->is_finish = TRUE; - g_mutex_lock(&(handle->thread_mutex)); - g_cond_signal(&(handle->thread_cond)); - mm_util_debug("===> send signal(finish) to transform_thread"); - g_mutex_unlock(&(handle->thread_mutex)); - g_thread_join(handle->thread); } @@ -1308,10 +1296,6 @@ _mm_util_handle_finalize(mm_util_s *handle) handle->queue = NULL; } - g_mutex_clear(&(handle->thread_mutex)); - - g_cond_clear(&(handle->thread_cond)); - mm_util_debug("Success - Finalize Handle"); return ret; @@ -1344,16 +1328,6 @@ int mm_util_create(mm_util_imgp_h *imgp_handle) return ret; } - ret = __mm_util_create_thread(handle); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("ERROR - Create thread"); - IMGP_FREE(handle); - TTRACE_END(); - return ret; - } else { - mm_util_debug("Success -__mm_util_create_thread"); - } - *imgp_handle = (mm_util_imgp_h)handle; TTRACE_END(); @@ -1505,10 +1479,14 @@ int mm_util_transform(mm_util_imgp_h imgp_handle, media_packet_h src_packet, mm_ if (handle->queue) { mm_util_debug("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)); - mm_util_debug("===> send signal to transform_thread"); - g_mutex_unlock(&(handle->thread_mutex)); + ret = __mm_util_create_thread(handle); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("ERROR - Create thread"); + TTRACE_END(); + return ret; + } else { + mm_util_debug("Success -__mm_util_create_thread"); + } } TTRACE_END(); @@ -1548,6 +1526,7 @@ int mm_util_destroy(mm_util_imgp_h imgp_handle) mm_util_s *handle = (mm_util_s *) imgp_handle; TTRACE_BEGIN("MM_UTILITY:IMGP:DESTROY"); + mm_util_debug("enter"); if (!handle) { mm_util_error("[ERROR] - handle"); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index ef1cdc4..4fbf371 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.42 +Version: 0.43 Release: 0 Group: System/Libraries License: Apache-2.0