Update to the latest
authorHyunjun Ko <zzoon.ko@samsung.com>
Fri, 31 Aug 2012 05:31:35 +0000 (14:31 +0900)
committerHyunjun Ko <zzoon.ko@samsung.com>
Fri, 31 Aug 2012 05:31:35 +0000 (14:31 +0900)
packaging/libmedia-thumbnail.spec
src/include/ipc/media-thumb-ipc.h
src/include/util/media-thumb-util.h
src/ipc/media-thumb-ipc.c
src/media-thumbnail.c
src/util/media-thumb-util.c

index c9c13bd3c29c646ccc59b882305374d9873d3af5..9d79991f18daa3f62fcb490390b62a1e96f15e94 100644 (file)
@@ -1,6 +1,7 @@
+#sbs-git:slp/pkgs/l/libmedia-thumbnail libmedia-thumbnail 0.1.32 a6b6cb2f372f6a8cca44ef50813ad0300d34a9de
 Name:       libmedia-thumbnail
 Summary:    Media thumbnail service library for multimedia applications.
-Version: 0.1.42
+Version: 0.1.44
 Release:    0
 Group:      utils
 License:    Apache
index 7c9f6b09bfa530475483aa777d41d9ef8b3ad0e8..31b707f642c9d5a34bbc289e249cb4f53bc2a5cf 100755 (executable)
@@ -37,7 +37,8 @@
 #define _MEDIA_THUMB_IPC_H_
 
 #define THUMB_DAEMON_PORT 10000
-#define MAX_PATH_SIZE 4096
+//#define MAX_PATH_SIZE 4096
+#define MAX_PATH_SIZE 2048
 
 #define TIMEOUT_SEC            10
 #define MAX_TRIES              3
index 8b455b57cf27ce4bad664d2c1396761ed0fb1c35..824ff67ca208ef12d523963bac66265eef0a1c69 100755 (executable)
@@ -62,6 +62,9 @@ _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);
 
+int
+_media_thumb_remove_file(const char *path);
+
 char
 *_media_thumb_generate_hash_name(const char *file);
 
index 2504480269cba2629228543400a2415cc0e02ddd..fd34f54e18da04b0b6d07ffcad67d48c4845863a 100755 (executable)
@@ -182,6 +182,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
        int origin_h = 0;
        int max_length = 0;
        char *thumb_path = NULL;
+       int need_update_db = 0;
 
        if (req_msg == NULL || res_msg == NULL) {
                thumb_err("Invalid msg!");
@@ -195,27 +196,57 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
        media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
 
        thumb_path = res_msg->dst_path;
+       thumb_path[0] = '\0';
        max_length = sizeof(res_msg->dst_path);
 
+       err = _media_thumb_db_connect();
+       if (err < 0) {
+               thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+               return MEDIA_THUMB_ERROR_DB;
+       }
+
        if (msg_type == THUMB_REQUEST_DB_INSERT) {
+               err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
+               if (err == 0) {
+                       res_msg->origin_width = origin_w;
+                       res_msg->origin_width = origin_h;
+                       _media_thumb_db_disconnect();
+                       return MEDIA_THUMB_ERROR_NONE;
+               } else {
+                       if (strlen(thumb_path) == 0) {
+                               err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+                               if (err < 0) {
+                                       thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+                                       strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+                                       _media_thumb_db_disconnect();
+                                       return err;
+                               }
+
+                               thumb_path[strlen(thumb_path)] = '\0';
+                       }
+               }
+
+       } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
+               strncpy(thumb_path, req_msg->dst_path, max_length);
+
+       } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
                err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
                if (err < 0) {
                        thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
                        strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+                       _media_thumb_db_disconnect();
                        return err;
                }
 
                thumb_path[strlen(thumb_path)] = '\0';
-       } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
-               strncpy(thumb_path, req_msg->dst_path, max_length);
        }
 
        thumb_dbg("Thumb path : %s", thumb_path);
 
        if (g_file_test(thumb_path, 
                                        G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-               thumb_warn("thumb path already exists in file system");
-               return 0;
+               thumb_warn("thumb path already exists in file system.. remove the existed file");
+               _media_thumb_remove_file(thumb_path);
        }
 
        err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
@@ -224,6 +255,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
                SAFE_FREE(data);
 
                strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+               _media_thumb_db_disconnect();
                return err;
        }
 
