summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-16 01:15:44 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-16 01:15:44 +0900
commit3ff947580f7829ddff385f73d59faeb96e52dcf3 (patch)
tree838c082eea3a355ff694d86cf6d542c92c81b58a
parentb8ccdef0306cf19cde9511ec244fd43b4ae1d863 (diff)
downloadlibmedia-thumbnail-3ff947580f7829ddff385f73d59faeb96e52dcf3.tar.gz
libmedia-thumbnail-3ff947580f7829ddff385f73d59faeb96e52dcf3.tar.bz2
libmedia-thumbnail-3ff947580f7829ddff385f73d59faeb96e52dcf3.zip
merge with master
-rw-r--r--CMakeLists.txt2
-rw-r--r--media-thumbnail-server.manifest7
-rw-r--r--packaging/libmedia-thumbnail.spec5
-rwxr-xr-xserver/include/thumb-server-internal.h1
-rwxr-xr-xserver/thumb-server-internal.c48
-rwxr-xr-xserver/thumb-server.c6
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c140
-rwxr-xr-xsrc/media-thumb-internal.c1
-rwxr-xr-xsrc/media-thumbnail.c3
9 files changed, 194 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4883f7..4c7439a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include
INCLUDE(FindPkgConfig)
pkg_check_modules(pkgs REQUIRED
glib-2.0 gthread-2.0 dlog mm-fileinfo drm-client aul
-libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils)
+libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf)
FOREACH(flag ${pkgs_CFLAGS})
diff --git a/media-thumbnail-server.manifest b/media-thumbnail-server.manifest
index 2ad22fe..de4c6b8 100644
--- a/media-thumbnail-server.manifest
+++ b/media-thumbnail-server.manifest
@@ -1,12 +1,9 @@
<manifest>
- <define>
- <domain name="thumb-server"/>
- </define>
<request>
- <domain name="_"/>
+ <domain name="media-server"/>
</request>
<assign>
- <filesystem path="/usr/bin/media-thumbnail-server" label="thumb-server" exec_label="thumb-server"/>
+ <filesystem path="/usr/bin/media-thumbnail-server" label="media-server" exec_label="media-server"/>
</assign>
</manifest>
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index ab20e17..7e74f60 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,10 +1,12 @@
Name: libmedia-thumbnail
Summary: Media thumbnail service library for multimedia applications.
-Version: 0.1.65
+Version: 0.1.68
Release: 1
Group: utils
License: Apache
Source0: %{name}-%{version}.tar.gz
+
+Requires: media-server
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(mm-fileinfo)
@@ -16,6 +18,7 @@ BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(evas)
BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(libmedia-utils)
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
index cbf8644..d8a16f3 100755
--- a/server/include/thumb-server-internal.h
+++ b/server/include/thumb-server-internal.h
@@ -46,6 +46,7 @@ gboolean _thumb_daemon_udp_thread(void *data);
gboolean _thumb_daemon_start_jobs(gpointer data);
void _thumb_daemon_finish_jobs();
+void _thumb_daemon_vconf_cb(void *data);
gboolean _thumb_server_prepare_socket(int *sock_fd);
gboolean _thumb_server_read_socket(GIOChannel *src,
GIOCondition condition,
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 3844fcb..98416d6 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -26,7 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <Ecore_Evas.h>
-
+#include <vconf.h>
#ifdef LOG_TAG
#undef LOG_TAG
@@ -43,6 +43,7 @@ GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
#ifdef _USE_MEDIA_UTIL_
gboolean _thumb_server_send_msg_to_agent(int msg_type);
#endif
+void _thumb_daemon_stop_job();
gboolean _thumb_daemon_start_jobs(gpointer data)
{
@@ -71,6 +72,46 @@ void _thumb_daemon_finish_jobs()
return;
}
+void _thumb_daemon_vconf_cb(void *data)
+{
+ int err = -1;
+ int status = 0;
+
+ thumb_warn("_thumb_daemon_vconf_cb called");
+
+ err = vconf_get_int(VCONFKEY_SYSMAN_MMC_FORMAT, &status);
+ if (err == 0) {
+ if (status == VCONFKEY_SYSMAN_MMC_FORMAT_COMPLETED) {
+ thumb_warn("SD card format is completed. So media-thumbnail-server stops jobs to extract all thumbnails");
+
+ _thumb_daemon_stop_job();
+ } else {
+ thumb_dbg("not completed");
+ }
+ } else if (err == -1) {
+ thumb_err("vconf_get_int failed : %d", err);
+ } else {
+ thumb_err("vconf_get_int Unexpected error code: %d", err);
+ }
+
+ return;
+}
+
+void _thumb_daemon_stop_job()
+{
+ int i = 0;
+ char *path = NULL;
+
+ thumb_warn("There are %d jobs in the queue. But all jobs will be stopped", g_idx - g_cur_idx);
+
+ for (i = g_cur_idx; i < g_idx; i++) {
+ path = arr_path[g_cur_idx++];
+ SAFE_FREE(path);
+ }
+
+ return;
+}
+
int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
{
int err = -1;
@@ -129,7 +170,8 @@ int _thumb_daemon_all_extract()
break;
}
- strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), MAX_PATH_SIZE + 1);
+ 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);
@@ -339,11 +381,13 @@ gboolean _thumb_server_send_msg_to_agent(int msg_type)
if (sendto(sock, &send_msg, sizeof(ms_thumb_server_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(ms_thumb_server_msg)) {
thumb_err("sendto failed: %s\n", strerror(errno));
+ close(sock);
return FALSE;
}
thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
+ close(sock);
return TRUE;
}
#endif
diff --git a/server/thumb-server.c b/server/thumb-server.c
index 3b79684..9e7c1e1 100755
--- a/server/thumb-server.c
+++ b/server/thumb-server.c
@@ -27,6 +27,7 @@
#include <pthread.h>
#include <heynoti.h>
+#include <vconf.h>
//#include <signal.h>
//#include <glib-unix.h>
@@ -78,6 +79,11 @@ int main()
}
}
+ /* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
+ err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
+ if (err == -1)
+ thumb_err("vconf_notify_key_changed %s fails", VCONFKEY_SYSMAN_MMC_FORMAT);
+
/* Create and bind new UDP socket */
if (!_thumb_server_prepare_socket(&sockfd)) {
thumb_err("Failed to create socket\n");
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 67f22bd..3897c4a 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -28,7 +28,12 @@
#include <string.h>
#include <errno.h>
-
+static __thread GQueue *g_request_queue = NULL;
+typedef struct {
+ GIOChannel *channel;
+ char *path;
+ int source_id;
+} thumbReq;
int
_media_thumb_create_socket(int sock_type, int *sock)
@@ -108,6 +113,79 @@ int _media_thumb_get_error()
}
}
+int __media_thumb_pop_req_queue(const char *path, bool shutdown_channel)
+{
+ int req_len = 0, i;
+
+ if (g_request_queue == NULL) return -1;
+ req_len = g_queue_get_length(g_request_queue);
+
+// thumb_dbg("Queue length : %d", req_len);
+// thumb_dbg("Queue path : %s", path);
+
+ if (req_len <= 0) {
+// thumb_dbg("There is no request in the queue");
+ } else {
+
+ for (i = 0; i < req_len; i++) {
+ thumbReq *req = NULL;
+ req = (thumbReq *)g_queue_peek_nth(g_request_queue, i);
+ if (req == NULL) continue;
+
+ if (strncmp(path, req->path, strlen(path)) == 0) {
+ //thumb_dbg("Popped %s", path);
+ if (shutdown_channel) {
+ g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id));
+
+ g_io_channel_shutdown(req->channel, TRUE, NULL);
+ g_io_channel_unref(req->channel);
+ }
+ g_queue_pop_nth(g_request_queue, i);
+
+ SAFE_FREE(req->path);
+ SAFE_FREE(req);
+
+ break;
+ }
+ }
+ if (i == req_len) {
+// thumb_dbg("There's no %s in the queue", path);
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int __media_thumb_check_req_queue(const char *path)
+{
+ int req_len = 0, i;
+
+ req_len = g_queue_get_length(g_request_queue);
+
+// thumb_dbg("Queue length : %d", req_len);
+// thumb_dbg("Queue path : %s", path);
+
+ if (req_len <= 0) {
+// thumb_dbg("There is no request in the queue");
+ } else {
+
+ for (i = 0; i < req_len; i++) {
+ thumbReq *req = NULL;
+ req = (thumbReq *)g_queue_peek_nth(g_request_queue, i);
+ if (req == NULL) continue;
+
+ if (strncmp(path, req->path, strlen(path)) == 0) {
+ //thumb_dbg("Same Request - %s", path);
+ return -1;
+
+ break;
+ }
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
int
_media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
{
@@ -291,6 +369,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
+ close(sock);
return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
@@ -503,8 +582,6 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
- thumb_err("_media_thumb_write_socket is called");
-
thumbMsg recv_msg;
int header_size = 0;
int recv_str_len = 0;
@@ -516,17 +593,22 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2;
+ thumb_err("_media_thumb_write_socket socket : %d", sock);
+
if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
thumb_err("_media_thumb_recv_msg failed ");
g_io_channel_shutdown(src, TRUE, NULL);
- return err;
+ return FALSE;
}
recv_str_len = strlen(recv_msg.dst_path);
- thumb_dbg("recv %s(%d) from thumb daemon is successful", recv_msg.dst_path, recv_str_len);
+ thumb_dbg("recv %s(%d) in [ %s ] from thumb daemon is successful", recv_msg.dst_path, recv_str_len, recv_msg.org_path);
g_io_channel_shutdown(src, TRUE, NULL);
+ //thumb_dbg("Completed..%s", recv_msg.org_path);
+ __media_thumb_pop_req_queue(recv_msg.org_path, FALSE);
+
if (recv_msg.status == THUMB_FAIL) {
thumb_err("Failed to make thumbnail");
err = MEDIA_THUMB_ERROR_UNSUPPORTED;
@@ -541,6 +623,7 @@ callback:
cb = NULL;
}
+ thumb_dbg("Done");
return FALSE;
}
@@ -553,6 +636,9 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
int pid;
+ if ((msg_type == THUMB_REQUEST_DB_INSERT) && (__media_thumb_check_req_queue(origin_path) < 0)) {
+ return MEDIA_THUMB_ERROR_DUPLICATED_REQUEST;
+ }
#ifdef _USE_MEDIA_UTIL_
if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) {
@@ -569,10 +655,8 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
GIOChannel *channel = NULL;
channel = g_io_channel_unix_new(sock);
+ int source_id = -1;
- if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
- g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData );
- }
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
@@ -590,6 +674,18 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
return MEDIA_THUMB_ERROR_NETWORK;
}
+ if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
+ //source_id = g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData );
+
+ /* Create new channel to watch udp socket */
+ GSource *source = NULL;
+ source = g_io_create_watch(channel, G_IO_IN);
+
+ /* Set callback to be called when socket is readable */
+ g_source_set_callback(source, (GSourceFunc)_media_thumb_write_socket, userData, NULL);
+ source_id = g_source_attach(source, g_main_context_get_thread_default());
+ }
+
thumbMsg req_msg;
memset((void *)&req_msg, 0, sizeof(thumbMsg));
@@ -618,6 +714,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
if (send(sock, buf, buf_size, 0) != buf_size) {
thumb_err("sendto failed: %d\n", errno);
SAFE_FREE(buf);
+ g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
g_io_channel_shutdown(channel, TRUE, NULL);
return MEDIA_THUMB_ERROR_NETWORK;
}
@@ -625,9 +722,36 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
SAFE_FREE(buf);
thumb_dbg("Sending msg to thumbnail daemon is successful");
+#if 0
+ if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) {
+ g_io_channel_shutdown(channel, TRUE, NULL);
+ }
+#else
if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) {
g_io_channel_shutdown(channel, TRUE, NULL);
+
+ //thumb_dbg("Cancel : %s[%d]", origin_path, sock);
+ __media_thumb_pop_req_queue(origin_path, TRUE);
+ } else if (msg_type == THUMB_REQUEST_DB_INSERT) {
+ if (g_request_queue == NULL) {
+ g_request_queue = g_queue_new();
+ }
+
+ thumbReq *thumb_req = NULL;
+ thumb_req = calloc(1, sizeof(thumbReq));
+ if (thumb_req == NULL) {
+ thumb_err("Failed to create request element");
+ return 0;
+ }
+
+ thumb_req->channel = channel;
+ thumb_req->path = strdup(origin_path);
+ thumb_req->source_id = source_id;
+
+ //thumb_dbg("Push : %s [%d]", origin_path, sock);
+ g_queue_push_tail(g_request_queue, (gpointer)thumb_req);
}
+#endif
return 0;
}
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index c809ead..0feee8a 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -1193,7 +1193,6 @@ _media_thumb_video(const char *origin_path,
return err;
}
} else {
-
thumb_info->size = size;
thumb_info->width = width;
thumb_info->height = height;
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index 11bcc0b..420414e 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -103,9 +103,10 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu
}
media_thumb_info thumb_info;
- char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
+ char tmp_thumb_path[MAX_PATH_SIZE + 1] = {0,};
strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
+ tmp_thumb_path[sizeof(tmp_thumb_path) - 1] = '\0';
/* Request for thumb file to the daemon "Thumbnail generator" */
err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);