summaryrefslogtreecommitdiff
path: root/server/thumb-server-internal.c
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2019-09-26 06:18:02 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2019-09-27 01:00:56 (GMT)
commit1dbcc2241014a5090093bbccce4878010763d2ea (patch)
tree87dd64706f6b5f396c88646f5c4be402d017c703 /server/thumb-server-internal.c
parenta7dfb761065e2b20829560d7aeeca5c2043a2bed (diff)
downloadlibmedia-thumbnail-1dbcc2241014a5090093bbccce4878010763d2ea.zip
libmedia-thumbnail-1dbcc2241014a5090093bbccce4878010763d2ea.tar.gz
libmedia-thumbnail-1dbcc2241014a5090093bbccce4878010763d2ea.tar.bz2
Change-Id: I827538cf8d3c634878d4d2da3fab71c8c89d0316 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'server/thumb-server-internal.c')
-rwxr-xr-xserver/thumb-server-internal.c371
1 files changed, 177 insertions, 194 deletions
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 3d97cb4..8aecc6b 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -40,6 +40,182 @@
#define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
#define THUMB_EMPTY_STR ""
+static int __thumbnail_get_data(const char *origin_path, char *thumb_path)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ int file_type = THUMB_NONE_TYPE;
+
+ thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
+ thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
+ thumb_dbg("Origin path : %s", origin_path);
+
+ file_type = _media_thumb_get_file_type(origin_path);
+
+ if (file_type == THUMB_IMAGE_TYPE) {
+ err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
+ }
+
+ thumb_dbg("Thumb data is generated successfully");
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __thumbnail_get_raw_data(const char *origin_path, int *width, int *height, unsigned char **data, int *size)
+{
+ 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 (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("Original path (%s) does not exist", origin_path);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ 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, NULL, thumb_width, thumb_height, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
+ }
+
+ if (size) *size = thumb_info.size;
+ *data = thumb_info.data;
+ *width = thumb_info.width;
+ *height = thumb_info.height;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
+{
+ int err = MS_MEDIA_ERR_NONE;
+
+ thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
+
+ memset(res_msg->dst_path, 0, MAX_FILEPATH_LEN);
+ res_msg->status = MS_MEDIA_ERR_NONE;
+
+ if (!g_file_test(req_msg->org_path, G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("origin_path does not exist in file system.");
+ res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST;
+ return MS_MEDIA_ERR_FILE_NOT_EXIST;
+ }
+
+ err = _media_thumb_get_thumb_from_db(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
+ thumb_retvm_if(err == MS_MEDIA_ERR_NONE, err, "Already exists");
+ if (strlen(res_msg->dst_path) == 0) {
+ err = _media_thumb_get_hash_name(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_get_hash_name failed - %d", err);
+ SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
+ res_msg->status = err;
+ return err;
+ }
+ }
+
+ thumb_dbg_slog("Thumb path : %s", res_msg->dst_path);
+
+ err = __thumbnail_get_data(req_msg->org_path, res_msg->dst_path);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_thumbnail_get_data failed - %d", err);
+ SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
+ res_msg->status = err;
+
+ goto DB_UPDATE;
+ }
+
+ res_msg->msg_type = THUMB_RESPONSE;
+
+DB_UPDATE:
+ err = _media_thumb_update_db(req_msg->org_path, res_msg->dst_path, req_msg->uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ res_msg->status = err;
+ }
+
+ return err;
+}
+
+static int __media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+
+ thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
+
+ thumb_w = (req_msg->thumb_width > 0) ? req_msg->thumb_width : THUMB_DEFAULT_WIDTH;
+ thumb_h = (req_msg->thumb_height > 0) ? req_msg->thumb_height : THUMB_DEFAULT_HEIGHT;
+
+ res_msg->status = MS_MEDIA_ERR_NONE;
+ res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
+
+ err = __thumbnail_get_raw_data(req_msg->org_path, &thumb_w, &thumb_h, &data, &thumb_size);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_thumbnail_get_data failed - %d", err);
+ res_msg->status = err;
+ res_msg->thumb_size = 0;
+ goto ERROR;
+ }
+
+ res_msg->thumb_width = thumb_w;
+ res_msg->thumb_height = thumb_h;
+ res_msg->thumb_size = thumb_size;
+ res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
+ if (res_msg->thumb_data) {
+ memcpy(res_msg->thumb_data, data, thumb_size);
+ } else {
+ thumb_err("Allocation failed");
+ err = MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
+ERROR:
+ SAFE_FREE(data);
+
+ return err;
+}
+
+static int __thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
+{
+ int err = MS_MEDIA_ERR_NONE;
+
+ if (req_msg->msg_type == THUMB_REQUEST_RAW_DATA) {
+ err = __media_thumb_process_raw(req_msg, res_msg);
+ if (err != MS_MEDIA_ERR_NONE)
+ thumb_err("_media_thumb_process_raw is failed: %d", err);
+ } else if (req_msg->msg_type == THUMB_REQUEST_DB_INSERT) {
+ err = __media_thumb_process(req_msg, res_msg);
+ if (err != MS_MEDIA_ERR_NONE)
+ thumb_err("_media_thumb_process is failed: %d", err);
+ }
+
+ return err;
+}
+
static void __thumb_server_send_deny_message(int sockfd)
{
thumbMsg msg = {0};
@@ -87,23 +263,6 @@ ERROR:
return G_SOURCE_REMOVE;
}
-int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- if (req_msg->msg_type == THUMB_REQUEST_RAW_DATA) {
- err = _media_thumb_process_raw(req_msg, res_msg);
- if (err != MS_MEDIA_ERR_NONE)
- thumb_warn("_media_thumb_process_raw is failed: %d", err);
- } else if (req_msg->msg_type == THUMB_REQUEST_DB_INSERT) {
- err = _media_thumb_process(req_msg, res_msg);
- if (err != MS_MEDIA_ERR_NONE)
- thumb_warn("_media_thumb_process is failed: %d", err);
- }
-
- return err;
-}
-
gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
struct sockaddr_un client_addr;
@@ -157,7 +316,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
thumb_warn_slog("Received [%d] %.*s(%zu) from PID(%d)", recv_msg.msg_type, MAX_FILEPATH_LEN, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
- _thumb_daemon_process_job(&recv_msg, &res_msg);
+ __thumb_daemon_process_job(&recv_msg, &res_msg);
if (res_msg.msg_type == 0)
res_msg.msg_type = recv_msg.msg_type;
@@ -207,179 +366,3 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
return TRUE;
}
-
-int _thumbnail_get_data(const char *origin_path, char *thumb_path)
-{
- int err = MS_MEDIA_ERR_NONE;
- int file_type = THUMB_NONE_TYPE;
-
- thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
- thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
- thumb_dbg("Origin path : %s", origin_path);
-
- file_type = _media_thumb_get_file_type(origin_path);
-
- if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
- } else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
- } else {
- thumb_err("invalid file type");
- return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
- }
-
- thumb_dbg("Thumb data is generated successfully");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, unsigned char **data, int *size)
-{
- 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 (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
- thumb_err("Original path (%s) does not exist", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- 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, NULL, thumb_width, thumb_height, &thumb_info);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
- } else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
- } else {
- thumb_err("invalid file type");
- return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
- }
-
- if (size) *size = thumb_info.size;
- *data = thumb_info.data;
- *width = thumb_info.width;
- *height = thumb_info.height;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *thumb_path = NULL;
-
- thumb_retvm_if(req_msg == NULL || res_msg == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
-
- const char *origin_path = req_msg->org_path;
- memset(res_msg->dst_path, 0, MAX_FILEPATH_LEN);
- thumb_path = res_msg->dst_path;
- res_msg->status = MS_MEDIA_ERR_NONE;
-
- if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
- thumb_err("origin_path does not exist in file system.");
- res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST;
- return MS_MEDIA_ERR_FILE_NOT_EXIST;
- }
-
- err = _media_thumb_get_thumb_from_db(origin_path, thumb_path, MAX_FILEPATH_LEN, req_msg->uid);
- if (err == MS_MEDIA_ERR_NONE) {
- thumb_dbg_slog("Thumb path : %s", thumb_path);
- return MS_MEDIA_ERR_NONE;
- } else {
- if (strlen(thumb_path) == 0) {
- err = _media_thumb_get_hash_name(origin_path, thumb_path, MAX_FILEPATH_LEN, req_msg->uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_hash_name failed - %d", err);
- SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
- res_msg->status = err;
- return err;
- }
- }
- }
-
- thumb_dbg_slog("Thumb path : %s", thumb_path);
-
- err = _thumbnail_get_data(origin_path, thumb_path);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_thumbnail_get_data failed - %d", err);
- SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
- res_msg->status = err;
-
- goto DB_UPDATE;
- }
-
- res_msg->msg_type = THUMB_RESPONSE;
-
-DB_UPDATE:
- err = _media_thumb_update_db(origin_path, thumb_path, req_msg->uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_update_db failed : %d", err);
- res_msg->status = err;
- }
-
- return err;
-}
-
-int
-_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
-{
- int err = MS_MEDIA_ERR_NONE;
- unsigned char *data = NULL;
- int thumb_size = 0;
- int thumb_w = 0;
- int thumb_h = 0;
-
- thumb_retvm_if(req_msg == NULL || res_msg == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
-
- const char *origin_path = req_msg->org_path;
- if (req_msg->thumb_width > 0)
- thumb_w = req_msg->thumb_width;
- else
- thumb_w = THUMB_DEFAULT_WIDTH;
-
- if (req_msg->thumb_height > 0)
- thumb_h = req_msg->thumb_height;
- else
- thumb_h = THUMB_DEFAULT_HEIGHT;
-
- res_msg->status = MS_MEDIA_ERR_NONE;
- res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
-
- err = _thumbnail_get_raw_data(origin_path, &thumb_w, &thumb_h, &data, &thumb_size);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_thumbnail_get_data failed - %d", err);
- res_msg->status = err;
- res_msg->thumb_size = 0;
- SAFE_FREE(data);
-
- return err;
- }
-
- res_msg->thumb_width = thumb_w;
- res_msg->thumb_height = thumb_h;
- res_msg->thumb_size = thumb_size;
- res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
- if (res_msg->thumb_data != NULL) {
- memcpy(res_msg->thumb_data, data, thumb_size);
- } else {
- thumb_err("Allocation failed");
- err = MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- SAFE_FREE(data);
-
- return err;
-}