@@ -243,9 +275,10 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
                thumb_err("save_to_file_with_evas failed - %d\n", err);
                SAFE_FREE(data);
 
-               if (msg_type == THUMB_REQUEST_DB_INSERT)
+               if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA)
                        strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
 
+               _media_thumb_db_disconnect();
                return err;
        } else {
                thumb_dbg("file save success\n");
@@ -267,7 +300,17 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
        /* End of fsync */
 
        SAFE_FREE(data);
-       
+
+       /* DB update if needed */
+       if (need_update_db == 1) {
+               err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height);
+               if (err < 0) {
+                       thumb_err("_media_thumb_update_db failed : %d", err);
+               }
+       }
+
+       _media_thumb_db_disconnect();
+
        return 0;
 }
 
index 10302799aed7b46edcb042d6c80636320c4af72a..3e4d3aab83a01222727ff385fb6130e3a597a7d9 100755 (executable)
 #include "media-thumb-util.h"
 #include "media-thumb-internal.h"
 #include "media-thumb-ipc.h"
-#include "media-thumb-db.h"
+//#include "media-thumb-db.h"
 
 #include <glib.h>
 
 int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length)
 {
        int err = -1;
-       int need_update_db = 0;
+       //int need_update_db = 0;
        media_thumb_info thumb_info;
 
        if (origin_path == NULL || thumb_path == NULL) {
@@ -59,7 +59,7 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max
        }
 
        thumb_err("Path : %s", origin_path);
-
+/*
        err = _media_thumb_db_connect();
        if (err < 0) {
                thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
@@ -71,16 +71,16 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max
                _media_thumb_db_disconnect();
                return MEDIA_THUMB_ERROR_NONE;
        }
-
+*/
        /* Request for thumb file to the daemon "Thumbnail generator" */
        err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
        if (err < 0) {
                thumb_err("_media_thumb_request failed : %d", err);
-               _media_thumb_db_disconnect();
+               //_media_thumb_db_disconnect();
                return err;
        }
-
-       /* Need to update DB once generating thumb is done */
+/*
+       // Need to update DB once generating thumb is done
        if (need_update_db) {
                err = _media_thumb_update_db(origin_path, thumb_path, thumb_info.origin_width, thumb_info.origin_height);
                if (err < 0) {
@@ -89,6 +89,7 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max
        }
 
        _media_thumb_db_disconnect();
+*/
        return MEDIA_THUMB_ERROR_NONE;
 }
 
@@ -119,8 +120,7 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu
 int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height)
 {
        int err = -1;
-       int need_update_db = 0;
-       int width, height = 0;
+       //int need_update_db = 0;
        media_thumb_info thumb_info;
 
        if (origin_path == NULL || thumb_path == NULL) {
@@ -153,7 +153,7 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat
        }
 
        thumb_err("Path : %s", origin_path);
-
+/*
        err = _media_thumb_db_connect();
        if (err < 0) {
                thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
@@ -165,19 +165,19 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat
                _media_thumb_db_disconnect();
                return MEDIA_THUMB_ERROR_NONE;
        }
-
+*/
        /* Request for thumb file to the daemon "Thumbnail generator" */
        err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
        if (err < 0) {
                thumb_err("_media_thumb_request failed : %d", err);
-               _media_thumb_db_disconnect();
+               //_media_thumb_db_disconnect();
                return err;
        }
 
        *origin_width = thumb_info.origin_width;
        *origin_height = thumb_info.origin_height;
 
-       _media_thumb_db_disconnect();
+       //_media_thumb_db_disconnect();
        return MEDIA_THUMB_ERROR_NONE;
 }
 
index 88473ac2d433ca9f1fdcb7b195d9219ac8c53cb1..5029e36e4066617fcc6269b072d586aeec4f3ba7 100755 (executable)
@@ -181,6 +181,20 @@ int _media_thumb_get_store_type_by_path(const char *full_path)
        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)