X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmedia_face.c;h=b191ca3a0aba9114bd10a0fba52332ef9b28db8a;hb=a14f941978dec0d06fa06ae3f6daccec168be1dc;hp=979a92c2d6863dd35b5c15ed61852bec84a5a9f3;hpb=6e46589e80bc6950d9a732e98b0580fec213714e;p=platform%2Fcore%2Fapi%2Fmedia-content.git diff --git a/src/media_face.c b/src/media_face.c index 979a92c..b191ca3 100755 --- a/src/media_face.c +++ b/src/media_face.c @@ -26,20 +26,20 @@ static int __media_face_check_media_id(const char *media_id) sqlite3_stmt *stmt = NULL; int item_count = 0; - media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id"); + content_retip_if_fail(STRING_VALID(media_id)); /* Get image count */ query_str = sqlite3_mprintf(SELECT_IMAGE_COUNT_FROM_MEDIA_BY_ID, media_id); - ret = _content_query_prepare(&stmt, query_str, NULL, NULL); + ret = _content_get_result(query_str, &stmt); SQLITE3_SAFE_FREE(query_str); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); if (sqlite3_step(stmt) == SQLITE_ROW) item_count = (int)sqlite3_column_int(stmt, 0); SQLITE3_FINALIZE(stmt); - media_content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); + content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); return MEDIA_CONTENT_ERROR_NONE; } @@ -48,11 +48,11 @@ int media_face_destroy(media_face_h face) { media_face_s *_face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); - SAFE_FREE(_face->media_id); - SAFE_FREE(_face->face_tag); - SAFE_FREE(_face); + g_free(_face->media_id); + g_free(_face->face_tag); + g_free(_face); return MEDIA_CONTENT_ERROR_NONE; } @@ -61,35 +61,19 @@ int media_face_clone(media_face_h *dst, media_face_h src) { media_face_s *_src = (media_face_s*)src; - media_content_retvm_if(src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid src handle"); + content_retip_if_fail(dst); + content_retip_if_fail(src); - media_face_s *_dst = (media_face_s *)calloc(1, sizeof(media_face_s)); - media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - - if (STRING_VALID(_src->media_id)) { - _dst->media_id = strdup(_src->media_id); - if (_dst->media_id == NULL) { - media_face_destroy((media_face_h)_dst); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - } + media_face_s *_dst = g_new0(media_face_s, 1); + _dst->media_id = g_strdup(_src->media_id); _dst->face_id = _src->face_id; _dst->face_rect_x = _src->face_rect_x; _dst->face_rect_y = _src->face_rect_y; _dst->face_rect_w = _src->face_rect_w; _dst->face_rect_h = _src->face_rect_h; _dst->orientation = _src->orientation; - - if (STRING_VALID(_src->face_tag)) { - _dst->face_tag = strdup(_src->face_tag); - if (_dst->face_tag == NULL) { - media_face_destroy((media_face_h)_dst); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - } + _dst->face_tag = g_strdup(_src->face_tag); *dst = (media_face_h)_dst; @@ -101,21 +85,18 @@ static void __media_face_convert_itoa(int face_id, char **face_strid) char buf[MAX_SIZE] = {0, }; snprintf(buf, MAX_SIZE, "%d", face_id); - *face_strid = strndup(buf, strlen(buf)); + *face_strid = g_strndup(buf, strlen(buf)); } int media_face_get_face_id(media_face_h face, char **face_id) { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); + content_retip_if_fail(face_id); - if (_face->face_id > 0) { + if (_face->face_id > 0) __media_face_convert_itoa(_face->face_id, face_id); - media_content_retvm_if(*face_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory"); - } else { - *face_id = NULL; - } return MEDIA_CONTENT_ERROR_NONE; } @@ -124,14 +105,10 @@ int media_face_get_media_id(media_face_h face, char **media_id) { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); + content_retip_if_fail(media_id); - if (STRING_VALID(_face->media_id)) { - *media_id = strdup(_face->media_id); - media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory"); - } else { - *media_id = NULL; - } + *media_id = g_strdup(_face->media_id); return MEDIA_CONTENT_ERROR_NONE; } @@ -140,8 +117,11 @@ int media_face_get_face_rect(media_face_h face, unsigned int *rect_x, unsigned i { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(!(rect_x && rect_y && rect_w && rect_h), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect"); + content_retip_if_fail(face); + content_retip_if_fail(rect_x); + content_retip_if_fail(rect_y); + content_retip_if_fail(rect_w); + content_retip_if_fail(rect_h); *rect_x = _face->face_rect_x; *rect_y = _face->face_rect_y; @@ -155,8 +135,8 @@ int media_face_get_orientation(media_face_h face, media_content_orientation_e *o { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(orientation == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid orientation"); + content_retip_if_fail(face); + content_retip_if_fail(orientation); *orientation = _face->orientation; @@ -167,14 +147,10 @@ int media_face_get_tag(media_face_h face, char **tag) { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); + content_retip_if_fail(tag); - if (STRING_VALID(_face->face_tag)) { - *tag = strdup(_face->face_tag); - media_content_retvm_if(*tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory"); - } else { - *tag = NULL; - } + *tag = g_strdup(_face->face_tag); return MEDIA_CONTENT_ERROR_NONE; } @@ -183,16 +159,14 @@ int media_face_create(const char *media_id, media_face_h *face) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id"); - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); ret = __media_face_check_media_id(media_id); - media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "media_id does not exist or is not an image"); + content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "media_id does not exist or is not an image"); - media_face_s* _face = calloc(1, sizeof(media_face_s)); - media_content_retvm_if(_face == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory"); + media_face_s* _face = g_new0(media_face_s, 1); - _face->media_id = strdup(media_id); + _face->media_id = g_strdup(media_id); *face = (media_face_h)_face; @@ -203,9 +177,9 @@ int media_face_set_face_rect(media_face_h face, unsigned int rect_x, unsigned in { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w"); - media_content_retvm_if(rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h"); + content_retip_if_fail(face); + content_retip_if_fail(rect_w > 0); + content_retip_if_fail(rect_h > 0); _face->face_rect_x = rect_x; _face->face_rect_y = rect_y; @@ -219,7 +193,7 @@ int media_face_set_orientation(media_face_h face, media_content_orientation_e or { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); _face->orientation = orientation; @@ -230,12 +204,10 @@ int media_face_set_tag(media_face_h face, const char *tag) { media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + content_retip_if_fail(face); - if (STRING_VALID(tag)) - _face->face_tag = strdup(tag); - else - _face->face_tag = NULL; + g_free(_face->face_tag); + _face->face_tag = g_strdup(tag); return MEDIA_CONTENT_ERROR_NONE; } @@ -248,10 +220,10 @@ int media_face_insert_to_db(media_face_h face) media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(_face->media_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); - media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w"); - media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h"); + content_retip_if_fail(face); + content_retip_if_fail(_face->media_id); + content_retip_if_fail(_face->face_rect_w > 0); + content_retip_if_fail(_face->face_rect_h > 0); query_str = sqlite3_mprintf(INSERT_FACE_TO_FACE, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag); @@ -259,9 +231,9 @@ int media_face_insert_to_db(media_face_h face) SQLITE3_SAFE_FREE(query_str); query_str = sqlite3_mprintf(SELECT_FACE_ID, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation); - ret = _content_query_prepare(&stmt, query_str, NULL, NULL); + ret = _content_get_result(query_str, &stmt); SQLITE3_SAFE_FREE(query_str); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); if (sqlite3_step(stmt) == SQLITE_ROW) _face->face_id = (int)sqlite3_column_int(stmt, 0); @@ -279,11 +251,11 @@ int media_face_update_to_db(media_face_h face) media_face_s* _face = (media_face_s*)face; - media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(_face->face_id == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid face_id"); - media_content_retvm_if(_face->media_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); - media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w"); - media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h"); + content_retip_if_fail(face); + content_retip_if_fail(_face->media_id); + content_retip_if_fail(_face->face_id > 0); + content_retip_if_fail(_face->face_rect_w > 0); + content_retip_if_fail(_face->face_rect_h > 0); query_str = sqlite3_mprintf(UPDATE_FACE_TO_FACE, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag, _face->face_id); @@ -297,15 +269,17 @@ static int __media_face_safe_atoi(const char *buffer, int *si) { char *end = NULL; errno = 0; - media_content_retvm_if(buffer == NULL || si == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid parameter"); + + content_retip_if_fail(buffer); + content_retip_if_fail(si); const long sl = strtol(buffer, &end, 10); - media_content_retvm_if(end == buffer, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "not a decimal number"); - media_content_retvm_if('\0' != *end, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "extra characters at end of input: %s", end); - media_content_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "out of range of type long"); - media_content_retvm_if(sl > INT_MAX, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "greater than INT_MAX"); - media_content_retvm_if(sl < INT_MIN, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "less than INT_MIN"); + content_retvm_if(end == buffer, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "not a decimal number"); + content_retvm_if('\0' != *end, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "extra characters at end of input: %s", end); + content_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "out of range of type long"); + content_retvm_if(sl > INT_MAX, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "greater than INT_MAX"); + content_retvm_if(sl < INT_MIN, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "less than INT_MIN"); *si = (int)sl; @@ -317,16 +291,15 @@ int media_face_delete_from_db(const char *face_id) int ret = MEDIA_CONTENT_ERROR_NONE; char *query_str = NULL; int query_face_id = 0; - media_content_retvm_if(!STRING_VALID(face_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id"); ret = __media_face_safe_atoi(face_id, &query_face_id); - media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id"); + content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id"); /*Update modified_time to 0.. It will restore the deleted face when media_info_start_face_detection() is called */ query_str = sqlite3_mprintf(UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST, query_face_id); ret = _content_query_sql(query_str); SQLITE3_SAFE_FREE(query_str); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, query_face_id); ret = _content_query_sql(query_str); @@ -337,25 +310,14 @@ int media_face_delete_from_db(const char *face_id) int media_face_get_face_count_from_db(filter_h filter, int *face_count) { - int ret = MEDIA_CONTENT_ERROR_NONE; - - if (face_count == NULL) { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - ret = _media_db_get_group_count(filter, MEDIA_GROUP_FACE, face_count); + content_retip_if_fail(face_count); - return ret; + return _media_db_get_group_count(filter, MEDIA_GROUP_FACE, face_count); } int media_face_foreach_face_from_db(filter_h filter, media_face_cb callback, void *user_data) { - int ret = MEDIA_CONTENT_ERROR_NONE; - - media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid paramter"); + content_retip_if_fail(callback); - ret = _media_db_get_face(NULL, filter, callback, user_data); - - return ret; + return _media_db_get_face(NULL, filter, callback, user_data); }