From: Jiyong Min Date: Tue, 27 Jun 2017 09:26:47 +0000 (+0900) Subject: Code refactoring for dcm-service X-Git-Tag: submit/tizen/20170705.070223~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9df9b2d266c8cdc7a91f16618b1edc9b3a399e58;p=platform%2Fcore%2Fmultimedia%2Fdcm-service.git Code refactoring for dcm-service - Remove unused source code - Cleanup header file Change-Id: Ia562e4ea5dcc9ce953b5d7925778c71929944885 Signed-off-by: Jiyong Min --- diff --git a/include/dcm_svc_db.h b/include/dcm_svc_db.h index 91e01bd..a63e728 100755 --- a/include/dcm_svc_db.h +++ b/include/dcm_svc_db.h @@ -18,13 +18,8 @@ #ifndef _DCM_DB_UTILS_H_ #define _DCM_DB_UTILS_H_ -#include #include -#include -#include -/*#include */ -#include -#include +#include #define DCM_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) #define DCM_SQLITE3_FINALIZE(x) { if (x != NULL) { sqlite3_finalize(x); x = NULL; } } diff --git a/include/dcm_svc_debug.h b/include/dcm_svc_debug.h index 4fce682..29d7f3c 100755 --- a/include/dcm_svc_debug.h +++ b/include/dcm_svc_debug.h @@ -19,6 +19,7 @@ #define _DCM_DEBUG_UTILS_H_ #include +#include #ifdef LOG_TAG #undef LOG_TAG diff --git a/include/dcm_svc_detect_face.h b/include/dcm_svc_detect_face.h index 841a138..db605fc 100755 --- a/include/dcm_svc_detect_face.h +++ b/include/dcm_svc_detect_face.h @@ -18,11 +18,11 @@ #ifndef _DCM_SVC_FACE_H_ #define _DCM_SVC_FACE_H_ -#include +#include -int face_detect_initialize(); -int face_detect_finalize(); -int face_detect_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info); +int dcm_face_detect_initialize(); +int dcm_face_detect_finalize(); +int dcm_face_detect_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info); #endif /*_DCM_SVC_FACE_H_*/ diff --git a/include/dcm_svc_extract_color.h b/include/dcm_svc_extract_color.h index e06aede..f33b674 100755 --- a/include/dcm_svc_extract_color.h +++ b/include/dcm_svc_extract_color.h @@ -18,9 +18,9 @@ #ifndef _DCM_SVC_COLOR_H_ #define _DCM_SVC_COLOR_H_ -#include +#include -int color_extract_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info); +int dcm_color_extract_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info); #endif /*_DCM_SVC_COLOR_H_*/ diff --git a/include/dcm_svc_internal.h b/include/dcm_svc_internal.h index b9d89c5..2a73af2 100755 --- a/include/dcm_svc_internal.h +++ b/include/dcm_svc_internal.h @@ -19,6 +19,7 @@ #define _DCM_SCAN_SVC_H_ #include +#include typedef struct { GMainLoop *main_loop; @@ -37,6 +38,36 @@ typedef struct { uid_t g_uid; } dcm_scan_s; +typedef enum { + DCM_SCAN_ITEM_TYPE_NONE, + DCM_SCAN_ITEM_TYPE_SCAN_ALL, + DCM_SCAN_ITEM_TYPE_SCAN_SINGLE, + DCM_SCAN_ITEM_TYPE_MAX, +} dcm_svc_type_e; + +typedef struct { + char *media_uuid; + char *file_path; + char *storage_uuid; + int image_width; + int image_height; + int image_orientation; + char *mime_type; + int face_count; + dcm_svc_type_e scan_item_type; +} dcm_svc_item_s; + +typedef struct { + unsigned char *pixel; /* decoding results, must be freed after use */ + unsigned long long size; + int orientation; /* orientation information extracted from exif */ + unsigned int original_width; /* original image width */ + unsigned int original_height; /* original image height */ + unsigned int buffer_width; /* scaled image width used by decoder (width/height ratio should be the same as original) */ + unsigned int buffer_height; /* scaled image height used by decoder (width/height ratio should be the same as original) */ + dcm_image_format_e decode_type; /* decoding pre-condition */ +} dcm_image_info_s; + gboolean dcm_scan_thread(void *data); int dcm_scan_single(const char *file_path, uid_t uid, int *face_count); diff --git a/include/dcm_svc_ipc.h b/include/dcm_svc_ipc.h index e8606bd..a748c3d 100755 --- a/include/dcm_svc_ipc.h +++ b/include/dcm_svc_ipc.h @@ -18,11 +18,19 @@ #ifndef _DCM_SVC_IPC_H_ #define _DCM_SVC_IPC_H_ -#include +#include #include +#define DCM_IPC_MSG_MAX_SIZE 4096 #define DCM_TIMEOUT_SEC_60 60 /**< Response to media server time out */ +typedef enum { + DCM_IPC_PORT_SCAN_RECV = 0, + DCM_IPC_PORT_DCM_RECV, + DCM_IPC_PORT_MS_RECV, + DCM_IPC_PORT_MAX, +} dcm_ipc_port_e; + int dcm_ipc_create_socket(int *socket_fd, dcm_ipc_port_e port); int dcm_ipc_accept_socket(int serv_sock, int *client_sock); int dcm_ipc_receive_message(int client_sock, dcmMsg *recv_msg); diff --git a/include/dcm_svc_main.h b/include/dcm_svc_main.h index 26aa670..f63bc14 100755 --- a/include/dcm_svc_main.h +++ b/include/dcm_svc_main.h @@ -19,8 +19,6 @@ #define _DCM_MAIN_SVC_H_ #include -#include -#include #ifndef EXPORT_API #define EXPORT_API __attribute__ ((visibility("default"))) diff --git a/include/dcm_svc_type.h b/include/dcm_svc_type.h deleted file mode 100755 index 4189971..0000000 --- a/include/dcm_svc_type.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _DCM_TYPES_H_ -#define _DCM_TYPES_H_ - -#include -#include - -/* - * Definitions defined here can be used by all threads - * If a definition can only be used in a specific thread, then this definition should be defined in that thread, not here. - */ - -#define DCM_MAX_PATH_SIZE 4096 -#define DCM_IPC_MSG_MAX_SIZE 4096 -#define DCM_DB_QUERY_MAX_SIZE 4096 - -typedef enum { - DCM_IPC_PORT_SCAN_RECV = 0, - DCM_IPC_PORT_DCM_RECV, - DCM_IPC_PORT_MS_RECV, - DCM_IPC_PORT_MAX, -} dcm_ipc_port_e; - -typedef enum { - DCM_SCAN_ITEM_TYPE_NONE, - DCM_SCAN_ITEM_TYPE_SCAN_ALL, - DCM_SCAN_ITEM_TYPE_SCAN_SINGLE, - DCM_SCAN_ITEM_TYPE_MAX, -} dcm_svc_type_e; - -typedef enum { - DCM_SVC_I420, - DCM_SVC_RGB, - DCM_SVC_RGBA, -} dcm_image_type_e; - -typedef struct { - char *media_uuid; - char *file_path; - char *storage_uuid; - int image_width; - int image_height; - int image_orientation; - char *mime_type; - int face_count; - dcm_svc_type_e scan_item_type; -} dcm_svc_item_s; - -typedef struct { - unsigned char *pixel; /* decoding results, must be freed after use */ - unsigned long long size; - int orientation; /* orientation information extracted from exif */ - unsigned int original_width; /* original image width */ - unsigned int original_height; /* original image height */ - unsigned int buffer_width; /* scaled image width used by decoder (width/height ratio should be the same as original) */ - unsigned int buffer_height; /* scaled image height used by decoder (width/height ratio should be the same as original) */ - dcm_image_type_e decode_type; /* decoding pre-condition */ -} dcm_image_info_s; - -#endif /* _DCM_TYPES_H_ */ - diff --git a/libdcm-face/dcm-face-debug.h b/libdcm-face/dcm-face-debug.h index fe3c4c4..7a21467 100755 --- a/libdcm-face/dcm-face-debug.h +++ b/libdcm-face/dcm-face-debug.h @@ -17,6 +17,7 @@ #define __FACE_DEBUG_H__ #include +#include #ifdef LOG_TAG #undef LOG_TAG diff --git a/libdcm-face/include/dcm-face.h b/libdcm-face/include/dcm-face.h index 2a250e6..b411ba5 100755 --- a/libdcm-face/include/dcm-face.h +++ b/libdcm-face/include/dcm-face.h @@ -18,7 +18,6 @@ #include #include "dcm-face_type.h" -#include #ifdef __cplusplus extern "C" { diff --git a/libdcm-util/dcm_image_codec.c b/libdcm-util/dcm_image_codec.c index 804bf5c..4bbd0db 100755 --- a/libdcm-util/dcm_image_codec.c +++ b/libdcm-util/dcm_image_codec.c @@ -15,20 +15,13 @@ * */ -#include -#include + #include #include #include #include -#include +#include #include -#include -#include - -#define MIME_TYPE_JPEG "image/jpeg" -#define MIME_TYPE_PNG "image/png" -#define MIME_TYPE_BMP "image/bmp" #define OPT_IMAGE_WIDTH 1280 #define OPT_IMAGE_HEIGHT 720 diff --git a/libdcm-util/include/dcm_image_codec.h b/libdcm-util/include/dcm_image_codec.h index 22d8129..f262046 100755 --- a/libdcm-util/include/dcm_image_codec.h +++ b/libdcm-util/include/dcm_image_codec.h @@ -18,11 +18,17 @@ #ifndef _DCM_IMAGE_CODEC_H_ #define _DCM_IMAGE_CODEC_H_ +#include + #define DEGREE_0 0 #define DEGREE_90 1 #define DEGREE_180 2 #define DEGREE_270 3 +#define MIME_TYPE_JPEG "image/jpeg" +#define MIME_TYPE_PNG "image/png" +#define MIME_TYPE_BMP "image/bmp" + #ifdef __cplusplus extern "C" { #endif @@ -33,17 +39,6 @@ typedef enum { DCM_IMAGE_FORMAT_RGBA, } dcm_image_format_e; -typedef struct { - int size; - int width; - int height; - int origin_width; - int origin_height; - int alpha; - unsigned char *data; -} dcm_image_info; - - int dcm_decode_image(const char *file_path, const dcm_image_format_e format, const char* mimne_type, const int orientation, const gboolean resize, unsigned char **image_buffer, unsigned long long *size, diff --git a/libdcm-util/include/dcm_image_codec_debug.h b/libdcm-util/include/dcm_image_codec_debug.h new file mode 100755 index 0000000..4b295ed --- /dev/null +++ b/libdcm-util/include/dcm_image_codec_debug.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _DCM_DEBUG_UTILS_H_ +#define _DCM_DEBUG_UTILS_H_ + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "DCM_IMAGE_CODEC" + +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" +#define FONT_COLOR_GREEN "\033[32m" +#define FONT_COLOR_YELLOW "\033[33m" +#define FONT_COLOR_BLUE "\033[34m" +#define FONT_COLOR_PURPLE "\033[35m" +#define FONT_COLOR_CYAN "\033[36m" +#define FONT_COLOR_GRAY "\033[37m" + +#define dcm_debug(fmt, arg...) do { \ + LOGD(FONT_COLOR_CYAN"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_info(fmt, arg...) do { \ + LOGI(FONT_COLOR_YELLOW"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_warn(fmt, arg...) do { \ + LOGW(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_error(fmt, arg...) do { \ + LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_sec_debug(fmt, arg...) do { \ + SECURE_LOGD(FONT_COLOR_CYAN"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_sec_info(fmt, arg...) do { \ + SECURE_LOGI(FONT_COLOR_YELLOW"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_sec_warn(fmt, arg...) do { \ + SECURE_LOGW(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \ + } while (0) + +#define dcm_sec_error(fmt, arg...) do { \ + SECURE_LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET , ##arg); \ + } while (0) + +#define dcm_debug_fenter() do { \ + LOGD(FONT_COLOR_RESET""); \ + } while (0) + +#define dcm_debug_fleave() do { \ + LOGD(FONT_COLOR_RESET""); \ + } while (0) + +#define dcm_retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + dcm_error(fmt, ##arg); \ + dcm_error("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) + +#define DCM_CHECK_VAL(expr, val) dcm_retvm_if(!(expr), val , "Invalid parameter, return ERROR code!") + +#define DCM_SAFE_FREE(ptr) { if (ptr) {free(ptr); ptr = NULL; } } + +#endif /* _DCM_DEBUG_UTILS_H_ */ diff --git a/libdcm-util/include/dcm_image_debug_utils.h b/libdcm-util/include/dcm_image_debug_utils.h deleted file mode 100755 index 6926c40..0000000 --- a/libdcm-util/include/dcm_image_debug_utils.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _DCM_DEBUG_UTILS_H_ -#define _DCM_DEBUG_UTILS_H_ - -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "DCM_IMAGE_CODEC" - -#define FONT_COLOR_RESET "\033[0m" -#define FONT_COLOR_RED "\033[31m" -#define FONT_COLOR_GREEN "\033[32m" -#define FONT_COLOR_YELLOW "\033[33m" -#define FONT_COLOR_BLUE "\033[34m" -#define FONT_COLOR_PURPLE "\033[35m" -#define FONT_COLOR_CYAN "\033[36m" -#define FONT_COLOR_GRAY "\033[37m" - -#define dcm_debug(fmt, arg...) do { \ - LOGD(FONT_COLOR_CYAN"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_info(fmt, arg...) do { \ - LOGI(FONT_COLOR_YELLOW"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_warn(fmt, arg...) do { \ - LOGW(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_error(fmt, arg...) do { \ - LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_sec_debug(fmt, arg...) do { \ - SECURE_LOGD(FONT_COLOR_CYAN"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_sec_info(fmt, arg...) do { \ - SECURE_LOGI(FONT_COLOR_YELLOW"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_sec_warn(fmt, arg...) do { \ - SECURE_LOGW(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \ - } while (0) - -#define dcm_sec_error(fmt, arg...) do { \ - SECURE_LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET , ##arg); \ - } while (0) - -#define dcm_debug_fenter() do { \ - LOGD(FONT_COLOR_RESET""); \ - } while (0) - -#define dcm_debug_fleave() do { \ - LOGD(FONT_COLOR_RESET""); \ - } while (0) - -#define dcm_retm_if(expr, fmt, arg...) do { \ - if (expr) { \ - dcm_error(fmt, ##arg); \ - dcm_error("(%s) -> %s() return", #expr, __FUNCTION__); \ - return; \ - } \ - } while (0) - -#define dcm_retvm_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - dcm_error(fmt, ##arg); \ - dcm_error("(%s) -> %s() return", #expr, __FUNCTION__); \ - return (val); \ - } \ - } while (0) - -#define ERR_BUF_LENGHT 256 -#define dcm_stderror(fmt) do { \ - char dcm_stderror_buf[ERR_BUF_LENGHT] = {0, }; \ - LOGE(fmt" : standard error= [%s]", strerror_r(errno, dcm_stderror_buf, ERR_BUF_LENGHT)); \ - } while (0) - -#define DCM_CHECK_VAL(expr, val) dcm_retvm_if(!(expr), val , "Invalid parameter, return ERROR code!") -#define DCM_CHECK_NULL(expr) dcm_retvm_if(!(expr), NULL, "Invalid parameter, return NULL!") -#define DCM_CHECK_FALSE(expr) dcm_retvm_if(!(expr), FALSE, "Invalid parameter, return FALSE!") -#define DCM_CHECK(expr) dcm_retm_if(!(expr), "Invalid parameter, return!") - -#define DCM_SAFE_FREE(ptr) { if (ptr) {free(ptr); ptr = NULL; } } - -#endif /* _DCM_DEBUG_UTILS_H_ */ diff --git a/packaging/dcm-service.spec b/packaging/dcm-service.spec index dfd3d68..45d377b 100755 --- a/packaging/dcm-service.spec +++ b/packaging/dcm-service.spec @@ -1,6 +1,6 @@ Name: dcm-service Summary: A media DCM(Digital Contents Management) Service -Version: 0.1.0 +Version: 0.1.1 Release: 0 Group: Multimedia/Service License: Apache-2.0 @@ -52,7 +52,6 @@ make %{?jobs:-j%jobs} #export CFLAGS+=" -Wwrite-strings -Wswitch-default" %install -rm -rf %{buildroot} %make_install %post -p /sbin/ldconfig diff --git a/src/dcm_svc_db.c b/src/dcm_svc_db.c index 5fcc4c3..4cc2f1f 100755 --- a/src/dcm_svc_db.c +++ b/src/dcm_svc_db.c @@ -17,15 +17,12 @@ #include #include -#include #include #include -#include -#include -#include #include -#include "dcm_svc_debug.h" +#include +#include static GMutex gMutexLock; static MediaDBHandle *db_handle; diff --git a/src/dcm_svc_detect_face.c b/src/dcm_svc_detect_face.c index 4496cb9..77ed35b 100755 --- a/src/dcm_svc_detect_face.c +++ b/src/dcm_svc_detect_face.c @@ -15,21 +15,12 @@ * */ -#include -#include #include -#include -#include #include -#include -#include -#include #include -#include #include -#include #include -#include "dcm_svc_detect_face.h" +#include static dcm_face_h dcm_face_handle = NULL; @@ -83,7 +74,7 @@ void _destroy_face_item(void *data) return; } -int face_detect_initialize() +int dcm_face_detect_initialize() { int ret = MS_MEDIA_ERR_NONE; @@ -96,7 +87,7 @@ int face_detect_initialize() return ret; } -int face_detect_finalize() +int dcm_face_detect_finalize() { int ret = MS_MEDIA_ERR_NONE; @@ -113,7 +104,7 @@ int face_detect_finalize() return ret; } -int face_detect_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info) +int dcm_face_detect_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info) { dcm_face_item_s *face = NULL; int face_area = 0; diff --git a/src/dcm_svc_extract_color.c b/src/dcm_svc_extract_color.c index 31c17c6..eab32c7 100755 --- a/src/dcm_svc_extract_color.c +++ b/src/dcm_svc_extract_color.c @@ -16,18 +16,13 @@ */ #include -#include -#include #include -#include #include -#include #include -#include -#include "dcm_svc_debug.h" -#include "dcm_svc_extract_color.h" +#include +#include -int color_extract_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info) +int dcm_color_extract_process(dcm_svc_item_s *scan_item, dcm_image_info_s *image_info) { DCM_CHECK_VAL(scan_item, MS_MEDIA_ERR_INVALID_PARAMETER); DCM_CHECK_VAL(image_info, MS_MEDIA_ERR_INVALID_PARAMETER); diff --git a/src/dcm_svc_internal.c b/src/dcm_svc_internal.c index 46fe605..c2e2ce7 100755 --- a/src/dcm_svc_internal.c +++ b/src/dcm_svc_internal.c @@ -15,29 +15,20 @@ * */ -#include #include #include #include -#include -#include #include #include -#include "../libdcm-util/include/dcm_image_codec.h" #include -#include #include #include #include -#include "dcm_svc_debug.h" -#include "dcm_svc_extract_color.h" -#include "dcm_svc_detect_face.h" - -#define MIME_TYPE_JPEG "image/jpeg" -#define MIME_TYPE_PNG "image/png" -#define MIME_TYPE_BMP "image/bmp" +#include +#include +#include #define DCM_SVC_SCAN_THREAD_TIMEOUT_SEC 1 @@ -274,7 +265,7 @@ int _dcm_scan_process(dcm_svc_item_s *scan_item) dcm_image_info_s image_info = {0, }; memset(&image_info, 0, sizeof(dcm_image_info_s)); - dcm_image_format_e image_format = DCM_IMAGE_FORMAT_I420; + image_info.decode_type = DCM_IMAGE_FORMAT_I420; /* Process scan operation if the file exists */ if (g_file_test(scan_item->file_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) == TRUE) { @@ -319,16 +310,16 @@ int _dcm_scan_process(dcm_svc_item_s *scan_item) } if (strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) { - image_format = DCM_IMAGE_FORMAT_RGB; + image_info.decode_type = DCM_IMAGE_FORMAT_RGB; } else if ((strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) || (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0)) { - image_format = DCM_IMAGE_FORMAT_RGBA; + image_info.decode_type = DCM_IMAGE_FORMAT_RGBA; } else { dcm_error("Failed not supported type! (%s)", scan_item->mime_type); return MS_MEDIA_ERR_INVALID_PARAMETER; } - ret = dcm_decode_image((const char *) (scan_item->file_path), image_format, scan_item->mime_type, + ret = dcm_decode_image((const char *) (scan_item->file_path), image_info.decode_type, scan_item->mime_type, image_info.orientation, FALSE, &(image_info.pixel), &(image_info.size), &(image_info.buffer_width), &(image_info.buffer_height)); if (ret != MS_MEDIA_ERR_NONE) { @@ -336,19 +327,17 @@ int _dcm_scan_process(dcm_svc_item_s *scan_item) return ret; } - image_info.decode_type = (dcm_image_type_e)image_format; - dcm_debug("Image info width: %d, height: %d, buf_width: %d, buf_height: %d", image_info.original_width, image_info.original_height, image_info.buffer_width, image_info.buffer_height); /* Process face scan */ - ret = face_detect_process(scan_item, &image_info); + ret = dcm_face_detect_process(scan_item, &image_info); if (ret != MS_MEDIA_ERR_NONE) dcm_error("Failed to process face detection! err: %d", ret); #if 0 /* Process color extract */ - ret = color_extract_process(scan_item, &image_info); + ret = dcm_color_extract_process(scan_item, &image_info); if (ret != MS_MEDIA_ERR_NONE) dcm_error("Failed to process color extraction! err: %d", ret); #endif @@ -494,7 +483,7 @@ int dcm_scan_init(gpointer data) _data->g_scan_cancel = FALSE; _data->kill_timer_source = NULL; - face_detect_initialize(); + dcm_face_detect_initialize(); return MS_MEDIA_ERR_NONE; } @@ -506,7 +495,7 @@ int dcm_scan_finalize(gpointer data) _dcm_scan_clear_all_items(data); _dcm_scan_clear_single_item(data); - face_detect_finalize(); + dcm_face_detect_finalize(); if (_data != NULL) free(_data); @@ -580,8 +569,7 @@ gboolean dcm_scan_read_request(GIOChannel *src, GIOCondition condition, gpointer } DCM_SVC_SCAN_READ_THREAD_RECV_SOCKET_FAILED: - if (close(client_sock) < 0) - dcm_stderror("close failed"); + dcm_ipc_close_socket(client_sock); return TRUE; } @@ -736,7 +724,7 @@ gboolean dcm_scan_thread(void *data) g_io_channel_unref(channel); /* Close the TCP socket */ - close(socket_fd); + dcm_ipc_close_socket(socket_fd); /* Descrease the reference count of main loop of scan thread */ g_main_loop_unref(dcm_scan_data->main_loop); diff --git a/src/dcm_svc_ipc.c b/src/dcm_svc_ipc.c index 8bfd26f..efd4151 100755 --- a/src/dcm_svc_ipc.c +++ b/src/dcm_svc_ipc.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -28,9 +27,7 @@ #include #include -#include #include -#include static char DCM_IPC_PATH[][100] = { {"/var/run/media-server/dcm_ipc_scanthread.socket"}, @@ -330,6 +327,10 @@ int dcm_ipc_send_complete(ms_dcm_msg_type_e msg_type, const unsigned int count, int dcm_ipc_close_socket(int socket_fd) { + if (socket_fd < 0) { + dcm_error("The socket has been closed already."); + return MS_MEDIA_ERR_NONE; + } close(socket_fd); return MS_MEDIA_ERR_NONE; diff --git a/svc/dcm_svc_main.c b/svc/dcm_svc_main.c index b6e15f0..9ad25b4 100755 --- a/svc/dcm_svc_main.c +++ b/svc/dcm_svc_main.c @@ -16,19 +16,13 @@ */ #include -#include -#include #include #include -#include #include #include #include -#include #include #include -#include - #define DCM_SVC_MAIN_THREAD_TIMEOUT_SEC 1 @@ -167,8 +161,7 @@ static void dcm_service_start(gpointer data) static void dcm_service_finish(gpointer data) { dcm_service_s *_data = (dcm_service_s *)data; - if (_data != NULL) - free(_data); + DCM_SAFE_FREE(_data); } gboolean dcm_service_recieve_request(GIOChannel *src, GIOCondition condition, gpointer data) @@ -235,8 +228,7 @@ gboolean dcm_service_recieve_request(GIOChannel *src, GIOCondition condition, gp dcm_debug("createDcmSvcReadSocket, invalid message(%d).", recv_msg.msg_type); } - if (dcm_ipc_close_socket(client_sock) < 0) - dcm_stderror("close failed"); + dcm_ipc_close_socket(client_sock); return TRUE; } @@ -287,7 +279,7 @@ EXPORT_API int main(int argc, char *argv[]) g_io_channel_shutdown(channel, FALSE, NULL); g_io_channel_unref(channel); - close(sockfd); + dcm_ipc_close_socket(sockfd); g_main_loop_unref(dcm_svc_data->main_loop); dcm_service_finish(dcm_svc_data);