From e8b091cc04a938fd171d3eec72b091150bbb18d7 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 16 Feb 2021 13:50:54 +0900 Subject: [PATCH] [ACR-1618] Add API to get media handle by path Change-Id: Idbccb44d28d01c5a429f7852e6b34389bd19d5fe Signed-off-by: Minje Ahn --- include/media_info.h | 32 +++++++++++++++++++++++++ include_product/media_info.h | 32 +++++++++++++++++++++++++ packaging/capi-content-media-content.spec | 2 +- src/media_info.c | 39 ++++++++++++++++++++++++++++++- 4 files changed, 103 insertions(+), 2 deletions(-) diff --git a/include/media_info.h b/include/media_info.h index 70c0f0b..9d00fa4 100755 --- a/include/media_info.h +++ b/include/media_info.h @@ -895,6 +895,38 @@ int media_info_get_storage_type(media_info_h media, media_content_storage_e *sto int media_info_get_media_from_db(const char *media_id, media_info_h *media); /** + * @brief Gets the media info from the media database using path. + * + * @details This function creates a new media handle filled with information from the database by the given @a media_path. + * + * @since_tizen 6.5 + * + * @remarks The @a media should be released using media_info_destroy().\n + * If you want to access only internal storage by using this function, you should add privilege %http://tizen.org/privilege/mediastorage. \n + * If you want to access only external storage by using this function, you should add privilege %http://tizen.org/privilege/externalstorage. \n + * If you want to access storages of both types, you must add all privileges. \n + * + * @param[in] media_path The media path + * @param[out] media The handle to the media info + * + * @return @c 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 + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre This function requires opened connection to content service by media_content_connect(). + * + * @see media_content_connect() + * @see media_info_destroy() + */ +int media_info_get_media_from_db_by_path(const char *media_path, media_info_h *media); + +/** * @brief Sets the favorite of media info. * @details This function can mark favorite of the media. If set to @c true, this function record the time of the change moment. \n * So, If you use it in order parameter, you can sort the order of the time was a favorite. \n diff --git a/include_product/media_info.h b/include_product/media_info.h index 70c0f0b..9d00fa4 100755 --- a/include_product/media_info.h +++ b/include_product/media_info.h @@ -895,6 +895,38 @@ int media_info_get_storage_type(media_info_h media, media_content_storage_e *sto int media_info_get_media_from_db(const char *media_id, media_info_h *media); /** + * @brief Gets the media info from the media database using path. + * + * @details This function creates a new media handle filled with information from the database by the given @a media_path. + * + * @since_tizen 6.5 + * + * @remarks The @a media should be released using media_info_destroy().\n + * If you want to access only internal storage by using this function, you should add privilege %http://tizen.org/privilege/mediastorage. \n + * If you want to access only external storage by using this function, you should add privilege %http://tizen.org/privilege/externalstorage. \n + * If you want to access storages of both types, you must add all privileges. \n + * + * @param[in] media_path The media path + * @param[out] media The handle to the media info + * + * @return @c 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 + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre This function requires opened connection to content service by media_content_connect(). + * + * @see media_content_connect() + * @see media_info_destroy() + */ +int media_info_get_media_from_db_by_path(const char *media_path, media_info_h *media); + +/** * @brief Sets the favorite of media info. * @details This function can mark favorite of the media. If set to @c true, this function record the time of the change moment. \n * So, If you use it in order parameter, you can sort the order of the time was a favorite. \n diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 59baa6b..c909639 100644 --- 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 Tizen Native API -Version: 0.4.13 +Version: 0.4.14 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_info.c b/src/media_info.c index 47b6a4d..94d5342 100644 --- a/src/media_info.c +++ b/src/media_info.c @@ -1303,6 +1303,43 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media) return ret; } +int media_info_get_media_from_db_by_path(const char *path, media_info_h *media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = NULL; + + content_retip_if_fail(STRING_VALID(path)); + content_retip_if_fail(media); + ret = _media_util_check_file_exist(path); + content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_util_check_file_exist failed : %d", ret); + +#ifdef _USE_TVPD_MODE + char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, }; + + ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid()); + if (ret != MS_MEDIA_ERR_NONE) { + content_error("media_svc_get_storage_id failed : %d", ret); + return _content_error_capi(ret); + } +#endif + + _media = g_new0(media_info_s, 1); + +#ifdef _USE_TVPD_MODE + ret = _media_info_get_media_info_from_db(path, STRING_VALID(storage_id) ? storage_id : DB_TABLE_MEDIA, (media_info_h)_media); +#else + ret = _media_info_get_media_info_from_db(path, (media_info_h)_media); +#endif + if (ret != MEDIA_CONTENT_ERROR_NONE) { + g_free(_media); + _media = NULL; + } + + *media = (media_info_h)_media; + + return ret; +} + int media_info_set_favorite(media_info_h media, bool favorite) { media_info_s *_media = (media_info_s*)media; @@ -1379,7 +1416,7 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) { int ret = MEDIA_CONTENT_ERROR_NONE; char repl_path[MAX_PATH_LEN] = {0, }; - media_info_s *_info = NULL; + media_info_s *_info = NULL; #ifdef _USE_TVPD_MODE char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, }; #endif -- 2.7.4