From: minje.ahn Date: Sun, 18 Sep 2022 23:52:52 +0000 (+0900) Subject: Remove check functions to reduce duplication X-Git-Tag: accepted/tizen/unified/20220920.110707^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_7.0_unified_hotfix;p=platform%2Fcore%2Fapi%2Fthumbnail-util.git Remove check functions to reduce duplication Modified to check the path and the media type in libmedia-thumbnail. Change-Id: I7d47e879b34369955f3f390cacfb6676347bc7e2 Signed-off-by: minje.ahn --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f52470f..5761e67 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 aul") +SET(dependents "dlog glib-2.0 capi-base-common media-thumbnail libmedia-utils") SET(pc_dependents "capi-base-common") PROJECT(${fw_name}) diff --git a/include/thumbnail_util_private.h b/include/thumbnail_util_private.h index e6ef700..ff25077 100755 --- a/include/thumbnail_util_private.h +++ b/include/thumbnail_util_private.h @@ -21,14 +21,11 @@ #include -#include #include #include #include -#include #include #include -#include #ifdef __cplusplus @@ -41,56 +38,17 @@ extern "C" { #define LOG_TAG "CAPI_MEDIA_THUMBNAIL_UTIL" -typedef enum { - THUMBNAIL_UTIL_IMAGE = 0, - THUMBNAIL_UTIL_VIDEO, -} thumbnail_util_media_type_e; - typedef struct { int request_id; } thumbnail_s; #define FONT_COLOR_RESET "\033[0m" -#define FONT_COLOR_RED "\033[31m" #define FONT_COLOR_GREEN "\033[32m" -#define FONT_COLOR_YELLOW "\033[33m" -#define FONT_COLOR_BLUE "\033[34m" -#define FONT_COLOR_PURPLE "\033[35m" -#define FONT_COLOR_CYAN "\033[36m" -#define FONT_COLOR_GRAY "\033[37m" - -#define THUMB_GETTID() syscall(__NR_gettid) - -#define THUMB_RETV_IF(expr, val) do { \ - if (expr) { \ - LOGE(FONT_COLOR_RED"[%ld]"FONT_COLOR_RESET, THUMB_GETTID()); \ - return (val); \ - } \ - } while (0) - -#define THUMB_RETVM_IF(expr, val, fmt, arg...) do { \ - if (expr) { \ - LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, THUMB_GETTID(), ##arg); \ - return (val); \ - } \ - } while (0) #define THUMB_WARN(fmt, arg...) do { \ LOGW(FONT_COLOR_GREEN""fmt""FONT_COLOR_RESET, ##arg); \ } while (0) -#define THUMB_DBG(fmt, arg...) do { \ - LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define THUMB_ERR(fmt, arg...) do { \ - LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define THUMB_SDBG(fmt, arg...) do { \ - SECURE_LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg); \ - } while (0) - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include/thumbnail_util_type.h b/include/thumbnail_util_type.h index efb6eec..7d8ddde 100755 --- a/include/thumbnail_util_type.h +++ b/include/thumbnail_util_type.h @@ -18,7 +18,7 @@ #ifndef __TIZEN_MULTIMEDIA_THUMBNAIL_UTIL_TYPE_H__ #define __TIZEN_MULTIMEDIA_THUMBNAIL_UTIL_TYPE_H__ -#include +#include #include #ifdef __cplusplus diff --git a/packaging/capi-media-thumbnail-util.spec b/packaging/capi-media-thumbnail-util.spec index 5b8a2f3..43921d0 100644 --- a/packaging/capi-media-thumbnail-util.spec +++ b/packaging/capi-media-thumbnail-util.spec @@ -1,6 +1,6 @@ Name: capi-media-thumbnail-util Summary: A media thumbnail util library in Tizen Native API -Version: 0.1.29 +Version: 0.1.30 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -11,7 +11,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libmedia-utils) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(media-thumbnail) -BuildRequires: pkgconfig(aul) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/thumbnail_util.c b/src/thumbnail_util.c index f279654..e7ba103 100644 --- a/src/thumbnail_util.c +++ b/src/thumbnail_util.c @@ -18,7 +18,6 @@ #include #include #include -#include // LCOV_EXCL_START static int __thumbnail_util_error_capi(int internal_error) @@ -75,83 +74,15 @@ int thumbnail_util_destroy(thumbnail_h thumb) return THUMBNAIL_UTIL_ERROR_NONE; } // LCOV_EXCL_STOP -static int __thumbnail_util_check_media_type(const char *path, thumbnail_util_media_type_e *type) -{ - int ret = THUMBNAIL_UTIL_ERROR_NONE; - char mimetype[255] = {0,}; - const char *unsupported_type = "image/tiff"; - const char *supported_type = "application/vnd.ms-asf"; - - // Check file is existed - THUMB_RETV_IF(path == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER); - THUMB_SDBG("path [%s]", path); - if (access(path, R_OK) < 0) { - THUMB_RETVM_IF(errno == EACCES || errno == EPERM, THUMBNAIL_UTIL_ERROR_PERMISSION_DENIED, "Open failed: Permission Denied"); - - THUMB_ERR("Open failed: Invalid Path"); - return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER; - } - - // Check media type - ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); - THUMB_RETVM_IF(ret < 0, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION, "aul_get_mime_from_file failed"); - - THUMB_DBG("mime type : %s", mimetype); - - /* categorize from mimetype */ - if (strstr(mimetype, "image") != NULL) { - THUMB_RETVM_IF(!strcmp(mimetype, unsupported_type), THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT, "This is unsupport file type"); - *type = THUMBNAIL_UTIL_IMAGE; - return THUMBNAIL_UTIL_ERROR_NONE; - } else if (strstr(mimetype, "video") != NULL) { - *type = THUMBNAIL_UTIL_VIDEO; - return THUMBNAIL_UTIL_ERROR_NONE; - } else if (strstr(mimetype, supported_type) != NULL) { - *type = THUMBNAIL_UTIL_VIDEO; - return THUMBNAIL_UTIL_ERROR_NONE; - } - - return THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT; -} 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_util_media_type_e type; - - /* check media type */ - ret = __thumbnail_util_check_media_type(path, &type); - THUMB_RETVM_IF(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed"); - - /* If image, check support format */ - 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); - + int ret = create_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height); 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; - thumbnail_util_media_type_e type; - - /* check media type */ - ret = __thumbnail_util_check_media_type(path, &type); - THUMB_RETVM_IF(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed"); - - /* If image, check support format */ - if (type == THUMBNAIL_UTIL_IMAGE) { - ret = create_image_thumbnail_to_file(path, width, height, thumbnail_path, false); - } else { - if (!g_regex_match_simple("[^/]\\.jpe?g$", thumbnail_path, G_REGEX_CASELESS, 0)) { - THUMB_ERR("Unsupported path or extensions [%s]", thumbnail_path); - return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER; - } - - ret = create_video_thumbnail_to_file(path, width, height, thumbnail_path, false); - } - + int ret = create_thumbnail_to_file(path, width, height, thumbnail_path); return __thumbnail_util_error_capi(ret); -} +} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 67e5f57..45662ae 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ SET(fw_test "${fw_name}-test") INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED glib-2.0 libmedia-utils capi-base-common libtzplatform-config) +pkg_check_modules(${fw_test} REQUIRED capi-base-common) FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")