void media_svc_destroy_content_info(media_svc_content_info_s *content_info);
int media_svc_generate_uuid(char **uuid);
-int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist);
int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid);
int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid);
int media_svc_update_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_path, uid_t uid);
Name: libmedia-service
Summary: Media information service library for multimedia applications
-Version: 0.3.29
+Version: 0.3.30
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
-{
- int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
-
- if (handle == NULL) {
- __set_error_message(ERR_HANDLE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
- if (ret < 0) {
- __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- return MEDIA_SVC_PLUGIN_ERROR_NONE;
-}
-
int check_storage(void * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid, char **err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
/* Get thumbnail for burst shot */
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- ret = _media_svc_create_thumbnail(content_info->path, thumb_path, sizeof(thumb_path), content_info->media_type, uid);
+ ret = _media_svc_create_thumbnail(content_info->storage_uuid, content_info->path, thumb_path, sizeof(thumb_path), content_info->media_type, uid);
if (ret == MS_MEDIA_ERR_NONE)
content_info->thumbnail_path = g_strdup(thumb_path);
}
#include "media-svc-util.h"
#include "media-svc-storage.h"
-int _media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- sql = sqlite3_mprintf("SELECT storage_name, storage_path, validity FROM '%q' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- *storage_name = NULL;
- *storage_path = NULL;
- *validity = 0;
- *info_exist = FALSE;
-
- return ret;
- }
-
- *storage_name = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 1));
- *validity = sqlite3_column_int(sql_stmt, 2);
-
- *info_exist = TRUE;
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
return ret;
}
+int _media_svc_delete_invalid_storage(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+ char *storage_id = NULL;
+ char *thumb_path = NULL;
+ sqlite3_stmt *sql_stmt = NULL;
+ GArray *storage_list = NULL;
+
+ /* Get invalid storage_uuid (with storage_type)*/
+ sql = sqlite3_mprintf("SELECT storage_uuid FROM '%q' WHERE validity = 0 AND storage_type=%d;", MEDIA_SVC_DB_TABLE_STORAGE, storage_type);
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ storage_list = g_array_new(false, false, sizeof(char *));
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ storage_id = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ if (storage_id != NULL)
+ g_array_append_val(storage_list, storage_id);
+
+ storage_id = NULL;
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ while (storage_list->len > 0) {
+ storage_id = g_array_index(storage_list, char *, 0);
+ storage_list = g_array_remove_index(storage_list, 0);
+
+ ret = ms_user_get_thumb_store_path(uid, storage_type, storage_id, &thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to get thumbnail directory");
+ goto ERROR;
+ }
+
+ ret = _media_svc_remove_dir(storage_type, thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to remove thumbnail directory[%s]", thumb_path);
+ goto ERROR;
+ }
+
+ /* remove media before drop table (for clear playlist, and tag table)*/
+ sql = sqlite3_mprintf("DELETE FROM '%q';DROP TABLE '%q';", storage_id);
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to drop table[%s]", storage_id);
+ goto ERROR;
+ }
+
+ SAFE_FREE(storage_id);
+ }
+
+ /* Update storage, folder table */
+ sql = sqlite3_mprintf("DELETE FROM '%q' WHERE validity=0 AND storage_type=%d;DELETE FROM '%q' WHERE validity=0 AND storage_type=%d;",
+ MEDIA_SVC_DB_TABLE_STORAGE, storage_type, MEDIA_SVC_DB_TABLE_FOLDER, storage_type);
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to update storage table");
+ goto ERROR;
+ }
+
+ERROR:
+ SAFE_FREE(storage_id);
+ SAFE_FREE(thumb_path);
+
+ while (storage_list->len > 0) {
+ storage_id = g_array_index(storage_list, char *, 0);
+ storage_list = g_array_remove_index(storage_list, 0);
+ SAFE_FREE(storage_id);
+ }
+
+ g_array_free(storage_list, false);
+ storage_list = NULL;
+
+ return ret;
+}
+
int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
if (storage_id == NULL)
- sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, validity);
+ sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid!='media';", MEDIA_SVC_DB_TABLE_STORAGE, validity);
else
sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, validity, storage_id);
}
}
-int _media_svc_remove_all_files_in_dir(const char *dir_path)
+int _media_svc_remove_dir(media_svc_storage_type_e storage_type, const char *dir_path)
{
char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
GDir *dir = NULL;
g_dir_close(dir);
+ if (storage_type != MEDIA_SVC_STORAGE_INTERNAL) {
+ /* Remove directory when external storage */
+ if (g_rmdir(dir_path) != 0) {
+ media_svc_error("Failed to remove directory");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+ }
+
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
+int _media_svc_get_thumbnail_path(const char *storage_id, media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
char *thumb_dir = NULL;
char *thumbfile_ext = NULL;
- ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
+ ret = ms_user_get_thumb_store_path(uid, storage_type, storage_id, &thumb_dir);
if (!STRING_VALID(thumb_dir)) {
media_svc_error("ms_user_get_thumb_store_path failed");
return MS_MEDIA_ERR_INTERNAL;
mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
- ret = _media_svc_get_thumbnail_path(content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid);
+ ret = _media_svc_get_thumbnail_path(content_info->storage_uuid, content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("Fail to Get Thumbnail Path");
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid)
+int _media_svc_create_thumbnail(const char *storage_id, const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
unsigned int origin_w = 0;
media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
//1. make hash path
- ret = _media_svc_get_thumbnail_path(store_type, media_type, thumb_path, path, THUMB_EXT, uid);
+ ret = _media_svc_get_thumbnail_path(storage_id, store_type, media_type, thumb_path, path, THUMB_EXT, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
+ ret = _media_svc_create_thumbnail(content_info.storage_uuid, content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
if (ret == MS_MEDIA_ERR_NONE)
content_info.thumbnail_path = g_strdup(thumb_path);
}
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
- ret = ms_user_get_thumb_store_path(uid, (ms_user_storage_type_e)storage_type, &thumb_path);
+ ret = ms_user_get_thumb_store_path(uid, (ms_user_storage_type_e)storage_type, storage_id, &thumb_path);
if (!STRING_VALID(thumb_path)) {
media_svc_error("fail to get thumbnail path");
return MS_MEDIA_ERR_INTERNAL;
}
- ret = _media_svc_remove_all_files_in_dir(thumb_path);
+ ret = _media_svc_remove_dir(storage_type, thumb_path);
SAFE_FREE(thumb_path);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
}
if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
memset(thumb_path, 0, sizeof(thumb_path));
- ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
+ ret = _media_svc_create_thumbnail(content_info.storage_uuid, content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
if (ret == MS_MEDIA_ERR_NONE)
content_info.thumbnail_path = g_strdup(thumb_path);
}
return ret;
}
- ret = _media_svc_get_thumbnail_path(storage_type, media_type, media_new_thumb_path, media_path, THUMB_EXT, uid);
+ ret = _media_svc_get_thumbnail_path(storage_id, storage_type, media_type, media_new_thumb_path, media_path, THUMB_EXT, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
SQLITE3_FINALIZE(sql_stmt);
if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- ret = _media_svc_create_thumbnail(_new_content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
+ ret = _media_svc_create_thumbnail(_new_content_info.storage_uuid, _new_content_info.path, thumb_path, sizeof(thumb_path), media_type, uid);
if (ret == MS_MEDIA_ERR_NONE)
_new_content_info.thumbnail_path = g_strdup(thumb_path);
}
return MS_MEDIA_ERR_NONE;
}
-int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
-{
- sqlite3 * db_handle = (sqlite3 *)handle;
-
- media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
-
- return _media_svc_get_mmc_info(db_handle, storage_name, storage_path, validity, info_exist);
-}
-
int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
ret = _media_svc_append_storage(storage_id, storage_name, storage_path, storage_type, uid);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
- if (strcmp(storage_id, MEDIA_SVC_DB_TABLE_MEDIA)) {
- ret = _media_svc_create_media_table_with_id(storage_id, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
+ ret = _media_svc_create_media_table_with_id(storage_id, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
- ret = _media_svc_update_media_view(db_handle, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
- }
+ ret = _media_svc_update_media_view(db_handle, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
+
+ /* Remove external storage that validity is 0 */
+ ret = _media_svc_delete_invalid_storage(db_handle, storage_type, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
return ret;
}
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("fail to _media_svc_delete_folder_by_storage_id. error : [%d]", ret);
- if (storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) {
+ if (storage_type != MEDIA_SVC_STORAGE_INTERNAL) {
ret = _media_svc_drop_media_table(storage_id, uid);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop table failed : %d", ret);
return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
// 2. try to create thumbnail
- ret = _media_svc_create_thumbnail(file_path, thumb_path, MEDIA_SVC_PATHNAME_SIZE, media_type, uid);
+ ret = _media_svc_create_thumbnail(storage_id, file_path, thumb_path, MEDIA_SVC_PATHNAME_SIZE, media_type, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("Failed to create thumbnail [%d]", ret);
if (ret == MS_MEDIA_ERR_UNSUPPORTED_CONTENT)
#include <sqlite3.h>
-int _media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist);
int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid);
int _media_svc_append_storage(const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid);
int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
int _media_svc_delete_storage(const char *storage_id, uid_t uid);
+int _media_svc_delete_invalid_storage(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid);
int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid);
int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid);
int _media_svc_get_storage_type(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e *storage_type);
char *_media_info_generate_uuid(void);
int _media_svc_rename_file(const char *old_name, const char *new_name);
int _media_svc_remove_file(const char *path);
-int _media_svc_remove_all_files_in_dir(const char *dir_path);
-int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
+int _media_svc_remove_dir(media_svc_storage_type_e storage_type, const char *dir_path);
+int _media_svc_get_thumbnail_path(const char *storage_id, media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
int _media_svc_get_file_time(const char *full_path);
int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh);
int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid);
time_t __media_svc_get_timeline_from_str(const char *timstr);
void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
-int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid);
+int _media_svc_create_thumbnail(const char *storage_id, const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid);
int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);
bool _media_svc_check_pinyin_support(void);
int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type);