2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <media_info_private.h>
22 static int __media_face_check_media_id(const char *media_id)
24 int ret = MEDIA_CONTENT_ERROR_NONE;
25 char *query_str = NULL;
26 sqlite3_stmt *stmt = NULL;
29 content_retip_if_fail(STRING_VALID(media_id));
32 query_str = sqlite3_mprintf(SELECT_IMAGE_COUNT_FROM_MEDIA_BY_ID, media_id);
33 ret = _content_get_result(query_str, &stmt);
34 sqlite3_free(query_str);
35 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
37 if (sqlite3_step(stmt) == SQLITE_ROW)
38 item_count = (int)sqlite3_column_int(stmt, 0);
40 sqlite3_finalize(stmt);
42 content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
44 return MEDIA_CONTENT_ERROR_NONE;
47 int media_face_destroy(media_face_h face)
49 content_warn("DEPRECATION WARNING: media_face_destroy() is deprecated and will be removed from next release.");
50 media_face_s *_face = (media_face_s*)face;
52 content_retip_if_fail(face);
54 g_free(_face->media_id);
55 g_free(_face->face_tag);
58 return MEDIA_CONTENT_ERROR_NONE;
61 int media_face_clone(media_face_h *dst, media_face_h src)
63 content_warn("DEPRECATION WARNING: media_face_clone() is deprecated and will be removed from next release.");
64 media_face_s *_src = (media_face_s*)src;
66 content_retip_if_fail(dst);
67 content_retip_if_fail(src);
69 media_face_s *_dst = g_new0(media_face_s, 1);
71 _dst->media_id = g_strdup(_src->media_id);
72 _dst->face_id = _src->face_id;
73 _dst->face_rect_x = _src->face_rect_x;
74 _dst->face_rect_y = _src->face_rect_y;
75 _dst->face_rect_w = _src->face_rect_w;
76 _dst->face_rect_h = _src->face_rect_h;
77 _dst->orientation = _src->orientation;
78 _dst->face_tag = g_strdup(_src->face_tag);
80 *dst = (media_face_h)_dst;
82 return MEDIA_CONTENT_ERROR_NONE;
85 static void __media_face_convert_itoa(int face_id, char **face_strid)
87 char buf[MAX_SIZE] = {0, };
89 snprintf(buf, MAX_SIZE, "%d", face_id);
90 *face_strid = g_strndup(buf, strlen(buf));
93 int media_face_get_face_id(media_face_h face, char **face_id)
95 content_warn("DEPRECATION WARNING: media_face_get_face_id() is deprecated and will be removed from next release.");
96 media_face_s* _face = (media_face_s*)face;
98 content_retip_if_fail(face);
99 content_retip_if_fail(face_id);
101 if (_face->face_id > 0)
102 __media_face_convert_itoa(_face->face_id, face_id);
104 return MEDIA_CONTENT_ERROR_NONE;
107 int media_face_get_media_id(media_face_h face, char **media_id)
109 content_warn("DEPRECATION WARNING: media_face_get_media_id() is deprecated and will be removed from next release.");
110 media_face_s* _face = (media_face_s*)face;
112 content_retip_if_fail(face);
113 content_retip_if_fail(media_id);
115 *media_id = g_strdup(_face->media_id);
117 return MEDIA_CONTENT_ERROR_NONE;
120 int media_face_get_face_rect(media_face_h face, unsigned int *rect_x, unsigned int *rect_y, unsigned int *rect_w, unsigned int *rect_h)
122 content_warn("DEPRECATION WARNING: media_face_get_face_rect() is deprecated and will be removed from next release.");
123 media_face_s* _face = (media_face_s*)face;
125 content_retip_if_fail(face);
126 content_retip_if_fail(rect_x);
127 content_retip_if_fail(rect_y);
128 content_retip_if_fail(rect_w);
129 content_retip_if_fail(rect_h);
131 *rect_x = _face->face_rect_x;
132 *rect_y = _face->face_rect_y;
133 *rect_w = _face->face_rect_w;
134 *rect_h = _face->face_rect_h;
136 return MEDIA_CONTENT_ERROR_NONE;
139 int media_face_get_orientation(media_face_h face, media_content_orientation_e *orientation)
141 content_warn("DEPRECATION WARNING: media_face_get_orientation() is deprecated and will be removed from next release.");
142 media_face_s* _face = (media_face_s*)face;
144 content_retip_if_fail(face);
145 content_retip_if_fail(orientation);
147 *orientation = _face->orientation;
149 return MEDIA_CONTENT_ERROR_NONE;
152 int media_face_get_tag(media_face_h face, char **tag)
154 content_warn("DEPRECATION WARNING: media_face_get_tag() is deprecated and will be removed from next release.");
155 media_face_s* _face = (media_face_s*)face;
157 content_retip_if_fail(face);
158 content_retip_if_fail(tag);
160 *tag = g_strdup(_face->face_tag);
162 return MEDIA_CONTENT_ERROR_NONE;
165 int media_face_create(const char *media_id, media_face_h *face)
167 content_warn("DEPRECATION WARNING: media_face_create() is deprecated and will be removed from next release.");
168 int ret = MEDIA_CONTENT_ERROR_NONE;
170 content_retip_if_fail(face);
172 ret = __media_face_check_media_id(media_id);
173 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "media_id does not exist or is not an image");
175 media_face_s* _face = g_new0(media_face_s, 1);
177 _face->media_id = g_strdup(media_id);
179 *face = (media_face_h)_face;
181 return MEDIA_CONTENT_ERROR_NONE;
184 int media_face_set_face_rect(media_face_h face, unsigned int rect_x, unsigned int rect_y, unsigned int rect_w, unsigned int rect_h)
186 content_warn("DEPRECATION WARNING: media_face_set_face_rect() is deprecated and will be removed from next release.");
187 media_face_s* _face = (media_face_s*)face;
189 content_retip_if_fail(face);
190 content_retip_if_fail(rect_w > 0);
191 content_retip_if_fail(rect_h > 0);
193 _face->face_rect_x = rect_x;
194 _face->face_rect_y = rect_y;
195 _face->face_rect_w = rect_w;
196 _face->face_rect_h = rect_h;
198 return MEDIA_CONTENT_ERROR_NONE;
201 int media_face_set_orientation(media_face_h face, media_content_orientation_e orientation)
203 content_warn("DEPRECATION WARNING: media_face_set_orientation() is deprecated and will be removed from next release.");
204 media_face_s* _face = (media_face_s*)face;
206 content_retip_if_fail(face);
208 _face->orientation = orientation;
210 return MEDIA_CONTENT_ERROR_NONE;
213 int media_face_set_tag(media_face_h face, const char *tag)
215 content_warn("DEPRECATION WARNING: media_face_set_tag() is deprecated and will be removed from next release.");
216 media_face_s* _face = (media_face_s*)face;
218 content_retip_if_fail(face);
220 g_free(_face->face_tag);
221 _face->face_tag = g_strdup(tag);
223 return MEDIA_CONTENT_ERROR_NONE;
226 int media_face_insert_to_db(media_face_h face)
228 content_warn("DEPRECATION WARNING: media_face_insert_to_db() is deprecated and will be removed from next release.");
229 int ret = MEDIA_CONTENT_ERROR_NONE;
230 char *query_str = NULL;
231 sqlite3_stmt *stmt = NULL;
233 media_face_s* _face = (media_face_s*)face;
235 content_retip_if_fail(face);
236 content_retip_if_fail(_face->media_id);
237 content_retip_if_fail(_face->face_rect_w > 0);
238 content_retip_if_fail(_face->face_rect_h > 0);
240 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);
242 ret = _content_query_sql(query_str);
243 sqlite3_free(query_str);
245 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);
246 ret = _content_get_result(query_str, &stmt);
247 sqlite3_free(query_str);
248 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
250 if (sqlite3_step(stmt) == SQLITE_ROW)
251 _face->face_id = (int)sqlite3_column_int(stmt, 0);
253 sqlite3_finalize(stmt);
259 int media_face_update_to_db(media_face_h face)
261 content_warn("DEPRECATION WARNING: media_face_update_to_db() is deprecated and will be removed from next release.");
262 int ret = MEDIA_CONTENT_ERROR_NONE;
263 char *query_str = NULL;
265 media_face_s* _face = (media_face_s*)face;
267 content_retip_if_fail(face);
268 content_retip_if_fail(_face->media_id);
269 content_retip_if_fail(_face->face_id > 0);
270 content_retip_if_fail(_face->face_rect_w > 0);
271 content_retip_if_fail(_face->face_rect_h > 0);
273 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);
275 ret = _content_query_sql(query_str);
276 sqlite3_free(query_str);
281 static int __media_face_safe_atoi(const char *buffer, int *si)
286 content_retip_if_fail(buffer);
287 content_retip_if_fail(si);
289 const long sl = strtol(buffer, &end, 10);
291 content_retvm_if(end == buffer, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "not a decimal number");
292 content_retvm_if('\0' != *end, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "extra characters at end of input: %s", end);
293 content_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "out of range of type long");
294 content_retvm_if(sl > INT_MAX, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "greater than INT_MAX");
295 content_retvm_if(sl < INT_MIN, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "less than INT_MIN");
299 return MEDIA_CONTENT_ERROR_NONE;
302 int media_face_delete_from_db(const char *face_id)
304 content_warn("DEPRECATION WARNING: media_face_delete_from_db() is deprecated and will be removed from next release.");
305 int ret = MEDIA_CONTENT_ERROR_NONE;
306 char *query_str = NULL;
307 int query_face_id = 0;
309 ret = __media_face_safe_atoi(face_id, &query_face_id);
310 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id");
312 /*Update modified_time to 0.. It will restore the deleted face when media_info_start_face_detection() is called */
313 query_str = sqlite3_mprintf(UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST, query_face_id);
314 ret = _content_query_sql(query_str);
315 sqlite3_free(query_str);
316 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
318 query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, query_face_id);
319 ret = _content_query_sql(query_str);
320 sqlite3_free(query_str);
325 int media_face_get_face_count_from_db(filter_h filter, int *face_count)
327 content_warn("DEPRECATION WARNING: media_face_get_face_count_from_db() is deprecated and will be removed from next release.");
328 content_retip_if_fail(face_count);
330 return _media_db_get_group_count(filter, MEDIA_GROUP_FACE, face_count);
333 int media_face_foreach_face_from_db(filter_h filter, media_face_cb callback, void *user_data)
335 content_warn("DEPRECATION WARNING: media_face_foreach_face_from_db() is deprecated and will be removed from next release.");
336 content_retip_if_fail(callback);
338 return _media_db_get_face(NULL, filter, callback, user_data);