Fix socket bind bug. 62/44262/1 accepted/tizen/mobile/20150721.092123 accepted/tizen/tv/20150721.092304 accepted/tizen/wearable/20150721.092419 submit/tizen/20150721.075626
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 20 Jul 2015 09:47:25 +0000 (18:47 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 20 Jul 2015 09:47:25 +0000 (18:47 +0900)
Fix gdkpixbuf issue.
replace some function.

Change-Id: I3176594d491f9ae1ef08cf7de46a0b791e09e231
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
12 files changed:
CMakeLists.txt
packaging/libmedia-thumbnail.spec
server/include/thumb-server-internal.h
server/thumb-server-internal.c
src/include/ipc/media-thumb-ipc.h
src/include/media-thumb-internal.h
src/include/util/media-thumb-debug.h
src/include/util/media-thumb-util.h
src/ipc/media-thumb-ipc.c
src/media-thumb-internal.c
src/util/media-thumb-util.c
test/test-thumb.c

index 876fb31..975f1d7 100644 (file)
@@ -86,9 +86,9 @@ ADD_EXECUTABLE(media-thumbnail-server ${THUMB-SERVER})
 TARGET_LINK_LIBRARIES(media-thumbnail-server ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
 INSTALL(TARGETS media-thumbnail-server DESTINATION ${BINDIR})
 
-ADD_EXECUTABLE(test-thumb ${TEST-THUMB})
-TARGET_LINK_LIBRARIES(test-thumb ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
-INSTALL(TARGETS test-thumb DESTINATION ${BINDIR})
+#ADD_EXECUTABLE(test-thumb ${TEST-THUMB})
+#TARGET_LINK_LIBRARIES(test-thumb ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
+#INSTALL(TARGETS test-thumb DESTINATION ${BINDIR})
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumbnail.h DESTINATION include/${MEDIATHUMB-LIB})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumb-types.h DESTINATION include/${MEDIATHUMB-LIB})
index 1902bb7..b1bd9bf 100644 (file)
@@ -40,13 +40,6 @@ Requires:       %{name} = %{version}-%{release}
 %description -n media-thumbnail-server
 Description: Media Thumbnail Server.
 
-%package test
-Summary:        Thumbnail generator Tests
-Requires:       %{name} = %{version}-%{release}
-
-%description test
-Media Thumbnail Tests.
-
 %prep
 %setup -q
 cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} .
@@ -83,6 +76,4 @@ make %{?_smp_mflags}
 %manifest media-thumbnail-server.manifest
 %defattr(-,root,root,-)
 %{_bindir}/media-thumbnail-server
-
-%files test
-%{_bindir}/test-thumb
+#%{_bindir}/test-thumb
index 64648b1..cd754e8 100755 (executable)
@@ -46,4 +46,28 @@ void _thumb_daemon_vconf_cb(void *data);
 gboolean _thumb_server_prepare_socket(int *sock_fd);
 gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data);
 
+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,
+                                               uid_t uid);
+
+int _thumbnail_get_raw_data(const char *origin_path,
+                                               media_thumb_format format,
+                                               unsigned char **data,
+                                               int *size,
+                                               int *width,
+                                               int *height,
+                                               uid_t uid);
+
+int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid);
+
+int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid);
+
 #endif /*_THUMB_DAEMON_INTERNAL_H_*/
index 1619a97..3fd4bb5 100755 (executable)
  */
 
 #include "thumb-server-internal.h"
+#include "media-thumb-util.h"
+#include "media-thumb-debug.h"
 
+#include <fcntl.h>
 #include <unistd.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <string.h>
 #include <vconf.h>
+#include <grp.h>
+#include <pwd.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 
 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
+#define THUMB_BLOCK_SIZE 512
 
 static __thread char **arr_path;
 static __thread uid_t *arr_uid;
@@ -189,7 +195,6 @@ static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg,
 int _thumb_daemon_all_extract(uid_t uid)
 {
        int err = MS_MEDIA_ERR_NONE;
-       int count = 0;
        char query_string[MAX_PATH_SIZE + 1] = { 0, };
        char path[MAX_PATH_SIZE + 1] = { 0, };
        sqlite3 *sqlite_db_handle = NULL;
@@ -231,7 +236,6 @@ int _thumb_daemon_all_extract(uid_t uid)
 
                strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
                path[sizeof(path) - 1] = '\0';
-               count = sqlite3_column_int(sqlite_stmt, 1);
 
                thumb_dbg("Path : %s", path);
 
@@ -355,12 +359,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
        } else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
                thumb_warn("received KILL msg from thumbnail agent.");
        } else {
-               long start = thumb_get_debug_time();
-
                _thumb_daemon_process_job(&recv_msg, &res_msg,recv_msg.uid);
-
-               long end = thumb_get_debug_time();
-               thumb_dbg("Time : %f (%s)", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path);
        }
 
        if(res_msg.msg_type == 0)
