From: Ji Yong Min Date: Mon, 21 Dec 2015 10:16:41 +0000 (+0900) Subject: Optimize dcm service X-Git-Tag: submit/tizen/20151222.022300^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4f9be3a22499a2da3092240f2c6035f7ef791d2;p=platform%2Fcore%2Fmultimedia%2Fdcm-service.git Optimize dcm service - Reduce memory usage by using RGB888 image format when JPEG is decoded - Ready to enhance performance by using image resizing for big size image Change-Id: Idf442de2add6ded01ade6a2e389c3689013fc6d2 Signed-off-by: Jiyong Min --- diff --git a/include/DcmTypes.h b/include/DcmTypes.h index 904d07e..c68ab60 100755 --- a/include/DcmTypes.h +++ b/include/DcmTypes.h @@ -129,12 +129,13 @@ typedef struct { typedef enum { DCM_SVC_I420, - DCM_SVC_RGB888, + DCM_SVC_RGB, + DCM_SVC_RGBA, } DcmImageDecodeType; typedef struct { unsigned char *pixel; /* decoding results, must be freed after use */ - unsigned int size; + 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 */ diff --git a/libdcm-face/dcm-face.c b/libdcm-face/dcm-face.c index 57dda45..729fcbb 100755 --- a/libdcm-face/dcm-face.c +++ b/libdcm-face/dcm-face.c @@ -72,17 +72,7 @@ EXPORT_API int dcm_face_destroy(__in dcm_face_h handle) return ret; } -EXPORT_API int dcm_face_get_prefered_colorspace(__in dcm_face_h handle, __out face_image_colorspace_e *colorspace) -{ - dcm_retvm_if(handle == NULL, FACE_ERROR_INVALID_PARAMTER, "Invalid handle"); - dcm_retvm_if(colorspace == NULL, FACE_ERROR_INVALID_PARAMTER, "Invalid colorspace"); - - *colorspace = FACE_IMAGE_COLORSPACE_RGB888; - - return FACE_ERROR_NONE; -} - -EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned int size) +EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned long long size) { FaceHandleT *_handle = (FaceHandleT *)handle; unsigned char *data = NULL; @@ -97,6 +87,10 @@ EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_ case FACE_IMAGE_COLORSPACE_RGB888: case FACE_IMAGE_COLORSPACE_RGBA: data = (unsigned char *)calloc(1, size); + if (data == NULL) { + dcm_error("Not allocate memory"); + return FACE_ERROR_OUT_OF_MEMORY; + } memcpy(data, buffer, size); break; default: diff --git a/libdcm-face/dcm-face_mediavision.c b/libdcm-face/dcm-face_mediavision.c index b93d8c1..c181d47 100755 --- a/libdcm-face/dcm-face_mediavision.c +++ b/libdcm-face/dcm-face_mediavision.c @@ -196,7 +196,7 @@ int _face_detect_faces(__in dcm_face_h handle, __out face_rect_s *face_rect[], _ dcm_debug("face_detect image: %p, size: %d, width: %d, height: %d, color: %d", handle->image_info->data, handle->image_info->size, handle->image_info->width, handle->image_info->height, colorspace); - err = mv_source_fill_by_buffer(_fengine->source, handle->image_info->data, handle->image_info->size, handle->image_info->width, handle->image_info->height, colorspace); + err = mv_source_fill_by_buffer(_fengine->source, handle->image_info->data, (unsigned int)(handle->image_info->size), handle->image_info->width, handle->image_info->height, colorspace); if (err != MEDIA_VISION_ERROR_NONE) { dcm_error("Fail to mv_source_fill_by_buffer"); return __convert_to_mv_error_e(err); diff --git a/libdcm-face/dcm-face_priv.h b/libdcm-face/dcm-face_priv.h index 4dd6a23..797984d 100755 --- a/libdcm-face/dcm-face_priv.h +++ b/libdcm-face/dcm-face_priv.h @@ -38,7 +38,7 @@ typedef struct face_image_s { unsigned char *data; unsigned int width; unsigned int height; - unsigned int size; + unsigned long long size; face_image_colorspace_e colorspace; unsigned int magic; } FaceImage; diff --git a/libdcm-face/include/dcm-face.h b/libdcm-face/include/dcm-face.h index 9797dc3..177e960 100755 --- a/libdcm-face/include/dcm-face.h +++ b/libdcm-face/include/dcm-face.h @@ -80,7 +80,7 @@ int dcm_face_get_prefered_colorspace(dcm_face_h handle, face_image_colorspace_e * @retval #FACE_ERROR_OUT_OF_MEMORY Out of memory * @see dcm_face_create() */ -int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned int size); +int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned long long size); /** * @brief Gets the face information of detected faces. diff --git a/libdcm-util/dcm_image_codec.cpp b/libdcm-util/dcm_image_codec.cpp index 650a41a..01ffc39 100755 --- a/libdcm-util/dcm_image_codec.cpp +++ b/libdcm-util/dcm_image_codec.cpp @@ -28,8 +28,8 @@ #define MIME_TYPE_PNG "image/png" #define MIME_TYPE_BMP "image/bmp" -#define OPT_IMAGE_WIDTH 2048 -#define OPT_IMAGE_HEIGHT 1536 +#define OPT_IMAGE_WIDTH 1280 +#define OPT_IMAGE_HEIGHT 720 static void _dcm_get_optimized_wh(unsigned int src_width, unsigned int src_height, unsigned int *calc_width, unsigned int *calc_height) { @@ -52,7 +52,7 @@ static void _dcm_get_optimized_wh(unsigned int src_width, unsigned int src_heigh } } -static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, dcm_image_codec_type_e decode_type, int orientation) +static int _dcm_rotate_image(const unsigned char *source, const dcm_image_format_e format, const int orientation, unsigned char **image_buffer, unsigned long long *size, unsigned int *buff_width, unsigned int *buff_height) { int ret = IMAGE_UTIL_ERROR_NONE; image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; @@ -63,22 +63,22 @@ static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_ DCM_CHECK_VAL(source, DCM_ERROR_INVALID_PARAMETER); - if (decode_type == DCM_IMAGE_CODEC_I420) { + if (format == DCM_IMAGE_FORMAT_I420) { colorspace = IMAGE_UTIL_COLORSPACE_I420; - } else if (decode_type == DCM_IMAGE_CODEC_RGB) { + } else if (format == DCM_IMAGE_FORMAT_RGB) { colorspace = IMAGE_UTIL_COLORSPACE_RGB888; - } else if (decode_type == DCM_IMAGE_CODEC_RGBA) { + } else if (format == DCM_IMAGE_FORMAT_RGBA) { colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; } else { return DCM_ERROR_UNSUPPORTED_IMAGE_TYPE; } /* Get rotate angle enum */ - if (orientation == DEGREE_180) { // 3-180 + if (orientation == DEGREE_180) { rotate = IMAGE_UTIL_ROTATION_180; - } else if (orientation == DEGREE_90) { // 6-90 + } else if (orientation == DEGREE_90) { rotate = IMAGE_UTIL_ROTATION_90; - } else if (orientation == DEGREE_270) { // 8-270 + } else if (orientation == DEGREE_270) { rotate = IMAGE_UTIL_ROTATION_270; } else { rotate = IMAGE_UTIL_ROTATION_NONE; @@ -114,8 +114,10 @@ static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_ return DCM_ERROR_IMAGE_UTIL_FAILED; } + *size = rotated_buffer_size; + try { - /* Rotate input bitmap */ + /* Rotate input buffer */ ret = image_util_rotate(rotated_buffer, &rotated_width, &rotated_height, rotate, source, *buff_width, *buff_height, colorspace); @@ -129,7 +131,7 @@ static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_ *buff_width = rotated_width; *buff_height = rotated_height; - /* Allocated pixel should be freed when scanning is finished for this rotated bitmap */ + /* Allocated data should be freed when scanning is finished for this rotated image */ *image_buffer = rotated_buffer; dcm_warn("rotated decode buffer: %p", *image_buffer); @@ -142,17 +144,18 @@ static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_ return DCM_SUCCESS; } -int dcm_decode_image(const char *file_path, - dcm_image_codec_type_e decode_type, const char* mimne_type, bool resize, - unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, - int orientation, unsigned int *size) +int dcm_decode_image(const char *file_path, const dcm_image_format_e format, + const char* mimne_type, const int orientation, const bool resize, + unsigned char **image_buffer, unsigned long long *size, + unsigned int *buff_width, unsigned int *buff_height) { int ret = IMAGE_UTIL_ERROR_NONE; image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; + mm_util_img_format mm_format = MM_UTIL_IMG_FMT_RGBA8888; unsigned char *decode_buffer = NULL; unsigned int decode_width = 0, decode_height = 0; unsigned char *resize_buffer = NULL; - unsigned int resize_buffer_size = 0; + unsigned int buffer_size = 0; image_util_decode_h handle = NULL; dcm_debug_fenter(); @@ -165,30 +168,30 @@ int dcm_decode_image(const char *file_path, return DCM_ERROR_IMAGE_UTIL_FAILED; } - if (strcmp(mimne_type, MIME_TYPE_PNG) == 0) { - DCM_CHECK_VAL((decode_type != DCM_IMAGE_CODEC_RGBA), DCM_ERROR_UNSUPPORTED_IMAGE_TYPE); - } else if (strcmp(mimne_type, MIME_TYPE_BMP) == 0) { - DCM_CHECK_VAL((decode_type != DCM_IMAGE_CODEC_RGBA), DCM_ERROR_UNSUPPORTED_IMAGE_TYPE); - } else if (strcmp(mimne_type, MIME_TYPE_JPEG) == 0) { - if (decode_type == DCM_IMAGE_CODEC_I420) { + ret = image_util_decode_set_input_path(handle, file_path); + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_set_input_path ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; + } + + if (strcmp(mimne_type, MIME_TYPE_JPEG) == 0) { + if (format == DCM_IMAGE_FORMAT_I420) { colorspace = IMAGE_UTIL_COLORSPACE_I420; - } else if (decode_type == DCM_IMAGE_CODEC_RGB) { + mm_format = MM_UTIL_IMG_FMT_I420; + } else if (format == DCM_IMAGE_FORMAT_RGB) { colorspace = IMAGE_UTIL_COLORSPACE_RGB888; - } else if (decode_type == DCM_IMAGE_CODEC_RGBA) { + mm_format = MM_UTIL_IMG_FMT_RGB888; + } else if (format == DCM_IMAGE_FORMAT_RGBA) { colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; + mm_format = MM_UTIL_IMG_FMT_RGBA8888; } else { return DCM_ERROR_UNSUPPORTED_IMAGE_TYPE; } ret = image_util_decode_set_colorspace(handle, colorspace); - } else { - dcm_error("Failed not supported mime type! (%s)", mimne_type); - return DCM_ERROR_INVALID_PARAMETER; - } - - ret = image_util_decode_set_input_path(handle, file_path); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_set_input_path ret : %d", ret); - return DCM_ERROR_IMAGE_UTIL_FAILED; + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_set_colorspace ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; + } } ret = image_util_decode_set_output_buffer(handle, &decode_buffer); @@ -197,7 +200,7 @@ int dcm_decode_image(const char *file_path, return DCM_ERROR_IMAGE_UTIL_FAILED; } - ret = image_util_decode_run(handle, (unsigned long *)&decode_width, (unsigned long *)&decode_height, (unsigned long long *)size); + ret = image_util_decode_run(handle, (unsigned long *)&decode_width, (unsigned long *)&decode_height, size); if (ret != IMAGE_UTIL_ERROR_NONE) { dcm_error("Error image_util_decode_run ret : %d", ret); return DCM_ERROR_IMAGE_UTIL_FAILED; @@ -220,13 +223,16 @@ int dcm_decode_image(const char *file_path, /* Resize the big size image to enhance performance for big size image */ if ((decode_width != *buff_width) || (decode_height != *buff_height)) { - ret = image_util_calculate_buffer_size(*buff_width, *buff_height, colorspace, &resize_buffer_size); + ret = image_util_calculate_buffer_size(*buff_width, *buff_height, colorspace, &buffer_size); if (ret != DCM_SUCCESS) { dcm_error("Failed to calculate image buffer size! err: %d", ret); return DCM_ERROR_CODEC_DECODE_FAILED; } - resize_buffer = (unsigned char *)malloc(sizeof(unsigned char) * (resize_buffer_size)); - mm_util_resize_image(decode_buffer, decode_width, decode_height, MM_UTIL_IMG_FMT_RGBA8888, resize_buffer, buff_width, buff_height); + *size = buffer_size; + resize_buffer = (unsigned char *)malloc(sizeof(unsigned char) * (buffer_size)); + if (resize_buffer != NULL) { + mm_util_resize_image(decode_buffer, decode_width, decode_height, mm_format, resize_buffer, buff_width, buff_height); + } } else { resize_buffer = decode_buffer; } @@ -235,7 +241,7 @@ int dcm_decode_image(const char *file_path, if (orientation == 0) { *image_buffer = resize_buffer; } else { - ret = _dcm_rotate_image(resize_buffer, image_buffer, buff_width, buff_height, decode_type, orientation); + ret = _dcm_rotate_image(resize_buffer, format, orientation, image_buffer, size, buff_width, buff_height); if (ret != DCM_SUCCESS) { dcm_error("Failed to rotate image buffer! err: %d", ret); return DCM_ERROR_CODEC_DECODE_FAILED; diff --git a/libdcm-util/include/dcm_image_codec.h b/libdcm-util/include/dcm_image_codec.h index 0281a72..7a0a7e4 100755 --- a/libdcm-util/include/dcm_image_codec.h +++ b/libdcm-util/include/dcm_image_codec.h @@ -28,10 +28,10 @@ extern "C" { #endif typedef enum { - DCM_IMAGE_CODEC_I420, - DCM_IMAGE_CODEC_RGB, - DCM_IMAGE_CODEC_RGBA, -} dcm_image_codec_type_e; + DCM_IMAGE_FORMAT_I420, + DCM_IMAGE_FORMAT_RGB, + DCM_IMAGE_FORMAT_RGBA, +} dcm_image_format_e; typedef struct { int size; @@ -44,9 +44,10 @@ typedef struct { } dcm_image_info; -int dcm_decode_image(const char *file_path, dcm_image_codec_type_e decode_type, const char* mimne_type, - bool resize, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, - int orientation, unsigned int *size); +int dcm_decode_image(const char *file_path, const dcm_image_format_e format, + const char* mimne_type, const int orientation, const bool resize, + unsigned char **image_buffer, unsigned long long *size, + unsigned int *buff_width, unsigned int *buff_height); #ifdef __cplusplus } diff --git a/packaging/dcm-service.spec b/packaging/dcm-service.spec index 3c3e068..1af871c 100755 --- a/packaging/dcm-service.spec +++ b/packaging/dcm-service.spec @@ -1,6 +1,6 @@ Name: dcm-service Summary: Multimedia DCM(Digital Contents Management) Service -Version: 0.0.2 +Version: 0.0.3 Release: 0 Group: Multimedia/Service License: Apache-2.0 diff --git a/src/DcmDbUtils.cpp b/src/DcmDbUtils.cpp index 380db02..2721352 100755 --- a/src/DcmDbUtils.cpp +++ b/src/DcmDbUtils.cpp @@ -482,7 +482,7 @@ int DcmDbUtils::_dcm_svc_db_update_color_to_db(DcmColorItem color) char* query_string = NULL; dcm_debug_fenter(); - +#if 0 DCM_CHECK_VAL(db_handle, DCM_ERROR_INVALID_PARAMETER); DCM_CHECK_VAL(color.media_uuid, DCM_ERROR_INVALID_PARAMETER); DCM_CHECK_VAL(color.storage_uuid, DCM_ERROR_INVALID_PARAMETER); @@ -499,7 +499,7 @@ int DcmDbUtils::_dcm_svc_db_update_color_to_db(DcmColorItem color) g_mutex_unlock(&gMutexLock); DCM_SQLITE3_FREE(query_string); - +#endif dcm_debug_fleave(); return ret; diff --git a/src/DcmFaceUtils.cpp b/src/DcmFaceUtils.cpp index 4ff22d6..77a9f71 100755 --- a/src/DcmFaceUtils.cpp +++ b/src/DcmFaceUtils.cpp @@ -96,19 +96,9 @@ int DcmFaceUtils::runFaceRecognizeProcess(DcmScanItem *scan_item, DcmImageInfo * DCM_CHECK_VAL(image_info, DCM_ERROR_INVALID_PARAMETER); DCM_CHECK_VAL(image_info->pixel, DCM_ERROR_INVALID_PARAMETER); - /* Create image buffer used for face detection */ - face_image_colorspace_e prefered_colorspace = FACE_IMAGE_COLORSPACE_RGB888; + dcm_debug("colorspce: [%d], w: [%d], h: [%d]", image_info->decode_type, image_info->buffer_width, image_info->buffer_height); - err = dcm_face_get_prefered_colorspace(dcm_face_handle, &prefered_colorspace); - if (err != FACE_ERROR_NONE) { - dcm_error("Failed to create face_image! err: %d", err); - ret = DCM_ERROR_FACE_ENGINE_FAILED; - goto DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED; - } - - dcm_debug("colorspce: [%d], w: [%d], h: [%d]", prefered_colorspace, image_info->buffer_width, image_info->buffer_height); - - err = dcm_face_set_image_info(dcm_face_handle, prefered_colorspace, image_info->pixel, image_info->buffer_width, image_info->buffer_height, image_info->size); + err = dcm_face_set_image_info(dcm_face_handle, (face_image_colorspace_e)image_info->decode_type, image_info->pixel, image_info->buffer_width, image_info->buffer_height, image_info->size); if (err != FACE_ERROR_NONE) { dcm_error("Failed to dcm_face_set_image_info! err: %d", err); ret = DCM_ERROR_FACE_ENGINE_FAILED; diff --git a/src/DcmIpcUtils.cpp b/src/DcmIpcUtils.cpp index f90666b..f911466 100755 --- a/src/DcmIpcUtils.cpp +++ b/src/DcmIpcUtils.cpp @@ -33,7 +33,7 @@ #include #include -static char DCM_IPC_PATH[5][100] = +static char DCM_IPC_PATH[][100] = {"/var/run/media-server/dcm_ipc_scanthread_recv", "/var/run/media-server/dcm_ipc_thumbserver_comm_recv", "/var/run/media-server/media_ipc_thumbdcm_dcmrecv"}; diff --git a/src/DcmScanSvc.cpp b/src/DcmScanSvc.cpp index 62f0afe..8b9f87e 100755 --- a/src/DcmScanSvc.cpp +++ b/src/DcmScanSvc.cpp @@ -260,7 +260,7 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) DcmImageInfo image_info = {0, }; memset(&image_info, 0, sizeof(DcmImageInfo)); - dcm_image_codec_type_e image_format = DCM_IMAGE_CODEC_RGBA; + dcm_image_format_e image_format = 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) { @@ -304,31 +304,34 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) dcm_debug("ImgGetImageInfo type: %d, width: %d, height: %d", type, image_info.original_width, image_info.original_height); } - if ((strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) || - (strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) || - (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0)) { - ret = dcm_decode_image((const char *) (scan_item->file_path), - image_format, scan_item->mime_type, FALSE, &(image_info.pixel), - &(image_info.buffer_width), &(image_info.buffer_height), image_info.orientation, &(image_info.size)); - if (ret != DCM_SUCCESS) { - dcm_error("Failed dcm_decode_image! err: %d", ret); - return ret; - } + if (strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) { + image_format = DCM_IMAGE_FORMAT_RGB; + } else if (strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) { + image_format = DCM_IMAGE_FORMAT_RGBA; + } else if (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0) { + image_format = DCM_IMAGE_FORMAT_RGBA; } else { dcm_error("Failed not supported type! (%s)", scan_item->mime_type); return DCM_ERROR_INVALID_PARAMETER; } + ret = dcm_decode_image((const char *) (scan_item->file_path), image_format, scan_item->mime_type, + image_info.orientation, FALSE, &(image_info.pixel), &(image_info.size), + &(image_info.buffer_width), &(image_info.buffer_height)); + if (ret != DCM_SUCCESS) { + dcm_error("Failed dcm_decode_image! err: %d", ret); + return ret; + } + image_info.decode_type = (DcmImageDecodeType)image_format; - dcm_debug("Image info width: %d, height: %d, buf_width: %d, buf_height: %d, orientation: %d", - image_info.original_width, image_info.original_height, image_info.buffer_width, image_info.buffer_height, image_info.orientation); + 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 = DcmFaceUtils::runFaceRecognizeProcess(scan_item, &image_info); - if (ret != DCM_SUCCESS) { + if (ret != DCM_SUCCESS) dcm_error("Failed to process face detection! err: %d", ret); - } #if 0 /* Process color extract */