summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt31
-rw-r--r--NOTICE4
-rwxr-xr-xinclude/media-thumbnail-debug.h (renamed from src/include/util/media-thumb-debug.h)37
-rwxr-xr-xinclude/media-thumbnail.h28
-rwxr-xr-xmd5/md5.c252
-rwxr-xr-xmd5/md5.h38
-rwxr-xr-xmd5/media-thumb-hash.c107
-rwxr-xr-xmedia-thumbnail.pc.in2
-rw-r--r--packaging/libmedia-thumbnail.spec37
-rw-r--r--packaging/media-thumbnail-server.manifest5
-rwxr-xr-xserver/CMakeLists.txt19
-rwxr-xr-xserver/include/thumb-server-internal.h33
-rwxr-xr-xserver/thumb-server-internal.c349
-rwxr-xr-xserver/thumb-server.c71
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h53
-rwxr-xr-xsrc/include/media-thumb-internal.h41
-rwxr-xr-xsrc/include/util/media-thumb-db.h39
-rwxr-xr-xsrc/include/util/media-thumb-util.h45
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c622
-rwxr-xr-xsrc/media-thumb-internal.c66
-rwxr-xr-xsrc/media-thumbnail.c657
-rwxr-xr-xsrc/util/media-thumb-db.c92
-rwxr-xr-xsrc/util/media-thumb-util.c110
-rw-r--r--unittest/CMakeLists.txt4
-rwxr-xr-xunittest/libmedia_thumbnail_unittest.cpp29
25 files changed, 446 insertions, 2325 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3313844..eeff3fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,18 +1,11 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6...2.8.12)
PROJECT(media-thumbnail C)
SET(VERSION_MAJOR 1)
SET(VERSION "${VERSION_MAJOR}.0.0")
SET(MEDIATHUMB-LIB "media-thumbnail")
-SET(MEDIAHASH-LIB "media-hash")
SET(SRCS
src/media-thumbnail.c
- src/util/media-thumb-util.c
- src/ipc/media-thumb-ipc.c
- )
-SET(HASH_SRCS
- md5/md5.c
- md5/media-thumb-hash.c
)
SET(VENDOR "samsung")
@@ -31,10 +24,15 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/ipc ${CMAKE_SOURCE_DIR}/server/include ${CMAKE_SOURCE_DIR}/md5)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+IF(WITH_DA_PROFILE)
+INCLUDE(FindPkgConfig)
+ pkg_check_modules(pkgs REQUIRED dlog mm-fileinfo aul mmutil-common mmutil-magick mmutil-gif mmutil-jpeg libexif)
+ELSE(WITH_DA_PROFILE)
INCLUDE(FindPkgConfig)
- pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul libmedia-utils libtzplatform-config mmutil-common mmutil-magick)
+ pkg_check_modules(pkgs REQUIRED dlog mm-fileinfo aul mmutil-common mmutil-magick)
+ENDIF(WITH_DA_PROFILE)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -57,24 +55,23 @@ ADD_DEFINITIONS("-DPACKAGE_NAME=\"${PKGNAME}\"")
ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
ADD_DEFINITIONS("-D_GNU_SOURCE")
+IF(WITH_DA_PROFILE)
+ ADD_DEFINITIONS("-DUSE_MEMORY_USAGE_REDUCTION")
+ ADD_DEFINITIONS("-DENABLE_IMAGE_SIZE_LIMITATION")
+ENDIF(WITH_DA_PROFILE)
+
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both")
CONFIGURE_FILE(media-thumbnail.pc.in media-thumbnail.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/media-thumbnail.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
LINK_DIRECTORIES(${LIB_INSTALL_DIR})
-ADD_LIBRARY(${MEDIAHASH-LIB} SHARED ${HASH_SRCS})
-SET_TARGET_PROPERTIES(${MEDIAHASH-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${MEDIAHASH-LIB} PROPERTIES VERSION ${VERSION})
ADD_LIBRARY(${MEDIATHUMB-LIB} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${MEDIATHUMB-LIB} ${pkgs_LDFLAGS} ${MEDIAHASH-LIB})
+TARGET_LINK_LIBRARIES(${MEDIATHUMB-LIB} ${pkgs_LDFLAGS})
SET_TARGET_PROPERTIES(${MEDIATHUMB-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${MEDIATHUMB-LIB} PROPERTIES VERSION ${VERSION})
INSTALL(TARGETS ${MEDIATHUMB-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(TARGETS ${MEDIAHASH-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-
-ADD_SUBDIRECTORY(server)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumbnail.h DESTINATION include/${MEDIATHUMB-LIB})
IF(BUILD_GTESTS)
diff --git a/NOTICE b/NOTICE
index 35369be..ccdad52 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,7 +1,3 @@
Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
Except as noted, this software is licensed under Apache License, Version 2.
Please, see the LICENSE file for Apache License terms and conditions.
-
-Some parts of libmedia-thumbnail are licensed under the Public domain
- - md5/md5.c
- - md5/md5.h
diff --git a/src/include/util/media-thumb-debug.h b/include/media-thumbnail-debug.h
index 2aa517f..4bdbd45 100755
--- a/src/include/util/media-thumb-debug.h
+++ b/include/media-thumbnail-debug.h
@@ -3,8 +3,6 @@
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -19,16 +17,11 @@
*
*/
-#ifndef _MEDIA_THUMB_DEBUG_H_
-#define _MEDIA_THUMB_DEBUG_H_
+#ifndef _MEDIA_THUMBNAIL_DEBUG_H_
+#define _MEDIA_THUMBNAIL_DEBUG_H_
-#include <stdio.h>
-#include <stdlib.h>
#include <dlog.h>
-
#include <unistd.h>
-#include <asm/unistd.h>
-#include <errno.h>
#ifdef LOG_TAG
#undef LOG_TAG
@@ -39,11 +32,6 @@
#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_dbg(fmt, arg...) do { \
LOGD(FONT_COLOR_RESET fmt "\n", ##arg); \
@@ -61,24 +49,6 @@
LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
} while (0)
-#define thumb_dbg_slog(fmt, arg...) do { \
- SECURE_LOGD(FONT_COLOR_CYAN""fmt""FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define thumb_warn_slog(fmt, arg...) do { \
- SECURE_LOGW(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define thumb_err_slog(fmt, arg...) do { \
- SECURE_LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define ERR_BUF_LENGTH 256
-#define thumb_stderror(fmt) do { \
- char thumb_stderror_buffer[ERR_BUF_LENGTH] = {0,}; \
- LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGTH)); \
- } while (0)
-
#define thumb_retm_if(expr, fmt, arg...) do { \
if (expr) { \
LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
@@ -98,5 +68,4 @@
} \
} while (0)
-#endif /*_MEDIA_THUMB_DEBUG_H_*/
-
+#endif /*_MEDIA_THUMBNAIL_DEBUG_H_*/
diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h
index 395855f..99a1df8 100755
--- a/include/media-thumbnail.h
+++ b/include/media-thumbnail.h
@@ -3,8 +3,6 @@
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -23,37 +21,31 @@
#ifndef _MEDIA_THUMBNAIL_H_
#define _MEDIA_THUMBNAIL_H_
-#include <sys/types.h>
#include <stdbool.h>
-#include <fcntl.h>
+#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
-#define CONTENT_THUMB_DEFAULT_WIDTH 320
-#define CONTENT_THUMB_DEFAULT_HEIGHT 240
-
-typedef int (*ThumbFunc) (int error_code, char* path, void* data);
-typedef void (*ThumbRawFunc) (int error_code, int request_id, const char* org_path, int thumb_width, int thumb_height, unsigned char* thumb_data, int thumb_size, void* data);
-
-int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid);
-int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_path, int width, int height, ThumbRawFunc func, void *user_data, uid_t uid);
-
-int thumbnail_request_cancel_media(unsigned int request_id);
-int thumbnail_request_cancel_raw_data(int request_id);
+/* media-thumbnail error */
+#define THUMB_OK 0
+#define THUMB_FAIL -1
+#define THUMB_PERM -2
+#define THUMB_UNSUPPORTED -3
int create_video_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate);
-int create_video_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, bool auto_rotate, bool is_server_request);
+int create_video_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_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);
-
+int get_image_info(const char *path, unsigned int *width, unsigned int *height);
#ifdef __cplusplus
}
#endif
#endif /*_MEDIA_THUMBNAIL_H_*/
-
diff --git a/md5/md5.c b/md5/md5.c
deleted file mode 100755
index c223cfe..0000000
--- a/md5/md5.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
- * will fill a supplied 16-byte array with the digest.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h> /* for memcpy() */
-#include "md5.h"
-
-#if (__BYTE_ORDER == 1234)
-#define byteReverse(buf, len) /* Nothing */
-#else
-void byteReverse(unsigned char *buf, unsigned longs);
-
-/*
- * Note: this code is harmless on little-endian machines.
- */
-void byteReverse(unsigned char *buf, unsigned longs)
-{
- uint32_t t;
- do {
- t = (uint32_t) ((unsigned)buf[3] << 8 | buf[2]) << 16 |
- ((unsigned)buf[1] << 8 | buf[0]);
- *(uint32_t *) buf = t;
- buf += 4;
- } while (--longs);
-}
-#endif
-
-/*
- * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-void media_thumb_MD5Init(MD5_CTX *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bits[0] = 0;
- ctx->bits[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-void media_thumb_MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len)
-{
- uint32_t t;
-
- /* Update bitcount */
-
- t = ctx->bits[0];
- if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) {
- ctx->bits[1]++; /* Carry from low to high */
- }
-
- ctx->bits[1] += len >> 29;
-
- t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
-
- /* Handle any leading odd-sized chunks */
-
- if (t) {
- unsigned char *p = (unsigned char *)ctx->in + t;
-
- t = 64 - t;
- if (len < t) {
- memcpy(p, buf, len);
- return;
- }
- memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- buf += t;
- len -= t;
- }
- /* Process data in 64-byte chunks */
-
- while (len >= 64) {
- memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- buf += 64;
- len -= 64;
- }
-
- /* Handle any remaining bytes of data. */
-
- memcpy(ctx->in, buf, len);
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void media_thumb_MD5Final(unsigned char digest[16], MD5_CTX *ctx)
-{
- unsigned count;
- unsigned char *p;
-
- /* Compute number of bytes mod 64 */
- count = (ctx->bits[0] >> 3) & 0x3F;
-
- /* Set the first char of padding to 0x80. This is safe since there is
- always at least one byte free */
- p = ctx->in + count;
- *p++ = 0x80;
-
- /* Bytes of padding needed to make 64 bytes */
- count = 64 - 1 - count;
-
- /* Pad out to 56 mod 64 */
- if (count < 8) {
- /* Two lots of padding: Pad the first block to 64 bytes */
- memset(p, 0, count);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
-
- /* Now fill the next block with 56 bytes */
- memset(ctx->in, 0, 56);
- } else {
- /* Pad block to 56 bytes */
- memset(p, 0, count - 8);
- }
- byteReverse(ctx->in, 14);
-
- /* Append length in bits and transform */
- memcpy(((uint32_t *) ctx->in)+14, ctx->bits, sizeof(uint32_t)*2);
-
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- byteReverse((unsigned char *)ctx->buf, 4);
- memcpy(digest, ctx->buf, 16);
- memset((char *)ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
-}
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1(x, y, z) (x & y | ~x & z) */
-#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
-#define F2(x, y, z) (F1((z), (x), (y)))
-#define F3(x, y, z) ((x) ^ (y) ^ (z))
-#define F4(x, y, z) ((y) ^ ((x) | ~(z)))
-
-/* This is the central step in the MD5 algorithm. */
-#define MD5STEP(f, w, x, y, z, data, s) \
-(w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x)
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-void MD5Transform(uint32_t buf[4], uint32_t const in[16])
-{
- register uint32_t a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
diff --git a/md5/md5.h b/md5/md5.h
deleted file mode 100755
index 72c9994..0000000
--- a/md5/md5.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
- * will fill a supplied 16-byte array with the digest.
- */
-
-
-#ifndef _MD5_H_
-#define _MD5_H_
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#define MD5_HASHBYTES 16
-
-typedef struct MD5Context {
- uint32_t buf[4];
- uint32_t bits[2];
- unsigned char in[64];
-} MD5_CTX;
-
-extern void media_thumb_MD5Init(MD5_CTX *context);
-extern void media_thumb_MD5Update(MD5_CTX *context, unsigned char const *buf, unsigned len);
-extern void media_thumb_MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
-extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
-
-#endif
diff --git a/md5/media-thumb-hash.c b/md5/media-thumb-hash.c
deleted file mode 100755
index b0a94f7..0000000
--- a/md5/media-thumb-hash.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "md5.h"
-#include <string.h>
-#include <alloca.h>
-#include <media-util-err.h>
-
-
-static const char ACCEPTABLE_URI_CHARS[96] = {
- /* ! " # $ % & ' ( ) * + , - . / */
- 0x00, 0x3F, 0x20, 0x20, 0x28, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x2A,
- 0x28, 0x3F, 0x3F, 0x1C,
- /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
- 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20,
- 0x20, 0x2C, 0x20, 0x20,
- /* @ A B C D E F G H I J K L M N O */
- 0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
- 0x3F, 0x3F, 0x3F, 0x3F,
- /* P Q R S T U V W X Y Z [ \ ] ^ _ */
- 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
- 0x20, 0x20, 0x20, 0x3F,
- /* ` a b c d e f g h i j k l m n o */
- 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
- 0x3F, 0x3F, 0x3F, 0x3F,
- /* p q r s t u v w x y z { | } ~ DEL */
- 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
- 0x20, 0x20, 0x3F, 0x20
-};
-
-char *_media_thumb_generate_hash_name(const char *file)
-{
- int n;
- MD5_CTX ctx;
- static char md5out[(2 * MD5_HASHBYTES) + 1];
- unsigned char hash[MD5_HASHBYTES];
- static const char hex[] = "0123456789abcdef";
-
- char *uri;
- char *t;
- const unsigned char *c;
- int length;
-
- if (!file) {
- return NULL;
- }
-
- length = 3 * strlen(file) + 9;
-
- memset(md5out, 0, sizeof(md5out));
-
-#define _check_uri_char(c) \
-((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08))
-
- uri = alloca(length);
- if (uri == NULL) {
- return NULL;
- }
-
- strncpy(uri, "file://", length);
- uri[length - 1] = '\0';
- t = uri + sizeof("file://") - 1;
-
- for (c = (const unsigned char *)file; *c != '\0'; c++) {
- if (!_check_uri_char(*c)) {
- *t++ = '%';
- *t++ = hex[*c >> 4];
- *t++ = hex[*c & 15];
- } else {
- *t++ = *c;
- }
- }
- *t = '\0';
-#undef _check_uri_char
-
- memset(&ctx, 0x00, sizeof(MD5_CTX));
-
- media_thumb_MD5Init(&ctx);
- media_thumb_MD5Update(&ctx, (unsigned char const *)uri, (unsigned)strlen(uri));
- media_thumb_MD5Final(hash, &ctx);
-
- for (n = 0; n < MD5_HASHBYTES; n++) {
- md5out[2 * n] = hex[hash[n] >> 4];
- md5out[2 * n + 1] = hex[hash[n] & 0x0f];
- }
- md5out[2 * n] = '\0';
-
- return md5out;
-}
diff --git a/media-thumbnail.pc.in b/media-thumbnail.pc.in
index 2ba5b97..d9e8954 100755
--- a/media-thumbnail.pc.in
+++ b/media-thumbnail.pc.in
@@ -9,5 +9,5 @@ Name: @PROJECT_NAME@
Description: Samsung Linux platform @PROJECT_NAME@ library
Version: @VERSION@
Requires:
-Libs: -L${libdir} -lmedia-thumbnail -lmedia-hash
+Libs: -L${libdir} -lmedia-thumbnail
Cflags: -I${includedir}/media-thumbnail
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index c218607..997a92c 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,26 +1,27 @@
Name: libmedia-thumbnail
Summary: Media thumbnail service library for multimedia applications
-Version: 0.3.3
+Version: 0.4.9
Release: 0
Group: Multimedia/Libraries
-License: Apache-2.0 and PD
+License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source1001: %{name}.manifest
Source1002: %{name}-devel.manifest
-Source1003: media-thumbnail-server.manifest
-Requires: media-server
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(mm-fileinfo)
BuildRequires: pkgconfig(aul)
-BuildRequires: pkgconfig(libmedia-utils)
-BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(mmutil-common)
BuildRequires: pkgconfig(mmutil-magick)
%if 0%{?gtests:1}
-BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(gmock)
+%endif
+%if 0%{?_with_da_profile:1}
+BuildRequires: pkgconfig(mmutil-gif)
+BuildRequires: pkgconfig(mmutil-jpeg)
+BuildRequires: pkgconfig(libexif)
%endif
%description
@@ -35,22 +36,14 @@ Group: Multimedia/Development
%description devel
Description: Media thumbnail service library for multimedia applications (development)
-%package -n media-thumbnail-server
-Summary: Thumbnail generator
-Requires: %{name} = %{version}-%{release}
-Group: Multimedia/Service
-
-%description -n media-thumbnail-server
-Description: Media Thumbnail Server
-
-
%prep
%setup -q
-cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} .
+cp %{SOURCE1001} %{SOURCE1002} .
%build
-%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0}
+%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+ -DWITH_DA_PROFILE=%{?_with_da_profile:1}%{!?_with_da_profile:0}
make %{?_smp_mflags}
%install
@@ -75,9 +68,3 @@ make %{?_smp_mflags}
%{_libdir}/*.so
%{_libdir}/pkgconfig/media-thumbnail.pc
%{_includedir}/media-thumbnail/*.h
-
-%files -n media-thumbnail-server
-%manifest media-thumbnail-server.manifest
-%defattr(-,root,root,-)
-%{_bindir}/media-thumbnail-server
-%license LICENSE.APLv2.0
diff --git a/packaging/media-thumbnail-server.manifest b/packaging/media-thumbnail-server.manifest
deleted file mode 100644
index c00c25b..0000000
--- a/packaging/media-thumbnail-server.manifest
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
- <domain name="_" />
- </request>
-</manifest>
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
deleted file mode 100755
index e0fbb06..0000000
--- a/server/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-SET(THUMB-SERVER
- ../src/util/media-thumb-db.c
- ../src/media-thumb-internal.c
- thumb-server.c
- thumb-server-internal.c)
-
-INCLUDE(FindPkgConfig)
- pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog mm-fileinfo aul libmedia-utils libtzplatform-config)
-
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both -pie")
-
-ADD_EXECUTABLE(media-thumbnail-server ${THUMB-SERVER})
-TARGET_LINK_LIBRARIES(media-thumbnail-server ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
-INSTALL(TARGETS media-thumbnail-server DESTINATION ${BINDIR})
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
deleted file mode 100755
index 5d862c9..0000000
--- a/server/include/thumb-server-internal.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * media-thumbnail-server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include "media-thumb-ipc.h"
-#include "media-thumb-db.h"
-
-#ifndef _THUMB_DAEMON_INTERNAL_H_
-#define _THUMB_DAEMON_INTERNAL_H_
-
-gboolean _thumb_daemon_start_jobs(gpointer data);
-gboolean _thumb_server_prepare_socket(int *sock_fd);
-gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data);
-
-#endif /*_THUMB_DAEMON_INTERNAL_H_*/
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
deleted file mode 100755
index 4f1e5f9..0000000
--- a/server/thumb-server-internal.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * media-thumbnail-server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "thumb-server-internal.h"
-#include "media-thumb-util.h"
-#include "media-thumb-debug.h"
-#include "media-thumbnail.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <tzplatform_config.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
-#define THUMB_DEFAULT_WIDTH 320
-#define THUMB_DEFAULT_HEIGHT 240
-#define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
-#define THUMB_EMPTY_STR ""
-
-static int __thumbnail_get_data(const char *origin_path, char *thumb_path)
-{
- int err = MS_MEDIA_ERR_NONE;
- int file_type = THUMB_NONE_TYPE;
-
- thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
- thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
- thumb_dbg_slog("Origin path : %s", origin_path);
-
- file_type = _media_thumb_get_file_type(origin_path);
-
- if (file_type == THUMB_IMAGE_TYPE) {
- err = create_image_thumbnail_to_file(origin_path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
- } else if (file_type == THUMB_VIDEO_TYPE) {
- err = create_video_thumbnail_to_file(origin_path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
- } else {
- thumb_err("invalid file type");
- return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
- }
-
- thumb_dbg("Thumb data is generated successfully");
-
- return err;
-}
-
-static int __thumbnail_get_raw_data(const char *origin_path, unsigned int *width, unsigned int *height, unsigned char **data, size_t *size)
-{
- int err = MS_MEDIA_ERR_NONE;
- int file_type = THUMB_NONE_TYPE;
-
- thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
- thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
- thumb_dbg_slog("Origin path : %s", origin_path);
-
- file_type = _media_thumb_get_file_type(origin_path);
-
- if (file_type == THUMB_IMAGE_TYPE) {
- err = create_image_thumbnail_to_buffer(origin_path, *width, *height, data, size, width, height);
- } else if (file_type == THUMB_VIDEO_TYPE) {
- err = create_video_thumbnail_to_buffer(origin_path, *width, *height, data, size, width, height, true, true);
- } else {
- thumb_err("invalid file type");
- return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
- }
-
- return err;
-}
-
-static int __media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
-
- memset(res_msg->dst_path, 0, MAX_FILEPATH_LEN);
- res_msg->status = MS_MEDIA_ERR_NONE;
-
- if (!g_file_test(req_msg->org_path, G_FILE_TEST_IS_REGULAR)) {
- thumb_err("origin_path does not exist in file system.");
- res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST;
- return MS_MEDIA_ERR_FILE_NOT_EXIST;
- }
-
- err = _media_thumb_get_thumb_from_db(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
- thumb_retvm_if(err == MS_MEDIA_ERR_NONE, err, "Already exists");
- if (strlen(res_msg->dst_path) == 0) {
- err = _media_thumb_get_hash_name(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_hash_name failed - %d", err);
- SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
- res_msg->status = err;
- return err;
- }
- }
-
- thumb_dbg_slog("Thumb path : %s", res_msg->dst_path);
-
- err = __thumbnail_get_data(req_msg->org_path, res_msg->dst_path);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_thumbnail_get_data failed - %d", err);
- SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
- res_msg->status = err;
-
- goto DB_UPDATE;
- }
-
- res_msg->msg_type = THUMB_RESPONSE;
-
-DB_UPDATE:
- err = _media_thumb_update_db(req_msg->org_path, res_msg->dst_path, req_msg->uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_update_db failed : %d", err);
- res_msg->status = err;
- }
-
- return err;
-}
-
-static int __media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
- unsigned char *data = NULL;
- size_t thumb_size = 0;
- unsigned int thumb_w = 0;
- unsigned int thumb_h = 0;
-
- thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
-
- thumb_w = (req_msg->thumb_width > 0) ? req_msg->thumb_width : THUMB_DEFAULT_WIDTH;
- thumb_h = (req_msg->thumb_height > 0) ? req_msg->thumb_height : THUMB_DEFAULT_HEIGHT;
-
- res_msg->status = MS_MEDIA_ERR_NONE;
- res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
-
- err = __thumbnail_get_raw_data(req_msg->org_path, &thumb_w, &thumb_h, &data, &thumb_size);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_thumbnail_get_data failed - %d", err);
- res_msg->status = err;
- res_msg->thumb_size = 0;
- goto ERROR;
- }
-
- res_msg->thumb_width = thumb_w;
- res_msg->thumb_height = thumb_h;
- res_msg->thumb_size = thumb_size;
- res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
- if (res_msg->thumb_data) {
- memcpy(res_msg->thumb_data, data, thumb_size);
- } else {
- thumb_err("Allocation failed");
- err = MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
-ERROR:
- SAFE_FREE(data);
-
- return err;
-}
-
-static int __thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- if (req_msg->msg_type == THUMB_REQUEST_RAW_DATA) {
- err = __media_thumb_process_raw(req_msg, res_msg);
- if (err != MS_MEDIA_ERR_NONE)
- thumb_err("_media_thumb_process_raw is failed: %d", err);
- } else if (req_msg->msg_type == THUMB_REQUEST_DB_INSERT) {
- err = __media_thumb_process(req_msg, res_msg);
- if (err != MS_MEDIA_ERR_NONE)
- thumb_err("_media_thumb_process is failed: %d", err);
- }
-
- return err;
-}
-
-static void __thumb_server_send_deny_message(int sockfd)
-{
- thumbMsg msg = {0};
-
- msg.msg_type = THUMB_RESPONSE;
- msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
-
- if (send(sockfd, &msg, sizeof(msg), 0) < 0)
- thumb_stderror("send failed");
-}
-
-gboolean _thumb_daemon_start_jobs(gpointer data)
-{
- int client_sock;
- struct sockaddr_un serv_addr;
- ms_thumb_server_msg send_msg;
-
- if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &client_sock) < 0) {
- thumb_err("ms_ipc_create_server_socket failed");
- return G_SOURCE_REMOVE;
- }
-
- memset(&serv_addr, 0, sizeof(serv_addr));
-
- serv_addr.sun_family = AF_UNIX;
- SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
-
- /* Connecting to the thumbnail server */
- if (connect(client_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- thumb_stderror("connect");
- goto ERROR;
- }
-
- send_msg.msg_type = MS_MSG_THUMB_SERVER_READY;
-
- if (send(client_sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
- thumb_stderror("send failed");
- goto ERROR;
- }
-
- thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
-ERROR:
- close(client_sock);
-
- return G_SOURCE_REMOVE;
-}
-
-gboolean _thumb_server_read_socket(GIOChannel *channel, GIOCondition condition, gpointer data)
-{
- struct sockaddr_un client_addr;
- unsigned int client_addr_len;
- thumbMsg recv_msg;
- thumbMsg res_msg;
- ms_peer_credentials credentials;
- GMainLoop *thumb_server = (GMainLoop *)data;
-
- int sock = -1;
- int client_sock = -1;
-
- int buf_size = 0;
- int send_len = 0;
- int send_pos = 0;
- unsigned char *buf = NULL;
-
- memset((void *)&recv_msg, 0, sizeof(recv_msg));
- memset((void *)&res_msg, 0, sizeof(res_msg));
- memset((void *)&credentials, 0, sizeof(credentials));
-
- sock = g_io_channel_unix_get_fd(channel);
- thumb_retvm_if(sock < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
-
- client_addr_len = sizeof(client_addr);
-
- if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
- thumb_stderror("accept failed");
- return G_SOURCE_CONTINUE;
- }
-
- if (ms_cynara_receive_untrusted_message_thumb(client_sock, &recv_msg, &credentials) != MS_MEDIA_ERR_NONE) {
- thumb_err("ms_cynara_receive_untrusted_message_thumb failed");
- goto ERROR;
- }
-
- if (recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER) {
- if (ms_cynara_check(&credentials, MEDIA_STORAGE_PRIVILEGE) != MS_MEDIA_ERR_NONE) {
- thumb_err("Cynara denied access to process request");
- __thumb_server_send_deny_message(client_sock);
- goto ERROR;
- }
- } else {
- thumb_warn("Shutting down...");
- g_main_loop_quit(thumb_server);
- close(client_sock);
-
- return G_SOURCE_REMOVE;
- }
-
- SAFE_FREE(credentials.smack);
- SAFE_FREE(credentials.uid);
-
- thumb_warn_slog("Received [%d] %.*s(%zu) from PID(%d)", recv_msg.msg_type, MAX_FILEPATH_LEN, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
-
- __thumb_daemon_process_job(&recv_msg, &res_msg);
-
- if (res_msg.msg_type == 0)
- res_msg.msg_type = recv_msg.msg_type;
- res_msg.request_id = recv_msg.request_id;
- SAFE_STRLCPY(res_msg.org_path, recv_msg.org_path, sizeof(res_msg.org_path));
- if (res_msg.msg_type != THUMB_RESPONSE_RAW_DATA)
- res_msg.thumb_size = 0;
- else
- res_msg.dst_path[0] = '\0';
-
- _media_thumb_set_buffer(&res_msg, &buf, &buf_size);
-
- while (buf_size > 0) {
- if ((send_len = send(client_sock, buf + send_pos, buf_size, 0)) < 0) {
- thumb_stderror("send failed");
- break;
- }
- send_pos += send_len;
- buf_size -= send_len;
- }
-
- SAFE_FREE(buf);
- SAFE_FREE(res_msg.thumb_data);
-
-ERROR:
- close(client_sock);
-
- return G_SOURCE_CONTINUE;
-}
-
-gboolean _thumb_server_prepare_socket(int *sock_fd)
-{
- int sock;
-
- if (ms_ipc_create_server_socket(MS_THUMB_DAEMON_PORT, &sock) < 0) {
- thumb_err("ms_ipc_create_server_socket failed");
- return FALSE;
- }
-
- if (ms_cynara_enable_credentials_passing(sock) != MS_MEDIA_ERR_NONE) {
- thumb_err("ms_cynara_enable_credentials_passing failed");
- close(sock);
- return FALSE;
- }
-
- *sock_fd = sock;
-
- return TRUE;
-}
diff --git a/server/thumb-server.c b/server/thumb-server.c
deleted file mode 100755
index 750f782..0000000
--- a/server/thumb-server.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * media-thumbnail-server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "media-thumbnail.h"
-#include "media-thumb-debug.h"
-#include "media-thumb-ipc.h"
-#include "media-thumb-util.h"
-#include "thumb-server-internal.h"
-#include <pthread.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
-
-static GMainLoop *g_thumb_server_mainloop;
-
-int main(void)
-{
- int sockfd = -1;
- GIOChannel *channel = NULL;
-
- if (ms_cynara_initialize() != MS_MEDIA_ERR_NONE) {
- thumb_err("Cynara initialization failed");
- return -1;
- }
-
- /* Create and bind new tcp socket */
- if (!_thumb_server_prepare_socket(&sockfd)) {
- thumb_err("Failed to create socket");
- return -1;
- }
-
- g_thumb_server_mainloop = g_main_loop_new(NULL, FALSE);
-
- /* Create new channel to watch tcp socket */
- channel = g_io_channel_unix_new(sockfd);
- g_io_add_watch(channel, G_IO_IN, _thumb_server_read_socket, g_thumb_server_mainloop);
- g_io_channel_unref(channel);
-
- g_idle_add(_thumb_daemon_start_jobs, NULL);
-
- thumb_info("Thumbnail server is running");
- g_main_loop_run(g_thumb_server_mainloop);
-
- thumb_info("Thumbnail server is shutting down");
- close(sockfd);
- g_main_loop_unref(g_thumb_server_mainloop);
- ms_cynara_finish();
-
- return 0;
-}
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
deleted file mode 100755
index b242b8e..0000000
--- a/src/include/ipc/media-thumb-ipc.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <sys/un.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <sys/types.h>
-
-#include "media-thumb-internal.h"
-#include "media-util-ipc.h"
-#include "media-server-ipc.h"
-
-#ifndef _MEDIA_THUMB_IPC_H_
-#define _MEDIA_THUMB_IPC_H_
-
-#define MAX_PATH_SIZE 4096
-
-int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size);
-
-int _media_thumb_request_async(int msg_type, unsigned int request_id, const char *origin_path, thumbUserData *userData, uid_t uid);
-
-int _media_thumb_request_raw_data_async(int msg_type,
- int request_id,
- const char *origin_path,
- int width,
- int height,
- thumbRawUserData *userData,
- uid_t uid);
-
-#endif /*_MEDIA_THUMB_IPC_H_*/
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
deleted file mode 100755
index 530f664..0000000
--- a/src/include/media-thumb-internal.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <media-util-err.h>
-#include "media-thumbnail.h"
-#include "media-thumb-util.h"
-
-#ifndef _MEDIA_THUMB_INTERNAL_H_
-#define _MEDIA_THUMB_INTERNAL_H_
-
-typedef struct {
- ThumbFunc func;
- void *user_data;
-} thumbUserData;
-
-typedef struct {
- ThumbRawFunc func;
- void *user_data;
-} thumbRawUserData;
-
-int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
-
-#endif /*_MEDIA_THUMB_INTERNAL_H_*/
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
deleted file mode 100755
index 27c21ed..0000000
--- a/src/include/util/media-thumb-db.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sqlite3.h>
-#include <media-util.h>
-
-#ifndef _MEDIA_THUMB_DB_H_
-#define _MEDIA_THUMB_DB_H_
-
-#define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
-#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); }
-#define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } }
-
-#define SELECT_THUMB_BY_PATH "SELECT media_thumbnail_path FROM media WHERE media_path='%q' AND media_thumbnail_path IS NOT NULL;"
-#define UPDATE_THUMB_BY_PATH "UPDATE media SET media_thumbnail_path = '%q' WHERE media_path='%q';"
-
-int _media_thumb_get_thumb_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid);
-int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid);
-
-#endif /*_MEDIA_THUMB_DB_H_*/
-
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
deleted file mode 100755
index 59a85f7..0000000
--- a/src/include/util/media-thumb-util.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef _MEDIA_THUMB_UTIL_H_
-#define _MEDIA_THUMB_UTIL_H_
-
-#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
-#define STRING_VALID(str) \
- ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
-#define THUMB_MALLOC(src, size) { if (size <= 0) {src = NULL; } \
- else { src = malloc(size); if (src) memset(src, 0x0, size); } }
-#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
-
-#define THUMB_NONE_TYPE -1 /* None */
-#define THUMB_IMAGE_TYPE 0 /* Image */
-#define THUMB_VIDEO_TYPE 1 /* Video */
-
-int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len);
-int _media_thumb_get_file_type(const char *file_full_path);
-
-char* _media_thumb_generate_hash_name(const char *file);
-
-#endif /*_MEDIA_THUMB_UTIL_H_*/
-
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
deleted file mode 100755
index c196f71..0000000
--- a/src/ipc/media-thumb-ipc.c
+++ /dev/null
@@ -1,622 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "media-thumbnail.h"
-#include "media-thumb-ipc.h"
-#include "media-thumb-util.h"
-#include "media-thumb-db.h"
-#include "media-thumb-debug.h"
-#include <glib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <grp.h>
-#include <pwd.h>
-
-#define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket")
-
-static GQueue *g_manage_queue = NULL;
-static GQueue *g_manage_raw_queue = NULL;
-
-
-typedef struct {
- GIOChannel *channel;
- int msg_type;
- unsigned int request_id;
- bool isCanceled;
- bool isRequested;
- int source_id;
- uid_t uid;
- char *path;
- thumbUserData *userData;
-} thumbReq;
-
-typedef struct {
- GIOChannel *channel;
- int msg_type;
- bool isCanceled;
- bool isRequested;
- int request_id;
- int source_id;
- unsigned int width;
- unsigned int height;
- uid_t uid;
- char *path;
- thumbRawUserData *userData;
-} thumbRawReq;
-
-static int __media_thumb_send_request(void);
-static int __media_thumb_raw_data_send_request(void);
-
-static int __media_thumb_cancel(unsigned int request_id)
-{
- int len = 0, i;
- thumbReq *req = NULL;
-
- thumb_retv_if(!g_manage_queue, MS_MEDIA_ERR_NONE);
-
- len = g_queue_get_length(g_manage_queue);
-
- for (i = 0; i < len; i++) {
- req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
- if (!req)
- continue;
-
- if (req->request_id == request_id) {
- if (req->isRequested) {
- req->isCanceled = true;
- } else {
- g_queue_pop_nth(g_manage_queue, i);
-
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
-
- return MS_MEDIA_ERR_NONE;
- }
- }
-
- return MS_MEDIA_ERR_INTERNAL;
-}
-
-static int __media_thumb_cancel_raw_data(int request_id)
-{
- int len = 0, i;
- thumbRawReq *req = NULL;
-
- thumb_retv_if(!g_manage_raw_queue, MS_MEDIA_ERR_NONE);
-
- len = g_queue_get_length(g_manage_raw_queue);
-
- for (i = 0; i < len; i++) {
- req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
- if (!req)
- continue;
-
- if (req->request_id == request_id) {
- if (req->isRequested) {
- req->isCanceled = true;
- } else {
- g_queue_pop_nth(g_manage_raw_queue, i);
-
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
-
- return MS_MEDIA_ERR_NONE;
- }
- }
-
- return MS_MEDIA_ERR_INTERNAL;
-}
-
-static bool __media_thumb_is_canceled(void)
-{
- thumbReq *req = (thumbReq *)g_queue_peek_head(g_manage_queue);
-
- if (!req)
- return true;
-
- return req->isCanceled;
-}
-
-static bool __media_thumb_is_canceled_for_raw(void)
-{
- thumbRawReq *req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
-
- if (!req)
- return true;
-
- return req->isCanceled;
-}
-
-static int __media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
-{
- int remain_size = 0;
- int recv_len = 0;
- int recv_pos = 0;
- unsigned char *buf = NULL;
-
- THUMB_MALLOC(buf, header_size);
- thumb_retv_if(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- while (header_size > 0) {
- if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
- thumb_stderror("recv failed");
- SAFE_FREE(buf);
- return MS_MEDIA_ERR_IPC;
- }
- header_size -= recv_len;
- recv_pos += recv_len;
- }
-
- header_size = recv_pos;
- recv_pos = 0;
-
- memcpy(msg, buf, header_size);
- SAFE_FREE(buf);
-
- thumb_retvm_if(strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MAX_FILEPATH_LEN, MS_MEDIA_ERR_IPC, "Invalid org_path");
- thumb_retvm_if(strlen(msg->dst_path) >= MAX_FILEPATH_LEN, MS_MEDIA_ERR_IPC, "Invalid dst_path");
- thumb_retvm_if(msg->thumb_size < 0, MS_MEDIA_ERR_IPC, "Invalid thumb_size");
- thumb_retv_if(msg->thumb_size == 0, MS_MEDIA_ERR_NONE);
-
- remain_size = msg->thumb_size;
- THUMB_MALLOC(buf, remain_size);
- thumb_retv_if(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- while (remain_size > 0) {
- if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
- thumb_stderror("recv failed");
- SAFE_FREE(buf);
- return MS_MEDIA_ERR_IPC;
- }
-
- fsync(sock);
- remain_size -= recv_len;
- recv_pos += recv_len;
- }
-
- SAFE_FREE(msg->thumb_data);
- THUMB_MALLOC(msg->thumb_data, msg->thumb_size);
- if (msg->thumb_data) {
- memcpy(msg->thumb_data, buf, msg->thumb_size);
- } else {
- SAFE_FREE(buf);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- SAFE_FREE(buf);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
-{
- if (req_msg == NULL || buf == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- int thumb_data_len = 0;
- int size = 0;
- int header_size = 0;
-
- header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
- thumb_data_len = req_msg->thumb_size;
- if (thumb_data_len < 0)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- size = header_size + thumb_data_len;
- THUMB_MALLOC(*buf, size);
- if (*buf == NULL) {
- *buf_size = 0;
- return 0;
- }
- memcpy(*buf, req_msg, header_size);
- if (thumb_data_len > 0)
- memcpy((*buf) + header_size, req_msg->thumb_data, thumb_data_len);
-
- *buf_size = size;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static void __media_thumb_pop(void)
-{
- int len = 0;
- int sock = 0;
- thumbReq *req = NULL;
- GSource *source_id = NULL;
-
- if (!g_manage_queue)
- return;
-
- req = (thumbReq *)g_queue_pop_head(g_manage_queue);
- if (req) {
- source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
- sock = g_io_channel_unix_get_fd(req->channel);
-
- g_io_channel_shutdown(req->channel, TRUE, NULL);
- g_io_channel_unref(req->channel);
- close(sock);
- if (source_id)
- g_source_destroy(source_id);
-
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
-
- /* Check manage queue */
- len = g_queue_get_length(g_manage_queue);
- if (len > 0)
- __media_thumb_send_request();
-}
-
-static void __media_thumb_pop_raw_data(void)
-{
- int len = 0;
- int sock = 0;
- thumbRawReq *req = NULL;
- GSource *source_id = NULL;
-
- if (!g_manage_raw_queue)
- return;
-
- req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
- if (req) {
- source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
- sock = g_io_channel_unix_get_fd(req->channel);
-
- g_io_channel_shutdown(req->channel, TRUE, NULL);
- g_io_channel_unref(req->channel);
- close(sock);
- if (source_id)
- g_source_destroy(source_id);
-
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
-
- /* Check manage queue */
- len = g_queue_get_length(g_manage_raw_queue);
- if (len > 0)
- __media_thumb_raw_data_send_request();
-}
-
-static gboolean __media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
-{
- thumbMsg recv_msg;
- int header_size = 0;
- int sock = 0;
- int err = MS_MEDIA_ERR_NONE;
- thumbUserData *userdata = NULL;
-
- memset((void *)&recv_msg, 0, sizeof(thumbMsg));
- sock = g_io_channel_unix_get_fd(src);
-
- header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
-
- if ((err = __media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
- thumb_err("_media_thumb_recv_msg failed ");
- goto NEXT;
- }
-
- if (recv_msg.status != MS_MEDIA_ERR_NONE) {
- err = recv_msg.status;
- thumb_err("Failed to make thumbnail (%d)", err);
- }
-
- if (__media_thumb_is_canceled() || !data)
- goto NEXT;
-
- userdata = (thumbUserData*)data;
- if (userdata->func)
- userdata->func(err, recv_msg.dst_path, userdata->user_data);
-
- thumb_dbg("Done");
-NEXT:
- __media_thumb_pop();
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean __media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
-{
- thumbMsg recv_msg;
- int header_size = 0;
- int sock = 0;
- int err = MS_MEDIA_ERR_NONE;
- thumbRawUserData *userdata = NULL;
-
- memset((void *)&recv_msg, 0, sizeof(thumbMsg));
- sock = g_io_channel_unix_get_fd(src);
-
- header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
-
- thumb_err("_media_thumb_write_socket socket : %d", sock);
-
- if ((err = __media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
- thumb_err("_media_thumb_recv_msg failed ");
- goto NEXT;
- }
-
- if (recv_msg.status != MS_MEDIA_ERR_NONE) {
- err = recv_msg.status;
- thumb_err("Failed to make thumbnail (%d)", err);
- }
-
- if (__media_thumb_is_canceled_for_raw() || !data)
- goto NEXT;
-
- userdata = (thumbRawUserData*)data;
- if (userdata->func)
- userdata->func(err, recv_msg.request_id, recv_msg.org_path, recv_msg.thumb_width, recv_msg.thumb_height, recv_msg.thumb_data, recv_msg.thumb_size, userdata->user_data);
-
- thumb_dbg("Done");
-NEXT:
- __media_thumb_pop_raw_data();
-
- return G_SOURCE_REMOVE;
-}
-
-static int __media_thumb_send_request(void)
-{
- int err = MS_MEDIA_ERR_NONE;
- int sock = -1;
- struct sockaddr_un serv_addr;
- thumbReq *req_manager = NULL;
- int pid;
-
- err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
-
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sun_family = AF_UNIX;
- SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
-
- GIOChannel *channel = NULL;
- channel = g_io_channel_unix_new(sock);
- int source_id = -1;
-
- /* Connecting to the thumbnail server */
- if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- thumb_stderror("connect");
- if (errno == EACCES)
- err = MS_MEDIA_ERR_PERMISSION_DENIED;
- else
- err = MS_MEDIA_ERR_IPC;
-
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
-
- return err;
- }
-
- req_manager = (thumbReq *)g_queue_peek_head(g_manage_queue);
- if (!req_manager) {
- thumb_err("queue peek fail");
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- GSource *source = NULL;
- source = g_io_create_watch(channel, G_IO_IN);
- g_source_set_callback(source, (GSourceFunc)__media_thumb_write_socket, req_manager->userData, NULL);
- source_id = g_source_attach(source, g_main_context_get_thread_default());
-
- thumbMsg req_msg;
- memset((void *)&req_msg, 0, sizeof(thumbMsg));
-
- pid = getpid();
- req_msg.pid = pid;
- req_msg.msg_type = req_manager->msg_type;
- req_msg.request_id = 0;
- req_msg.uid = req_manager->uid;
- SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
- req_msg.dst_path[0] = '\0';
- req_msg.thumb_size = 0;
-
- unsigned char *buf = NULL;
- int buf_size = 0;
- _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
-
- if (send(sock, buf, buf_size, 0) < 0) {
- thumb_err("send failed: %d", errno);
- SAFE_FREE(buf);
- g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
- return MS_MEDIA_ERR_IPC;
- }
-
- SAFE_FREE(buf);
- thumb_dbg("Sending msg to thumbnail daemon is successful");
-
- if (req_manager->msg_type == THUMB_REQUEST_DB_INSERT) {
- req_manager->channel = channel;
- req_manager->source_id = source_id;
- req_manager->isRequested = true;
- }
-
- return err;
-}
-
-static int __media_thumb_raw_data_send_request(void)
-{
- int err = MS_MEDIA_ERR_NONE;
- int sock = -1;
- struct sockaddr_un serv_addr;
- thumbRawReq *req_manager = NULL;
- int pid;
-
- err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
-
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sun_family = AF_UNIX;
- SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
-
- GIOChannel *channel = NULL;
- channel = g_io_channel_unix_new(sock);
- int source_id = -1;
-
- /* Connecting to the thumbnail server */
- if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- thumb_stderror("connect error");
- if (errno == EACCES)
- err = MS_MEDIA_ERR_PERMISSION_DENIED;
- else
- err = MS_MEDIA_ERR_IPC;
-
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
- return err;
- }
-
- req_manager = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
-
- if (!req_manager) {
- thumb_err("queue peek fail");
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- GSource *source = NULL;
- source = g_io_create_watch(channel, G_IO_IN);
- g_source_set_callback(source, (GSourceFunc)__media_thumb_raw_data_write_socket, req_manager->userData, NULL);
- source_id = g_source_attach(source, g_main_context_get_thread_default());
-
- thumbMsg req_msg;
- memset((void *)&req_msg, 0, sizeof(thumbMsg));
-
- pid = getpid();
- req_msg.pid = pid;
- req_msg.msg_type = req_manager->msg_type;
- req_msg.request_id = req_manager->request_id;
- req_msg.thumb_width = req_manager->width;
- req_msg.thumb_height = req_manager->height;
- req_msg.uid = req_manager->uid;
-
- SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
- req_msg.dst_path[0] = '\0';
- req_msg.thumb_size = 0;
-
- unsigned char *buf = NULL;
- int buf_size = 0;
- _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
-
- if (send(sock, buf, buf_size, 0) < 0) {
- thumb_err("send failed: %d", errno);
- SAFE_FREE(buf);
- g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- return MS_MEDIA_ERR_IPC;
- }
-
- SAFE_FREE(buf);
-
- if (req_manager->msg_type == THUMB_REQUEST_RAW_DATA) {
- req_manager->channel = channel;
- req_manager->source_id = source_id;
- req_manager->isRequested = true;
- }
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_request_async(int msg_type, unsigned int request_id, const char *origin_path, thumbUserData *userData, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- int len = 0;
-
- if (msg_type == THUMB_REQUEST_CANCEL_MEDIA)
- return __media_thumb_cancel(request_id);
-
- if (g_manage_queue == NULL)
- g_manage_queue = g_queue_new();
-
- thumbReq *thumb_req = NULL;
- THUMB_MALLOC(thumb_req, sizeof(thumbReq));
- thumb_retvm_if(thumb_req == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Failed to create request element");
-
- thumb_req->msg_type = msg_type;
- thumb_req->path = g_strdup(origin_path);
- thumb_req->userData = userData;
- thumb_req->isCanceled = false;
- thumb_req->isRequested = false;
- thumb_req->request_id = request_id;
- thumb_req->uid = uid;
-
- len = g_queue_get_length(g_manage_queue);
- g_queue_push_tail(g_manage_queue, (gpointer)thumb_req);
-
- if (len == 0)
- err = __media_thumb_send_request();
-
- return err;
-}
-
-int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char *origin_path, int width, int height, thumbRawUserData *userData, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- int len = 0;
- thumbRawReq *thumb_req = NULL;
-
- if (msg_type == THUMB_REQUEST_CANCEL_RAW_DATA)
- return __media_thumb_cancel_raw_data(request_id);
-
- if (g_manage_raw_queue == NULL)
- g_manage_raw_queue = g_queue_new();
-
- THUMB_MALLOC(thumb_req, sizeof(thumbRawReq));
- if (thumb_req == NULL) {
- thumb_err("Failed to create request element");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- thumb_req->msg_type = msg_type;
- thumb_req->request_id = request_id;
- thumb_req->path = g_strdup(origin_path);
- thumb_req->width = width;
- thumb_req->height = height;
- thumb_req->userData = userData;
- thumb_req->isCanceled = false;
- thumb_req->isRequested = false;
- thumb_req->uid = uid;
-
- len = g_queue_get_length(g_manage_raw_queue);
- g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req);
-
- if (len == 0)
- err = __media_thumb_raw_data_send_request();
-
- return err;
-}
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
deleted file mode 100755
index 3334a48..0000000
--- a/src/media-thumb-internal.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <media-util.h>
-#include "media-thumb-debug.h"
-#include "media-thumb-internal.h"
-
-int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid)
-{
- char *hash_name = NULL;
- char file_ext[255] = { 0 };
- char *get_path = NULL;
- int ret_len = 0;
- ms_user_storage_type_e storage_type = -1;
- int ret = MS_MEDIA_ERR_NONE;
-
- if (file_full_path == NULL || thumb_hash_path == NULL || max_thumb_path <= 0) {
- thumb_err("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- _media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
-
- ret = ms_user_get_storage_type(uid, file_full_path, &storage_type);
- if ((ret != MS_MEDIA_ERR_NONE) || ((storage_type != MS_USER_STORAGE_INTERNAL) && (storage_type != MS_USER_STORAGE_EXTERNAL))) {
- thumb_err_slog("origin path(%s) is invalid. err : [%d] storage_type [%d]", file_full_path, ret, storage_type);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- hash_name = _media_thumb_generate_hash_name(file_full_path);
- if (hash_name == NULL) {
- thumb_err("_media_thumb_generate_hash_name fail");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- ret = ms_user_get_root_thumb_store_path(uid, &get_path);
- if (get_path != NULL)
- ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.png", get_path, file_ext, hash_name);
-
- SAFE_FREE(get_path);
-
- if ((ret_len < 0) || (ret_len > (int)max_thumb_path)) {
- thumb_err("invalid hash path ret_len[%d]", ret_len);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index d51a280..146bd28 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -3,8 +3,6 @@
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -19,120 +17,40 @@
*
*/
-#include <glib.h>
+#include <aul.h>
+#include <limits.h>
+#include <malloc.h>
+#include <string.h>
+#include <regex.h>
#include <mm_file.h>
+#include <mm_util_image.h>
#include <mm_util_magick.h>
-#include <media-util.h>
-#include "media-thumbnail.h"
-#include "media-thumb-debug.h"
-#include "media-thumb-util.h"
-#include "media-thumb-internal.h"
-#include "media-thumb-ipc.h"
-
-/* The maximum of resolution to be able to get thumbnail is 3000 x 3000, except for only jpeg */
-#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 9000000
-#define THUMB_MAX_ALLOWED_RESOLUTION 2000
-
-int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- ms_user_storage_type_e store_type = MS_USER_STORAGE_INTERNAL;
-
- thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
- thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "No file [%s]", origin_path);
-
- err = ms_user_get_storage_type(uid, origin_path, &store_type);
- if ((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
- thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- thumb_dbg_slog("Path : %s", origin_path);
-
- thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
- thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
-
- userData->func = (ThumbFunc)func;
- userData->user_data = user_data;
-
- /* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, request_id, origin_path, userData, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- SAFE_FREE(userData);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_path, int width, int height, ThumbRawFunc func, void *user_data, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- int exist = 0;
-
- thumb_retvm_if(!origin_path || request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "original path is NULL. Or there is an error in request_id.");
-
- /* check the file exits actually */
- exist = open(origin_path, O_RDONLY);
- if (exist < 0) {
- if (errno == EACCES || errno == EPERM) {
- thumb_err("Fail to open original_path[%s]: Permission Denied", origin_path);
- return MS_MEDIA_ERR_PERMISSION_DENIED;
- } else {
- thumb_err("Fail to open original_path[%s]: Invalid Path", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- }
- close(exist);
-
- thumb_dbg_slog("Path : %s", origin_path);
-
- thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData));
- thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
-
- userData->func = func;
- userData->user_data = user_data;
-
- err = _media_thumb_request_raw_data_async(THUMB_REQUEST_RAW_DATA, request_id, origin_path, width, height, userData, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_raw_thumb_request failed : %d", err);
- SAFE_FREE(userData);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int thumbnail_request_cancel_media(unsigned int request_id)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, NULL, NULL, 0);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_async failed : %d", err);
-
- return err;
-}
-
-int thumbnail_request_cancel_raw_data(int request_id)
-{
- int err = MS_MEDIA_ERR_NONE;
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+#include <mm_util_gif.h>
+#include <mm_util_jpeg.h>
+#include <libexif/exif-data.h>
+#endif
- thumb_retvm_if(request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
+#include "media-thumbnail.h"
+#include "media-thumbnail-debug.h"
- err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_raw_data_async failed : %d", err);
+#define MAX_THUMB_SIZE 2000
+#define MIME_TYPE_TIFF "image/tiff"
+#define MIME_TYPE_ASF "application/vnd.ms-asf"
+#define MIME_MAX_LEN 255
- return err;
-}
+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)
+static void __get_rotation(const char *path, mm_util_rotate_type_e *rot_type)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = FILEINFO_ERROR_NONE;
MMHandleType tag = (MMHandleType) NULL;
char *p = NULL;
int size = 0;
- int _cdis_value = 0;
mm_util_rotate_type_e _rot_type = MM_UTIL_ROTATE_0;
/* Get Content Tag attribute for orientation */
@@ -154,33 +72,24 @@ static void __get_rotation_and_cdis(const char *path, mm_util_rotate_type_e *rot
thumb_dbg("There is tag rotate : %d", _rot_type);
}
- err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL);
- if (err != FILEINFO_ERROR_NONE)
- _cdis_value = 0;
-
*rot_type = _rot_type;
- *cdis_value = _cdis_value;
mm_file_destroy_tag_attrs(tag);
}
-static int __get_video_meta(int cdis_value, const char *path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *frame_size)
+static int __get_video_meta(const char *path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *frame_size)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = FILEINFO_ERROR_NONE;
MMHandleType content = (MMHandleType) NULL;
int _video_track_num = 0;
unsigned int _width = 0;
unsigned int _height = 0;
size_t _frame_size = 0;
void *_frame = NULL;
+ void *_copied = NULL;
- if (cdis_value == 1) {
- thumb_warn("This is CDIS vlaue 1");
- err = mm_file_create_content_attrs_safe(&content, path);
- } else {
- err = mm_file_create_content_attrs(&content, path);
- }
- thumb_retvm_if(err != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_file_create_content_attrs fails : %d", err);
+ err = mm_file_create_content_attrs(&content, path);
+ thumb_retvm_if(err != FILEINFO_ERROR_NONE, THUMB_FAIL, "mm_file_create_content_attrs fails : %d", err);
err = mm_file_get_attrs(content,
MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num,
@@ -192,43 +101,50 @@ static int __get_video_meta(int cdis_value, const char *path, int *video_track_n
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %d", err);
mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ return THUMB_FAIL;
}
*video_track_num = _video_track_num;
if (_video_track_num == 0) {
mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_NONE;
+ return THUMB_OK;
}
- if (!_frame || !_width || !_height) {
+ if (!_frame || _width == 0 || _height == 0 || _frame_size == 0) {
thumb_err("wrong video info W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _frame_size, _frame);
mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ return THUMB_FAIL;
+ }
+
+ _copied = malloc(_frame_size);
+ if (!_copied) {
+ thumb_err("allocation failed");
+ mm_file_destroy_content_attrs(content);
+ return THUMB_FAIL;
}
*width = _width;
*height = _height;
*frame_size = _frame_size;
- *frame = g_memdup(_frame, _frame_size);
+ memcpy(_copied, _frame, _frame_size);
+ *frame = _copied;
mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_NONE;
+ return THUMB_OK;
}
-
static int __get_video_info(const char *path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *frame_size, mm_util_rotate_type_e *rot_type)
{
- int err = MS_MEDIA_ERR_NONE;
- int _cdis_value = 0;
+ int err = THUMB_OK;
mm_util_rotate_type_e _rot_type = MM_UTIL_ROTATE_0;
- __get_rotation_and_cdis(path, &_rot_type, &_cdis_value);
- err = __get_video_meta(_cdis_value, path, video_track_num, width, height, frame, frame_size);
+ __get_rotation(path, &_rot_type);
+ err = __get_video_meta(path, video_track_num, width, height, frame, frame_size);
- *rot_type = _rot_type;
+ if (rot_type)
+ *rot_type = _rot_type;
return err;
}
@@ -262,22 +178,19 @@ static void __media_thumb_get_proper_thumb_size(unsigned int origin_width, unsig
static int __get_video_thumb_to_file(unsigned int width, unsigned int height, void *frame, size_t frame_size, mm_util_rotate_type_e rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = MM_UTIL_ERROR_NONE;
mm_util_image_h img = NULL;
mm_util_image_h resize_img = NULL;
unsigned int thumb_w = thumb_width;
unsigned int thumb_h = thumb_height;
- thumb_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
+ thumb_retvm_if(!thumb_path, THUMB_FAIL, "Invalid thumb_path");
__media_thumb_get_proper_thumb_size(width, height, &thumb_w, &thumb_h);
- if (thumb_w == 0 || thumb_h == 0) {
- thumb_err("Failed to get thumb size");
- return MS_MEDIA_ERR_INTERNAL;
- }
+ thumb_retv_if(thumb_w == 0 || thumb_h == 0, THUMB_FAIL);
err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, frame_size, &img);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "fail to mm_image_create_image [%d]", err);
if (width > thumb_w || height > thumb_h) {
if (rot_type != MM_UTIL_ROTATE_0) {
@@ -300,120 +213,107 @@ static int __get_video_thumb_to_file(unsigned int width, unsigned int height, vo
ERROR:
mm_image_destroy_image(img);
mm_image_destroy_image(resize_img);
- if (err == MS_MEDIA_ERR_NONE)
- return err;
- return MS_MEDIA_ERR_INTERNAL;
+ return (err == MM_UTIL_ERROR_NONE) ? THUMB_OK : THUMB_FAIL;
}
-static int __get_video_thumb_to_buffer(unsigned int width, unsigned int height, void *frame, size_t frame_size, mm_util_rotate_type_e rot_type, unsigned int thumb_width, unsigned int thumb_height, mm_util_image_h *dst_img)
+static int __get_video_thumb_to_buffer(unsigned int width, unsigned int height, void *frame, size_t frame_size, unsigned int thumb_width, unsigned int thumb_height, mm_util_image_h *dst_img)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = MM_UTIL_ERROR_NONE;
mm_util_image_h img = NULL;
- mm_util_image_h resize_img = NULL;
unsigned int thumb_w = thumb_width;
unsigned int thumb_h = thumb_height;
__media_thumb_get_proper_thumb_size(width, height, &thumb_w, &thumb_h);
- if (thumb_w == 0 || thumb_h == 0) {
- thumb_err("Failed to get thumb size");
- return MS_MEDIA_ERR_INTERNAL;
- }
+ thumb_retv_if(thumb_w == 0 || thumb_h == 0, THUMB_FAIL);
err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, frame_size, &img);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err);
-
- if (width > thumb_w || height > thumb_h) {
- if (rot_type != MM_UTIL_ROTATE_0) {
- err = mm_util_resize_B_B(img, thumb_w, thumb_h, &resize_img);
- if (err != MM_UTIL_ERROR_NONE)
- goto ERROR;
-
- err = mm_util_rotate_B_B(resize_img, rot_type, dst_img);
-
- } else {
- err = mm_util_resize_B_B(img, thumb_w, thumb_h, dst_img);
- }
- } else {
- if (rot_type != MM_UTIL_ROTATE_0)
- err = mm_util_rotate_B_B(img, rot_type, dst_img);
- else
- err = mm_image_clone_image(img, dst_img);
- }
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "fail to mm_image_create_image [%d]", err);
-ERROR:
+ if (width > thumb_w || height > thumb_h)
+ err = mm_util_resize_B_B(img, thumb_w, thumb_h, dst_img);
+ else
+ err = mm_image_clone_image(img, dst_img);
mm_image_destroy_image(img);
- mm_image_destroy_image(resize_img);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INTERNAL;
- return MS_MEDIA_ERR_NONE;
+ return (err == MM_UTIL_ERROR_NONE) ? THUMB_OK : THUMB_FAIL;
}
static int __check_path_validity(const char *path)
{
- thumb_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ thumb_retvm_if(!path, THUMB_FAIL, "Invalid path");
if (access(path, R_OK) < 0) {
if (errno == EACCES || errno == EPERM) {
thumb_err("Fail to open path: Permission Denied [%s]", path);
- return MS_MEDIA_ERR_PERMISSION_DENIED;
+ return THUMB_PERM;
} else {
thumb_err("Fail to open path: Invalid Path [%s]", path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return THUMB_FAIL;
}
}
- return MS_MEDIA_ERR_NONE;
+ return THUMB_OK;
}
static int __check_thumb_path_validity(const char *path)
{
- char *dir_name = NULL;
- int ret = MS_MEDIA_ERR_NONE;
+ char dir_name[PATH_MAX + 1] = { 0, };
+ int len = 0;
+
+ if (!path || strlen(path) == 0) {
+ thumb_err("Invalid path");
+ return THUMB_FAIL;
+ }
- thumb_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ strncpy(dir_name, path, PATH_MAX);
+ len = strlen(dir_name);
+ while (--len) {
+ if (dir_name[len] == '/') {
+ dir_name[len] = '\0';
+ break;
+ }
+ }
- dir_name = g_path_get_dirname(path);
+ if (len == 0)
+ return THUMB_FAIL;
if (access(dir_name, W_OK) != 0) {
if (errno == EACCES || errno == EPERM) {
thumb_err("No permission to write[%s]", dir_name);
- ret = MS_MEDIA_ERR_PERMISSION_DENIED;
+ return THUMB_PERM;
} else {
thumb_err("Does not exists[%s]", dir_name);
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ return THUMB_FAIL;
}
}
- SAFE_FREE(dir_name);
-
- return ret;
+ return THUMB_OK;
}
static int __check_parameter_validity_for_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = THUMB_OK;
- thumb_retvm_if((width > THUMB_MAX_ALLOWED_RESOLUTION || width == 0), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid width[%d]", width);
- thumb_retvm_if((height > THUMB_MAX_ALLOWED_RESOLUTION || height == 0), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid height[%d]", height);
+ thumb_retvm_if((width > MAX_THUMB_SIZE || width == 0), THUMB_FAIL, "Invalid width[%d]", width);
+ thumb_retvm_if((height > MAX_THUMB_SIZE || height == 0), THUMB_FAIL, "Invalid height[%d]", height);
/* Check path is accessible */
err = __check_path_validity(path);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid path");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid path");
/* Check thumbnail path is writable */
err = __check_thumb_path_validity(thumb_path);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid thumb_path");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid thumb_path");
- return MS_MEDIA_ERR_NONE;
+ return THUMB_OK;
}
static int __check_parameter_validity_for_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)
{
- thumb_retvm_if((width > THUMB_MAX_ALLOWED_RESOLUTION || width == 0), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid width[%d]", width);
- thumb_retvm_if((height > THUMB_MAX_ALLOWED_RESOLUTION || height == 0), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid height[%d]", height);
- thumb_retvm_if(!thumb_buffer || !thumb_size || !thumb_width || !thumb_height, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid out param");
+ thumb_retvm_if((width > MAX_THUMB_SIZE || width == 0), THUMB_FAIL, "Invalid width[%d]", width);
+ thumb_retvm_if((height > MAX_THUMB_SIZE || height == 0), THUMB_FAIL, "Invalid height[%d]", height);
+ thumb_retvm_if(!thumb_buffer || !thumb_size || !thumb_width || !thumb_height, THUMB_FAIL, "Invalid out param");
//Check path is accessible
return __check_path_validity(path);
@@ -421,7 +321,7 @@ static int __check_parameter_validity_for_buffer(const char *path, unsigned int
int create_video_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = THUMB_OK;
int video_track_num = 0;
unsigned int video_width = 0;
unsigned int video_height = 0;
@@ -430,19 +330,20 @@ int create_video_thumbnail_to_file(const char *path, unsigned int width, unsigne
mm_util_rotate_type_e rot_type = MM_UTIL_ROTATE_NUM;
err = __check_parameter_validity_for_file(path, width, height, thumb_path);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid parameter");
//Get video info
err = __get_video_info(path, &video_track_num, &video_width, &video_height, &frame, &frame_size, &rot_type);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_video_info [%d]", err);
- thumb_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track");
+ thumb_retvm_if(err != THUMB_OK, err, "fail to __get_video_info [%d]", err);
+ thumb_retvm_if(video_track_num == 0, THUMB_OK, "No video track");
if (!auto_rotate)
rot_type = MM_UTIL_ROTATE_0;
//Extract thumbnail
err = __get_video_thumb_to_file(video_width, video_height, frame, frame_size, rot_type, thumb_path, width, height);
- g_free(frame);
+ if (frame)
+ free(frame);
return err;
}
@@ -453,135 +354,355 @@ int create_video_thumbnail_to_buffer(const char *path,
unsigned char **thumb_buffer,
size_t *thumb_size,
unsigned int *thumb_width,
- unsigned int *thumb_height,
- bool auto_rotate,
- bool is_server_request)
+ unsigned int *thumb_height)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = THUMB_OK;
int video_track_num = 0;
unsigned int video_w = 0;
unsigned int video_h = 0;
void *frame = NULL;
size_t frame_size = 0;
mm_util_image_h img = NULL;
- mm_util_rotate_type_e rot_type = MM_UTIL_ROTATE_NUM;
- mm_util_image_h convert_img = NULL;
err = __check_parameter_validity_for_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid parameter");
//Get video info
- err = __get_video_info(path, &video_track_num, &video_w, &video_h, &frame, &frame_size, &rot_type);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_video_info [%d]", err);
- thumb_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track");
-
- if (!auto_rotate)
- rot_type = MM_UTIL_ROTATE_0;
+ err = __get_video_info(path, &video_track_num, &video_w, &video_h, &frame, &frame_size, NULL);
+ thumb_retvm_if(err != THUMB_OK, err, "fail to __get_video_info [%d]", err);
+ thumb_retvm_if(video_track_num == 0, THUMB_OK, "No video track");
//Extract thumbnail
- err = __get_video_thumb_to_buffer(video_w, video_h, frame, frame_size, rot_type, width, height, &img);
- g_free(frame);
- if (err != MS_MEDIA_ERR_NONE)
+ err = __get_video_thumb_to_buffer(video_w, video_h, frame, frame_size, width, height, &img);
+ if (frame)
+ free(frame);
+
+ if (err != THUMB_OK)
return err;
- if (is_server_request) {
- err = mm_util_convert_B_B(img, MM_UTIL_COLOR_BGRA, &convert_img);
- mm_image_destroy_image(img);
- if (err != MM_UTIL_ERROR_NONE) {
- thumb_err("mm_util_convert_B_B failed");
- return MS_MEDIA_ERR_INTERNAL;
+ err = mm_image_get_image(img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size);
+ mm_image_destroy_image(img);
+
+ return (err == MM_UTIL_ERROR_NONE) ? THUMB_OK : THUMB_FAIL;
+}
+
+static int __adjust_thumb_ratio(const char *path, unsigned int *width, unsigned int *height,
+ unsigned int *image_w, unsigned int *image_h, mm_util_img_codec_type *image_type)
+{
+ int err = MM_UTIL_ERROR_NONE;
+#if defined(ENABLE_IMAGE_SIZE_LIMITATION)
+ const size_t image_size_limit[IMG_CODEC_UNKNOWN_TYPE] = {
+ [IMG_CODEC_JPEG] = (4096 * 4096),
+ [IMG_CODEC_PNG] = (3000 * 3000),
+ [IMG_CODEC_GIF] = (3000 * 3000),
+ };
+#endif
+
+ err = mm_util_extract_image_info(path, image_type, image_w, image_h);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_extract_image_info: %d", err);
+ thumb_retvm_if(*image_type == IMG_CODEC_UNKNOWN_TYPE, THUMB_UNSUPPORTED, "Unsupported image codec");
+
+#if defined(ENABLE_IMAGE_SIZE_LIMITATION)
+ if ((*image_type == IMG_CODEC_JPEG) ||
+ (*image_type == IMG_CODEC_PNG) ||
+ (*image_type == IMG_CODEC_GIF))
+ if ((size_t)((*image_w) * (*image_h)) > image_size_limit[*image_type]) {
+ thumb_err("Unsupported image size [%u x %u] limit [%zu]", *image_w, *image_h, image_size_limit[*image_type]);
+ return THUMB_UNSUPPORTED;
}
+#endif
+ __media_thumb_get_proper_thumb_size(*image_w, *image_h, width, height);
- err = mm_image_get_image(convert_img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size);
- mm_image_destroy_image(convert_img);
- } else {
- err = mm_image_get_image(img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size);
- mm_image_destroy_image(img);
+ return THUMB_OK;
+}
+
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+static mm_util_rotate_type_e __get_image_orientation(const char *path)
+{
+ ExifData *ed = NULL;
+ ExifEntry *entry = NULL;
+ short orientation = 0;
+ mm_util_rotate_type_e rotation = MM_UTIL_ROTATE_0;
+
+ ed = exif_data_new_from_file(path);
+ thumb_retvm_if(!ed, MM_UTIL_ROTATE_0, "no exif data");
+
+ entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
+ if (!entry) {
+ thumb_info("no orientation entry");
+ exif_data_unref(ed);
+ return MM_UTIL_ROTATE_0;
}
- return err;
+ orientation = exif_get_short(entry->data, exif_data_get_byte_order(ed));
+
+ /* exif orientation
+ * 0 - not available, 1- normal, 2 - hflip, 3 - rot_180,
+ * 4 - vflip, 5 - transpose, 6 - rot_90, 7 - transverse, 8 - rot_270
+ */
+ switch (orientation) {
+ case 3:
+ rotation = MM_UTIL_ROTATE_180;
+ break;
+ case 6:
+ rotation = MM_UTIL_ROTATE_90;
+ break;
+ case 8:
+ rotation = MM_UTIL_ROTATE_270;
+ break;
+ default:
+ thumb_warn("not supported orientation[%d], rotation will be 0", orientation);
+ rotation = MM_UTIL_ROTATE_0;
+ break;
+ };
+
+ exif_data_unref(ed);
+ thumb_info("orientation: %d, rotation: %d", orientation, rotation);
+
+ return rotation;
}
-static int __get_image_info(const char *path, unsigned int *width, unsigned int *height)
+static int __create_gif_thumbnail_to_file(const char *path, unsigned int thumb_w, unsigned int thumb_h, const char *thumb_path)
{
- int err = MS_MEDIA_ERR_NONE;
- mm_util_img_codec_type image_type = 0;
- unsigned int image_w = 0;
- unsigned int image_h = 0;
+ int err = MM_UTIL_ERROR_NONE;
+ mm_util_image_h decode_image = NULL;
+
+ err = mm_util_decode_from_gif_file(path, &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_decode_from_gif_file failed : %d", err);
+
+ err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_B_P failed : %d", err);
+
+ return THUMB_OK;
+}
+
+static int __create_gif_thumbnail_to_buffer(const char *path, unsigned int thumb_w, unsigned int thumb_h, mm_util_image_h *thumbnail)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ mm_util_image_h decode_image = NULL;
+ mm_util_image_h rgba_thumbnail = NULL;
+
+ err = mm_util_decode_from_gif_file(path, &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_decode_from_gif_file failed : %d", err);
+
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &rgba_thumbnail);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_B_B failed : %d", err);
+
+ err = mm_util_convert_B_B(rgba_thumbnail, MM_UTIL_COLOR_BGRA, thumbnail);
+ mm_image_destroy_image(rgba_thumbnail);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_convert_B_B failed : %d", err);
+
+ return THUMB_OK;
+}
+
+static int __decode_jpeg_with_downscale(const char *path, size_t image_size, size_t thumb_size, mm_util_image_h *decode_image)
+{
+ mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
- thumb_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
- thumb_retvm_if(!width, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid width");
- thumb_retvm_if(!height, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid height");
+ // The downscale divide each width & height, so we should use squares 4(2*2), 16(4*4), 64(8*8).
+ if ((image_size >= thumb_size * 4) && (image_size < thumb_size * 16))
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2;
+ else if ((image_size >= thumb_size * 16) && (image_size < thumb_size * 64))
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4;
+ else if (image_size >= thumb_size * 64)
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8;
- err = mm_util_extract_image_info(path, &image_type, &image_w, &image_h);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INTERNAL, "Getting image info is failed err: %d", err);
- thumb_retvm_if(image_type == IMG_CODEC_UNKNOWN_TYPE, MS_MEDIA_ERR_UNSUPPORTED_CONTENT, "Unsupported image codec");
+ thumb_info("downscale: %d", downscale);
- /*
- if ((image_type != IMG_CODEC_JPEG) && (image_w * image_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
- thumb_warn("This original image is too big. w[%d] h[%d] size limit[%d]", image_w, image_h, THUMB_MAX_ALLOWED_MEM_FOR_THUMB);
- return MS_MEDIA_ERR_THUMB_TOO_BIG;
+ return mm_util_decode_from_jpeg_file(path, MM_UTIL_COLOR_BGRA, downscale, decode_image);
+}
+
+static int __create_jpeg_thumbnail_to_file(const char *path, size_t image_size, unsigned int thumb_w, unsigned int thumb_h, const char *thumb_path, bool auto_rotate)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ mm_util_image_h decode_image = NULL;
+ mm_util_image_h resize_image = NULL;
+ mm_util_rotate_type_e rotation = __get_image_orientation(path);
+
+ err = __decode_jpeg_with_downscale(path, image_size, (size_t)(thumb_w * thumb_h), &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_decode_from_jpeg_file failed : %d", err);
+
+ if (auto_rotate && (rotation != MM_UTIL_ROTATE_0)) {
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &resize_image);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_B_B failed : %d", err);
+
+ err = mm_util_rotate_B_P(resize_image, rotation, thumb_path);
+ mm_image_destroy_image(resize_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_rotate_B_P failed : %d", err);
+ } else {
+ err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_B_P failed : %d", err);
}
- */
- *width = image_w;
- *height = image_h;
+ return THUMB_OK;
+}
+
+static int __create_jpeg_thumbnail_to_buffer(const char *path, size_t image_size, unsigned int thumb_w, unsigned int thumb_h, mm_util_image_h *thumbnail)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ mm_util_image_h decode_image = NULL;
+
+ err = __decode_jpeg_with_downscale(path, image_size, (size_t)(thumb_w * thumb_h), &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_decode_from_jpeg_file failed : %d", err);
- return MS_MEDIA_ERR_NONE;
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, thumbnail);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_B_B failed : %d", err);
+
+ return THUMB_OK;
}
+#endif
int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate)
{
- int err = MS_MEDIA_ERR_NONE;
+ int err = THUMB_OK;
unsigned int image_w = 0;
unsigned int image_h = 0;
unsigned int thumb_w = width;
unsigned int thumb_h = height;
+ mm_util_img_codec_type image_type = 0;
err = __check_parameter_validity_for_file(path, width, height, thumb_path);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid parameter");
- //Get image info
- err = __get_image_info(path, &image_w, &image_h);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_image_info [%d]", err);
+ err = __adjust_thumb_ratio(path, &thumb_w, &thumb_h, &image_w, &image_h, &image_type);
+ thumb_retvm_if(err != THUMB_OK, err, "__adjust_thumb_ratio failed");
- //Extract thumbnail
- __media_thumb_get_proper_thumb_size(image_w, image_h, &thumb_w, &thumb_h);
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+ if (image_type == IMG_CODEC_GIF)
+ return __create_gif_thumbnail_to_file(path, thumb_w, thumb_h, thumb_path);
+ else if (image_type == IMG_CODEC_JPEG)
+ return __create_jpeg_thumbnail_to_file(path, (size_t)(image_w * image_h), thumb_w, thumb_h, thumb_path, auto_rotate);
+#endif
if (auto_rotate)
err = mm_util_resize_and_rotate_P_P(path, thumb_w, thumb_h, thumb_path);
else
err = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_P_P failed : %d", err);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_P_P failed : %d", err);
- return MS_MEDIA_ERR_NONE;
+ return THUMB_OK;
}
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 err = MS_MEDIA_ERR_NONE;
+ int err = THUMB_OK;
unsigned int image_w = 0;
unsigned int image_h = 0;
unsigned int thumb_w = width;
unsigned int thumb_h = height;
mm_util_image_h img = NULL;
+ mm_util_img_codec_type image_type = 0;
err = __check_parameter_validity_for_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter");
+ thumb_retvm_if(err != THUMB_OK, err, "Invalid parameter");
+
+ err = __adjust_thumb_ratio(path, &thumb_w, &thumb_h, &image_w, &image_h, &image_type);
+ thumb_retvm_if(err != THUMB_OK, err, "__adjust_thumb_ratio failed");
+
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+ if (image_type == IMG_CODEC_GIF) {
+ err = __create_gif_thumbnail_to_buffer(path, thumb_w, thumb_h, &img);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "__create_gif_thumbnail_to_buffer failed : %d", err);
+ } else if (image_type == IMG_CODEC_JPEG) {
+ err = __create_jpeg_thumbnail_to_buffer(path, (size_t)(image_w * image_h), thumb_w, thumb_h, &img);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "__create_jpeg_thumbnail_to_buffer failed : %d", err);
+ } else
+#endif
+ {
+ err = mm_util_resize_P_B(path, thumb_w, thumb_h, MM_UTIL_COLOR_BGRA, &img);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_resize_P_B failed : %d", err);
+ }
- //Get image info
- err = __get_image_info(path, &image_w, &image_h);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_image_info [%d]", err);
+ err = mm_image_get_image(img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size);
- //Extract thumbnail
- __media_thumb_get_proper_thumb_size(image_w, image_h, &thumb_w, &thumb_h);
+ mm_image_destroy_image(img);
- err = mm_util_resize_P_B(path, thumb_w, thumb_h, MM_UTIL_COLOR_BGRA, &img);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_P_B failed : %d", err);
+ return (err == MM_UTIL_ERROR_NONE) ? THUMB_OK : THUMB_FAIL;
+}
- err = mm_image_get_image(img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size);
+static int __get_media_type(const char *path, thumbnail_media_type_e *media_type)
+{
+ int ret = THUMB_OK;
+ char mime[MIME_MAX_LEN] = {0,};
- mm_image_destroy_image(img);
+ ret = __check_path_validity(path);
+ thumb_retv_if(ret != THUMB_OK, ret);
- return err;
+ ret = aul_get_mime_from_file(path, mime, MIME_MAX_LEN);
+ thumb_retvm_if(ret < 0, THUMB_FAIL, "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), THUMB_UNSUPPORTED, "Unsupported type");
+ *media_type = MEDIA_THUMB_IMAGE;
+ return THUMB_OK;
+ }
+
+ if (strstr(mime, "video") != NULL) {
+ *media_type = MEDIA_THUMB_VIDEO;
+ return THUMB_OK;
+ }
+
+ if (strcmp(mime, MIME_TYPE_ASF) == 0) {
+ *media_type = MEDIA_THUMB_VIDEO;
+ return THUMB_OK;
+ }
+
+ return 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 = THUMB_OK;
+ thumbnail_media_type_e type = MEDIA_THUMB_INVALID;
+
+ ret = __get_media_type(path, &type);
+ thumb_retvm_if(ret != THUMB_OK, 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 = THUMB_OK;
+ regex_t regex;
+ thumbnail_media_type_e type = MEDIA_THUMB_INVALID;
+
+ ret = __get_media_type(path, &type);
+ thumb_retvm_if(ret != THUMB_OK, ret, "__get_media_type failed");
+
+ if (type == MEDIA_THUMB_IMAGE)
+ return create_image_thumbnail_to_file(path, width, height, thumb_path, false);
+
+ if (regcomp(&regex, "[^/]\\.jpe?g$", REG_ICASE | REG_EXTENDED) != 0) {
+ thumb_err("regcomp failed");
+ return THUMB_FAIL;
+ }
+
+ if (regexec(&regex, thumb_path, 0, NULL, 0) == REG_NOMATCH) {
+ thumb_err("Unsupported path or extensions [%s]", thumb_path);
+ return THUMB_FAIL;
+ }
+
+ regfree(&regex);
+ return create_video_thumbnail_to_file(path, width, height, thumb_path, false);
+}
+
+int get_image_info(const char *path, unsigned int *width, unsigned int *height)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ ret = mm_util_extract_image_info(path, NULL, width, height);
+ thumb_retvm_if(ret != MM_UTIL_ERROR_NONE, THUMB_FAIL, "mm_util_extract_image_info failed");
+
+ return THUMB_OK;
}
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
deleted file mode 100755
index 972fdc2..0000000
--- a/src/util/media-thumb-db.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "media-thumb-db.h"
-#include "media-thumb-util.h"
-#include "media-thumb-debug.h"
-
-#include <glib.h>
-#include <string.h>
-#include <unistd.h>
-
-int _media_thumb_get_thumb_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *query_string = NULL;
- sqlite3_stmt *stmt = NULL;
- sqlite3 *db_handle = NULL;
-
- thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path");
-
- query_string = sqlite3_mprintf(SELECT_THUMB_BY_PATH, origin_path);
- thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed");
- thumb_dbg_slog("Query: %s", query_string);
-
- err = media_db_connect(&db_handle, uid, FALSE);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("media_db_connect failed: %d", err);
- db_handle = NULL;
- SQLITE3_SAFE_FREE(query_string);
- return err;
- }
-
- err = sqlite3_prepare_v2(db_handle, query_string, strlen(query_string), &stmt, NULL);
- SQLITE3_SAFE_FREE(query_string);
- if (SQLITE_OK != err) {
- thumb_err("prepare error [%s]", sqlite3_errmsg(db_handle));
- media_db_disconnect(db_handle);
-
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- SAFE_STRLCPY(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length);
- } else {
- thumb_err("end of row [%s]", sqlite3_errmsg(db_handle));
- SQLITE3_FINALIZE(stmt);
- media_db_disconnect(db_handle);
-
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- SQLITE3_FINALIZE(stmt);
- media_db_disconnect(db_handle);
-
- thumb_retvm_if(!g_file_test(thumb_path, G_FILE_TEST_EXISTS), MS_MEDIA_ERR_INTERNAL, "thumb path doesn't exist in file system");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *query_string = NULL;
-
- thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path");
-
- query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path);
- thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed");
-
- err = media_db_request_update_db(query_string, uid);
- SQLITE3_SAFE_FREE(query_string);
-
- return err;
-} \ No newline at end of file
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
deleted file mode 100755
index cc03075..0000000
--- a/src/util/media-thumb-util.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "media-thumb-util.h"
-#include "media-thumb-internal.h"
-#include "media-thumb-debug.h"
-
-#include <glib.h>
-#include <aul.h>
-#include <string.h>
-
-int _media_thumb_get_file_type(const char *file_full_path)
-{
- int ret = 0;
- char mimetype[255] = {0,};
- const char *unsupported_type = "image/tiff";
- const char *supported_type = "application/vnd.ms-asf";
-
- if (file_full_path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /* get content type and mime type from file. */
- ret = aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
- if (ret < 0) {
- thumb_warn
- ("aul_get_mime_from_file fail.. Now trying to get type by extension");
-
- char ext[255] = { 0 };
- ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext));
- if (ret < 0) {
- thumb_err("_media_thumb_get_file_ext failed");
- return THUMB_NONE_TYPE;
- }
-
- if (strcasecmp(ext, "JPG") == 0 ||
- strcasecmp(ext, "JPEG") == 0 ||
- strcasecmp(ext, "PNG") == 0 ||
- strcasecmp(ext, "GIF") == 0 ||
- strcasecmp(ext, "AGIF") == 0 ||
- strcasecmp(ext, "XWD") == 0 ||
- strcasecmp(ext, "BMP") == 0 ||
- strcasecmp(ext, "WBMP") == 0) {
- return THUMB_IMAGE_TYPE;
- } else if (strcasecmp(ext, "AVI") == 0 ||
- strcasecmp(ext, "MPEG") == 0 ||
- strcasecmp(ext, "MP4") == 0 ||
- strcasecmp(ext, "DCF") == 0 ||
- strcasecmp(ext, "WMV") == 0 ||
- strcasecmp(ext, "3GPP") == 0 ||
- strcasecmp(ext, "3GP") == 0) {
- return THUMB_VIDEO_TYPE;
- } else {
- return THUMB_NONE_TYPE;
- }
- }
-
- thumb_dbg("mime type : %s", mimetype);
-
- /* categorize from mimetype */
- if (strstr(mimetype, "image") != NULL) {
- if (!strcmp(mimetype, unsupported_type)) {
- thumb_warn("This is unsupport file type");
- return THUMB_NONE_TYPE;
- }
- return THUMB_IMAGE_TYPE;
- } else if (strstr(mimetype, "video") != NULL) {
- return THUMB_VIDEO_TYPE;
- } else if (strstr(mimetype, supported_type) != NULL) {
- return THUMB_VIDEO_TYPE;
- }
-
- return THUMB_NONE_TYPE;
-}
-
-int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
-{
- int i = 0;
-
- for (i = (int)strlen(file_path); i >= 0; i--) {
- if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
- strncpy(file_ext, &file_path[i + 1], max_len);
- return 0;
- }
-
- /* meet the dir. no ext */
- if (file_path[i] == '/') {
- return -1;
- }
- }
-
- return -1;
-}
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
index fa13bc6..43ab957 100644
--- a/unittest/CMakeLists.txt
+++ b/unittest/CMakeLists.txt
@@ -5,17 +5,13 @@ SET(GTEST_TEST "gtest-libmedia-thumbnail")
ADD_DEFINITIONS("-DUSE_DLOG")
SET(REQUIRES_LIST ${REQUIRES_LIST}
- glib-2.0
- gio-2.0
gmock
dlog
- libmedia-utils
libtzplatform-config
)
SET(PKG_LIBRARIES ${PKG_LIBRARIES}
"media-thumbnail"
- "media-hash"
)
INCLUDE(FindPkgConfig)
diff --git a/unittest/libmedia_thumbnail_unittest.cpp b/unittest/libmedia_thumbnail_unittest.cpp
index 5e5077c..13cb0a0 100755
--- a/unittest/libmedia_thumbnail_unittest.cpp
+++ b/unittest/libmedia_thumbnail_unittest.cpp
@@ -17,7 +17,6 @@
#include <tzplatform_config.h>
#include "libmedia_thumbnail_unittest.h"
-#include "media-util.h"
#include "media-thumbnail.h"
#define GTEST_IMAGE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmedia-thumbnail-unittest.jpg")
@@ -40,23 +39,29 @@ class libmedia_thumbnail_Test : public ::testing::Test {
}
};
-TEST(libmedia_thumbnail_Test, thumbnail_request_from_db_async_n)
+TEST(libmedia_thumbnail_Test, create_image_thumbnail_to_buffer_n)
{
- int ret = MS_MEDIA_ERR_NONE;
+ int ret = THUMB_OK;
+ unsigned char *buffer = NULL;
+ size_t size = 0;
+ unsigned int w, h;
- ret = thumbnail_request_from_db_async(0, NULL, NULL, NULL, 5001);
- EXPECT_EQ(ret, MS_MEDIA_ERR_INVALID_PARAMETER);
-
- ret = thumbnail_request_from_db_async(0, GTEST_IMAGE_FILE_PATH, NULL, NULL, 5001);
- EXPECT_EQ(ret, MS_MEDIA_ERR_INVALID_PARAMETER);
+ ret = create_image_thumbnail_to_buffer(NULL, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, &buffer, &size, &w, &h);
+ EXPECT_EQ(ret, THUMB_FAIL);
}
-TEST(libmedia_thumbnail_Test, thumbnail_request_cancel_media_n)
+TEST(libmedia_thumbnail_Test, create_image_thumbnail_to_buffer_p)
{
- int ret = MS_MEDIA_ERR_NONE;
+ int ret = THUMB_OK;
+ unsigned char *buffer = NULL;
+ size_t size = 0;
+ unsigned int w, h;
+
+ ret = create_image_thumbnail_to_buffer(GTEST_IMAGE_FILE_PATH, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, &buffer, &size, &w, &h);
+ EXPECT_EQ(ret, THUMB_OK);
- ret = thumbnail_request_cancel_media(0);
- EXPECT_EQ(ret, MS_MEDIA_ERR_INTERNAL);
+ if (buffer)
+ free(buffer);
}
int main(int argc, char **argv)