From d75689908a8efc42e3774ae20553b75c9fc1c1be Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Mon, 5 Feb 2018 16:35:49 +0900 Subject: [PATCH] [ACR-1163] Add synchronous API to create thumbnails Change-Id: Ib7de464bf2ec6cc38591a043393b52a6cd1f406b Signed-off-by: Minje Ahn --- include/media_content_type.h | 1 + include/media_info.h | 44 ++++++++++++++++++++++++++++++++---- include_product/media_content_type.h | 1 + include_product/media_info.h | 44 ++++++++++++++++++++++++++++++++---- src/media_info.c | 36 +++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 8 deletions(-) diff --git a/include/media_content_type.h b/include/media_content_type.h index 2f20453..6df515a 100755 --- a/include/media_content_type.h +++ b/include/media_content_type.h @@ -423,6 +423,7 @@ typedef void (*media_insert_burst_shot_completed_cb)(media_content_error_e error /** + * @deprecated Deprecated since 5.0. * @ingroup CAPI_CONTENT_MEDIA_INFO_MODULE * @brief Called when creating a thumbnail image. * @details This callback is called for completion of generating the thumbnail image. diff --git a/include/media_info.h b/include/media_info.h index 7455015..6530b21 100755 --- a/include/media_info.h +++ b/include/media_info.h @@ -734,8 +734,9 @@ int media_info_get_timeline(media_info_h media, time_t *time); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * * @remarks The @a path should be released using free(). \n - * If the thumbnail extraction for the given media has not been requested yet, this function returns NULL. To create a thumbnail, you should use media_info_create_thumbnail() function. \n - * Since 3.0, this function returns an empty string if media_info_create_thumbnail() has failed to create a thumbnail for the given media. + * If the thumbnail extraction for the given media has not been requested yet, this function returns NULL. \n + * To create a thumbnail, you should use media_info_generate_thumbnail() function. \n + * This function returns an empty string if media_info_generate_thumbnail() has failed to create a thumbnail for the given media. * * @param[in] media The handle to the media info * @param[out] path The thumbnail path @@ -1606,6 +1607,7 @@ int media_info_set_added_time(media_info_h media, time_t added_time) TIZEN_DEPRE int media_info_move_to_db(media_info_h media, const char* dst_path); /** + * @deprecated Deprecated since 5.0. Use media_info_generate_thumbnail() instead. * @brief Creates a thumbnail file for the given media, asynchronously. * @details This function creates an thumbnail file for given media item and calls @a callback for completion of creating the thumbnail. * If a thumbnail already exists for the given media, then the path of thumbnail will be returned in callback function. \n @@ -1643,9 +1645,10 @@ int media_info_move_to_db(media_info_h media, const char* dst_path); * * @see media_content_connect() */ -int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data); +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data) TIZEN_DEPRECATED_API; /** + * @deprecated Deprecated since 5.0. * @brief Cancels the creation of thumbnail file for the given media. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @@ -1667,7 +1670,40 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb * @pre This function requires opened connection to content service by media_content_connect(). * @see media_content_connect() */ -int media_info_cancel_thumbnail(media_info_h media); +int media_info_cancel_thumbnail(media_info_h media) TIZEN_DEPRECATED_API; + +/** + * @brief Generates a thumbnail file for the given media, synchronously. + * + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/content.write + * + * @remarks http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage. \n + * http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage. \n + * Items in external storage are not supported, with the exception of MMC. + * + * @param[in] 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_INVALID_OPERATION Invalid operation + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * @retval #MEDIA_CONTENT_ERROR_NETWORK Network fail + * @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_get_thumbnail_path() + */ +int media_info_generate_thumbnail(media_info_h media); /** * @ingroup CAPI_CONTENT_MEDIA_FACE_DETECTION_MODULE diff --git a/include_product/media_content_type.h b/include_product/media_content_type.h index 35e986f..4f8a83f 100755 --- a/include_product/media_content_type.h +++ b/include_product/media_content_type.h @@ -489,6 +489,7 @@ typedef void (*media_insert_burst_shot_completed_cb)(media_content_error_e error /** + * @deprecated Deprecated since 5.0. * @ingroup CAPI_CONTENT_MEDIA_INFO_MODULE * @brief Called when creating a thumbnail image. * @details This callback is called for completion of generating the thumbnail image. diff --git a/include_product/media_info.h b/include_product/media_info.h index 7455015..6530b21 100755 --- a/include_product/media_info.h +++ b/include_product/media_info.h @@ -734,8 +734,9 @@ int media_info_get_timeline(media_info_h media, time_t *time); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * * @remarks The @a path should be released using free(). \n - * If the thumbnail extraction for the given media has not been requested yet, this function returns NULL. To create a thumbnail, you should use media_info_create_thumbnail() function. \n - * Since 3.0, this function returns an empty string if media_info_create_thumbnail() has failed to create a thumbnail for the given media. + * If the thumbnail extraction for the given media has not been requested yet, this function returns NULL. \n + * To create a thumbnail, you should use media_info_generate_thumbnail() function. \n + * This function returns an empty string if media_info_generate_thumbnail() has failed to create a thumbnail for the given media. * * @param[in] media The handle to the media info * @param[out] path The thumbnail path @@ -1606,6 +1607,7 @@ int media_info_set_added_time(media_info_h media, time_t added_time) TIZEN_DEPRE int media_info_move_to_db(media_info_h media, const char* dst_path); /** + * @deprecated Deprecated since 5.0. Use media_info_generate_thumbnail() instead. * @brief Creates a thumbnail file for the given media, asynchronously. * @details This function creates an thumbnail file for given media item and calls @a callback for completion of creating the thumbnail. * If a thumbnail already exists for the given media, then the path of thumbnail will be returned in callback function. \n @@ -1643,9 +1645,10 @@ int media_info_move_to_db(media_info_h media, const char* dst_path); * * @see media_content_connect() */ -int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data); +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data) TIZEN_DEPRECATED_API; /** + * @deprecated Deprecated since 5.0. * @brief Cancels the creation of thumbnail file for the given media. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @@ -1667,7 +1670,40 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb * @pre This function requires opened connection to content service by media_content_connect(). * @see media_content_connect() */ -int media_info_cancel_thumbnail(media_info_h media); +int media_info_cancel_thumbnail(media_info_h media) TIZEN_DEPRECATED_API; + +/** + * @brief Generates a thumbnail file for the given media, synchronously. + * + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/content.write + * + * @remarks http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage. \n + * http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage. \n + * Items in external storage are not supported, with the exception of MMC. + * + * @param[in] 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_INVALID_OPERATION Invalid operation + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * @retval #MEDIA_CONTENT_ERROR_NETWORK Network fail + * @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_get_thumbnail_path() + */ +int media_info_generate_thumbnail(media_info_h media); /** * @ingroup CAPI_CONTENT_MEDIA_FACE_DETECTION_MODULE diff --git a/src/media_info.c b/src/media_info.c index 9b2de2e..95266c9 100755 --- a/src/media_info.c +++ b/src/media_info.c @@ -3096,6 +3096,7 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; + media_content_warn("DEPRECATION WARNING: media_info_create_thumbnail() is deprecated and will be removed from next release. Use media_info_generate_thumbnail() instead."); static unsigned int req_id = 0; char repl_path[MAX_PATH_LEN] = {0, }; media_info_s *_media = (media_info_s*)media; @@ -3124,9 +3125,44 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb return ret; } +int media_info_generate_thumbnail(media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char repl_path[MAX_PATH_LEN] = {0, }; + char *thumb_path = NULL; + media_info_s *_media = (media_info_s*)media; + + if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) { + /* Already exists */ + if (STRING_VALID(_media->thumbnail_path)) + return MEDIA_CONTENT_ERROR_NONE; + + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + + ret = media_svc_create_thumbnail(repl_path, _media->media_type, _content_get_uid(), &thumb_path); + ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); + if (ret == MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT) + return ret; + + /* thumb_path is not NULL except #MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT */ + _media->thumbnail_path = g_strdup(thumb_path); + SAFE_FREE(thumb_path); + if (_media->thumbnail_path == NULL) + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + int media_info_cancel_thumbnail(media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; + media_content_warn("DEPRECATION WARNING: media_info_cancel_thumbnail() is deprecated and will be removed from next release."); media_info_s *_media = (media_info_s*)media; if (_media != NULL && STRING_VALID(_media->media_id) && _media->request_id > 0) { -- 2.7.4