summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2018-01-25 09:57:30 +0900
committerMinje Ahn <minje.ahn@samsung.com>2018-01-31 14:58:04 +0900
commit6fd9ba41fd0ee715c77f37f0211435f8e44562bc (patch)
treec2b3f07600af5e7d3e68e9ba2eb5ab5374c19eaf
parenteecae1bb5a57f33fc65c203afc8024266f03356d (diff)
downloadlibmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.tar.gz
libmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.tar.bz2
libmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.zip
Modify video thumbnail process
Change-Id: Iddde97e813d5d5ea1d67524cf1063561d65f7c91 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--packaging/libmedia-thumbnail.spec1
-rwxr-xr-xserver/thumb-server-internal.c8
-rwxr-xr-xsrc/include/media-thumb-internal.h2
-rwxr-xr-xsrc/include/util/media-thumb-util.h2
-rwxr-xr-xsrc/media-thumb-internal.c172
-rwxr-xr-xtest/test-thumb.c85
7 files changed, 113 insertions, 159 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 821871a..2c95a0a 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,7 +38,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/codec ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/ipc ${CMAKE_SOURCE_DIR}/server/include ${CMAKE_SOURCE_DIR}/md5)
INCLUDE(FindPkgConfig)
- pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul libexif ecore-evas evas capi-media-image-util libmedia-utils libtzplatform-config db-util)
+ pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul libexif ecore-evas evas capi-media-image-util libmedia-utils libtzplatform-config db-util mmutil-magick)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index 4515507..448123e 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -22,6 +22,7 @@ BuildRequires: pkgconfig(libmedia-utils)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(mmutil-magick)
%description
Description: Media thumbnail service library for multimedia applications
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 1b8bac3..2c84120 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -288,8 +288,8 @@ int _thumbnail_get_data(const char *origin_path,
err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, &thumb_info);
thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, &thumb_info);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INTERNAL, "_media_thumb_video failed");
} else {
thumb_err("invalid file type");
return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
@@ -334,8 +334,8 @@ int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, un
err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, &thumb_info);
thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_width, thumb_height, &thumb_info);
- thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ err = _media_thumb_video(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INTERNAL, "_media_thumb_video failed");
} else {
thumb_err("invalid file type");
return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index 43d9b41..94f9e8f 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -65,7 +65,7 @@ typedef struct {
} thumbRawUserData;
int _media_thumb_image(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
-int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
+int _media_thumb_video(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
int _media_thumb_save_to_file_with_evas(unsigned char *data, int w, int h, int alpha, char *thumb_path);
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
index c71d6a3..a166bcb 100755
--- a/src/include/util/media-thumb-util.h
+++ b/src/include/util/media-thumb-util.h
@@ -25,6 +25,8 @@
#define _MEDIA_THUMB_UTIL_H_
#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
+#define STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define THUMB_MALLOC(src, size) { if (size <= 0) {src = NULL; } \
else { src = malloc(size); if (src) memset(src, 0x0, size); } }
#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index e77a6a2..b0069d4 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -42,6 +42,8 @@
#include <Ecore_Evas.h>
#include <libexif/exif-data.h>
+#include <mm_util_magick.h>
+
#define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
static int __media_thumb_get_buffer_size(image_util_colorspace_e format, unsigned int width, unsigned int height, unsigned int *imgsize)
@@ -1018,45 +1020,55 @@ int _media_thumb_image(const char *origin_path, const char *thumb_path, int thum
return err;
}
-int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
+int _media_thumb_video(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
MMHandleType content = (MMHandleType) NULL;
+ MMHandleType tag = (MMHandleType) NULL;
+
+ char *p = NULL;
+ int cdis_value = 0;
void *frame = NULL;
int video_track_num = 0;
char *err_msg = NULL;
int size = 0;
int width = 0;
int height = 0;
+ mm_util_image_h img = NULL;
+ mm_util_image_h resize_img = NULL;
+ mm_util_image_h dst_img = NULL;
- /* Get Content Tag attribute for orientatin */
- MMHandleType tag = (MMHandleType) NULL;
- char *p = NULL;
- int cdis_value = 0;
+ unsigned char *res_buf = NULL;
+ size_t res_size = 0;
+ unsigned int res_width = 0;
+ unsigned int res_height = 0;
+ mm_util_magick_format res_format;
+
+ /* Get Content Tag attribute for orientation */
err = mm_file_create_tag_attrs(&tag, origin_path);
- image_util_rotation_e rot_type = IMAGE_UTIL_ROTATION_NONE;
+ mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
if (err == FILEINFO_ERROR_NONE) {
err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
if (err == FILEINFO_ERROR_NONE && size >= 0) {
if (p == NULL) {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
} else {
if (strncmp(p, "90", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_90;
+ rot_type = MM_UTIL_ROTATE_90;
} else if (strncmp(p, "180", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_180;
+ rot_type = MM_UTIL_ROTATE_180;
} else if (strncmp(p, "270", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_270;
+ rot_type = MM_UTIL_ROTATE_270;
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ 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 = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
SAFE_FREE(err_msg);
}
@@ -1067,7 +1079,7 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
}
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
cdis_value = 0;
}
@@ -1092,8 +1104,7 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
if (video_track_num > 0) {
@@ -1108,76 +1119,99 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_dbg("video width: %d", width);
- thumb_dbg("video height: %d", height);
- thumb_dbg("thumbnail size: %d", size);
- thumb_dbg("frame: %p", frame);
- thumb_dbg("orientation: %d", rot_type);
-
+ thumb_dbg("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", width, height, size, frame, rot_type);
if (frame == NULL || width == 0 || height == 0) {
thumb_err("Failed to get frame data");
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_info->origin_width = width;
- thumb_info->origin_height = height;
+ thumb_info->is_saved = true;
err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
-
- unsigned int new_size = 0;
- unsigned char *new_frame = NULL;
- err = _media_thumb_rgb_to_argb(frame, size, &new_frame, &new_size, width, height);
- if ((err != MS_MEDIA_ERR_NONE) || (new_frame == NULL)) {
- thumb_err("_media_thumb_convert_video falied: %d", err);
- mm_file_destroy_content_attrs(content);
- SAFE_FREE(new_frame);
- return err;
+ if (thumb_width <= 0 || thumb_height <= 0) {
+ thumb_err("Failed to get thumb size");
+ goto ERROR;
}
- mm_file_destroy_content_attrs(content);
- thumb_dbg("original size - width:%d, height:%d", width, height);
- thumb_dbg("proper thumb size - width:%d, height:%d", thumb_width, thumb_height);
+ thumb_dbg("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
+
+ err = mm_util_create_handle(&img, (unsigned char *)frame, width, height, size, MM_UTIL_IMG_FMT_RGB888);
if (width > thumb_width || height > thumb_height) {
- err = _media_thumb_resize_with_evas(new_frame, thumb_width, thumb_height, thumb_info);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_resize_video_with_evas falied: %d", err);
- SAFE_FREE(new_frame);
- return err;
+ 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);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } 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, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(resize_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
}
} else {
- thumb_info->size = new_size;
- thumb_info->width = width;
- thumb_info->height = height;
- thumb_info->data = malloc(new_size);
- if (thumb_info->data == NULL) {
- thumb_err("memory allcation failed");
- SAFE_FREE(new_frame);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- memcpy(thumb_info->data, new_frame, new_size);
- }
- SAFE_FREE(new_frame);
-
- if (rot_type == IMAGE_UTIL_ROTATION_90 || rot_type == IMAGE_UTIL_ROTATION_180 || rot_type == IMAGE_UTIL_ROTATION_270) {
- err = _media_thumb_rotate_thumb(thumb_info->data, thumb_info->size, &(thumb_info->width), &(thumb_info->height), rot_type, IMAGE_UTIL_COLORSPACE_BGRA8888);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_rotate_thumb falied: %d", err);
- SAFE_FREE(thumb_info->data);
- return err;
+ 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);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } else {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_P(img, width, height, thumb_path);
+ } else {
+ thumb_info->data = calloc(1, size);
+ memcpy(thumb_info->data, frame, size);
+ thumb_info->size = size;
+ thumb_info->width = width;
+ thumb_info->height = height;
+ }
}
}
- } else {
- thumb_dbg("no contents information");
- frame = NULL;
- mm_file_destroy_content_attrs(content);
-
- return MS_MEDIA_ERR_INTERNAL;
}
+ERROR:
+ mm_util_destroy_handle(img);
+ mm_util_destroy_handle(resize_img);
+ mm_util_destroy_handle(dst_img);
+ mm_file_destroy_content_attrs(content);
+
return err;
}
diff --git a/test/test-thumb.c b/test/test-thumb.c
index 47e2903..ac9e638 100755
--- a/test/test-thumb.c
+++ b/test/test-thumb.c
@@ -23,8 +23,6 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
-#include <Evas.h>
-#include <Ecore_Evas.h>
#include "media-thumbnail.h"
#include "thumb-server-internal.h"
@@ -32,61 +30,6 @@
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"
-int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
-{
- ecore_evas_init();
-
- Ecore_Evas *ee =
- ecore_evas_buffer_new(w, h);
- Evas *evas = ecore_evas_get(ee);
-
- Evas_Object *img = NULL;
- img = evas_object_image_add(evas);
-
- if (img == NULL) {
- printf("image object is NULL\n");
- ecore_evas_free(ee);
- ecore_evas_shutdown();
- return -1;
- }
-
- evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_size_set(img, w, h);
- evas_object_image_fill_set(img, 0, 0, w, h);
-
- if (!is_bgra) {
- unsigned char *m = NULL;
- m = evas_object_image_data_get(img, 1);
- /* Use self-logic to convert from RGB888 to RGBA */
- int i = 0, j;
- for (j = 0; j < w * 3 * h;
- j += 3) {
- m[i++] = (data[j + 2]);
- m[i++] = (data[j + 1]);
- m[i++] = (data[j]);
- m[i++] = 0x0;
- }
-
- evas_object_image_data_set(img, m);
- evas_object_image_data_update_add(img, 0, 0, w, h);
- } else {
- evas_object_image_data_set(img, data);
- evas_object_image_data_update_add(img, 0, 0, w, h);
- }
-
- if (evas_object_image_save
- (img, "/mnt/nfs/test.jpg", NULL,
- "quality=50 compress=2")) {
- printf("evas_object_image_save success\n");
- } else {
- printf("evas_object_image_save failed\n");
- }
-
- ecore_evas_shutdown();
-
- return 0;
-}
-
int main(int argc, char *argv[])
{
int mode;
@@ -105,42 +48,16 @@ int main(int argc, char *argv[])
if (origin_path && (mode == 1)) {
printf("Test _thumbnail_get_data\n");
#if 0
- unsigned char *data = NULL;
- int thumb_size = 0;
- int thumb_w = 0;
- int thumb_h = 0;
- int origin_w = 0;
- int origin_h = 0;
- int alpha = FALSE;
- bool is_saved = FALSE;
char *thumb_path = "thumbnail_path.jpg";
- int is_bgra = 1;
- //int is_bgra = 0;
-
//long start = thumb_get_debug_time();
- err = _thumbnail_get_data(origin_path, thumb_path, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, &is_saved);
+ err = _thumbnail_get_data(origin_path, thumb_path);
if (err < 0) {
printf("_thumbnail_get_data failed - %d\n", err);
return -1;
}
- printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);
- printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
-
- if (is_saved == FALSE) {
- err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
- if (err < 0) {
- printf("save_to_file_with_evas failed - %d\n", err);
- return -1;
- } else {
- printf("file save success\n");
- }
- }
-
- SAFE_FREE(data);
-
//long end = thumb_get_debug_time();
//printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
#endif