@@ -395,9 +394,9 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
        //Add sendto_raw_data
        if(recv_msg.msg_type == THUMB_REQUEST_RAW_DATA) {
                _media_thumb_set_add_raw_data_buffer(&res_raw_msg, &buf, &buf_size);
-               block_size = 512;
+               block_size = THUMB_BLOCK_SIZE;
                while(buf_size > 0) {
-                       if (buf_size < 512) {
+                       if (buf_size < THUMB_BLOCK_SIZE) {
                                block_size = buf_size;
                        }
                        if (sendto(sock, buf + sent_size, block_size, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != block_size) {
@@ -477,3 +476,424 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
        return TRUE;
 }
 
+static int _mkdir(const char *dir, mode_t mode) {
+        char tmp[256];
+        char *p = NULL;
+        size_t len;
+
+        snprintf(tmp, sizeof(tmp),"%s",dir);
+        len = strlen(tmp);
+        if(tmp[len - 1] == '/')
+                tmp[len - 1] = 0;
+        for(p = tmp + 1; *p; p++)
+                if(*p == '/') {
+                        *p = 0;
+                        mkdir(tmp, mode);
+                        *p = '/';
+                }
+        return mkdir(tmp, mode);
+}
+
+static char* _media_thumb_get_default_path(uid_t uid)
+{
+       char *result_psswd = NULL;
+       struct group *grpinfo = NULL;
+       if(uid == getuid())
+       {
+               result_psswd = strdup(THUMB_DEFAULT_PATH);
+               grpinfo = getgrnam("users");
+               if(grpinfo == NULL) {
+                       thumb_err("getgrnam(users) returns NULL !");
+                       if(result_psswd)
+                               free(result_psswd);
+                       return NULL;
+               }
+       }
+       else
+       {
+               struct passwd *userinfo = getpwuid(uid);
+               if(userinfo == NULL) {
+                       thumb_err("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               grpinfo = getgrnam("users");
+               if(grpinfo == NULL) {
+                       thumb_err("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       thumb_err("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+               asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
+       }
+
+       /* create dir */
+       _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+       return result_psswd;
+}
+
+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,
+                                               uid_t uid)
+{
+       int err = MS_MEDIA_ERR_NONE;
+       int thumb_width = -1;
+       int thumb_height = -1;
+
+       if (origin_path == NULL || size == NULL
+                       || width == NULL || height == NULL) {
+               thumb_err("Invalid parameter");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
+               thumb_err("parameter format is invalid");
+               return MS_MEDIA_ERR_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 MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       thumb_width = _media_thumb_get_width(thumb_type);
+       if (thumb_width < 0) {
+               thumb_err("media_thumb_type is invalid");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       thumb_height = _media_thumb_get_height(thumb_type);
+       if (thumb_height < 0) {
+               thumb_err("media_thumb_type is invalid");
+               return MS_MEDIA_ERR_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, false, uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       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,uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       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.gdkdata;
+       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 MS_MEDIA_ERR_NONE;
+}
+
+int _thumbnail_get_raw_data(const char *origin_path,
+                                               media_thumb_format format,
+                                               unsigned char **data,
+                                               int *size,
+                                               int *width,
+                                               int *height,
+                                               uid_t uid)
+{
+       int err = MS_MEDIA_ERR_NONE;
+       int thumb_width = -1;
+       int thumb_height = -1;
+
+       if (origin_path == NULL || *width <= 0 || *height <= 0) {
+               thumb_err("Invalid parameter");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
+               thumb_err("parameter format is invalid");
+               return MS_MEDIA_ERR_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 MS_MEDIA_ERR_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);
+       thumb_width = *width;
+       thumb_height = *height;
+
+       if (file_type == THUMB_IMAGE_TYPE) {
+               err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, true, uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       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,uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       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;
+
+       //thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x", *size, *width, *height, *data);
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
+{
+       int err = MS_MEDIA_ERR_NONE;
+       GdkPixbuf *gdkdata = NULL;
+       int thumb_size = 0;
+       int thumb_w = 0;
+       int thumb_h = 0;
+       int origin_w = 0;
+       int origin_h = 0;
+       int max_length = 0;
+       char *thumb_path = NULL;
+       int need_update_db = 0;
+       int alpha = 0;
+
+       if (req_msg == NULL || res_msg == NULL) {
+               thumb_err("Invalid msg!");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       int msg_type = req_msg->msg_type;
+       media_thumb_type thumb_type = req_msg->thumb_type;
+       const char *origin_path = req_msg->org_path;
+
+       // Currently, The color space that is supported by the gdk-pixbuf is only RGB.
+       media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
+
+       thumb_path = res_msg->dst_path;
+       thumb_path[0] = '\0';
+       max_length = sizeof(res_msg->dst_path);
+
+       err = _media_thumb_db_connect(uid);
+       if (err != MS_MEDIA_ERR_NONE) {
+               thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+               return MS_MEDIA_ERR_DB_CONNECT_FAIL;
+       }
+
+       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 == MS_MEDIA_ERR_NONE) {
+                       res_msg->origin_width = origin_w;
+                       res_msg->origin_height = origin_h;
+                       _media_thumb_db_disconnect();
+                       return MS_MEDIA_ERR_NONE;
+               } else {
+                       if (strlen(thumb_path) == 0) {
+                               err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid);
+                               if (err != MS_MEDIA_ERR_NONE) {
+                                       char *default_path = _media_thumb_get_default_path(uid);
+                                       if(default_path) {
+                                               thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+                                               strncpy(thumb_path, default_path, max_length);
+                                               free(default_path);
+                                       }
+                                       _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,uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       char *default_path = _media_thumb_get_default_path(uid);
+                       if(default_path) {
+                               thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+                               strncpy(thumb_path, default_path, max_length);
+                               free(default_path);
+                       }
+                       _media_thumb_db_disconnect();
+                       return err;
+               }
+
+               thumb_path[strlen(thumb_path)] = '\0';
+       }
+
+       thumb_dbg_slog("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.. remove the existed file");
+               _media_thumb_remove_file(thumb_path);
+       }
+
+       err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &gdkdata, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
+       if (err != MS_MEDIA_ERR_NONE) {
+               char *default_path = _media_thumb_get_default_path(uid);
+               thumb_err("_thumbnail_get_data failed - %d\n", err);
+               if ( gdkdata != NULL ){
+                       g_object_unref(gdkdata);
+               }
+               if(default_path) {
+                       strncpy(thumb_path, default_path, max_length);
+                       free(default_path);
+               }
+               _media_thumb_db_disconnect();
+               return err;
+       }
+
+       //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
+       //thumb_dbg("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
+       //thumb_dbg("Thumb : %s", thumb_path);
+
+       res_msg->msg_type = THUMB_RESPONSE;
+       res_msg->thumb_size = thumb_size;
+       res_msg->thumb_width = thumb_w;
+       res_msg->thumb_height = thumb_h;
+       res_msg->origin_width = origin_w;
+       res_msg->origin_height = origin_h;
+
+       /* If the image is transparent PNG format, make png file as thumbnail of this image */
+       if (alpha) {
+               char file_ext[10];
+               err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
+               if (strncasecmp(file_ext, "png", 3) == 0) {
+                       int len = strlen(thumb_path);
+                       thumb_path[len - 3] = 'p';
+                       thumb_path[len - 2] = 'n';
+                       thumb_path[len - 1] = 'g';
+               }
+               thumb_dbg("Thumb path is changed : %s", thumb_path);
+       }
+
+       err = _media_thumb_save_to_file_with_gdk(gdkdata, thumb_w, thumb_h, alpha, thumb_path);
+       if (err != MS_MEDIA_ERR_NONE) {
+               char *default_path = _media_thumb_get_default_path(uid);
+               thumb_err("save_to_file_with_gdk failed - %d", err);
+               if ( gdkdata != NULL ){
+                       g_object_unref(gdkdata);
+               }
+
+               if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
+                       if(default_path) {
+                               strncpy(thumb_path, default_path, max_length);
+                               free(default_path);
+                       }
+               }
+               _media_thumb_db_disconnect();
+               return err;
+       } else {
+               thumb_dbg("file save success");
+       }
+
+       /* fsync */
+       int fd = 0;
+       fd = open(thumb_path, O_WRONLY);
+       if (fd < 0) {
+               thumb_warn("open failed");
+       } else {
+               err = fsync(fd);
+               if (err == -1) {
+                       thumb_warn("fsync failed");
+               }
+
+               close(fd);
+       }
+       /* End of fsync */
+
+       g_object_unref(gdkdata);
+
+       /* 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, uid);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       thumb_err("_media_thumb_update_db failed : %d", err);
+               }
+       }
+
+       _media_thumb_db_disconnect();
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+int
+_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid)
+{
+       int err = MS_MEDIA_ERR_NONE;
+       unsigned char *data = NULL;
+       int thumb_size = 0;
+       int thumb_w = 0;
+       int thumb_h = 0;
+
+       if (req_msg == NULL || res_msg == NULL) {
+               thumb_err("Invalid msg!");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
+
+       const char *origin_path = req_msg->org_path;
+
+       media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+       thumb_w = req_msg->thumb_width;
+       thumb_h = req_msg->thumb_height;
+
+       //thumb_dbg("origin_path : %s, thumb_w : %d, thumb_h : %d ", origin_path, thumb_w, thumb_h);
+
+       if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+               thumb_err("origin_path does not exist in file system.");
+               return MS_MEDIA_ERR_FILE_NOT_EXIST;
+       }
+
+       err = _thumbnail_get_raw_data(origin_path, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, uid);
+
+       if (err != MS_MEDIA_ERR_NONE) {
+               thumb_err("_thumbnail_get_data failed - %d", err);
+               SAFE_FREE(data);
+       }
+
+       res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
+       res_msg->thumb_width = thumb_w;
+       res_msg->thumb_height = thumb_h;
+       res_raw_msg->thumb_size = thumb_size;
+       res_raw_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
+       memcpy(res_raw_msg->thumb_data, data, thumb_size);
+       res_msg->thumb_size = thumb_size + sizeof(thumbRawAddMsg) - sizeof(unsigned char*);
+
+       //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
+
+       return MS_MEDIA_ERR_NONE;
+}
index ea07e5e..fcd4560 100755 (executable)
@@ -21,6 +21,7 @@
 
 
 #include <sys/un.h>
+#include <sys/stat.h>
 #include <arpa/inet.h>
 #include <stdlib.h>
 #include <string.h>
@@ -60,11 +61,6 @@ enum {
        THUMB_FAIL
 };
 
-
-int _media_thumb_create_socket(int sock_type, int *sock);
-
-int _media_thumb_create_udp_socket(int *sock);
-
 int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg);
 
 int _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_un *from_addr, unsigned int *from_size);
@@ -97,8 +93,4 @@ int _media_thumb_request_raw_data_async(int msg_type,
                                        thumbRawUserData *userData,
                                        uid_t uid);
 
-int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid);
-
-int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid);
-
 #endif /*_MEDIA_THUMB_IPC_H_*/
index 151836a..0ab9eb7 100755 (executable)
@@ -22,6 +22,7 @@
 #include <stdbool.h>
 #include <media-util-err.h>
 #include "media-thumbnail.h"
+#include "media-thumb-util.h"
 #include "media-thumb-types.h"
 #include "media-thumb-debug.h"
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -75,7 +76,7 @@ int _media_thumb_image(const char *origin_path,
                                        int thumb_width,
                                        int thumb_height,
                                        media_thumb_format format,
-                                       media_thumb_info *thumb_info, 
+                                       media_thumb_info *thumb_info,
                                        bool is_raw,
                                        uid_t uid);
 
index f14ea11..3044fc4 100755 (executable)
 
 #define LOG_TAG "MEDIA_THUMBNAIL"
 
-static pid_t gettid(void)
-{
-       return syscall(__NR_gettid);
-}
-
 #define FONT_COLOR_RESET    "\033[0m"
 #define FONT_COLOR_RED      "\033[31m"
 #define FONT_COLOR_GREEN    "\033[32m"
@@ -51,31 +46,31 @@ static pid_t gettid(void)
 #define FONT_COLOR_GRAY     "\033[37m"
 
 #define thumb_dbg(fmt, arg...) do{ \
-               LOGD(FONT_COLOR_RESET"[%d] " fmt "\n", gettid(), ##arg); \
+               LOGD(FONT_COLOR_RESET fmt "\n", ##arg); \
                } while(0)
 
 #define thumb_warn(fmt, arg...)        do{ \
-               LOGW(FONT_COLOR_GREEN"[%d] " fmt "\n", gettid(), ##arg); \
+               LOGW(FONT_COLOR_GREEN fmt "\n", ##arg); \
                } while(0)
 
 #define thumb_err(fmt, arg...) do{ \
-                LOGE(FONT_COLOR_RED"[%d] " fmt "\n", gettid(), ##arg); \
+                LOGE(FONT_COLOR_RED fmt "\n", ##arg); \
                } while(0)
 
 #define thumb_dbg_slog(fmt, arg...)    do{ \
-               SECURE_LOGD(FONT_COLOR_RESET"[%d] " fmt "\n", gettid(), ##arg); \
+               SECURE_LOGD(FONT_COLOR_RESET fmt "\n", ##arg); \
                } while(0)
 
 #define thumb_warn_slog(fmt, arg...)   do{ \
-               SECURE_LOGW(FONT_COLOR_GREEN"[%d] " fmt "\n", gettid(), ##arg); \
+               SECURE_LOGW(FONT_COLOR_GREEN fmt "\n", ##arg); \
                } while(0)
 
 
 #define ERR_BUF_LENGHT 256
 #define thumb_stderror(fmt) do { \
-                       char buf[ERR_BUF_LENGHT] = {0,}; \
-                       strerror_r(errno, buf, ERR_BUF_LENGHT); \
-                       LOGE(FONT_COLOR_RED fmt" : standard error [%s]", buf); \
+                       char thumb_stderror_buffer[ERR_BUF_LENGHT] = {0,}; \
+                       strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGHT); \
+                       LOGE(FONT_COLOR_RED fmt" : standard error [%s]", thumb_stderror_buffer); \
                } while (0)
 
 #ifdef _USE_LOG_FILE_
index cb93115..bee3b44 100755 (executable)
@@ -72,25 +72,5 @@ int _media_thumb_get_width(media_thumb_type thumb_type);
 
 int _media_thumb_get_height(media_thumb_type thumb_type);
 
-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,
-                                               uid_t uid);
-
-int _thumbnail_get_raw_data(const char *origin_path,
-                                               media_thumb_format format,
-                                               unsigned char **data,
-                                               int *size,
-                                               int *width,
-                                               int *height,
-                                               uid_t uid);
-
 #endif /*_MEDIA_THUMB_UTIL_H_*/
 
index 64c4b46..e98d629 100755 (executable)
@@ -49,61 +49,7 @@ typedef struct {
        thumbRawUserData *userData;
 } thumbRawReq;
 
-int _media_thumb_create_socket(int sock_type, int *sock)
-{
-       int sock_fd = 0;
-
-       if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
-               thumb_err("socket failed: %s", strerror(errno));
-               return MS_MEDIA_ERR_SOCKET_CONN;
-       }
-
-       if (sock_type == CLIENT_SOCKET) {
-               struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 };
-
-               if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
-                       thumb_err("setsockopt failed: %s", strerror(errno));
-                       close(sock_fd);
-                       return MS_MEDIA_ERR_SOCKET_CONN;
-               }
-       } else if (sock_type == SERVER_SOCKET) {
-
-               int n_reuse = 1;
-
-               if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
-                       thumb_err("setsockopt failed: %s", strerror(errno));
-                       close(sock_fd);
-                       return MS_MEDIA_ERR_SOCKET_CONN;
-               }
-       }
-
-       *sock = sock_fd;
 
-       return MS_MEDIA_ERR_NONE;
-}
-
-
-int _media_thumb_create_udp_socket(int *sock)
-{
-       int sock_fd = 0;
-
-       if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-               thumb_err("socket failed: %s", strerror(errno));
-               return MS_MEDIA_ERR_SOCKET_CONN;
-       }
-
-       struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 };
-
-       if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
-               thumb_err("setsockopt failed: %s", strerror(errno));
-               close(sock_fd);
-               return MS_MEDIA_ERR_SOCKET_CONN;
-       }
-
-       *sock = sock_fd;
-
-       return MS_MEDIA_ERR_NONE;
-}
 
 int _media_thumb_get_error()
 {
@@ -209,7 +155,6 @@ int __media_thumb_check_req_queue(const char *path)
 {
        int req_len = 0, i;
 
-       if (g_request_queue == NULL) return MS_MEDIA_ERR_NONE;
        req_len = g_queue_get_length(g_request_queue);
 
 //     thumb_dbg("Queue length : %d", req_len);
@@ -248,7 +193,6 @@ _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
 
        buf = (unsigned char*)malloc(header_size * sizeof(unsigned char));
        block_buf = (unsigned char*)malloc(THUMB_SOCK_BLOCK_SIZE * sizeof(unsigned char));
-
        if (buf == NULL || block_buf == NULL) {
                thumb_err("memory allocation failed");
                SAFE_FREE(buf);
@@ -323,7 +267,6 @@ _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct socka
        }
 
        strncpy(msg->org_path, (char*)buf + header_size, msg->origin_path_size);
-       //thumb_dbg("original path : %s", msg->org_path);
 
        if (msg->dest_path_size <= 0  || msg->dest_path_size > MAX_PATH_SIZE) {
                SAFE_FREE(buf);
@@ -332,7 +275,6 @@ _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct socka
        }
 
        strncpy(msg->dst_path, (char*)buf + header_size + msg->origin_path_size, msg->dest_path_size);
-       //thumb_dbg("destination path : %s", msg->dst_path);
 
        SAFE_FREE(buf);
        *from_size = from_addr_size;
@@ -553,285 +495,6 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
        return MS_MEDIA_ERR_NONE;
 }
 
-static int _mkdir(const char *dir, mode_t mode) {
-        char tmp[256];
-        char *p = NULL;
-        size_t len;
-
-        snprintf(tmp, sizeof(tmp),"%s",dir);
-        len = strlen(tmp);
-        if(tmp[len - 1] == '/')
-                tmp[len - 1] = 0;
-        for(p = tmp + 1; *p; p++)
-                if(*p == '/') {
-                        *p = 0;
-                        mkdir(tmp, mode);
-                        *p = '/';
-                }
-        return mkdir(tmp, mode);
-}
-
-static char* _media_thumb_get_default_path(uid_t uid)
-{
-       char *result_psswd = NULL;
-       struct group *grpinfo = NULL;
-       if(uid == getuid())
-       {
-               result_psswd = strdup(THUMB_DEFAULT_PATH);
-               grpinfo = getgrnam("users");
-               if(grpinfo == NULL) {
-                       thumb_err("getgrnam(users) returns NULL !");
-                       if(result_psswd)
-                               free(result_psswd);
-                       return NULL;
-               }
-       }
-       else
-       {
-               struct passwd *userinfo = getpwuid(uid);
-               if(userinfo == NULL) {
-                       thumb_err("getpwuid(%d) returns NULL !", uid);
-                       return NULL;
-               }
-               grpinfo = getgrnam("users");
-               if(grpinfo == NULL) {
-                       thumb_err("getgrnam(users) returns NULL !");
-                       return NULL;
-               }
-               // Compare git_t type and not group name
-               if (grpinfo->gr_gid != userinfo->pw_gid) {
-                       thumb_err("UID [%d] does not belong to 'users' group!", uid);
-                       return NULL;
-               }
-               asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
-       }
-
-       /* create dir */
-       _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
-
-       return result_psswd;
-}
-
-int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
-{
-       int err = -1;
-       GdkPixbuf *gdkdata = NULL;
-       int thumb_size = 0;
-       int thumb_w = 0;
-       int thumb_h = 0;
-       int origin_w = 0;
-       int origin_h = 0;
-       int max_length = 0;
-       char *thumb_path = NULL;
-       int need_update_db = 0;
-       int alpha = 0;
-
-       if (req_msg == NULL || res_msg == NULL) {
-               thumb_err("Invalid msg!");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       int msg_type = req_msg->msg_type;
-       media_thumb_type thumb_type = req_msg->thumb_type;
-       const char *origin_path = req_msg->org_path;
-
-       // Currently, The color space that is supported by the gdk-pixbuf is only RGB.
-       media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
-
-       thumb_path = res_msg->dst_path;
-       thumb_path[0] = '\0';
-       max_length = sizeof(res_msg->dst_path);
-
-       err = _media_thumb_db_connect(uid);
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
-               return MS_MEDIA_ERR_DB_CONNECT_FAIL;
-       }
-
-       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 == MS_MEDIA_ERR_NONE) {
-                       res_msg->origin_width = origin_w;
-                       res_msg->origin_height = origin_h;
-                       _media_thumb_db_disconnect();
-                       return MS_MEDIA_ERR_NONE;
-               } else {
-                       if (strlen(thumb_path) == 0) {
-                               err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid);
-                               if (err != MS_MEDIA_ERR_NONE) {
-                                       char *default_path = _media_thumb_get_default_path(uid);
-                                       if(default_path) {
-                                               thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
-                                               strncpy(thumb_path, default_path, max_length);
-                                               free(default_path);
-                                       }
-                                       _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,uid);
-               if (err < 0) {
-                       char *default_path = _media_thumb_get_default_path(uid);
-                       if(default_path) {
-                               thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
-                               strncpy(thumb_path, default_path, max_length);
-                               free(default_path);
-                       }
-                       _media_thumb_db_disconnect();
-                       return err;
-               }
-
-               thumb_path[strlen(thumb_path)] = '\0';
-       }
-
-       if (g_file_test(thumb_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-               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, &gdkdata, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
-       if (err != MS_MEDIA_ERR_NONE) {
-               char *default_path = _media_thumb_get_default_path(uid);
-               thumb_err("_thumbnail_get_data failed - %d\n", err);
-               if ( gdkdata != NULL ){
-                       g_object_unref(gdkdata);
-               }
-               if(default_path) {
-                       strncpy(thumb_path, default_path, max_length);
-                       free(default_path);
-               }
-               _media_thumb_db_disconnect();
-               return err;
-       }
-
-       //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
-       //thumb_dbg("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
-       //thumb_dbg("Thumb : %s", thumb_path);
-
-       res_msg->msg_type = THUMB_RESPONSE;
-       res_msg->thumb_size = thumb_size;
-       res_msg->thumb_width = thumb_w;
-       res_msg->thumb_height = thumb_h;
-       res_msg->origin_width = origin_w;
-       res_msg->origin_height = origin_h;
-
-       /* If the image is transparent PNG format, make png file as thumbnail of this image */
-       if (alpha) {
-               char file_ext[10];
-               err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
-               if (strncasecmp(file_ext, "png", 3) == 0) {
-                       int len = strlen(thumb_path);
-                       thumb_path[len - 3] = 'p';
-                       thumb_path[len - 2] = 'n';
-                       thumb_path[len - 1] = 'g';
-               }
-               thumb_dbg("Thumb path is changed : %s", thumb_path);
-       }
-
-       err = _media_thumb_save_to_file_with_gdk(gdkdata, thumb_w, thumb_h, alpha, thumb_path);
-       if (err < 0) {
-               char *default_path = _media_thumb_get_default_path(uid);
-               thumb_err("save_to_file_with_gdk failed - %d\n", err);
-               if ( gdkdata != NULL ){
-                       g_object_unref(gdkdata);
-               }
-
-               if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
-                       if(default_path) {
-                               strncpy(thumb_path, default_path, max_length);
-                               free(default_path);
-                       }
-               }
-               _media_thumb_db_disconnect();
-               return err;
-       } else {
-               thumb_dbg("file save success\n");
-       }
-
-       /* fsync */
-       int fd = 0;
-       fd = open(thumb_path, O_WRONLY);
-       if (fd < 0) {
-               thumb_warn("open failed");
-       } else {
-               err = fsync(fd);
-               if (err == -1) {
-                       thumb_warn("fsync failed");
-               }
-               close(fd);
-       }
-       /* End of fsync */
-
-       g_object_unref(gdkdata);
-
-       /* 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, uid);
-               if (err != MS_MEDIA_ERR_NONE) {
-                       thumb_err("_media_thumb_update_db failed : %d", err);
-               }
-       }
-
-       _media_thumb_db_disconnect();
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int
-_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid)
-{
-       int err = MS_MEDIA_ERR_NONE;
-       unsigned char *data = NULL;
-       int thumb_size = 0;
-       int thumb_w = 0;
-       int thumb_h = 0;
-
-       if (req_msg == NULL || res_msg == NULL) {
-               thumb_err("Invalid msg!");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       const char *origin_path = req_msg->org_path;
-
-       media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
-       thumb_w = req_msg->thumb_width;
-       thumb_h = req_msg->thumb_height;
-
-       //thumb_dbg("origin_path : %s, thumb_w : %d, thumb_h : %d ", origin_path, thumb_w, thumb_h);
-
-       if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-               thumb_err("origin_path does not exist in file system.");
-               return MS_MEDIA_ERR_FILE_NOT_EXIST;
-       }
-
-       err = _thumbnail_get_raw_data(origin_path, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, uid);
-
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_thumbnail_get_data failed - %d", err);
-               SAFE_FREE(data);
-       }
-
-       res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
-       res_msg->thumb_width = thumb_w;
-       res_msg->thumb_height = thumb_h;
-       res_raw_msg->thumb_size = thumb_size;
-       res_raw_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
-       memcpy(res_raw_msg->thumb_data, data, thumb_size);
-       res_msg->thumb_size = thumb_size + sizeof(thumbRawAddMsg) - sizeof(unsigned char*);
-
-       //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
 {
        thumbMsg recv_msg;
@@ -945,17 +608,16 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
                thumb_err("ms_ipc_create_client_socket failed");
                return err;
        }
-       GIOChannel *channel = NULL;
-       channel = g_io_channel_unix_new(sock);
-       int source_id = -1;
-
 
        memset(&serv_addr, 0, sizeof(serv_addr));
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-
        strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
 
+       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");
@@ -1050,7 +712,7 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
 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 sock;
+       int sock = -1;
        struct sockaddr_un serv_addr;
        ms_sock_info_s sock_info;
        int pid;
@@ -1062,17 +724,16 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
                thumb_err("ms_ipc_create_client_socket failed");
                return err;
        }
-       GIOChannel *channel = NULL;
-       channel = g_io_channel_unix_new(sock);
-       int source_id = -1;
-
 
        memset(&serv_addr, 0, sizeof(serv_addr));
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-
        strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
 
+       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_err("connect error : %s", strerror(errno));
index 30e6f6b..a8c7fd7 100755 (executable)
@@ -22,6 +22,7 @@
 #include "media-thumb-debug.h"
 #include "media-thumb-util.h"
 #include "media-thumb-internal.h"
+#include "media-thumb-ipc.h"
 
 #include "AGifFrameInfo.h"
 #include "IfegDecodeAGIF.h"
@@ -903,6 +904,8 @@ int _media_thumb_jpeg_for_raw(const char *origin_path,
                thumb_err("decode_with_gdk failed : %d", err);
                return err;
        }
+       /* Temporary process */
+       thumb_info->data = gdk_pixbuf_get_pixels(thumb_info->gdkdata);
 
        err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
        if (err != MS_MEDIA_ERR_NONE) {
@@ -1009,7 +1012,6 @@ int _media_thumb_video(const char *origin_path,
        int size = 0;
        int width = 0;
        int height = 0;
-       int ret = 0;
        GdkPixbuf *pixbuf;
        bool drm_type = FALSE;
 
index 387a941..c86d55d 100755 (executable)
@@ -325,146 +325,4 @@ int _media_thumb_save_to_file_with_gdk(GdkPixbuf *data,
        }
 
        return 0;
-}
-
-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,
-                                               uid_t uid)
-{
-       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 MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
-               thumb_err("parameter format is invalid");
-               return MS_MEDIA_ERR_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 MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       thumb_width = _media_thumb_get_width(thumb_type);
-       if (thumb_width < 0) {
-               thumb_err("media_thumb_type is invalid");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       thumb_height = _media_thumb_get_height(thumb_type);
-       if (thumb_height < 0) {
-               thumb_err("media_thumb_type is invalid");
-               return MS_MEDIA_ERR_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, false, uid);
-               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,uid);
-               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.gdkdata;
-       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 MS_MEDIA_ERR_NONE;
-}
-
-int _thumbnail_get_raw_data(const char *origin_path,
-                                               media_thumb_format format,
-                                               unsigned char **data,
-                                               int *size,
-                                               int *width,
-                                               int *height,
-                                               uid_t uid)
-{
-       int err = -1;
-       int thumb_width = -1;
-       int thumb_height = -1;
-
-       if (origin_path == NULL || * width <= 0 || *height <= 0) {
-               thumb_err("Invalid parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
-               thumb_err("parameter format is invalid");
-               return MS_MEDIA_ERR_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 MS_MEDIA_ERR_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);
-       thumb_width = *width;
-       thumb_height = *height;
-
-       if (file_type == THUMB_IMAGE_TYPE) {
-               err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, true, uid);
-               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,uid);
-               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.gdkdata;
-
-       thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x",
-                               *size, *width, *height, *data);
-
-       return MS_MEDIA_ERR_NONE;
 }
\ No newline at end of file
index eea85ac..5c390e9 100755 (executable)
@@ -28,6 +28,7 @@
 #include <stdbool.h>
 
 #include "media-thumbnail.h"
+#include "thumb-server-internal.h"
 #include "media-thumb-debug.h"
 #include "media-thumb-ipc.h"
 #include "media-thumb-util.h"
@@ -61,7 +62,7 @@ int main(int argc, char *argv[])
 
        if (origin_path && (mode == 1)) {
                printf("Test _thumbnail_get_data\n");
-
+#if 0
                GdkPixbuf *data = NULL;
                int thumb_size = 0;
                int thumb_w = 0;
@@ -100,7 +101,7 @@ int main(int argc, char *argv[])
 
                long end = thumb_get_debug_time();
                printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
-
+#endif
        } else if (mode == 2) {
                printf("Test thumbnail_request_from_db\n");
                //const char *origin_path = "/opt/media/test/movie1.mp4";