4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "media-svc-media.h"
21 #include "media-svc-debug.h"
22 #include "media-svc-util.h"
23 #include "media-svc-db-utils.h"
24 #include "media-svc-env.h"
25 #include "media-svc-media-folder.h"
26 #include "media-svc-album.h"
27 #include "media-svc-noti.h"
28 #include "media-svc-storage.h"
30 #include <iniparser.h>
32 #define CONTENT_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
34 static __thread int g_media_svc_cur_data_cnt = 0;
36 /* Flag for items to be published by notification */
37 static __thread bool g_insert_with_noti = false;
39 #define BATCH_ITEM_COUNT_MAX 100
41 int media_svc_check_table_exist(sqlite3 *handle, bool *exist)
43 return _media_svc_check_table_exist(handle, exist);
46 int media_svc_create_table(uid_t uid)
48 int ret = MS_MEDIA_ERR_NONE;
49 media_svc_debug_fenter();
51 ret = _media_svc_init_table_query();
52 if (ret != MS_MEDIA_ERR_NONE) {
53 media_svc_error("_media_svc_init_table_query fail.");
57 /*create media table*/
58 ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
59 if (ret != MS_MEDIA_ERR_NONE) {
60 media_svc_error("_media_svc_make_table_query fail.");
64 /*create folder table*/
65 ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
66 if (ret != MS_MEDIA_ERR_NONE) {
67 media_svc_error("_media_svc_make_table_query fail.");
71 /*create playlist_map table*/
72 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
73 if (ret != MS_MEDIA_ERR_NONE) {
74 media_svc_error("_media_svc_make_table_query fail.");
78 /*create playlist table*/
79 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
80 if (ret != MS_MEDIA_ERR_NONE) {
81 media_svc_error("_media_svc_make_table_query fail.");
85 /* create album table*/
86 ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
87 if (ret != MS_MEDIA_ERR_NONE) {
88 media_svc_error("_media_svc_make_table_query fail.");
92 /*create tag_map table*/
93 ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
94 if (ret != MS_MEDIA_ERR_NONE) {
95 media_svc_error("_media_svc_make_table_query fail.");
100 ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
101 if (ret != MS_MEDIA_ERR_NONE) {
102 media_svc_error("_media_svc_make_table_query fail.");
106 /*create bookmark table*/
107 ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
108 if (ret != MS_MEDIA_ERR_NONE) {
109 media_svc_error("_media_svc_make_table_query fail.");
113 /*create storage table from tizen 2.4 */
114 ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
115 if (ret != MS_MEDIA_ERR_NONE) {
116 media_svc_error("_media_svc_make_table_query fail.");
120 /*create face table. from tizen 3.0*/
121 ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
122 if (ret != MS_MEDIA_ERR_NONE) {
123 media_svc_error("_media_svc_make_table_query fail.");
127 ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
128 if (ret != MS_MEDIA_ERR_NONE) {
129 media_svc_error("_media_svc_make_table_query fail.");
133 _media_svc_destroy_table_query();
135 media_svc_debug_fleave();
140 int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
142 return _media_svc_check_data_by_path(handle, path);
145 int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
147 return _media_svc_get_modified_time(handle, path, modified_time);
150 int media_svc_insert_item_begin(bool with_noti, int from_pid)
152 g_media_svc_cur_data_cnt = 0;
154 /* Prepare for making noti item list */
156 media_svc_debug("making noti list from pid[%d]", from_pid);
157 _media_svc_initialize_noti_list();
158 _media_svc_set_noti_from_pid(from_pid);
159 g_insert_with_noti = true;
162 return MS_MEDIA_ERR_NONE;
165 int media_svc_insert_item_end(uid_t uid)
167 int ret = MS_MEDIA_ERR_NONE;
169 media_svc_debug_fenter();
171 if (g_media_svc_cur_data_cnt > 0) {
172 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
173 if (g_insert_with_noti) {
174 media_svc_debug("sending noti list");
175 _media_svc_publish_noti_list();
176 g_insert_with_noti = false;
177 _media_svc_set_noti_from_pid(-1);
181 g_media_svc_cur_data_cnt = 0;
186 int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
188 int ret = MS_MEDIA_ERR_NONE;
189 long long int folder_id = 0;
191 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
192 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
193 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
195 media_svc_content_info_s content_info = { 0, };
198 ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
199 if (ret != MS_MEDIA_ERR_NONE)
202 switch (content_info.media_type) {
203 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
204 ret = _media_svc_extract_image_metadata(&content_info);
206 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
207 _media_svc_extract_video_metadata(&content_info);
209 case MEDIA_SVC_MEDIA_TYPE_SOUND:
210 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
211 _media_svc_extract_audio_metadata(handle, true, &content_info, uid);
213 case MEDIA_SVC_MEDIA_TYPE_BOOK:
214 ret = _media_svc_extract_book_metadata(&content_info);
217 /* The 'TITLE' should always be filled in */
218 content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
222 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
224 /*Set or Get folder id*/
225 ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, &folder_id, uid);
226 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
228 content_info.folder_id = folder_id;
229 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
231 ret = _media_svc_insert_item_stack(&content_info);
232 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
234 if (g_insert_with_noti)
235 _media_svc_insert_item_to_noti_list(&content_info);
237 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
238 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
239 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
240 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
242 if (g_insert_with_noti)
243 _media_svc_publish_noti_list();
245 g_media_svc_cur_data_cnt = 0;
248 _media_svc_destroy_content_info(&content_info);
250 return MS_MEDIA_ERR_NONE;
253 int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
255 int ret = MS_MEDIA_ERR_NONE;
256 long long int folder_id = 0;
258 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
259 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
260 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
262 media_svc_content_info_s content_info = { 0, };
265 ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
266 if (ret != MS_MEDIA_ERR_NONE)
269 switch (content_info.media_type) {
270 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
271 ret = _media_svc_extract_image_metadata(&content_info);
273 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
274 _media_svc_extract_video_metadata(&content_info);
276 case MEDIA_SVC_MEDIA_TYPE_SOUND:
277 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
278 _media_svc_extract_audio_metadata(handle, false, &content_info, uid);
280 case MEDIA_SVC_MEDIA_TYPE_BOOK:
281 ret = _media_svc_extract_book_metadata(&content_info);
284 /* The 'TITLE' should always be filled in */
285 content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
289 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
291 /*Set or Get folder id*/
292 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, &folder_id, uid);
293 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
295 content_info.folder_id = folder_id;
296 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
298 /* Extracting thumbnail */
299 if (content_info.thumbnail_path == NULL) {
300 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
301 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
303 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
304 if (ret == MS_MEDIA_ERR_NONE)
305 content_info.thumbnail_path = g_strdup(thumb_path);
309 ret = _media_svc_insert_item(&content_info, uid);
310 if (ret == MS_MEDIA_ERR_NONE) {
311 media_svc_debug("Insertion is successful. Sending noti for this");
312 _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
313 } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
314 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
317 _media_svc_destroy_content_info(&content_info);
321 int media_svc_move_item(sqlite3 *handle,
322 const char *src_path,
323 const char *dest_path,
324 const char *media_id,
326 const char *mime_type,
329 int ret = MS_MEDIA_ERR_NONE;
330 char *file_name = NULL;
331 int modified_time = 0;
332 long long int folder_id = 0;
333 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
334 char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
336 media_svc_debug_fenter();
338 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
339 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
340 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
341 media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
342 media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
345 ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
346 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
348 /*check and update folder*/
349 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, &folder_id, uid);
350 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
353 file_name = g_path_get_basename(dest_path);
355 /*get modified_time*/
356 modified_time = _media_svc_get_file_time(dest_path);
358 /*get old thumbnail_path and remove thumbnail */
359 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
360 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
361 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
366 _media_svc_remove_file(old_thumb_path);
369 ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dest_path, file_name, modified_time, folder_id, uid);
371 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
373 media_svc_debug("Move is successful. Sending noti for this");
374 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
376 return MS_MEDIA_ERR_NONE;
379 int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
381 int ret = MS_MEDIA_ERR_NONE;
383 ret = _media_svc_update_item_validity(path, validity, true, uid);
384 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
386 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
387 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
388 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
389 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
391 g_media_svc_cur_data_cnt = 0;
397 int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
399 int ret = MS_MEDIA_ERR_NONE;
400 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
401 media_svc_noti_item *noti_item = NULL;
403 media_svc_debug_fenter();
405 /*Get thumbnail path to delete*/
406 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
407 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
409 /* Get notification info */
410 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
411 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
414 ret = _media_svc_delete_item_by_path(path, uid);
415 if (ret != MS_MEDIA_ERR_NONE) {
416 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
417 _media_svc_destroy_noti_item(noti_item);
422 /* Send notification */
423 media_svc_debug("Deletion is successful. Sending noti for this");
424 _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
425 _media_svc_destroy_noti_item(noti_item);
428 _media_svc_remove_file(thumb_path);
430 return MS_MEDIA_ERR_NONE;
433 int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
435 int ret = MS_MEDIA_ERR_NONE;
436 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
437 media_svc_content_info_s content_info = {0, };
438 media_svc_noti_item *noti_item = NULL;
440 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
441 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
444 ret = _media_svc_set_media_info(&content_info, NULL, path, true);
445 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
447 /* Initialize thumbnail information to remake thumbnail. */
448 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
449 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
450 goto REFRESH_FINALIZE;
452 if (strlen(thumb_path) > 0) {
453 _media_svc_remove_file(thumb_path);
455 ret = _media_svc_update_thumbnail_path(path, NULL, uid);
456 if (ret != MS_MEDIA_ERR_NONE)
457 goto REFRESH_FINALIZE;
460 /* Get notification info */
461 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
462 if (ret != MS_MEDIA_ERR_NONE)
463 goto REFRESH_FINALIZE;
465 content_info.media_type = noti_item->media_type;
466 content_info.mime_type = g_strdup(noti_item->mime_type);
468 switch (content_info.media_type) {
469 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
470 ret = _media_svc_extract_image_metadata(&content_info);
472 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
473 _media_svc_extract_video_metadata(&content_info);
475 case MEDIA_SVC_MEDIA_TYPE_SOUND:
476 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
477 _media_svc_extract_audio_metadata(handle, is_direct, &content_info, uid);
479 case MEDIA_SVC_MEDIA_TYPE_BOOK:
480 ret = _media_svc_extract_book_metadata(&content_info);
483 /* The 'TITLE' should always be filled in */
484 content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
488 if (ret != MS_MEDIA_ERR_NONE)
489 goto REFRESH_FINALIZE;
491 /* Extracting thumbnail */
492 if (content_info.thumbnail_path == NULL) {
493 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
494 memset(thumb_path, 0, sizeof(thumb_path));
496 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
497 if (ret == MS_MEDIA_ERR_NONE)
498 content_info.thumbnail_path = g_strdup(thumb_path);
502 ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
504 if (ret == MS_MEDIA_ERR_NONE) {
506 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
507 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
508 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
509 if (ret != MS_MEDIA_ERR_NONE)
510 goto REFRESH_FINALIZE;
512 g_media_svc_cur_data_cnt = 0;
515 /* Except scanner case */
516 media_svc_debug("Update is successful. Sending noti for this");
517 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
520 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
524 _media_svc_destroy_content_info(&content_info);
525 _media_svc_destroy_noti_item(noti_item);
530 int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, int update_type, int pid)
532 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
534 return _media_svc_publish_dir_noti((media_item_update_type_e)update_type, dir_path, folder_id, pid);
537 int media_svc_publish_update_noti(const char *path, int media_type, const char *uuid, const char *mime_type)
539 return _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, path, media_type, uuid, mime_type);
542 int media_svc_set_storage_validity(const char *storage_id, int validity, uid_t uid)
544 return _media_svc_update_storage_validity(storage_id, validity, uid);
547 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
549 return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
552 int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
554 return _media_svc_check_storage(handle, storage_id, storage_path, validity);
557 int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
559 return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
562 int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
564 int ret = MS_MEDIA_ERR_NONE;
566 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
567 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
568 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
570 ret = _media_svc_append_storage(storage_id, storage_path, uid);
571 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
573 /* Remove external storage that validity is 0 */
574 ret = _media_svc_delete_invalid_storage(handle, uid);
575 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
580 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
582 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
583 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
584 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
586 return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
589 int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
591 return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
594 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
596 return _media_svc_check_folder_by_path(handle, folder_path);
599 int media_svc_append_query(const char *query, uid_t uid)
601 return _media_svc_append_query_list(query, uid);
604 int media_svc_send_query(uid_t uid)
606 return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
609 int media_svc_get_media_type(const char *path, int *mediatype)
611 return _media_svc_get_media_type(path, mediatype);
614 int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
616 int ret = MS_MEDIA_ERR_NONE;
617 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
620 // 1. Check media type
621 if (media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE && media_type != MEDIA_SVC_MEDIA_TYPE_VIDEO)
622 return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
624 // 2. try to create thumbnail
625 ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
626 if (ret != MS_MEDIA_ERR_NONE) {
627 media_svc_error("Failed to create thumbnail [%d]", ret);
628 if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
632 // 3. Update creation result to media db
633 sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
635 ret = _media_svc_sql_query(sql, uid);
636 SQLITE3_SAFE_FREE(sql);
637 if (ret != MS_MEDIA_ERR_NONE) {
638 media_svc_error("Failed to update media db [%d]", ret);
639 *thumbnail_path = g_strdup("");
641 *thumbnail_path = g_strdup(thumb_path);
647 static int __media_svc_get_ebook_search_type(void)
649 dictionary *dict = NULL;
650 static int _ebook_search_type = -1;
652 if (_ebook_search_type == -1) {
653 dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
655 media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
656 return MEDIA_SVC_SEARCH_TYPE_DIRECT;
659 _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
660 media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
662 iniparser_freedict(dict);
665 return _ebook_search_type;
668 int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
670 int ret = MS_MEDIA_ERR_NONE;
671 GList *item_list = NULL;
673 const char *query = "SELECT media_path FROM media WHERE media_type=5 AND validity=1;";
675 media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
676 media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
677 media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
679 ret = _media_svc_get_media(handle, query, &item_list);
680 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
682 if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
683 for (iter = item_list; iter; iter = g_list_next(iter))
684 _media_svc_update_wordbook((char *)iter->data, uid);
686 _media_svc_clean_wordbook(uid);
688 if (!_media_svc_get_matched_list(keyword, uid, result))
689 media_svc_error("_media_svc_get_matched_list failed");
691 for (iter = item_list; iter; iter = g_list_next(iter)) {
692 if (_media_svc_is_keyword_included((char *)iter->data, keyword))
693 *result = g_list_append(*result, g_strdup((gchar *)iter->data));
697 g_list_free_full(item_list, g_free);
702 int media_svc_check_db(sqlite3 *handle, uid_t uid)
704 int ret = MS_MEDIA_ERR_NONE;
707 ret = media_svc_check_table_exist(handle, &exist);
708 if (ret != MS_MEDIA_ERR_NONE)
712 ret = media_svc_create_table(uid);