Use get_image_info instead
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc.c
index 9cee4f9..a78f53f 100755 (executable)
@@ -3,8 +3,6 @@
  *
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -186,7 +184,7 @@ int media_svc_insert_item_end(uid_t uid)
        return ret;
 }
 
-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)
+int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        long long int folder_id = 0;
@@ -194,13 +192,12 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
        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, false);
+       ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
        if (ret != MS_MEDIA_ERR_NONE)
                return ret;
 
@@ -209,28 +206,30 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
                ret = _media_svc_extract_image_metadata(&content_info);
                break;
        case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+               ret = _media_svc_extract_video_metadata(&content_info);
+               break;
        case MEDIA_SVC_MEDIA_TYPE_SOUND:
        case MEDIA_SVC_MEDIA_TYPE_MUSIC:
-               ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
+               ret = _media_svc_extract_audio_metadata(handle, true, &content_info, uid);
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
                /* The 'TITLE' should always be filled in */
                if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
                        g_free(content_info.media_meta.title);
-                       content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+                       content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                }
                break;
        default:
                /* The 'TITLE' should always be filled in */
-               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+               content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                break;
        }
 
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        /*Set or Get folder id*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, &folder_id, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, &folder_id, uid);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        content_info.folder_id = folder_id;
@@ -258,7 +257,7 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
        return MS_MEDIA_ERR_NONE;
 }
 
-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)
+int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        long long int folder_id = 0;
@@ -266,13 +265,12 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
        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, false);
+       ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
        if (ret != MS_MEDIA_ERR_NONE)
                return ret;
 
@@ -281,28 +279,30 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
                ret = _media_svc_extract_image_metadata(&content_info);
                break;
        case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+               ret = _media_svc_extract_video_metadata(&content_info);
+               break;
        case MEDIA_SVC_MEDIA_TYPE_SOUND:
        case MEDIA_SVC_MEDIA_TYPE_MUSIC:
-               ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
+               ret = _media_svc_extract_audio_metadata(handle, false, &content_info, uid);
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
                /* The 'TITLE' should always be filled in */
                if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
                        g_free(content_info.media_meta.title);
-                       content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+                       content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                }
                break;
        default:
                /* The 'TITLE' should always be filled in */
-               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+               content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                break;
        }
 
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        /*Set or Get folder id*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, &folder_id, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, &folder_id, uid);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        content_info.folder_id = folder_id;
@@ -347,8 +347,6 @@ int media_svc_move_item(sqlite3 *handle,
        long long int folder_id = 0;
        char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
        char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
-       ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
-       ms_user_storage_type_e dst_stg_type = MS_USER_STORAGE_INTERNAL;
 
        media_svc_debug_fenter();
 
@@ -361,14 +359,9 @@ int media_svc_move_item(sqlite3 *handle,
        /* Get storage_id */
        ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-       /* Get storage_type */
-       ret = ms_user_get_storage_type(uid, src_path, &org_stg_type);
-       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-       ret = ms_user_get_storage_type(uid, dest_path, &dst_stg_type);
-       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        /*check and update folder*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, &folder_id, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, &folder_id, uid);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        /*get filename*/
@@ -388,7 +381,7 @@ int media_svc_move_item(sqlite3 *handle,
        _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_id, uid);
+       ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dest_path, file_name, modified_time, folder_id, uid);
        g_free(file_name);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
@@ -458,7 +451,7 @@ int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const
        return MS_MEDIA_ERR_NONE;
 }
 
-int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
+int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
@@ -468,10 +461,9 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
        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");
 
        /*Set media info*/
-       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, true);
+       ret = _media_svc_set_media_info(&content_info, storage_id, path, true);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        /* Initialize thumbnail information to remake thumbnail. */
@@ -500,21 +492,23 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
                ret = _media_svc_extract_image_metadata(&content_info);
                break;
        case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+               ret = _media_svc_extract_video_metadata(&content_info);
+               break;
        case MEDIA_SVC_MEDIA_TYPE_SOUND:
        case MEDIA_SVC_MEDIA_TYPE_MUSIC:
-               ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
+               ret = _media_svc_extract_audio_metadata(handle, is_direct, &content_info, uid);
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
                /* The 'TITLE' should always be filled in */
                if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
                        g_free(content_info.media_meta.title);
-                       content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+                       content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                }
                break;
        default:
                /* The 'TITLE' should always be filled in */
-               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
+               content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
                break;
        }
 
@@ -572,16 +566,9 @@ int media_svc_publish_noti(media_item_update_type_e update_type, const char *pat
        return _media_svc_publish_noti(update_type, path, media_type, uuid, mime_type);
 }
 
-int media_svc_set_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
+int media_svc_set_storage_validity(const char *storage_id, int validity, uid_t uid)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-
-       media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
-
-       ret = _media_svc_update_storage_validity(storage_id, validity, uid);
-       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
-
-       return ret;
+       return _media_svc_update_storage_validity(storage_id, validity, uid);
 }
 
 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
@@ -599,16 +586,15 @@ int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char
        return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
 }
 
-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)
+int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
-       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
-       ret = _media_svc_append_storage(storage_id, storage_path, storage_type, uid);
+       ret = _media_svc_append_storage(storage_id, storage_path, uid);
        media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
 
        /* Remove external storage that validity is 0 */
@@ -618,14 +604,13 @@ int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char
        return ret;
 }
 
-int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
+int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
 {
        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");
 
-       return _media_svc_append_by_folder_path(handle, storage_id, path, storage_type, uid);
+       return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
 }
 
 int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)