summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rwxr-xr-xsrc/util/media-thumb-db.c609
-rwxr-xr-xsrc/util/media-thumb-debug.c112
-rwxr-xr-xsrc/util/media-thumb-util.c374
3 files changed, 1095 insertions, 0 deletions
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
new file mode 100755
index 0000000..e3ca193
--- /dev/null
+++ b/src/util/media-thumb-db.c
@@ -0,0 +1,609 @@
+/*
+ * 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 <glib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util-func.h>
+
+
+#ifdef _USE_MEDIA_UTIL_
+static __thread MediaDBHandle *db_handle;
+#else
+static __thread sqlite3 *db_handle;
+#endif
+
+static int _media_thumb_busy_handler(void *pData, int count)
+{
+ usleep(50000);
+ thumb_dbg("_media_thumb_busy_handler called : %d\n", count);
+
+ return 100 - count;
+}
+
+sqlite3 *_media_thumb_db_get_handle()
+{
+ return db_handle;
+}
+
+int
+_media_thumb_sqlite_connect(sqlite3 **handle)
+{
+ int err = -1;
+
+ err = db_util_open(MEDIA_DATABASE_NAME, handle,
+ DB_UTIL_REGISTER_HOOK_METHOD);
+
+ if (SQLITE_OK != err) {
+ *handle = NULL;
+ return -1;
+ }
+
+ /*Register busy handler*/
+ if (*handle) {
+ err = sqlite3_busy_handler(*handle, _media_thumb_busy_handler, NULL);
+ if (SQLITE_OK != err) {
+ if (*handle) {
+ thumb_err("[sqlite] %s\n", sqlite3_errmsg(*handle));
+ db_util_close(*handle);
+ }
+ *handle = NULL;
+
+ return -1;
+ }
+ } else {
+ *handle = NULL;
+ return -1;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_sqlite_disconnect(sqlite3 *handle)
+{
+ int err = -1;
+ if (handle != NULL) {
+ err = db_util_close(handle);
+
+ if (SQLITE_OK != err) {
+ handle = NULL;
+ return -1;
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_type_from_db(sqlite3 *handle,
+ const char *origin_path,
+ int *type)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ *type = sqlite3_column_int(stmt, 0);
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+
+int _media_thumb_get_wh_from_db(sqlite3 *handle,
+ const char *origin_path,
+ int *width,
+ int *height)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ *width = sqlite3_column_int(stmt, 0);
+ *height = sqlite3_column_int(stmt, 1);
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_thumb_path_from_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path,
+ int max_length)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ if (sqlite3_column_text(stmt, 0))
+ strncpy(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length);
+ else
+ thumb_path[0] = '\0';
+
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_thumb_path_to_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *thumbpath_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ thumbpath_string = sqlite3_mprintf("%s", thumb_path);
+ query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string);
+
+#ifndef _USE_MEDIA_UTIL_
+ char *err_msg = NULL;
+ err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg);
+
+ thumb_dbg("Query : %s", query_string);
+
+ sqlite3_free(query_string);
+ sqlite3_free(thumbpath_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ if (err_msg) {
+ thumb_err("Failed to query[ %s ]", err_msg);
+ sqlite3_free(err_msg);
+ err_msg = NULL;
+ }
+
+ return -1;
+ }
+
+ if (err_msg)
+ sqlite3_free(err_msg);
+#else
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+#endif
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_wh_to_db(sqlite3 *handle,
+ const char *origin_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string);
+
+#ifndef _USE_MEDIA_UTIL_
+ char *err_msg = NULL;
+ err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg);
+
+ thumb_dbg("Query : %s", query_string);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ if (err_msg) {
+ thumb_err("Failed to query[ %s ]", err_msg);
+ sqlite3_free(err_msg);
+ err_msg = NULL;
+ }
+
+ return -1;
+ }
+
+ if (err_msg)
+ sqlite3_free(err_msg);
+#else
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+#endif
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string);
+
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_db_connect()
+{
+ int err = -1;
+/*
+ err = media_svc_connect(&mb_svc_handle);
+ if (err < 0) {
+ thumb_err("media_svc_connect failed: %d", err);
+ mb_svc_handle = NULL;
+ return err;
+ }
+*/
+#ifndef _USE_MEDIA_UTIL_
+ err = _media_thumb_sqlite_connect(&db_handle);
+ if (err < 0) {
+ thumb_err("_media_thumb_sqlite_connect failed: %d", err);
+ db_handle = NULL;
+ return err;
+ }
+#else
+ err = media_db_connect(&db_handle);
+ if (err < 0) {
+ thumb_err("media_db_connect failed: %d", err);
+ db_handle = NULL;
+ return MEDIA_THUMB_ERROR_DB;
+ }
+#endif
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_db_disconnect()
+{
+ int err = -1;
+/*
+ err = media_svc_disconnect(mb_svc_handle);
+
+ if (err < 0) {
+ thumb_err("media_svc_disconnect failed: %d", err);
+ }
+
+ mb_svc_handle = NULL;
+*/
+#ifndef _USE_MEDIA_UTIL_
+ err = _media_thumb_sqlite_disconnect(db_handle);
+ if (err < 0) {
+ thumb_err("_media_thumb_sqlite_disconnect failed: %d", err);
+ db_handle = NULL;
+ return err;
+ }
+#else
+ err = media_db_disconnect(db_handle);
+ if (err < 0) {
+ thumb_err("media_db_disconnect failed: %d", err);
+ db_handle = NULL;
+ return MEDIA_THUMB_ERROR_DB;
+ }
+#endif
+
+ db_handle = NULL;
+ return err;
+}
+
+int
+_media_thumb_get_thumb_from_db(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db)
+{
+ thumb_dbg("");
+ int err = -1;
+
+ //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
+ err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_warn("Original path doesn't exist in DB");
+ return -1;
+ }
+
+ if (strlen(thumb_path) == 0) {
+ thumb_warn("thumb path doesn't exist in DB");
+ *need_update_db = 1;
+ return -1;
+ }
+
+ thumb_dbg("Thumb path in DB is %s", thumb_path);
+
+ if (!g_file_test(thumb_path,
+ G_FILE_TEST_EXISTS)) {
+ thumb_warn("thumb path doesn't exist in file system");
+ *need_update_db = 1;
+ return -1;
+ } else {
+ thumb_dbg("This thumb path already exist");
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_thumb_from_db_with_size(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db,
+ int *width,
+ int *height)
+{
+ thumb_dbg("");
+ int err = -1;
+
+ //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
+ err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_warn("Original path doesn't exist in DB");
+ return -1;
+ }
+
+ if (strlen(thumb_path) == 0) {
+ thumb_warn("thumb path doesn't exist in DB");
+ *need_update_db = 1;
+ return -1;
+ }
+
+ thumb_dbg("Thumb path in DB is %s", thumb_path);
+
+ if (!g_file_test(thumb_path,
+ G_FILE_TEST_EXISTS)) {
+ thumb_warn("thumb path doesn't exist in file system");
+ *need_update_db = 1;
+ return -1;
+ } else {
+ thumb_dbg("This thumb path already exist");
+ int orig_w = 0;
+ int orig_h = 0;
+
+ err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_wh_from_db failed : %d", err);
+ } else {
+ thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h);
+ *width = orig_w;
+ *height = orig_h;
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_db(const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+
+#if 0
+ Mitem *item = NULL;
+
+ err = minfo_get_item(mb_svc_handle, origin_path, &item);
+ if (err < 0) {
+ thumb_err("minfo_get_item (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ err = minfo_update_media_thumb(mb_svc_handle, item->uuid, thumb_path);
+ if (err < 0) {
+ thumb_err("minfo_update_media_thumb (ID:%s, %s) failed: %d",
+ item->uuid, thumb_path, err);
+ minfo_destroy_mtype_item(item);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ if (item->type == MINFO_ITEM_IMAGE) {
+ err = minfo_update_image_meta_info_int(mb_svc_handle, item->uuid,
+ MINFO_IMAGE_META_WIDTH, width,
+ MINFO_IMAGE_META_HEIGHT, height, -1);
+
+ if (err < 0) {
+ thumb_err("minfo_update_image_meta_info_int failed: %d", err);
+ minfo_destroy_mtype_item(item);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+
+ err = minfo_destroy_mtype_item(item);
+#endif
+
+ int media_type = THUMB_NONE_TYPE;
+ err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+#if 0
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
+ err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+#else
+ if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
+ err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ } else {
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+#endif
+
+ thumb_dbg("_media_thumb_update_db success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
diff --git a/src/util/media-thumb-debug.c b/src/util/media-thumb-debug.c
new file mode 100755
index 0000000..b684aa4
--- /dev/null
+++ b/src/util/media-thumb-debug.c
@@ -0,0 +1,112 @@
+/*
+ * 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 <unistd.h>
+#include <asm/unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include "media-thumb-debug.h"
+
+#ifdef _PERFORMANCE_CHECK_
+static long g_time_usec = 0L;
+#endif
+
+#ifdef _USE_LOG_FILE_
+static FILE *g_log_fp = NULL;
+static char _g_file_path[1024] = "\0";
+
+FILE *get_fp()
+{
+ return g_log_fp;
+}
+
+void thumb_init_file_debug()
+{
+ if (g_log_fp == NULL) {
+ snprintf(_g_file_path, sizeof(_g_file_path), "/tmp/%s",
+ "media-thumb.log");
+ if (access(_g_file_path, R_OK == 0)) {
+ remove(_g_file_path);
+ }
+
+ g_log_fp = fopen(_g_file_path, "a");
+ }
+}
+
+void thumb_close_file_debug()
+{
+ if (g_log_fp != NULL) {
+ fclose(g_log_fp);
+ g_log_fp = NULL;
+ }
+}
+
+#endif
+
+long thumb_get_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ return time.tv_sec * 1000000 + time.tv_usec;
+#else
+ return 0L;
+#endif
+}
+
+void thumb_reset_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ g_time_usec = time.tv_sec * 1000000 + time.tv_usec;
+#endif
+}
+
+void thumb_print_debug_time(char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ double totaltime = 0.0;
+
+ gettimeofday(&time, NULL);
+ totaltime =
+ (double)(time.tv_sec * 1000000 + time.tv_usec -
+ g_time_usec) / CLOCKS_PER_SEC;
+
+ thumb_dbg("time [%s] : %f \n", time_string, totaltime);
+#endif
+}
+
+void
+thumb_print_debug_time_ex(long start, long end, const char *func_name,
+ char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ double totaltime = 0.0;
+
+ totaltime = (double)(end - start) / CLOCKS_PER_SEC;
+
+ thumb_dbg("time [%s: %s] : %f \n", func_name, time_string,
+ totaltime);
+#endif
+}
+
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
new file mode 100755
index 0000000..0db4133
--- /dev/null
+++ b/src/util/media-thumb-util.c
@@ -0,0 +1,374 @@
+/*
+ * 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 <glib.h>
+#include <aul.h>
+#include <string.h>
+#include <drm_client.h>
+
+#include <Evas.h>
+#include <Ecore_Evas.h>
+
+int _media_thumb_get_width(media_thumb_type thumb_type)
+{
+ if (thumb_type == MEDIA_THUMB_LARGE) {
+ return THUMB_LARGE_WIDTH;
+ } else if (thumb_type == MEDIA_THUMB_SMALL) {
+ return THUMB_SMALL_WIDTH;
+ } else {
+ return -1;
+ }
+}
+
+int _media_thumb_get_height(media_thumb_type thumb_type)
+{
+ if (thumb_type == MEDIA_THUMB_LARGE) {
+ return THUMB_LARGE_HEIGHT;
+ } else if (thumb_type == MEDIA_THUMB_SMALL) {
+ return THUMB_SMALL_HEIGHT;
+ } else {
+ return -1;
+ }
+}
+
+int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
+
+ for (i = strlen(file_path); i >= 0; i--) {
+ if ((file_path[i] == '.') && (i < 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;
+}
+
+int
+_media_thumb_get_file_type(const char *file_full_path)
+{
+ int ret = 0;
+ drm_bool_type_e drm_type;
+ drm_file_type_e drm_file_type;
+ char mimetype[255];
+
+ if (file_full_path == NULL)
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+
+ ret = drm_is_drm_file(file_full_path, &drm_type);
+ if (ret < 0) {
+ thumb_err("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ if (drm_type == DRM_TRUE) {
+ thumb_dbg("DRM file : %s", file_full_path);
+
+ ret = drm_get_file_type(file_full_path, &drm_file_type);
+ if (ret < 0) {
+ thumb_err("drm_get_file_type falied : %d", ret);
+ return THUMB_NONE_TYPE;
+ }
+
+ if (drm_file_type == DRM_TYPE_UNDEFINED) {
+ return THUMB_NONE_TYPE;
+ } else {
+ drm_content_info_s contentInfo;
+ memset(&contentInfo, 0x00, sizeof(drm_content_info_s));
+
+ ret = drm_get_content_info(file_full_path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ thumb_err("drm_get_content_info() fails. : %d", ret);
+ return THUMB_NONE_TYPE;
+ }
+ thumb_dbg("DRM mime type: %s", contentInfo.mime_type);
+
+ strncpy(mimetype, contentInfo.mime_type, sizeof(mimetype) - 1);
+ mimetype[sizeof(mimetype) - 1] = '\0';
+ }
+ } else {
+ /* 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 };
+ int 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) {
+ return THUMB_IMAGE_TYPE;
+ } else if (strstr(mimetype, "video") != NULL) {
+ return THUMB_VIDEO_TYPE;
+ }
+
+ return THUMB_NONE_TYPE;
+}
+
+int _media_thumb_get_store_type_by_path(const char *full_path)
+{
+ if (full_path != NULL) {
+ if (strncmp
+ (full_path, THUMB_PATH_PHONE,
+ strlen(THUMB_PATH_PHONE)) == 0) {
+ return THUMB_PHONE;
+ } else
+ if (strncmp
+ (full_path, THUMB_PATH_MMC,
+ strlen(THUMB_PATH_MMC)) == 0) {
+ return THUMB_MMC;
+ }
+ }
+
+ return -1;
+}
+
+int _media_thumb_remove_file(const char *path)
+{
+ int result = -1;
+
+ result = remove(path);
+ if (result == 0) {
+ thumb_dbg("success to remove file");
+ return TRUE;
+ } else {
+ thumb_err("fail to remove file[%s] result errno = %s", path, strerror(errno));
+ return FALSE;
+ }
+}
+
+int
+_media_thumb_get_hash_name(const char *file_full_path,
+ char *thumb_hash_path, size_t max_thumb_path)
+{
+ char *hash_name;
+ char *thumb_dir = NULL;
+ char file_ext[255] = { 0 };
+ media_thumb_store_type store_type = -1;
+
+ 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 -1;
+ }
+
+ _media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
+
+ store_type = _media_thumb_get_store_type_by_path(file_full_path);
+ if (store_type == THUMB_PHONE) {
+ thumb_dir = THUMB_PHONE_PATH;
+ } else if (store_type == THUMB_MMC) {
+ thumb_dir = THUMB_MMC_PATH;
+ } else {
+ thumb_dir = THUMB_PHONE_PATH;
+ }
+
+ hash_name = _media_thumb_generate_hash_name(file_full_path);
+
+ int ret_len;
+ ret_len =
+ snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg",
+ thumb_dir, file_ext, hash_name);
+ if (ret_len < 0) {
+ thumb_err("Error when snprintf");
+ return -1;
+ } else if (ret_len > max_thumb_path) {
+ thumb_err("Error for the length of thumb pathname");
+ return -1;
+ }
+
+ //thumb_dbg("thumb hash : %s", thumb_hash_path);
+
+ return 0;
+}
+
+
+int _media_thumb_save_to_file_with_evas(unsigned char *data,
+ int w,
+ int h,
+ int alpha,
+ char *thumb_path)
+{
+ Ecore_Evas *ee =
+ ecore_evas_buffer_new(w, h);
+ if (ee == NULL) {
+ thumb_err("Failed to create a new ecore evas buffer\n");
+ return -1;
+ }
+
+ Evas *evas = ecore_evas_get(ee);
+ if (evas == NULL) {
+ thumb_err("Failed to ecore_evas_get\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ Evas_Object *img = NULL;
+ img = evas_object_image_add(evas);
+
+ if (img == NULL) {
+ thumb_err("image object is NULL\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_size_set(img, w, h);
+ evas_object_image_fill_set(img, 0, 0, w, h);
+
+ if (alpha) evas_object_image_alpha_set(img, 1);
+
+ evas_object_image_data_set(img, data);
+ evas_object_image_data_update_add(img, 0, 0, w, h);
+
+ if (evas_object_image_save
+ (img, thumb_path, NULL, "quality=100 compress=1")) {
+ thumb_dbg("evas_object_image_save success\n");
+ ecore_evas_free(ee);
+
+ return 0;
+ } else {
+ thumb_dbg("evas_object_image_save failed\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+}
+
+
+int _thumbnail_get_data(const char *origin_path,
+ media_thumb_type thumb_type,
+ media_thumb_format format,
+ unsigned char **data,
+ int *size,
+ int *width,
+ int *height,
+ int *origin_width,
+ int *origin_height,
+ int *alpha)
+{
+ int err = -1;
+ int thumb_width = -1;
+ int thumb_height = -1;
+
+ if (origin_path == NULL || size == NULL
+ || width == NULL || height == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
+ thumb_err("parameter format is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!g_file_test
+ (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("Original path (%s) does not exist", origin_path);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_width = _media_thumb_get_width(thumb_type);
+ if (thumb_width < 0) {
+ thumb_err("media_thumb_type is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_height = _media_thumb_get_height(thumb_type);
+ if (thumb_height < 0) {
+ thumb_err("media_thumb_type is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_dbg("Origin path : %s", origin_path);
+
+ int file_type = THUMB_NONE_TYPE;
+ media_thumb_info thumb_info = {0,};
+ file_type = _media_thumb_get_file_type(origin_path);
+
+ if (file_type == THUMB_IMAGE_TYPE) {
+ err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_image failed");
+ return err;
+ }
+
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_image failed");
+ return err;
+ }
+ }
+
+ if (size) *size = thumb_info.size;
+ if (width) *width = thumb_info.width;
+ if (height) *height = thumb_info.height;
+ *data = thumb_info.data;
+ if (origin_width) *origin_width = thumb_info.origin_width;
+ if (origin_height) *origin_height = thumb_info.origin_height;
+ if (alpha) *alpha = thumb_info.alpha;
+
+ thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x",
+ *size, *width, *height, *data);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}