Use new image thumbnail extracting APIs provided by libmedia-thumbnail 31/227331/6
authorhj kim <backto.kim@samsung.com>
Wed, 11 Mar 2020 08:10:31 +0000 (17:10 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 13 Mar 2020 05:50:25 +0000 (14:50 +0900)
Change-Id: I47515eb4d64519b990f2821cffd4ed879f6ec781

CMakeLists.txt
include/thumbnail_util_private.h
packaging/capi-media-thumbnail-util.spec
src/thumbnail_util.c

index 31c70e3..1064ddf 100755 (executable)
@@ -26,7 +26,7 @@ SET(submodule "thumbnail-util")
 SET(fw_name "${project_prefix}-${service}-${submodule}")
 
 # for package file
-SET(dependents "dlog glib-2.0 capi-base-common media-thumbnail libmedia-utils storage aul mm-fileinfo mmutil-common mmutil-magick")
+SET(dependents "dlog glib-2.0 capi-base-common media-thumbnail libmedia-utils storage aul")
 SET(pc_dependents "capi-base-common")
 
 PROJECT(${fw_name})
index 7dcde72..1becf03 100755 (executable)
@@ -64,17 +64,6 @@ typedef struct {
 } thumbnail_s;
 
 typedef struct {
-       char *path;
-       thumbnail_util_extract_type_e extract_type;
-       thumbnail_util_media_type_e media_type;
-       unsigned int width;
-       unsigned int height;
-       char *thumbnail_path;
-       unsigned char *buffer;
-       int buffer_size;
-} thumbnail_data_s;
-
-typedef struct {
        thumbnail_extracted_cb thumb_extract_cb;
        void *user_data;
 } thumbnail_extract_cb_s;
index dac4aa0..b4dea14 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-thumbnail-util
 Summary:    A media thumbnail util library in Tizen Native API
-Version: 0.1.20
+Version: 0.1.21
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -13,9 +13,6 @@ BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(media-thumbnail)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(aul)
-BuildRequires:  pkgconfig(mm-fileinfo)
-BuildRequires:  pkgconfig(mmutil-common)
-BuildRequires:  pkgconfig(mmutil-magick)
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
index 336077e..4273b22 100644 (file)
@@ -24,8 +24,6 @@
 
 /* For sync API */
 #include <aul.h>
-#include <mm_util_magick.h>
-#include <mm_file.h>
 
 #define MAX_SIZE 16
 #define MAX_PATH_SIZE 4096
@@ -230,230 +228,6 @@ int thumbnail_util_destroy(thumbnail_h thumb)
        return ret;
 }
 
