Change thumbnail generation location 02/169002/4 accepted/tizen/unified/20180206.064145 submit/tizen/20180205.005408
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 1 Feb 2018 23:49:45 +0000 (08:49 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 5 Feb 2018 01:58:45 +0000 (10:58 +0900)
Change thumbnail generation location from thumb-server to media-service

Change-Id: Iffb2364c075fb7bc1b72a37923cbc42cb3d8b266
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
CMakeLists.txt
md5/md5.h
packaging/libmedia-service.spec
plugin/media-content-plugin.c
src/common/media-svc-media.c
src/common/media-svc-util.c
src/common/media-svc.c
src/include/common/media-svc-env.h
src/include/common/media-svc-util.h

index 95b86dd..7d4e378 100755 (executable)
@@ -52,7 +52,7 @@ EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
 
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 db-util libexif mm-fileinfo media-thumbnail libmedia-utils aul uuid vconf capi-system-info mmutil-magick)
+pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 db-util libexif mm-fileinfo libmedia-utils aul uuid vconf capi-system-info mmutil-magick)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index ae9b307..b05cbcb 100755 (executable)
--- a/md5/md5.h
+++ b/md5/md5.h
@@ -30,10 +30,9 @@ typedef struct MD5Context {
        unsigned char in[64];
 } MD5_CTX;
 
-extern void   media_svc_MD5Init(MD5_CTX *context);
-extern void   media_svc_MD5Update(MD5_CTX *context, unsigned char const *buf, unsigned len);
-extern void   media_svc_MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
-
-extern void   MD5Transform(uint32_t buf[4], uint32_t const in[16]);
+extern void media_svc_MD5Init(MD5_CTX *context);
+extern void media_svc_MD5Update(MD5_CTX *context, unsigned char const *buf, unsigned len);
+extern void media_svc_MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
+extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
 
 #endif
index 63e3d33..4e5a9cd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-service
 Summary:    Media information service library for multimedia applications
-Version: 0.3.24
+Version: 0.3.25
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
@@ -18,7 +18,6 @@ BuildRequires:  pkgconfig(libexif)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(mm-fileinfo)
-BuildRequires:  pkgconfig(media-thumbnail)
 BuildRequires:  pkgconfig(libmedia-utils)
 BuildRequires:  pkgconfig(uuid)
 BuildRequires:  pkgconfig(libtzplatform-config)
index 75af2e5..dd6ee95 100755 (executable)
@@ -22,7 +22,6 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <mm_file.h>
-#include <media-thumbnail.h>
 #include <media-util.h>
 #include "media-svc.h"
 #include "media-svc-util.h"
index 53f51de..af44e8e 100755 (executable)
@@ -111,7 +111,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, const char *storage_id, me
                /* Get thumbnail for burst shot */
                char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
 
-               ret = _media_svc_request_thumbnail(content_info->path, thumb_path, sizeof(thumb_path), uid);
+               ret = _media_svc_create_thumbnail(content_info->path, thumb_path, sizeof(thumb_path), content_info->media_type, uid);
                if (ret == MS_MEDIA_ERR_NONE)
                        content_info->thumbnail_path = g_strdup(thumb_path);
        }
@@ -806,11 +806,10 @@ int _media_svc_change_validity_item_batch(const char *storage_id, const char *pa
 int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       char *burst_id = NULL;
 
-       char * db_fields = (char *)"media_uuid, folder_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, is_drm, storage_type, timeline, burst_id, storage_uuid";
+       char * db_fields = (char *)"media_uuid, folder_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, is_drm, storage_type, timeline, storage_uuid";
 
-       char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, %d, %d, %d, %d, %d, %Q, %Q);",
+       char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, %d, %d, %d, %d, %d, %Q);",
                storage_id, db_fields,
                content_info->media_uuid,
                content_info->folder_uuid,
@@ -824,12 +823,9 @@ int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_
                content_info->is_drm,
                content_info->storage_type,
                content_info->timeline,
-               burst_id,
                storage_id
                );
-#if 0
-               SQLITE3_SAFE_FREE(burst_id);
-#endif
+
        media_svc_debug("MAKE PASS 1 QUERY END");
 
        if (!stack_query) {
index 24a3e2e..a0bc2d8 100755 (executable)
@@ -39,7 +39,6 @@
 #include <aul/aul.h>
 #include <mm_file.h>
 #include <libexif/exif-data.h>
-#include <media-thumbnail.h>
 #include <media-util.h>
 #include <uuid/uuid.h>
 #include <mm_util_magick.h>
@@ -519,7 +518,7 @@ static int __media_svc_resize_artwork(const char *path, const char *img_format)
        unsigned int height = 0;
        unsigned int resized_width = 0;
        unsigned int resized_height = 0;
-       mm_util_img_code_type img_type = IMG_CODEC_NONE;
+       mm_util_img_codec_type img_type = IMG_CODEC_NONE;
 
        if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
                media_svc_debug("type [jpeg]");
@@ -741,14 +740,13 @@ int _media_svc_remove_all_files_in_dir(const char *dir_path)
        return MS_MEDIA_ERR_NONE;
 }
 
