[0.6.173] Change to convert and rotate image with mm_util_image_h 11/201411/4 accepted/tizen/unified/20190318.221233 submit/tizen/20190313.075153
authorjiyong.min <jiyong.min@samsung.com>
Thu, 14 Mar 2019 00:36:14 +0000 (09:36 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 14 Mar 2019 04:47:23 +0000 (13:47 +0900)
- Changed function
 : mm_util_convert_image(), mm_util_rotate_image()
- These functions convert & rotate mm_util_image_h image with format & rotation,
  it will return allocated mm_util_image_h image.
  before changing, it has too few parameter to check problem
  like buffer overflow.
  So, change parameter to mm_util_image_h with mandotory information.

Change-Id: If958b352ef62ed8bedafd8234b05ef24152421ce

configure.ac
packaging/libmm-player.spec
src/Makefile.am
src/mm_player_capture.c

index 4642268..b9f99c4 100644 (file)
@@ -80,6 +80,10 @@ AC_SUBST(TZPLATFORM_CONFIG_CFLAGS)
 AC_SUBST(TZPLATFORM_CONFIG_LIBS)
 
 # for testsuite
+PKG_CHECK_MODULES(MMUTIL, mmutil-common)
+AC_SUBST(MMUTIL_COMMON_CFLAGS)
+AC_SUBST(MMUTIL_COMMON_LIBS)
+
 PKG_CHECK_MODULES(MMUTIL, mmutil-imgp)
 AC_SUBST(MMUTIL_CFLAGS)
 AC_SUBST(MMUTIL_LIBS)
index e80c2cc..bef7041 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.172
+Version:    0.6.173
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
@@ -16,6 +16,7 @@ BuildRequires:  pkgconfig(gstreamer-1.0)
 BuildRequires:  pkgconfig(gstreamer-plugins-base-1.0)
 BuildRequires:  pkgconfig(gstreamer-video-1.0)
 BuildRequires:  pkgconfig(gstreamer-app-1.0)
+BuildRequires:  pkgconfig(mmutil-common)
 BuildRequires:  pkgconfig(mmutil-imgp)
 BuildRequires:  pkgconfig(iniparser)
 BuildRequires:  pkgconfig(icu-i18n)
index 04cd36b..e3b0705 100644 (file)
@@ -21,6 +21,7 @@ libmmfplayer_la_SOURCES = mm_player.c \
 
 libmmfplayer_la_CFLAGS =  -I$(srcdir)/include \
                        $(MMCOMMON_CFLAGS) \
+                       $(MMUTIL_COMMON_CFLAGS) \
                        $(MMUTIL_CFLAGS) \
                        $(GST_CFLAGS) \
                        $(GST_VIDEO_CFLAGS) \
@@ -52,6 +53,7 @@ noinst_HEADERS = include/mm_player_utils.h \
 
 libmmfplayer_la_LIBADD = $(GST_LIBS) \
                $(MMCOMMON_LIBS) \
+               $(MMUTIL_COMMON_LIBS) \
                $(MMUTIL_LIBS) \
                $(GST_INTERFACE_LIBS) \
                $(GST_VIDEO_LIBS) \
index 64fae89..44f6e0b 100644 (file)
@@ -30,6 +30,7 @@
 #include "mm_player_capture.h"
 #include "mm_player_priv.h"
 
+#include <mm_util_image.h>
 #include <mm_util_imgp.h>
 #include <gst/video/video-info.h>
 
@@ -46,7 +47,7 @@ static int  __mmplayer_get_video_frame_from_buffer(mm_player_t *player, GstPad *
 static gpointer __mmplayer_capture_thread(gpointer data);
 static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src, int yuv420_width, int yuv420_height, int left, int top, int right, int buttom);
 static int __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos);
-static int __mm_player_convert_colorspace(mm_player_t *player, unsigned char *src_data, mm_util_color_format_e src_fmt, unsigned int src_w, unsigned int src_h, mm_util_color_format_e dst_fmt);
+static int __mm_player_convert_colorspace(mm_player_t *player, unsigned char *src_data, size_t src_size, mm_util_color_format_e src_fmt, unsigned int src_w, unsigned int src_h, mm_util_color_format_e dst_fmt);
 static int __mm_player_convert_NV12_tiled(mm_player_t *player);
 static int __mm_player_convert_NV12(mm_player_t *player);
 static int __mm_player_convert_I420(mm_player_t *player);
