Replace thread creation before pushing data to async_queue after pushing data to... 67/157067/5 accepted/tizen/unified/20171025.075123 submit/tizen/20171024.105208
authorJiyong Min <jiyong.min@samsung.com>
Mon, 23 Oct 2017 08:22:21 +0000 (17:22 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Tue, 24 Oct 2017 01:51:18 +0000 (10:51 +0900)
(Fix callback not invoked because thread finish with no data)

Change-Id: Id6109637cac8900ff95ad20feef64c037592b284
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
imgp/include/mm_util_imgp_internal.h
imgp/mm_util_imgp.c
packaging/libmm-utility.spec

index 9e18a6d67c78f36cdb54e09d44d206b3b5e6043b..4abb74b01928a15235d029a3e625e7d52ba5b971 100755 (executable)
@@ -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;
index a8e19d6b094198a7048df4f3d31db583fb7f5149..174a871b6834b65079230259cee688f30a051348 100755 (executable)
@@ -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");
index ef1cdc4c33918d59fce7e81deb087041f0257b25..4fbf3716bcdb0de75b50334ea2534e2a00d9bd75 100755 (executable)
@@ -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