-int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
+int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
        char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
        char hash[255 + 1] = {0, };
-       char *thumbfile_ext = NULL;
        char *thumb_dir = NULL;
+       char *thumbfile_ext = NULL;
 
        ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
        if (!STRING_VALID(thumb_dir)) {
@@ -773,26 +771,29 @@ int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *t
                return MS_MEDIA_ERR_INTERNAL;
        }
 
-       /*media_svc_debug("img format is [%s]", img_format); */
+       if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
+               if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
+                       thumbfile_ext = (char *)"jpg";
+               } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
+                       thumbfile_ext = (char *)"png";
+               } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
+                       thumbfile_ext = (char *)"gif";
+               } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
+                       thumbfile_ext = (char *)"bmp";
+               } else {
+                       media_svc_error("Not proper img format");
+                       SAFE_FREE(thumb_dir);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
 
-       if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
-               thumbfile_ext = (char *)"jpg";
-       } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
-               thumbfile_ext = (char *)"png";
-       } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
-               thumbfile_ext = (char *)"gif";
-       } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
-               thumbfile_ext = (char *)"bmp";
+               snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
        } else {
-               media_svc_error("Not proper img format");
-               SAFE_FREE(thumb_dir);
-               return MS_MEDIA_ERR_INTERNAL;
+               if (strcasecmp(file_ext, "PNG") == 0)
+                       snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
+               else
+                       snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
        }
 
-       snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
-       SAFE_STRLCPY(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
-       /*media_svc_debug("thumb_path is [%s]", thumb_path); */
-
        SAFE_FREE(thumb_dir);
 
        return MS_MEDIA_ERR_NONE;
@@ -1232,7 +1233,7 @@ GET_WIDTH_HEIGHT:
                /*Get image width, height*/
                unsigned int img_width = 0;
                unsigned int img_height = 0;
-               mm_util_img_code_type img_type = IMG_CODEC_NONE;
+               mm_util_img_codec_type img_type = IMG_CODEC_NONE;
 
                mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
                if (content_info->media_meta.width == 0)
@@ -1536,7 +1537,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
 
                                mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
                                if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
-                                       ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
+                                       ret = _media_svc_get_thumbnail_path(content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid);
                                        if (ret != MS_MEDIA_ERR_NONE)
                                                media_svc_error("Fail to Get Thumbnail Path");
 
@@ -1770,16 +1771,225 @@ void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
        return;
 }
 
