4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "media-svc.h"
25 #include "media-svc-media.h"
26 #include "media-svc-debug.h"
27 #include "media-svc-util.h"
28 #include "media-svc-db-utils.h"
29 #include "media-svc-env.h"
30 #include "media-svc-media-folder.h"
31 #include "media-svc-album.h"
32 #include "media-svc-noti.h"
33 #include "media-svc-storage.h"
35 static __thread int g_media_svc_item_validity_data_cnt = 1;
36 static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
38 static __thread int g_media_svc_insert_item_data_cnt = 1;
39 static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
41 static __thread int g_media_svc_update_item_data_cnt = 1;
42 static __thread int g_media_svc_update_item_cur_data_cnt = 0;
44 static __thread int g_media_svc_insert_folder_data_cnt = 1;
45 static __thread int g_media_svc_insert_folder_cur_data_cnt = 0;
47 /* Flag for items to be published by notification */
48 static __thread int g_insert_with_noti = FALSE;
50 #define BATCH_REQUEST_MAX 300
52 static bool __media_svc_check_storage(ms_user_storage_type_e storage_type)
54 if ((storage_type != MS_USER_STORAGE_INTERNAL)
55 && (storage_type != MS_USER_STORAGE_EXTERNAL)
56 && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
57 media_svc_error("storage type is incorrect[%d]", storage_type);
64 int media_svc_cleanup_db(sqlite3 *handle, uid_t uid)
66 media_svc_debug_fenter();
68 return _media_svc_do_cleanup(handle, uid);
71 int media_svc_get_user_version(sqlite3 *handle, int *user_version)
73 return _media_svc_get_user_version(handle, user_version);
76 int media_svc_create_table(uid_t uid)
78 int ret = MS_MEDIA_ERR_NONE;
81 media_svc_debug_fenter();
83 ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
84 if (ret != MS_MEDIA_ERR_NONE) {
85 media_svc_error("_media_svc_init_table_query fail.");
89 /*create media table*/
90 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
91 if (ret != MS_MEDIA_ERR_NONE) {
92 media_svc_error("_media_svc_make_table_query fail.");
96 /*create folder table*/
97 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
98 if (ret != MS_MEDIA_ERR_NONE) {
99 media_svc_error("_media_svc_make_table_query fail.");
103 /*create playlist_map table*/
104 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
105 if (ret != MS_MEDIA_ERR_NONE) {
106 media_svc_error("_media_svc_make_table_query fail.");
110 /*create playlist table*/
111 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
112 if (ret != MS_MEDIA_ERR_NONE) {
113 media_svc_error("_media_svc_make_table_query fail.");
117 /* create album table*/
118 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
119 if (ret != MS_MEDIA_ERR_NONE) {
120 media_svc_error("_media_svc_make_table_query fail.");
124 /*create tag_map table*/
125 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
126 if (ret != MS_MEDIA_ERR_NONE) {
127 media_svc_error("_media_svc_make_table_query fail.");
132 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
133 if (ret != MS_MEDIA_ERR_NONE) {
134 media_svc_error("_media_svc_make_table_query fail.");
138 /*create bookmark table*/
139 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
140 if (ret != MS_MEDIA_ERR_NONE) {
141 media_svc_error("_media_svc_make_table_query fail.");
145 /*create storage table from tizen 2.4 */
146 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
147 if (ret != MS_MEDIA_ERR_NONE) {
148 media_svc_error("_media_svc_make_table_query fail.");
152 /*create face table. from tizen 3.0*/
153 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
154 if (ret != MS_MEDIA_ERR_NONE) {
155 media_svc_error("_media_svc_make_table_query fail.");
159 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_LIST_FACE, uid);
160 if (ret != MS_MEDIA_ERR_NONE) {
161 media_svc_error("_media_svc_make_table_query fail.");
165 sql = sqlite3_mprintf("pragma user_version = %d;", LATEST_VERSION_NUMBER);
166 ret = _media_svc_sql_query(sql, uid);
167 if (ret != MS_MEDIA_ERR_NONE) {
168 media_svc_error("user_version update fail.");
172 _media_svc_destroy_table_query();
174 media_svc_debug_fleave();
176 return MS_MEDIA_ERR_NONE;
178 _media_svc_destroy_table_query();
180 media_svc_debug_fleave();
185 int media_svc_get_file_info(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
187 return _media_svc_get_fileinfo_by_path(handle, storage_id, path, modified_time, size);
190 int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
192 int ret = MS_MEDIA_ERR_NONE;
195 ret = _media_svc_count_record_with_path(handle, storage_id, path, &count);
196 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
199 media_svc_debug("item is exist in database");
200 return MS_MEDIA_ERR_NONE;
202 media_svc_debug("item is not exist in database");
203 return MS_MEDIA_ERR_DB_NO_RECORD;
206 return MS_MEDIA_ERR_NONE;
209 int media_svc_insert_item_begin(int data_cnt, int with_noti, int from_pid)
211 media_svc_debug("Transaction data count : [%d]", data_cnt);
213 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
215 g_media_svc_insert_item_data_cnt = data_cnt;
216 g_media_svc_insert_item_cur_data_cnt = 0;
218 /* Prepare for making noti item list */
220 media_svc_debug("making noti list from pid[%d]", from_pid);
221 if (_media_svc_create_noti_list(data_cnt) != MS_MEDIA_ERR_NONE)
222 return MS_MEDIA_ERR_OUT_OF_MEMORY;
224 _media_svc_set_noti_from_pid(from_pid);
225 g_insert_with_noti = TRUE;
228 return MS_MEDIA_ERR_NONE;
231 int media_svc_insert_item_end(uid_t uid)
233 int ret = MS_MEDIA_ERR_NONE;
235 media_svc_debug_fenter();
237 if (g_media_svc_insert_item_cur_data_cnt > 0) {
239 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
240 if (g_insert_with_noti) {
241 media_svc_debug("sending noti list");
242 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
243 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
244 g_insert_with_noti = FALSE;
245 _media_svc_set_noti_from_pid(-1);
249 g_media_svc_insert_item_data_cnt = 1;
250 g_media_svc_insert_item_cur_data_cnt = 0;
255 int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
257 int ret = MS_MEDIA_ERR_NONE;
258 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
259 media_svc_media_type_e media_type;
261 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
262 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
263 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
264 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
266 media_svc_content_info_s content_info;
267 memset(&content_info, 0, sizeof(media_svc_content_info_s));
270 /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
271 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
272 if (ret != MS_MEDIA_ERR_NONE)
275 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
276 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
277 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
278 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
279 media_svc_debug("Do nothing[%d]", media_type);
280 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
281 ret = _media_svc_extract_image_metadata(&content_info);
283 ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
284 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
286 /*Set or Get folder id*/
287 ret = _media_svc_get_and_append_folder_id_by_path(handle, storage_id, path, storage_type, folder_uuid, uid);
288 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
290 content_info.folder_uuid = g_strdup(folder_uuid);
291 media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
293 if (g_media_svc_insert_item_data_cnt == 1) {
295 ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, FALSE, uid);
296 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
298 if (g_insert_with_noti)
299 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
301 } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
303 ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, TRUE, uid);
304 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
306 if (g_insert_with_noti)
307 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
309 g_media_svc_insert_item_cur_data_cnt++;
311 } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
313 ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, TRUE, uid);
314 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
316 if (g_insert_with_noti)
317 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
319 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
320 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
322 if (g_insert_with_noti) {
323 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
324 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
326 /* Recreate noti list */
327 ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
328 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
331 g_media_svc_insert_item_cur_data_cnt = 0;
334 media_svc_error("Error in media_svc_insert_item_bulk");
335 _media_svc_destroy_content_info(&content_info);
336 return MS_MEDIA_ERR_INTERNAL;
339 _media_svc_destroy_content_info(&content_info);
341 return MS_MEDIA_ERR_NONE;
344 int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
346 int ret = MS_MEDIA_ERR_NONE;
347 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
348 media_svc_media_type_e media_type;
350 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
351 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
352 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
353 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
355 media_svc_content_info_s content_info;
356 memset(&content_info, 0, sizeof(media_svc_content_info_s));
359 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
360 if (ret != MS_MEDIA_ERR_NONE)
363 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
364 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
365 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
366 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA)) {
368 } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
369 ret = _media_svc_extract_image_metadata(&content_info);
371 ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
374 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
376 /*Set or Get folder id*/
377 ret = _media_svc_get_and_append_folder_id_by_path(handle, storage_id, path, storage_type, folder_uuid, uid);
378 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
380 content_info.folder_uuid = g_strdup(folder_uuid);
381 media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
383 /* Extracting thumbnail */
384 if (content_info.thumbnail_path == NULL) {
385 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
386 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
388 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
389 if (ret == MS_MEDIA_ERR_NONE)
390 content_info.thumbnail_path = g_strdup(thumb_path);
394 ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, FALSE, uid);
396 if (ret == MS_MEDIA_ERR_NONE) {
397 media_svc_debug("Insertion is successful. Sending noti for this");
398 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
399 } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
400 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
403 _media_svc_destroy_content_info(&content_info);
407 int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_path, uid_t uid)
409 int ret = MS_MEDIA_ERR_NONE;
410 char *file_name = NULL;
411 char *folder_path = NULL;
412 int modified_time = 0;
413 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
414 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
415 char org_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
416 char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
417 ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
418 ms_user_storage_type_e dst_stg_type = MS_USER_STORAGE_INTERNAL;
421 media_svc_debug_fenter();
423 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
424 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
425 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
428 ret = _media_svc_get_storage_uuid(handle, src_path, org_stg_id, uid);
429 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
430 ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
431 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
432 /* Get storage_type */
433 ret = ms_user_get_storage_type(uid, src_path, &org_stg_type);
434 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
435 ret = ms_user_get_storage_type(uid, dest_path, &dst_stg_type);
436 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
438 /*check and update folder*/
439 ret = _media_svc_get_and_append_folder_id_by_path(handle, dst_stg_id, dest_path, dst_stg_type, folder_uuid, uid);
440 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
443 file_name = g_path_get_basename(dest_path);
445 /*get modified_time*/
446 modified_time = _media_svc_get_file_time(dest_path);
448 ret = _media_svc_get_media_type_by_path(handle, org_stg_id, src_path, &media_type);
449 if (ret != MS_MEDIA_ERR_NONE) {
450 media_svc_error("_media_svc_get_media_type_by_path failed");
451 SAFE_FREE(file_name);
455 /*get old thumbnail_path and remove thumbnail */
456 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
457 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
458 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
459 SAFE_FREE(file_name);
463 if (STRING_VALID(old_thumb_path)) {
464 ret = _media_svc_remove_file(old_thumb_path);
465 if (ret != MS_MEDIA_ERR_NONE)
466 media_svc_error("_media_svc_remove_file failed : %d", ret);
470 ret = _media_svc_update_item_by_path(org_stg_id, src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_uuid, uid);
471 SAFE_FREE(file_name);
472 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
474 media_svc_debug("Move is successful. Sending noti for this");
476 /* Get notification info */
477 media_svc_noti_item *noti_item = NULL;
478 ret = _media_svc_get_noti_info(handle, dst_stg_id, dest_path, MS_MEDIA_ITEM_FILE, ¬i_item);
479 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
481 /* Send notification for move */
482 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
483 _media_svc_destroy_noti_item(noti_item);
485 /*update folder modified_time*/
486 folder_path = g_path_get_dirname(dest_path);
487 ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, uid);
488 SAFE_FREE(folder_path);
489 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
491 return MS_MEDIA_ERR_NONE;
494 int media_svc_set_item_validity_begin(int data_cnt)
496 media_svc_debug("Transaction data count : [%d]", data_cnt);
498 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
500 g_media_svc_item_validity_data_cnt = data_cnt;
501 g_media_svc_item_validity_cur_data_cnt = 0;
503 return MS_MEDIA_ERR_NONE;
506 int media_svc_set_item_validity_end(uid_t uid)
508 int ret = MS_MEDIA_ERR_NONE;
510 media_svc_debug_fenter();
512 if (g_media_svc_item_validity_cur_data_cnt > 0)
513 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
515 g_media_svc_item_validity_data_cnt = 1;
516 g_media_svc_item_validity_cur_data_cnt = 0;
521 int media_svc_set_item_validity(const char *storage_id, const char *path, int validity, uid_t uid)
523 int ret = MS_MEDIA_ERR_NONE;
525 if (g_media_svc_item_validity_data_cnt == 1) {
527 return _media_svc_update_item_validity(storage_id, path, validity, FALSE, uid);
529 } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
531 ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
532 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
534 g_media_svc_item_validity_cur_data_cnt++;
536 } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
538 ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
539 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
541 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
542 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
544 g_media_svc_item_validity_cur_data_cnt = 0;
548 media_svc_error("Error in media_svc_set_item_validity");
549 return MS_MEDIA_ERR_INTERNAL;
552 return MS_MEDIA_ERR_NONE;
555 int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
557 int ret = MS_MEDIA_ERR_NONE;
558 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
560 media_svc_debug_fenter();
563 ret = _media_svc_get_media_type_by_path(handle, storage_id, path, &media_type);
564 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
566 /*Get thumbnail path to delete*/
567 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
568 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
570 if (g_media_svc_insert_item_data_cnt == 1) {
572 /* Get notification info */
573 media_svc_noti_item *noti_item = NULL;
574 ret = _media_svc_get_noti_info(handle, storage_id, path, MS_MEDIA_ITEM_FILE, ¬i_item);
575 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
578 ret = _media_svc_delete_item_by_path(storage_id, path, FALSE, uid);
579 if (ret != MS_MEDIA_ERR_NONE) {
580 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
581 _media_svc_destroy_noti_item(noti_item);
586 /* Send notification */
587 media_svc_debug("Deletion is successful. Sending noti for this");
588 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
589 _media_svc_destroy_noti_item(noti_item);
591 ret = _media_svc_delete_item_by_path(storage_id, path, TRUE, uid);
592 if (ret != MS_MEDIA_ERR_NONE) {
593 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
600 if (STRING_VALID(thumb_path)) {
601 ret = _media_svc_remove_file(thumb_path);
602 if (ret != MS_MEDIA_ERR_NONE)
603 media_svc_error("fail to remove thumbnail file.");
606 return MS_MEDIA_ERR_NONE;
609 int media_svc_delete_invalid_items_in_storage(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, uid_t uid)
611 media_svc_debug_fenter();
613 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
614 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
615 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
617 /*Delete from DB and remove thumbnail files*/
618 return _media_svc_delete_invalid_items(handle, storage_id, storage_type, uid);
621 int media_svc_set_all_storage_items_validity(const char *storage_id, ms_user_storage_type_e storage_type, int validity, uid_t uid)
623 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
624 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
626 return _media_svc_update_storage_item_validity(storage_id, storage_type, validity, uid);
629 int media_svc_set_folder_items_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid)
631 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
632 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
633 media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
636 return _media_svc_update_recursive_folder_item_validity(storage_id, folder_path, validity, uid);
638 return _media_svc_update_folder_item_validity(handle, storage_id, folder_path, validity, uid);
641 int media_svc_refresh_item(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
643 int ret = MS_MEDIA_ERR_NONE;
644 media_svc_media_type_e media_type;
645 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
647 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
648 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
649 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
650 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
652 media_svc_content_info_s content_info;
653 memset(&content_info, 0, sizeof(media_svc_content_info_s));
656 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, TRUE);
657 if (ret != MS_MEDIA_ERR_NONE)
660 /* Initialize thumbnail information to remake thumbnail. */
661 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
662 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD) {
663 _media_svc_destroy_content_info(&content_info);
667 if (STRING_VALID(thumb_path)) {
668 if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
669 ret = _media_svc_remove_file(thumb_path);
670 if (ret != MS_MEDIA_ERR_NONE)
671 media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
674 ret = _media_svc_update_thumbnail_path(storage_id, path, NULL, uid);
675 if (ret != MS_MEDIA_ERR_NONE) {
676 _media_svc_destroy_content_info(&content_info);
681 /* Get notification info */
682 media_svc_noti_item *noti_item = NULL;
683 ret = _media_svc_get_noti_info(handle, storage_id, path, MS_MEDIA_ITEM_FILE, ¬i_item);
684 if (ret != MS_MEDIA_ERR_NONE) {
685 _media_svc_destroy_content_info(&content_info);
689 media_type = noti_item->media_type;
690 content_info.media_type = media_type;
692 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
693 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
694 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
695 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
696 media_svc_debug("Do nothing [%d]", media_type);
697 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
698 ret = _media_svc_extract_image_metadata(&content_info);
700 ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
702 if (ret != MS_MEDIA_ERR_NONE) {
703 _media_svc_destroy_noti_item(noti_item);
704 _media_svc_destroy_content_info(&content_info);
708 /* Extracting thumbnail */
709 if (content_info.thumbnail_path == NULL) {
710 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
711 memset(thumb_path, 0, sizeof(thumb_path));
713 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
714 if (ret == MS_MEDIA_ERR_NONE)
715 content_info.thumbnail_path = g_strdup(thumb_path);
719 ret = _media_svc_update_item_with_data(storage_id, &content_info, uid);
721 if (ret == MS_MEDIA_ERR_NONE) {
722 media_svc_debug("Update is successful. Sending noti for this");
723 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
725 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
728 _media_svc_destroy_content_info(&content_info);
729 _media_svc_destroy_noti_item(noti_item);
734 int media_svc_request_update_db(const char *db_query, uid_t uid)
736 return _media_svc_sql_query(db_query, uid);
739 int media_svc_send_dir_update_noti(sqlite3 *handle, const char *storage_id, const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
741 int ret = MS_MEDIA_ERR_NONE;
744 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
745 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
747 /* Get notification info */
748 media_svc_noti_item *noti_item = NULL;
749 ret = _media_svc_get_noti_info(handle, storage_id, dir_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
750 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
752 if (folder_id != NULL) {
753 uuid = strndup(folder_id, strlen(folder_id));
755 if (noti_item->media_uuid != NULL) {
756 uuid = strndup(noti_item->media_uuid, strlen(noti_item->media_uuid));
758 _media_svc_destroy_noti_item(noti_item);
759 media_svc_error("folder uuid is wrong");
760 return MS_MEDIA_ERR_DB_INTERNAL;
764 ret = _media_svc_publish_dir_noti_v2(MS_MEDIA_ITEM_DIRECTORY, update_type, dir_path, -1, uuid, NULL, pid);
765 _media_svc_destroy_noti_item(noti_item);
771 int media_svc_check_db_upgrade(sqlite3 *handle, int user_version, uid_t uid)
773 media_svc_debug_fenter();
775 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
777 return _media_svc_check_db_upgrade(handle, user_version, uid);
780 int media_svc_update_item_begin(int data_cnt)
782 media_svc_debug("Transaction data count : [%d]", data_cnt);
784 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
786 g_media_svc_update_item_data_cnt = data_cnt;
787 g_media_svc_update_item_cur_data_cnt = 0;
789 return MS_MEDIA_ERR_NONE;
792 int media_svc_update_item_end(uid_t uid)
794 int ret = MS_MEDIA_ERR_NONE;
796 media_svc_debug_fenter();
798 if (g_media_svc_update_item_cur_data_cnt > 0)
799 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
801 g_media_svc_update_item_data_cnt = 1;
802 g_media_svc_update_item_cur_data_cnt = 0;
807 int media_svc_update_item_meta(const char *file_path, const char *storage_id, int storage_type, uid_t uid)
809 int ret = MS_MEDIA_ERR_NONE;
810 media_svc_media_type_e media_type;
812 media_svc_retvm_if(!STRING_VALID(file_path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
813 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
815 media_svc_content_info_s content_info;
816 memset(&content_info, 0, sizeof(media_svc_content_info_s));
819 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, file_path, &media_type, FALSE);
820 if (ret != MS_MEDIA_ERR_NONE)
823 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)
824 ret = _media_svc_extract_music_metadata_for_update(&content_info, media_type);
826 _media_svc_destroy_content_info(&content_info);
827 return MS_MEDIA_ERR_NONE;
830 if (ret != MS_MEDIA_ERR_NONE) {
831 _media_svc_destroy_content_info(&content_info);
835 if (g_media_svc_update_item_data_cnt == 1) {
837 ret = _media_svc_update_meta_with_data(&content_info);
838 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
840 } else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
842 ret = _media_svc_update_meta_with_data(&content_info);
843 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
845 g_media_svc_update_item_cur_data_cnt++;
847 } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
849 ret = _media_svc_update_meta_with_data(&content_info);
850 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
852 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
853 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
855 g_media_svc_update_item_cur_data_cnt = 0;
858 media_svc_error("Error in media_svc_update_item_meta");
859 _media_svc_destroy_content_info(&content_info);
860 return MS_MEDIA_ERR_INTERNAL;
863 _media_svc_destroy_content_info(&content_info);
868 int media_svc_publish_noti(media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
870 return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
873 int media_svc_get_pinyin(const char *src_str, char **pinyin_str)
875 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
877 return _media_svc_get_pinyin_str(src_str, pinyin_str);
880 int media_svc_check_pinyin_support(bool *support)
882 *support = _media_svc_check_pinyin_support();
884 return MS_MEDIA_ERR_NONE;
887 int media_svc_set_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
889 int ret = MS_MEDIA_ERR_NONE;
891 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
893 ret = _media_svc_update_storage_validity(storage_id, validity, uid);
894 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
896 ret = _media_svc_update_media_view(handle, uid);
897 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
902 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
904 int ret = MS_MEDIA_ERR_NONE;
906 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
907 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
909 ret = _media_svc_get_storage_uuid(handle, path, storage_id, uid);
914 int media_svc_get_storage_list(sqlite3 *handle, char ***storage_list, char ***storage_id_list, int *count)
916 media_svc_debug_fenter();
918 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
919 media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
921 return _media_svc_get_all_storage(handle, storage_list, storage_id_list, count);
924 int media_svc_generate_uuid(char **uuid)
926 char *gen_uuid = NULL;
927 gen_uuid = _media_info_generate_uuid();
928 media_svc_retvm_if(gen_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Fail to generate uuid");
930 *uuid = strdup(gen_uuid);
932 return MS_MEDIA_ERR_NONE;
935 int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
937 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
938 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
939 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
940 media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
942 return _media_svc_check_storage(handle, storage_id, storage_path, validity, uid);
945 int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
947 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
948 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
949 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
951 return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
954 int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, ms_user_storage_type_e storage_type, uid_t uid)
956 int ret = MS_MEDIA_ERR_NONE;
958 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
959 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
960 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
961 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
963 ret = _media_svc_append_storage(storage_id, storage_path, storage_type, uid);
964 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
966 ret = _media_svc_create_media_table_with_id(storage_id, uid);
967 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
969 ret = _media_svc_update_media_view(handle, uid);
970 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
972 /* Remove external storage that validity is 0 */
973 ret = _media_svc_delete_invalid_storage(handle, storage_type, uid);
974 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
979 int media_svc_insert_folder_begin(int data_cnt)
981 media_svc_debug("Transaction data count : [%d]", data_cnt);
983 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
985 g_media_svc_insert_folder_data_cnt = data_cnt;
986 g_media_svc_insert_folder_cur_data_cnt = 0;
988 return MS_MEDIA_ERR_NONE;
991 int media_svc_insert_folder_end(uid_t uid)
993 int ret = MS_MEDIA_ERR_NONE;
995 media_svc_debug_fenter();
997 if (g_media_svc_insert_folder_cur_data_cnt > 0)
998 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1000 g_media_svc_insert_folder_data_cnt = 1;
1001 g_media_svc_insert_folder_cur_data_cnt = 0;
1006 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
1008 int ret = MS_MEDIA_ERR_NONE;
1009 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1011 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1012 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1013 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1014 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1016 if (g_media_svc_insert_folder_data_cnt == 1) {
1018 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, FALSE, uid);
1020 } else if (g_media_svc_insert_folder_cur_data_cnt < (g_media_svc_insert_folder_data_cnt - 1)) {
1022 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1023 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1025 g_media_svc_insert_folder_cur_data_cnt++;
1027 } else if (g_media_svc_insert_folder_cur_data_cnt == (g_media_svc_insert_folder_data_cnt - 1)) {
1029 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1030 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1032 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1033 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1035 g_media_svc_insert_folder_cur_data_cnt = 0;
1038 media_svc_error("Error in media_svc_set_insert_folder");
1039 return MS_MEDIA_ERR_INTERNAL;
1045 int media_svc_delete_invalid_folder(const char *storage_id, int storage_type, uid_t uid)
1047 int ret = MS_MEDIA_ERR_NONE;
1049 ret = _media_svc_delete_invalid_folder(storage_id, storage_type, uid);
1054 int media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
1056 int ret = MS_MEDIA_ERR_NONE;
1058 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1060 ret = _media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
1065 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
1067 int ret = MS_MEDIA_ERR_NONE;
1070 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1071 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1072 media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
1074 ret = _media_svc_count_folder_with_path(handle, storage_id, folder_path, &count);
1075 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1078 media_svc_debug("item is exist in database");
1079 return MS_MEDIA_ERR_NONE;
1081 media_svc_debug("item is not exist in database");
1082 return MS_MEDIA_ERR_DB_NO_RECORD;
1085 return MS_MEDIA_ERR_NONE;
1088 int media_svc_get_folder_id(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id)
1090 int ret = MS_MEDIA_ERR_NONE;
1092 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1093 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1095 ret = _media_svc_get_folder_uuid(handle, storage_id, path, folder_id);
1100 int media_svc_append_query(const char *query, uid_t uid)
1102 int ret = MS_MEDIA_ERR_NONE;
1104 media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
1106 ret = _media_svc_append_query_list(query, uid);
1111 int media_svc_send_query(uid_t uid)
1113 int ret = MS_MEDIA_ERR_NONE;
1115 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
1120 int media_svc_get_media_type(const char *path, int *mediatype)
1122 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1124 return _media_svc_get_media_type(path, mediatype);
1127 int media_svc_create_thumbnail(const char *storage_id, const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
1129 int ret = MS_MEDIA_ERR_NONE;
1130 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
1133 // 1. Check media type
1134 if (media_type != MS_MEDIA_IMAGE && media_type != MS_MEDIA_VIDEO)
1135 return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
1137 // 2. try to create thumbnail
1138 ret = _media_svc_create_thumbnail(file_path, thumb_path, MEDIA_SVC_PATHNAME_SIZE, media_type, uid);
1139 if (ret != MS_MEDIA_ERR_NONE) {
1140 media_svc_error("Failed to create thumbnail [%d]", ret);
1141 if (ret == MS_MEDIA_ERR_UNSUPPORTED_CONTENT)
1145 // 3. Update creation result to media db
1146 sql = sqlite3_mprintf("UPDATE '%q' SET thumbnail_path='%q' WHERE path='%q';", storage_id, thumb_path, file_path);
1148 ret = _media_svc_sql_query(sql, uid);
1149 SQLITE3_SAFE_FREE(sql);
1150 if (ret != MS_MEDIA_ERR_NONE) {
1151 media_svc_error("Failed to update media db [%d]", ret);
1152 *thumbnail_path = g_strdup("");
1154 *thumbnail_path = g_strdup(thumb_path);