summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2019-09-16 11:43:26 +0900
committerMinje Ahn <minje.ahn@samsung.com>2019-09-16 14:54:10 +0900
commitae9e34e2114f65b9f2cf5af8b9297d5c45ff0673 (patch)
tree9e6c684710546a408d3d91859e216fd3445a1758 /src
parente00db9e711125bb169a49c46456ad7083cb243d2 (diff)
downloadlibmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.tar.gz
libmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.tar.bz2
libmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.zip
Code cleanup
Change-Id: I89af900ba9477a68632482e7960683949df37107 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/include/util/media-thumb-debug.h6
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c247
-rwxr-xr-xsrc/media-thumb-internal.c8
-rwxr-xr-xsrc/media-thumbnail.c50
-rwxr-xr-xsrc/util/media-thumb-db.c5
5 files changed, 135 insertions, 181 deletions
diff --git a/src/include/util/media-thumb-debug.h b/src/include/util/media-thumb-debug.h
index b88ae4f..2aa517f 100755
--- a/src/include/util/media-thumb-debug.h
+++ b/src/include/util/media-thumb-debug.h
@@ -73,10 +73,10 @@
SECURE_LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
} while (0)
-#define ERR_BUF_LENGHT 256
+#define ERR_BUF_LENGTH 256
#define thumb_stderror(fmt) do { \
- char thumb_stderror_buffer[ERR_BUF_LENGHT] = {0,}; \
- LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGHT)); \
+ char thumb_stderror_buffer[ERR_BUF_LENGTH] = {0,}; \
+ LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGTH)); \
} while (0)
#define thumb_retm_if(expr, fmt, arg...) do { \
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index ed5ecb7..64afe5a 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -63,11 +63,11 @@ typedef struct {
thumbRawUserData *userData;
} thumbRawReq;
-static int _media_thumb_send_request();
-static int _media_thumb_raw_data_send_request();
+static int __media_thumb_send_request(void);
+static int __media_thumb_raw_data_send_request(void);
-int _media_thumb_get_error()
+static int __media_thumb_get_error(void)
{
if (errno == EWOULDBLOCK) {
thumb_err("Timeout. Can't try any more");
@@ -78,173 +78,162 @@ int _media_thumb_get_error()
}
}
-void __media_thumb_pop()
+static void __media_thumb_pop(void)
{
int len = 0;
int sock = 0;
+ thumbReq *req = NULL;
- if (g_manage_queue != NULL) {
- thumbReq *req = (thumbReq *)g_queue_pop_head(g_manage_queue);
- if (req != NULL) {
- GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
- sock = g_io_channel_unix_get_fd(req->channel);
-
- g_io_channel_shutdown(req->channel, TRUE, NULL);
- g_io_channel_unref(req->channel);
- close(sock);
- if (source_id != NULL) {
- g_source_destroy(source_id);
- } else {
- thumb_err("G_SOURCE_ID is NULL");
- }
+ if (!g_manage_queue)
+ return;
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
+ req = (thumbReq *)g_queue_pop_head(g_manage_queue);
+ if (req != NULL) {
+ GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
+ sock = g_io_channel_unix_get_fd(req->channel);
+
+ g_io_channel_shutdown(req->channel, TRUE, NULL);
+ g_io_channel_unref(req->channel);
+ close(sock);
+ if (source_id) {
+ g_source_destroy(source_id);
+ } else {
+ thumb_err("G_SOURCE_ID is NULL");
}
- /* Check manage queue */
- len = g_queue_get_length(g_manage_queue);
- if (len > 0)
- _media_thumb_send_request();
+ SAFE_FREE(req->path);
+ SAFE_FREE(req->userData);
+ SAFE_FREE(req);
}
+
+ /* Check manage queue */
+ len = g_queue_get_length(g_manage_queue);
+ if (len > 0)
+ __media_thumb_send_request();
}
-int __media_thumb_cancel(unsigned int request_id)
+static int __media_thumb_cancel(unsigned int request_id)
{
int len = 0, i;
- bool flag = false;
-
- if (g_manage_queue != NULL) {
- len = g_queue_get_length(g_manage_queue);
- for (i = 0; i < len; i++) {
- thumbReq *req = NULL;
- req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
- if (req == NULL) continue;
+ thumb_retv_if(!g_manage_queue, MS_MEDIA_ERR_NONE);
- if (req->request_id == request_id) {
- if (req->isRequested == true) {
- req->isCanceled = true;
- } else {
- g_queue_pop_nth(g_manage_queue, i);
+ len = g_queue_get_length(g_manage_queue);
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
+ for (i = 0; i < len; i++) {
+ thumbReq *req = NULL;
+ req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
+ if (req == NULL) continue;
- flag = true;
+ if (req->request_id == request_id) {
+ if (req->isRequested) {
+ req->isCanceled = true;
+ } else {
+ g_queue_pop_nth(g_manage_queue, i);
- break;
+ SAFE_FREE(req->path);
+ SAFE_FREE(req->userData);
+ SAFE_FREE(req);
}
+
+ return MS_MEDIA_ERR_NONE;
}
}
- if (flag == false)
- return MS_MEDIA_ERR_INTERNAL;
-
- return MS_MEDIA_ERR_NONE;
+ return MS_MEDIA_ERR_INTERNAL;
}
-void __media_thumb_pop_raw_data()
+static void __media_thumb_pop_raw_data(void)
{
int len = 0;
int sock = 0;
+ thumbRawReq *req = NULL;
- if (g_manage_raw_queue != NULL) {
- thumbRawReq *req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
- if (req != NULL) {
- GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
- sock = g_io_channel_unix_get_fd(req->channel);
-
- g_io_channel_shutdown(req->channel, TRUE, NULL);
- g_io_channel_unref(req->channel);
- close(sock);
- if (source_id != NULL) {
- g_source_destroy(source_id);
- } else {
- thumb_err("G_SOURCE_ID is NULL");
- }
+ if (!g_manage_raw_queue)
+ return;
+
+ req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
+ if (req != NULL) {
+ GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
+ sock = g_io_channel_unix_get_fd(req->channel);
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
+ g_io_channel_shutdown(req->channel, TRUE, NULL);
+ g_io_channel_unref(req->channel);
+ close(sock);
+ if (source_id) {
+ g_source_destroy(source_id);
+ } else {
+ thumb_err("G_SOURCE_ID is NULL");
}
- /* Check manage queue */
- len = g_queue_get_length(g_manage_raw_queue);
- if (len > 0)
- _media_thumb_raw_data_send_request();
+ SAFE_FREE(req->path);
+ SAFE_FREE(req->userData);
+ SAFE_FREE(req);
}
+
+ /* Check manage queue */
+ len = g_queue_get_length(g_manage_raw_queue);
+ if (len > 0)
+ __media_thumb_raw_data_send_request();
}
-int __media_thumb_cancel_raw_data(int request_id)
+static int __media_thumb_cancel_raw_data(int request_id)
{
int len = 0, i;
- bool flag = false;
-
- if (g_manage_raw_queue != NULL) {
- len = g_queue_get_length(g_manage_raw_queue);
- for (i = 0; i < len; i++) {
- thumbRawReq *req = NULL;
- req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
- if (req == NULL) continue;
+ thumb_retv_if(!g_manage_raw_queue, MS_MEDIA_ERR_NONE);
- if (req->request_id == request_id) {
- if (req->isRequested == true) {
- req->isCanceled = true;
- } else {
- g_queue_pop_nth(g_manage_raw_queue, i);
+ len = g_queue_get_length(g_manage_raw_queue);
- SAFE_FREE(req->path);
- SAFE_FREE(req->userData);
- SAFE_FREE(req);
- }
+ for (i = 0; i < len; i++) {
+ thumbRawReq *req = NULL;
+ req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
+ if (req == NULL) continue;
- flag = true;
+ if (req->request_id == request_id) {
+ if (req->isRequested) {
+ req->isCanceled = true;
+ } else {
+ g_queue_pop_nth(g_manage_raw_queue, i);
- break;
+ SAFE_FREE(req->path);
+ SAFE_FREE(req->userData);
+ SAFE_FREE(req);
}
+
+ return MS_MEDIA_ERR_NONE;
}
}
- if (flag == false)
- return MS_MEDIA_ERR_INTERNAL;
-
- return MS_MEDIA_ERR_NONE;
-
+ return MS_MEDIA_ERR_INTERNAL;
}
-bool __media_thumb_check_cancel(void)
+static bool __media_thumb_check_cancel(void)
{
thumbReq *req = NULL;
req = (thumbReq *)g_queue_peek_head(g_manage_queue);
- if (req == NULL) {
+ if (!req)
return false;
- } else {
- if (req->isCanceled)
- return false;
- else
- return true;
- }
+
+ if (req->isCanceled)
+ return false;
+ else
+ return true;
}
-bool __media_thumb_check_cancel_for_raw(void)
+static bool __media_thumb_check_cancel_for_raw(void)
{
thumbRawReq *req = NULL;
req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
- if (req == NULL) {
+ if (!req)
return false;
- } else {
- if (req->isCanceled)
- return false;
- else
- return true;
- }
+
+ if (req->isCanceled)
+ return false;
+ else
+ return true;
}
int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
@@ -265,7 +254,7 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
thumb_stderror("recv failed");
SAFE_FREE(buf);
- return _media_thumb_get_error();
+ return __media_thumb_get_error();
}
header_size -= recv_len;
recv_pos += recv_len;
@@ -296,15 +285,13 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
if (msg->thumb_size > 0) {
remain_size = msg->thumb_size;
THUMB_MALLOC(buf, remain_size);
- if (buf == NULL) {
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ thumb_retv_if(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
while (remain_size > 0) {
if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
thumb_stderror("recv failed");
SAFE_FREE(buf);
- return _media_thumb_get_error();
+ return __media_thumb_get_error();
}
fsync(sock);
@@ -377,7 +364,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
thumb_err("_media_thumb_recv_msg failed ");
__media_thumb_pop();
- return FALSE;
+ return G_SOURCE_REMOVE;
}
if (recv_msg.status != MS_MEDIA_ERR_NONE) {
@@ -397,7 +384,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
thumb_dbg("Done");
- return FALSE;
+ return G_SOURCE_REMOVE;
}
gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
@@ -418,7 +405,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
thumb_err("_media_thumb_recv_msg failed ");
__media_thumb_pop_raw_data();
- return FALSE;
+ return G_SOURCE_REMOVE;
}
if (recv_msg.status != MS_MEDIA_ERR_NONE) {
@@ -438,10 +425,10 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
thumb_dbg("Done");
- return FALSE;
+ return G_SOURCE_REMOVE;
}
-static int _media_thumb_send_request()
+static int __media_thumb_send_request(void)
{
int err = MS_MEDIA_ERR_NONE;
int sock = -1;
@@ -450,10 +437,7 @@ static int _media_thumb_send_request()
int pid;
err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("ms_ipc_create_client_socket failed");
- return err;
- }
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
@@ -531,7 +515,7 @@ static int _media_thumb_send_request()
return err;
}
-static int _media_thumb_raw_data_send_request()
+static int __media_thumb_raw_data_send_request(void)
{
int err = MS_MEDIA_ERR_NONE;
int sock = -1;
@@ -540,10 +524,7 @@ static int _media_thumb_raw_data_send_request()
int pid;
err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("ms_ipc_create_client_socket failed");
- return err;
- }
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
@@ -647,7 +628,7 @@ int _media_thumb_request_async(int msg_type, unsigned int request_id, const char
g_queue_push_tail(g_manage_queue, (gpointer)thumb_req);
if (len == 0)
- err = _media_thumb_send_request();
+ err = __media_thumb_send_request();
return err;
}
@@ -684,7 +665,7 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req);
if (len == 0)
- err = _media_thumb_raw_data_send_request();
+ err = __media_thumb_raw_data_send_request();
return err;
}
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index 9899783..0514c6c 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -347,10 +347,10 @@ int _media_thumb_video(const char *origin_path, const char *thumb_path, int thum
err = __get_video_thumb(width, height, frame, size, rot_type, NULL, thumb_width, thumb_height, &dst_img);
if (err == MS_MEDIA_ERR_NONE) {
err = mm_image_get_image(dst_img, &width, &height, &format, &buf, &size);
- thumb_info->data = buf;
- thumb_info->size = size;
- thumb_info->width = width;
- thumb_info->height = height;
+ thumb_info->data = buf;
+ thumb_info->size = size;
+ thumb_info->width = width;
+ thumb_info->height = height;
}
mm_image_destroy_image(dst_img);
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index be1b09a..474325b 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -30,20 +30,12 @@
int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
+ ms_user_storage_type_e store_type = MS_USER_STORAGE_INTERNAL;
- if (origin_path == NULL) {
- 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) doesn't exist.", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
+ thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "No file [%s]", origin_path);
- ms_user_storage_type_e store_type = -1;
err = ms_user_get_storage_type(uid, origin_path, &store_type);
-
if ((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type);
return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -52,10 +44,8 @@ int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_
thumb_dbg_slog("Path : %s", origin_path);
thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
- if (userData == NULL) {
- thumb_err("memory allocation failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+
userData->func = (ThumbFunc)func;
userData->user_data = user_data;
@@ -75,10 +65,7 @@ int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_
int err = MS_MEDIA_ERR_NONE;
int exist = 0;
- if (origin_path == NULL || request_id == 0) {
- thumb_err("original path is NULL. Or there is an error in request_id.");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ thumb_retvm_if(!origin_path || request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "original path is NULL. Or there is an error in request_id.");
/* check the file exits actually */
exist = open(origin_path, O_RDONLY);
@@ -96,10 +83,8 @@ int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_
thumb_dbg_slog("Path : %s", origin_path);
thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData));
- if (userData == NULL) {
- thumb_err("userData malloc failed : %d", err);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+
userData->func = func;
userData->user_data = user_data;
@@ -118,28 +103,19 @@ int thumbnail_request_cancel_media(unsigned int request_id)
int err = MS_MEDIA_ERR_NONE;
err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, NULL, NULL, 0);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_async failed : %d", err);
- return MS_MEDIA_ERR_NONE;
+ return err;
}
int thumbnail_request_cancel_raw_data(int request_id)
{
int err = MS_MEDIA_ERR_NONE;
- if (request_id == 0) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ thumb_retvm_if(request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_raw_data_async failed : %d", err);
- return MS_MEDIA_ERR_NONE;
+ return err;
}
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index 6f2d604..ae76d43 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -146,10 +146,7 @@ int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid)
int _media_thumb_get_storage_id_from_db(const char *origin_path, char **storage_id, uid_t uid)
{
- int err = MS_MEDIA_ERR_NONE;
thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path");
- err = __media_thumb_get_storage_id(origin_path, uid, storage_id);
-
- return err;
+ return __media_thumb_get_storage_id(origin_path, uid, storage_id);
} \ No newline at end of file