summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorminje.ahn <minje.ahn@samsung.com>2022-09-19 08:40:00 +0900
committerminje.ahn <minje.ahn@samsung.com>2022-09-19 14:56:22 +0900
commit6678129c4289346a4eeebb5d4d96d1b34fc3f196 (patch)
treee9b38ce6aff6952daa30d2634de5b00d2f51e300
parent828c4897c3dc1ee4b63d6872cd9aeb11514b3137 (diff)
downloadlibmedia-thumbnail-tizen.tar.gz
libmedia-thumbnail-tizen.tar.bz2
libmedia-thumbnail-tizen.zip
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>
-rwxr-xr-xinclude/media-thumbnail.h3
-rw-r--r--packaging/libmedia-thumbnail.spec2
-rwxr-xr-xsrc/media-thumbnail.c75
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 <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