X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fcommon%2Fmedia-svc-util.c;h=1db380d93debd09b5997bca617a0e6d3672b971b;hb=refs%2Fchanges%2F81%2F307481%2F4;hp=2e7930a00beb02e5face0c24aa5450fd6d92aaf0;hpb=2bc1d2a82f85e1c9560fa2466d0c24cc9c0f0045;p=platform%2Fcore%2Fmultimedia%2Flibmedia-service.git diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 2e7930a..1db380d 100644 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -27,9 +27,9 @@ #include #include #include -#include #include #include +#include #include "media-svc-util.h" #include "media-svc-db-utils.h" #include "media-svc-debug.h" @@ -264,25 +264,6 @@ static bool __media_svc_get_file_ext(const char *file_path, char *file_ext) return false; } -static int __media_svc_safe_atoi(char *buffer, int *si) -{ - char *end = NULL; - errno = 0; - media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter"); - - const long sl = strtol(buffer, &end, 10); - - media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number"); - media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end); - media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long"); - media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX"); - media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN"); - - *si = (int)sl; - - return MS_MEDIA_ERR_NONE; -} - static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; @@ -466,7 +447,6 @@ static char * __media_svc_get_title(MMHandleType tag, const char *filename) char * _media_svc_get_title_from_filename(const char *filename) { - /* No MMHandleType in media-svc.c */ return __media_svc_get_title_from_filename(filename); } @@ -581,16 +561,40 @@ static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_na return g_strdup(MEDIA_SVC_TAG_UNKNOWN); } -int _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid) +static char * __media_svc_extract_albumart(MMHandleType tag, const char *path, uid_t uid) +{ + int ret = FILEINFO_ERROR_NONE; + unsigned char *image = NULL; + unsigned int size = 0; + char *mimetype = NULL; + char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = { 0, }; + unsigned int mime_size = 0; + + ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL); + media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag artwork[%d]", ret); + media_svc_retvm_if(!image || size == 0, NULL, "Invalid artwork"); + + ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &mimetype, &mime_size, NULL); + media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag mime[%d]", ret); + media_svc_retvm_if(mime_size == 0, NULL, "Invalid mimetype"); + + ret = __media_svc_get_thumbnail_path(thumb_path, path, mimetype, uid); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Failed to get thumbnail path"); + + ret = __media_svc_save_image(image, size, thumb_path, uid); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Fail to save thumbnail"); + + return g_strdup(thumb_path); +} + +void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid) { MMHandleType tag = 0; char *p = NULL; - unsigned char *image = NULL; unsigned int size = 0; int mmf_error = FILEINFO_ERROR_NONE; int album_id = 0; int ret = MS_MEDIA_ERR_NONE; - int convert_value = 0; bool support_albumart = ms_user_thumb_support(uid, content_info->path); /*Get Content Tag attribute ===========*/ @@ -599,97 +603,57 @@ int _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc else mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path); - if (mmf_error == FILEINFO_ERROR_NONE) { - content_info->media_meta.title = __media_svc_get_title(tag, content_info->file_name); - content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM); - content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST); - content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST); - content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE); - content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM); - content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT); + if (mmf_error != FILEINFO_ERROR_NONE) { + content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name); + content_info->album_id = 0; + return; + } - mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL); - if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) { - if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) { - /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00 +0000 like exif time format*/ - char *p_value = g_strdelimit(g_strdup(p), "-", ':'); - content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value); - g_free(p_value); - } else { - content_info->media_meta.recorded_date = g_strdup(p); - } + content_info->media_meta.title = __media_svc_get_title(tag, content_info->file_name); + content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM); + content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST); + content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST); + content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE); + content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM); + content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT); + + mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL); + if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) { + if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) { + /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00 +0000 like exif time format*/ + char *p_value = g_strdelimit(g_strdup(p), "-", ':'); + content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value); + g_free(p_value); + } else { + content_info->media_meta.recorded_date = g_strdup(p); } + } - if (content_info->media_meta.recorded_date == NULL) - content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN); - - mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL); - if (mmf_error == FILEINFO_ERROR_NONE && size == 4) { - if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE) - content_info->media_meta.year = g_strdup(p); - } + if (content_info->media_meta.recorded_date == NULL) + content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN); - if (!content_info->media_meta.year) - content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN); - - /*Do not extract artwork for the USB Storage content*/ - if (support_albumart) { - mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL); - if (mmf_error != FILEINFO_ERROR_NONE) - media_svc_error("fail to get tag artwork - err(%x)", mmf_error); - - mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL); - if (mmf_error != FILEINFO_ERROR_NONE) - media_svc_error("fail to get artwork size - err(%x)", mmf_error); - - if (image != NULL && size > 0) { - char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0"; - int artwork_mime_size = -1; - - mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL); - if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) { - ret = __media_svc_get_thumbnail_path(thumb_path, content_info->path, p, uid); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("Fail to Get Thumbnail Path"); - } else { - ret = __media_svc_save_image(image, size, thumb_path, uid); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("Fail to Save Image"); - } else { - content_info->thumbnail_path = g_strdup(thumb_path); - } - } - } - } - } + mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL); + if (mmf_error == FILEINFO_ERROR_NONE && size == 4) + content_info->media_meta.year = g_strdup(p); + else + content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN); - /*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"); - if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) && - (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) - ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid); - else - ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid); - - content_info->album_id = album_id; - } - } else { - content_info->album_id = album_id; - } + /*Do not extract artwork for the USB Storage content*/ + if (support_albumart) + content_info->thumbnail_path = __media_svc_extract_albumart(tag, content_info->path, uid); - mmf_error = mm_file_destroy_tag_attrs(tag); - if (mmf_error != FILEINFO_ERROR_NONE) - media_svc_error("fail to free tag attr - err(%x)", mmf_error); - } else { - content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name); - 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_DB_NO_RECORD) { + media_svc_debug("album does not exist. So start to make album art"); + if (strlen(content_info->media_meta.album) > 0 && strlen(content_info->media_meta.artist) > 0) + ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid); + else + ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid); } + content_info->album_id = album_id; - return MS_MEDIA_ERR_NONE; + if (mm_file_destroy_tag_attrs(tag) != FILEINFO_ERROR_NONE) + media_svc_error("destroy failed"); } int _media_svc_extract_video_metadata(media_svc_content_info_s *content_info) @@ -898,6 +862,7 @@ static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_ } content_info->media_meta.title = __media_svc_find_and_get_value(root, "title"); + /* In the case of PDF, if there is no title, it may not be a metadata block. Search for the next xml block*/ if (is_pdf && !content_info->media_meta.title) { xmlFreeDoc(doc); return FALSE; @@ -1024,12 +989,22 @@ static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info) int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info) { + int ret = MS_MEDIA_ERR_NONE; + media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL"); if (g_str_has_suffix(content_info->mime_type, "epub+zip")) - return __media_svc_get_epub_metadata(content_info); + ret = __media_svc_get_epub_metadata(content_info); else - return __media_svc_get_pdf_metadata(content_info); + ret = __media_svc_get_pdf_metadata(content_info); + + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to extract metadata"); + if (!content_info->media_meta.title || strlen(content_info->media_meta.title) == 0) { + g_free(content_info->media_meta.title); + content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name); + } + + return MS_MEDIA_ERR_NONE; } void _media_svc_destroy_content_info(media_svc_content_info_s *content_info) @@ -1074,11 +1049,7 @@ int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_me //1. make thumb path ret = __media_svc_get_thumbnail_path(thumb_path, path, NULL, uid); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("Failed to create thumbnail path[%d]", ret); - g_strlcpy(thumb_path, "", MAX_FILEPATH_LEN); - return ret; - } + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to create thumbnail path[%d]", ret); //2. save thumbnail if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)