#include <unistd.h>
-#include <asm/unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <glib.h>
#include <thumbnail_util_type.h>
#include <dlog.h>
-#include <tzplatform_config.h>
#ifdef __cplusplus
#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 */
#include <thumbnail_util_private.h>
#include <media-thumbnail.h>
#include <media-util.h>
-#include <aul.h>
// LCOV_EXCL_START
static int __thumbnail_util_error_capi(int internal_error)
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