-////////////////////////////////////////// Sync
-
-static void __thumbnail_util_destroy_thumb_data(thumbnail_data_s *thumb)
-{
-       SAFE_FREE(thumb->path);
-       SAFE_FREE(thumb->thumbnail_path);
-       SAFE_FREE(thumb->buffer);
-       SAFE_FREE(thumb);
-}
-
-static void __thumbnail_util_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
-{
-       bool portrait = false;
-       double ratio = 0.0;
-
-       thumbnail_util_retm_if(orig_w == 0, "Invalid orig_w");
-       thumbnail_util_retm_if(orig_h == 0, "Invalid orig_h");
-       thumbnail_util_retm_if(!thumb_w, "Invalid thumb_w");
-       thumbnail_util_retm_if(!thumb_h, "Invalid thumb_h");
-
-       if (orig_w < orig_h)
-               portrait = true;
-
-       /* Set smaller length to default size */
-       if (portrait) {
-               if (orig_w < *thumb_w)
-                       *thumb_w = orig_w;
-               ratio = (double)orig_h / (double)orig_w;
-               *thumb_h = *thumb_w * ratio;
-       } else {
-               if (orig_h < *thumb_h)
-                       *thumb_h = orig_h;
-               ratio = (double)orig_w / (double)orig_h;
-               *thumb_w = *thumb_h * ratio;
-       }
-
-       thumbnail_util_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
-
-}
-
-static int __thumbnail_util_extract_video(thumbnail_data_s *thumb)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       MMHandleType content = NULL;
-       MMHandleType tag = NULL;
-       void *frame = NULL;
-       int video_track_num = 0;
-       int size = 0;
-       unsigned int width = 0;
-       unsigned int height = 0;
-       unsigned int thumb_width = 0;
-       unsigned int thumb_height = 0;
-       int cdis_value = 0;
-       mm_util_image_h img = NULL;
-
-       thumbnail_util_retvm_if(thumb == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Data is NULL");
-
-       thumb_width = thumb->width;
-       thumb_height = thumb->height;
-
-       //1. get CDIS
-       ret = mm_file_create_tag_attrs(&tag, thumb->path);
-       if (ret == FILEINFO_ERROR_NONE) {
-               ret = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
-               if (ret != FILEINFO_ERROR_NONE)
-                       cdis_value = 0;
-       } else {
-               cdis_value = 0;
-       }
-
-       ret = mm_file_destroy_tag_attrs(tag);
-       if (ret != FILEINFO_ERROR_NONE) {
-               thumbnail_util_error("fail to free tag attr - err(%x)", ret);
-       }
-
-       thumbnail_util_warn("CDIS vlaue[%d]", cdis_value);
-       if (cdis_value == 1)
-               ret = mm_file_create_content_attrs_safe(&content, thumb->path);
-       else
-               ret = mm_file_create_content_attrs(&content, thumb->path);
-
-       thumbnail_util_retvm_if(ret != FILEINFO_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION, "mm_file_create_content_attrs fails");
-
-       //2. get frame
-       ret = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &video_track_num, NULL);
-       if (ret != FILEINFO_ERROR_NONE) {
-               thumbnail_util_error("mm_file_get_attrs fails : %d", ret);
-               goto ERROR;
-       }
-
-       if (video_track_num > 0) {
-               ret = mm_file_get_attrs(content,
-                                       MM_FILE_CONTENT_VIDEO_WIDTH,
-                                       &width,
-                                       MM_FILE_CONTENT_VIDEO_HEIGHT,
-                                       &height,
-                                       MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame,
-                                       &size, NULL);
-
-               if (ret != FILEINFO_ERROR_NONE) {
-                       thumbnail_util_error("mm_file_get_attrs fails : %d", ret);
-                       goto ERROR;
-               }
-
-               thumbnail_util_debug("W[%d] H[%d] Size[%d] Frame[%p]", width, height, size, frame);
-
-               if (frame == NULL || width == 0 || height == 0) {
-                       thumbnail_util_error("Failed to get frame data");
-                       goto ERROR;
-               }
-
-               ret = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, frame, size, &img);
-               if (ret != MM_UTIL_ERROR_NONE) {
-                       thumbnail_util_error("Failed to mm_image_create_image");
-                       goto ERROR;
-               }
-
-               /* check thumb size */
-               __thumbnail_util_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
-
-               if (thumb->extract_type == THUMBNAIL_UTIL_FILE) {
-                       ret = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb->thumbnail_path);
-                       mm_image_destroy_image(img);
-                       if (ret != MM_UTIL_ERROR_NONE)
-                               goto ERROR;
-               } else {
-                       mm_util_image_h res_img = NULL;
-                       unsigned char *res_buf = NULL;
-                       unsigned int res_width = 0;
-                       unsigned int res_height = 0;
-                       size_t res_buf_size = 0;
-                       mm_util_color_format_e res_format = MM_UTIL_COLOR_NUM;
-
-                       ret = mm_util_resize_B_B(img, thumb_width, thumb_height, &res_img);
-                       mm_image_destroy_image(img);
-                       if (ret != MM_UTIL_ERROR_NONE)
-                               goto ERROR;
-                       ret = mm_image_get_image(res_img, &res_width, &res_height, &res_format, &res_buf, &res_buf_size);
-                       mm_image_destroy_image(res_img);
-                       if (ret != MM_UTIL_ERROR_NONE)
-                               goto ERROR;
-
-                       thumb->buffer = malloc(res_buf_size * sizeof(unsigned char));
-                       if (thumb->buffer != NULL) {
-                               memcpy(thumb->buffer, res_buf, res_buf_size);
-                               thumb->buffer_size = res_buf_size;
-                               thumb->width = res_width;
-                               thumb->height = res_height;
-                       } else {
-                               SAFE_FREE(res_buf);
-                               goto ERROR;
-                       }
-
-                       SAFE_FREE(res_buf);
-               }
-       }
-
-       mm_file_destroy_content_attrs(content);
-       return THUMBNAIL_UTIL_ERROR_NONE;
-ERROR:
-       mm_file_destroy_content_attrs(content);
-       return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
-}
-
-static int __thumbnail_util_extract(thumbnail_data_s *thumb)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       unsigned int orig_width = 0;
-       unsigned int orig_height = 0;
-       unsigned int thumb_width = 0;
-       unsigned int thumb_height = 0;
-       mm_util_img_codec_type type = IMG_CODEC_UNKNOWN_TYPE;
-
-       thumbnail_util_retvm_if(thumb == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Data is NULL");
-
-       if (thumb->media_type == THUMBNAIL_UTIL_IMAGE) {
-               thumb_width = thumb->width;
-               thumb_height = thumb->height;
-               /* Get original resolution */
-               ret = mm_util_extract_image_info(thumb->path, &type, &orig_width, &orig_height);
-               thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
-
-               __thumbnail_util_get_proper_thumb_size(orig_width, orig_height, &thumb_width, &thumb_height);
-
-               if (thumb->extract_type == THUMBNAIL_UTIL_FILE) {
-                       ret = mm_util_resize_P_P(thumb->path, thumb_width, thumb_height, thumb->thumbnail_path);
-                       thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
-
-               } else {
-                       mm_util_image_h res_img = NULL;
-                       unsigned char *buf = NULL;
-                       unsigned int width = 0;
-                       unsigned int height = 0;
-                       size_t buf_size = 0;
-                       mm_util_color_format_e format = MM_UTIL_COLOR_NUM;
-
-                       ret = mm_util_resize_P_B(thumb->path, thumb_width, thumb_height, MM_UTIL_COLOR_BGRA, &res_img);
-                       thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
-
-                       ret = mm_image_get_image(res_img, &width, &height, &format, &buf, &buf_size);
-                       mm_image_destroy_image(res_img);
-                       thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
-
-                       thumb->buffer = malloc(buf_size * sizeof(unsigned char));
-                       if (thumb->buffer != NULL) {
-                               memcpy(thumb->buffer, buf, buf_size);
-                               thumb->buffer_size = buf_size;
-                               thumb->width = width;
-                               thumb->height = height;
-                       } else {
-                               SAFE_FREE(buf);
-                               return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
-                       }
-
-                       SAFE_FREE(buf);
-               }
-       } else {
-               ret = __thumbnail_util_extract_video(thumb);
-               thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_extract_video failed");
-       }
-
-       return THUMBNAIL_UTIL_ERROR_NONE;
-}
-
 int __thumbnail_util_get_file_ext(const char *file_path, char *file_ext, int max_len)
 {
        int i = 0;
@@ -513,139 +287,49 @@ static int __thumbnail_util_check_media_type(const char *path, thumbnail_util_me
        return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER;
 }
 
-static bool __thumbnail_util_is_support_img(const char *path)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       mm_util_img_codec_type t = IMG_CODEC_UNKNOWN_TYPE;
-       unsigned int w = 0;
-       unsigned int h = 0;
-
-       ret = mm_util_extract_image_info(path, &t, &w, &h);
-       if (ret != MM_UTIL_ERROR_NONE || t == IMG_CODEC_UNKNOWN_TYPE)
-               return false;
-       else
-               return true;
-}
-
 int thumbnail_util_extract_to_buffer(const char *path, unsigned int width, unsigned int height, unsigned char **thumb_buffer, size_t *thumb_size, unsigned int *thumb_width, unsigned int *thumb_height)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       thumbnail_data_s *thumb = NULL;
        thumbnail_util_media_type_e type = -1;
 
