#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)
{
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