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 char *folder_path = NULL;
332 int modified_time = 0;
333 long long int folder_id = 0;
334 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
335 char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
337 media_svc_debug_fenter();
339 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
340 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
341 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
342 media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
343 media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
346 ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
347 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
349 /*check and update folder*/
350 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, &folder_id, uid);
351 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
354 file_name = g_path_get_basename(dest_path);
356 /*get modified_time*/
357 modified_time = _media_svc_get_file_time(dest_path);
359 /*get old thumbnail_path and remove thumbnail */
360 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
361 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
362 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
367 _media_svc_remove_file(old_thumb_path);
370 ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dest_path, file_name, modified_time, folder_id, uid);
372 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
374 media_svc_debug("Move is successful. Sending noti for this");
375 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
377 /*update folder modified_time*/
378 folder_path = g_path_get_dirname(dest_path);
379 ret = _media_svc_update_folder_modified_time(folder_path, uid);
381 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
383 return MS_MEDIA_ERR_NONE;
386 int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
388 int ret = MS_MEDIA_ERR_NONE;
390 ret = _media_svc_update_item_validity(path, validity, true, uid);
391 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
393 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
394 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
395 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
396 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
398 g_media_svc_cur_data_cnt = 0;
404 int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
406 int ret = MS_MEDIA_ERR_NONE;
407 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
408 media_svc_noti_item *noti_item = NULL;
410 media_svc_debug_fenter();
412 /*Get thumbnail path to delete*/
413 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
414 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
416 /* Get notification info */
417 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
418 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
421 ret = _media_svc_delete_item_by_path(path, uid);
422 if (ret != MS_MEDIA_ERR_NONE) {
423 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
424 _media_svc_destroy_noti_item(noti_item);
429 /* Send notification */
430 media_svc_debug("Deletion is successful. Sending noti for this");
431 _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
432 _media_svc_destroy_noti_item(noti_item);
435 _media_svc_remove_file(thumb_path);
437 return MS_MEDIA_ERR_NONE;
440 int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
442 int ret = MS_MEDIA_ERR_NONE;
443 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
444 media_svc_content_info_s content_info = {0, };
445 media_svc_noti_item *noti_item = NULL;
447 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
448 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
451 ret = _media_svc_set_media_info(&content_info, NULL, path, true);
452 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
454 /* Initialize thumbnail information to remake thumbnail. */
455 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
456 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
457 goto REFRESH_FINALIZE;
459 if (strlen(thumb_path) > 0) {
460 _media_svc_remove_file(thumb_path);
462 ret = _media_svc_update_thumbnail_path(path, NULL, uid);
463 if (ret != MS_MEDIA_ERR_NONE)
464 goto REFRESH_FINALIZE;
467 /* Get notification info */
468 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
469 if (ret != MS_MEDIA_ERR_NONE)
470 goto REFRESH_FINALIZE;
472 content_info.media_type = noti_item->media_type;
473 content_info.mime_type = g_strdup(noti_item->mime_type);
475 switch (content_info.media_type) {
476 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
477 ret = _media_svc_extract_image_metadata(&content_info);
479 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
480 _media_svc_extract_video_metadata(&content_info);
482 case MEDIA_SVC_MEDIA_TYPE_SOUND:
483 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
484 _media_svc_extract_audio_metadata(handle, is_direct, &content_info, uid);
486 case MEDIA_SVC_MEDIA_TYPE_BOOK:
487 ret = _media_svc_extract_book_metadata(&content_info);
490 /* The 'TITLE' should always be filled in */
491 content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
495 if (ret != MS_MEDIA_ERR_NONE)
496 goto REFRESH_FINALIZE;
498 /* Extracting thumbnail */
499 if (content_info.thumbnail_path == NULL) {
500 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
501 memset(thumb_path, 0, sizeof(thumb_path));
503 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
504 if (ret == MS_MEDIA_ERR_NONE)
505 content_info.thumbnail_path = g_strdup(thumb_path);
509 ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
511 if (ret == MS_MEDIA_ERR_NONE) {
513 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
514 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
515 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
516 if (ret != MS_MEDIA_ERR_NONE)
517 goto REFRESH_FINALIZE;
519 g_media_svc_cur_data_cnt = 0;
522 /* Except scanner case */
523 media_svc_debug("Update is successful. Sending noti for this");
524 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
527 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
531 _media_svc_destroy_content_info(&content_info);
532 _media_svc_destroy_noti_item(noti_item);
537 int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, int update_type, int pid)
539 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
541 return _media_svc_publish_dir_noti((media_item_update_type_e)update_type, dir_path, folder_id, pid);
544 int media_svc_publish_update_noti(const char *path, int media_type, const char *uuid, const char *mime_type)
546 return _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, path, media_type, uuid, mime_type);
549 int media_svc_set_storage_validity(const char *storage_id, int validity, uid_t uid)
551 return _media_svc_update_storage_validity(storage_id, validity, uid);
554 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
556 return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
559 int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
561 return _media_svc_check_storage(handle, storage_id, storage_path, validity);
564 int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
566 return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
569 int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
571 int ret = MS_MEDIA_ERR_NONE;
573 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
574 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
575 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
577 ret = _media_svc_append_storage(storage_id, storage_path, uid);
578 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
580 /* Remove external storage that validity is 0 */
581 ret = _media_svc_delete_invalid_storage(handle, uid);
582 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
587 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
589 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
590 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
591 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
593 return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
596 int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
598 return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
601 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
603 return _media_svc_check_folder_by_path(handle, folder_path);
606 int media_svc_append_query(const char *query, uid_t uid)
608 return _media_svc_append_query_list(query, uid);
611 int media_svc_send_query(uid_t uid)
613 return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
616 int media_svc_get_media_type(const char *path, int *mediatype)
618 return _media_svc_get_media_type(path, mediatype);
621 int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
623 int ret = MS_MEDIA_ERR_NONE;
624 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
627 // 1. Check media type
628 if (media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE && media_type != MEDIA_SVC_MEDIA_TYPE_VIDEO)
629 return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
631 // 2. try to create thumbnail
632 ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
633 if (ret != MS_MEDIA_ERR_NONE) {
634 media_svc_error("Failed to create thumbnail [%d]", ret);
635 if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
639 // 3. Update creation result to media db
640 sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
642 ret = _media_svc_sql_query(sql, uid);
643 SQLITE3_SAFE_FREE(sql);
644 if (ret != MS_MEDIA_ERR_NONE) {
645 media_svc_error("Failed to update media db [%d]", ret);
646 *thumbnail_path = g_strdup("");
648 *thumbnail_path = g_strdup(thumb_path);
654 static int __media_svc_get_ebook_search_type(void)
656 dictionary *dict = NULL;
657 static int _ebook_search_type = -1;
659 if (_ebook_search_type == -1) {
660 dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
662 media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
663 return MEDIA_SVC_SEARCH_TYPE_DIRECT;
666 _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
667 media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
669 iniparser_freedict(dict);
672 return _ebook_search_type;
675 int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
677 int ret = MS_MEDIA_ERR_NONE;
678 GList *item_list = NULL;
680 const char *query = "SELECT media_path FROM media WHERE media_type=5 AND validity=1;";
682 media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
683 media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
684 media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
686 ret = _media_svc_get_media(handle, query, &item_list);
687 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
689 if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
690 for (iter = item_list; iter; iter = g_list_next(iter))
691 _media_svc_update_wordbook((char *)iter->data, uid);
693 _media_svc_clean_wordbook(uid);
695 if (!_media_svc_get_matched_list(keyword, uid, result))
696 media_svc_error("_media_svc_get_matched_list failed");
698 for (iter = item_list; iter; iter = g_list_next(iter)) {
699 if (_media_svc_is_keyword_included((char *)iter->data, keyword))
700 *result = g_list_append(*result, g_strdup((gchar *)iter->data));
704 g_list_free_full(item_list, g_free);
709 int media_svc_check_db(sqlite3 *handle, uid_t uid)
711 int ret = MS_MEDIA_ERR_NONE;
714 ret = media_svc_check_table_exist(handle, &exist);
715 if (ret != MS_MEDIA_ERR_NONE)
719 ret = media_svc_create_table(uid);