From 6678129c4289346a4eeebb5d4d96d1b34fc3f196 Mon Sep 17 00:00:00 2001 From: "minje.ahn" Date: Mon, 19 Sep 2022 08:40:00 +0900 Subject: Add function to check media type for thumbnail-util Function of check media type is moved from thumbnail-util for reduce duplication. Therefore, follow the same exception handling as thumbnail-util. Change-Id: I459bd33bc40c7d5ce9f1c0fca7ff4615e540828a Signed-off-by: minje.ahn --- include/media-thumbnail.h | 3 +- packaging/libmedia-thumbnail.spec | 2 +- src/media-thumbnail.c | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h index f091f1a..8c94cc9 100755 --- a/include/media-thumbnail.h +++ b/include/media-thumbnail.h @@ -38,7 +38,8 @@ int create_video_thumbnail_to_buffer(const char *path, unsigned int width, unsig int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate); int create_image_thumbnail_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 create_thumbnail_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 create_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path); #ifdef __cplusplus diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec index 32a2f4f..c5fb01f 100644 --- a/packaging/libmedia-thumbnail.spec +++ b/packaging/libmedia-thumbnail.spec @@ -1,6 +1,6 @@ Name: libmedia-thumbnail Summary: Media thumbnail service library for multimedia applications -Version: 0.4.2 +Version: 0.4.3 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c index 5d21169..6b4960e 100755 --- a/src/media-thumbnail.c +++ b/src/media-thumbnail.c @@ -24,8 +24,18 @@ #include #include "media-thumbnail.h" #include "media-thumbnail-debug.h" +#include #define MAX_THUMB_SIZE 2000 +#define MIME_TYPE_TIFF "image/tiff" +#define MIME_TYPE_ASF "application/vnd.ms-asf" +#define MIME_MAX_LEN 255 + +typedef enum { + MEDIA_THUMB_INVALID = 0, + MEDIA_THUMB_IMAGE, + MEDIA_THUMB_VIDEO, +} thumbnail_media_type_e; static void __get_rotation_and_cdis(const char *path, mm_util_rotate_type_e *rot_type, int *cdis_value) { @@ -417,3 +427,68 @@ int create_image_thumbnail_to_buffer(const char *path, unsigned int width, unsig return err; } + +static int __get_media_type(const char *path, thumbnail_media_type_e *media_type) +{ + int ret = MS_MEDIA_ERR_NONE; + char mime[MIME_MAX_LEN] = {0,}; + + ret = __check_path_validity(path); + thumb_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + + ret = aul_get_mime_from_file(path, mime, MIME_MAX_LEN); + thumb_retvm_if(ret < 0, MS_MEDIA_ERR_INTERNAL, "aul_get_mime_from_file failed"); + + thumb_dbg("mime type : %s", mime); + + if (strstr(mime, "image") != NULL) { + thumb_retvm_if(!strcmp(mime, MIME_TYPE_TIFF), MS_MEDIA_ERR_THUMB_UNSUPPORTED, "Unsupported type"); + *media_type = MEDIA_THUMB_IMAGE; + return MS_MEDIA_ERR_NONE; + } + + if (strstr(mime, "video") != NULL) { + *media_type = MEDIA_THUMB_VIDEO; + return MS_MEDIA_ERR_NONE; + } + + if (strcmp(mime, MIME_TYPE_ASF) == 0) { + *media_type = MEDIA_THUMB_VIDEO; + return MS_MEDIA_ERR_NONE; + } + + return MS_MEDIA_ERR_THUMB_UNSUPPORTED; +} + +int create_thumbnail_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 = MS_MEDIA_ERR_NONE; + thumbnail_media_type_e type = MEDIA_THUMB_INVALID; + + ret = __get_media_type(path, &type); + thumb_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "__get_media_type failed"); + + if (type == MEDIA_THUMB_IMAGE) + return create_image_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height); + else + return create_video_thumbnail_to_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height); +} + +int create_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path) +{ + int ret = MS_MEDIA_ERR_NONE; + thumbnail_media_type_e type = MEDIA_THUMB_INVALID; + + ret = __get_media_type(path, &type); + thumb_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "__get_media_type failed"); + + if (type == MEDIA_THUMB_IMAGE) + return create_image_thumbnail_to_file(path, width, height, thumb_path, false); + + if (!g_regex_match_simple("[^/]\\.jpe?g$", thumb_path, G_REGEX_CASELESS, 0)) { + thumb_err("Unsupported path or extensions [%s]", thumb_path); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + return create_video_thumbnail_to_file(path, width, height, thumb_path, false); +} \ No newline at end of file -- cgit v1.2.3