summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdebian/changelog8
-rwxr-xr-xinclude/media-thumb-types.h2
-rwxr-xr-xinclude/media-thumbnail.h30
-rw-r--r--packaging/libmedia-thumbnail.spec22
-rwxr-xr-xserver/include/thumb-server-internal.h8
-rwxr-xr-xserver/thumb-server-internal.c232
-rwxr-xr-xserver/thumb-server.c10
-rw-r--r--src/codec/img-codec.c22
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h5
-rwxr-xr-xsrc/include/util/media-thumb-db.h11
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c19
-rwxr-xr-xsrc/media-thumb-internal.c7
-rwxr-xr-xsrc/media-thumbnail.c23
-rwxr-xr-xsrc/util/media-thumb-db.c60
-rwxr-xr-xtest/test-thumb.c10
15 files changed, 296 insertions, 173 deletions
diff --git a/debian/changelog b/debian/changelog
index 455bed9..c2ac9c8 100755
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+libmedia-thumbnail (0.2.0-5) unstable; urgency=low
+
+ * Push for tizen 1.0 release
+ * Git : pkgs/l/libmedia-thumbnail
+ * Tag : libmedia-thumbnail_0.2.0-5
+
+ -- Hyunjun Ko <zzoon.ko@samsung.com> Mon, 19 Mar 2012 18:30:00 +0900
+
libmedia-thumbnail (0.2.0-4) unstable; urgency=low
* Change thumbnail policy - Large: 320x240, Small: 160x120
diff --git a/include/media-thumb-types.h b/include/media-thumb-types.h
index c73289d..3387a6c 100755
--- a/include/media-thumb-types.h
+++ b/include/media-thumb-types.h
@@ -30,7 +30,7 @@ typedef enum {
} media_thumb_type;
typedef enum {
- MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */
+ MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */
MEDIA_THUMB_RGB888, /* RGB888 */
} media_thumb_format;
diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h
index ab68c4a..2d77601 100755
--- a/include/media-thumbnail.h
+++ b/include/media-thumbnail.h
@@ -127,8 +127,38 @@ int thumbnail_request_save_to_file(const char *origin_path,
const char *thumb_path);
+/**
+ * thumbnail_request_extract_all_thumbs:
+ * This function generates thumbnail of all media, which don't have thumbnail yet and save it to the file system as jpeg format.
+ * Once thumbnail generated, the thumbnail path and original image's width and height will be updated to media database.
+ *
+ * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code.
+ * Please refer 'media-thumb-error.h' to know the exact meaning of the error.
+ * @see None.
+ * @pre None.
+ * @post None.
+ * @par example
+ * @code
+#include <media-thumbnail.h>
+
+void extract_all_thumbs()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+
+ ret = thumbnail_request_extract_all_thumbs();
+
+ if (ret < 0) {
+ printf( "thumbnail_request_extract_all_thumbs fails. error code->%d", ret);
+ }
+
+ return;
+}
+
+ * @endcode
+ */
+int thumbnail_request_extract_all_thumbs(void);
/** @} */
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index ebb9bd4..7407641 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -2,7 +2,7 @@ Name: libmedia-thumbnail
Summary: Media thumbnail service library for multimedia applications.
Version: 0.2.0
Release: 1
-Group: TO_BE/FILLED_IN
+Group: System/Libraries
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
@@ -23,7 +23,7 @@ Description: Media thumbnail service library for multimedia applications.
%package devel
-License: TO_BE / FILL_IN
+License: Apache-2.0
Summary: Media thumbnail service library for multimedia applications. (development)
Requires: %{name} = %{version}-%{release}
Group: Development/Libraries
@@ -32,7 +32,7 @@ Group: Development/Libraries
Description: Media thumbnail service library for multimedia applications. (development)
%package -n media-thumbnail-server
-License: TO_BE / FILL_IN
+License: Apache-2.0
Summary: Thumbnail generator.
Requires: %{name} = %{version}-%{release}
Group: Development/Libraries
@@ -50,24 +50,24 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
make %{?jobs:-j%jobs}
%install
+rm -rf %{buildroot}
%make_install
-chmod +x %{buildroot}/etc//init.d/thumbsvr
-
-%post
-ln -s /etc//init.d/thumbsvr %{_sysconfdir}/rc.d/rc5.d/S47thumbsvr
-ln -s /etc/init.d/thumbsvr %{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d/
+ln -s %{_sysconfdir}/init.d/thumbsvr %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S47thumbsvr
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d/
+ln -s %{_sysconfdir}/init.d/thumbsvr %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
%files
+%{_libdir}/libmedia-thumbnail.so
%{_libdir}/libmedia-thumbnail.so.*
+%{_libdir}/libmedia-hash.so
%{_libdir}/libmedia-hash.so.*
%files devel
-%{_libdir}/libmedia-thumbnail.so
-%{_libdir}/libmedia-hash.so
%{_libdir}/pkgconfig/media-thumbnail.pc
%{_includedir}/media-thumbnail/media-thumb-types.h
%{_includedir}/media-thumbnail/media-thumb-error.h
@@ -78,5 +78,7 @@ ln -s /etc/init.d/thumbsvr %{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
%files -n media-thumbnail-server
%{_bindir}/media-thumbnail-server
%attr(755,root,root) %{_sysconfdir}/init.d/thumbsvr
+%attr(755,root,root) %{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
+%attr(755,root,root) %{_sysconfdir}/rc.d/rc5.d/S47thumbsvr
%exclude %{_bindir}/test-thumb
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
index 1b19a61..2d061c8 100755
--- a/server/include/thumb-server-internal.h
+++ b/server/include/thumb-server-internal.h
@@ -21,6 +21,7 @@
#include <glib.h>
#include "media-thumb-ipc.h"
+#include "media-thumb-db.h"
#ifndef _THUMB_DAEMON_INTERNAL_H_
#define _THUMB_DAEMON_INTERNAL_H_
@@ -38,14 +39,7 @@ typedef enum {
TIMEOUT_MODE = 1
} _server_mode_e;
-typedef struct _queueMsg{
- thumbMsg *recv_msg;
- thumbMsg *res_msg;
- struct sockaddr_in *client_addr;
-} queueMsg;
-
int _thumb_daemon_get_sockfd();
-GAsyncQueue *_thumb_daemon_get_queue();
gboolean _thumb_daemon_udp_thread(void *data);
#endif /*_THUMB_DAEMON_INTERNAL_H_*/
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 7e749a3..bf455db 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -31,10 +31,12 @@
#undef LOG_TAG
#endif
-#define LOG_TAG "Thumb-Daemon"
+#define LOG_TAG "Thumb-Server"
-static int sock;
-GAsyncQueue *g_req_queue = NULL;
+static __thread int sock;
+static __thread char **arr_path;
+static __thread int g_idx = 0;
+static __thread int g_cur_idx = 0;
static __thread _server_mode_e g_server_mode = BLOCK_MODE;
static __thread int g_media_svr_pid = 0;
@@ -44,29 +46,6 @@ int _thumb_daemon_get_sockfd()
return sock;
}
-
-GAsyncQueue *_thumb_daemon_get_queue()
-{
- return g_req_queue;
-}
-
-void _thumb_daemon_destroy_queue_msg(queueMsg *msg)
-{
- if (msg != NULL) {
- if (msg->recv_msg != NULL) {
- free(msg->recv_msg);
- msg->recv_msg = NULL;
- }
-
- if (msg->res_msg != NULL) {
- free(msg->res_msg);
- msg->res_msg = NULL;
- }
-
- msg = NULL;
- }
-}
-
int _thumb_daemon_compare_pid_with_mediaserver_fast(int pid)
{
int find_pid = -1;
@@ -155,7 +134,6 @@ int _thumb_daemon_compare_pid_with_mediaserver(int pid)
int _thumb_daemon_recv_by_select(int fd, gboolean is_timeout)
{
- thumb_err("");
fd_set fds;
int ret = -1;
@@ -164,8 +142,8 @@ int _thumb_daemon_recv_by_select(int fd, gboolean is_timeout)
if (is_timeout) {
struct timeval timeout;
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 10000;
ret = select(fd + 1, &fds, 0, 0, &timeout);
} else {
@@ -181,7 +159,7 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
err = _media_thumb_process(req_msg, res_msg);
if (err < 0) {
- if (req_msg->msg_type == THUMB_REQUEST_SAVE) {
+ if (req_msg->msg_type == THUMB_REQUEST_SAVE_FILE) {
thumb_err("_media_thumb_process is failed: %d", err);
res_msg->status = THUMB_FAIL;
} else {
@@ -195,33 +173,114 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
return err;
}
-int _thumb_daemon_process_queue_jobs()
+int _thumb_daemon_all_extract()
{
- int length = 0;
+ int err = -1;
+ int count = 0;
+ char query_string[MAX_PATH_SIZE + 1] = { 0, };
+ char path[MAX_PATH_SIZE + 1] = { 0, };
+ sqlite3 *sqlite_db_handle = NULL;
+ sqlite3_stmt *sqlite_stmt = NULL;
+
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_db_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ sqlite_db_handle = _media_thumb_db_get_handle();
+ if (sqlite_db_handle == NULL) {
+ thumb_err("sqlite handle is NULL");
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ snprintf(query_string, sizeof(query_string), SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA);
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(sqlite_db_handle, query_string, strlen(query_string), &sqlite_stmt, NULL);
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(sqlite_db_handle));
+ return MEDIA_THUMB_ERROR_DB;
+ }
while(1) {
- length = g_async_queue_length(g_req_queue);
- if (length > 0) {
- thumb_dbg("There are %d jobs in the queue", length);
- queueMsg *data = g_async_queue_pop(g_req_queue);
+ err = sqlite3_step(sqlite_stmt);
+ if (err != SQLITE_ROW) {
+ thumb_dbg("end of row [%s]\n", sqlite3_errmsg(sqlite_db_handle));
+ break;
+ }
- _thumb_daemon_process_job(data->recv_msg, data->res_msg);
+ strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), MAX_PATH_SIZE + 1);
+ count = sqlite3_column_int(sqlite_stmt, 1);
- if (sendto(sock, data->res_msg, sizeof(thumbMsg), 0, (struct sockaddr *)data->client_addr, sizeof(struct sockaddr_in)) != sizeof(thumbMsg)) {
- thumb_err("sendto failed\n");
- } else {
- thumb_dbg("Sent %s(%d) \n", data->res_msg->dst_path, strlen(data->res_msg->dst_path));
- }
+ thumb_dbg("Path : %s", path);
- _thumb_daemon_destroy_queue_msg(data);
+ if (g_idx == 0) {
+ arr_path = (char**)malloc(sizeof(char*));
} else {
- break;
+ arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*));
}
+
+ arr_path[g_idx++] = strdup(path);
}
- g_server_mode = BLOCK_MODE;
+ sqlite3_finalize(sqlite_stmt);
+ _media_thumb_db_disconnect();
- return 0;
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int _thumb_daemon_process_queue_jobs()
+{
+ int err = -1;
+ char *path = NULL;
+
+ if (g_cur_idx < g_idx) {
+ thumb_dbg("There are %d jobs in the queue", g_idx - g_cur_idx);
+ thumb_dbg("Current idx : [%d]", g_cur_idx);
+ path = arr_path[g_cur_idx++];
+
+ thumbMsg recv_msg, res_msg;
+ memset(&recv_msg, 0x00, sizeof(thumbMsg));
+ memset(&res_msg, 0x00, sizeof(thumbMsg));
+
+ recv_msg.msg_type = THUMB_REQUEST_DB_INSERT;
+ recv_msg.thumb_type = MEDIA_THUMB_LARGE;
+ strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path));
+
+ _thumb_daemon_process_job(&recv_msg, &res_msg);
+
+ if (res_msg.status == THUMB_SUCCESS) {
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ /* Need to update DB once generating thumb is done */
+ err = _media_thumb_update_db(recv_msg.org_path,
+ res_msg.dst_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();
+ }
+
+ free(path);
+ path = NULL;
+ g_server_mode = TIMEOUT_MODE;
+ } else {
+ g_cur_idx = 0;
+ g_idx = 0;
+ g_server_mode = BLOCK_MODE;
+ thumb_warn("Deleting array");
+ free(arr_path);
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
}
gboolean _thumb_daemon_udp_thread(void *data)
@@ -234,7 +293,6 @@ gboolean _thumb_daemon_udp_thread(void *data)
unsigned short serv_port;
unsigned int client_addr_len;
- queueMsg *queue_msg = NULL;
thumbMsg recv_msg;
thumbMsg res_msg;
int recv_msg_size;
@@ -244,10 +302,6 @@ gboolean _thumb_daemon_udp_thread(void *data)
memset((void *)&res_msg, 0, sizeof(res_msg));
serv_port = THUMB_DAEMON_PORT;
- if (!g_req_queue) {
- g_req_queue = g_async_queue_new();
- }
-
/* Creaete a datagram/UDP socket */
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
thumb_err("socket failed");
@@ -270,7 +324,7 @@ gboolean _thumb_daemon_udp_thread(void *data)
while(1) {
if (g_server_mode == TIMEOUT_MODE) {
- thumb_dbg("Wait for other app's request for 1 sec");
+ thumb_dbg("Wait for other app's request for 10 msec");
is_timeout = TRUE;
} else {
is_timeout = FALSE;
@@ -289,7 +343,6 @@ gboolean _thumb_daemon_udp_thread(void *data)
continue;
} else {
- _pid_e pid_type = 0;
/* Socket is readable */
client_addr_len = sizeof(client_addr);
if ((recv_msg_size = recvfrom(sock, &recv_msg, sizeof(recv_msg), 0, (struct sockaddr *)&client_addr, &client_addr_len)) < 0) {
@@ -299,77 +352,28 @@ gboolean _thumb_daemon_udp_thread(void *data)
thumb_dbg("Received [%d] %s(%d) from PID(%d) \n", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
- if (g_media_svr_pid > 0) {
- pid_type = _thumb_daemon_compare_pid_with_mediaserver_fast(recv_msg.pid);
- }
-
- if (g_media_svr_pid <= 0) {
- pid_type = _thumb_daemon_compare_pid_with_mediaserver(recv_msg.pid);
- }
-
- if (pid_type == GETPID_FAIL) {
- thumb_err("Failed to get media svr pid. So This req is regarded as other app's request.");
- pid_type = OTHERS_PID;
- }
+ if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
+ thumb_dbg("All thumbnails are being extracted now");
+ _thumb_daemon_all_extract();
- if (g_server_mode == BLOCK_MODE || pid_type == OTHERS_PID) {
+ g_server_mode = TIMEOUT_MODE;
+ } else {
long start = thumb_get_debug_time();
_thumb_daemon_process_job(&recv_msg, &res_msg);
long end = thumb_get_debug_time();
thumb_dbg("Time : %f (%s)\n", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path);
+ }
- if (sendto(sock, &res_msg, sizeof(res_msg), 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != sizeof(res_msg)) {
- thumb_err("sendto failed\n");
- } else {
- thumb_dbg("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path));
- }
-
- memset((void *)&recv_msg, 0, sizeof(recv_msg));
- memset((void *)&res_msg, 0, sizeof(res_msg));
-
- if (pid_type == OTHERS_PID) {
- g_server_mode = TIMEOUT_MODE;
- }
+ if (sendto(sock, &res_msg, sizeof(res_msg), 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != sizeof(res_msg)) {
+ thumb_err("sendto failed\n");
} else {
- /* This is a request from media-server on TIMEOUT mode.
- So this req is going to be pushed to the queue */
-
- queue_msg = malloc(sizeof(queueMsg));
- if (queue_msg == NULL) {
- thumb_err("malloc failed");
- continue;
- }
- queue_msg->recv_msg = malloc(sizeof(thumbMsg));
- if (queue_msg->recv_msg == NULL) {
- thumb_err("malloc failed");
- SAFE_FREE(queue_msg);
- continue;
- }
- queue_msg->res_msg = malloc(sizeof(thumbMsg));
- if (queue_msg->res_msg == NULL) {
- thumb_err("malloc failed");
- SAFE_FREE(queue_msg->recv_msg);
- SAFE_FREE(queue_msg);
- continue;
- }
- queue_msg->client_addr = malloc(sizeof(struct sockaddr_in));
- if (queue_msg->client_addr == NULL) {
- thumb_err("malloc failed");
- SAFE_FREE(queue_msg->recv_msg);
- SAFE_FREE(queue_msg->res_msg);
- SAFE_FREE(queue_msg);
- continue;
- }
-
- memcpy(queue_msg->recv_msg, &recv_msg, sizeof(thumbMsg));
- memcpy(queue_msg->res_msg, &res_msg, sizeof(thumbMsg));
- memcpy(queue_msg->client_addr, &client_addr, sizeof(struct sockaddr_in));
-
- g_async_queue_push(g_req_queue, GINT_TO_POINTER(queue_msg));
- g_server_mode = TIMEOUT_MODE;
+ thumb_dbg("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path));
}
+
+ memset((void *)&recv_msg, 0, sizeof(recv_msg));
+ memset((void *)&res_msg, 0, sizeof(res_msg));
}
}
diff --git a/server/thumb-server.c b/server/thumb-server.c
index 16a42fe..f94d32a 100755
--- a/server/thumb-server.c
+++ b/server/thumb-server.c
@@ -32,7 +32,7 @@
#undef LOG_TAG
#endif
-#define LOG_TAG "Thumb-Daemon"
+#define LOG_TAG "Thumb-Server"
#ifdef USE_HIB
#undef USE_HIB
@@ -75,13 +75,6 @@ void _hibernation_enter_callback(void *data)
close(sock);
}
- GAsyncQueue *req_queue = _thumb_daemon_get_queue();
-
- if (req_queue != NULL) {
- g_async_queue_unref(req_queue);
- req_queue = NULL;
- }
-
if (hib_fd != 0) {
heynoti_close(hib_fd);
hib_fd = 0;
@@ -120,6 +113,7 @@ int main()
}
udp_thr = g_thread_create((GThreadFunc)_thumb_daemon_udp_thread, NULL, FALSE, NULL);
+
mainloop = g_main_loop_new(NULL, FALSE);
thumb_dbg("*****************************************");
diff --git a/src/codec/img-codec.c b/src/codec/img-codec.c
index 06a6419..fadd8c2 100644
--- a/src/codec/img-codec.c
+++ b/src/codec/img-codec.c
@@ -22,6 +22,7 @@
#include "media-thumb-debug.h"
#include "img-codec.h"
#include <string.h>
+#include <mm_util_imgp.h>
unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
ImgImageInfo *image_info)
@@ -57,8 +58,15 @@ unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
pFrameInfo->pOutBits = pDecodedRGB888Buf;
unsigned char *src =
((unsigned char *)(pFrameInfo->pOutBits));
- int i =
- image_info->width * image_info->height * 3;
+
+ unsigned int i = 0;
+
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, image_info->width, image_info->height, &i) < 0) {
+ thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size");
+ return NULL;
+ }
+ thumb_dbg("ImgGetFirstFrameAGIFAtSize: raw data size : %d)", i);
+
raw_data = (unsigned char *)malloc(i);
memset(raw_data, 0, i);
unsigned char *dest = raw_data;
@@ -90,6 +98,7 @@ int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width,
unsigned char *rgb888Buf = 0;
unsigned char red, green, blue;
int i;
+ unsigned int size;
rgb565buf = (unsigned short *)pBuf_rgb565;
if (rgb565buf == NULL) {
@@ -97,14 +106,19 @@ int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width,
return FALSE;
}
- rgb888Buf = (unsigned char *)malloc(width * height * 3);
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, width, height, &size) < 0) {
+ thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size");
+ return FALSE;
+ }
+
+ rgb888Buf = (unsigned char *)malloc(size);
if (rgb888Buf == NULL) {
thumb_err("rgb888Buf is NULL: Error !!!");
return FALSE;
}
- memset(rgb888Buf, 0, (width * height * 3));
+ memset(rgb888Buf, 0, size);
for (i = 0; i < width * height; i++) {
red = ((rgb565buf[i] >> 11) & 0x1F) << 3;
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
index 3c91a1e..81f9116 100755
--- a/src/include/ipc/media-thumb-ipc.h
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -43,8 +43,9 @@
#define MAX_TRIES 3
enum {
- THUMB_REQUEST_DB,
- THUMB_REQUEST_SAVE,
+ THUMB_REQUEST_DB_INSERT,
+ THUMB_REQUEST_SAVE_FILE,
+ THUMB_REQUEST_ALL_MEDIA,
THUMB_RESPONSE
};
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
index 10b08d2..bf89e94 100755
--- a/src/include/util/media-thumb-db.h
+++ b/src/include/util/media-thumb-db.h
@@ -19,7 +19,7 @@
*
*/
-
+#include <sqlite3.h>
#include "media-thumb-error.h"
#include "media-thumb-types.h"
#include "media-thumb-debug.h"
@@ -27,6 +27,15 @@
#ifndef _MEDIA_THUMB_DB_H_
#define _MEDIA_THUMB_DB_H_
+#define MEDIA_DATABASE_NAME "/opt/dbspace/.media.db"
+
+#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from visual_media where thumbnail_path='' and valid=1;"
+#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM visual_media WHERE path='%q';"
+#define UPDATE_THUMB_BY_PATH "UPDATE visual_media SET thumbnail_path = '%q' WHERE path='%q';"
+#define UPDATE_WH_BY_PATH "UPDATE image_meta SET width=%d,height=%d WHERE visual_uuid=(SELECT visual_uuid FROM visual_media WHERE path='%q');"
+
+sqlite3 *_media_thumb_db_get_handle();
+
int
_media_thumb_db_connect();
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 3718f6f..ad45153 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -56,7 +56,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
- if (msg_type == THUMB_REQUEST_SAVE) {
+ if (msg_type == THUMB_REQUEST_SAVE_FILE) {
strncpy(req_msg.dst_path, thumb_path, sizeof(req_msg.dst_path));
req_msg.dst_path[strlen(req_msg.dst_path)] = '\0';
}
@@ -83,7 +83,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
thumb_err("setsockopt failed: %d\n", errno);
return MEDIA_THUMB_ERROR_NETWORK;
}
-
+
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
@@ -162,7 +162,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
return -1;
}
- if (msg_type != THUMB_REQUEST_SAVE) {
+ if (msg_type != THUMB_REQUEST_SAVE_FILE) {
strncpy(thumb_path, recv_msg.dst_path, max_length);
}
@@ -196,10 +196,10 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
- thumb_path = req_msg->dst_path;
- max_length = sizeof(req_msg->dst_path);
+ thumb_path = res_msg->dst_path;
+ max_length = sizeof(res_msg->dst_path);
- if (msg_type == THUMB_REQUEST_DB) {
+ if (msg_type == THUMB_REQUEST_DB_INSERT) {
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);
@@ -208,6 +208,8 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
}
thumb_path[strlen(thumb_path)] = '\0';
+ } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
+ strncpy(thumb_path, req_msg->dst_path, sizeof(thumb_path));
}
thumb_dbg("Thumb path : %s", thumb_path);
@@ -215,7 +217,6 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
if (g_file_test(thumb_path,
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
thumb_warn("thumb path already exists in file system");
- strncpy(res_msg->dst_path, thumb_path, sizeof(res_msg->dst_path));
return 0;
}
@@ -244,7 +245,7 @@ _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)
+ if (msg_type == THUMB_REQUEST_DB_INSERT)
strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
return err;
@@ -267,8 +268,6 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
}
/* End of fsync */
- strncpy(res_msg->dst_path, thumb_path, sizeof(res_msg->dst_path));
-
SAFE_FREE(data);
return 0;
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index 513ccb4..1f62014 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -829,6 +829,11 @@ int _media_thumb_agif(const char *origin_path,
thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
+ if (!thumb) {
+ thumb_err("Frame data is NULL!!");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
thumb_type = MEDIA_THUMB_LARGE;
} else {
@@ -857,7 +862,7 @@ int _media_thumb_agif(const char *origin_path,
SAFE_FREE(thumb);
return err;
}
-
+
SAFE_FREE(thumb);
err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index 7d7165c..0796bec 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -60,7 +60,6 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max
thumb_err("Path : %s", origin_path);
- //err = minfo_init();
err = _media_thumb_db_connect();
if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
@@ -74,7 +73,7 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max
}
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
+ 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();
@@ -108,7 +107,7 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu
strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_SAVE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -117,4 +116,22 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu
return MEDIA_THUMB_ERROR_NONE;
}
+int thumbnail_request_extract_all_thumbs(void)
+{
+ int err = -1;
+
+ media_thumb_info thumb_info;
+ media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
+ char tmp_origin_path[MAX_PATH_SIZE] = {0,};
+ char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
+
+ /* Request for thumb file to the daemon "Thumbnail generator" */
+ err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index a302c7c..a379eed 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -20,19 +20,13 @@
*/
#include "media-thumb-db.h"
-//#include <media-svc.h>
-//#include <visual-svc.h>
+#include "media-thumb-util.h"
#include <glib.h>
#include <string.h>
#include <unistd.h>
#include <util-func.h>
-//__thread MediaSvcHandle *mb_svc_handle = NULL;
-__thread sqlite3 *db_handle;
-const char *MEDIA_DATABASE_NAME = "/opt/dbspace/.media.db";
-const char *SELECT_MEDIA_BY_PATH = "SELECT thumbnail_path FROM visual_media WHERE path='%q';";
-const char *UPDATE_THUMB_BY_PATH = "UPDATE visual_media SET thumbnail_path = '%q' WHERE path='%q';";
-const char *UPDATE_WH_BY_PATH = "UPDATE image_meta SET width=%d,height=%d WHERE visual_uuid=(SELECT visual_uuid FROM visual_media WHERE path='%q');";
+static __thread sqlite3 *db_handle;
static int _media_thumb_busy_handler(void *pData, int count)
{
@@ -42,6 +36,11 @@ static int _media_thumb_busy_handler(void *pData, int count)
return 100 - count;
}
+sqlite3 *_media_thumb_db_get_handle()
+{
+ return db_handle;
+}
+
int
_media_thumb_sqlite_connect(sqlite3 **handle)
{
@@ -313,18 +312,55 @@ _media_thumb_update_db(const char *origin_path,
thumb_dbg("");
int err = -1;
- err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+#if 0
+ Mitem *item = NULL;
+
+ err = minfo_get_item(mb_svc_handle, origin_path, &item);
if (err < 0) {
- thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ 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;
}
- err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height);
+ 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
+
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
if (err < 0) {
- thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
+ thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
return MEDIA_THUMB_ERROR_DB;
}
+ int media_type = THUMB_NONE_TYPE;
+ media_type = _media_thumb_get_file_type(origin_path);
+
+ 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;
+ }
+ }
+
thumb_dbg("_media_thumb_update_db success");
return MEDIA_THUMB_ERROR_NONE;
diff --git a/test/test-thumb.c b/test/test-thumb.c
index 3dbbd47..69c619a 100755
--- a/test/test-thumb.c
+++ b/test/test-thumb.c
@@ -216,6 +216,16 @@ int main(int argc, char *argv[])
}
printf("Success!!\n");
+ } else if (mode == 5) {
+ printf("Test thumbnail_request_extract_all_thumbs\n");
+
+ err = thumbnail_request_extract_all_thumbs();
+ if (err < 0) {
+ printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
+ return -1;
+ } else {
+ printf("thumbnail_request_extract_all_thumbs success!\n");
+ }
}
return 0;