Add function to check media type for thumbnail-util 21/281421/4 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.063205 accepted/tizen/7.0/unified/hotfix/20221116.105408 accepted/tizen/unified/20220920.110703 tizen_7.0_m2_release
authorminje.ahn <minje.ahn@samsung.com>
Sun, 18 Sep 2022 23:40:00 +0000 (08:40 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Mon, 19 Sep 2022 05:56:22 +0000 (14:56 +0900)
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 <minje.ahn@samsung.com>
include/media-thumbnail.h
packaging/libmedia-thumbnail.spec
src/media-thumbnail.c

index f091f1a..8c94cc9 100755 (executable)
@@ -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
index 32a2f4f..c5fb01f 100644 (file)
@@ -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
index 5d21169..6b4960e 100755 (executable)
 #include <media-util.h>
 #include "media-thumbnail.h"
 #include "media-thumbnail-debug.h"
+#include <aul.h>
 
 #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