From 434db29ac0ccaef1719345fec0b147c3f93917d4 Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 6 Mar 2020 10:39:52 +0900 Subject: [PATCH] Use new video thumbnail extracting API provided by libmedia-thumbnail and Remove related codes. Duplicated thumbnail extracing codes were unified into libmedia-thumbnail. Change-Id: Ied325bbf74c669dba153fd3a34474e9538ad34e8 --- CMakeLists.txt | 2 +- packaging/libmedia-service.spec | 3 +- src/common/media-svc-util.c | 190 +--------------------------------------- 3 files changed, 5 insertions(+), 190 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45ad6b7..e208bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 icu-i18n libexif mm-fileinfo libmedia-utils aul uuid vconf capi-system-info mmutil-magick) +pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 icu-i18n libexif mm-fileinfo libmedia-utils aul uuid vconf capi-system-info mmutil-magick media-thumbnail) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index 1ed1b78..d2cb99a 100644 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -22,7 +22,8 @@ BuildRequires: pkgconfig(libmedia-utils) BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(mmutil-magick) +BuildRequires: pkgconfig(mmutil-magick) +BuildRequires: pkgconfig(media-thumbnail) %if 0%{?gtests:1} BuildRequires: pkgconfig(gmock) %endif diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 43dc6d1..fb5d0c8 100644 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "media-util-err.h" #include "media-svc-util.h" #include "media-svc-db-utils.h" @@ -1413,193 +1414,6 @@ static void __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int return; } -static void __get_rotation_and_cdis(const char *origin_path, mm_util_magick_rotate_type *rot_type, int *cdis_value) -{ - int err = MS_MEDIA_ERR_NONE; - MMHandleType tag = (MMHandleType) NULL; - char *p = NULL; - int size = 0; - int _cdis_value = 0; - mm_util_magick_rotate_type _rot_type = MM_UTIL_ROTATE_NUM; - - /* Get Content Tag attribute for orientation */ - err = mm_file_create_tag_attrs(&tag, origin_path); - if (err != FILEINFO_ERROR_NONE) { - *rot_type = MM_UTIL_ROTATE_0; - *cdis_value = 0; - return; - } - - err = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL); - if (err == 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; - } - - err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL); - if (err != FILEINFO_ERROR_NONE) - _cdis_value = 0; - - *rot_type = _rot_type; - *cdis_value = _cdis_value; - - err = mm_file_destroy_tag_attrs(tag); - if (err != FILEINFO_ERROR_NONE) { - media_svc_error("fail to free tag attr - err(%x)", err); - } - - return; -} - -static int __get_video_info(int cdis_value, const char *origin_path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *size) -{ - int err = MS_MEDIA_ERR_NONE; - MMHandleType content = (MMHandleType) NULL; - int _video_track_num = 0; - int _width = 0; - int _height = 0; - size_t _size = 0; - void *_frame = NULL; - - if (cdis_value == 1) { - media_svc_debug("This is CDIS vlaue 1"); - err = mm_file_create_content_attrs_safe(&content, origin_path); - } else { - err = mm_file_create_content_attrs(&content, origin_path); - } - - if (err != FILEINFO_ERROR_NONE) { - media_svc_error("mm_file_create_content_attrs fails : %d", err); - return MS_MEDIA_ERR_INTERNAL; - } - - err = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num, NULL); - if (err != FILEINFO_ERROR_NONE) { - media_svc_error("mm_file_get_attrs fails : %d", err); - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - *video_track_num = _video_track_num; - - if (_video_track_num == 0) { - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_NONE; - } - - err = mm_file_get_attrs(content, - MM_FILE_CONTENT_VIDEO_WIDTH, - &_width, - MM_FILE_CONTENT_VIDEO_HEIGHT, - &_height, - MM_FILE_CONTENT_VIDEO_THUMBNAIL, &_frame, /* raw image is RGB888 format */ - &_size, NULL); - - if (err != FILEINFO_ERROR_NONE) { - media_svc_error("mm_file_get_attrs fails : %d", err); - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - media_svc_debug("W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _size, _frame); - if (!_frame || !_width || !_height) { - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - - *width = _width; - *height = _height; - *size = _size; - *frame = calloc(1, _size); - memcpy(*frame, _frame, _size); - - mm_file_destroy_content_attrs(content); - - return MS_MEDIA_ERR_NONE; -} - -static int __get_video_thumb(int width, int height, void *frame, size_t size, mm_util_magick_rotate_type rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height) -{ - int err = MS_MEDIA_ERR_NONE; - mm_util_image_h img = NULL; - mm_util_image_h resize_img = NULL; - - media_svc_retvm_if(!STRING_VALID(thumb_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path"); - __media_svc_get_proper_thumb_size(width, height, &thumb_width, &thumb_height); - if (thumb_width <= 0 || thumb_height <= 0) { - media_svc_error("Failed to get thumb size"); - return MS_MEDIA_ERR_INTERNAL; - } - - media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height); - - err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img); - media_svc_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err); - - if (width > thumb_width || height > thumb_height) { - if (rot_type != MM_UTIL_ROTATE_0) { - err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img); - if (err != MM_UTIL_ERROR_NONE) - goto ERROR; - - err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path); - } else { - err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path); - } - } else { - if (rot_type != MM_UTIL_ROTATE_0) - err = mm_util_rotate_B_P(img, rot_type, thumb_path); - else - err = mm_util_resize_B_P(img, width, height, thumb_path); - } - -ERROR: - mm_image_destroy_image(img); - mm_image_destroy_image(resize_img); - if (err != MS_MEDIA_ERR_NONE) - return MS_MEDIA_ERR_INTERNAL; - - return MS_MEDIA_ERR_NONE; -} - -static int __create_video_thumbnail(const char *path, char *thumb_path) -{ - int ret = MS_MEDIA_ERR_NONE; - int cdis_value = 0; - unsigned int width = 0; - unsigned int height = 0; - void *frame = NULL; - int video_track_num = 0; - size_t size = 0; - mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM; - - __get_rotation_and_cdis(path, &rot_type, &cdis_value); - ret = __get_video_info(cdis_value, path, &video_track_num, &width, &height, &frame, &size); - media_svc_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to __get_video_info [%d]", ret); - media_svc_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track"); - - ret = __get_video_thumb(width, height, frame, size, rot_type, thumb_path, THUMB_WIDTH, THUMB_HEIGHT); - - SAFE_FREE(frame); - - return ret; -} - int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; @@ -1659,7 +1473,7 @@ int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_me return MS_MEDIA_ERR_INTERNAL; } } else { - return __create_video_thumbnail(path, thumb_path); + return create_video_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true); } return ret; -- 2.7.4