#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>
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]");
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)) {
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;
/*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)
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");
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;
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);
}
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) {
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);
}
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");
/*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);
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);
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);
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);
}