-       thumbnail_util_retvm_if(!STRING_VALID(path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong path");
-       thumbnail_util_retvm_if((width > 2000 || width == 0) || (height > 2000 || width == 0), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong width/height");
-       thumbnail_util_retvm_if(thumb_buffer == NULL || thumb_size == NULL || thumb_width == NULL || thumb_height == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Out param is NULL");
-
        /* check media type */
        ret = __thumbnail_util_check_media_type(path, &type);
        thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed");
 
        /* If image, check support format */
-       if (type == THUMBNAIL_UTIL_IMAGE) {
-               if (__thumbnail_util_is_support_img(path) == false) {
-                       thumbnail_util_error("This image format is not supported");
-                       return THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT;
-               }
-       } else if (type == THUMBNAIL_UTIL_VIDEO) {
-               return __thumbnail_util_error_capi(create_video_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height, false));
-       }
-
-       thumb = calloc(1, sizeof(thumbnail_data_s));
-       thumb->extract_type = THUMBNAIL_UTIL_BUFFER;
-       thumb->media_type = type;
-       thumb->path = g_strdup(path);
-       thumb->width = width;
-       thumb->height = height;
-
-       if (thumb->path == NULL) {
-               __thumbnail_util_destroy_thumb_data(thumb);
-               return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = __thumbnail_util_extract(thumb);
-       if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
-               thumbnail_util_error("Extract failed");
-       } else {
-               *thumb_buffer = malloc(thumb->buffer_size);
-               memcpy(*thumb_buffer, thumb->buffer, thumb->buffer_size);
-               *thumb_size = thumb->buffer_size;
-               *thumb_width = thumb->width;
-               *thumb_height = thumb->height;
-       }
-
-       __thumbnail_util_destroy_thumb_data(thumb);
+       if (type == THUMBNAIL_UTIL_IMAGE)
+               ret = create_image_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height);
+       else
+               ret = create_video_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height, false);
 
-       return ret;
+       return __thumbnail_util_error_capi(ret);
 }
 
 int thumbnail_util_extract_to_file(const char *path, unsigned int width, unsigned int height, const char *thumbnail_path)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       char *check_str = NULL;