-int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
+int __media_svc_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;
+
+       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;
+       }
+
+       media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
+       unsigned int origin_w = 0;
+       unsigned int origin_h = 0;
+       unsigned int thumb_w = THUMB_WIDTH;
+       unsigned int thumb_h = THUMB_HEIGHT;
+       mm_util_img_codec_type image_type = IMG_CODEC_NONE;
+
+       if (path == NULL || thumb_path == NULL) {
+               media_svc_error("Invalid parameter");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+                       media_svc_error("Original path(%s) doesn't exist.", path);
+                       return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       if (max_length <= 0) {
+               media_svc_error("Length is invalid");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       ms_user_storage_type_e store_type = -1;
+       ret = ms_user_get_storage_type(uid, path, &store_type);
+
+       if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
+               media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
 
-       ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
+       media_svc_sec_debug("Path : %s", path);
+
+       //1. make hash path
+       ret = _media_svc_get_thumbnail_path(store_type, media_type, thumb_path, path, THUMB_EXT, uid);
        if (ret != MS_MEDIA_ERR_NONE) {
-               media_svc_error("thumbnail_request_from_db failed: %d", ret);
-               ret = MS_MEDIA_ERR_INTERNAL;
+               media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
+               SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
+               return ret;
+       }
+
+       //2. save thumbnail
+       if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+               ret = mm_util_extract_image_info(path, &image_type, &origin_w, &origin_h);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       media_svc_error("Getting image info is failed err: %d", ret);
+                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+
+               if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM)) {
+                       media_svc_error("This original image is too big");
+                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
+                       return MS_MEDIA_ERR_THUMB_TOO_BIG;
+               }
+
+               __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
+               ret = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       media_svc_error("mm_util_resize_P_P err: %d", ret);
+                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
        } else {
-               media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
+               MMHandleType content = (MMHandleType) NULL;
+               MMHandleType tag = (MMHandleType) NULL;
+
+               char *p = NULL;
+               int cdis_value = 0;
+               void *frame = NULL;
+               int video_track_num = 0;
+               char *err_msg = NULL;
+               int size = 0;
+               mm_util_image_h img = NULL;
+               mm_util_image_h resize_img = NULL;
+
+               /* Get Content Tag attribute for orientation */
+               ret = mm_file_create_tag_attrs(&tag, path);
+               mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
+
+               if (ret == FILEINFO_ERROR_NONE) {
+                       ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
+                       if (ret == FILEINFO_ERROR_NONE && size >= 0) {
+                               if (p == NULL) {
+                                       rot_type = MM_UTIL_ROTATE_0;
+                               } else {
+                                       if (strncmp(p, "90", size) == 0)
+                                               rot_type = MM_UTIL_ROTATE_90;
+                                       else if (strncmp(p, "180", size) == 0)
+                                               rot_type = MM_UTIL_ROTATE_180;
+                                       else if (strncmp(p, "270", size) == 0)
+                                               rot_type = MM_UTIL_ROTATE_270;
+                                       else
+                                               rot_type = MM_UTIL_ROTATE_0;
+                               }
+                               media_svc_debug("There is tag rotate : %d", rot_type);
+                       } else {
+                               media_svc_debug("There is NOT tag rotate");
+                               rot_type = MM_UTIL_ROTATE_0;
+                               SAFE_FREE(err_msg);
+                       }
+
+                       ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
+                       if (ret != FILEINFO_ERROR_NONE) {
+                               cdis_value = 0;
+                               SAFE_FREE(err_msg);
+                       }
+               } else {
+                       rot_type = MM_UTIL_ROTATE_0;
+                       cdis_value = 0;
+               }
+
+               ret = mm_file_destroy_tag_attrs(tag);
+               if (ret != FILEINFO_ERROR_NONE) {
+                       media_svc_error("fail to free tag attr - err(%x)", ret);
+               }
+
+               if (cdis_value == 1) {
+                       media_svc_debug("This is CDIS vlaue 1");
+                       ret = mm_file_create_content_attrs_safe(&content, path);
+               } else {
+                       ret = mm_file_create_content_attrs(&content, path);
+               }
+
+               if (ret != FILEINFO_ERROR_NONE) {
+                       media_svc_error("mm_file_create_content_attrs fails : %d", ret);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+
+               ret = mm_file_get_attrs(content, &err_msg, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &video_track_num, NULL);
+               if (ret != FILEINFO_ERROR_NONE) {
+                       media_svc_error("mm_file_get_attrs fails : %s", err_msg);
+                       SAFE_FREE(err_msg);
+                       goto ERROR;
+               }
+
+               if (video_track_num > 0) {
+                       ret = mm_file_get_attrs(content, &err_msg,
+                                               MM_FILE_CONTENT_VIDEO_WIDTH,
+                                               &origin_w,
+                                               MM_FILE_CONTENT_VIDEO_HEIGHT,
+                                               &origin_h,
+                                               MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
+                                               &size, NULL);
+
+                       if (ret != FILEINFO_ERROR_NONE) {
+                               media_svc_error("mm_file_get_attrs fails : %s", err_msg);
+                               SAFE_FREE(err_msg);
+                               goto ERROR;
+                       }
+
+                       media_svc_debug("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", origin_w, origin_h, size, frame, rot_type);
+                       if (frame == NULL || origin_w == 0 || origin_h == 0) {
+                               media_svc_error("Failed to get frame data");
+                               goto ERROR;
+                       }
+
+                       ret = __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
+                       if (thumb_w <= 0 || thumb_h <= 0) {
+                               media_svc_error("Failed to get thumb size");
+                               goto ERROR;
+                       }
+
+                       media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", origin_w, origin_h, thumb_w, thumb_h);
+
+                       ret = mm_util_create_handle(&img, (unsigned char *)frame, origin_w, origin_h, size, MM_UTIL_IMG_FMT_RGB888);
+                       if (origin_w > thumb_w || origin_h > thumb_h) {
+                               if (rot_type != MM_UTIL_ROTATE_0) {
+                                       ret = mm_util_resize_B_B(img, thumb_w, thumb_h, &resize_img);
+                                       if (ret != MM_UTIL_ERROR_NONE)
+                                               goto ERROR;
+                                       ret = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
+                               } else {
+                                       ret = mm_util_resize_B_P(img, thumb_w, thumb_h, thumb_path);
+                               }
+                       } else {
+                               if (rot_type != MM_UTIL_ROTATE_0)
+                                       ret = mm_util_rotate_B_P(img, rot_type, thumb_path);
+                               else
+                                       ret = mm_util_resize_B_P(img, origin_w, origin_h, thumb_path);
+                       }
+               }
+
+       ERROR:
+               mm_util_destroy_handle(img);
+               mm_util_destroy_handle(resize_img);
+               mm_file_destroy_content_attrs(content);
+
+               if (ret != MS_MEDIA_ERR_NONE)
+                       return MS_MEDIA_ERR_INTERNAL;
+
+               return MS_MEDIA_ERR_NONE;
        }
 
        return ret;
index c17fe00..daa593b 100755 (executable)
@@ -449,7 +449,7 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, const char *storag
                if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
                        char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
 
-                       ret = _media_svc_request_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), uid);
+                       ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
                        if (ret == MS_MEDIA_ERR_NONE)
                                content_info.thumbnail_path = g_strdup(thumb_path);
                }
