diff options
author | hj kim <backto.kim@samsung.com> | 2020-03-06 13:21:38 +0900 |
---|---|---|
committer | hj kim <backto.kim@samsung.com> | 2020-03-13 15:52:23 +0900 |
commit | 7987cc930a4af11c432f21de47b826332590d8ca (patch) | |
tree | 8549122c919b9ab84dea6ea2117d10e8cc9e5c98 /src/media-thumb-internal.c | |
parent | 07702e87ee405bff94c3d66aa84f6424f5865dc4 (diff) | |
download | libmedia-thumbnail-7987cc930a4af11c432f21de47b826332590d8ca.tar.gz libmedia-thumbnail-7987cc930a4af11c432f21de47b826332590d8ca.tar.bz2 libmedia-thumbnail-7987cc930a4af11c432f21de47b826332590d8ca.zip |
Create New APIs for Creating Video Thumbnail
To unify duplicated thumbnail extracting codes in libmedia-service, libmedia-thumbnail and thumbnail-util
Change-Id: I1d9fd61349fe02086240db07e3b22a058518c65e
Diffstat (limited to 'src/media-thumb-internal.c')
-rwxr-xr-x | src/media-thumb-internal.c | 229 |
1 files changed, 0 insertions, 229 deletions
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index aa7e6aa..bd6ff2d 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -28,8 +28,6 @@ #include <sys/types.h> #include <fcntl.h> #include <unistd.h> - -#include <mm_file.h> #include <mm_util_magick.h> static void __media_thumb_get_proper_thumb_size(unsigned int origin_width, unsigned int origin_height, unsigned int *thumb_width, unsigned int *thumb_height) @@ -123,233 +121,6 @@ int _media_thumb_image(const char *origin_path, char *thumb_path, unsigned int t return err; } -static void __get_rotation_and_cdis(const char *origin_path, mm_util_magick_rotate_type *rot_type, int *cdis_value) -{ - int err = MS_MEDIA_ERR_NONE; - MMHandleType tag = (MMHandleType) NULL; - char *p = NULL; - int size = 0; - int _cdis_value = 0; - mm_util_magick_rotate_type _rot_type = MM_UTIL_ROTATE_NUM; - - /* Get Content Tag attribute for orientation */ - err = mm_file_create_tag_attrs(&tag, origin_path); - if (err != FILEINFO_ERROR_NONE) { - *rot_type = MM_UTIL_ROTATE_0; - *cdis_value = 0; - return; - } - - err = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL); - if (err == FILEINFO_ERROR_NONE && size >= 0) { - if (p == NULL) { - _rot_type = MM_UTIL_ROTATE_0; - } else { - if (strncmp(p, "90", size) == 0) - _rot_type = MM_UTIL_ROTATE_90; - else if (strncmp(p, "180", size) == 0) - _rot_type = MM_UTIL_ROTATE_180; - else if (strncmp(p, "270", size) == 0) - _rot_type = MM_UTIL_ROTATE_270; - else - _rot_type = MM_UTIL_ROTATE_0; - } - thumb_dbg("There is tag rotate : %d", _rot_type); - } else { - thumb_dbg("There is NOT tag rotate"); - _rot_type = MM_UTIL_ROTATE_0; - } - - err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL); - if (err != FILEINFO_ERROR_NONE) - _cdis_value = 0; - - *rot_type = _rot_type; - *cdis_value = _cdis_value; - - err = mm_file_destroy_tag_attrs(tag); - if (err != FILEINFO_ERROR_NONE) { - thumb_err("fail to free tag attr - err(%x)", err); - } - - return; -} - -static int __get_video_info(int cdis_value, const char *origin_path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *size) -{ - int err = MS_MEDIA_ERR_NONE; - MMHandleType content = (MMHandleType) NULL; - int _video_track_num = 0; - int _width = 0; - int _height = 0; - size_t _size = 0; - void *_frame = NULL; - - if (cdis_value == 1) { - thumb_warn("This is CDIS vlaue 1"); - err = mm_file_create_content_attrs_safe(&content, origin_path); - } else { - err = mm_file_create_content_attrs(&content, origin_path); - } - - if (err != FILEINFO_ERROR_NONE) { - thumb_err("mm_file_create_content_attrs fails : %d", err); - return MS_MEDIA_ERR_INTERNAL; - } - - err = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num, NULL); - if (err != FILEINFO_ERROR_NONE) { - thumb_err("mm_file_get_attrs fails : %d", err); - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - *video_track_num = _video_track_num; - - if (_video_track_num == 0) { - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_NONE; - } - - err = mm_file_get_attrs(content, - MM_FILE_CONTENT_VIDEO_WIDTH, - &_width, - MM_FILE_CONTENT_VIDEO_HEIGHT, - &_height, - MM_FILE_CONTENT_VIDEO_THUMBNAIL, &_frame, /* raw image is RGB888 format */ - &_size, NULL); - - if (err != FILEINFO_ERROR_NONE) { - thumb_err("mm_file_get_attrs fails : %d", err); - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - thumb_dbg("W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _size, _frame); - if (!_frame || !_width || !_height) { - mm_file_destroy_content_attrs(content); - return MS_MEDIA_ERR_INTERNAL; - } - - - *width = _width; - *height = _height; - *size = _size; - *frame = calloc(1, _size); - memcpy(*frame, _frame, _size); - - mm_file_destroy_content_attrs(content); - - return MS_MEDIA_ERR_NONE; -} - -static int __get_video_thumb(int width, int height, void *frame, size_t size, mm_util_magick_rotate_type rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height, mm_util_image_h *dst_img) -{ - int err = MS_MEDIA_ERR_NONE; - mm_util_image_h img = NULL; - mm_util_image_h resize_img = NULL; - - __media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height); - if (thumb_width <= 0 || thumb_height <= 0) { - thumb_err("Failed to get thumb size"); - return MS_MEDIA_ERR_INTERNAL; - } - - thumb_dbg("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height); - - err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img); - thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err); - - if (width > thumb_width || height > thumb_height) { - if (rot_type != MM_UTIL_ROTATE_0) { - if (STRING_VALID(thumb_path)) { - err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img); - if (err != MM_UTIL_ERROR_NONE) - goto ERROR; - - err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path); - - } else { - err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img); - if (err != MM_UTIL_ERROR_NONE) - goto ERROR; - - err = mm_util_rotate_B_B(resize_img, rot_type, dst_img); - } - } else { - if (STRING_VALID(thumb_path)) - err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path); - else - err = mm_util_resize_B_B(img, thumb_width, thumb_height, dst_img); - } - } else { - if (rot_type != MM_UTIL_ROTATE_0) { - if (STRING_VALID(thumb_path)) { - err = mm_util_rotate_B_P(img, rot_type, thumb_path); - } else { - err = mm_util_rotate_B_B(img, rot_type, dst_img); - } - } else { - if (STRING_VALID(thumb_path)) { - err = mm_util_resize_B_P(img, width, height, thumb_path); - } else { - err = mm_image_clone_image(img, dst_img); - } - } - } - -ERROR: - mm_image_destroy_image(img); - mm_image_destroy_image(resize_img); - if (err != MS_MEDIA_ERR_NONE) - return MS_MEDIA_ERR_INTERNAL; - - return MS_MEDIA_ERR_NONE; -} - -int _media_thumb_video(const char *origin_path, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height, media_thumb_info *thumb_info) -{ - int err = MS_MEDIA_ERR_NONE; - int cdis_value = 0; - void *frame = NULL; - int video_track_num = 0; - unsigned int width = 0; - unsigned int height = 0; - mm_util_image_h dst_img = NULL; - unsigned char *buf = NULL; - size_t size = 0; - mm_util_color_format_e format = MM_UTIL_COLOR_NUM; - mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM; - - __get_rotation_and_cdis(origin_path, &rot_type, &cdis_value); - err = __get_video_info(cdis_value, origin_path, &video_track_num, &width, &height, &frame, &size); - thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_video_info [%d]", err); - thumb_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track"); - - if (STRING_VALID(thumb_path)) { - err = __get_video_thumb(width, height, frame, size, rot_type, thumb_path, thumb_width, thumb_height, NULL); - - } else if (thumb_info) { - err = __get_video_thumb(width, height, frame, size, rot_type, NULL, thumb_width, thumb_height, &dst_img); - if (err == MS_MEDIA_ERR_NONE) { - err = mm_image_get_image(dst_img, &width, &height, &format, &buf, &size); - thumb_info->data = buf; - thumb_info->size = size; - thumb_info->width = width; - thumb_info->height = height; - } - - mm_image_destroy_image(dst_img); - } else { - thumb_err("Invalid parameter"); - err = MS_MEDIA_ERR_INVALID_PARAMETER; - } - - SAFE_FREE(frame); - - return err; -} - int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid) { char *hash_name = NULL; |