Remove duplicated mm_util_cb 79/190979/2
authorhj kim <backto.kim@samsung.com>
Wed, 10 Oct 2018 07:12:48 +0000 (16:12 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 10 Oct 2018 07:23:29 +0000 (16:23 +0900)
Change-Id: I4728fa5910dd0c449cc317411ff800dd267e1820

include/image_util_private.h
src/image_util.c [changed mode: 0644->0755]

index 1bd3854..dfeffd9 100755 (executable)
@@ -98,6 +98,11 @@ extern "C"
 typedef gboolean(*ModuleFunc)(void *, int, int, unsigned char *, unsigned char *, unsigned char *);
 
 typedef struct {
+       void *user_data;
+       image_util_transform_completed_cb completed_cb;
+} image_util_cb_s;
+
+typedef struct {
        mm_image_info_s *src;
        mm_image_info_s *dst;
 
@@ -119,7 +124,7 @@ typedef struct {
        bool set_rotate;
 
        /* for multi instance */
-       mm_util_cb_s *_util_cb;
+       image_util_cb_s *_util_cb;
        bool is_completed;
        bool is_finish;
        GThread* thread;
@@ -127,13 +132,8 @@ typedef struct {
 } mm_util_s;
 
 typedef struct {
-       void *user_data;
-       image_util_transform_completed_cb completed_cb;
-} image_util_cb_s;
-
-typedef struct {
        mm_util_s *image_h;
-       image_util_cb_s *_util_cb;
+//     image_util_cb_s *_util_cb;
 } transformation_s;
 
 typedef struct {
old mode 100644 (file)
new mode 100755 (executable)
index 2ce379f..612b89f
@@ -306,8 +306,7 @@ static int __mm_util_transform_exec(mm_util_s *handle, mm_image_info_s *source_i
        image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
        image_util_retvm_if(source_image == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid source_image");
 
-       image_util_debug("orig_image: %p [%zu] %lu X %lu (%u)", source_image->data, source_image->size,
-               source_image->width, source_image->height, source_image->color);
+       image_util_debug("orig_image: %p [%zu] %lu X %lu (%u)", source_image->data, source_image->size, source_image->width, source_image->height, source_image->color);
 
        handle->src = source_image;
        handle->dst = NULL;
@@ -315,17 +314,86 @@ static int __mm_util_transform_exec(mm_util_s *handle, mm_image_info_s *source_i
        ret = __mm_util_processing(handle);
        image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "__mm_util_processing failed [%d]", ret);
 
-       image_util_debug("result_image: %p [%zu] %lu X %lu (%u)", handle->dst->data, handle->dst->size,
-               handle->dst->width, handle->dst->height, handle->dst->color);
+       image_util_debug("result_image: %p [%zu] %lu X %lu (%u)", handle->dst->data, handle->dst->size, handle->dst->width, handle->dst->height, handle->dst->color);
 
        return ret;
 }
 
+static int __image_util_image_to_packet(mm_util_color_image_h image, media_packet_h *packet)
+{
+       int err = IMAGE_UTIL_ERROR_NONE;
+       mm_util_color_format_e format = 0;
+       unsigned long width = 0, height = 0;
+       void *buffer = NULL;
+       size_t buffer_size = 0;
+       media_format_h fmt = NULL;
+       void *packet_ptr = NULL;
+       uint64_t packet_size = 0;
+       size_t size = 0;
+
+       image_util_fenter();
+
+       err = __mm_util_get_color_image(image, &width, &height, &format, &buffer, &buffer_size);
+       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__mm_util_get_color_image failed (%d)", err);
+
+       err = __create_media_format(__image_format_to_mimetype(format), (unsigned int)width, (unsigned int)height, &fmt);
+       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__create_media_format failed (%d)", err);
+
+       err = media_packet_create_alloc(fmt, NULL, NULL, packet);
+       if (err != MEDIA_PACKET_ERROR_NONE) {
+               image_util_error("media_packet_create_alloc failed (%d)", err);
+               media_format_unref(fmt);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       err = media_packet_get_buffer_size(*packet, &packet_size);
+       if (err != MEDIA_PACKET_ERROR_NONE) {
+               image_util_error("media_packet_get_buffer_size failed (%d)", err);
+               media_packet_destroy(*packet);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       err = media_packet_get_buffer_data_ptr(*packet, &packet_ptr);
+       if (err != MEDIA_PACKET_ERROR_NONE) {
+               image_util_error("media_packet_get_buffer_data_ptr failed");
+               media_packet_destroy(*packet);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       if (packet_ptr == NULL || packet_size == 0) {
+               image_util_error("media_packet creation failed (%p, %" PRIu64 ")", packet_ptr, packet_size);
+               media_packet_destroy(*packet);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+       image_util_debug("Success - media_packet is created (%p, %" PRIu64 ")", packet_ptr, packet_size);
+
+       if ((uint64_t)buffer_size < packet_size) {
+               size = (size_t)buffer_size;
+       } else {
+               size = (size_t)packet_size;
+       }
+
+       image_util_debug("Size: result(%u) media_packet(%" PRIu64 ") copied(%zu)", buffer_size, packet_size, size);
+       memcpy(packet_ptr, buffer, size);
+
+       err = media_packet_set_buffer_size(*packet, (uint64_t)size);
+       if (err != MEDIA_PACKET_ERROR_NONE) {
+               image_util_error("media_packet_set_buffer_size failed (%d)", err);
+               media_packet_destroy(*packet);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       image_util_fleave();
+
+       return IMAGE_UTIL_ERROR_NONE;
+}
+
 gpointer __mm_util_thread_repeate(gpointer data)
 {
        mm_util_s *handle = (mm_util_s *) data;
        int ret = IMAGE_UTIL_ERROR_NONE;
        mm_util_color_image_h pop_data = NULL;
+       media_packet_h packet = NULL;
 
        image_util_retvm_if(handle == NULL, NULL, "invalid handle");
 
@@ -345,9 +413,17 @@ gpointer __mm_util_thread_repeate(gpointer data)
                else
                        image_util_error("Error - transform_exec");
 
-               if (handle->_util_cb->completed_cb) {
+               if ((handle->_util_cb != NULL) && (handle->_util_cb->completed_cb != NULL)) {
                        image_util_debug("completed_cb is called");
-                       handle->_util_cb->completed_cb(handle->dst, ret, handle->_util_cb->user_data);
+                       ret = __image_util_image_to_packet(handle->dst, &packet);
+                       if (ret != IMAGE_UTIL_ERROR_NONE) {
+                               image_util_error("__image_util_image_to_packet failed (%d)", ret);
+                               handle->_util_cb->completed_cb(NULL, ret, handle->_util_cb->user_data);
+                       } else {
+                               handle->_util_cb->completed_cb(&packet, ret, handle->_util_cb->user_data);
+                       }
+               } else {
+                       image_util_error("There is no callback");
                }
                __mm_util_destroy_color_image(pop_data);
                __mm_util_destroy_color_image(handle->dst);
@@ -376,7 +452,7 @@ static int __mm_util_create_thread(mm_util_s *handle)
        return ret;
 }
 
-static int __mm_util_transform(mm_util_imgp_h imgp_handle, mm_util_color_image_h image, mm_util_completed_callback completed_callback, void *user_data)
+static int __mm_util_transform(mm_util_imgp_h imgp_handle, mm_util_color_image_h image)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
        mm_util_s *handle = (mm_util_s *) imgp_handle;
@@ -385,19 +461,9 @@ static int __mm_util_transform(mm_util_imgp_h imgp_handle, mm_util_color_image_h
 
        image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
        image_util_retvm_if(image == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
-       image_util_retvm_if(completed_callback == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid completed_callback");
 
        image_util_debug("image: %p", image);
 
-       IMAGE_UTIL_SAFE_FREE(handle->_util_cb);
-       handle->_util_cb = (mm_util_cb_s *)calloc(1, sizeof(mm_util_cb_s));
-       if (handle->_util_cb) {
-               handle->_util_cb->completed_cb = completed_callback;
-               handle->_util_cb->user_data = user_data;
-       } else {
-               image_util_error("[ERROR] _util_cb_s");
-       }
-
        if (handle->queue) {
                image_util_debug("g_async_queue_push");
                g_async_queue_push(handle->queue, GINT_TO_POINTER(image));
@@ -456,92 +522,6 @@ static int _image_util_packet_to_image(media_packet_h packet, mm_util_color_imag
        return IMAGE_UTIL_ERROR_NONE;
 }
 
-static int _image_util_image_to_packet(mm_util_color_image_h image, media_packet_h *packet)
-{
-       int err = IMAGE_UTIL_ERROR_NONE;
-       mm_util_color_format_e format = 0;
-       unsigned long width = 0, height = 0;
-       void *buffer = NULL;
-       size_t buffer_size = 0;
-       media_format_h fmt = NULL;
-       void *packet_ptr = NULL;
-       uint64_t packet_size = 0;
-       size_t size = 0;
-
-       err = __mm_util_get_color_image(image, &width, &height, &format, &buffer, &buffer_size);
-       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__mm_util_get_color_image failed (%d)", err);
-
-       err = __create_media_format(__image_format_to_mimetype(format), (unsigned int)width, (unsigned int)height, &fmt);
-       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__create_media_format failed (%d)", err);
-
-       err = media_packet_create_alloc(fmt, NULL, NULL, packet);
-       if (err != MEDIA_PACKET_ERROR_NONE) {
-               image_util_error("media_packet_create_alloc failed (%d)", err);
-               media_format_unref(fmt);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-
-       err = media_packet_get_buffer_size(*packet, &packet_size);
-       if (err != MEDIA_PACKET_ERROR_NONE) {
-               image_util_error("media_packet_get_buffer_size failed (%d)", err);
-               media_packet_destroy(*packet);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-
-       err = media_packet_get_buffer_data_ptr(*packet, &packet_ptr);
-       if (err != MEDIA_PACKET_ERROR_NONE) {
-               image_util_error("media_packet_get_buffer_data_ptr failed");
-               media_packet_destroy(*packet);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-
-       if (packet_ptr == NULL || packet_size == 0) {
-               image_util_error("media_packet creation failed (%p, %" PRIu64 ")", packet_ptr, packet_size);
-               media_packet_destroy(*packet);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-       image_util_debug("Success - media_packet is created (%p, %" PRIu64 ")", packet_ptr, packet_size);
-
-       if ((uint64_t)buffer_size < packet_size) {
-               size = (size_t)buffer_size;
-       } else {
-               size = (size_t)packet_size;
-       }
-
-       image_util_debug("Size: result(%u) media_packet(%" PRIu64 ") copied(%zu)", buffer_size, packet_size, size);
-       memcpy(packet_ptr, buffer, size);
-
-       err = media_packet_set_buffer_size(*packet, (uint64_t)size);
-       if (err != MEDIA_PACKET_ERROR_NONE) {
-               image_util_error("media_packet_set_buffer_size failed (%d)", err);
-               media_packet_destroy(*packet);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-
-       image_util_debug("_image_util_image_to_packet succeed");
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static void _image_util_transform_completed_cb(mm_util_color_image_h raw_image, int error, void *user_data)
-{
-       int err = IMAGE_UTIL_ERROR_NONE;
-       image_util_cb_s *_util_cb = (image_util_cb_s *) user_data;
-       media_packet_h packet = NULL;
-
-       if ((_util_cb != NULL) && (_util_cb->completed_cb != NULL)) {
-               err = _image_util_image_to_packet(raw_image, &packet);
-               if (err != IMAGE_UTIL_ERROR_NONE) {
-                       image_util_error("_image_util_image_to_packet failed (%d)", err);
-                       _util_cb->completed_cb(NULL, err, _util_cb->user_data);
-               } else {
-                       _util_cb->completed_cb(&packet, _image_error_capi(ERR_TYPE_TRANSFORM, error), _util_cb->user_data);
-               }
-       }
-
-       return;
-}
-
 static int _image_util_create_transform_handle(transformation_s *handle)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
@@ -595,7 +575,6 @@ int image_util_transform_create(transformation_h * handle)
        transformation_s *_handle = (transformation_s *) calloc(1, sizeof(transformation_s));
        image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-       _handle->_util_cb = NULL;
        _handle->image_h = NULL;
 
        err = _image_util_create_transform_handle(_handle);
@@ -785,16 +764,17 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_
        err = _image_util_packet_to_image(src, &color_image);
        image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_packet_to_image failed");
 
-       _handle->_util_cb = (image_util_cb_s *) calloc(1, sizeof(image_util_cb_s));
-       if (_handle->_util_cb == NULL) {
+       _handle->image_h->_util_cb = (image_util_cb_s *) calloc(1, sizeof(image_util_cb_s));
+       if (_handle->image_h->_util_cb == NULL) {
                image_util_error("Memory allocation failed");
                __mm_util_destroy_color_image(color_image);
                return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
        }
-       _handle->_util_cb->user_data = user_data;
-       _handle->_util_cb->completed_cb = completed_cb;
 
-       err = __mm_util_transform(_handle->image_h, color_image, (mm_util_completed_callback) _image_util_transform_completed_cb, (void *)_handle->_util_cb);
+       _handle->image_h->_util_cb->user_data = user_data;
+       _handle->image_h->_util_cb->completed_cb = completed_cb;
+
+       err = __mm_util_transform(_handle->image_h, color_image);
        if (err != IMAGE_UTIL_ERROR_NONE) {
                image_util_error("Error - Run transform (%d)", err);
                __mm_util_destroy_color_image(color_image);
@@ -826,7 +806,6 @@ int image_util_transform_destroy(transformation_h handle)
        IMAGE_UTIL_SAFE_FREE(_handle->image_h->_util_cb);
        IMAGE_UTIL_SAFE_FREE(_handle->image_h);
 
-       IMAGE_UTIL_SAFE_FREE(_handle->_util_cb);
        IMAGE_UTIL_SAFE_FREE(_handle);
 
        image_util_fleave();