summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt1
-rwxr-xr-xinclude/media-svc-types.h7
-rwxr-xr-xinclude/media-svc.h18
-rwxr-xr-xplugin/media-content-plugin.c250
-rwxr-xr-xsrc/common/media-svc-db-utils.c1348
-rwxr-xr-xsrc/common/media-svc-media-folder.c278
-rwxr-xr-xsrc/common/media-svc-media.c243
-rwxr-xr-xsrc/common/media-svc-noti.c69
-rwxr-xr-xsrc/common/media-svc-storage.c95
-rwxr-xr-xsrc/common/media-svc-storage.h32
-rwxr-xr-xsrc/common/media-svc-util.c1632
-rwxr-xr-xsrc/common/media-svc.c925
-rwxr-xr-xsrc/include/common/media-svc-db-utils.h22
-rwxr-xr-xsrc/include/common/media-svc-env.h108
-rwxr-xr-xsrc/include/common/media-svc-media-folder.h9
-rwxr-xr-xsrc/include/common/media-svc-media.h15
-rwxr-xr-xsrc/include/common/media-svc-util.h93
-rw-r--r--test/media-service-test.c4
-rwxr-xr-xtest/plugin/media_svc_plugin_test.c35
19 files changed, 3507 insertions, 1677 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a189fd8..fe2b706 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@ SET(SRCS
src/common/media-svc-util.c
src/common/media-svc-debug.c
src/common/media-svc-noti.c
+ src/common/media-svc-storage.c
src/common/media-svc-localize-utils.c
src/common/media-svc-localize_ch.c
src/common/media-svc-localize_tw.c
diff --git a/include/media-svc-types.h b/include/media-svc-types.h
index e5dbe55..b9bc3c2 100755
--- a/include/media-svc-types.h
+++ b/include/media-svc-types.h
@@ -32,9 +32,10 @@ typedef void MediaSvcHandle; /**< Handle */
* Type definition for storage type
*/
typedef enum{
- MEDIA_SVC_STORAGE_INTERNAL, /**< Internal storage*/
- MEDIA_SVC_STORAGE_EXTERNAL, /**< External storage*/
- MEDIA_SVC_STORAGE_MAX, /**< Invalid storage*/
+ MEDIA_SVC_STORAGE_INTERNAL = 0, /**< Internal storage*/
+ MEDIA_SVC_STORAGE_EXTERNAL = 1, /**< External storage*/
+ MEDIA_SVC_STORAGE_CLOUD = 100, /**< Cloud Storage*/
+ MEDIA_SVC_STORAGE_MAX, /**< Invalid storage*/
}media_svc_storage_type_e;
/**
diff --git a/include/media-svc.h b/include/media-svc.h
index 5f1e2e3..c892688 100755
--- a/include/media-svc.h
+++ b/include/media-svc.h
@@ -26,6 +26,7 @@
#include "media-svc-types.h"
#include <media-util-noti.h>
+#include <time.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
@@ -56,17 +57,26 @@ int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *fold
int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *storage_id, const char *path, uid_t uid);
int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, const char *src_path, const char *dst_path, uid_t uid);
int media_svc_request_update_db(const char *db_query, uid_t uid);
-int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type);
-int media_svc_get_mime_type(const char *path, char *mimetype);
-int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
+int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid);
+int media_svc_get_file_info(MediaSvcHandle *handle, const char *path, time_t *modified_time, unsigned long long *size);
int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path);
int media_svc_count_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path, int *count);
+int media_svc_check_db_upgrade(MediaSvcHandle *handle, uid_t uid);
+int media_svc_check_db_corrupt(MediaSvcHandle *handle);
+int media_svc_get_folder_list(MediaSvcHandle *handle, char* start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count);
+int media_svc_update_folder_time(MediaSvcHandle *handle, const char *folder_path, uid_t uid);
int media_svc_publish_noti(MediaSvcHandle *handle, media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type);
int media_svc_get_pinyin(MediaSvcHandle *handle, const char * src_str, char **pinyin_str);
int media_svc_check_pinyin_support(bool *support);
-int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info);
+int media_svc_update_item_begin(MediaSvcHandle *handle, int data_cnt);
+int media_svc_update_item_end(MediaSvcHandle *handle, uid_t uid);
+int media_svc_update_item_meta(MediaSvcHandle *handle, const char *file_path, int storage_type, uid_t uid);
+int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info, uid_t uid);
void media_svc_destroy_content_info(media_svc_content_info_s *content_info);
char *media_info_generate_uuid(void);
+int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid);
+int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, uid_t uid);
+int media_svc_request_extract_all_thumbs(uid_t uid);
diff --git a/plugin/media-content-plugin.c b/plugin/media-content-plugin.c
index fc9f035..b4333b8 100755
--- a/plugin/media-content-plugin.c
+++ b/plugin/media-content-plugin.c
@@ -20,6 +20,7 @@
*/
#include <string.h>
+#include <sys/stat.h>
#include <mm_file.h>
#include <media-thumbnail.h>
#include "media-svc.h"
@@ -88,19 +89,9 @@ static void __set_error_message(int err_type, char ** err_msg)
return;
}
-int check_item(const char *file_path, char ** err_msg)
-{
- if (!STRING_VALID(file_path)) {
- __set_error_message(ERR_FILE_PATH, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- return MEDIA_SVC_PLUGIN_ERROR_NONE;
-}
-
int connect_db(void ** handle, uid_t uid, char ** err_msg)
{
- int ret = media_svc_connect(handle,uid);
+ int ret = media_svc_connect(handle, uid);
if(ret < 0) {
__set_error_message(ret, err_msg);
@@ -128,9 +119,10 @@ int disconnect_db(void * handle, char ** err_msg)
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
+int check_item_exist(void* handle, const char *file_path, bool *modified, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+ *modified = TRUE;
if(handle == NULL) {
__set_error_message(ERR_HANDLE, err_msg);
@@ -142,13 +134,23 @@ int check_item_exist(void* handle, const char *file_path, int storage_type, char
return MEDIA_SVC_PLUGIN_ERROR;
}
- if(!STORAGE_VALID(storage_type)) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
ret = media_svc_check_item_exist_by_path(handle, file_path);
if(ret == MS_MEDIA_ERR_NONE) {
+ time_t modified_time = 0;
+ unsigned long long file_size = 0;
+ struct stat st;
+
+ ret = media_svc_get_file_info(handle, file_path, &modified_time, &file_size);
+ if(ret == MS_MEDIA_ERR_NONE) {
+ memset(&st, 0, sizeof(struct stat));
+ if (stat(file_path, &st) == 0) {
+ if((st.st_mtime != modified_time) || (st.st_size != file_size))
+ *modified = TRUE;
+ else
+ *modified = FALSE;
+ }
+ }
+
return MEDIA_SVC_PLUGIN_ERROR_NONE; //exist
}
@@ -277,70 +279,6 @@ int insert_burst_item(void * handle, const char *file_path, int storage_type, ui
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int move_item_begin(void * handle, int item_cnt, 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_move_item_begin(handle, item_cnt);
- if(ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- return MEDIA_SVC_PLUGIN_ERROR_NONE;
-}
-
-int move_item_end(void * handle, uid_t uid, 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_move_item_end(handle, uid);
- if(ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- return MEDIA_SVC_PLUGIN_ERROR_NONE;
-}
-
-int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, uid_t uid, 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;
- }
-
- if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
- __set_error_message(ERR_FILE_PATH, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path, uid);
- if(ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- return MEDIA_SVC_PLUGIN_ERROR_NONE;
-}
-
int set_all_storage_items_validity(void * handle, int storage_type, int validity, uid_t uid, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
@@ -452,7 +390,7 @@ int set_item_validity(void * handle, const char *file_path, int storage_type, in
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int delete_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
+int delete_item(void * handle, const char *file_path, uid_t uid, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
@@ -466,11 +404,6 @@ int delete_item(void * handle, const char *file_path, int storage_type, uid_t ui
return MEDIA_SVC_PLUGIN_ERROR;
}
- if(!STORAGE_VALID(storage_type)) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
ret = media_svc_check_item_exist_by_path(handle, file_path);
if(ret == 0) {
ret = media_svc_delete_item_by_path(handle, "media", file_path, uid);
@@ -556,27 +489,43 @@ int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, u
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int delete_all_items(void * handle, uid_t uid ,char ** err_msg)
+
+int update_begin(void)
+{
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_end(uid_t uid)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
- if(handle == NULL) {
- __set_error_message(ERR_HANDLE, err_msg);
+ ret = thumbnail_request_extract_all_thumbs(uid);
+ if (ret < 0) {
return MEDIA_SVC_PLUGIN_ERROR;
}
- ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, uid, err_msg);
- if(ret < 0)
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if (!STRING_VALID(dir_path)) {
+ __set_error_message(ERR_FOLDER_PATH, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
+ }
- ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, uid, err_msg);
- if(ret < 0)
+ ret = media_svc_send_dir_update_noti(handle, dir_path);
+ if (ret < 0) {
+ __set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
+ }
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int refresh_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
+int count_delete_items_in_folder(void * handle, const char *folder_path, int *count, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
@@ -585,17 +534,17 @@ int refresh_item(void * handle, const char *file_path, int storage_type, uid_t u
return MEDIA_SVC_PLUGIN_ERROR;
}
- if (!STRING_VALID(file_path)) {
- __set_error_message(ERR_FILE_PATH, err_msg);
+ if(count == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
- if(!STORAGE_VALID(storage_type)) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ if (!STRING_VALID(folder_path)) {
+ __set_error_message(ERR_FOLDER_PATH, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
- ret = media_svc_refresh_item(handle, storage_type, "media", file_path, uid);
+ ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
if(ret < 0) {
__set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
@@ -604,33 +553,56 @@ int refresh_item(void * handle, const char *file_path, int storage_type, uid_t u
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int update_begin(void)
+int check_db(void * handle, uid_t uid, char **err_msg)
{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ /*check db schema*/
+ ret = media_svc_create_table(handle, uid);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ /*check db version*/
+ ret = media_svc_check_db_upgrade(handle, uid);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int update_end(uid_t uid)
+int check_db_corrupt(void * handle, char **err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
- ret = thumbnail_request_extract_all_thumbs(uid);
+ /*check db version*/
+ ret = media_svc_check_db_corrupt(handle);
if(ret < 0) {
+ __set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
+int get_folder_list(void * handle, char* start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
- if (!STRING_VALID(dir_path)) {
- __set_error_message(ERR_FOLDER_PATH, err_msg);
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
- ret = media_svc_send_dir_update_noti(handle, dir_path);
+ if(count == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t**)modified_time_list, item_num_list, count);
if(ret < 0) {
__set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
@@ -639,7 +611,7 @@ int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
-int count_delete_items_in_folder(void * handle, const char *folder_path, int *count, char ** err_msg)
+int update_folder_time(void * handle, char *folder_path, uid_t uid, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
@@ -648,17 +620,71 @@ int count_delete_items_in_folder(void * handle, const char *folder_path, int *co
return MEDIA_SVC_PLUGIN_ERROR;
}
- if(count == NULL) {
+ if(folder_path == NULL) {
__set_error_message(ERR_HANDLE, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
- if (!STRING_VALID(folder_path)) {
- __set_error_message(ERR_FOLDER_PATH, err_msg);
+ ret = media_svc_update_folder_time(handle, folder_path, uid);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
}
- ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_item_begin(void * handle, int item_cnt, 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_update_item_begin(handle, item_cnt);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_item_end(void * handle, uid_t uid, 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_update_item_end(handle, uid);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_item_meta(void * handle, const char *file_path, int storage_type, uid_t uid, 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;
+ }
+
+ if(file_path == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
if(ret < 0) {
__set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c
index 564b865..333dd69 100755
--- a/src/common/media-svc-db-utils.c
+++ b/src/common/media-svc-db-utils.c
@@ -24,6 +24,8 @@
#include <db-util.h>
#include <media-util.h>
#include <errno.h>
+#include <grp.h>
+#include <pwd.h>
#include "media-svc-env.h"
#include "media-svc-debug.h"
#include "media-svc-util.h"
@@ -32,615 +34,761 @@
#include "media-util-db.h"
#include "media-svc-media.h"
-static int __media_svc_create_update_media_table(sqlite3 *db_handle);
-
-#define MEDIA_DB_SCHEMA "CREATE TABLE IF NOT EXISTS %s (\
- media_uuid TEXT PRIMARY KEY, \
- path TEXT NOT NULL UNIQUE, \
- file_name TEXT NOT NULL, \
- media_type INTEGER,\
- mime_type TEXT, \
- size INTEGER DEFAULT 0, \
- added_time INTEGER DEFAULT 0,\
- modified_time INTEGER DEFAULT 0, \
- folder_uuid TEXT NOT NULL, \
- thumbnail_path TEXT, \
- title TEXT, \
- album_id INTEGER DEFAULT 0, \
- album TEXT, \
- artist TEXT, \
- album_artist TEXT, \
- genre TEXT, \
- composer TEXT, \
- year TEXT, \
- recorded_date TEXT, \
- copyright TEXT, \
- track_num TEXT, \
- description TEXT, \
- bitrate INTEGER DEFAULT -1, \
- bitpersample INTEGER DEFAULT 0, \
- samplerate INTEGER DEFAULT -1, \
- channel INTEGER DEFAULT -1, \
- duration INTEGER DEFAULT -1, \
- longitude DOUBLE DEFAULT 0, \
- latitude DOUBLE DEFAULT 0, \
- altitude DOUBLE DEFAULT 0, \
- exposure_time TEXT, \
- fnumber DOUBLE DEFAULT 0, \
- iso INTEGER DEFAULT -1, \
- model TEXT, \
- width INTEGER DEFAULT -1, \
- height INTEGER DEFAULT -1, \
- datetaken TEXT, \
- orientation INTEGER DEFAULT -1, \
- burst_id TEXT, \
- played_count INTEGER DEFAULT 0, \
- last_played_time INTEGER DEFAULT 0, \
- last_played_position INTEGER DEFAULT 0, \
- rating INTEGER DEFAULT 0, \
- favourite INTEGER DEFAULT 0, \
- author TEXT, \
- provider TEXT, \
- content_name TEXT, \
- category TEXT, \
- location_tag TEXT, \
- age_rating TEXT, \
- keyword TEXT, \
- is_drm INTEGER DEFAULT 0, \
- storage_type INTEGER, \
- timeline INTEGER DEFAULT 0, \
- weather TEXT, \
- sync_status INTEGER DEFAULT 0, \
- file_name_pinyin TEXT, \
- title_pinyin TEXT, \
- album_pinyin TEXT, \
- artist_pinyin TEXT, \
- album_artist_pinyin TEXT, \
- genre_pinyin TEXT, \
- composer_pinyin TEXT, \
- copyright_pinyin TEXT, \
- description_pinyin TEXT, \
- author_pinyin TEXT, \
- provider_pinyin TEXT, \
- content_name_pinyin TEXT, \
- category_pinyin TEXT, \
- location_tag_pinyin TEXT, \
- age_rating_pinyin TEXT, \
- keyword_pinyin TEXT, \
- validity INTEGER DEFAULT 1, \
- storage_uuid TEXT, \
- unique(path, file_name) \
- );"
-
-static int __media_svc_busy_handler(void *pData, int count);
-
-static int __media_svc_busy_handler(void *pData, int count)
-{
- usleep(50000);
+static int __media_svc_db_upgrade(sqlite3 *db_handle, uid_t uid);
+static int __media_svc_rebuild_view_query(sqlite3 *db_handle, uid_t uid);
- media_svc_debug("media_svc_busy_handler called : %d", count);
- return 100 - count;
-}
+static GHashTable *table;
+static GSList *column_list[MEDIA_SVC_DB_LIST_MAX];
-int _media_svc_connect_db_with_handle(sqlite3 **db_handle)
+char* _media_svc_get_path(uid_t uid)
{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_debug_func();
-
- /*Connect DB*/
- ret = db_util_open(MEDIA_SVC_DB_NAME, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
-
- if (SQLITE_OK != ret) {
-
- media_svc_error("error when db open");
- *db_handle = NULL;
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- /*Register busy handler*/
- if (*db_handle) {
- ret = sqlite3_busy_handler(*db_handle, __media_svc_busy_handler, NULL);
-
- if (SQLITE_OK != ret) {
-
- if (*db_handle) {
- media_svc_error("[error when register busy handler] %s\n", sqlite3_errmsg(*db_handle));
- }
-
- db_util_close(*db_handle);
- *db_handle = NULL;
-
- return MS_MEDIA_ERR_DB_INTERNAL;
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
}
- } else {
- *db_handle = NULL;
- return MS_MEDIA_ERR_DB_INTERNAL;
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ media_svc_error("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ media_svc_error("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
}
- return MS_MEDIA_ERR_NONE;
+ return result_psswd;
}
-int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle)
+int __media_svc_add_table_info(char *name, char *triggerName, char *eventTable, char *actionTable, char *viewName)
{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_debug_func();
-
- ret = db_util_close(db_handle);
+ table_info *tbl = NULL;
+ tbl = malloc(sizeof(table_info));
+ if(tbl == NULL) {
+ media_svc_error("MS_MEDIA_ERR_OUT_OF_MEMORY");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+ memset(tbl, 0, sizeof(table_info));
- if (SQLITE_OK != ret) {
- media_svc_error("Error when db close : %s", sqlite3_errmsg(db_handle));
- db_handle = NULL;
- return MS_MEDIA_ERR_DB_INTERNAL;
+ if(triggerName != NULL) {
+ tbl->triggerName = strndup(triggerName, strlen(triggerName));
+ tbl->eventTable = strndup(eventTable, strlen(eventTable));
+ tbl->actionTable = strndup(actionTable, strlen(actionTable));
}
+ if(viewName != NULL) {
+ tbl->viewName = strndup(viewName, strlen(viewName));
+ }
+ g_hash_table_insert(table, name, tbl);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_media_table(sqlite3 *db_handle, uid_t uid)
+int __media_svc_add_column_info(GSList **slist, char *name, char *type, char *option, int version, char *indexName, bool isUnique, bool isTrigger, bool isView)
{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- media_svc_debug_func();
-
- sql = sqlite3_mprintf(MEDIA_DB_SCHEMA, MEDIA_SVC_DB_TABLE_MEDIA);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ column_info *col = NULL;
+ col = malloc(sizeof(column_info));
+ if(col == NULL) {
+ media_svc_error("MS_MEDIA_ERR_OUT_OF_MEMORY");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
+ memset(col, 0, sizeof(column_info));
- /* Create Index*/
- sql = sqlite3_mprintf(" CREATE INDEX IF NOT EXISTS media_media_type_idx on %s (media_type); \
- CREATE INDEX IF NOT EXISTS media_title_idx on %s (title); \
- CREATE INDEX IF NOT EXISTS media_modified_time_idx on %s (modified_time); \
- CREATE INDEX IF NOT EXISTS media_provider_idx on %s (provider); \
- CREATE INDEX IF NOT EXISTS folder_uuid_idx on %s (folder_uuid); \
- CREATE INDEX IF NOT EXISTS media_album_idx on %s (album); \
- CREATE INDEX IF NOT EXISTS media_artist_idx on %s (artist); \
- CREATE INDEX IF NOT EXISTS media_author_idx on %s (author); \
- CREATE INDEX IF NOT EXISTS media_category_idx on %s (category); \
- CREATE INDEX IF NOT EXISTS media_composer_idx on %s (composer); \
- CREATE INDEX IF NOT EXISTS media_content_name_idx on %s (content_name); \
- CREATE INDEX IF NOT EXISTS media_file_name_idx on %s (file_name); \
- CREATE INDEX IF NOT EXISTS media_genre_idx on %s (genre); \
- CREATE INDEX IF NOT EXISTS media_location_tag_idx on %s (location_tag); \
- CREATE INDEX IF NOT EXISTS media_media_uuid_idx on %s (media_uuid); \
- CREATE INDEX IF NOT EXISTS media_timeline_idx on %s (timeline); \
- CREATE INDEX IF NOT EXISTS media_path_idx on %s (path); \
- ",
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA,
- MEDIA_SVC_DB_TABLE_MEDIA);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ col->name = strndup(name, strlen(name));
+ col->type = strndup(type, strlen(type));
+ if(option != NULL) {
+ col->hasOption = true;
+ col->option = strndup(option, strlen(option));
+ } else {
+ col->hasOption = false;
+ }
+ col->version = version;
+ if(indexName != NULL) {
+ col->isIndex = true;
+ col->indexName = strndup(indexName, strlen(indexName));
+ } else {
+ col->isIndex = false;
}
+ col->isUnique = isUnique;
+ col->isTrigger = isTrigger;
+ col->isView = isView;
+ *slist = g_slist_append(*slist, col);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_folder_table(sqlite3 *db_handle, uid_t uid)
+static int __media_svc_rebuild_view_query(sqlite3 *db_handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
+ column_info *col_ptr = NULL;
char *sql = NULL;
-
- media_svc_debug_func();
-
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- folder_uuid TEXT PRIMARY KEY, \
- path TEXT NOT NULL UNIQUE, \
- name TEXT NOT NULL, \
- modified_time INTEGER DEFAULT 0, \
- name_pinyin TEXT, \
- storage_type INTEGER, \
- unique(path, name, storage_type) \
- );",
- MEDIA_SVC_DB_TABLE_FOLDER);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
+ char table_query[4096] = {0,};
+ char temp[1024] = {0,};
+ int table_len = 0;
+ int i, len;
+ //media
+ _media_svc_update_media_view(db_handle, uid);
+
+ //drop playlist_view, tag_view
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_DROP_VIEW, MEDIA_SVC_DB_VIEW_PLAYLIST);
ret = _media_svc_sql_query(db_handle, sql, uid);
sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- /* Create Trigger to remove folder which have no content from folder when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS folder_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s \
- WHERE (SELECT count(*) FROM %s WHERE folder_uuid=old.folder_uuid)=1 AND folder_uuid=old.folder_uuid;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_MEDIA);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_DROP_VIEW, MEDIA_SVC_DB_VIEW_TAG);
ret = _media_svc_sql_query(db_handle, sql, uid);
sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ //create playlist_view
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST], i);
+ if(col_ptr->isView) {
+ if(table_len > 0) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_THUMBNAIL, strlen(MEDIA_SVC_DB_COLUMN_THUMBNAIL)) == 0)
+ snprintf(temp, sizeof(temp), ", playlist.%s AS p_thumbnail_path", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", playlist.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "playlist.%s", col_ptr->name);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], i);
+ if(col_ptr->isView) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
+ snprintf(temp, sizeof(temp), ", playlist_map.%s AS pm_id", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", playlist_map.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
}
- /* Create Index*/
- sql = sqlite3_mprintf(" CREATE INDEX IF NOT EXISTS folder_folder_uuid_idx on %s (folder_uuid); \
- ",
- MEDIA_SVC_DB_TABLE_FOLDER);
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
+ if(col_ptr->isView) {
+ snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_PLAYLIST, MEDIA_SVC_DB_VIEW_PLAYLIST, table_query);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ //create tag_view
+ table_len = 0;
+ memset(table_query, 0, sizeof(table_query));
+
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG], i);
+ if(col_ptr->isView) {
+ if(table_len > 0) {
+ snprintf(temp, sizeof(temp), ", tag.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "tag.%s", col_ptr->name);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG_MAP]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG_MAP], i);
+ if(col_ptr->isView) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
+ snprintf(temp, sizeof(temp), ", tag_map.%s AS tm_id", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", tag_map.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
+ if(col_ptr->isView) {
+ snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_TAG, MEDIA_SVC_DB_VIEW_TAG, table_query);
ret = _media_svc_sql_query(db_handle, sql, uid);
sqlite3_free(sql);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_playlist_table(sqlite3 *db_handle, uid_t uid)
+int _media_svc_make_table_query(sqlite3 *db_handle, const char *table_name, media_svc_table_slist_e list, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char * sql = NULL;
-
- media_svc_debug_func();
-
- /*Create playlist table*/
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- playlist_id INTEGER PRIMARY KEY AUTOINCREMENT, \
- name TEXT NOT NULL UNIQUE,\
- name_pinyin TEXT, \
- thumbnail_path TEXT\
- );",
- MEDIA_SVC_DB_TABLE_PLAYLIST);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ table_info *tb = NULL;
+ column_info *col_ptr = NULL;
+ char *sql = NULL;
+ char table_query[4096] = {0,};
+ char index_query[4096] = {0,};
+ char trigger_query[4096] = {0,};
+ char table_query_sub[1024] = {0,};
+ char temp[1024] = {0,};
+ int table_len = 0;
+ int index_len = 0;
+ int trigger_len = 0;
+ int table_sub_len = 0;
+ int len = 0;
+ int i = 0;
+ sqlite3_stmt *sql_stmt = NULL;
+ int storage_cnt = 0;
+
+ tb = g_hash_table_lookup(table, table_name);
+ len = g_slist_length(column_list[list]);
+
+ if(len == 0)
+ {
+ media_svc_error("Invalid column");
+ return MS_MEDIA_ERR_INTERNAL;
}
- /*Create playlist_map table*/
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- _id INTEGER PRIMARY KEY AUTOINCREMENT, \
- playlist_id INTEGER NOT NULL,\
- media_uuid TEXT NOT NULL,\
- play_order INTEGER NOT NULL\
- );",
- MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[list], i);
+ //create table
+ if(col_ptr->hasOption) {
+ if(table_len > 0) {
+ snprintf(temp, sizeof(temp), ", %s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ } else {
+ if(table_len > 0) {
+ snprintf(temp, sizeof(temp), ", %s %s", col_ptr->name, col_ptr->type);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "%s %s", col_ptr->name, col_ptr->type);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ //unique
+ if(col_ptr->isUnique) {
+ if(table_sub_len > 0) {
+ snprintf(temp, sizeof(temp), ", %s", col_ptr->name);
+ strncat(table_query_sub, temp, strlen(temp));
+ table_sub_len = strlen(table_query_sub);
+ } else {
+ snprintf(temp, sizeof(temp), "%s", col_ptr->name);
+ strncpy(table_query_sub, temp, strlen(temp));
+ table_sub_len = strlen(table_query_sub);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ //create index
+ if(col_ptr->isIndex) {
+ if(index_len > 0) {
+ snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_INDEX, col_ptr->indexName, table_name, col_ptr->name);
+ strncat(index_query, temp, strlen(temp));
+ index_len = strlen(index_query);
+ } else {
+ snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_INDEX, col_ptr->indexName, table_name, col_ptr->name);
+ strncpy(index_query, temp, strlen(temp));
+ index_len = strlen(index_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ //create trigger
+ if(col_ptr->isTrigger) {
+ if(strncmp(table_name, MEDIA_SVC_DB_TABLE_ALBUM, strlen(MEDIA_SVC_DB_TABLE_ALBUM)) == 0) {
+ snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_TRIGGER_WITH_COUNT, tb->triggerName, tb->eventTable, tb->actionTable, tb->eventTable, col_ptr->name, col_ptr->name, col_ptr->name, col_ptr->name);
+ strncpy(trigger_query, temp, strlen(temp));
+ trigger_len = strlen(trigger_query);
+ } else {
+ snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_TRIGGER, tb->triggerName, tb->eventTable, tb->actionTable, col_ptr->name, col_ptr->name);
+ strncpy(trigger_query, temp, strlen(temp));
+ trigger_len = strlen(trigger_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ }
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ //send queries
+ if(table_sub_len > 0) {
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_TABLE_WITH_UNIQUE, table_name, table_query, table_query_sub);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ memset(table_query, 0, sizeof(table_query));
+ memset(table_query_sub, 0, sizeof(table_query_sub));
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ } else {
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_TABLE, table_name, table_query);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ memset(table_query, 0, sizeof(table_query));
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
}
- /* Create playlist_view*/
- sql = sqlite3_mprintf(" \
- CREATE VIEW IF NOT EXISTS playlist_view AS \
- SELECT p.playlist_id, p.name, p.thumbnail_path AS p_thumbnail_path, media_count, pm._id as pm_id, pm.play_order, m.media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, m.thumbnail_path, description, rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel, weather, burst_id, timeline, sync_status, bitpersample FROM playlist AS p \
- INNER JOIN playlist_map AS pm \
- INNER JOIN media AS m \
- INNER JOIN (SELECT count(playlist_id) as media_count, playlist_id FROM playlist_map group by playlist_id) as cnt_tbl \
- ON (p.playlist_id=pm.playlist_id AND pm.media_uuid = m.media_uuid AND cnt_tbl.playlist_id=pm.playlist_id AND m.validity=1) \
- UNION \
- SELECT playlist_id, name, thumbnail_path, 0, 0, -1, NULL, NULL, -1, -1, -1, -1, -1, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, 0, -1, -1, -1, NULL, 0, -1, NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, NULL, -1, NULL, NULL, -1, 0, 0 FROM playlist \
- WHERE playlist_id NOT IN (select playlist_id from playlist_map) \
- UNION \
- SELECT playlist_id, name, thumbnail_path, 0, 0, -1, NULL, NULL, -1, -1, -1, -1, -1, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, 0, -1, -1, -1, NULL, 0, -1, NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, NULL, -1, NULL, NULL, -1, 0, 0 FROM playlist \
- WHERE playlist_id IN (select pm.playlist_id from playlist_map AS pm INNER JOIN media AS m ON (pm.media_uuid= m.media_uuid) AND m.validity=0); \
- ");
+ if(index_len > 0) {
+ ret = _media_svc_sql_query(db_handle, index_query, uid);
+ memset(index_query, 0, sizeof(index_query));
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ }
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ if(trigger_len > 0) {
+ ret = _media_svc_sql_query(db_handle, trigger_query, uid);
+ memset(trigger_query, 0, sizeof(trigger_query));
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ }
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ //create view
+ table_len = 0;
+ if(tb != NULL && tb->viewName != NULL) {
+ if(strncmp(table_name, MEDIA_SVC_DB_TABLE_MEDIA, strlen(MEDIA_SVC_DB_TABLE_MEDIA)) == 0) {
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_MEDIA, tb->viewName, table_name);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ } else if(strncmp(table_name, MEDIA_SVC_DB_TABLE_PLAYLIST, strlen(MEDIA_SVC_DB_TABLE_PLAYLIST)) == 0) {
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST], i);
+ if(col_ptr->isView) {
+ if(table_len > 0) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_THUMBNAIL, strlen(MEDIA_SVC_DB_COLUMN_THUMBNAIL)) == 0)
+ snprintf(temp, sizeof(temp), ", playlist.%s AS p_thumbnail_path", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", playlist.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "playlist.%s", col_ptr->name);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], i);
+ if(col_ptr->isView) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
+ snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, playlist_map.%s AS pm_id", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", playlist_map.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
- /* Create Trigger to remove media from playlist_map when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS playlist_map_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
+ if(col_ptr->isView) {
+ snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_PLAYLIST, tb->viewName, table_query);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ } else {
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG], i);
+ if(col_ptr->isView) {
+ if(table_len > 0) {
+ snprintf(temp, sizeof(temp), ", tag.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ } else {
+ snprintf(temp, sizeof(temp), "tag.%s", col_ptr->name);
+ strncpy(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG_MAP]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG_MAP], i);
+ if(col_ptr->isView) {
+ if(strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
+ snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, tag_map.%s AS tm_id", col_ptr->name);
+ else
+ snprintf(temp, sizeof(temp), ", tag_map.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
+ for(i=1; i<len; i++) {
+ col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
+ if(col_ptr->isView) {
+ snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
+ strncat(table_query, temp, strlen(temp));
+ table_len = strlen(table_query);
+ }
+ memset(temp, 0, sizeof(temp));
+ }
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_TAG, tb->viewName, table_query);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ }
}
- /* Create Trigger to remove media from playlist_map when playlist removed from playlist table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS playlist_map_cleanup_1 \
- DELETE ON %s BEGIN DELETE FROM %s WHERE playlist_id=old.playlist_id;END;",
- MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
+ if(strncmp(table_name, MEDIA_SVC_DB_TABLE_STORAGE, strlen(MEDIA_SVC_DB_TABLE_STORAGE)) == 0) {
+ sql = sqlite3_mprintf("SELECT COUNT(*) FROM '%s' WHERE storage_uuid='%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
+ ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ storage_cnt = sqlite3_column_int(sql_stmt, 0);
+ SQLITE3_FINALIZE(sql_stmt);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ if(storage_cnt == 0) {
+ sql = sqlite3_mprintf("INSERT INTO %s VALUES('%s', '%s', '%s', '%s', 0, 0, 1);", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, _media_svc_get_path(uid), NULL);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ }
}
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_album_table(sqlite3 *db_handle, uid_t uid)
+int _media_svc_upgrade_table_query(sqlite3 *db_handle, char *table_name, media_svc_table_slist_e list, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char * sql = NULL;
-
- media_svc_debug_func();
+ column_info *col_ptr = NULL;
+ char *sql = NULL;
+ char temp[1024] = {0,};
+ int len,i;
+ int cur_version = 0;
+ sqlite3_stmt *sql_stmt = NULL;
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- album_id INTEGER PRIMARY KEY AUTOINCREMENT, \
- name TEXT NOT NULL,\
- artist TEXT, \
- album_art TEXT, \
- unique(name, artist) \
- );",
- MEDIA_SVC_DB_TABLE_ALBUM);
+ len = g_slist_length(column_list[list]);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ sql = sqlite3_mprintf("PRAGMA user_version");
+ ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when get user_version. err = [%d]", ret);
+ return ret;
}
-
- /* Create Trigger to remove album when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS album_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s \
- WHERE (SELECT count(*) FROM %s WHERE album_id=old.album_id)=1 AND album_id=old.album_id;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_TABLE_MEDIA);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ cur_version = sqlite3_column_int(sql_stmt, 0);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ len = g_slist_length(column_list[list]);
+ for(i=1;i<len;i++) {
+ col_ptr = g_slist_nth_data(column_list[list], i);
+ if(col_ptr->version > cur_version) {
+ //alter table
+ if(col_ptr->hasOption)
+ snprintf(temp, sizeof(temp), "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
+ else
+ snprintf(temp, sizeof(temp), "%s %s", col_ptr->name, col_ptr->type);
+ sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_ALTER_TABLE, MEDIA_SVC_DB_TABLE_MEDIA, temp);
+ ret = _media_svc_sql_query(db_handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ //create index
+ if(col_ptr->isIndex) {
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_INDEX, col_ptr->indexName, table_name, col_ptr->name);
+ ret = _media_svc_sql_query(db_handle, temp, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ }
+ }
+ memset(temp, 0, sizeof(temp));
}
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_tag_table(sqlite3 *db_handle, uid_t uid)
+int _media_svc_init_table_query()
{
int ret = MS_MEDIA_ERR_NONE;
- char * sql = NULL;
+ int i = 0;
- media_svc_debug_func();
+ //variable initialize..
+ table = g_hash_table_new(g_str_hash, g_str_equal);
+ for(i=0;i<MEDIA_SVC_DB_LIST_MAX;i++) {
+ column_list[i] = g_slist_alloc();
+ }
- /*Create tag table*/
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- tag_id INTEGER PRIMARY KEY AUTOINCREMENT, \
- name TEXT NOT NULL UNIQUE, \
- name_pinyin TEXT \
- );",
- MEDIA_SVC_DB_TABLE_TAG);
+ //table specification.. (table_name, index, unique set, trigger, view, trigger name, event table, action table, view name)
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_MEDIA, NULL, NULL, NULL, MEDIA_SVC_DB_VIEW_MEDIA);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TRIGGER_FOLDER, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_FOLDER, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP1, MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_VIEW_PLAYLIST);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_TRIGGER_ALBUM, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_ALBUM, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_TRIGGER_TAG_MAP, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_TAG_MAP, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TRIGGER_TAG_MAP1, MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_VIEW_TAG);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_TRIGGER_BOOKMARK, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_BOOKMARK, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TRIGGER_STORAGE, MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_FOLDER, NULL);
+ ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_CUSTOM, MEDIA_SVC_DB_TRIGGER_CUSTOM, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_CUSTOM, NULL);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ //insert column info..
+ /*media*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", 0, NULL, true, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "file_name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, "media_file_name_idx", true, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "media_type", MEDIA_SVC_DB_TYPE_INT, NULL, 0, "media_media_type_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "mime_type", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "size", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "added_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "modified_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, "media_modified_time_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, "folder_uuid_idx", false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "title", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_title_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_id", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_album_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_artist_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "genre", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_genre_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "composer", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_composer_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "year", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "recorded_date", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "copyright", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "track_num", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "description", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "bitrate", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "bitpersample", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "samplerate", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "channel", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "duration", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "longitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "latitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "altitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "exposure_time", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "fnumber", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "iso", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "model", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "width", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "height", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "datetaken", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "orientation", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "burst_id", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "played_count", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "last_played_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "last_played_position", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "rating", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "favourite", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "author", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_author_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "provider", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_provider_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "content_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_content_name_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_category_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "location_tag", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "media_location_tag_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "age_rating", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "keyword", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "is_drm", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "storage_type", MEDIA_SVC_DB_TYPE_INT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "timeline", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, "media_timeline_idx", false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "weather", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "sync_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "file_name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "title_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "artist_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_artist_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "genre_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "composer_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "copyright_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "description_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "author_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "provider_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "content_name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "location_tag_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "age_rating_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "keyword_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ /*folder*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "modified_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "storage_type", MEDIA_SVC_DB_TYPE_INT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "folder_order", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "parent_folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /*Create tag_map table*/
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- _id INTEGER PRIMARY KEY AUTOINCREMENT, \
- tag_id INTEGER NOT NULL,\
- media_uuid TEXT NOT NULL,\
- unique(tag_id, media_uuid) \
- );",
- MEDIA_SVC_DB_TABLE_TAG_MAP);
+ /*playlist_map*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "playlist_id", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, false, true, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "play_order", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", 0, NULL, false, false, true);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ /*playlist*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "playlist_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, true, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, true);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ /*album*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "album_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, true, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "album_art", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /*Create tag_view*/
- sql = sqlite3_mprintf("\
- CREATE VIEW IF NOT EXISTS tag_view AS \
- SELECT \
- t.tag_id, t.name, media_count, tm._id as tm_id, m.media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, model, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel, weather, timeline, sync_status, bitpersample FROM tag AS t \
- INNER JOIN tag_map AS tm \
- INNER JOIN media AS m \
- INNER JOIN (SELECT count(tag_id) as media_count, tag_id FROM tag_map group by tag_id) as cnt_tbl \
- ON (t.tag_id=tm.tag_id AND tm.media_uuid = m.media_uuid AND cnt_tbl.tag_id=tm.tag_id AND m.validity=1) \
- UNION \
- SELECT \
- tag_id, name, 0, 0, NULL, NULL, -1, -1, -1, -1, -1, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, 0, -1, -1, -1, -1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, NULL, -1, NULL, -1, 0, 0 FROM tag \
- WHERE tag_id \
- NOT IN (select tag_id from tag_map); \
- ");
+ /*tag_map*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "tag_id", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, true, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ /*tag*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "tag_id ", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, true, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", 0, NULL, false, false, true);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
+ /*bookmark*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "bookmark_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, true, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "marked_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /* Create Trigger to remove media from tag_map when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS tag_map_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_TAG_MAP);
+ /*storage*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", 0, NULL, false, true, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_account", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, true, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_type", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "scan_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ /*custom*/
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, true, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "media_type", MEDIA_SVC_DB_TYPE_INT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "author", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "provider", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, "custom_provider_idx", false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "content_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "category", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "location_tag", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_CUSTOM], "age_rating", MEDIA_SVC_DB_TYPE_TEXT, NULL, 0, NULL, false, false, false);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ return ret;
+}
- /* Create Trigger to remove media from tag_map when tag removed from tag table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS tag_map_cleanup_1 \
- DELETE ON %s BEGIN DELETE FROM %s WHERE tag_id=old.tag_id;END;",
- MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TABLE_TAG_MAP);
+void _media_svc_destroy_table_query()
+{
+ int i = 0;
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ g_hash_table_remove_all(table);
+ g_hash_table_destroy(table);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
- return MS_MEDIA_ERR_NONE;
+ for(i=0; i<MEDIA_SVC_DB_LIST_MAX; i++)
+ g_slist_free(column_list[i]);
}
-int _media_svc_create_bookmark_table(sqlite3 *db_handle, uid_t uid)
+static int __media_svc_db_upgrade(sqlite3 *db_handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char * sql = NULL;
- media_svc_debug_func();
-
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- bookmark_id INTEGER PRIMARY KEY AUTOINCREMENT, \
- media_uuid TEXT NOT NULL,\
- marked_time INTEGER DEFAULT 0, \
- thumbnail_path TEXT, \
- unique(media_uuid, marked_time) \
- );",
- MEDIA_SVC_DB_TABLE_BOOKMARK);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- /* Create Trigger to remove media from tag_map when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS bookmark_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_BOOKMARK);
-
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ ret = _media_svc_init_table_query();
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_MEDIA , MEDIA_SVC_DB_LIST_MEDIA, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- return MS_MEDIA_ERR_NONE;
-}
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_FOLDER , MEDIA_SVC_DB_LIST_FOLDER, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-int _media_svc_create_custom_table(sqlite3 *db_handle, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char * sql = NULL;
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP , MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_debug_func();
-
- sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
- _id INTEGER PRIMARY KEY AUTOINCREMENT, \
- media_uuid TEXT, \
- media_type INTEGER,\
- author TEXT, \
- provider TEXT, \
- content_name TEXT, \
- category TEXT, \
- location_tag TEXT, \
- age_rating TEXT \
- );",
- MEDIA_SVC_DB_TABLE_CUSTOM);
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST , MEDIA_SVC_DB_LIST_PLAYLIST, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_ALBUM , MEDIA_SVC_DB_LIST_ALBUM, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG_MAP , MEDIA_SVC_DB_LIST_TAG_MAP, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /* Create Trigger to remove media from tag_map when media remove from media_table*/
- sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS custom_cleanup \
- DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
- MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_CUSTOM);
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG , MEDIA_SVC_DB_LIST_TAG, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_BOOKMARK , MEDIA_SVC_DB_LIST_BOOKMARK, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = _media_svc_sql_query(db_handle, sql, uid);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create trigger (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
+ ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_STORAGE , MEDIA_SVC_DB_LIST_STORAGE, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /* Create Index*/
- sql = sqlite3_mprintf("CREATE INDEX IF NOT EXISTS custom_provider_idx on %s (provider); \
- ",
- MEDIA_SVC_DB_TABLE_CUSTOM);
+ ret = __media_svc_rebuild_view_query(db_handle, uid);
+ sql = sqlite3_mprintf("PRAGMA user_version=%d;", LATEST_VERSION_NUMBER);
media_svc_retv_if(sql == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
ret = _media_svc_sql_query(db_handle, sql, uid);
sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("It failed to create db table (%d)", ret);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_request_update_db(const char *sql_str, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- ret = media_db_request_update_db(sql_str, uid);
+ _media_svc_destroy_table_query();
return ret;
}
@@ -649,10 +797,9 @@ int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- media_svc_debug("[SQL query] : %s", sql_str);
+ media_svc_sec_debug("[SQL query] : %s", sql_str);
- //DB will be updated by Media Server.
- ret = _media_svc_request_update_db(sql_str, uid);
+ ret = media_db_request_update_db(sql_str, uid);
return ret;
}
@@ -661,19 +808,31 @@ int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3
{
int err = -1;
- media_svc_debug("[SQL query] : %s", sql_str);
+ media_svc_sec_debug("[SQL query] : %s", sql_str);
+
+ if(!STRING_VALID(sql_str))
+ {
+ media_svc_error("invalid query");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
sqlite3_free((char *)sql_str);
if (err != SQLITE_OK) {
media_svc_error ("prepare error %d[%s]", err, sqlite3_errmsg(handle));
+ if (err == SQLITE_CORRUPT) {
+ return MS_MEDIA_ERR_DB_CORRUPT;
+ } else if (err == SQLITE_PERM) {
+ return MS_MEDIA_ERR_DB_PERMISSION;
+ }
+
return MS_MEDIA_ERR_DB_INTERNAL;
}
err = sqlite3_step(*stmt);
if (err != SQLITE_ROW) {
- media_svc_error("Item not found. end of row [%s]", sqlite3_errmsg(handle));
+ media_svc_sec_debug("Item not found. end of row [%s]", sqlite3_errmsg(handle));
SQLITE3_FINALIZE(*stmt);
return MS_MEDIA_ERR_DB_NO_RECORD;
}
@@ -681,6 +840,35 @@ int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3
return MS_MEDIA_ERR_NONE;
}
+int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt)
+{
+ int err = -1;
+
+ media_svc_sec_debug("[SQL query] : %s", sql_str);
+
+ if(!STRING_VALID(sql_str))
+ {
+ media_svc_error("invalid query");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
+ sqlite3_free((char *)sql_str);
+
+ if (err != SQLITE_OK) {
+ media_svc_error ("prepare error %d[%s]", err, sqlite3_errmsg(handle));
+ if (err == SQLITE_CORRUPT) {
+ return MS_MEDIA_ERR_DB_CORRUPT;
+ } else if (err == SQLITE_PERM) {
+ return MS_MEDIA_ERR_DB_PERMISSION;
+ }
+
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
int _media_svc_sql_begin_trans(sqlite3 *handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
@@ -707,8 +895,7 @@ int _media_svc_sql_rollback_trans(sqlite3 *handle, uid_t uid)
{
media_svc_error("========_media_svc_sql_rollback_trans");
- return _media_svc_request_update_db("ROLLBACK;", uid);
-
+ return _media_svc_sql_query(handle, "ROLLBACK;", uid);
}
int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list, uid_t uid)
@@ -752,3 +939,160 @@ void _media_svc_sql_query_release(GList **query_list)
*query_list = NULL;
}
}
+
+int _media_svc_check_db_upgrade(sqlite3 *db_handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ int cur_version;
+ char *sql = sqlite3_mprintf("PRAGMA user_version");
+
+ ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when get user_version. err = [%d]", ret);
+ return ret;
+ }
+
+ cur_version = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if (cur_version < LATEST_VERSION_NUMBER) {
+ media_svc_error("Current DB is out of date(%d).. So start to upgrade DB(%d)", cur_version, LATEST_VERSION_NUMBER);
+ return __media_svc_db_upgrade(db_handle, uid);
+ } else {
+ return MS_MEDIA_ERR_NONE;
+ }
+}
+
+int _media_db_check_corrupt(sqlite3 *db_handle)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = sqlite3_mprintf("PRAGMA quick_check(1)");
+ sqlite3_stmt *sql_stmt = NULL;
+ char *result = NULL;
+
+ ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when check db. err = [%d]", ret);
+ return ret;
+ }
+
+ result = (char *)sqlite3_column_text(sql_stmt, 0);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if(result != NULL) {
+ media_svc_debug("result %s", result);
+ if (strcasecmp(result, "OK"))
+ ret = MS_MEDIA_ERR_DB_CORRUPT;
+ } else {
+ media_svc_error("result is NULL");
+ ret = MS_MEDIA_ERR_DB_INTERNAL;
+ }
+
+ return ret;
+}
+
+
+int _media_svc_create_media_table_with_id(sqlite3 *db_handle, const char *table_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_init_table_query();
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ ret = _media_svc_make_table_query(db_handle, table_id, MEDIA_SVC_DB_LIST_MEDIA, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ _media_svc_destroy_table_query();
+
+ return ret;
+}
+
+int _media_svc_drop_media_table(sqlite3 *handle, const char *storage_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ char *sql = sqlite3_mprintf("DROP TABLE IF EXISTS '%q'", storage_id);
+
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int _media_svc_update_media_view(sqlite3 *db_handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char * sql = NULL;
+ sqlite3_stmt *sql_stmt = NULL;
+ int item_cnt = 0;
+ int idx = 0;
+ GList *storage_list = NULL;
+ char view_query[4096] = {0,};
+ memset(view_query, 0x00, sizeof(view_query));
+
+ snprintf(view_query, sizeof(view_query), "DROP VIEW IF EXISTS %s; CREATE VIEW IF NOT EXISTS %s AS SELECT * from %s ", MEDIA_SVC_DB_VIEW_MEDIA, MEDIA_SVC_DB_VIEW_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA);
+
+ /*Select list of storage*/
+ sql = sqlite3_mprintf("SELECT storage_uuid FROM '%s' WHERE validity=1 AND storage_uuid != '%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
+ ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ {
+ if(STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
+ {
+ storage_list = g_list_append(storage_list, strdup((char *)sqlite3_column_text(sql_stmt, 0)));
+ }
+ }
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if((storage_list != NULL) && ( g_list_length(storage_list) > 0))
+ {
+ item_cnt = g_list_length(storage_list);
+
+ for(idx = 0; idx < item_cnt; idx++)
+ {
+ int table_cnt = 0;
+ char * storage_id = NULL;
+ storage_id = g_list_nth_data(storage_list, idx);
+
+ if(STRING_VALID(storage_id))
+ {
+ /*Select list of storage*/
+ sql = sqlite3_mprintf("SELECT COUNT(*) FROM SQLITE_MASTER WHERE type='table' and name='%q'", storage_id);
+ ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
+ if(ret != MS_MEDIA_ERR_NONE)
+ {
+ SAFE_FREE(storage_id);
+ continue;
+ }
+
+ table_cnt = sqlite3_column_int(sql_stmt, 0);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if(table_cnt > 0)
+ {
+ char append_query[128] = {0,};
+ memset(append_query, 0x00, sizeof(append_query));
+ snprintf(append_query, sizeof(append_query), " UNION SELECT * from '%s'", storage_id);
+ strncat(view_query, append_query, strlen(append_query));
+ }
+ else
+ {
+ media_svc_error("media table not exist for storage [%s]", storage_id);
+ }
+
+ SAFE_FREE(storage_id);
+ }
+ }
+ g_list_free(storage_list);
+ }
+
+ ret = _media_svc_sql_query(db_handle, view_query, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ return ret;
+}
diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c
index 0a2e741..f500681 100755
--- a/src/common/media-svc-media-folder.c
+++ b/src/common/media-svc-media-folder.c
@@ -29,12 +29,16 @@
extern __thread GList *g_media_svc_move_item_query_list;
-int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id)
+int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
- char *sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, folder_name);
+ if(STRING_VALID(storage_id))
+ sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE storage_uuid = '%q' AND path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name);
+ else
+ sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, folder_name);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
@@ -55,8 +59,8 @@ int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_n
return ret;
}
-int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type,
- const char *folder_id, const char *path_name, const char *folder_name, int modified_date, uid_t uid)
+int _media_svc_append_folder(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
+ const char *folder_id, const char *path_name, const char *folder_name, int modified_date, const char *parent_folder_uuid, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
@@ -65,8 +69,9 @@ int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_t
if(_media_svc_check_pinyin_support())
_media_svc_get_pinyin_str(folder_name, &folder_name_pinyin);
- char *sql = sqlite3_mprintf("INSERT INTO %s (folder_uuid, path, name, storage_type, modified_time, name_pinyin) values (%Q, %Q, %Q, '%d', '%d', %Q); ",
- MEDIA_SVC_DB_TABLE_FOLDER, folder_id, path_name, folder_name, storage_type, modified_date, folder_name_pinyin);
+ char *sql = sqlite3_mprintf("INSERT INTO %s (folder_uuid, path, name, storage_uuid, storage_type, modified_time, name_pinyin, parent_folder_uuid) \
+ values (%Q, %Q, %Q, %Q, '%d', '%d', %Q, %Q); ",
+ MEDIA_SVC_DB_TABLE_FOLDER, folder_id, path_name, folder_name, storage_id, storage_type, modified_date, folder_name_pinyin, parent_folder_uuid);
ret = _media_svc_sql_query(handle, sql, uid);
sqlite3_free(sql);
@@ -94,33 +99,108 @@ int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const
return ret;
}
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
+int __media_svc_get_and_append_parent_folder(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
{
- char *path_name = NULL;
int ret = MS_MEDIA_ERR_NONE;
+ unsigned int next_pos;
+ char *next = NULL;
+ char *dir_path = NULL;
+ char *token = "/";
+ char *folder_uuid = NULL;
+ char *folder_name = NULL;
+ int folder_modified_date = 0;
+ char parent_folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+ bool folder_search_end = FALSE;
- path_name = g_path_get_dirname(path);
+ memset(parent_folder_uuid, 0, sizeof(parent_folder_uuid));
+
+ if(strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0)
+ next_pos = strlen(_media_svc_get_path(uid));
+ else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)
+ next_pos = strlen(MEDIA_ROOT_PATH_SDCARD);
+ else
+ {
+ media_svc_error("Invalid Path");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ while (!folder_search_end)
+ {
+ next = strstr(path + next_pos , token);
+ if (next != NULL)
+ {
+ next_pos = (next - path);
+ dir_path = strndup(path, next_pos);
+ next_pos++;
+ }
+ else
+ {
+ media_svc_error("End Path");
+ dir_path = strndup(path, strlen(path));
+ folder_search_end = TRUE;
+ }
- ret = _media_svc_get_folder_id_by_foldername(handle, path_name, folder_id);
+ ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, dir_path, parent_folder_uuid);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ {
+ media_svc_error("NOT EXIST dir path : %s", dir_path);
- if(ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- char *folder_name = NULL;
- int folder_modified_date = 0;
- char *folder_uuid = _media_info_generate_uuid();
- if(folder_uuid == NULL ) {
+ folder_uuid = _media_info_generate_uuid();
+ if(folder_uuid == NULL )
+ {
media_svc_error("Invalid UUID");
- SAFE_FREE(path_name);
+ SAFE_FREE(dir_path);
return MS_MEDIA_ERR_INTERNAL;
}
- folder_name = g_path_get_basename(path_name);
- folder_modified_date = _media_svc_get_file_time(path_name);
+ folder_name = g_path_get_basename(dir_path);
+ folder_modified_date = _media_svc_get_file_time(dir_path);
+
+ ret = _media_svc_append_folder(handle, storage_id, storage_type, folder_uuid, dir_path, folder_name, folder_modified_date, parent_folder_uuid, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_append_folder is failed");
+ }
+
+ _strncpy_safe(parent_folder_uuid, folder_uuid, MEDIA_SVC_UUID_SIZE+1);
- ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path_name, folder_name, folder_modified_date, uid);
SAFE_FREE(folder_name);
+ }
+ else
+ {
+ media_svc_error("EXIST dir path : %s\n", dir_path);
+ }
+
+ SAFE_FREE(dir_path);
+ }
+
_strncpy_safe(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE+1);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_get_and_append_folder(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, path, folder_id);
+
+ if(ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ {
+ ret = __media_svc_get_and_append_parent_folder(handle, storage_id, path, storage_type, folder_id, uid);
}
+ return ret;
+}
+
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
+{
+ char *path_name = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
+
+ path_name = g_path_get_dirname(path);
+
+ ret = _media_svc_get_and_append_folder(handle, storage_id, path_name, storage_type, folder_id, uid);
+
SAFE_FREE(path_name);
return ret;
@@ -139,3 +219,163 @@ int _media_svc_update_folder_table(sqlite3 *handle, uid_t uid)
return ret;
}
+
+static int __media_svc_count_all_folders(sqlite3 *handle, char* start_path, int *count)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE path LIKE '%q%%'", MEDIA_SVC_DB_TABLE_FOLDER, start_path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when _media_svc_sql_prepare_to_step. err = [%d]", ret);
+ return ret;
+ }
+
+ *count = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_get_all_folders(sqlite3 *handle, char *start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int idx = 0;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+ int cnt =0;
+ char **folder_uuid = NULL;
+ int i =0;
+
+ ret = __media_svc_count_all_folders(handle, start_path, &cnt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when __media_svc_count_all_folders. err = [%d]", ret);
+ return ret;
+ }
+
+ if (cnt > 0) {
+ sql = sqlite3_mprintf("SELECT path, modified_time, folder_uuid FROM %s WHERE path LIKE '%q%%'", MEDIA_SVC_DB_TABLE_FOLDER, start_path);
+ } else {
+ *folder_list = NULL;
+ *modified_time_list = NULL;
+ *item_num_list = NULL;
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ *folder_list = malloc(sizeof(char *) * cnt);
+ *modified_time_list = malloc(sizeof(int) * cnt);
+ *item_num_list = malloc(sizeof(int) * cnt);
+ folder_uuid = malloc(sizeof(char *) * cnt);
+
+ if((*folder_list == NULL) || (*modified_time_list == NULL) || (*item_num_list == NULL) ||(folder_uuid == NULL)) {
+ media_svc_error("Out of memory");
+ goto ERROR;
+ }
+ memset(folder_uuid, 0x0, sizeof(char *) * cnt);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
+ goto ERROR;
+ }
+
+ media_svc_debug("QEURY OK");
+
+ while (1) {
+ if(STRING_VALID((char *)sqlite3_column_text(sql_stmt, 0)))
+ (*folder_list)[idx] = strdup((char *)sqlite3_column_text(sql_stmt, 0));
+
+ (*modified_time_list)[idx] = (int)sqlite3_column_int(sql_stmt, 1);
+
+ /* get the folder's id */
+ if(STRING_VALID((char *)sqlite3_column_text(sql_stmt, 2)))
+ folder_uuid[idx] = strdup((char *)sqlite3_column_text(sql_stmt, 2));
+
+ idx++;
+
+ if(sqlite3_step(sql_stmt) != SQLITE_ROW)
+ break;
+ }
+ SQLITE3_FINALIZE(sql_stmt);
+
+ /*get the numbder of item in the folder by using folder's id */
+ for (i = 0; i < idx; i ++) {
+ if(STRING_VALID(folder_uuid[i])) {
+ sql = sqlite3_mprintf("SELECT COUNT(*) FROM %s WHERE (folder_uuid='%q' AND validity = 1)", MEDIA_SVC_DB_TABLE_MEDIA, folder_uuid[i]);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
+ goto ERROR;
+ }
+
+ (*item_num_list)[i] = (int)sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+ } else
+ {
+ media_svc_error("Invalid Folder Id");
+ }
+ }
+
+ if (cnt == idx) {
+ *count = cnt;
+ media_svc_debug("Get Folder is OK");
+ } else {
+ media_svc_error("Fail to get folder");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
+ }
+
+ /* free all data */
+ for (i = 0; i < idx; i ++) {
+ SAFE_FREE(folder_uuid[i]);
+ }
+ SAFE_FREE(folder_uuid);
+
+ return ret;
+
+ERROR:
+
+ /* free all data */
+ for (i = 0; i < idx; i ++) {
+ SAFE_FREE((*folder_list)[i]);
+ SAFE_FREE(folder_uuid[i]);
+ }
+ SAFE_FREE(*folder_list);
+ SAFE_FREE(*modified_time_list);
+ SAFE_FREE(*item_num_list);
+ SAFE_FREE(folder_uuid);
+
+ *count = 0;
+
+ return ret;
+}
+
+int _media_svc_get_folder_info_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id, time_t *modified_time)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT folder_uuid, modified_time FROM %s WHERE path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, folder_name);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if(ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ media_svc_debug("there is no folder.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ _strncpy_safe(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
+ *modified_time = (int)sqlite3_column_int(sql_stmt, 1);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c
index 1712a6d..dcccc5b 100755
--- a/src/common/media-svc-media.c
+++ b/src/common/media-svc-media.c
@@ -20,6 +20,8 @@
*/
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include <media-util-err.h>
@@ -39,6 +41,7 @@ typedef struct{
static __thread GList *g_media_svc_item_validity_query_list = NULL;
static __thread GList *g_media_svc_insert_item_query_list = NULL;
__thread GList *g_media_svc_move_item_query_list = NULL;
+static __thread GList *g_media_svc_update_item_query_list = NULL;
static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, int *count);
static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type,
@@ -81,11 +84,10 @@ static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media
media_svc_debug("[SQL query] : %s", sql);
- ret = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
- sqlite3_free(sql);
- if (ret != SQLITE_OK) {
- media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
- return MS_MEDIA_ERR_DB_INTERNAL;
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when __media_svc_get_invalid_records_with_thumbnail. err = [%d]", ret);
+ return ret;
}
while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
@@ -133,10 +135,9 @@ static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle
media_svc_debug("[SQL query] : %s", sql);
- ret = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
- sqlite3_free(sql);
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
+ media_svc_error("error when __media_svc_get_invalid_folder_records_with_thumbnail. err = [%d]", ret);
return ret;
}
@@ -206,15 +207,14 @@ char* _media_svc_get_thumb_default_path(uid_t uid)
int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
{
- media_svc_debug("");
int ret = MS_MEDIA_ERR_NONE;
char *burst_id = NULL;
char * db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, \
thumbnail_path, title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description,\
- bitrate, bitpersample, samplerate, channel, duration, longitude, latitude, altitude, width, height, datetaken, orientation,\
+ bitrate, bitpersample, samplerate, channel, duration, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation,\
rating, is_drm, storage_type, burst_id, timeline, weather, sync_status, \
- file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin ";
+ file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid";
/* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
/* This code will be removed when sqlite3_mprintf works clearly */
@@ -238,11 +238,9 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *
int width = 0;
int height = 0;
- ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("thumbnail_request_from_db failed: %d", ret);
- } else {
- media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
+ if(ret == MS_MEDIA_ERR_NONE) {
+
ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
content_info->thumbnail_path = NULL;
@@ -279,12 +277,12 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *
_media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
}
- char *sql = sqlite3_mprintf("INSERT INTO %s (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
+ char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
%Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
- %d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %d, %d, %Q, %d, \
+ %d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
%d, %d, %d, %Q, %d, %Q, %d, \
- %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
- MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
+ %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
+ content_info->storage_uuid, db_fields,
content_info->media_uuid,
content_info->path,
content_info->file_name,
@@ -315,6 +313,10 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *
content_info->media_meta.longitude,
content_info->media_meta.latitude,
content_info->media_meta.altitude,
+ content_info->media_meta.exposure_time,
+ content_info->media_meta.fnumber,
+ content_info->media_meta.iso,
+ content_info->media_meta.model,
content_info->media_meta.width,
content_info->media_meta.height,
content_info->media_meta.datetaken,
@@ -334,7 +336,8 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *
content_info->media_meta.genre_pinyin,
content_info->media_meta.composer_pinyin,
content_info->media_meta.copyright_pinyin,
- content_info->media_meta.description_pinyin
+ content_info->media_meta.description_pinyin,
+ content_info->storage_uuid
);
if (burst_id)
@@ -358,7 +361,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
+int _media_svc_update_meta_with_data(sqlite3 *handle, media_svc_content_info_s *content_info)
{
int ret = MS_MEDIA_ERR_NONE;
@@ -370,6 +373,8 @@ int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *
/*Update Pinyin If Support Pinyin*/
if(_media_svc_check_pinyin_support())
{
+ if(STRING_VALID(content_info->file_name))
+ _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
if(STRING_VALID(content_info->media_meta.title))
_media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
if(STRING_VALID(content_info->media_meta.album))
@@ -388,12 +393,82 @@ int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *
_media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
}
- char *sql = sqlite3_mprintf("UPDATE %s SET \
+ char *sql = sqlite3_mprintf("UPDATE %s SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
+ file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q \
+ WHERE path=%Q",
+ MEDIA_SVC_DB_TABLE_MEDIA,
+ content_info->media_meta.title,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.copyright,
+ content_info->media_meta.description,
+ content_info->file_name_pinyin,
+ content_info->media_meta.title_pinyin,
+ content_info->media_meta.album_pinyin,
+ content_info->media_meta.artist_pinyin,
+ content_info->media_meta.album_artist_pinyin,
+ content_info->media_meta.genre_pinyin,
+ content_info->media_meta.composer_pinyin,
+ content_info->media_meta.copyright_pinyin,
+ content_info->media_meta.description_pinyin,
+ content_info->path
+ );
+
+ media_svc_error("");
+ if (sql != NULL) {
+ media_svc_debug("query : %s", sql);
+ _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
+ } else {
+ media_svc_error("sqlite3_mprintf failed");
+ ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
+ media_svc_error("");
+
+ return ret;
+}
+
+int _media_svc_update_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
+ /* This code will be removed when sqlite3_mprintf works clearly */
+ char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
+ sqlite3_free(test_sql);
+
+ /*Update Pinyin If Support Pinyin*/
+ if(_media_svc_check_pinyin_support())
+ {
+ if(STRING_VALID(content_info->file_name))
+ _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
+ if(STRING_VALID(content_info->media_meta.title))
+ _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
+ if(STRING_VALID(content_info->media_meta.album))
+ _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
+ if(STRING_VALID(content_info->media_meta.artist))
+ _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
+ if(STRING_VALID(content_info->media_meta.album_artist))
+ _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
+ if(STRING_VALID(content_info->media_meta.genre))
+ _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
+ if(STRING_VALID(content_info->media_meta.composer))
+ _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
+ if(STRING_VALID(content_info->media_meta.copyright))
+ _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
+ if(STRING_VALID(content_info->media_meta.description))
+ _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
+ }
+
+ char *sql = sqlite3_mprintf("UPDATE '%s' SET \
size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, \
composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, \
- bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, longitude=%f, latitude=%f, altitude=%f, width=%d, height=%d, datetaken=%Q, \
+ bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, longitude=%f, latitude=%f, altitude=%f, exposure_time=%Q, fnumber=%f, iso=%d, model=%Q, width=%d, height=%d, datetaken=%Q, \
orientation=%d WHERE path=%Q",
- MEDIA_SVC_DB_TABLE_MEDIA,
+ storage_id,
content_info->size,
content_info->modified_time,
content_info->thumbnail_path,
@@ -417,6 +492,10 @@ int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *
content_info->media_meta.longitude,
content_info->media_meta.latitude,
content_info->media_meta.altitude,
+ content_info->media_meta.exposure_time,
+ content_info->media_meta.fnumber,
+ content_info->media_meta.iso,
+ content_info->media_meta.model,
content_info->media_meta.width,
content_info->media_meta.height,
content_info->media_meta.datetaken,
@@ -429,12 +508,12 @@ int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *
return ret;
}
-int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
@@ -455,12 +534,12 @@ int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, cha
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type)
+int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT media_type FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ char *sql = sqlite3_mprintf("SELECT media_type FROM '%s' WHERE path='%q'", storage_id, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
@@ -476,16 +555,21 @@ int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *me
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path, uid_t uid)
+int _media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, bool stack_query, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity=1 AND path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE path='%q'", storage_id, path);
- ret = _media_svc_sql_query(handle, sql, uid);
- sqlite3_free(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("failed to delete item");
- return ret;
+ if(!stack_query) {
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("failed to delete item");
+ return ret;
+ }
+ } else {
+ media_svc_debug("query : %s", sql);
+ _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
}
return ret;
@@ -512,7 +596,7 @@ int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e st
ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_type, &invalid_count);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- media_svc_debug("invalid count: %d\n", invalid_count);
+ media_svc_debug("invalid count: %d", invalid_count);
if (invalid_count > 0) {
thumbpath_record = (media_svc_thumbnailpath_s *)calloc( invalid_count, sizeof(media_svc_thumbnailpath_s));
@@ -542,7 +626,8 @@ int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e st
/*Delete thumbnails*/
for (idx = 0; idx < invalid_count; idx++) {
if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
- if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
+ ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
+ if(ret != MS_MEDIA_ERR_NONE) {
media_svc_error("fail to remove thumbnail file.");
}
}
@@ -593,8 +678,9 @@ int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_p
/*Delete thumbnails*/
for (idx = 0; idx < invalid_count; idx++) {
if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
- if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
- media_svc_error("fail to remove thumbnail file [%s].", thumbpath_record[idx].thumbnail_path);
+ ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
+ if(ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("fail to remove thumbnail file.");
}
}
}
@@ -620,11 +706,11 @@ int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int valid
return ret;
}
-int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path, uid_t uid)
+int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE %s SET thumbnail_path=%Q WHERE path= %Q", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
+ char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q", storage_id, thumb_path, path);
ret = _media_svc_sql_query(handle, sql, uid);
sqlite3_free(sql);
@@ -655,7 +741,11 @@ int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_p
sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when get folder_id. err = [%d]", ret);
+ if(ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ media_svc_debug("folder not exist");
+ else
+ media_svc_error("error when get folder_id. err = [%d]", ret);
+
return ret;
}
@@ -663,7 +753,7 @@ int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_p
SQLITE3_FINALIZE(sql_stmt);
/*Update folder item validity*/
- sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE folder_uuid='%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_uuid);
+ sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE (storage_type = 0 OR storage_type = 1) AND folder_uuid='%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_uuid);
ret = _media_svc_sql_query(handle, sql, uid);
sqlite3_free(sql);
@@ -675,7 +765,8 @@ int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char
int ret = MS_MEDIA_ERR_NONE;
/*Update folder item validity*/
- char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_path);
+ char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE (storage_type = 0 OR storage_type = 1) AND path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_path);
+
ret = _media_svc_sql_query(handle, sql, uid);
sqlite3_free(sql);
@@ -739,7 +830,7 @@ int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type,
ret = _media_svc_sql_end_trans(handle, uid);
if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
+ media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
_media_svc_sql_rollback_trans(handle,uid);
return ret;
}
@@ -747,28 +838,6 @@ int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type,
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT media_uuid FROM %s WHERE validity=1 AND path='%q'",
- MEDIA_SVC_DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
-
- strncpy(media_uuid, (const char*)sqlite3_column_text(sql_stmt, 0), max_length);
- media_uuid[max_length - 1] = '\0';
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
int _media_svc_get_burst_id(sqlite3 *handle, int *id)
{
int ret = MS_MEDIA_ERR_NONE;
@@ -790,7 +859,7 @@ int _media_svc_get_burst_id(sqlite3 *handle, int *id)
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item)
+int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
@@ -798,14 +867,14 @@ int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item,
int is_root_dir = FALSE;
if (item == NULL) {
- media_svc_error("_media_svc_get_noti_info failed");
+ media_svc_error("invalid parameter");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
if (update_item == MS_MEDIA_ITEM_FILE) {
- sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM %s WHERE path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%s' WHERE path=%Q", storage_id, path);
} else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
- sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path=%Q", MEDIA_SVC_DB_TABLE_FOLDER, path);
+ sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path=%Q AND storage_uuid='%s'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
} else {
media_svc_error("_media_svc_get_noti_info failed : update item");
return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -831,18 +900,18 @@ int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item,
}
if (update_item == MS_MEDIA_ITEM_FILE) {
- if (sqlite3_column_text(sql_stmt, 0))
+ if(STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
(*item)->media_uuid = strdup((const char *)sqlite3_column_text(sql_stmt, 0));
(*item)->media_type = sqlite3_column_int(sql_stmt, 1);
- if (sqlite3_column_text(sql_stmt, 2))
+ if(STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2)))
(*item)->mime_type = strdup((const char *)sqlite3_column_text(sql_stmt, 2));
} else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
if (is_root_dir) {
(*item)->media_uuid = NULL;
} else {
- if (sqlite3_column_text(sql_stmt, 0))
+ if(STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
(*item)->media_uuid = strdup((const char *)sqlite3_column_text(sql_stmt, 0));
}
}
@@ -862,7 +931,7 @@ int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_pa
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
+ media_svc_error("error when _media_svc_count_invalid_folder_items. err = [%d]", ret);
return ret;
}
@@ -892,3 +961,25 @@ int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *thumb_path, int
return MS_MEDIA_ERR_NONE;
}
+
+int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *path, time_t *modified_time, unsigned long long *size)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT modified_time, size FROM %s WHERE path='%q'",
+ MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when _media_svc_get_fileinfo_by_path. err = [%d]", ret);
+ return ret;
+ }
+
+ *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
+ *size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
diff --git a/src/common/media-svc-noti.c b/src/common/media-svc-noti.c
index 54ad73d..5537f0b 100755
--- a/src/common/media-svc-noti.c
+++ b/src/common/media-svc-noti.c
@@ -23,6 +23,8 @@
#include "media-svc-noti.h"
#include "media-svc-util.h"
+static int __media_svc_publish_noti_by_item(media_svc_noti_item *noti_item);
+
static __thread media_svc_noti_item *g_inserted_noti_list = NULL;
static __thread int g_noti_from_pid = -1;
@@ -32,13 +34,7 @@ static int __media_svc_publish_noti_by_item(media_svc_noti_item *noti_item)
if (noti_item && noti_item->path)
{
- ret = media_db_update_send(noti_item->pid,
- noti_item->update_item,
- noti_item->update_type,
- noti_item->path,
- noti_item->media_uuid,
- noti_item->media_type,
- noti_item->mime_type);
+ ret = media_db_update_send(noti_item->pid, noti_item->update_item, noti_item->update_type, noti_item->path, noti_item->media_uuid, noti_item->media_type, noti_item->mime_type);
if(ret != MS_MEDIA_ERR_NONE)
{
media_svc_error("media_db_update_send failed : %d [%s]", ret, noti_item->path);
@@ -68,15 +64,21 @@ int _media_svc_publish_noti(media_item_type_e update_item,
{
int ret = MS_MEDIA_ERR_NONE;
- if(path) {
+ if(STRING_VALID(path))
+ {
ret = media_db_update_send(getpid(), update_item, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
- if(ret != MS_MEDIA_ERR_NONE) {
+ if(ret != MS_MEDIA_ERR_NONE)
+ {
media_svc_error("Send noti failed : %d [%s]", ret, path);
ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
- } else {
- media_svc_debug("media_db_update_send success");
}
- } else {
+ else
+ {
+ media_svc_debug("Send noti success [%d][%d]", update_item, update_type);
+ }
+ }
+ else
+ {
media_svc_debug("invalid path");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -84,11 +86,6 @@ int _media_svc_publish_noti(media_item_type_e update_item,
return ret;
}
-media_svc_noti_item *_media_svc_get_noti_list()
-{
- return g_inserted_noti_list;
-}
-
void _media_svc_set_noti_from_pid(int pid)
{
g_noti_from_pid = pid;
@@ -161,44 +158,6 @@ int _media_svc_publish_noti_list(int all_cnt)
return ret;
}
-
-int _media_svc_create_noti_item(media_svc_content_info_s *content_info,
- int pid,
- media_item_type_e update_item,
- media_item_update_type_e update_type,
- media_svc_noti_item **item)
-{
- media_svc_noti_item *_item = NULL;
-
- if (item == NULL || content_info == NULL) {
- media_svc_error("_media_svc_create_noti_item : invalid param");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- _item = calloc(1, sizeof(media_svc_noti_item));
-
- if (_item == NULL) {
- media_svc_error("Failed to prepare noti items");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- _item->pid = pid;
- _item->update_item = update_item;
- _item->update_type = update_type;
- _item->media_type = content_info->media_type;
-
- if (content_info->media_uuid)
- _item->media_uuid = strdup(content_info->media_uuid);
- if (content_info->path)
- _item->path = strdup(content_info->path);
- if (content_info->mime_type)
- _item->mime_type = strdup(content_info->mime_type);
-
- *item = _item;
-
- return MS_MEDIA_ERR_NONE;
-}
-
int _media_svc_destroy_noti_item(media_svc_noti_item *item)
{
if (item) {
diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c
new file mode 100755
index 0000000..7be2dfa
--- /dev/null
+++ b/src/common/media-svc-storage.c
@@ -0,0 +1,95 @@
+/*
+ * libmedia-service
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-util-err.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-util.h"
+#include "media-svc-storage.h"
+
+int _media_svc_init_storage(sqlite3 *handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+ sqlite3_stmt *sql_stmt = NULL;
+ int storage_cnt = 0;
+
+ /*Add Internal storage*/
+ sql = sqlite3_mprintf("SELECT COUNT(*) FROM '%s' WHERE storage_uuid='%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ storage_cnt = sqlite3_column_int(sql_stmt, 0);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if(storage_cnt == 0)
+ {
+ sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_type) VALUES ('%s', '%s', '%s', 0);",
+ MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, _media_svc_get_path(uid));
+
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ }
+
+ return ret;
+}
+
+int _media_svc_append_storage(sqlite3 *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_account, storage_type) values (%Q, %Q, %Q, %Q, %d); ",
+ MEDIA_SVC_DB_TABLE_STORAGE, storage_id, storage_name, storage_path, storage_account, storage_type);
+
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int _media_svc_delete_storage(sqlite3 *handle, const char *storage_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
+
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int _media_svc_update_storage_validity(sqlite3 *handle, 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 '%s' SET validity=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, validity);
+ } else {
+ sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, validity, storage_id);
+ }
+
+ ret = _media_svc_sql_query(handle, sql, uid);
+ sqlite3_free(sql);
+
+ return ret;
+}
diff --git a/src/common/media-svc-storage.h b/src/common/media-svc-storage.h
new file mode 100755
index 0000000..3ad39e2
--- /dev/null
+++ b/src/common/media-svc-storage.h
@@ -0,0 +1,32 @@
+/*
+ * libmedia-service
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SVC_STORAGE_H_
+#define _MEDIA_SVC_STORAGE_H_
+
+#include <sqlite3.h>
+
+int _media_svc_init_storage(sqlite3 *handle, uid_t uid);
+int _media_svc_append_storage(sqlite3 *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid);
+int _media_svc_delete_storage(sqlite3 *handle, const char *storage_id, uid_t uid);
+int _media_svc_update_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid);
+
+#endif /*_MEDIA_SVC_STORAGE_H_*/
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
index 7a2892e..77fefea 100755
--- a/src/common/media-svc-util.c
+++ b/src/common/media-svc-util.c
@@ -29,7 +29,6 @@
#include <string.h>
#include <dirent.h>
#include <ctype.h>
-#include <errno.h>
#include <aul/aul.h>
#include <mm_file.h>
#include <mm_error.h>
@@ -46,25 +45,99 @@
#include "media-svc-env.h"
#include "media-svc-hash.h"
#include "media-svc-album.h"
+#include "media-svc-localize-utils.h"
#include "media-svc-localize_ch.h"
+#include "media-svc-localize_tw.h"
#define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
+/* Define data structures for media type and mime type */
+#define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
+#define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
+#define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
+#define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
+#define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
+#define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
+
+#define CONTENT_TYPE_NUM 5
+#define MUSIC_MIME_NUM 29
+#define SOUND_MIME_NUM 1
+#define MIME_TYPE_LENGTH 255
+#define MIME_LENGTH 50
+#define _3GP_FILE ".3gp"
+#define _MP4_FILE ".mp4"
+#define _ASF_FILE ".asf"
+
+typedef struct {
+ char content_type[15];
+ int category_by_mime;
+} _media_svc_content_table_s;
+
+static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
+ {"audio", MEDIA_SVC_CATEGORY_SOUND},
+ {"image", MEDIA_SVC_CATEGORY_IMAGE},
+ {"video", MEDIA_SVC_CATEGORY_VIDEO},
+ {"application", MEDIA_SVC_CATEGORY_ETC},
+ {"text", MEDIA_SVC_CATEGORY_ETC},
+};
+
+static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
+ /*known mime types of normal files*/
+ "mpeg",
+ "ogg",
+ "x-ms-wma",
+ "x-flac",
+ "mp4",
+ /* known mime types of drm files*/
+ "mp3",
+ "x-mp3", /*alias of audio/mpeg*/
+ "x-mpeg", /*alias of audio/mpeg*/
+ "3gpp",
+ "x-ogg", /*alias of audio/ogg*/
+ "vnd.ms-playready.media.pya:*.pya", /*playready*/
+ "wma",
+ "aac",
+ "x-m4a", /*alias of audio/mp4*/
+ /* below mimes are rare*/
+ "x-vorbis+ogg",
+ "x-flac+ogg",
+ "x-matroska",
+ "ac3",
+ "mp2",
+ "x-ape",
+ "x-ms-asx",
+ "vnd.rn-realaudio",
+
+ "x-vorbis", /*alias of audio/x-vorbis+ogg*/
+ "vorbis", /*alias of audio/x-vorbis+ogg*/
+ "x-oggflac",
+ "x-mp2", /*alias of audio/mp2*/
+ "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "x-wav",
+};
+
+static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
+ "x-smaf",
+};
+
typedef enum {
MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
- MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
+ MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
- MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
+ MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
+ MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
} media_svc_extracted_field_e;
+static char* _media_svc_get_thumb_path(uid_t uid);
char *_media_info_generate_uuid(void)
{
@@ -120,53 +193,73 @@ int __media_svc_malloc_and_strncpy(char **dst, const char *src)
return MS_MEDIA_ERR_NONE;
}
-static void __media_svc_split_to_double(char *input, double *arr, int *num)
+int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
{
- char tmp_arr[255] = { 0, };
- int len = strlen(input);
- int i = 0, idx = 0, tmp_idx = 0;
- int is_prev_space = 0;
-
- for (;;) {
- if (input[len - 1] == ' ') {
- len--;
- } else {
- break;
- }
+ if (!STRING_VALID(src)) {
+ media_svc_error("invalid src");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- for (i = 0; i < len; i++) {
- if (idx > 2) {
- break;
- }
+ SAFE_FREE(*dst);
- if (input[i] == ' ') {
- if (is_prev_space == 1) {
- continue;
- }
- if (idx <= 2) {
- arr[idx++] = atof(tmp_arr);
- }
- tmp_idx = 0;
- is_prev_space = 1;
- continue;
- }
+ *dst = malloc(copysize + 1);
+
+ if (*dst == NULL) {
+ media_svc_error("malloc failed");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ strncpy(*dst, src, copysize);
+ char *p = *dst;
+ p[copysize] = '\0';
+
+ return MS_MEDIA_ERR_NONE;
+}
- tmp_arr[tmp_idx] = input[i];
- tmp_arr[++tmp_idx] = '\0';
- is_prev_space = 0;
+static int __media_svc_split_to_double(char *input, double *arr)
+{
+ char tmp_arr[255] = {0, };
+ int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
+
+ if(!STRING_VALID(input))
+ {
+ media_svc_error("Invalid parameter");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ memset(tmp_arr, 0x0, sizeof(tmp_arr));
- if (i == len) {
- if (idx <= 2) {
- arr[idx++] = atof(tmp_arr);
+ //media_svc_debug("input: [%s]", input);
+
+ len = strlen(input);
+
+ for (idx = 0; idx < (len+1); idx++)
+ {
+ if(input[idx] == ' ')
+ {
+ continue;
}
- *num = idx;
- return;
- } else {
- *num = idx--;
- return;
+ else if((input[idx] == ',') || (idx == len))
+ {
+ arr[arr_idx] = atof(tmp_arr);
+ arr_idx++;
+ str_idx = 0;
+ //media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr));
+ memset(tmp_arr, 0x0, sizeof(tmp_arr));
+ }
+ else
+ {
+ tmp_arr[str_idx] = input[idx];
+ str_idx++;
+ }
+ }
+
+ if(arr_idx != 3)
+ {
+ media_svc_error("Error when parsing GPS [%d]", arr_idx);
+ return MS_MEDIA_ERR_INTERNAL;
}
+
+ return MS_MEDIA_ERR_NONE;
}
static int __media_svc_get_exif_info(ExifData *ed,
@@ -177,7 +270,6 @@ static int __media_svc_get_exif_info(ExifData *ed,
long tagtype)
{
ExifEntry *entry;
- ExifIfd ifd;
ExifTag tag;
if (ed == NULL) {
@@ -185,7 +277,6 @@ static int __media_svc_get_exif_info(ExifData *ed,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- ifd = ifdtype;
tag = tagtype;
entry = exif_data_get_entry(ed, tag);
@@ -213,23 +304,19 @@ static int __media_svc_get_exif_info(ExifData *ed,
}
/* Get the contents of the tag in human-readable form */
- char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+ char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
gps_buf[strlen(gps_buf)] = '\0';
-
- //media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
+ int ret = MS_MEDIA_ERR_NONE;
+ //media_svc_debug("%s: [%s]", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
double tmp_arr[3] = { 0.0, 0.0, 0.0 };
- int count = 0;
- __media_svc_split_to_double(gps_buf, tmp_arr, &count);
- if (count != 3) {
- media_svc_error("Value is invalid");
- return MS_MEDIA_ERR_INTERNAL;
- }
+ ret = __media_svc_split_to_double(gps_buf, tmp_arr);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
*d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
- //media_svc_debug("GPS value is %f", *d_value);
+ //media_svc_debug("GPS value is [%f], %f, %f, %f", *d_value, tmp_arr[0], tmp_arr[1], tmp_arr[2]);
} else {
if (buf == NULL) {
@@ -239,135 +326,272 @@ static int __media_svc_get_exif_info(ExifData *ed,
exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
buf[strlen(buf)] = '\0';
-
- if (*buf) {
- media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
- }
}
}
return MS_MEDIA_ERR_NONE;
}
-unsigned int _media_svc_get_current_time(void)
+time_t __media_svc_get_timeline_from_str(const char *timstr)
{
- struct timeval t;
- unsigned int tval = 0;
- gettimeofday(&t, NULL);
+ struct tm t;
+ time_t modified_t = 0;
+ time_t rawtime;
+ struct tm timeinfo;
- tval = t.tv_sec*1000000L + t.tv_usec;
+ if (!STRING_VALID(timstr))
+ {
+ media_svc_error("Invalid Parameter");
+ return 0;
+ }
- return tval/1000;
-}
+ /*Exif Format : %Y:%m:%d %H:%M:%S
+ Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
+ memset(&t, 0x00, sizeof(struct tm));
-int _media_svc_check_escape_char(char ch)
-{
- int i;
- char escape_char[3] = {'%', '_' ,'#'};
+ tzset();
+ time ( &rawtime );
+ localtime_r (&rawtime, &timeinfo);
- for (i = 0; i < 3; i++) {
- if (ch == escape_char[i]) {
- return 1;
+ if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t))
+ {
+ t.tm_isdst = timeinfo.tm_isdst;
+ if(t.tm_isdst != 0) {
+ media_svc_error("DST %d", t.tm_isdst);
}
+
+ modified_t = mktime(&t);
+ if(modified_t > 0)
+ {
+ return modified_t;
+ }
+ else
+ {
+ media_svc_error("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+ }
+ }
+ else
+ {
+ media_svc_error("Failed to get timeline : [%s]", timstr);
}
return 0;
}
-char *_media_svc_escape_str(char *input, int len)
+static int __media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
{
- int i = 0;
- int j = 0;
- char *result = NULL;
+ int idx = 0;
- result = (char*)malloc(len * 2 * sizeof(char) + 1);
- if (result == NULL) {
- return NULL;
+ *category = MEDIA_SVC_CATEGORY_UNKNOWN;
+
+ /*categorize from mimetype */
+ for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
+ if (strstr(mimetype, content_category[idx].content_type) != NULL) {
+ *category = (*category | content_category[idx].category_by_mime);
+ break;
+ }
}
- for (i = 0; i < len; i++, j++) {
- if (input[i] == '\0') break;
+ /*in application type, exitst sound file ex) x-smafs */
+ if (*category & MEDIA_SVC_CATEGORY_ETC) {
+ int prefix_len = strlen(content_category[0].content_type);
- if (_media_svc_check_escape_char(input[i])) {
- result[j] = '#';
- result[++j] = input[i];
- } else {
- result[j] = input[i];
+ for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
+ if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
+ *category ^= MEDIA_SVC_CATEGORY_ETC;
+ *category |= MEDIA_SVC_CATEGORY_SOUND;
+ break;
+ }
+ }
+
+ if(strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_ETC;
+ *category |= MEDIA_SVC_CATEGORY_SOUND;
}
}
- result[j] = '\0';
+ /*check music file in soun files. */
+ if (*category & MEDIA_SVC_CATEGORY_SOUND) {
+ int prefix_len = strlen(content_category[0].content_type) + 1;
+
+ for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
+ if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_SOUND;
+ *category |= MEDIA_SVC_CATEGORY_MUSIC;
+ break;
+ }
+ }
- return result;
+ /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
+ if(strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_SOUND;
+ *category |= MEDIA_SVC_CATEGORY_ETC;
+ }
+ } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
+ /*some video files don't have video stream. in this case it is categorize as music. */
+ char *ext = NULL;
+ /*"3gp" and "mp4" must check video stream and then categorize in directly. */
+ ext = strrchr(path, '.');
+ if (ext != NULL) {
+ if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0) || (strncasecmp(ext, _ASF_FILE, 5) == 0)) {
+ int audio = 0;
+ int video = 0;
+ int err = 0;
+
+ err = mm_file_get_stream_info(path, &audio, &video);
+ if (err == 0) {
+ if (audio > 0 && video == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_VIDEO;
+ *category |= MEDIA_SVC_CATEGORY_MUSIC;
+ }
+ }
+ //even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content.
+ }
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
}
-int _media_svc_rename_file( const char *old_name, const char *new_name)
+static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
{
- if((old_name == NULL) || (new_name == NULL))
- {
- media_svc_error("invalid file name");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ int ret = MS_MEDIA_ERR_NONE;
+ int category = 0;
+
+ media_svc_media_type_e type;
+
+ ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
}
- if (rename(old_name, new_name) < 0) {
- media_svc_error("Old : [%s] New : [%s] errno : [%s]", old_name, new_name, strerror(errno));
+ if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+ else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+ else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+
+ *media_type = type;
+
+ return ret;
+}
+
+/*
+drm_contentifo is not NULL, if the file is OMA DRM.
+If the file is not OMA DRM, drm_contentinfo must be NULL.
+*/
+static int __media_svc_get_mime_type(const char *path, char *mimetype)
+{
+ if (path == NULL)
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+
+ /*in case of normal files or failure to get mime in drm */
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ media_svc_error("aul_get_mime_from_file fail");
return MS_MEDIA_ERR_INTERNAL;
}
return MS_MEDIA_ERR_NONE;
}
-bool _media_svc_remove_file(const char *path)
+static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
{
- int result = -1;
+ int i = 0;
- result = remove(path);
- if (result == 0) {
- media_svc_debug("success to remove file");
- return TRUE;
- } else {
- media_svc_error("fail to remove file result errno = %s", strerror(errno));
- return FALSE;
+ for (i = strlen(file_path); i >= 0; i--) {
+ if (file_path[i] == '.') {
+ _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
+ return true;
+ }
+
+ if (file_path[i] == '/') {
+ return false;
+ }
}
+ return false;
}
-int _media_svc_remove_all_files_in_dir(const char *dir_path)
+static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
{
- struct dirent *entry = NULL;
- struct stat st;
- char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
- DIR *dir = NULL;
+ char *err_attr_name = NULL;
+ double gps_value = 0.0;
+ int mmf_error = MM_ERROR_NONE;
- dir = opendir(dir_path);
- if (dir == NULL) {
- media_svc_error("%s is not exist", dir_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (longitude != NULL) {
+ *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
+ }
+ } else {
+ SAFE_FREE(err_attr_name);
}
- while ((entry = readdir(dir)) != NULL) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
- continue;
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (latitude != NULL) {
+ *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
}
- snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry->d_name);
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
- if (stat(filename, &st) != 0) {
- continue;
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (altitude != NULL) {
+ *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
}
- if (S_ISDIR(st.st_mode)) {
- continue;
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
+{
+ media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
+
+ if (!image) {
+ media_svc_error("invalid image..");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ struct statfs fs;
+ if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
+ media_svc_error("error in statfs");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ long bsize_kbytes = fs.f_bsize >> 10;
+
+ if ((bsize_kbytes * fs.f_bavail) < 1024) {
+ media_svc_error("not enought space...");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ FILE *fp = NULL;
+ int nwrite = -1;
+ if (image != NULL && size > 0) {
+ fp = fopen(image_path, "w");
+
+ if (fp == NULL) {
+ media_svc_error("failed to open file");
+ return MS_MEDIA_ERR_INTERNAL;
}
- if (unlink(filename) != 0) {
- media_svc_error("failed to remove : %s", filename);
- closedir(dir);
+
+ nwrite = fwrite(image, 1, size, fp);
+ if (nwrite != size) {
+ media_svc_error("failed to write thumbnail");
+ fclose(fp);
return MS_MEDIA_ERR_INTERNAL;
}
+ fclose(fp);
}
- closedir(dir);
return MS_MEDIA_ERR_NONE;
}
-char *_media_svc_get_title_from_filepath (const char *path)
+static char *_media_svc_get_title_from_filepath (const char *path)
{
char *filename = NULL;
char *title = NULL;
@@ -411,6 +635,76 @@ char *_media_svc_get_title_from_filepath (const char *path)
return title;
}
+int _media_svc_rename_file( const char *old_name, const char *new_name)
+{
+ if((old_name == NULL) || (new_name == NULL))
+ {
+ media_svc_error("invalid file name");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ if (rename(old_name, new_name) < 0) {
+ media_svc_stderror(" ");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_remove_file(const char *path)
+{
+ int result = -1;
+
+ result = remove(path);
+ if (result == 0) {
+ media_svc_debug("success to remove file");
+ return MS_MEDIA_ERR_NONE;
+ } else {
+ media_svc_stderror("fail to remove file result");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+}
+
+int _media_svc_remove_all_files_in_dir(const char *dir_path)
+{
+ struct dirent entry;
+ struct dirent *result;
+ struct stat st;
+ char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
+ DIR *dir = NULL;
+
+ dir = opendir(dir_path);
+ if (dir == NULL) {
+ media_svc_error("%s is not exist", dir_path);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ while (!readdir_r(dir, &entry, &result)) {
+ if (result == NULL)
+ break;
+
+ if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
+ continue;
+ }
+ snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
+
+ if (stat(filename, &st) != 0) {
+ continue;
+ }
+ if (S_ISDIR(st.st_mode)) {
+ continue;
+ }
+ if (unlink(filename) != 0) {
+ media_svc_stderror("failed to remove");
+ closedir(dir);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+ }
+
+ closedir(dir);
+ return MS_MEDIA_ERR_NONE;
+}
+
static int _mkdir(const char *dir, mode_t mode) {
char tmp[256];
char *p = NULL;
@@ -429,13 +723,13 @@ static int _mkdir(const char *dir, mode_t mode) {
return mkdir(tmp, mode);
}
-static char* _media_svc_get_thumb_path(uid_t uid)
+char* _media_svc_get_thumb_internal_path(uid_t uid)
{
char *result_psswd = NULL;
struct group *grpinfo = NULL;
if(uid == getuid())
{
- result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
+ result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
grpinfo = getgrnam("users");
if(grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
@@ -459,7 +753,7 @@ static char* _media_svc_get_thumb_path(uid_t uid)
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir);
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
}
_mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
@@ -467,13 +761,13 @@ static char* _media_svc_get_thumb_path(uid_t uid)
return result_psswd;
}
-char* _media_svc_get_thumb_internal_path(uid_t uid)
+char* _media_svc_get_thumb_external_path(uid_t uid)
{
char *result_psswd = NULL;
- struct group *grpinfo = NULL;
+ struct group *grpinfo = NULL;
if(uid == getuid())
{
- result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
+ result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
grpinfo = getgrnam("users");
if(grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
@@ -497,7 +791,7 @@ char* _media_svc_get_thumb_internal_path(uid_t uid)
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
}
_mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
@@ -505,13 +799,49 @@ char* _media_svc_get_thumb_internal_path(uid_t uid)
return result_psswd;
}
-char* _media_svc_get_thumb_external_path(uid_t uid)
+static int __media_svc_check_thumb_dir(char *thumb_dir) {
+ int ret = 0;
+ DIR *dir = NULL;
+
+ dir = opendir(thumb_dir);
+ if (dir != NULL) {
+ closedir(dir);
+ } else {
+ media_svc_stderror("opendir fail");
+ if (errno == ENOENT) {
+ media_svc_error("[%s] is not exit. So, make it", thumb_dir);
+ ret = mkdir(thumb_dir, 0777);
+ if (ret < 0) {
+ media_svc_error("make fail");
+ goto ERROR;
+ }
+ } else {
+ goto ERROR;
+ }
+
+ ret = chmod(thumb_dir, 0777);
+ if (ret != 0) {
+ media_svc_stderror("chmod failed");
+ }
+ ret = chown(thumb_dir, 5000, 5000);
+ if (ret != 0) {
+ media_svc_stderror("chown failed");
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+
+ERROR:
+ return -1;
+}
+
+static char* _media_svc_get_thumb_path(uid_t uid)
{
char *result_psswd = NULL;
- struct group *grpinfo = NULL;
+ struct group *grpinfo = NULL;
if(uid == getuid())
{
- result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
+ result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
grpinfo = getgrnam("users");
if(grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
@@ -535,7 +865,7 @@ char* _media_svc_get_thumb_external_path(uid_t uid)
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir);
}
_mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
@@ -543,53 +873,9 @@ char* _media_svc_get_thumb_external_path(uid_t uid)
return result_psswd;
}
-int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
-{
- media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
-
- if (!image) {
- media_svc_error("invalid image..");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- struct statfs fs;
- if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
- media_svc_error("error in statfs");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- long bsize_kbytes = fs.f_bsize >> 10;
-
- if ((bsize_kbytes * fs.f_bavail) < 1024) {
- media_svc_error("not enought space...");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- FILE *fp = NULL;
- int nwrite = -1;
- if (image != NULL && size > 0) {
- fp = fopen(image_path, "w");
-
- if (fp == NULL) {
- media_svc_error("failed to open file");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- nwrite = fwrite(image, 1, size, fp);
- if (nwrite != size) {
- media_svc_error("failed to write thumbnail");
- fclose(fp);
- return MS_MEDIA_ERR_INTERNAL;
- }
- fclose(fp);
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-
-bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
+int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
{
+ int ret = MS_MEDIA_ERR_NONE;
char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
char *thumb_dir = NULL;
@@ -598,16 +884,21 @@ bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *
thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
+ ret = __media_svc_check_thumb_dir(thumb_dir);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("__media_svc_check_thumb_dir");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
memset(file_ext, 0, sizeof(file_ext));
- if (!_media_svc_get_file_ext(pathname, file_ext)) {
+ if (!__media_svc_get_file_ext(pathname, file_ext)) {
media_svc_error("get file ext fail");
}
- int err = -1;
- err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
- if (err < 0) {
- media_svc_error("mb_svc_generate_hash_code failed : %d", err);
- return FALSE;
+ ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
+ return MS_MEDIA_ERR_INTERNAL;
}
//media_svc_debug("img format is [%s]", img_format);
@@ -622,31 +913,14 @@ bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *
thumbfile_ext = "bmp";
} else {
media_svc_error("Not proper img format");
- return FALSE;
+ return MS_MEDIA_ERR_INTERNAL;
}
snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
_strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
//media_svc_debug("thumb_path is [%s]", thumb_path);
- return TRUE;
-}
-
-bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
-{
- int i = 0;
-
- for (i = strlen(file_path); i >= 0; i--) {
- if (file_path[i] == '.') {
- _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
- return true;
- }
-
- if (file_path[i] == '/') {
- return false;
- }
- }
- return false;
+ return MS_MEDIA_ERR_NONE;
}
int _media_svc_get_file_time(const char *full_path)
@@ -664,13 +938,14 @@ int _media_svc_get_file_time(const char *full_path)
return statbuf.st_mtime;
}
-int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
const char *path, media_svc_media_type_e *media_type, bool refresh)
{
int ret = MS_MEDIA_ERR_NONE;
char * media_uuid = NULL;
char * file_name = NULL;
struct stat st;
+ bool drm_type = false;
char mime_type[256] = {0};
ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
@@ -683,7 +958,7 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_
content_info->size = st.st_size;
//media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
} else {
- media_svc_error("stat failed : %s", strerror(errno));
+ media_svc_stderror("stat failed");
}
/* Set default GPS value before extracting meta information */
@@ -700,7 +975,7 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_
media_svc_error("strcpy error");
SAFE_FREE(title);
} else {
- media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ media_svc_error("Can't extract title");
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
}
@@ -739,11 +1014,17 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_
return MS_MEDIA_ERR_NONE;
}
+ ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
+
content_info->storage_type = storage_type;
time(&content_info->added_time);
media_uuid = _media_info_generate_uuid();
- media_svc_retvm_if(media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Invalid UUID");
+ if(media_uuid == NULL) {
+ _media_svc_destroy_content_info(content_info);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
@@ -753,16 +1034,17 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_
SAFE_FREE(file_name);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
- ret = _media_svc_get_mime_type(path, mime_type);
- if (ret < 0) {
- media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ /* if the file is DRM file, drm_type value is DRM_TRUE(1).
+ if drm_contentinfo is not NULL, the file is OMA DRM.*/
+ ret = __media_svc_get_mime_type(path, mime_type);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
+
+ media_svc_debug("mime [%s]", mime_type);
+ content_info->is_drm = drm_type;
- media_svc_error("mime [%s]", mime_type);
+ ret = __media_svc_get_media_type(path, mime_type, media_type);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
- ret = _media_svc_get_media_type(path, mime_type, media_type);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
media_svc_error("invalid media_type condition[%d]", *media_type);
return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -784,28 +1066,38 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
+int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
{
- if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
- media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
- char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
- memset(buf, 0x00, sizeof(buf));
- memset(description_buf, 0x00, sizeof(description_buf));
-
int ret = MS_MEDIA_ERR_NONE;
double value = 0.0;
int orient_value = 0;
int exif_width = 0;
int exif_height = 0;
ExifData *ed = NULL;
+ int has_datetaken = FALSE;
+ int datetaken_size = 19;
+ double fnumber = 0.0;
+ int iso = 0;
+ char *path = NULL;
- char *path = content_info->path;
- if (path == NULL) {
- media_svc_error("path is NULL");
+ char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+ char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
+ char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+ char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+
+ memset(buf, 0x00, sizeof(buf));
+ memset(description_buf, 0x00, sizeof(description_buf));
+ memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
+ memset(model_buf, 0x00, sizeof(model_buf));
+
+ if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+ media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ path = content_info->path;
+ if (!STRING_VALID(path)) {
+ media_svc_error("Invalid Path");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -813,7 +1105,7 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, me
ed = exif_data_new_from_file(path);
if (!ed) {
- media_svc_debug("There is no exif data in [ %s ]", path);
+ media_svc_sec_debug("There is no exif data in [ %s ]", path);
}
if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
@@ -875,15 +1167,19 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, me
memset(buf, 0x00, sizeof(buf));
- if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
+ if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
if (strlen(buf) == 0) {
//media_svc_debug("time is NULL");
} else {
- //media_svc_debug("time is %s", buf);
+#if 0
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
+#else
+ ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
+#endif
if(ret != MS_MEDIA_ERR_NONE) {
media_svc_error("strcpy error");
} else {
+ has_datetaken = TRUE;
/* This is same as recorded_date */
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
if(ret != MS_MEDIA_ERR_NONE)
@@ -892,6 +1188,82 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, me
}
}
+ memset(buf, 0x00, sizeof(buf));
+
+ if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
+ if (strlen(buf) == 0) {
+ //media_svc_debug("time is NULL");
+ } else {
+#if 0
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
+#else
+ ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
+#endif
+ if(ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("strcpy error");
+ } else {
+ has_datetaken = TRUE;
+ /* This is same as recorded_date */
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ }
+ }
+ }
+
+ if (has_datetaken) {
+ content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
+ if (content_info->timeline == 0) {
+ content_info->timeline = content_info->modified_time;
+ } else {
+ media_svc_debug("Timeline : %ld", content_info->timeline);
+ }
+ }
+
+ /* Get exposure_time value from exif. */
+ if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
+ if (strlen(exposure_time_buf) == 0) {
+ media_svc_error("exposure_time_buf is NULL");
+ } else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ }
+ }
+
+ /* Get fnumber value from exif. */
+ if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_IFD_0, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
+ if (fnumber > 0.0) {
+ content_info->media_meta.fnumber = fnumber;
+ } else {
+ content_info->media_meta.fnumber = 0.0;
+ }
+ } else {
+ content_info->media_meta.fnumber = 0.0;
+ }
+
+ /* Get iso value from exif. */
+ if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_IFD_0, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
+ if (iso > 0) {
+ content_info->media_meta.iso = iso;
+ } else {
+ content_info->media_meta.iso = 0;
+ }
+ } else {
+ content_info->media_meta.iso = 0;
+ }
+
+ /* Get model value from exif. */
+ if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
+ if (strlen(model_buf) == 0) {
+ media_svc_error("model_buf is NULL");
+ } else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ }
+ }
+
/* Get orientation value from exif. */
if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
@@ -925,165 +1297,209 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, me
content_info->media_meta.height = 0;
}
- content_info->media_meta.weather = NULL;
-
if (ed != NULL) exif_data_unref(ed);
- /* Set filename to title for image media */
- char *title = NULL;
- title = _media_svc_get_title_from_filepath(content_info->path);
- if (title) {
- ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
- if(ret != MS_MEDIA_ERR_NONE)
- media_svc_error("strcpy error");
- SAFE_FREE(title);
- } else {
- media_svc_error("Can't extract title from filepath [%s]", content_info->path);
- }
-
-#if 0
- /* Extracting thumbnail */
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- int width = 0;
- int height = 0;
-
- ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
- if (ret < 0) {
- media_svc_error("thumbnail_request_from_db failed: %d", ret);
- } else {
- //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- }
-
- content_info->media_meta.width = width;
- content_info->media_meta.height = height;
-
- if (STRING_VALID(thumb_path))
- ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
- else
- content_info->thumbnail_path = NULL;
-
- if(ret != MS_MEDIA_ERR_NONE)
- media_svc_error("strcpy error");
-#endif
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
+int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
{
- MMHandleType content = 0;
MMHandleType tag = 0;
char *p = NULL;
- void *image = NULL;
int size = -1;
int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
int mmf_error = MM_ERROR_NONE;
- bool thumb_extracted_from_drm = FALSE;
char *err_attr_name = NULL;
char *title = NULL;
- bool extract_thumbnail = FALSE;
- bool append_album = FALSE;
int album_id = 0;
- double gps_value = 0.0;
int ret = MS_MEDIA_ERR_NONE;
- /*Get Content attribute ===========*/
- mmf_error = mm_file_create_content_attrs(&content, content_info->path);
+ /*Get Content Tag attribute ===========*/
+ mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
if (mmf_error == MM_ERROR_NONE) {
- /*Common attribute*/
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
- if (mmf_error != MM_ERROR_NONE) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+
+ //media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
+ } else {
SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
+ //media_svc_debug("album - unknown");
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
} else {
- //media_svc_debug("duration : %d", content_info->media_meta.duration);
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("artist - unknown");
}
- /*Sound/Music attribute*/
- if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist);
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("album_artist - unknown");
+ }
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
- }
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
+ //media_svc_debug("genre : %s", content_info->media_meta.genre);
+ /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
+ /*
+ if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
+ content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
}
+ */
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("genre - unknown");
+ }
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("channel : %d", content_info->media_meta.channel);
- }
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
+ if(!isspace(*p)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
- } else {
- media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
}
- }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
- int audio_bitrate = 0;
- int video_bitrate = 0;
+ else {
+ int idx = 0;
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("audio bit rate : %d", audio_bitrate);
- }
+ for(idx = 0; idx < size; idx++) {
+ if(isspace(*p)) {
+ media_svc_debug("SPACE [%s]", p);
+ p++;
+ continue;
+ } else {
+ media_svc_debug("Not SPACE [%s]", p);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ break;
+ }
+ }
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("video bit rate : %d", video_bitrate);
+ if(idx == size)
+ {
+ media_svc_debug("Can't extract title. All string is space");
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
+ } else {
+ media_svc_error("Can't extract title");
+ }
+ }
}
-
- content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
+ } else {
+ SAFE_FREE(err_attr_name);
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
} else {
- //media_svc_debug("width : %d", content_info->media_meta.width);
+ media_svc_error("Can't extract title");
}
+ }
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
- } else {
- //media_svc_debug("height : %d", content_info->media_meta.height);
- }
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("desc : %s", content_info->media_meta.description);
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ //media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
} else {
- media_svc_error("Not support type");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ //media_svc_debug("composer - unknown");
+ SAFE_FREE(err_attr_name);
}
- mmf_error = mm_file_destroy_content_attrs(content);
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ //media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright);
+ } else {
+ //media_svc_debug("copyright - unknown");
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_destroy_tag_attrs(tag);
if (mmf_error != MM_ERROR_NONE) {
- media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ media_svc_error("fail to free tag attr - err(%x)", mmf_error);
}
- } else {
- media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
+ } else {
+ /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
+ char *title = NULL;
+ media_svc_error("no tag information");
+
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
+ } else {
+ media_svc_error("Can't extract title");
+ }
+
+ content_info->album_id = album_id;
}
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
+{
+ MMHandleType content = 0;
+ MMHandleType tag = 0;
+ char *p = NULL;
+ void *image = NULL;
+ int size = -1;
+ int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
+ int mmf_error = MM_ERROR_NONE;
+ bool thumb_extracted_from_drm = FALSE;
+ char *err_attr_name = NULL;
+ char *title = NULL;
+ bool extract_thumbnail = FALSE;
+ bool append_album = FALSE;
+ int album_id = 0;
+ int ret = MS_MEDIA_ERR_NONE;
+ int cdis_value = 0;
+
/*Get Content Tag attribute ===========*/
mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
@@ -1111,6 +1527,17 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
//media_svc_debug("artist - unknown");
}
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist);
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("album_artist - unknown");
+ }
+
mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
@@ -1165,7 +1592,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
media_svc_error("strcpy error");
SAFE_FREE(title);
} else {
- media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ media_svc_error("Can't extract title");
}
}
}
@@ -1178,7 +1605,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
media_svc_error("strcpy error");
SAFE_FREE(title);
} else {
- media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ media_svc_error("Can't extract title");
}
}
@@ -1193,15 +1620,49 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
}
mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
- if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
- ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
+ if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
+ char time_info[64] = {0, };
+ char p_value[64] = {0, };
+ int idx = 0;
+ memset(time_info, 0x00, sizeof(time_info));
+ memset(p_value, 0x00, sizeof(p_value));
+ strncpy(p_value, p, size);
+ for(idx =0; idx < size; idx++) {
+ if(p_value[idx] == '-') {
+ time_info[idx] = ':';
+ } else if(p_value[idx] != '\0') {
+ time_info[idx] = p_value[idx];
+ } else {
+ media_svc_error("strcpy error");
+ break;
+ }
+ }
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
+ } else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
+ }
+
if(ret != MS_MEDIA_ERR_NONE) {
media_svc_error("strcpy error");
} else {
/* This is same as datetaken */
- ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, p);
+#if 0
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
+#else
+ int datetaken_size = 19;
+ ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
+#endif
if(ret != MS_MEDIA_ERR_NONE)
media_svc_error("strcpy error");
+
+ content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
+ if (content_info->timeline == 0) {
+ content_info->timeline = content_info->modified_time;
+ } else {
+ media_svc_debug("Timeline : %ld", content_info->timeline);
+ }
}
//media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date);
} else {
@@ -1263,125 +1724,109 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
content_info->media_meta.rating = 0;
}
- if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
- /*Initialize album_id to 0. below code will set the album_id*/
- content_info->album_id = album_id;
- ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- media_svc_debug("album does not exist. So start to make album art");
- extract_thumbnail = TRUE;
- append_album = TRUE;
- } else {
- extract_thumbnail = FALSE;
- append_album = FALSE;
- }
+ /*Initialize album_id to 0. below code will set the album_id*/
+ content_info->album_id = album_id;
+ ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ media_svc_debug("album does not exist. So start to make album art");
+ extract_thumbnail = TRUE;
+ append_album = TRUE;
} else {
- content_info->album_id = album_id;
+ extract_thumbnail = TRUE;
append_album = FALSE;
-
- if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
- (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
-
- media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
- extract_thumbnail = TRUE;
- } else {
-
- media_svc_debug("album already exists. don't need to make album art");
- ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
- media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, content_info);
- extract_thumbnail = FALSE;
- }
}
-
- if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
- SAFE_FREE(err_attr_name);
+ } else {
+ content_info->album_id = album_id;
+ append_album = FALSE;
+
+ if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
+ (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
+
+ media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
+ extract_thumbnail = TRUE;
+ } else {
+ media_svc_debug("album already exists. don't need to make album art");
+ ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
+ media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, content_info);
+ extract_thumbnail = TRUE;
+ }
+ }
+
+ if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
+ SAFE_FREE(err_attr_name);
+ } else {
+ //media_svc_debug("artwork size1 [%d]", size);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to get artwork size - err(%x)", mmf_error);
+ SAFE_FREE(err_attr_name);
+ } else {
+ //media_svc_debug("artwork size2 [%d]", size);
+ }
+ if (image != NULL && size > 0) {
+ int ret = MS_MEDIA_ERR_NONE;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
+ int artwork_mime_size = -1;
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
+ if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
+ ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to Get Thumbnail Path");
+ }
} else {
- //media_svc_debug("artwork size1 [%d]", size);
- }
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
- if (mmf_error != MM_ERROR_NONE) {
- media_svc_error("fail to get artwork size - err(%x)", mmf_error);
SAFE_FREE(err_attr_name);
- } else {
- //media_svc_debug("artwork size2 [%d]", size);
}
- if (image != NULL && size > 0) {
- bool result = FALSE;
- int ret = MS_MEDIA_ERR_NONE;
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
- int artwork_mime_size = -1;
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
- if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
- result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
- if (result == FALSE) {
- media_svc_error("Fail to Get Thumbnail Path");
- }
- } else {
- SAFE_FREE(err_attr_name);
+
+ if(strlen(thumb_path) > 0)
+ {
+ ret = _media_svc_save_image(image, size, thumb_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to Save Thumbnail Image");
}
-
- if(strlen(thumb_path) > 0)
- {
- ret = _media_svc_save_image(image, size, thumb_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Fail to Save Thumbnail Image");
- }
- else {
- ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
- if(ret != MS_MEDIA_ERR_NONE)
- media_svc_error("strcpy error");
- }
+ else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy error");
}
}
}
-
- if(append_album == TRUE) {
-
- if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
- (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
- ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
- else
- ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
-
- content_info->album_id = album_id;
- }
- } else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
- if (mmf_error == MM_ERROR_NONE) {
- if (gps_value == 0.0)
- content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
- else
- content_info->media_meta.longitude = gps_value;
- } else {
- SAFE_FREE(err_attr_name);
- }
+ }
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
- if (mmf_error == MM_ERROR_NONE) {
- if (gps_value == 0.0)
- content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
- else
- content_info->media_meta.latitude = gps_value;
- } else {
- SAFE_FREE(err_attr_name);
- }
+ if(append_album == TRUE) {
+ if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
+ (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
+ ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
+ else
+ ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
- if (mmf_error == MM_ERROR_NONE) {
- if (gps_value == 0.0)
- content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
- else
- content_info->media_meta.altitude = gps_value;
- } else {
+ content_info->album_id = album_id;
+ }
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ double longitude = 0.0;
+ double latitude = 0.0;
+ double altitude = 0.0;
+
+ __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
+ content_info->media_meta.longitude = longitude;
+ content_info->media_meta.latitude = latitude;
+ content_info->media_meta.altitude = altitude;
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ cdis_value = 0;
SAFE_FREE(err_attr_name);
}
+
+ media_svc_debug("CDIS : %d", cdis_value);
}
mmf_error = mm_file_destroy_tag_attrs(tag);
@@ -1400,12 +1845,118 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
media_svc_error("strcpy error");
SAFE_FREE(title);
} else {
- media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ media_svc_error("Can't extract title");
}
content_info->album_id = album_id;
}
+ /*Get Content attribute ===========*/
+ if (cdis_value == 1) {
+ mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
+ } else {
+ mmf_error = mm_file_create_content_attrs(&content, content_info->path);
+ }
+
+ if (mmf_error == MM_ERROR_NONE) {
+ /*Common attribute*/
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("duration : %d", content_info->media_meta.duration);
+ }
+
+ /*Sound/Music attribute*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("channel : %d", content_info->media_meta.channel);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
+ } else {
+ media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
+ }
+ }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
+ int audio_bitrate = 0;
+ int video_bitrate = 0;
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("audio bit rate : %d", audio_bitrate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("video bit rate : %d", video_bitrate);
+ }
+
+ content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("width : %d", content_info->media_meta.width);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("height : %d", content_info->media_meta.height);
+ }
+
+ } else {
+ media_svc_error("Not support type");
+ mmf_error = mm_file_destroy_content_attrs(content);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ }
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ mmf_error = mm_file_destroy_content_attrs(content);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ }
+ } else {
+ media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
+ }
+
return MS_MEDIA_ERR_NONE;
}
@@ -1434,6 +1985,8 @@ void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
SAFE_FREE(content_info->media_meta.track_num);
SAFE_FREE(content_info->media_meta.description);
SAFE_FREE(content_info->media_meta.datetaken);
+ SAFE_FREE(content_info->media_meta.exposure_time);
+ SAFE_FREE(content_info->media_meta.model);
SAFE_FREE(content_info->media_meta.weather);
SAFE_FREE(content_info->media_meta.title_pinyin);
@@ -1448,18 +2001,23 @@ void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
return;
}
-int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
+int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
{
if(STRING_VALID(path))
{
- if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
+ if(strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0)
{
*storage_type = MEDIA_SVC_STORAGE_INTERNAL;
}
- else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
+ else if(strncmp (path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)
{
*storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
}
+ else
+ {
+ media_svc_error("Invalid Path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
}
else
{
@@ -1504,125 +2062,24 @@ char *_media_svc_replace_path(char *s, const char *olds, const char *news)
bool _media_svc_is_drm_file(const char *path)
{
-#ifdef __SUPPORT_DRM
- int ret;
- drm_bool_type_e is_drm_file = DRM_UNKNOWN;
-
- ret = drm_is_drm_file(path,&is_drm_file);
- if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
- return TRUE;
-#endif
return FALSE;
}
-int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
-{
- int i = 0;
- int err = 0;
-
- *category = MEDIA_SVC_CATEGORY_UNKNOWN;
-
- //media_svc_debug("mime type : %s", mimetype);
-
- /*categorize from mimetype */
- for (i = 0; i < CONTENT_TYPE_NUM; i++) {
- if (strstr(mimetype, content_category[i].content_type) != NULL) {
- *category = (*category | content_category[i].category_by_mime);
- break;
- }
- }
-
- /*in application type, exitst sound file ex) x-smafs */
- if (*category & MEDIA_SVC_CATEGORY_ETC) {
- int prefix_len = strlen(content_category[0].content_type);
-
- for (i = 0; i < SOUND_MIME_NUM; i++) {
- if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
- *category ^= MEDIA_SVC_CATEGORY_ETC;
- *category |= MEDIA_SVC_CATEGORY_SOUND;
- break;
- }
- }
- }
-
- /*check music file in soun files. */
- if (*category & MEDIA_SVC_CATEGORY_SOUND) {
- int prefix_len = strlen(content_category[0].content_type) + 1;
-
- //media_svc_error("mime_type : %s", mimetype + prefix_len);
-
- for (i = 0; i < MUSIC_MIME_NUM; i++) {
- if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
- *category ^= MEDIA_SVC_CATEGORY_SOUND;
- *category |= MEDIA_SVC_CATEGORY_MUSIC;
- break;
- }
- }
-
- /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
- if(strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
- *category ^= MEDIA_SVC_CATEGORY_SOUND;
- *category |= MEDIA_SVC_CATEGORY_ETC;
- }
- } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
- /*some video files don't have video stream. in this case it is categorize as music. */
- char *ext;
- /*"3gp" and "mp4" must check video stream and then categorize in directly. */
- ext = strrchr(path, '.');
- if (ext != NULL) {
- if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
- int audio = 0;
- int video = 0;
-
- err = mm_file_get_stream_info(path, &audio, &video);
- if (err == 0) {
- if (audio > 0 && video == 0) {
- *category ^= MEDIA_SVC_CATEGORY_VIDEO;
- *category |= MEDIA_SVC_CATEGORY_MUSIC;
- }
- }
- }
- }
- }
-
- //media_svc_debug("category_from_ext : %d", *category);
-
- return err;
-}
-
-int _media_svc_get_mime_type(const char *path, char *mimetype)
-{
- if (path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /*in case of normal files or failure to get mime in drm */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- media_svc_error("aul_get_mime_from_file fail");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
+int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- int category = 0;
- media_svc_media_type_e type;
+ ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
- ret = _media_svc_get_content_type_from_mime(path, mime_type, &category);
- if (ret < 0) {
- media_svc_error("_media_svc_get_content_type_from_mime failed : %d", ret);
+ if(ret != MS_MEDIA_ERR_NONE)
+ {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ ret = MS_MEDIA_ERR_INTERNAL;
+ }
+ else
+ {
+ media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
}
-
- if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
- else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
- else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
- else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
- else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
-
- *media_type = type;
return ret;
}
@@ -1659,3 +2116,22 @@ bool _media_svc_check_pinyin_support(void)
/*Check CSC*/
return TRUE;
}
+
+int _media_svc_request_extract_all_thumbs(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = thumbnail_request_extract_all_thumbs(uid);
+
+ if(ret != MS_MEDIA_ERR_NONE)
+ {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ ret = MS_MEDIA_ERR_INTERNAL;
+ }
+ else
+ {
+ media_svc_sec_debug("thumbnail_request_extract_all_thumbs");
+ }
+
+ return ret;
+}
diff --git a/src/common/media-svc.c b/src/common/media-svc.c
index 5b877a6..0bd62a7 100755
--- a/src/common/media-svc.c
+++ b/src/common/media-svc.c
@@ -27,9 +27,11 @@
#include "media-svc-debug.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
+#include "media-svc-env.h"
#include "media-svc-media-folder.h"
#include "media-svc-album.h"
#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;
@@ -40,9 +42,14 @@ static __thread int g_media_svc_move_item_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_update_item_data_cnt = 1;
+static __thread int g_media_svc_update_item_cur_data_cnt = 0;
+
/* Flag for items to be published by notification */
static __thread int g_insert_with_noti = FALSE;
+#define DEFAULT_MEDIA_SVC_STORAGE_ID "media"
+
int media_svc_connect(MediaSvcHandle **handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
@@ -50,18 +57,10 @@ int media_svc_connect(MediaSvcHandle **handle, uid_t uid)
media_svc_debug_func();
-#if 1 //Use libmedia_utils API
ret = media_db_connect(&db_handle,uid);
if(ret != MS_MEDIA_ERR_NONE)
return ret;
-#else
- sqlite3 * db_handle = NULL;
-
- ret = _media_svc_connect_db_with_handle(&db_handle);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-#endif
-
*handle = db_handle;
return MS_MEDIA_ERR_NONE;
}
@@ -74,16 +73,10 @@ int media_svc_disconnect(MediaSvcHandle *handle)
media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
-#if 1 //Use libmedia_utils API
int ret = MS_MEDIA_ERR_NONE;
ret = media_db_disconnect(db_handle);
return ret;
-#else
- sqlite3 * db_handle = (sqlite3 *)handle;
-
- return _media_svc_disconnect_db_with_handle(db_handle);
-#endif
}
int media_svc_create_table(MediaSvcHandle *handle, uid_t uid)
@@ -93,68 +86,77 @@ int media_svc_create_table(MediaSvcHandle *handle, uid_t uid)
media_svc_debug_func();
+ ret = _media_svc_init_table_query();
media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
/*create media table*/
- ret = _media_svc_create_media_table(handle, uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*create folder table*/
- ret = _media_svc_create_folder_table(handle, uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*create playlist_map table*/
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*create playlist table*/
- ret = _media_svc_create_playlist_table(handle, uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/* create album table*/
- ret = _media_svc_create_album_table(handle, uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*create tag_map table*/
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*create tag table*/
- ret = _media_svc_create_tag_table(handle,uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*create bookmark table*/
- ret = _media_svc_create_bookmark_table(handle, uid);
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-#if 0 /*unify media and custom table*/
- /*create custom table*/
- ret = _media_svc_create_custom_table(handle, uid);
+ /*create storage table*/
+ ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-#endif
+
+ /*init storage table*/
+ ret = _media_svc_init_storage(db_handle, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ _media_svc_destroy_table_query();
+
+ media_svc_debug_func();
return MS_MEDIA_ERR_NONE;
}
-int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type)
+int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
media_svc_storage_type_e type;
- ret = _media_svc_get_store_type_by_path(path, &type);
- media_svc_retvm_if(ret < MS_MEDIA_ERR_NONE, ret, "_media_svc_get_store_type_by_path failed : %d", ret);
+ ret = _media_svc_get_store_type_by_path(path, &type, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_store_type_by_path failed : %d", ret);
*storage_type = type;
return ret;
}
-int media_svc_get_mime_type(const char *path, char *mimetype)
+int media_svc_get_file_info(MediaSvcHandle *handle, const char *path, time_t *modified_time, unsigned long long *size)
{
int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
- ret = _media_svc_get_mime_type(path, mimetype);
-
- return ret;
-}
-
-int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
-{
- int ret = MS_MEDIA_ERR_NONE;
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- ret = _media_svc_get_media_type(path, mime_type, media_type);
+ ret = _media_svc_get_fileinfo_by_path(db_handle, path, modified_time, size);
return ret;
}
@@ -254,21 +256,24 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e
memset(&content_info, 0, sizeof(media_svc_content_info_s));
/*Set media info*/
- ret = _media_svc_set_media_info(&content_info, storage_type, path, &media_type, FALSE);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
+ ret = _media_svc_set_media_info(&content_info, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, path, &media_type, FALSE);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ return ret;
+ }
if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
/*Do nothing.*/
} else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
- ret = _media_svc_extract_image_metadata(&content_info, media_type);
+ ret = _media_svc_extract_image_metadata(handle, &content_info, media_type, uid);
} else {
ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, uid);
}
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ 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, path, storage_type, folder_uuid, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, path, storage_type, folder_uuid, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
@@ -307,9 +312,8 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e
_media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
/* Recreate noti list */
- if (_media_svc_create_noti_list(g_media_svc_insert_item_data_cnt) != MS_MEDIA_ERR_NONE) {
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ 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;
@@ -335,64 +339,67 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_
media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+#if 0
if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
media_svc_error("storage type is incorrect[%d]", storage_type);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+#endif
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_type, path, &media_type, FALSE);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_set_media_info(&content_info, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, path, &media_type, FALSE);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ return ret;
+ }
if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
/*Do nothing.*/
} else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
- ret = _media_svc_extract_image_metadata(&content_info, media_type);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_extract_image_metadata(handle, &content_info, media_type, uid);
} else {
ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
}
+ 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, path, storage_type, folder_uuid, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, path, storage_type, folder_uuid, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
#if 1
/* Extracting thumbnail */
- if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- int width = 0;
- int height = 0;
-
- ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
- if (ret < 0) {
- media_svc_error("thumbnail_request_from_db failed: %d", ret);
- } else {
- media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
- if (ret < 0) {
- media_svc_error("__media_svc_malloc_and_strncpy failed : %d", ret);
+ if (content_info.thumbnail_path == NULL) {
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
+ if(ret == MS_MEDIA_ERR_NONE) {
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
}
- }
- if (content_info.media_meta.width <= 0)
- content_info.media_meta.width = width;
+ if (content_info.media_meta.width <= 0)
+ content_info.media_meta.width = width;
- if (content_info.media_meta.height <= 0)
- content_info.media_meta.height = height;
+ if (content_info.media_meta.height <= 0)
+ content_info.media_meta.height = height;
+ }
}
#endif
+
ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE, uid);
if (ret == MS_MEDIA_ERR_NONE) {
media_svc_debug("Insertion is successful. Sending noti for this");
_media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
+ } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
+ media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
}
_media_svc_destroy_content_info(&content_info);
@@ -403,6 +410,8 @@ int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e sto
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0, };
+ memset(folder_uuid, 0, sizeof(folder_uuid));
media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
@@ -414,27 +423,9 @@ int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e sto
media_svc_debug("storage[%d], folder_path[%s]", storage_type, path);
- /*Get folder info*/
- char *folder_name = NULL;
- int folder_modified_date = 0;
- char *folder_uuid = _media_info_generate_uuid();
- if(folder_uuid == NULL ) {
- media_svc_error("Invalid UUID");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- folder_name = g_path_get_basename(path);
- folder_modified_date = _media_svc_get_file_time(path);
-
- ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date, uid);
- SAFE_FREE(folder_name);
+ ret = _media_svc_get_and_append_folder(db_handle, DEFAULT_MEDIA_SVC_STORAGE_ID, path, storage_type, folder_uuid, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_append_folder error [%d]", ret);
- return ret;
- }
-
- return MS_MEDIA_ERR_NONE;
+ return ret;
}
int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt)
@@ -505,7 +496,7 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto
}
/*check and update folder*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid, uid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, dest_path, dest_storage, folder_uuid, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*get filename*/
@@ -515,13 +506,21 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto
modified_time = _media_svc_get_file_time(dest_path);
/*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
- ret = _media_svc_get_media_type_by_path(handle, src_path, &media_type);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_media_type_by_path(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, src_path, &media_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_get_media_type_by_path failed");
+ SAFE_FREE(file_name);
+ return ret;
+ }
if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
/*get old thumbnail_path*/
- ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
- media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
+ ret = _media_svc_get_thumbnail_path_by_path(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, src_path, old_thumb_path);
+ if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
+ media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
+ SAFE_FREE(file_name);
+ return ret;
+ }
/* If old thumb path is default or not */
if (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
@@ -546,7 +545,7 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto
/* Get notification info */
media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(handle, dest_path, MS_MEDIA_ITEM_FILE, &noti_item);
+ ret = _media_svc_get_noti_info(handle, DEFAULT_MEDIA_SVC_STORAGE_ID, dest_path, MS_MEDIA_ITEM_FILE, &noti_item);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/* Send notification for move */
@@ -610,13 +609,13 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto
}
/*rename thumbnail file*/
- if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
- if((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+// if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ if((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
ret = _media_svc_rename_file(old_thumb_path,new_thumb_path);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("_media_svc_rename_file failed : %d", ret);
}
- }
+// }
return MS_MEDIA_ERR_NONE;
}
@@ -705,15 +704,17 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *storage_id
media_svc_debug_func();
media_svc_retvm_if(db_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");
int media_type = -1;
- ret = _media_svc_get_media_type_by_path(db_handle, path, &media_type);
+ ret = _media_svc_get_media_type_by_path(db_handle, storage_id, path, &media_type);
media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
+#if 0
if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
/*Get thumbnail path to delete*/
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
} else if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
int count = 0;
@@ -722,45 +723,49 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *storage_id
if (count == 1) {
/*Get thumbnail path to delete*/
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
}
}
+#endif
+ /*Get thumbnail path to delete*/
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
+ media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
- /* Get notification info */
- media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, &noti_item);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ if (g_media_svc_insert_item_data_cnt == 1) {
- /*Delete item*/
- ret = _media_svc_delete_item_by_path(db_handle, path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*Delete item*/
+ ret = _media_svc_delete_item_by_path(db_handle, storage_id, path, FALSE, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
+ _media_svc_destroy_noti_item(noti_item);
+
+ return ret;
+ }
+
+ /* Send notification */
+ media_svc_debug("Deletion is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
_media_svc_destroy_noti_item(noti_item);
+ } else {
+ ret = _media_svc_delete_item_by_path(db_handle, storage_id, path, TRUE, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
+ return ret;
+ }
- return ret;
}
- /* Send notification */
- media_svc_debug("Deletion is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
- _media_svc_destroy_noti_item(noti_item);
-
/*Delete thumbnail*/
if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
- int thumb_count = 1;
- /* Get count of media, which contains same thumbnail for music */
- if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
- ret = _media_svc_get_thumbnail_count(db_handle, thumb_path, &thumb_count);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Failed to get thumbnail count : %d", ret);
- }
- }
-
- if (thumb_count == 1) {
- if (_media_svc_remove_file(thumb_path) == FALSE) {
- media_svc_error("fail to remove thumbnail file.");
- }
+ ret = _media_svc_remove_file(thumb_path);
+ if(ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("fail to remove thumbnail file.");
}
}
@@ -857,9 +862,10 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor
media_svc_media_type_e media_type;
media_svc_retvm_if(db_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");
- if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL) && (storage_type != MEDIA_SVC_STORAGE_CLOUD)) {
media_svc_error("storage type is incorrect[%d]", storage_type);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -868,72 +874,79 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor
memset(&content_info, 0, sizeof(media_svc_content_info_s));
/*Set media info*/
- ret = _media_svc_set_media_info(&content_info, storage_type, path, &media_type, TRUE);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_set_media_info(&content_info, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, path, &media_type, TRUE);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ return ret;
+ }
/* Initialize thumbnail information to remake thumbnail. */
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
- ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+ }
- if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
ret = _media_svc_remove_file(thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
}
}
- ret = _media_svc_update_thumbnail_path(handle, path, NULL, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_update_thumbnail_path(db_handle, storage_id, path, NULL, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+ }
/* Get notification info */
media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, &noti_item);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_noti_info(handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+ }
media_type = noti_item->media_type;
if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
/*Do nothing.*/
} else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
- ret = _media_svc_extract_image_metadata(&content_info, media_type);
- if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_noti_item(noti_item);
- return ret;
- }
+ ret = _media_svc_extract_image_metadata(handle, &content_info, media_type, uid);
} else {
ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_noti_item(noti_item);
- return ret;
- }
+ }
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ _media_svc_destroy_noti_item(noti_item);
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
}
#if 1
/* Extracting thumbnail */
- if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- int width = 0;
- int height = 0;
-
- ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
- if (ret < 0) {
- media_svc_error("thumbnail_request_from_db failed: %d", ret);
- } else {
- media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
- if (ret < 0) {
- media_svc_error("__media_svc_malloc_and_strncpy failed : %d", ret);
+ if (content_info.thumbnail_path == NULL) {
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
+ if(ret == MS_MEDIA_ERR_NONE) {
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
}
- }
if (content_info.media_meta.width <= 0)
content_info.media_meta.width = width;
if (content_info.media_meta.height <= 0)
content_info.media_meta.height = height;
- }
+ }
+ }
+
#endif
- ret = _media_svc_update_item_with_data(db_handle, &content_info, uid);
+
+ ret = _media_svc_update_item_with_data(db_handle, storage_id, &content_info, uid);
if (ret == MS_MEDIA_ERR_NONE) {
media_svc_debug("Update is successful. Sending noti for this");
@@ -959,11 +972,6 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
- /* Get notification info */
- media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(handle, src_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
ret = _media_svc_sql_begin_trans(handle,uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
@@ -977,7 +985,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash);
- //ret = _media_svc_sql_query(handle, update_folder_path_sql);
+ //ret = _media_svc_sql_query(handle, update_folder_path_sql, uid);
ret = media_db_request_update_db_batch(update_folder_path_sql, uid);
sqlite3_free(update_folder_path_sql);
@@ -996,7 +1004,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d where path like '%q';", date, dst_path);
ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid);
- //ret = _media_svc_sql_query(handle, update_folder_modified_time_sql);
+ //ret = _media_svc_sql_query(handle, update_folder_modified_time_sql, uid);
sqlite3_free(update_folder_modified_time_sql);
if (ret != SQLITE_OK) {
@@ -1017,13 +1025,11 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
media_svc_debug("[SQL query] : %s", select_all_sql);
- ret = sqlite3_prepare_v2(handle, select_all_sql, -1, &sql_stmt, NULL);
- sqlite3_free((char *)select_all_sql);
-
+ ret = _media_svc_sql_prepare_to_step(db_handle, select_all_sql, &sql_stmt);
if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle));
- _media_svc_sql_rollback_trans(handle, uid);
- return MS_MEDIA_ERR_DB_INTERNAL;
+ media_svc_error("error when media_svc_rename_folder. err = [%d]", ret);
+ _media_svc_sql_rollback_trans(db_handle, uid);
+ return ret;
}
while (1) {
@@ -1037,7 +1043,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
- int media_type;
+ //int media_type;
bool no_thumb = FALSE;
if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
@@ -1064,7 +1070,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
no_thumb = TRUE;
}
- media_type = sqlite3_column_int(sql_stmt, 3);
+ //media_type = sqlite3_column_int(sql_stmt, 3);
/* Update path, thumbnail path of this item */
char *replaced_path = NULL;
@@ -1084,7 +1090,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
if (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
strncpy(media_new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(media_new_thumb_path));
} else {
- ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type);
+ ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret);
SAFE_FREE(replaced_path);
@@ -1110,15 +1116,19 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
if (no_thumb) {
update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q' WHERE media_uuid='%q'", replaced_path, media_uuid);
} else {
+#if 0
if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
} else {
update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_thumb_path, media_uuid);
}
+#else
+ update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
+#endif
}
ret = media_db_request_update_db_batch(update_item_sql,uid);
- //ret = _media_svc_sql_query(handle, update_item_sql);
+ //ret = _media_svc_sql_query(handle, update_item_sql,uid);
sqlite3_free(update_item_sql);
SAFE_FREE(replaced_path);
@@ -1131,8 +1141,9 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
}
/* Rename thumbnail file of file system */
- if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)
- && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+// if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)
+// && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ if ((!no_thumb) && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_rename_file failed : %d", ret);
@@ -1150,6 +1161,11 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
}
media_svc_debug("Folder update is successful. Sending noti for this");
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(db_handle, storage_id, dst_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
_media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
_media_svc_destroy_noti_item(noti_item);
@@ -1158,13 +1174,9 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
int media_svc_request_update_db(const char *db_query, uid_t uid)
{
- int ret = MS_MEDIA_ERR_NONE;
-
media_svc_retvm_if(!STRING_VALID(db_query), MS_MEDIA_ERR_INVALID_PARAMETER, "db_query is NULL");
- ret = _media_svc_request_update_db(db_query, uid);
-
- return ret;
+ return _media_svc_sql_query(NULL, db_query, uid);
}
int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path)
@@ -1172,11 +1184,12 @@ int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path)
int ret = MS_MEDIA_ERR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
/* Get notification info */
media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(db_handle, dir_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
+ ret = _media_svc_get_noti_info(db_handle, DEFAULT_MEDIA_SVC_STORAGE_ID, dir_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
ret = _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL);
@@ -1198,6 +1211,163 @@ int media_svc_count_invalid_items_in_folder(MediaSvcHandle *handle, const char *
return _media_svc_count_invalid_folder_items(db_handle, folder_path, count);
}
+int media_svc_check_db_upgrade(MediaSvcHandle *handle, uid_t uid)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ return _media_svc_check_db_upgrade(db_handle, uid);
+}
+
+int media_svc_check_db_corrupt(MediaSvcHandle *handle)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ return _media_db_check_corrupt(db_handle);
+}
+
+int media_svc_get_folder_list(MediaSvcHandle *handle, char* start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
+
+ return _media_svc_get_all_folders(db_handle, start_path, folder_list, modified_time_list, item_num_list, count);
+}
+
+int media_svc_update_folder_time(MediaSvcHandle *handle, const char *folder_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ time_t sto_time = 0;
+ int cur_time = _media_svc_get_file_time(folder_path);
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ ret = _media_svc_get_folder_info_by_foldername(db_handle, folder_path, folder_uuid, &sto_time);
+ if (ret == MS_MEDIA_ERR_NONE) {
+ if (sto_time != cur_time) {
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(db_handle, folder_uuid, folder_path, FALSE, uid);
+ }
+ }
+
+ return ret;
+}
+
+int media_svc_update_item_begin(MediaSvcHandle *handle, int data_cnt)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug("Transaction data count : [%d]", data_cnt);
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+
+ g_media_svc_update_item_data_cnt = data_cnt;
+ g_media_svc_update_item_cur_data_cnt = 0;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_svc_update_item_end(MediaSvcHandle *handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ if (g_media_svc_update_item_cur_data_cnt > 0) {
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+ }
+
+ g_media_svc_update_item_data_cnt = 1;
+ g_media_svc_update_item_cur_data_cnt = 0;
+
+ return ret;
+}
+
+
+int media_svc_update_item_meta(MediaSvcHandle *handle, const char *file_path, int storage_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ media_svc_media_type_e media_type;
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(file_path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ 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, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, file_path, &media_type, FALSE);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ return ret;
+ }
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
+ ret = _media_svc_extract_music_metadata_for_update(db_handle, &content_info, media_type);
+ } else{
+ return MS_MEDIA_ERR_NONE;
+ }
+ if (ret != MS_MEDIA_ERR_NONE) {
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+ }
+
+ if (g_media_svc_update_item_data_cnt == 1) {
+
+ ret = _media_svc_update_meta_with_data(db_handle, &content_info);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ } else if(g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
+
+ ret = _media_svc_update_meta_with_data(db_handle, &content_info);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ g_media_svc_update_item_cur_data_cnt ++;
+
+ } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
+
+ ret = _media_svc_update_meta_with_data(db_handle, &content_info);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ g_media_svc_update_item_cur_data_cnt = 0;
+
+ } else {
+ media_svc_error("Error in media_svc_update_item_meta");
+ _media_svc_destroy_content_info(&content_info);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ _media_svc_destroy_content_info(&content_info);
+
+ return ret;
+}
+
int media_svc_publish_noti(MediaSvcHandle *handle, media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
{
return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
@@ -1217,8 +1387,383 @@ int media_svc_check_pinyin_support(bool *support)
return MS_MEDIA_ERR_NONE;
}
+static int __media_svc_copy_para_to_content(media_svc_content_info_s *content_info ,media_svc_content_info_s *new_content_info)
+{
+ media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(new_content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ /*
+ initialize media content datas
+ */
+ int ret = MS_MEDIA_ERR_NONE;
+ char * media_uuid = NULL;
+ char * file_name = NULL;
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->path, content_info->path);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->storage_uuid, content_info->storage_uuid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ /* Set default GPS value before extracting meta information */
+ new_content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ new_content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ new_content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+
+ /* Set default value before extracting meta information */
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+// ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
+// media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ new_content_info->storage_type = content_info->storage_type;
+ time(&new_content_info->added_time);
+
+ media_uuid = _media_info_generate_uuid();
+ media_svc_retvm_if(media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Invalid UUID");
+
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_uuid, media_uuid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ file_name = g_path_get_basename(content_info->path);
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->file_name, file_name);
+ SAFE_FREE(file_name);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, new_content_info);
+
+ new_content_info->played_count = 0;
+ new_content_info->last_played_time= 0;
+ new_content_info->last_played_position= 0;
+ new_content_info->favourate= 0;
+ new_content_info->media_meta.rating = 0;
+ /*
+ end of initializing
+ */
+
+ new_content_info->size = content_info->size;
+ new_content_info->added_time = content_info->added_time;
+ new_content_info->modified_time = content_info->modified_time;
+ new_content_info->is_drm = content_info->is_drm;
+ new_content_info->media_type = content_info->media_type;
+
+ if(STRING_VALID(content_info->mime_type))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->mime_type, content_info->mime_type);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy mime_type failed");
+ }
+
+ if(STRING_VALID(content_info->thumbnail_path))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->thumbnail_path, content_info->thumbnail_path);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy thumbnail_path failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.title))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.title, content_info->media_meta.title);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy title failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.album))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album, content_info->media_meta.album);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy album failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.artist))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.artist, content_info->media_meta.artist);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy artist failed");
+ }
+
+/*
+ if(STRING_VALID(content_info->media_meta.album_artist))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album_artist, content_info->media_meta.album_artist);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy album_artist failed");
+ }
+*/
+
+ if(STRING_VALID(content_info->media_meta.genre))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.genre, content_info->media_meta.genre);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy genre failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.composer))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.composer, content_info->media_meta.composer);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy composer failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.year))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.year, content_info->media_meta.year);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy year failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.recorded_date))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.recorded_date, content_info->media_meta.recorded_date);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy recorded_date failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.copyright))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.copyright, content_info->media_meta.copyright);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy copyright failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.track_num))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.track_num, content_info->media_meta.track_num);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy track_num failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.description))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.description, content_info->media_meta.description);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy description failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.weather))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.weather, content_info->media_meta.weather);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy description failed");
+ }
+
+ if(STRING_VALID(content_info->media_meta.datetaken))
+ {
+ ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.datetaken, content_info->media_meta.datetaken);
+ if(ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("strcpy datetaken failed");
+
+ new_content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
+ if (new_content_info->timeline == 0) {
+ media_svc_error("Failed to get timeline : %s", new_content_info->media_meta.datetaken);
+ new_content_info->timeline = new_content_info->modified_time;
+ } else {
+ media_svc_debug("Timeline : %ld", new_content_info->timeline);
+ }
+ }
+
+ new_content_info->media_meta.bitrate = content_info->media_meta.bitrate;
+ new_content_info->media_meta.samplerate = content_info->media_meta.samplerate;
+ new_content_info->media_meta.channel = content_info->media_meta.channel;
+ new_content_info->media_meta.duration = content_info->media_meta.duration;
+ new_content_info->media_meta.longitude = content_info->media_meta.longitude;
+ new_content_info->media_meta.latitude = content_info->media_meta.latitude;
+ new_content_info->media_meta.altitude = content_info->media_meta.altitude;
+ new_content_info->media_meta.width = content_info->media_meta.width;
+ new_content_info->media_meta.height = content_info->media_meta.height;
+ new_content_info->media_meta.orientation = content_info->media_meta.orientation;
+ new_content_info->media_meta.rating = content_info->media_meta.rating;
+
+ return 0;
+}
+
+int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+ bool append_album = FALSE;
+
+ /* Checking parameters if they are valid */
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
+ media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "file_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(content_info->mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
+
+ if ((content_info->media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (content_info->media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
+ media_svc_error("invalid media_type condition[%d]", content_info->media_type);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ if (content_info->size <= 0)
+ {
+ media_svc_error("invalid size condition[%d]", content_info->size);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ if (content_info->modified_time <= 0)
+ {
+ media_svc_error("invalid modified_time condition[%d]", content_info->modified_time);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ media_svc_debug("storage[%d], path[%s], media_type[%d]", content_info->storage_type, content_info->path, content_info->media_type);
+
+ media_svc_content_info_s _new_content_info;
+ memset(&_new_content_info, 0, sizeof(media_svc_content_info_s));
+
+ /* set othere data to the structure, which is passed as parameters */
+ __media_svc_copy_para_to_content(content_info , &_new_content_info);
+
+ /* Set or Get folder id */
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, _new_content_info.storage_uuid, _new_content_info.path, _new_content_info.storage_type, folder_uuid, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ ret = __media_svc_malloc_and_strncpy(&_new_content_info.folder_uuid, folder_uuid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &_new_content_info);
+
+ /* register album table data */
+
+ int album_id = 0;
+ if(_new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SOUND || _new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)
+ {
+ ret = _media_svc_get_album_id(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, &album_id);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ media_svc_debug("album does not exist. So start to make album art");
+ append_album = TRUE;
+ } else {
+ media_svc_debug("other error");
+ append_album = FALSE;
+ }
+ } else {
+ _new_content_info.album_id = album_id;
+ append_album = FALSE;
+
+ if((!strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
+ (!strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
+
+ media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
+ } else {
+
+ media_svc_debug("album already exists. don't need to make album art");
+ ret = _media_svc_get_album_art_by_album_id(handle, album_id, &_new_content_info.thumbnail_path);
+ media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, &_new_content_info);
+ }
+ }
+ }
+
+ if(append_album == TRUE) {
+
+ if((strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
+ (strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
+ ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, _new_content_info.thumbnail_path, &album_id, uid);
+ else
+ ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, NULL, &album_id, uid);
+
+ _new_content_info.album_id = album_id;
+ }
+
+ /* Insert to db - calling _media_svc_insert_item_with_data */
+ ret = _media_svc_insert_item_with_data(db_handle, &_new_content_info, FALSE, FALSE, uid);
+
+ if (ret == MS_MEDIA_ERR_NONE) {
+ media_svc_debug("Insertion is successful.");
+ }
+
+ if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
+ media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
+ }
+
+ _media_svc_destroy_content_info(&_new_content_info);
+
+ /* handling returned value - important */
+ return ret;
+}
+
+void media_svc_destroy_content_info(media_svc_content_info_s *content_info)
+{
+ _media_svc_destroy_content_info(content_info);
+}
char *media_info_generate_uuid(void)
{
return _media_info_generate_uuid();
}
+
+int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_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");
+
+ ret = _media_svc_append_storage(db_handle, storage_id, storage_name, storage_path, storage_account, storage_type, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
+
+ ret = _media_svc_create_media_table_with_id(db_handle, storage_id, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
+
+ if(storage_type == MEDIA_SVC_STORAGE_CLOUD)
+ {
+ 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);
+ }
+
+ return ret;
+}
+
+int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_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");
+
+ ret = _media_svc_delete_storage(db_handle, storage_id, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "remove storage failed : %d", ret);
+
+ ret = _media_svc_drop_media_table(db_handle, storage_id, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop 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);
+
+ return ret;
+}
+
+int media_svc_request_extract_all_thumbs(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_request_extract_all_thumbs(uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_request_extract_all_thumbs failed : %d", ret);
+
+ return ret;
+}
diff --git a/src/include/common/media-svc-db-utils.h b/src/include/common/media-svc-db-utils.h
index e5685b6..125242f 100755
--- a/src/include/common/media-svc-db-utils.h
+++ b/src/include/common/media-svc-db-utils.h
@@ -28,23 +28,25 @@
#define SQLITE3_FINALIZE(x) if(x != NULL) {sqlite3_finalize(x);}
-int _media_svc_connect_db_with_handle(sqlite3 **db_handle);
-int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle);
-int _media_svc_create_media_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_folder_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_playlist_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_album_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_tag_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_bookmark_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_create_custom_table(sqlite3 *db_handle, uid_t uid);
-int _media_svc_request_update_db(const char *sql_str, uid_t uid);
+int _media_svc_make_table_query(sqlite3 *db_handle, const char *table_name, media_svc_table_slist_e list, uid_t uid);
+int _media_svc_upgrade_table_query(sqlite3 *db_handle, char *table_name, media_svc_table_slist_e list, uid_t uid);
+int _media_svc_init_table_query();
+void _media_svc_destroy_table_query();
+int _media_svc_create_media_table_with_id(sqlite3 *db_handle, const char *table_id, uid_t uid);
+int _media_svc_drop_media_table(sqlite3 *handle, const char *storage_id, uid_t uid);
+int _media_svc_update_media_view(sqlite3 *db_handle, uid_t uid);
int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str, uid_t uid);
int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt);
+int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt);
int _media_svc_sql_begin_trans(sqlite3 *handle, uid_t uid);
int _media_svc_sql_end_trans(sqlite3 *handle, uid_t uid);
int _media_svc_sql_rollback_trans(sqlite3 *handle, uid_t uid);
int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list, uid_t uid);
void _media_svc_sql_query_add(GList **query_list, char **query);
void _media_svc_sql_query_release(GList **query_list);
+int _media_svc_check_db_upgrade(sqlite3 *db_handle, uid_t uid);
+int _media_db_check_corrupt(sqlite3 *db_handle);
+char* _media_svc_get_path(uid_t uid);
+
#endif /*_MEDIA_SVC_DB_UTILS_H_*/
diff --git a/src/include/common/media-svc-env.h b/src/include/common/media-svc-env.h
index d9ae2f0..cc11674 100755
--- a/src/include/common/media-svc-env.h
+++ b/src/include/common/media-svc-env.h
@@ -43,15 +43,74 @@ extern "C" {
* DB table information
*/
-#define MEDIA_SVC_DB_TABLE_MEDIA "media" /**< media table*/
-#define MEDIA_SVC_DB_TABLE_FOLDER "folder" /**< media_folder table*/
-#define MEDIA_SVC_DB_TABLE_PLAYLIST "playlist" /**< playlist table*/
-#define MEDIA_SVC_DB_TABLE_PLAYLIST_MAP "playlist_map" /**< playlist_map table*/
-#define MEDIA_SVC_DB_TABLE_ALBUM "album" /**< album table*/
+/**
+ * Table Name
+ */
+#define MEDIA_SVC_DB_TABLE_MEDIA "media" /**< media table*/
+#define MEDIA_SVC_DB_TABLE_FOLDER "folder" /**< media_folder table*/
+#define MEDIA_SVC_DB_TABLE_PLAYLIST "playlist" /**< playlist table*/
+#define MEDIA_SVC_DB_TABLE_PLAYLIST_MAP "playlist_map" /**< playlist_map table*/
+#define MEDIA_SVC_DB_TABLE_ALBUM "album" /**< album table*/
#define MEDIA_SVC_DB_TABLE_TAG "tag" /**< tag table*/
#define MEDIA_SVC_DB_TABLE_TAG_MAP "tag_map" /**< tag_map table*/
#define MEDIA_SVC_DB_TABLE_BOOKMARK "bookmark" /**< bookmark table*/
#define MEDIA_SVC_DB_TABLE_CUSTOM "custom" /**< custom table*/
+#define MEDIA_SVC_DB_TABLE_STORAGE "storage" /**< storage table*/
+
+/**
+ * View Name
+ */
+#define MEDIA_SVC_DB_VIEW_MEDIA "media_view" /**< media_view*/
+#define MEDIA_SVC_DB_VIEW_PLAYLIST "playlist_view" /**< playlist_view*/
+#define MEDIA_SVC_DB_VIEW_TAG "tag_view" /**< tag_view*/
+
+/**
+ * Trigger Name
+ */
+#define MEDIA_SVC_DB_TRIGGER_FOLDER "folder_cleanup"
+#define MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP "playlist_map_cleanup" /**< media to map*/
+#define MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP1 "playlist_map_cleanup_1" /**< playlist to map*/
+#define MEDIA_SVC_DB_TRIGGER_ALBUM "album_cleanup"
+#define MEDIA_SVC_DB_TRIGGER_TAG_MAP "tag_map_cleanup" /**< media to map*/
+#define MEDIA_SVC_DB_TRIGGER_TAG_MAP1 "tag_map_cleanup_1" /**< tag to map*/
+#define MEDIA_SVC_DB_TRIGGER_BOOKMARK "bookmark_cleanup"
+#define MEDIA_SVC_DB_TRIGGER_STORAGE "storage_folder_cleanup"
+#define MEDIA_SVC_DB_TRIGGER_CUSTOM "custom_cleanup"
+
+/**
+ * Trigger Name
+ */
+#define MEDIA_SVC_DB_COLUMN_THUMBNAIL "thumbnail_path"
+#define MEDIA_SVC_DB_COLUMN_MAP_ID "_id"
+
+
+/**
+ * option
+ */
+#define MEDIA_SVC_DB_TYPE_TEXT "TEXT"
+#define MEDIA_SVC_DB_TYPE_INT "INTEGER"
+#define MEDIA_SVC_DB_TYPE_DOUBLE "DOUBLE"
+
+/**
+ * Query form
+ */
+#define MEDIA_SVC_DB_QUERY_TABLE_WITH_UNIQUE "CREATE TABLE IF NOT EXISTS '%s' (%s, unique(%s));"
+#define MEDIA_SVC_DB_QUERY_TABLE "CREATE TABLE IF NOT EXISTS '%s' (%s);"
+#define MEDIA_SVC_DB_QUERY_INDEX "CREATE INDEX IF NOT EXISTS %s on '%s' (%s);"
+#define MEDIA_SVC_DB_QUERY_TRIGGER "CREATE TRIGGER IF NOT EXISTS %s DELETE ON %s BEGIN DELETE FROM %s WHERE %s=old.%s;END;"
+#define MEDIA_SVC_DB_QUERY_TRIGGER_WITH_COUNT "CREATE TRIGGER IF NOT EXISTS %s DELETE ON %s BEGIN DELETE FROM %s WHERE (SELECT count(*) FROM %s WHERE %s=old.%s)=1 AND %s=old.%s;END;"
+#define MEDIA_SVC_DB_QUERY_VIEW_MEDIA "CREATE VIEW IF NOT EXISTS %s AS SELECT * from %s;"
+#define MEDIA_SVC_DB_QUERY_VIEW_PLAYLIST "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM playlist \
+ LEFT OUTER JOIN playlist_map ON playlist.playlist_id = playlist_map.playlist_id \
+ LEFT OUTER JOIN media ON (playlist_map.media_uuid = media.media_uuid AND media.validity=1) \
+ LEFT OUTER JOIN (SELECT count(playlist_id) as media_count, playlist_id FROM playlist_map group by playlist_id) as cnt_tbl ON (cnt_tbl.playlist_id=playlist_map.playlist_id AND media.validity=1);"
+#define MEDIA_SVC_DB_QUERY_VIEW_TAG "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM tag \
+ LEFT OUTER JOIN tag_map ON tag.tag_id=tag_map.tag_id \
+ LEFT OUTER JOIN media ON (tag_map.media_uuid = media.media_uuid AND media.validity=1) \
+ LEFT OUTER JOIN (SELECT count(tag_id) as media_count, tag_id FROM tag_map group by tag_id) as cnt_tbl ON (cnt_tbl.tag_id=tag_map.tag_id AND media.validity=1);"
+#define MEDIA_SVC_DB_QUERY_ALTER_TABLE "ALTER TABLE %s ADD COLUMN %s;"
+#define MEDIA_SVC_DB_QUERY_DROP_VIEW "DROP VIEW IF EXISTS %s;"
+
#define MEDIA_SVC_METADATA_LEN_MAX 128 /**< Length of metadata*/
@@ -69,9 +128,6 @@ extern "C" {
#define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
#define THUMB_EXT "jpg"
-#define MEDIA_SVC_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL
-#define MEDIA_SVC_PATH_MMC MEDIA_ROOT_PATH_SDCARD
-
enum Exif_Orientation {
NOT_AVAILABLE=0,
NORMAL =1,
@@ -88,8 +144,44 @@ typedef enum{
MEDIA_SVC_QUERY_INSERT_ITEM,
MEDIA_SVC_QUERY_SET_ITEM_VALIDITY,
MEDIA_SVC_QUERY_MOVE_ITEM,
+ MEDIA_SVC_QUERY_UPDATE_ITEM
} media_svc_query_type_e;
+typedef enum{
+ MEDIA_SVC_DB_LIST_MEDIA = 0,
+ MEDIA_SVC_DB_LIST_FOLDER = 1,
+ MEDIA_SVC_DB_LIST_PLAYLIST_MAP = 2,
+ MEDIA_SVC_DB_LIST_PLAYLIST = 3,
+ MEDIA_SVC_DB_LIST_ALBUM = 4,
+ MEDIA_SVC_DB_LIST_TAG_MAP = 5,
+ MEDIA_SVC_DB_LIST_TAG = 6,
+ MEDIA_SVC_DB_LIST_BOOKMARK = 7,
+ MEDIA_SVC_DB_LIST_STORAGE = 8,
+ MEDIA_SVC_DB_LIST_CUSTOM = 9,
+ MEDIA_SVC_DB_LIST_MAX = 10,
+} media_svc_table_slist_e;
+
+typedef struct table_inform {
+ char *triggerName;
+ char *viewName;
+ char *eventTable;
+ char *actionTable;
+}table_info;
+
+typedef struct column_inform {
+ char *name;
+ char *type;
+ bool hasOption;
+ char *option;
+ int version;
+ bool isIndex;
+ char *indexName;
+ bool isUnique;
+ bool isTrigger;
+ bool isView;
+}column_info;
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h
index 1a17e27..a0b8ea7 100755
--- a/src/include/common/media-svc-media-folder.h
+++ b/src/include/common/media-svc-media-folder.h
@@ -26,10 +26,13 @@
#include <stdbool.h>
#include "media-svc-types.h"
-int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id);
-int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type, const char *folder_id, const char *path_name, const char *folder_name, int modified_date, uid_t uid);
+int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id);
+int _media_svc_append_folder(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *folder_id, const char *path_name, const char *folder_name, int modified_date, const char *parent_folder_uuid, uid_t uid);
int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query, uid_t uid);
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid);
+int _media_svc_get_and_append_folder(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid);
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid);
int _media_svc_update_folder_table(sqlite3 *handle, uid_t uid);
+int _media_svc_get_all_folders(sqlite3 *handle, char* start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count);
+int _media_svc_get_folder_info_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id, time_t *modified_time);
#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/
diff --git a/src/include/common/media-svc-media.h b/src/include/common/media-svc-media.h
index b29c503..a7f2fe4 100755
--- a/src/include/common/media-svc-media.h
+++ b/src/include/common/media-svc-media.h
@@ -30,11 +30,11 @@
int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count);
int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid);
-int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid);
-int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
-int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type);
+int _media_svc_update_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, uid_t uid);
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path);
+int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type);
int _media_svc_get_burst_id(sqlite3 *handle, int *id);
-int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path, uid_t uid);
+int _media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, bool stack_query, uid_t uid);
int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid);
int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid);
int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path, uid_t uid);
@@ -44,11 +44,12 @@ int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char
int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query, uid_t uid);
int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid);
int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type, uid_t uid);
-int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length);
-int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path, uid_t uid);
-int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item);
+int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *storage_id, const char *path, const char *thumb_path, uid_t uid);
+int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item);
int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_path, int *count);
int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *thumb_path, int *count);
char* _media_svc_get_thumb_default_path(uid_t uid);
+int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *path, time_t *modified_time, unsigned long long *size);
+int _media_svc_update_meta_with_data(sqlite3 *handle, media_svc_content_info_s *content_info);
#endif /*_MEDIA_SVC_MEDIA_H_*/
diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h
index 9e2261c..b272f1e 100755
--- a/src/include/common/media-svc-util.h
+++ b/src/include/common/media-svc-util.h
@@ -46,103 +46,30 @@ extern "C" {
((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
char *_media_info_generate_uuid(void);
-char *_media_svc_escape_str(char *input, int len);
void _strncpy_safe(char *x_dst, const char *x_src, int max_len);
-unsigned int _media_svc_get_current_time(void);
int _media_svc_rename_file( const char *old_name, const char *new_name);
-bool _media_svc_remove_file(const char *path);
+int _media_svc_remove_file(const char *path);
int _media_svc_remove_all_files_in_dir(const char *dir_path);
-char *_media_svc_get_title_from_filepath (const char *path);
-int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid);
-bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
-bool _media_svc_get_file_ext(const char *file_path, char *file_ext);
+int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_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_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
const char *path, media_svc_media_type_e *media_type, bool refresh);
-int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
+int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid);
int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid);
int __media_svc_malloc_and_strncpy(char **dst, const char *src);
+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_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type);
+int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid);
char *_media_svc_replace_path(char *s, const char *olds, const char *news);
char* _media_svc_get_thumb_internal_path(uid_t uid);
char* _media_svc_get_thumb_external_path(uid_t uid);
-int _media_svc_error_convert(int error);
-
-/* Define data structures for media type and mime type */
-#define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
-#define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
-#define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
-#define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
-#define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
-#define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
-
-#define CONTENT_TYPE_NUM 4
-#define MUSIC_MIME_NUM 29
-#define SOUND_MIME_NUM 1
-#define MIME_TYPE_LENGTH 255
-#define MIME_LENGTH 50
-#define _3GP_FILE ".3gp"
-#define _MP4_FILE ".mp4"
-
-typedef struct {
- char content_type[15];
- int category_by_mime;
-} _media_svc_content_table_s;
-
-static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
- {"audio", MEDIA_SVC_CATEGORY_SOUND},
- {"image", MEDIA_SVC_CATEGORY_IMAGE},
- {"video", MEDIA_SVC_CATEGORY_VIDEO},
- {"application", MEDIA_SVC_CATEGORY_ETC},
-};
-
-static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
- /*known mime types of normal files*/
- "mpeg",
- "ogg",
- "x-ms-wma",
- "x-flac",
- "mp4",
- /* known mime types of drm files*/
- "mp3",
- "x-mp3", /*alias of audio/mpeg*/
- "x-mpeg", /*alias of audio/mpeg*/
- "3gpp",
- "x-ogg", /*alias of audio/ogg*/
- "vnd.ms-playready.media.pya:*.pya", /*playready*/
- "wma",
- "aac",
- "x-m4a", /*alias of audio/mp4*/
- /* below mimes are rare*/
- "x-vorbis+ogg",
- "x-flac+ogg",
- "x-matroska",
- "ac3",
- "mp2",
- "x-ape",
- "x-ms-asx",
- "vnd.rn-realaudio",
-
- "x-vorbis", /*alias of audio/x-vorbis+ogg*/
- "vorbis", /*alias of audio/x-vorbis+ogg*/
- "x-oggflac",
- "x-mp2", /*alias of audio/mp2*/
- "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
- "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
- "x-wav",
-};
-
-static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
- "x-smaf",
-};
-
bool _media_svc_is_drm_file(const char *path);
-int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category);
+int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, 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_get_mime_type(const char *path, char *mimetype);
-int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
+int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
+int _media_svc_request_extract_all_thumbs(uid_t uid);
+
#ifdef __cplusplus
}
diff --git a/test/media-service-test.c b/test/media-service-test.c
index 93eae99..a0a5ea3 100644
--- a/test/media-service-test.c
+++ b/test/media-service-test.c
@@ -88,7 +88,7 @@ gboolean _send_noti_batch_operations(gpointer data)
media_svc_storage_type_e storage_type;
- ret = media_svc_get_storage_type(path, &storage_type);
+ ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
SAFE_FREE(user_str);
@@ -132,7 +132,7 @@ gboolean _send_noti_operations(gpointer data)
char *path = tzplatform_mkpath(TZ_USER_CONTENT,"test/image1.jpg");
media_svc_storage_type_e storage_type;
- ret = media_svc_get_storage_type(path, &storage_type);
+ ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
SAFE_FREE(user_str);
diff --git a/test/plugin/media_svc_plugin_test.c b/test/plugin/media_svc_plugin_test.c
index 5cba9bc..31797fa 100755
--- a/test/plugin/media_svc_plugin_test.c
+++ b/test/plugin/media_svc_plugin_test.c
@@ -33,10 +33,9 @@ void *funcHandle = NULL;
static void msg_print(int line, char *msg);
-int (*svc_check_item) (const char *file_path, const char * mime_type, char ** err_msg);
int (*svc_connect) (void ** handle, char ** err_msg);
int (*svc_disconnect) (void * handle, char ** err_msg);
-int (*svc_check_item_exist) (void* handle, const char *file_path, int storage_type, char ** err_msg);
+int (*svc_check_item_exist) (void* handle, const char *file_path, bool *modified, char ** err_msg);
int (*svc_insert_item_immediately) (void* handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg);
int (*svc_set_folder_item_validity) (void * handle, const char * folder_path, int validity, int recursive, char ** err_msg);
int (*svc_delete_all_invalid_items_in_folder) (void * handle, const char *folder_path, char ** err_msg);
@@ -50,16 +49,14 @@ int __load_functions()
fprintf (stderr,"error: %s\n", dlerror());
}
- svc_check_item = dlsym (funcHandle, "check_item");
- svc_connect = dlsym (funcHandle, "connect_db");
- svc_disconnect = dlsym (funcHandle, "disconnect_db");
+ svc_connect = dlsym (funcHandle, "connect");
+ svc_disconnect = dlsym (funcHandle, "disconnect");
svc_check_item_exist = dlsym (funcHandle, "check_item_exist");
svc_insert_item_immediately = dlsym (funcHandle, "insert_item_immediately");
svc_set_folder_item_validity = dlsym (funcHandle, "set_folder_item_validity");
svc_delete_all_invalid_items_in_folder = dlsym (funcHandle, "delete_all_invalid_items_in_folder");
- if ( !svc_check_item ||
- !svc_connect ||
+ if ( !svc_connect ||
!svc_disconnect ||
!svc_insert_item_immediately ||
!svc_set_folder_item_validity ||
@@ -100,21 +97,6 @@ int main()
msg_print(__LINE__, "__load_functions success");
}
- //check_item ================================================
- ret = svc_check_item(tzplatform_mkpath(TZ_USER_CONTENT,"Music/Over the horizon.mp3"), "audio/mpeg", &err_msg);
- if(ret < 0) {
- msg_print(__LINE__, "svc_check_item error");
- if(err_msg != NULL) {
- printf("err_msg[%s]\n", err_msg);
- free(err_msg);
- err_msg = NULL;
- }
- __unload_functions();
- return -1;
- } else {
- msg_print(__LINE__, "svc_check_item success");
- }
-
//db open ==================================================
ret = svc_connect(&db_handle, &err_msg);
if(ret < 0) {
@@ -144,9 +126,9 @@ int main()
printf("Enter path and mimetype ( ex. %s image ) : ", tzplatform_mkpath(TZ_USER_CONTENT, "a.jpg"));
scanf("%s %s", path, type);
-
+ bool modified = false;
//check_item_exist ============================================
- ret = svc_check_item_exist(db_handle, path, 0, &err_msg);
+ ret = svc_check_item_exist(db_handle, path, &modified, &err_msg);
if(ret < 0) {
msg_print(__LINE__, "svc_check_item_exist error");
if(err_msg != NULL) {
@@ -157,7 +139,10 @@ int main()
//__unload_functions();
//return -1;
} else {
- msg_print(__LINE__, "svc_check_item_exist success");
+ if(modified)
+ msg_print(__LINE__, "svc_check_item_exist success. Modified");
+ else
+ msg_print(__LINE__, "svc_check_item_exist success. Not modified");
}
// svc_check_item_exist ============================================