#include "media-svc-noti.h"
#include "media-svc-storage.h"
-static __thread int g_media_svc_item_validity_data_cnt = 1;
-static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
-
-static __thread int g_media_svc_insert_item_data_cnt = 1;
-static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
+//static __thread int g_media_svc_data_cnt = 0;
+static __thread int g_media_svc_cur_data_cnt = 0;
/* Flag for items to be published by notification */
static __thread bool g_insert_with_noti = false;
-#define BATCH_REQUEST_MAX 300
+#define BATCH_ITEM_COUNT_MAX 100
int media_svc_get_user_version(sqlite3 *handle, int *user_version)
{
media_svc_error("user_version update fail.");
goto ERROR;
}
-
- _media_svc_destroy_table_query();
-
- media_svc_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
ERROR:
_media_svc_destroy_table_query();
int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
{
- int ret = MS_MEDIA_ERR_NONE;
- int count = -1;
-
- ret = _media_svc_count_record_with_path(handle, path, &count);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- if (count > 0) {
- media_svc_debug("item is exist in database");
- return MS_MEDIA_ERR_NONE;
- } else {
- media_svc_debug("item is not exist in database");
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- return MS_MEDIA_ERR_NONE;
+ return _media_svc_check_data_by_path(handle, path);
}
int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
return _media_svc_get_modified_time(handle, path, modified_time);
}
-int media_svc_insert_item_begin(int data_cnt, bool with_noti, int from_pid)
+int media_svc_insert_item_begin(bool with_noti, int from_pid)
{
- media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
-
- g_media_svc_insert_item_data_cnt = data_cnt;
- g_media_svc_insert_item_cur_data_cnt = 0;
+ g_media_svc_cur_data_cnt = 0;
/* Prepare for making noti item list */
if (with_noti) {
media_svc_debug("making noti list from pid[%d]", from_pid);
- if (_media_svc_create_noti_list(data_cnt) != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
-
+ _media_svc_initialize_noti_list();
_media_svc_set_noti_from_pid(from_pid);
g_insert_with_noti = true;
}
media_svc_debug_fenter();
- if (g_media_svc_insert_item_cur_data_cnt > 0) {
-
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
+ if (g_media_svc_cur_data_cnt > 0) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
if (g_insert_with_noti) {
media_svc_debug("sending noti list");
- _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
- _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
+ _media_svc_publish_noti_list();
g_insert_with_noti = false;
_media_svc_set_noti_from_pid(-1);
}
}
- g_media_svc_insert_item_data_cnt = 1;
- g_media_svc_insert_item_cur_data_cnt = 0;
+ g_media_svc_cur_data_cnt = 0;
return ret;
}
ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
break;
default:
- media_svc_debug("Do nothing[%d]", content_info.media_type);
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
break;
}
content_info.folder_uuid = g_strdup(folder_uuid);
media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
- if (g_media_svc_insert_item_data_cnt == 1) {
-
- ret = _media_svc_insert_item_with_data(true, &content_info, false, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- if (g_insert_with_noti)
- _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
-
- } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
-
- ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- if (g_insert_with_noti)
- _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
-
- g_media_svc_insert_item_cur_data_cnt++;
+ ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
- } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
+ if (g_insert_with_noti)
+ _media_svc_insert_item_to_noti_list(&content_info);
- ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
+ /* 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);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
if (g_insert_with_noti)
- _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
-
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- if (g_insert_with_noti) {
- _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
- _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
-
- /* Recreate noti list */
- ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
- }
-
- g_media_svc_insert_item_cur_data_cnt = 0;
+ _media_svc_publish_noti_list();
- } else {
- media_svc_error("Error in media_svc_insert_item_bulk");
- _media_svc_destroy_content_info(&content_info);
- return MS_MEDIA_ERR_INTERNAL;
+ g_media_svc_cur_data_cnt = 0;
}
_media_svc_destroy_content_info(&content_info);
ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
break;
default:
- media_svc_debug("Do nothing[%d]", content_info.media_type);
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
break;
}
return ret;
}
- if (STRING_VALID(old_thumb_path)) {
- ret = _media_svc_remove_file(old_thumb_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("_media_svc_remove_file failed : %d", ret);
- }
+ _media_svc_remove_file(old_thumb_path);
/*move item*/
ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_uuid, uid);
return MS_MEDIA_ERR_NONE;
}
-int media_svc_set_item_validity_begin(int data_cnt)
-{
- media_svc_debug("Transaction data count : [%d]", data_cnt);
-
- media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
-
- g_media_svc_item_validity_data_cnt = data_cnt;
- g_media_svc_item_validity_cur_data_cnt = 0;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_set_item_validity_end(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_debug_fenter();
-
- if (g_media_svc_item_validity_cur_data_cnt > 0)
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
-
- g_media_svc_item_validity_data_cnt = 1;
- g_media_svc_item_validity_cur_data_cnt = 0;
-
- return ret;
-}
-
int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- if (g_media_svc_item_validity_data_cnt == 1) {
-
- return _media_svc_update_item_validity(path, validity, false, uid);
-
- } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
-
- ret = _media_svc_update_item_validity(path, validity, true, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- g_media_svc_item_validity_cur_data_cnt++;
-
- } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
-
- ret = _media_svc_update_item_validity(path, validity, true, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_update_item_validity(path, validity, true, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
+ /* 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);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- g_media_svc_item_validity_cur_data_cnt = 0;
-
- } else {
-
- media_svc_error("Error in media_svc_set_item_validity");
- return MS_MEDIA_ERR_INTERNAL;
+ g_media_svc_cur_data_cnt = 0;
}
- return MS_MEDIA_ERR_NONE;
+ return ret;
}
int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
_media_svc_destroy_noti_item(noti_item);
/*Delete thumbnail*/
- if (STRING_VALID(thumb_path)) {
- ret = _media_svc_remove_file(thumb_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("fail to remove thumbnail file.");
- }
+ _media_svc_remove_file(thumb_path);
return MS_MEDIA_ERR_NONE;
}
}
if (STRING_VALID(thumb_path)) {
- if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
- ret = _media_svc_remove_file(thumb_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
- }
+ _media_svc_remove_file(thumb_path);
ret = _media_svc_update_thumbnail_path(path, NULL, uid);
if (ret != MS_MEDIA_ERR_NONE) {
}
content_info.media_type = noti_item->media_type;
+ content_info.mime_type = g_strdup(noti_item->mime_type);
- if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
- || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
- || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
- || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
- media_svc_debug("Do nothing [%d]", content_info.media_type);
- else if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+ switch (content_info.media_type) {
+ case MEDIA_SVC_MEDIA_TYPE_IMAGE:
ret = _media_svc_extract_image_metadata(&content_info);
- else
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+ case MEDIA_SVC_MEDIA_TYPE_SOUND:
+ case MEDIA_SVC_MEDIA_TYPE_MUSIC:
ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
+ break;
+ default:
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+ break;
+ }
if (ret != MS_MEDIA_ERR_NONE) {
_media_svc_destroy_noti_item(noti_item);
g_ptr_array_free(path_list, TRUE);
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+ 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 */
int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
{
- int ret = MS_MEDIA_ERR_NONE;
- int count = -1;
-
- ret = _media_svc_count_folder_with_path(handle, storage_id, folder_path, &count);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- if (count > 0) {
- media_svc_debug("item is exist in database");
- return MS_MEDIA_ERR_NONE;
- } else {
- media_svc_debug("item is not exist in database");
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- return MS_MEDIA_ERR_NONE;
+ return _media_svc_check_folder_by_path(handle, storage_id, folder_path);
}
int media_svc_append_query(const char *query, uid_t uid)
return _media_svc_get_media_type(path, mediatype);
}
-int media_svc_create_thumbnail(const char *storage_id, const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
+int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
{
int ret = MS_MEDIA_ERR_NONE;
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
}
// 3. Update creation result to media db
- sql = sqlite3_mprintf("UPDATE '%q' SET media_thumbnail_path='%q' WHERE media_path='%q';", storage_id, thumb_path, file_path);
+ sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, file_path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);