media_svc_debug_fenter();
- ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
+ ret = _media_svc_init_table_query();
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_init_table_query fail.");
goto ERROR;
}
/*create media table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create folder table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create playlist_map table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create playlist table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/* create album table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create tag_map table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create tag table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create bookmark table*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create storage table from tizen 2.4 */
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
/*create face table. from tizen 3.0*/
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
- ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_LIST_FACE, uid);
+ ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
sql = sqlite3_mprintf("pragma user_version = %d;", LATEST_DB_VERSION);
ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("user_version update fail.");
goto ERROR;
}
int media_svc_move_item(sqlite3 *handle,
- const char *src_path,
- const char *dest_path,
- const char *media_id,
- int media_type,
- const char *mime_type,
- uid_t uid)
+ const char *src_path,
+ const char *dest_path,
+ const char *media_id,
+ int media_type,
+ const char *mime_type,
+ uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *file_name = NULL;
{
int ret = MS_MEDIA_ERR_NONE;
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ media_svc_content_info_s content_info = {0, };
+ media_svc_noti_item *noti_item = NULL;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
- media_svc_content_info_s content_info;
- memset(&content_info, 0, sizeof(media_svc_content_info_s));
-
/*Set media info*/
ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, true);
- if (ret != MS_MEDIA_ERR_NONE)
- return ret;
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/* Initialize thumbnail information to remake thumbnail. */
ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
- if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD) {
- _media_svc_destroy_content_info(&content_info);
- return ret;
- }
+ if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
+ goto REFRESH_FINALIZE;
if (STRING_VALID(thumb_path)) {
_media_svc_remove_file(thumb_path);
ret = _media_svc_update_thumbnail_path(path, NULL, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_content_info(&content_info);
- return ret;
- }
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
}
/* Get notification info */
- media_svc_noti_item *noti_item = NULL;
ret = _media_svc_get_noti_info(handle, path, ¬i_item);
- if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_content_info(&content_info);
- return ret;
- }
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
content_info.media_type = noti_item->media_type;
content_info.mime_type = g_strdup(noti_item->mime_type);
break;
}
- if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_noti_item(noti_item);
- _media_svc_destroy_content_info(&content_info);
- return ret;
- }
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
/* Extracting thumbnail */
if (content_info.thumbnail_path == NULL) {
ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
if (ret == MS_MEDIA_ERR_NONE) {
- media_svc_debug("Update is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+ if (is_direct) {
+ /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+ if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
+
+ g_media_svc_cur_data_cnt = 0;
+ }
+ } else {
+ /* Except scanner case */
+ media_svc_debug("Update is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+ }
} else {
media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
}
+REFRESH_FINALIZE:
_media_svc_destroy_content_info(&content_info);
_media_svc_destroy_noti_item(noti_item);
g_ptr_array_free(path_list, TRUE);
}
+static void __media_svc_foreach_update_media(gpointer data, gpointer user_data)
+{
+ media_svc_content_info_s content_info = {0, };
+
+ if (_media_svc_extract_music_metadata_for_update(&content_info, (const char *)data) != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to extract metadata");
+ _media_svc_destroy_content_info(&content_info);
+ return;
+ }
+
+ if (_media_svc_update_meta_with_data(&content_info) != MS_MEDIA_ERR_NONE)
+ media_svc_error("Fail to append item[%s]", content_info.path);
+
+ _media_svc_destroy_content_info(&content_info);
+}
+
int media_svc_update_item_meta(sqlite3 *handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- int i = 0;
char *sql = NULL;
- char *file_path = NULL;
- media_svc_content_info_s content_info;
- GPtrArray *path_list = NULL;
-
- path_list = g_ptr_array_new_with_free_func(g_free);
- media_svc_retvm_if(!path_list, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+ GList *path_list = NULL;
- sql = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=3 AND validity=1", MEDIA_SVC_DB_TABLE_MEDIA);
+ sql = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=3 AND validity=1", DB_TABLE_MEDIA);
ret = _media_svc_get_media(handle, sql, &path_list);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Fail to get media list");
- g_ptr_array_free(path_list, TRUE);
- return ret;
- }
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get media list");
- for (i = 0; i < path_list->len; i++) {
- file_path = g_ptr_array_index(path_list, i);
-
- memset(&content_info, 0, sizeof(media_svc_content_info_s));
- ret = _media_svc_extract_music_metadata_for_update(&content_info, file_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Fail to extract metadata");
- _media_svc_destroy_content_info(&content_info);
- continue;
- }
+ if (path_list) {
+ g_list_foreach(path_list, __media_svc_foreach_update_media, NULL);
+ g_list_free_full(path_list, g_free);
- ret = _media_svc_update_meta_with_data(&content_info);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("Fail to append item[%s]", content_info.path);
-
- _media_svc_destroy_content_info(&content_info);
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_list_query_do failed");
}
- g_ptr_array_free(path_list, TRUE);
-
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_list_query_do failed");
-
/* Noti for this */
__media_svc_noti_all_storage(handle, uid);
}
// 3. Update creation result to media db
- sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, file_path);
+ sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);