@@ -183,32 +184,20 @@ __mmplayer_handle_orientation(mm_player_t *player, int orientation, int format)
 {
        unsigned char *src_buffer = NULL;
        int ret = MM_ERROR_NONE;
-       unsigned char *dst_frame = NULL;
-       unsigned int dst_width = 0;
-       unsigned int dst_height = 0;
+       mm_util_image_h src_image = NULL;
+       mm_util_image_h dst_image = NULL;
        size_t dst_size = 0;
        mm_util_img_rotate_type rot_enum = MM_UTIL_ROTATE_NUM;
 
        player->capture.orientation = orientation;
 
-       if (orientation == 90 || orientation == 270) {
-               dst_width = player->captured.height[0];
-               dst_height = player->captured.width[0];
-               LOGD("interchange width & height");
-       } else if (orientation == 180) {
-               dst_width = player->captured.width[0];
-               dst_height = player->captured.height[0];
-       } else if (orientation == 0) {
+       if (orientation == 0) {
                LOGE("no need handle orientation : %d", orientation);
                player->capture.width = player->captured.width[0];
                player->capture.height = player->captured.height[0];
                return MM_ERROR_NONE;
-       } else {
-               LOGE("wrong orientation value...");
        }
 
-       /* height & width will be interchanged for 90 and 270 orientation */
-       LOGD("before rotation : dst_width = %d and dst_height = %d", dst_width, dst_height);
        src_buffer = (unsigned char *)player->capture.data;
 
        /* convert orientation degree into enum here */
@@ -229,27 +218,35 @@ __mmplayer_handle_orientation(mm_player_t *player, int orientation, int format)
 
        LOGD("source buffer for rotation = %p and rotation = %d", src_buffer, rot_enum);
 
-       ret = mm_util_rotate_image(src_buffer,
-                       player->captured.width[0], player->captured.height[0], format, rot_enum,
-                       &dst_frame, &dst_width, &dst_height, &dst_size);
-       if (ret != MM_ERROR_NONE || !dst_frame) {
-               LOGE("failed to do rotate image");
-               free(dst_frame);
+       ret = mm_image_create_image(player->captured.width[0], player->captured.height[0], format, src_buffer, (size_t)player->capture.size, &src_image);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("failed to create image");
+               return ret;
+       }
+
+       ret = mm_util_rotate_image(src_image, rot_enum, &dst_image);
+       mm_image_destroy_image(src_image);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("failed to rotate image");
                return ret;
        }
 
-       LOGD("after rotation same stride: dst_width = %d and dst_height = %d, dst_size = %zu", dst_width, dst_height, dst_size);
+       mm_image_debug_image(dst_image, NULL);
+
+       ret = mm_image_get_image(dst_image, &player->capture.width, &player->capture.height, NULL, &player->capture.data, &dst_size);
+       mm_image_destroy_image(dst_image);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("failed to get image");
+               return ret;
+       }
 
        free(src_buffer);
 
-       player->capture.data = dst_frame;
        player->capture.size = (int)dst_size;
        player->capture.orientation = orientation;
-       player->capture.width = dst_width;
-       player->capture.height = dst_height;
 
-       player->captured.width[0] = player->captured.stride_width[0] = dst_width;
-       player->captured.height[0] = player->captured.stride_height[0] = dst_height;
+       player->captured.width[0] = player->captured.stride_width[0] = player->capture.width;
+       player->captured.height[0] = player->captured.stride_height[0] = player->capture.height;
 
        return ret;
 }
@@ -473,27 +470,38 @@ __mmplayer_video_capture_probe(GstPad *pad, GstPadProbeInfo *info, gpointer u_da
 }
 
 static int
