diff options
author | Haejeong Kim <backto.kim@samsung.com> | 2012-08-31 13:34:36 +0900 |
---|---|---|
committer | Haejeong Kim <backto.kim@samsung.com> | 2012-08-31 13:34:36 +0900 |
commit | 91757ec657c7d815d2b2fe25cc34e96fb8cc0cb7 (patch) | |
tree | 6dd4472c8d588ad369d954d972c691e4ae5fee62 | |
parent | 2b7dd9e0874a86f5ac4cff404c03d3ed3808967d (diff) | |
download | media-content-91757ec657c7d815d2b2fe25cc34e96fb8cc0cb7.tar.gz media-content-91757ec657c7d815d2b2fe25cc34e96fb8cc0cb7.tar.bz2 media-content-91757ec657c7d815d2b2fe25cc34e96fb8cc0cb7.zip |
update latest code
-rwxr-xr-x | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | include/media_bookmark.h | 6 | ||||
-rwxr-xr-x | include/media_content_type.h | 25 | ||||
-rwxr-xr-x | include/media_info.h | 28 | ||||
-rwxr-xr-x | include/media_info_private.h | 60 | ||||
-rwxr-xr-x | include/media_util_private.h | 4 | ||||
-rwxr-xr-x | packaging/capi-content-media-content.spec | 3 | ||||
-rwxr-xr-x | src/media_bookmark.c | 24 | ||||
-rwxr-xr-x | src/media_content.c | 30 | ||||
-rwxr-xr-x | src/media_db.c | 255 | ||||
-rwxr-xr-x | src/media_filter.c | 26 | ||||
-rwxr-xr-x | src/media_folder.c | 84 | ||||
-rwxr-xr-x | src/media_info.c | 319 | ||||
-rwxr-xr-x | src/media_util_private.c | 23 | ||||
-rwxr-xr-x | test/media-content_test.c | 111 |
15 files changed, 377 insertions, 623 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b9373bf..6632a6a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog libmedia-service libmedia-utils capi-base-common") +SET(dependents "dlog libmedia-service media-thumbnail libmedia-utils capi-base-common") SET(pc_dependents "dlog capi-base-common") INCLUDE(FindPkgConfig) diff --git a/include/media_bookmark.h b/include/media_bookmark.h index 5697a58..ce974c2 100755 --- a/include/media_bookmark.h +++ b/include/media_bookmark.h @@ -136,16 +136,16 @@ int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t *marked_tim /** * @brief Gets the media bookmark's thumbnail. * - * @remarks thumbnail must be released with free() by you. + * @remarks @a path must be released with free() by you. * * @param [in] bookmark The handle to media bookmark - * @param [out] thumbnail_path The thumbnail path of media bookmark + * @param [out] path The thumbnail path of media bookmark * @return 0 on success, otherwise a negative error value. * @retval #MEDIA_CONTENT_ERROR_NONE Successful * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory */ -int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **thumbnail_path); +int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path); /** diff --git a/include/media_content_type.h b/include/media_content_type.h index 852b13e..715c385 100755 --- a/include/media_content_type.h +++ b/include/media_content_type.h @@ -102,11 +102,14 @@ typedef enum */ typedef enum { - MEDIA_CONTENT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - MEDIA_CONTENT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - MEDIA_CONTENT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + MEDIA_CONTENT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + MEDIA_CONTENT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + MEDIA_CONTENT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ MEDIA_CONTENT_ERROR_DB_FAILED = TIZEN_ERROR_CONTENT_CLASS | 0x01, /**< DB operation failed */ MEDIA_CONTENT_ERROR_DB_BUSY = TIZEN_ERROR_CONTENT_CLASS | 0x02, /**< DB operation BUSY */ + MEDIA_CONTENT_ERROR_NETWORK = TIZEN_ERROR_CONTENT_CLASS | 0x03, /**< Network Fail */ + MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT = TIZEN_ERROR_CONTENT_CLASS | 0x04, /**< Unsupported Content */ + MEDIA_CONTENT_ERROR_INVALID_OPERATION = TIZEN_ERROR_CONTENT_CLASS | 0x05, /**< Invalid Operation */ } media_content_error_e; /** @@ -235,6 +238,22 @@ typedef struct filter_s *filter_h; */ typedef bool (*media_info_cb)(media_info_h media, void *user_data); + +/** + * @ingroup CAPI_CONTENT_MEDIA_INFO_MODULE + * @brief Creates a thumbnail image. + * + * @details This callback is called for completion of generating the thumbnail image.\n + * + * @param[in] error The Error code + * @param[in] path The Path of thumbnail which is generated + * @param[in] user_data The user data passed from the foreach function + * @pre media_info_create_thumbnail() + * @see media_info_create_thumbnail() + */ +typedef void (*media_thumbnail_completed_cb)(media_content_error_e error, const char *path, void *user_data); + + /** * @ingroup CAPI_CONTENT_MEDIA_FOLDER_MODULE * @brief Iterates over a list of folders. diff --git a/include/media_info.h b/include/media_info.h index 7677352..0b35ae3 100755 --- a/include/media_info.h +++ b/include/media_info.h @@ -45,7 +45,7 @@ extern "C" { * @return 0 on success, otherwise a negative error value. * @retval #MEDIA_CONTENT_ERROR_NONE Successful * @pre This function requires opened connection to content service by media_content_connect(). - * @see #media_content_type_e media_content_connect() + * @see media_content_connect() */ int media_info_insert_to_db (const char *path, media_info_h *info); @@ -59,7 +59,7 @@ int media_info_insert_to_db (const char *path, media_info_h *info); * @return 0 on success, otherwise a negative error value. * @retval #MEDIA_CONTENT_ERROR_NONE Successful * @pre This function requires opened connection to content service by media_content_connect(). - * @see #media_content_type_e media_content_connect() + * @see media_content_connect() */ int media_info_delete_from_db(const char *media_id); @@ -721,7 +721,6 @@ int media_info_set_author(media_info_h media, const char *author); * @retval #MEDIA_CONTENT_ERROR_NONE Successful * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter - * */ int media_info_set_provider(media_info_h media, const char *provider); @@ -799,8 +798,8 @@ int media_info_set_keyword(media_info_h media, const char *keyword); /** * @brief Updates the media info to the media database. * - * @details The function updates the given media info in the media database. The function should be called after any change in media, to be updated to the media - * database. For example, after using media_info_set_display_name() for setting the name of the media, media_info_update_to_db() function should be called so as to update + * @details The function updates the given media info in the media database. The function should be called after any change in media, to be updated to the media + * database. For example, after using media_info_set_display_name() for setting the name of the media, media_info_update_to_db() function should be called so as to update * the given media info attibutes in the media database. * * @param[in] media The handle to media info @@ -867,8 +866,27 @@ int media_info_set_added_time(media_info_h media, time_t added_time); * @see media_content_connect() * */ +int media_info_move_to_db(media_info_h media, const char* dst_path); int media_info_move_media_to_db(media_info_h media, const char* dst_path); + +/** + * @brief Creates a thumbnail image for given the media, asynchronously. + * @details This function creates an thumbnail image for given media item and and calls registered callback function for completion of creating the thumbnail. + * If there already exist a thumbnail for given media, then the path of thumbnail will be return in callback function. + * + * @param[in] media The handle to media info + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data); + /** * @} */ diff --git a/include/media_info_private.h b/include/media_info_private.h index 526f7bf..d60f68c 100755 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -38,14 +38,12 @@ extern "C" { #define LOG_TAG "TIZEN_N_MEDIACONTENT" +#define SAFE_STRLCPY(dst, src, n) ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE) #define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n); #define SAFE_FREE(src) {if(src) {free(src); src = NULL;}} #define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) #define SQLITE3_FINALIZE(x) {if(x != NULL) {sqlite3_finalize(x);}} -#define MEDIA_CONTENT_TYPE 5 -#define MEDIA_REGISTER_TYPE 6 - #define MEDIA_CONTENT_PATH_PHONE "/opt/media" /**< File path prefix of files stored in phone */ #define MEDIA_CONTENT_PATH_MMC "/mnt/mmc" /**< File path prefix of files stored in mmc card */ @@ -57,6 +55,12 @@ extern "C" { #define MEDIA_CONTENT_UUID_SIZE 36 typedef enum { + MEDIA_CONTENT_TYPE = 0, + MEDIA_THUMBNAIL_TYPE, + MEDIA_REGISTER_TYPE +} media_info_error_type_e; + +typedef enum { Table_Media, Table_Folder, Table_Bookmark, @@ -80,10 +84,6 @@ typedef enum { typedef enum { MEDIA_GROUP_NONE, MEDIA_GROUP_ALBUM, - MEDIA_GROUP_ARTIST, - MEDIA_GROUP_GENRE, - MEDIA_GROUP_COMPOSER, - MEDIA_GROUP_YEAR, MEDIA_GROUP_FOLDER, MEDIA_GROUP_PLAYLIST, MEDIA_GROUP_TAG, @@ -123,7 +123,7 @@ typedef struct int bookmark_id; char *media_id; time_t marked_time; - char *thumbnail; + char *thumbnail_path; }media_bookmark_s; typedef struct @@ -201,7 +201,7 @@ typedef struct unsigned long long size; time_t added_time; time_t modified_time; - char *thumbnail; + char *thumbnail_path; char *description; double longitude; double latitude; @@ -263,6 +263,13 @@ typedef struct _attribute_map_s GHashTable *attr_map; }attribute_s; +typedef struct +{ + media_info_s *handle; + void *user_data; + media_thumbnail_completed_cb thumbnail_completed_cb; +}media_thumbnail_cb_s; + typedef struct attribute_s *attribute_h; /* DB Table */ @@ -426,12 +433,10 @@ typedef struct attribute_s *attribute_h; #define SELECT_MEDIA_COUNT_FROM_GROUP "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP //to apply limit condition. #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL //to apply limit condition. #define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'" -#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid IN \ - (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND media_uuid IN \ - (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" -//#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) " -//#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " +//#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid IN (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" +//#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND media_uuid IN (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" +#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) " +#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " /* Get Group Info by Group ID*/ #define SELECT_ALBUM_FROM_ALBUM "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d" @@ -522,11 +527,6 @@ int _content_error_capi(int type, int cotent_error); /** *@internal */ -int _content_get_storage_type(const char *full_path); - -/** - *@internal - */ int _content_query_sql(char *query_str); /** @@ -597,11 +597,6 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark /** *@internal */ -int _media_db_get_group(filter_h filter, media_group_cb callback, void *user_data, group_list_e group_type); - -/** - *@internal - */ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count); /** @@ -660,21 +655,6 @@ int _media_filter_attribute_create(attribute_h *attr); int _media_filter_attribute_add(attribute_h atrr, char *user_attr, char *platform_attr); /** - * @brief Remove the attributes from the handle. - * @details This function remove the attribute from handle. - * @param[in] filter The handle to media filter attribute - * @param[in] user_attr The user attribute - * @param[in] platform_attr The platform attribute - * @return 0 on success, otherwise a negative error value. - * @retval #MEDIA_CONTENT_ERROR_NONE Successful - * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory - * @see media_filter_attribute_remove() - * - */ -int _media_filter_attribute_remove(attribute_h atrr, char *user_attr); - -/** * @brief Destroys a media filter attribute handle. * @details The function frees all resources related to the media filter attribute handle. The filter attribute * handle no longer can be used to perform any operation. A new handle diff --git a/include/media_util_private.h b/include/media_util_private.h index f4acbbe..59dd538 100755 --- a/include/media_util_private.h +++ b/include/media_util_private.h @@ -29,10 +29,6 @@ extern "C" { */ int _media_util_get_store_type_by_path(const char *path, int *storage_type); -/** - *@internal - */ -int _media_util_get_file_dir_modified_time(const char *path); #ifdef __cplusplus } diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index c9fa611..7984e96 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in SLP C API -Version: 0.2.13 +Version: 0.2.14 Release: 1 Group: System/Libraries License: Apache-2.0 @@ -9,6 +9,7 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libmedia-service) +BuildRequires: pkgconfig(media-thumbnail) BuildRequires: pkgconfig(libmedia-utils) diff --git a/src/media_bookmark.c b/src/media_bookmark.c index fc64e67..04bb17a 100755 --- a/src/media_bookmark.c +++ b/src/media_bookmark.c @@ -68,6 +68,12 @@ int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_cou media_content_debug_func(); + if (bookmark_count == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count); return ret; @@ -98,7 +104,7 @@ int media_bookmark_destroy(media_bookmark_h bookmark) if(_bookmark) { SAFE_FREE(_bookmark->media_id); - SAFE_FREE(_bookmark->thumbnail); + SAFE_FREE(_bookmark->thumbnail_path); free(_bookmark); ret = MEDIA_CONTENT_ERROR_NONE; } @@ -140,10 +146,10 @@ int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src) _dst->marked_time = _src->marked_time; - if(STRING_VALID(_src->thumbnail)) + if(STRING_VALID(_src->thumbnail_path)) { - _dst->thumbnail = (char*)strdup(_src->thumbnail); - if(_dst->thumbnail == NULL) + _dst->thumbnail_path = (char*)strdup(_src->thumbnail_path); + if(_dst->thumbnail_path == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); media_bookmark_destroy((media_bookmark_h)_dst); @@ -234,17 +240,17 @@ int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_tim return ret; } -int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **thumbnail) +int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path) { int ret = MEDIA_CONTENT_ERROR_NONE; media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark; if(_bookmark) { - if(STRING_VALID(_bookmark->thumbnail)) + if(STRING_VALID(_bookmark->thumbnail_path)) { - *thumbnail = strdup(_bookmark->thumbnail); - if(*thumbnail == NULL) + *path = strdup(_bookmark->thumbnail_path); + if(*path == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; @@ -252,7 +258,7 @@ int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **thumbnai } else { - *thumbnail = NULL; + *path = NULL; } ret = MEDIA_CONTENT_ERROR_NONE; diff --git a/src/media_content.c b/src/media_content.c index 4935015..823b1bd 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -15,7 +15,7 @@ */ - +#include <media-thumb-error.h> #include <media_content.h> #include <media_info_private.h> #include <media-util-err.h> @@ -470,6 +470,8 @@ int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condit int _content_error_capi(int type, int content_error) { + media_content_debug("[type : %d] content_error : %d ", type, content_error); + if(type == MEDIA_CONTENT_TYPE) { if(content_error == MEDIA_INFO_ERROR_NONE) @@ -484,6 +486,29 @@ int _content_error_capi(int type, int content_error) return MEDIA_CONTENT_ERROR_DB_FAILED; else if(content_error == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) return MEDIA_CONTENT_ERROR_DB_FAILED; + + } else if(type == MEDIA_THUMBNAIL_TYPE) { + if(content_error == MEDIA_THUMB_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + else if(content_error == MEDIA_THUMB_ERROR_INVALID_PARAMETER) + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + else if(content_error == MEDIA_THUMB_ERROR_DB) + return MEDIA_CONTENT_ERROR_DB_FAILED; + else if(content_error == MEDIA_THUMB_ERROR_DB) + return MEDIA_CONTENT_ERROR_DB_FAILED; + else if(content_error == MEDIA_THUMB_ERROR_NETWORK) + return MEDIA_CONTENT_ERROR_NETWORK; + else if(content_error == MEDIA_THUMB_ERROR_TIMEOUT) + return MEDIA_CONTENT_ERROR_NETWORK; + else if(content_error == MEDIA_THUMB_ERROR_MM_UTIL) /* Error in mm-util lib */ + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + else if(content_error == MEDIA_THUMB_ERROR_HASHCODE) /* Failed to generate hash code */ + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + else if(content_error == MEDIA_THUMB_ERROR_TOO_BIG) /* Original is too big to make thumb */ + return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT; + else if(content_error == MEDIA_THUMB_ERROR_UNSUPPORTED) /* Unsupported type */ + return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT; + } else if(type == MEDIA_REGISTER_TYPE) { if(content_error == MS_MEDIA_ERR_NONE) return MEDIA_CONTENT_ERROR_NONE; @@ -493,8 +518,7 @@ int _content_error_capi(int type, int content_error) return MEDIA_CONTENT_ERROR_DB_FAILED; } - media_content_error("content_error : %d [ type :%d ]", content_error, type); - return MEDIA_CONTENT_ERROR_DB_FAILED; + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; } int _content_query_sql(char *query_str) diff --git a/src/media_db.c b/src/media_db.c index a89667a..6a60c56 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -25,57 +25,57 @@ static char * __media_db_get_group_name(media_group_e group) switch(group) { case MEDIA_CONTENT_GROUP_DISPLAY_NAME: - return "file_name"; + return DB_FIELD_MEDIA_DISPLAY_NAME; case MEDIA_CONTENT_GROUP_TYPE: - return "media_type"; + return DB_FIELD_MEDIA_TYPE; case MEDIA_CONTENT_GROUP_MIME_TYPE: - return "mime_type"; + return DB_FIELD_MEDIA_MIME_TYPE; case MEDIA_CONTENT_GROUP_SIZE: - return "size"; + return DB_FIELD_MEDIA_SIZE; case MEDIA_CONTENT_GROUP_ADDED_TIME: - return "added_time"; + return DB_FIELD_MEDIA_ADDED_TIME; case MEDIA_CONTENT_GROUP_MODIFIED_TIME: - return "modified_time"; + return DB_FIELD_MEDIA_MODIFIED_TIME; case MEDIA_CONTENT_GROUP_TITLE: - return "title"; + return DB_FIELD_MEDIA_TITLE; case MEDIA_CONTENT_GROUP_ARTIST: - return "artist"; + return DB_FIELD_MEDIA_ARTIST; case MEDIA_CONTENT_GROUP_GENRE: - return "genre"; + return DB_FIELD_MEDIA_GENRE; case MEDIA_CONTENT_GROUP_COMPOSER: - return "composer"; + return DB_FIELD_MEDIA_COMPOSER; case MEDIA_CONTENT_GROUP_YEAR: - return "year"; + return DB_FIELD_MEDIA_YEAR; case MEDIA_CONTENT_GROUP_RECORDED_DATE: - return "recorded_date"; + return DB_FIELD_MEDIA_RECORDED_DATE; case MEDIA_CONTENT_GROUP_COPYRIGHT: - return "copyright"; + return DB_FIELD_MEDIA_COPYRIGHT; case MEDIA_CONTENT_GROUP_TRACK_NUM: - return "track_num"; + return DB_FIELD_MEDIA_TRACK_NUM; case MEDIA_CONTENT_GROUP_DESCRIPTION: - return "description"; + return DB_FIELD_MEDIA_DESCRIPTION; case MEDIA_CONTENT_GROUP_LONGITUDE: - return "longitude"; + return DB_FIELD_MEDIA_LONGITUDE; case MEDIA_CONTENT_GROUP_LATIITUDE: - return "latitude"; + return DB_FIELD_MEDIA_LATITUDE; case MEDIA_CONTENT_GROUP_ALTITUDE: - return "altitude"; + return DB_FIELD_MEDIA_ALTITUDE; case MEDIA_CONTENT_GROUP_RATING: - return "rating"; + return DB_FIELD_MEDIA_RATING; case MEDIA_CONTENT_GROUP_AUTHOR: - return "author"; + return DB_FIELD_MEDIA_AUTHOR; case MEDIA_CONTENT_GROUP_PROVIDER: - return "provider"; + return DB_FIELD_MEDIA_PROVIDER; case MEDIA_CONTENT_GROUP_CONTENT_NAME: - return "content_name"; + return DB_FIELD_MEDIA_CONTENT_NAME; case MEDIA_CONTENT_GROUP_CATEGORY: - return "category"; + return DB_FIELD_MEDIA_CATEGORY; case MEDIA_CONTENT_GROUP_LOCATION_TAG: - return "location_tag"; + return DB_FIELD_MEDIA_LOCATION_TAG; case MEDIA_CONTENT_GROUP_AGE_RATING: - return "age_rating"; + return DB_FIELD_MEDIA_AGE_RATING; case MEDIA_CONTENT_GROUP_KEYWORD: - return "keyword"; + return DB_FIELD_MEDIA_KEYWORD; default: return NULL; } @@ -110,35 +110,49 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro break; case MEDIA_GROUP_ALBUM: attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT); - break; - case MEDIA_GROUP_ARTIST: - snprintf(select_query, sizeof(select_query), SELECT_ARTIST_COUNT); - break; - case MEDIA_GROUP_GENRE: - snprintf(select_query, sizeof(select_query), SELECT_GENRE_COUNT); - break; - case MEDIA_GROUP_COMPOSER: - snprintf(select_query, sizeof(select_query), SELECT_COMPOSER_COUNT); - break; - case MEDIA_GROUP_YEAR: - snprintf(select_query, sizeof(select_query), SELECT_YEAR_COUNT); + //snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT); + if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; case MEDIA_GROUP_FOLDER: attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT); + //snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT); + if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } break; case MEDIA_GROUP_PLAYLIST: //attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_COUNT); + //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_COUNT); + if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } break; case MEDIA_GROUP_TAG: //attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT); + //snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT); + if(!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } break; case MEDIA_GROUP_BOOKMARK: attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT); + //snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT); + if(!SAFE_STRLCPY(select_query, SELECT_BOOKMARK_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } break; } @@ -312,7 +326,12 @@ int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_dat memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST); + //snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST); + if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } if(filter != NULL) { @@ -386,7 +405,12 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST); + //snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST); + if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } if(filter != NULL) { @@ -462,7 +486,13 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_LIST); + //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_LIST); + if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + if(filter != NULL) { @@ -604,7 +634,12 @@ int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callba { //attr = _content_get_alias_attirbute_handle(); attr = _content_get_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST); + //snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST); + if(!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } } else { @@ -683,7 +718,12 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark if(!STRING_VALID(media_id)) { attr = _content_get_alias_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST); + //snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST); + if(!SAFE_STRLCPY(select_query, SELECT_BOOKMARK_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } } else { @@ -735,7 +775,7 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark bookmark->marked_time = (int)sqlite3_column_int(stmt, 2); if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) - bookmark->thumbnail = strdup((const char *)sqlite3_column_text(stmt, 3)); + bookmark->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 3)); if(callback((media_bookmark_h)bookmark, user_data) == false) { @@ -752,87 +792,6 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark } -int _media_db_get_group(filter_h filter, media_group_cb callback, void *user_data, group_list_e group_type) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; - char *condition_query = NULL; - char *option_query = NULL; - char *name = NULL; - sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - - memset(select_query, 0x00, sizeof(select_query)); - - if(group_type == MEDIA_GROUP_ARTIST) - { - snprintf(select_query, sizeof(select_query), SELECT_ARTIST_LIST); - } - else if(group_type == MEDIA_GROUP_GENRE) - { - snprintf(select_query, sizeof(select_query), SELECT_GENRE_LIST); - } - else if(group_type == MEDIA_GROUP_COMPOSER) - { - snprintf(select_query, sizeof(select_query), SELECT_COMPOSER_LIST); - } - else if(group_type == MEDIA_GROUP_YEAR) - { - snprintf(select_query, sizeof(select_query), SELECT_YEAR_LIST); - } - else - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } - - ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); - SAFE_FREE(condition_query); - SAFE_FREE(option_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - while(sqlite3_step(stmt) == SQLITE_ROW) - { - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) - { - name = strdup((const char *)sqlite3_column_text(stmt, 0)); - media_content_debug("group name : [%s]", name); - } - - if(callback(name, user_data) == false) - { - SAFE_FREE(name); - break; - } - - SAFE_FREE(name); - } - - SQLITE3_FINALIZE(stmt); - - return ret; -} - int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -888,7 +847,7 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); } } - +/* if((group_type == MEDIA_GROUP_PLAYLIST) || (group_type == MEDIA_GROUP_TAG)) { strncat(select_query, QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE)); @@ -903,7 +862,7 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li SAFE_FREE(condition_query); SAFE_FREE(option_query); } - +*/ ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); @@ -936,22 +895,6 @@ int _media_db_get_group_item_count(const char *group_name, filter_h filter, grou { select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA); } - else if(group_type == MEDIA_GROUP_ARTIST) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_ARTIST, group_name); - } - else if(group_type == MEDIA_GROUP_GENRE) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GENRE, group_name); - } - else if(group_type == MEDIA_GROUP_COMPOSER) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_COMPOSER, group_name); - } - else if(group_type == MEDIA_GROUP_YEAR) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_YEAR, group_name); - } else if(group_type == MEDIA_GROUP_FOLDER) { select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, group_name); @@ -1128,22 +1071,6 @@ int _media_db_get_group_item(const char *group_name, filter_h filter, media_info { select_query = sqlite3_mprintf(SELECT_MEDIA_ITEM); } - else if(group_type == MEDIA_GROUP_ARTIST) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_ARTIST, group_name); - } - else if(group_type == MEDIA_GROUP_GENRE) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GENRE, group_name); - } - else if(group_type == MEDIA_GROUP_COMPOSER) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_COMPOSER, group_name); - } - else if(group_type == MEDIA_GROUP_YEAR) - { - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_YEAR, group_name); - } else if(group_type == MEDIA_GROUP_FOLDER) { select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_FOLDER, group_name); diff --git a/src/media_filter.c b/src/media_filter.c index 4c198f0..6280759 100755 --- a/src/media_filter.c +++ b/src/media_filter.c @@ -662,32 +662,6 @@ int _media_filter_attribute_add(attribute_h attr, char *user_attr, char *platfor return ret; } -int _media_filter_attribute_remove(attribute_h attr, char *user_attr) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - attribute_s *_attr = (attribute_s*)attr; - - if(attr != NULL) - { - if(STRING_VALID(user_attr)) - { - g_hash_table_remove(_attr->attr_map, user_attr); - } - else - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - } - else - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - return ret; -} - int _media_filter_attribute_destory(attribute_h attr) { int ret = MEDIA_CONTENT_ERROR_NONE; diff --git a/src/media_folder.c b/src/media_folder.c index e805d76..e0f104b 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -21,57 +21,8 @@ static char *g_src_path = NULL; -static void __media_folder_get_detail(sqlite3_stmt *stmt, media_folder_h folder); -static int __media_folder_get_folder_info_from_db(const char *path, media_folder_h folder); static char *__media_folder_get_update_folder_sql(media_folder_h folder); -static void __media_folder_get_detail(sqlite3_stmt* stmt, media_folder_h folder) -{ - media_folder_s *_folder = (media_folder_s*)folder; - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) - _folder->folder_id = strdup((const char *)sqlite3_column_text(stmt, 0)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) - _folder->path = strdup((const char *)sqlite3_column_text(stmt, 1)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) - _folder->name = strdup((const char *)sqlite3_column_text(stmt, 2)); - - _folder->storage_type = (int)sqlite3_column_int(stmt,3); - - _folder->modified_time = (int)sqlite3_column_int(stmt,4); -} - -static int __media_folder_get_folder_info_from_db(const char *path, media_folder_h folder) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - sqlite3_stmt *stmt = NULL; - char *select_query = NULL; - media_folder_s *_folder = (media_folder_s*)folder; - - if(_folder == NULL) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - select_query = sqlite3_mprintf(SELECT_FOLDER_BY_PATH, path); - - ret = _content_query_prepare(&stmt, select_query, NULL, NULL); - sqlite3_free(select_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - while(sqlite3_step(stmt) == SQLITE_ROW) - { - __media_folder_get_detail(stmt, (media_folder_h)_folder); - } - - SQLITE3_FINALIZE(stmt); - - return ret; -} - static char *__media_folder_get_update_folder_sql(media_folder_h folder) { media_folder_s *_folder = (media_folder_s*)folder; @@ -85,41 +36,6 @@ static char *__media_folder_get_update_folder_sql(media_folder_h folder) return return_sql; } -int media_folder_insert_to_db(const char *path, media_folder_h *folder) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - int storage_type = -1; - - if(!STRING_VALID(path)) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s)); - - _folder->path = strdup(path); - _media_util_get_store_type_by_path(path, &storage_type); - _folder->storage_type = storage_type; - - if(_folder->path == NULL) - { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - /* New media svc api */ - ret = media_svc_insert_folder(_content_get_db_handle(), _folder->storage_type, _folder->path); - - if(ret == MEDIA_INFO_ERROR_NONE) - { - ret = __media_folder_get_folder_info_from_db(_folder->path, (media_folder_h)_folder); - *folder = (media_folder_h)_folder; - } - - return _content_error_capi(MEDIA_CONTENT_TYPE, ret); -} - int media_folder_delete_from_db(const char *folder_id) { int ret = MEDIA_CONTENT_ERROR_NONE; diff --git a/src/media_info.c b/src/media_info.c index bf260f7..cb067dc 100755 --- a/src/media_info.c +++ b/src/media_info.c @@ -16,6 +16,7 @@ #include <media_content.h> +#include <media-thumbnail.h> #include <media_info_private.h> #include <media_util_private.h> #include <media-svc.h> @@ -24,9 +25,7 @@ static int __media_info_get_media_info_from_db(char *path, media_info_h media); -static void __media_info_image_item_get_detail(sqlite3_stmt* stmt, image_meta_h image); -static void __media_info_video_item_get_detail(sqlite3_stmt* stmt, video_meta_h video); -static void __media_info_audio_item_get_detail(sqlite3_stmt* stmt, audio_meta_h audio); +static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data); static int __media_info_get_media_info_from_db(char *path, media_info_h media) { @@ -66,111 +65,28 @@ static int __media_info_get_media_info_from_db(char *path, media_info_h media) return ret; } -static void __media_info_image_item_get_detail(sqlite3_stmt* stmt, image_meta_h image) +static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data) { - image_meta_s *_image = (image_meta_s*)image; + int error_value = MEDIA_CONTENT_ERROR_NONE; - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) - _image->media_id = strdup((const char *)sqlite3_column_text(stmt, 0)); - - _image->width = sqlite3_column_int(stmt, 1); - - _image->height = sqlite3_column_int(stmt, 2); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) - _image->date_taken = strdup((const char *)sqlite3_column_text(stmt, 3)); - - _image->orientation = sqlite3_column_int(stmt, 4); - - return; -} - -static void __media_info_video_item_get_detail(sqlite3_stmt* stmt, video_meta_h video) -{ - video_meta_s *_video = (video_meta_s*)video; - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) - _video->media_id = strdup((const char *)sqlite3_column_text(stmt, 0)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) - _video->title = strdup((const char *)sqlite3_column_text(stmt, 1)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) - _video->album = strdup((const char *)sqlite3_column_text(stmt, 2)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) - _video->artist = strdup((const char *)sqlite3_column_text(stmt, 3)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 4))) - _video->genre = strdup((const char *)sqlite3_column_text(stmt, 4)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 5))) - _video->composer = strdup((const char *)sqlite3_column_text(stmt, 5)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 6))) - _video->year = strdup((const char *)sqlite3_column_text(stmt, 6)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 7))) - _video->recorded_date = strdup((const char *)sqlite3_column_text(stmt, 7)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 8))) - _video->copyright = strdup((const char *)sqlite3_column_text(stmt, 8)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 9))) - _video->track_num = strdup((const char *)sqlite3_column_text(stmt, 9)); + media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data; + media_info_s *media = NULL; - _video->bitrate = sqlite3_column_int(stmt, 10); - _video->duration = sqlite3_column_int(stmt, 11); - _video->played_count = sqlite3_column_int(stmt, 12); - _video->played_time = sqlite3_column_int(stmt, 13); - _video->played_position = sqlite3_column_int(stmt, 14); - _video->width = sqlite3_column_int(stmt, 15); - _video->height = sqlite3_column_int(stmt, 16); - - return; -} - -static void __media_info_audio_item_get_detail(sqlite3_stmt* stmt, audio_meta_h audio) -{ - audio_meta_s *_audio = (audio_meta_s*)audio; - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) - _audio->media_id = strdup((const char *)sqlite3_column_text(stmt, 0)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) - _audio->title = strdup((const char *)sqlite3_column_text(stmt, 1)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) - _audio->album = strdup((const char *)sqlite3_column_text(stmt, 2)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) - _audio->artist = strdup((const char *)sqlite3_column_text(stmt, 3)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 4))) - _audio->genre = strdup((const char *)sqlite3_column_text(stmt, 4)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 5))) - _audio->composer = strdup((const char *)sqlite3_column_text(stmt, 5)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 6))) - _audio->year = strdup((const char *)sqlite3_column_text(stmt, 6)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 7))) - _audio->recorded_date = strdup((const char *)sqlite3_column_text(stmt, 7)); - - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 8))) - _audio->copyright = strdup((const char *)sqlite3_column_text(stmt, 8)); + if(_thumb_cb != NULL) + { + media = _thumb_cb->handle; + if((media != NULL) && STRING_VALID(path)) + { + SAFE_FREE(media->thumbnail_path); + media->thumbnail_path = strdup(path); + } - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 9))) - _audio->track_num = strdup((const char *)sqlite3_column_text(stmt, 9)); + media_content_debug("error [%d], thumbnail_path [%s]", error, path); + error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error); + _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data); + } - _audio->bitrate = sqlite3_column_int(stmt, 10); - _audio->duration = sqlite3_column_int(stmt, 11); - _audio->played_count = sqlite3_column_int(stmt, 12); - _audio->played_time = sqlite3_column_int(stmt, 13); - _audio->played_position = sqlite3_column_int(stmt, 14); - _audio->samplerate = sqlite3_column_int(stmt, 15); - _audio->channel = sqlite3_column_int(stmt, 16); + SAFE_FREE(_thumb_cb); return; } @@ -203,7 +119,7 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) _media->modified_time = (int)sqlite3_column_int(stmt, 7); if(STRING_VALID((const char *)sqlite3_column_text(stmt, 8))) - _media->thumbnail = strdup((const char *)sqlite3_column_text(stmt, 8)); + _media->thumbnail_path= strdup((const char *)sqlite3_column_text(stmt, 8)); if(STRING_VALID((const char *)sqlite3_column_text(stmt, 9))) _media->description = strdup((const char *)sqlite3_column_text(stmt, 9)); @@ -344,22 +260,6 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) } } -int _content_get_storage_type(const char *full_path) -{ - if(STRING_VALID(full_path)) { - if(strncmp(full_path, MEDIA_CONTENT_PATH_PHONE, strlen(MEDIA_CONTENT_PATH_PHONE)) == 0) - { - return MEDIA_CONTENT_STORAGE_INTERNAL; - } - else if(strncmp(full_path, MEDIA_CONTENT_PATH_MMC, strlen(MEDIA_CONTENT_PATH_MMC)) == 0) - { - return MEDIA_CONTENT_STORAGE_EXTERNAL; - } - } - - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; -} - int media_info_insert_to_db (const char *path, media_info_h *info) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -438,7 +338,7 @@ int media_info_destroy(media_info_h media) SAFE_FREE(_media->file_path); SAFE_FREE(_media->display_name); SAFE_FREE(_media->mime_type); - SAFE_FREE(_media->thumbnail); + SAFE_FREE(_media->thumbnail_path); SAFE_FREE(_media->description); SAFE_FREE(_media->author); SAFE_FREE(_media->provider); @@ -550,10 +450,10 @@ int media_info_clone(media_info_h *dst, media_info_h src) return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } } - if(STRING_VALID(_src->thumbnail)) + if(STRING_VALID(_src->thumbnail_path)) { - _dst->thumbnail = strdup(_src->thumbnail); - if(_dst->thumbnail == NULL) + _dst->thumbnail_path = strdup(_src->thumbnail_path); + if(_dst->thumbnail_path == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); media_info_destroy((media_info_h)_dst); @@ -1254,126 +1154,6 @@ int media_info_get_audio(media_info_h media, audio_meta_h *audio) return ret; } -int media_info_get_image_from_db(const char *media_id, image_meta_h *image) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; - sqlite3_stmt *stmt = NULL; - - media_content_debug_func(); - - if(!STRING_VALID(media_id)) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - memset(select_query,0x00, sizeof(select_query)); - - snprintf(select_query, sizeof(select_query), SELECT_IMAGE_FROM_MEDIA, media_id); - - ret = _content_query_prepare(&stmt, select_query, NULL, NULL); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s)); - if(_image == NULL) - { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - while(sqlite3_step(stmt) == SQLITE_ROW) - { - __media_info_image_item_get_detail(stmt, (image_meta_h)_image); - } - - *image = (image_meta_h)_image; - - SQLITE3_FINALIZE(stmt); - - return ret; -} - -int media_info_get_video_from_db(const char *media_id, video_meta_h *video) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; - sqlite3_stmt *stmt = NULL; - - media_content_debug_func(); - - if(!STRING_VALID(media_id)) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - memset(select_query,0x00, sizeof(select_query)); - - snprintf(select_query, sizeof(select_query), SELECT_VIDEO_FROM_MEDIA, media_id); - - ret = _content_query_prepare(&stmt, select_query, NULL, NULL); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s)); - if(_video == NULL) - { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - while(sqlite3_step(stmt) == SQLITE_ROW) - { - __media_info_video_item_get_detail(stmt, (video_meta_h)_video); - } - - *video = (video_meta_h)_video; - - SQLITE3_FINALIZE(stmt); - - return ret; -} - -int media_info_get_audio_from_db(const char *media_id, audio_meta_h *audio) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; - sqlite3_stmt *stmt = NULL; - - media_content_debug_func(); - - if(!STRING_VALID(media_id)) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - memset(select_query,0x00, sizeof(select_query)); - - snprintf(select_query, sizeof(select_query), SELECT_AUDIO_FROM_MEDIA, media_id); - - ret = _content_query_prepare(&stmt, select_query, NULL, NULL); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s)); - if(_audio == NULL) - { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - while(sqlite3_step(stmt) == SQLITE_ROW) - { - __media_info_audio_item_get_detail(stmt, (audio_meta_h)_audio); - } - - *audio = (audio_meta_h)_audio; - - SQLITE3_FINALIZE(stmt); - - return ret; -} - int media_info_get_media_id(media_info_h media, char **media_id) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -1578,9 +1358,9 @@ int media_info_get_thumbnail_path(media_info_h media, char **path) media_info_s *_media = (media_info_s*)media; if(_media && path) { - if(STRING_VALID(_media->thumbnail)) + if(STRING_VALID(_media->thumbnail_path)) { - *path = strdup(_media->thumbnail); + *path = strdup(_media->thumbnail_path); if(*path == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); @@ -2494,6 +2274,30 @@ int media_info_refresh_metadata_to_db(const char *media_id) return ret; } +int media_info_move_to_db(media_info_h media, const char* dst_path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + int src_storage_type = 0; + int dst_storage_type = 0; + + if(media == NULL || !STRING_VALID(dst_path)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_info_s *_media = (media_info_s*)media; + + ret = _media_util_get_store_type_by_path(_media->file_path, &src_storage_type); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + ret = _media_util_get_store_type_by_path(dst_path, &dst_storage_type); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = media_svc_move_item(_content_get_db_handle(), src_storage_type, _media->file_path, dst_storage_type, dst_path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + int media_info_move_media_to_db(media_info_h media, const char* dst_path) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -2518,3 +2322,26 @@ int media_info_move_media_to_db(media_info_h media, const char* dst_path) return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) + { + media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s)); + _thumb_cb->handle = _media; + _thumb_cb->user_data = user_data; + _thumb_cb->thumbnail_completed_cb = callback; + + ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb); + _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_util_private.c b/src/media_util_private.c index 7927b01..10d518f 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -43,26 +43,3 @@ int _media_util_get_store_type_by_path(const char *path, int *storage_type) return MEDIA_CONTENT_ERROR_NONE; } - -int _media_util_get_file_dir_modified_time(const char *path) -{ - struct stat statbuf; - int fd = 0; - int err = 0; - - if(!STRING_VALID(path)) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - memset(&statbuf, 0, sizeof(struct stat)); - fd = stat(path, &statbuf); - if(fd == -1) { - err = errno; - media_content_error("stat(%s) fails. err[%d]", path, err); - return -1; - } - - return statbuf.st_mtime; -} diff --git a/test/media-content_test.c b/test/media-content_test.c index 1da6157..566e13f 100755 --- a/test/media-content_test.c +++ b/test/media-content_test.c @@ -32,6 +32,9 @@ filter_h g_filter = NULL; filter_h g_filter_g = NULL; //filter for group like folder, tag, playlist, album, year ... +GMainLoop *g_loop = NULL; +static int g_cnt = 0; +static int g_media_cnt = 0; #define test_audio_id "0f999626-6218-450c-a4ad-181a3bab6ebf" #define test_video_id "c1a92494-cc5b-4d74-aa7d-253199234548" @@ -658,7 +661,7 @@ int test_filter_create(void) int ret = MEDIA_CONTENT_ERROR_NONE; /* Filter for media */ - char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + char *condition = "MEDIA_TYPE=0"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ ret = media_filter_create(&g_filter); @@ -1650,11 +1653,11 @@ int test_update_operation() image_meta_h image_handle; media_content_orientation_e orientation; - ret = media_info_get_image_from_db(media_id, &image_handle); + ret = media_info_get_image(media_handle, &image_handle); if(ret < 0) { - media_content_error("media_info_get_image_from_db failed: %d", ret); + media_content_error("media_info_get_image failed: %d", ret); } else { - media_content_debug("media_info_get_image_from_db success"); + media_content_debug("media_info_get_image success"); //update image meta orientation = MEDIA_CONTENT_ORIENTATION_ROT_180; @@ -1671,11 +1674,11 @@ int test_update_operation() } else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) { video_meta_h video_handle; - ret = media_info_get_video_from_db(media_id, &video_handle); + ret = media_info_get_video(media_handle, &video_handle); if(ret < 0) { - media_content_error("media_info_get_video_from_db failed: %d", ret); + media_content_error("media_info_get_video failed: %d", ret); } else { - media_content_debug("media_info_get_video_from_db success"); + media_content_debug("media_info_get_video success"); //update video meta video_meta_set_played_count(video_handle,5); @@ -1692,11 +1695,11 @@ int test_update_operation() } } else if(media_type == MEDIA_CONTENT_TYPE_MUSIC) {//update audio meta audio_meta_h audio_handle = NULL; - ret = media_info_get_audio_from_db(media_id, &audio_handle); + ret = media_info_get_audio(media_handle, &audio_handle); if(ret < 0) { - media_content_error("media_info_get_audio_from_db failed: %d", ret); + media_content_error("media_info_get_audio failed: %d", ret); } else { - media_content_debug("media_info_get_audio_from_db success"); + media_content_debug("media_info_get_audio success"); audio_meta_set_played_count(audio_handle,5); audio_meta_set_played_time(audio_handle,1000); @@ -1765,7 +1768,7 @@ int test_move(void) media_content_debug("\n============DB Move Test============\n\n"); if(move_media) { - ret = media_info_move_media_to_db(move_media, dst_path); + ret = media_info_move_to_db(move_media, dst_path); if(ret == MEDIA_CONTENT_ERROR_NONE) media_content_debug("Move is success\n\n"); @@ -1778,6 +1781,88 @@ int test_move(void) return ret; } +void thumbnail_completed_cb(media_content_error_e error, const char *path, void *user_data) +{ + char *thumbnail_path = NULL; + g_cnt++; + + printf("=================[%d][%d]\n", g_media_cnt, g_cnt); + printf("error_code [%d]\n", error); + printf("thumbnail_path [%s]\n", path); + if(user_data != NULL) + { + media_info_h media = (media_info_h)user_data; + media_info_get_thumbnail_path(media, &thumbnail_path); + printf("thumbnail_path get from media[%s]\n", thumbnail_path); + SAFE_FREE(thumbnail_path); + media_info_destroy(media); + } + + if(g_cnt == g_media_cnt) + g_main_loop_quit(g_loop); + + return; +} + +bool thumbnail_create_cb(media_info_h media, void *user_data) +{ + char *media_id = NULL; + media_info_h dst = NULL; + + if(media == NULL) + { + media_content_debug("NO Item \n"); + return true; + } + + media_info_get_media_id(media, &media_id); + media_content_debug("media_id : [%s] \n", media_id); + + media_info_clone(&dst, media); + media_info_create_thumbnail(dst, thumbnail_completed_cb, dst); + + return true; +} + +gboolean create_thumbnail_start(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_info_foreach_media_from_db(g_filter, thumbnail_create_cb, NULL); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_foreach_media_from_db is success\n\n"); + else + media_content_error("media_info_foreach_media_from_db is failed\n\n"); + + return false; +} + +int test_create_thumbnail(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + GSource *source = NULL; + GMainContext *context = NULL; + + test_filter_create(); + + media_info_get_media_count_from_db(g_filter, &g_media_cnt); + media_content_debug("media_count : [%d],\n", g_media_cnt); + + g_loop = g_main_loop_new(NULL, FALSE); + context = g_main_loop_get_context(g_loop); + source = g_idle_source_new(); + g_source_set_callback (source, create_thumbnail_start, NULL, NULL); + g_source_attach (source, context); + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + + test_filter_destroy(); + + return ret; +} + int test_disconnect_database(void) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -2024,6 +2109,10 @@ int main(int argc, char *argv[]) if(ret != MEDIA_CONTENT_ERROR_NONE) return ret; + ret = test_create_thumbnail(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + ret = DFT_test(); if(ret != MEDIA_CONTENT_ERROR_NONE) return ret; |