Append performance patch 32/224332/1 accepted/tizen/5.5/unified/20200210.131548 submit/tizen_5.5/20200210.014050
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 10 Feb 2020 02:19:54 +0000 (11:19 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 10 Feb 2020 02:19:54 +0000 (11:19 +0900)
The following patches are included:
1. Prevent albumart resize for performance
2. Fix exception handling
3. Use 'switch-case' instead 'if-else'
4. Improve record date exception handling

Change-Id: Ib309a6965b1475e582e923a57961a247c6e00bea
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/media-svc-util.c
src/common/media-svc.c

index 03524e7..be0d578 100644 (file)
@@ -437,19 +437,26 @@ static int __media_svc_get_media_type(const char *path, const char *mime_type, m
        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 (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;
+       switch (category) {
+       case MEDIA_SVC_CATEGORY_SOUND:
+               *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+               break;
+       case MEDIA_SVC_CATEGORY_MUSIC:
+               *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+               break;
+       case MEDIA_SVC_CATEGORY_IMAGE:
+               *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+               break;
+       case MEDIA_SVC_CATEGORY_VIDEO:
+               *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+               break;
+       default:
+               *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+       }
 
        return ret;
 }
@@ -486,7 +493,7 @@ static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
        }
        return false;
 }
-
+#if 0
 static int __media_svc_resize_artwork(const char *path, const char *img_format)
 {
        int ret = MS_MEDIA_ERR_NONE;
@@ -525,7 +532,7 @@ static int __media_svc_resize_artwork(const char *path, const char *img_format)
 
        return ret;
 }
-
+#endif
 static int __media_svc_safe_atoi(char *buffer, int *si)
 {
        char *end = NULL;
@@ -1156,23 +1163,10 @@ int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *conte
 
        mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
        if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
-               if (!isspace(*p)) {
-                       content_info->media_meta.title = g_strdup(p);
-               } else {
-                       int idx = 0;
+               while(p && isspace(*p))
+                       p++;
 
-                       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);
-                                       content_info->media_meta.title = g_strdup(p);
-                                       break;
-                               }
-                       }
-               }
+               content_info->media_meta.title = g_strdup(p);
        }
 
        mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
@@ -1240,32 +1234,11 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc
 
                mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
                if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
-                       char mime_type[255] = {0, };
-                       ret = __media_svc_get_mime_type(content_info->path, mime_type);
-                       /*if 3gp that audio only, media_type is music */
-                       if ((ret == MS_MEDIA_ERR_NONE) &&
-                               ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
-                               /*Creation time format is 2013-01-01 00:00:00 +0000. change it to 2013:01:01 00:00:00 like exif time format*/
-                               char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
-                               char *p_value = p;
-                               char *time_value = time_info;
-                               if (time_info != NULL) {
-                                       while (*p_value != '\0') {
-                                               if (*p_value == '-')
-                                                       *time_value = ':';
-                                               else
-                                                       *time_value = *p_value;
-                                               time_value++;
-                                               p_value++;
-                                       }
-                                       content_info->media_meta.recorded_date = g_strdup(time_info);
-                                       SAFE_FREE(time_info);
-                               } else {
-                                       media_svc_error("memory allocation error");
-                               }
+                       if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
+                               /*Creation time format is 2013-01-01 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);
+                               SAFE_FREE(p_value);
                        } else {
                                content_info->media_meta.recorded_date = g_strdup(p);
                        }
@@ -1340,14 +1313,19 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc
                                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(content_info->media_type, thumb_path, content_info->path, p, uid);
-                                       if (ret != MS_MEDIA_ERR_NONE)
+                                       if (ret != MS_MEDIA_ERR_NONE) {
                                                media_svc_error("Fail to Get Thumbnail Path");
-
-                                       if (strlen(thumb_path) > 0) {
+                                       } 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);
+                                                       /* NOTICE : Prevent resize for performance (2020.02.07)
+                                                       *  In most cases, artwork's format is jpeg and size is under MEDIA_SVC_ARTWORK_SIZE * MEDIA_SVC_ARTWORK_SIZE.
+                                                       *  So, doing mm_util_extract_image_info to check image size is a time-consuming task.
+                                                       */
+#if 0
                                                        /* albumart resizing */
                                                        ret = __media_svc_resize_artwork(thumb_path, p);
                                                        if (ret != MS_MEDIA_ERR_NONE) {
@@ -1357,6 +1335,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc
                                                        } else {
                                                                content_info->thumbnail_path = g_strdup(thumb_path);
                                                        }
+#endif
                                                }
                                        }
                                }
@@ -1842,12 +1821,13 @@ int _media_svc_get_media_type(const char *path, int *mediatype)
 
 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
 {
-       if ((storage_type != MS_USER_STORAGE_INTERNAL)
-               && (storage_type != MS_USER_STORAGE_EXTERNAL)
-               && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
+       switch (storage_type) {
+       case MS_USER_STORAGE_INTERNAL:
+       case MS_USER_STORAGE_EXTERNAL:
+       case MS_USER_STORAGE_EXTERNAL_USB:
+               return true;
+       default:
                media_svc_error("storage type is incorrect[%d]", storage_type);
                return false;
        }
-
-       return true;
 }
index 0e2cc72..0f172ae 100755 (executable)
@@ -599,16 +599,21 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
        }
 
        content_info.media_type = noti_item->media_type;
+       content_info.mime_type = g_strdup(noti_item->mime_type);
 
-       if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
-       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
-       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
-       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
-               media_svc_debug("Do nothing [%d]", content_info.media_type);
-       else if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+       switch (content_info.media_type) {
+       case MEDIA_SVC_MEDIA_TYPE_IMAGE:
                ret = _media_svc_extract_image_metadata(&content_info);
-       else
+               break;
+       case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+       case MEDIA_SVC_MEDIA_TYPE_SOUND:
+       case MEDIA_SVC_MEDIA_TYPE_MUSIC:
                ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
+               break;
+       default:
+               media_svc_debug("Do nothing[%d]", content_info.media_type);
+               break;
+       }
 
        if (ret != MS_MEDIA_ERR_NONE) {
                _media_svc_destroy_noti_item(noti_item);