-__mm_player_convert_colorspace(mm_player_t *player, unsigned char *src_data, mm_util_color_format_e src_fmt, unsigned int src_w, unsigned int src_h, mm_util_color_format_e dst_fmt)
+__mm_player_convert_colorspace(mm_player_t *player, unsigned char *src_data, size_t src_size, mm_util_color_format_e src_fmt, unsigned int src_w, unsigned int src_h, mm_util_color_format_e dst_fmt)
 {
-       unsigned char *dst_data = NULL;
-       unsigned int dst_width = 0;
-       unsigned int dst_height = 0;
-       size_t dst_size = 0;
        int ret = MM_ERROR_NONE;
+       mm_util_image_h src_image = NULL;
+       mm_util_image_h dst_image = NULL;
+       size_t size = 0;
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_INTERNAL);
        SECURE_LOGD("src size info. width: %d, height: %d", src_w, src_h);
 
-       ret = mm_util_convert_colorspace(src_data, src_w, src_h, src_fmt, dst_fmt, &dst_data, &dst_width, &dst_height, &dst_size);
-       if (ret != MM_ERROR_NONE || !dst_data) {
+       ret = mm_image_create_image(src_w, src_h, src_fmt, src_data, src_size, &src_image);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("failed to create image for capture, %d", ret);
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
+       ret = mm_util_convert_colorspace(src_image, dst_fmt, &dst_image);
+       mm_image_destroy_image(src_image);
+       if (ret != MM_ERROR_NONE) {
                LOGE("failed to convert for capture, %d", ret);
-               free(dst_data);
                return MM_ERROR_PLAYER_INTERNAL;
        }
-       SECURE_LOGD("dst size info. width: %d, height: %d, size: %zu", dst_width, dst_height, dst_size);
+       mm_image_debug_image(dst_image, NULL);
 
-       player->capture.size = (int)dst_size;
-       player->capture.data = dst_data;
+       ret = mm_image_get_image(dst_image, NULL, NULL, NULL, &player->capture.data, &size);
+       mm_image_destroy_image(dst_image);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("failed to get image for capture, %d", ret);
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
+       player->capture.size = (int)size;
 
        return MM_ERROR_NONE;
 }
@@ -815,8 +823,8 @@ __mm_player_convert_NV12_tiled(mm_player_t *player)
        memcpy(src_buffer + linear_y_plane_size, linear_uv_plane, linear_uv_plane_size);
 
        /* NV12 linear to RGB888 */
-       ret = __mm_player_convert_colorspace(player, src_buffer, MM_UTIL_COLOR_NV12,
-               width, height, MM_UTIL_COLOR_RGB24);
+       ret = __mm_player_convert_colorspace(player, src_buffer, (size_t)(linear_y_plane_size + linear_uv_plane_size),
+               MM_UTIL_COLOR_NV12, width, height, MM_UTIL_COLOR_RGB24);
 
        MMPLAYER_FREEIF(src_buffer);
        MMPLAYER_FREEIF(linear_y_plane);
@@ -870,7 +878,7 @@ __mm_player_convert_NV12(mm_player_t *player)
        }
 
        /* NV12 -> RGB888 */
-       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer,
+       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer, (size_t)src_buffer_size,
                        MM_UTIL_COLOR_NV12, player->captured.width[0],
                        player->captured.height[0], MM_UTIL_COLOR_RGB24);
 
@@ -936,8 +944,8 @@ __mm_player_convert_I420(mm_player_t *player)
        }
 
        /* I420 -> RGB888 */
-       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer, MM_UTIL_COLOR_I420,
-                       player->captured.width[0], player->captured.height[0], MM_UTIL_COLOR_RGB24);
+       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer, (size_t)(planes[0] + planes[1] + planes[2]),
+                       MM_UTIL_COLOR_I420, player->captured.width[0], player->captured.height[0], MM_UTIL_COLOR_RGB24);
 
 #ifdef CAPTURE_OUTPUT_DUMP
        capture_output_dump(player);
@@ -968,7 +976,7 @@ __mm_player_convert_BGRx(mm_player_t *player)
        memcpy(src_buffer, player->captured.data[0], size);
 
        /* BGRx -> RGB888 */
-       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer, MM_UTIL_COLOR_BGRX,
+       ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer, (size_t)size, MM_UTIL_COLOR_BGRX,
                        player->captured.width[0], player->captured.height[0], MM_UTIL_COLOR_RGB24);
 
 #ifdef CAPTURE_OUTPUT_DUMP