@@ -516,7 +516,7 @@ int media_svc_move_item(MediaSvcHandle *handle, const char *storage_id, media_sv
                        return ret;
                }
 
-               _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid);
+               _media_svc_get_thumbnail_path(dest_storage, media_type, new_thumb_path, dest_path, THUMB_EXT, uid);
        }
 
        if (g_media_svc_move_item_data_cnt == 1) {
@@ -869,7 +869,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, const char *storage_id, media
                if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
                        memset(thumb_path, 0, sizeof(thumb_path));
 
-                       ret = _media_svc_request_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), uid);
+                       ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
                        if (ret == MS_MEDIA_ERR_NONE)
                                content_info.thumbnail_path = g_strdup(thumb_path);
                }
@@ -898,6 +898,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
        char *name_pinyin = NULL;
        bool pinyin_support = FALSE;
        char *sql = NULL;
+       int media_type = 0;
        GArray *query_array = NULL;
 
        media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
@@ -950,7 +951,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
        /*3. Get and update thumbnail_path if exists */
        sqlite3_stmt *sql_stmt = NULL;
 
-       sql = sqlite3_mprintf("SELECT path, thumbnail_path from '%q' where path LIKE '%q/%%' AND thumbnail_path is not null", storage_id, dst_path);
+       sql = sqlite3_mprintf("SELECT path, thumbnail_path, media_type from '%q' where path LIKE '%q/%%' AND thumbnail_path is not null", storage_id, dst_path);
        media_svc_debug("[SQL query] : %s", sql);
 
        ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
@@ -982,6 +983,8 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
                        return MS_MEDIA_ERR_DB_INTERNAL;
                }
 
+               media_type = sqlite3_column_int(sql_stmt, 2);
+
                ms_user_storage_type_e storage_type = -1;
 
                ret = ms_user_get_storage_type(uid, media_path, &storage_type);
@@ -991,7 +994,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
                        return ret;
                }
 
-               ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, media_path, THUMB_EXT, uid);
+               ret = _media_svc_get_thumbnail_path(storage_type, media_type, media_new_thumb_path, media_path, THUMB_EXT, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
                        SQLITE3_FINALIZE(sql_stmt);
@@ -1390,7 +1393,7 @@ int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_sv
                if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
                        char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
 
-                       ret = _media_svc_request_thumbnail(_new_content_info.path, thumb_path, sizeof(thumb_path), uid);
+                       ret = _media_svc_create_thumbnail(_new_content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
                        if (ret == MS_MEDIA_ERR_NONE)
                                _new_content_info.thumbnail_path = g_strdup(thumb_path);
                }
index ce6f014..c69db5f 100755 (executable)
@@ -135,6 +135,9 @@ extern "C" {
 #define MEDIA_SVC_TAG_UNKNOWN                          ""
 
 #define THUMB_EXT              "jpg"
+#define THUMB_MAX_ALLOWED_MEM 9000000
+#define THUMB_WIDTH 320
+#define THUMB_HEIGHT 240
 
 enum Exif_Orientation {
        NOT_AVAILABLE = 0,
index fa3941e..b19b1ea 100755 (executable)
@@ -53,7 +53,7 @@ char *_media_info_generate_uuid(void);
 int _media_svc_rename_file(const char *old_name, const char *new_name);
 int _media_svc_remove_file(const char *path);
 int _media_svc_remove_all_files_in_dir(const char *dir_path);
-int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
+int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
 int _media_svc_get_file_time(const char *full_path);
 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh);
 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
@@ -62,7 +62,7 @@ int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s
 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid);
 time_t __media_svc_get_timeline_from_str(const char *timstr);
 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
-int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid);
+int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid);
 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);
 bool _media_svc_check_pinyin_support(void);
 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type);