-       thumbnail_data_s *thumb = NULL;
        thumbnail_util_media_type_e type = -1;
 
-       thumbnail_util_retvm_if(!STRING_VALID(path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong path");
-       thumbnail_util_retvm_if((width > 2000 || width == 0) || (height > 2000 || height == 0), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong width/height");
-       thumbnail_util_retvm_if(!STRING_VALID(thumbnail_path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong thumbnail_path");
-
        /* check media type */
        ret = __thumbnail_util_check_media_type(path, &type);
        thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed");
 
        /* If image, check support format */
        if (type == THUMBNAIL_UTIL_IMAGE) {
-               if (__thumbnail_util_is_support_img(path) == false) {
-                       thumbnail_util_error("This image format is not supported");
-                       return THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT;
-               }
-       }
-
-       /* check thumbnail path is writable */
-       check_str = g_path_get_dirname(thumbnail_path);
-       if (check_str != NULL) {
-               if (access(check_str, W_OK) != 0) {
-                       thumbnail_util_error("No permission to write[%s]", check_str);
-                       SAFE_FREE(check_str);
-                       return THUMBNAIL_UTIL_ERROR_PERMISSION_DENIED;
-               } else {
-                       SAFE_FREE(check_str);
-               }
-       }
-
-       /* If video file, thumbnail extension is only JPEG */
-       if (type == THUMBNAIL_UTIL_VIDEO) {
+               ret = create_image_thumbnail_to_file(path, width, height, thumbnail_path);
+       } else {
                char ext[255] = { 0 };
                ret = __thumbnail_util_get_file_ext(thumbnail_path, ext, sizeof(ext));
                thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_get_file_ext failed");
+
+               /* If video file, thumbnail extension is only JPEG */
                if (strcasecmp(ext, "JPG") != 0 && strcasecmp(ext, "JPEG") != 0) {
                        thumbnail_util_error("Wrong file name[%s]", thumbnail_path);
                        return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER;
                }
 
-               return __thumbnail_util_error_capi(create_video_thumbnail_to_file(path, width, height, thumbnail_path, false));
+               ret = create_video_thumbnail_to_file(path, width, height, thumbnail_path, false);
        }
 
-       thumb = calloc(1, sizeof(thumbnail_data_s));
-       thumb->extract_type = THUMBNAIL_UTIL_FILE;
-       thumb->media_type = type;
-       thumb->path = g_strdup(path);
-       thumb->width = width;
-       thumb->height = height;
-       thumb->thumbnail_path = g_strdup(thumbnail_path);
-
-       if (thumb->path == NULL || thumb->thumbnail_path == NULL) {
-               __thumbnail_util_destroy_thumb_data(thumb);
-               return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = __thumbnail_util_extract(thumb);
-       if (ret != THUMBNAIL_UTIL_ERROR_NONE)
-               thumbnail_util_error("Extract failed");
-
-       __thumbnail_util_destroy_thumb_data(thumb);
-
-       return ret;
+       return __thumbnail_util_error_capi(ret);
 }
-