summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilbok Lee <gilbok.lee@samsung.com>2018-11-06 15:52:43 +0900
committerGilbok Lee <gilbok.lee@samsung.com>2018-11-08 11:51:22 +0900
commitb8e649a1ab3a5453ceaae4d243cb16978d784974 (patch)
tree1636d3fb91edd17d6c30a7d830bcc0d4ddd14c35
parent20faab669b8da03a2d43acc90f1a5dce13f1a30b (diff)
downloadlibmm-player-b8e649a1ab3a5453ceaae4d243cb16978d784974.tar.gz
libmm-player-b8e649a1ab3a5453ceaae4d243cb16978d784974.tar.bz2
libmm-player-b8e649a1ab3a5453ceaae4d243cb16978d784974.zip
[0.6.142] resolve complexity issue
- resolve the cyclomatic complexity issue of below function __mmplayer_capture_thread Change-Id: I6e4cfc8c243bd2f4b211a27a69f7e993b18fcfaf
-rw-r--r--packaging/libmm-player.spec2
-rwxr-xr-xsrc/mm_player_capture.c391
2 files changed, 219 insertions, 174 deletions
diff --git a/packaging/libmm-player.spec b/packaging/libmm-player.spec
index c044836..06bfb79 100644
--- a/packaging/libmm-player.spec
+++ b/packaging/libmm-player.spec
@@ -1,6 +1,6 @@
Name: libmm-player
Summary: Multimedia Framework Player Library
-Version: 0.6.141
+Version: 0.6.142
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0
diff --git a/src/mm_player_capture.c b/src/mm_player_capture.c
index dc8ba6c..37cdd0f 100755
--- a/src/mm_player_capture.c
+++ b/src/mm_player_capture.c
@@ -47,6 +47,9 @@ 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_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);
#ifdef CAPTURE_OUTPUT_DUMP
static void capture_output_dump(mm_player_t* player);
#endif
@@ -267,18 +270,12 @@ __mmplayer_handle_orientation(mm_player_t* player, int orientation, int format)
static gpointer
__mmplayer_capture_thread(gpointer data)
{
- mm_player_t* player = (mm_player_t*) data;
+ mm_player_t *player = (mm_player_t *) data;
MMMessageParamType msg = {0, };
- unsigned char * src_buffer = NULL;
- unsigned char * linear_y_plane = NULL;
- unsigned char * linear_uv_plane = NULL;
int orientation = 0;
int display_angle = 0;
int ret = 0;
- int planes[MAX_BUFFER_PLANE] = {0, };
- unsigned char * p_buf = NULL;
- unsigned char * temp = NULL;
- int i, j;
+ int i;
MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL);
@@ -298,165 +295,23 @@ __mmplayer_capture_thread(gpointer data)
*/
if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED) {
/* Colorspace conversion : NV12T-> NV12-> RGB888 */
- int ret = 0;
- int linear_y_plane_size;
- int linear_uv_plane_size;
- int width = player->captured.width[0];
- int height = player->captured.height[0];
-
- linear_y_plane_size = (width * height);
- linear_uv_plane_size = (width * height / 2);
-
- linear_y_plane = (unsigned char*) g_try_malloc(linear_y_plane_size);
- if (linear_y_plane == NULL) {
- msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
- goto ERROR;
- }
-
- linear_uv_plane = (unsigned char*) g_try_malloc(linear_uv_plane_size);
- if (linear_uv_plane == NULL) {
- msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
- goto ERROR;
- }
- /* NV12 tiled to linear */
- __csc_tiled_to_linear_crop(linear_y_plane,
- player->captured.data[0], width, height, 0, 0, 0, 0);
- __csc_tiled_to_linear_crop(linear_uv_plane,
- player->captured.data[1], width, height / 2, 0, 0, 0, 0);
-
- for (i = 0; i < player->captured.handle_num; i++) {
- MMPLAYER_FREEIF(player->captured.data[i]);
- }
-
- src_buffer = (unsigned char*) g_try_malloc(linear_y_plane_size+linear_uv_plane_size);
-
- if (src_buffer == NULL) {
- msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
- goto ERROR;
- }
- memset(src_buffer, 0x00, linear_y_plane_size+linear_uv_plane_size);
- memcpy(src_buffer, linear_y_plane, linear_y_plane_size);
- 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_NV12_tiled(player);
if (ret != MM_ERROR_NONE) {
- LOGE("failed to convert nv12 linear");
- goto ERROR;
- }
- /* clean */
- MMPLAYER_FREEIF(src_buffer);
- MMPLAYER_FREEIF(linear_y_plane);
- MMPLAYER_FREEIF(linear_uv_plane);
- } else if (MM_PLAYER_COLORSPACE_NV12 == player->video_cs) {
- int ret = 0;
- /* using original width otherwises, app can't know aligned to resize */
- planes[0] = player->captured.stride_width[0] * player->captured.stride_height[0];
- planes[1] = player->captured.stride_width[1] * player->captured.stride_height[1];
- int src_buffer_size = planes[0] + planes[1];
- src_buffer = (unsigned char*) g_try_malloc(src_buffer_size);
- p_buf = src_buffer;
-
- if (!src_buffer_size) {
- LOGE("invalid data size");
+ msg.code = ret;
goto ERROR;
}
-
- if (!src_buffer) {
- msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
- goto ERROR;
- }
-
- memset(src_buffer, 0x00, src_buffer_size);
-
- temp = player->captured.data[0];
-
- /* set Y plane */
- for (i = 0; i < player->captured.height[0]; i++) {
- memcpy(p_buf, temp, player->captured.width[0]);
- p_buf += player->captured.width[0];
- temp += player->captured.stride_width[0];
- }
-
- temp = player->captured.data[1];
-
- /* set UV plane*/
- for (j = 0; j < player->captured.height[1]; j++) {
- memcpy(p_buf, temp, player->captured.width[1]);
- p_buf += player->captured.width[1];
- temp += player->captured.stride_width[1];
- }
-
- /* NV12 -> RGB888 */
- ret = __mm_player_convert_colorspace(player, (unsigned char*)src_buffer, MM_UTIL_COLOR_NV12,
- player->captured.width[0], player->captured.height[0], MM_UTIL_COLOR_RGB24);
+ } else if (player->video_cs == MM_PLAYER_COLORSPACE_NV12) {
+ ret = __mm_player_convert_NV12(player);
if (ret != MM_ERROR_NONE) {
- LOGE("failed to convert nv12 linear");
+ msg.code = ret;
goto ERROR;
}
-#ifdef CAPTURE_OUTPUT_DUMP
- capture_output_dump(player);
-#endif
- /* clean */
- MMPLAYER_FREEIF(src_buffer);
- /* free captured buf */
- for (i = 0; i < player->captured.handle_num; i++) {
- MMPLAYER_FREEIF(player->captured.data[i]);
- }
- } else if (MM_PLAYER_COLORSPACE_I420 == player->video_cs) {
- planes[0] = player->captured.stride_width[0] * player->captured.stride_height[0];
- planes[1] = planes[2] = (player->captured.stride_width[0]>>1) * (player->captured.stride_height[0]>>1);
-
- src_buffer = (unsigned char*) g_try_malloc(player->captured.stride_width[0] * player->captured.stride_height[0]*3/2);
- p_buf = src_buffer;
- /* set Y plane */
- memset(p_buf, 0x00, planes[0]);
- temp = player->captured.data[0];
-
- for (i = 0; i < player->captured.height[0]; i++) {
- memcpy(p_buf, temp, player->captured.width[0]);
- temp += player->captured.stride_width[0];
- p_buf += player->captured.width[0];
- }
-
- /* set U plane */
- memset(p_buf, 0x00, planes[1]);
- temp = player->captured.data[1];
-
- for (i = 0; i < player->captured.height[1]; i++) {
- memcpy(p_buf, temp, player->captured.width[1]);
- temp += player->captured.stride_width[1];
- p_buf += player->captured.width[1];
- }
-
- /* set V plane */
- memset(p_buf, 0x00, planes[2]);
- temp = player->captured.data[2];
-
- for (i = 0; i < player->captured.height[2]; i++) {
- memcpy(p_buf, temp, player->captured.width[2]);
- temp += player->captured.stride_width[2];
- p_buf += player->captured.width[2];
- }
-
- /* 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);
+ } else if (player->video_cs == MM_PLAYER_COLORSPACE_I420) {
+ ret = __mm_player_convert_I420(player);
if (ret != MM_ERROR_NONE) {
- LOGE("failed to convert I420 linear");
+ msg.code = ret;
goto ERROR;
}
-#ifdef CAPTURE_OUTPUT_DUMP
- capture_output_dump(player);
-#endif
- /* clean */
- MMPLAYER_FREEIF(src_buffer);
- /* free captured buf */
- for (i = 0; i < player->captured.handle_num; i++) {
- MMPLAYER_FREEIF(player->captured.data[i]);
- }
}
ret = __mmplayer_get_video_angle((MMHandleType)player, &display_angle, &orientation);
@@ -476,29 +331,16 @@ __mmplayer_capture_thread(gpointer data)
player->capture.fmt = MM_PLAYER_COLORSPACE_RGB888;
msg.data = &player->capture;
msg.size = player->capture.size;
-// msg.captured_frame.width = player->capture.width;
-// msg.captured_frame.height = player->capture.height;
-// msg.captured_frame.orientation = player->capture.orientation;
if (player->cmd >= MMPLAYER_COMMAND_START) {
MMPLAYER_POST_MSG(player, MM_MESSAGE_VIDEO_CAPTURED, &msg);
LOGD("returned from capture message callback");
}
- //MMPLAYER_FREEIF(player->capture.data);
continue;
ERROR:
- MMPLAYER_FREEIF(src_buffer);
-
- for (i = 0; i < player->captured.handle_num; i++) {
+ for (i = 0; i < player->captured.handle_num; i++)
MMPLAYER_FREEIF(player->captured.data[i]);
- }
-
- if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED) {
- /* clean */
- MMPLAYER_FREEIF(linear_y_plane);
- MMPLAYER_FREEIF(linear_uv_plane);
- }
msg.union_type = MM_MSG_UNION_CODE;
@@ -600,6 +442,7 @@ __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuff
}
memcpy(player->captured.data[i], pixels, size);
}
+ player->captured.handle_num = GST_VIDEO_FRAME_N_PLANES(&vframe);
gst_video_frame_unmap(&vframe);
}
goto DONE;
@@ -608,7 +451,6 @@ __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuff
player->captured.height[0] = src_height;
player->captured.stride_width[0] = MM_ALIGN(src_width, 4);
player->captured.stride_height[0] = src_height;
-
switch (GST_VIDEO_INFO_FORMAT(&video_info)) {
case GST_VIDEO_FORMAT_I420:
src_fmt = MM_UTIL_COLOR_I420;
@@ -629,6 +471,7 @@ __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuff
goto ERROR;
break;
}
+ player->captured.handle_num = 1;
}
} else {
LOGE("unknown format to capture\n");
@@ -999,3 +842,205 @@ static void capture_output_dump(mm_player_t* player)
LOGE("capture rgb dumped!! ret = %d", ret);
}
#endif
+
+static int
+__mm_player_convert_NV12_tiled(mm_player_t *player)
+{
+ /* Colorspace conversion : NV12T-> NV12-> RGB888 */
+ int ret = MM_ERROR_NONE;
+ unsigned char *src_buffer = NULL;
+ unsigned char *linear_y_plane = NULL;
+ unsigned char *linear_uv_plane = NULL;
+ int linear_y_plane_size;
+ int linear_uv_plane_size;
+ int width = player->captured.width[0];
+ int height = player->captured.height[0];
+ int i;
+
+ linear_y_plane_size = (width * height);
+ linear_uv_plane_size = linear_y_plane_size / 2;
+
+ linear_y_plane = (unsigned char *)g_try_malloc(linear_y_plane_size);
+ if (!linear_y_plane)
+ return MM_ERROR_PLAYER_NO_FREE_SPACE;
+
+ linear_uv_plane = (unsigned char *)g_try_malloc(linear_uv_plane_size);
+ if (!linear_uv_plane) {
+ ret = MM_ERROR_PLAYER_NO_FREE_SPACE;
+ goto EXIT;
+ }
+ /* NV12 tiled to linear */
+ __csc_tiled_to_linear_crop(linear_y_plane,
+ player->captured.data[0], width, height, 0, 0, 0, 0);
+ __csc_tiled_to_linear_crop(linear_uv_plane,
+ player->captured.data[1], width, height / 2, 0, 0, 0, 0);
+
+ src_buffer = (unsigned char *)g_try_malloc(linear_y_plane_size + linear_uv_plane_size);
+
+ if (!src_buffer) {
+ ret = MM_ERROR_PLAYER_NO_FREE_SPACE;
+ goto EXIT;
+ }
+ memset(src_buffer, 0x00, linear_y_plane_size + linear_uv_plane_size);
+ memcpy(src_buffer, linear_y_plane, linear_y_plane_size);
+ 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);
+ if (ret != MM_ERROR_NONE) {
+ LOGE("failed to convert nv12 linear");
+ goto EXIT;
+ }
+
+EXIT:
+ /* clean */
+ MMPLAYER_FREEIF(src_buffer);
+ MMPLAYER_FREEIF(linear_y_plane);
+ MMPLAYER_FREEIF(linear_uv_plane);
+
+ for (i = 0; i < player->captured.handle_num; i++)
+ MMPLAYER_FREEIF(player->captured.data[i]);
+
+ return ret;
+}
+
+static int
+__mm_player_convert_NV12(mm_player_t *player)
+{
+ unsigned char *src_buffer = NULL;
+ unsigned char *p_buf = NULL;
+ unsigned char *temp = NULL;
+ int planes[MAX_BUFFER_PLANE] = {0, };
+ int ret = MM_ERROR_NONE;
+ int i, j;
+
+ /* using original width otherwises, app can't know aligned to resize */
+ planes[0] = player->captured.stride_width[0] * player->captured.stride_height[0];
+ planes[1] = player->captured.stride_width[1] * player->captured.stride_height[1];
+ int src_buffer_size = planes[0] + planes[1];
+
+ if (!src_buffer_size) {
+ LOGE("invalid data size");
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+ src_buffer = (unsigned char *)g_try_malloc(src_buffer_size);
+ if (!src_buffer)
+ return MM_ERROR_PLAYER_NO_FREE_SPACE;
+
+ memset(src_buffer, 0x00, src_buffer_size);
+ p_buf = src_buffer;
+
+ temp = player->captured.data[0];
+
+ /* set Y plane */
+ for (i = 0; i < player->captured.height[0]; i++) {
+ memcpy(p_buf, temp, player->captured.width[0]);
+ p_buf += player->captured.width[0];
+ temp += player->captured.stride_width[0];
+ }
+
+ temp = player->captured.data[1];
+
+ /* set UV plane*/
+ for (j = 0; j < player->captured.height[1]; j++) {
+ memcpy(p_buf, temp, player->captured.width[1]);
+ p_buf += player->captured.width[1];
+ temp += player->captured.stride_width[1];
+ }
+
+ /* NV12 -> RGB888 */
+ ret = __mm_player_convert_colorspace(player, (unsigned char *)src_buffer,
+ MM_UTIL_COLOR_NV12, player->captured.width[0],
+ player->captured.height[0], MM_UTIL_COLOR_RGB24);
+ if (ret != MM_ERROR_NONE) {
+ LOGE("failed to convert nv12 linear");
+ goto EXIT;
+ }
+#ifdef CAPTURE_OUTPUT_DUMP
+ capture_output_dump(player);
+#endif
+
+EXIT:
+ /* clean */
+ MMPLAYER_FREEIF(src_buffer);
+ /* free captured buf */
+ for (i = 0; i < player->captured.handle_num; i++)
+ MMPLAYER_FREEIF(player->captured.data[i]);
+
+ return ret;
+}
+
+static int
+__mm_player_convert_I420(mm_player_t *player)
+{
+ unsigned char *src_buffer = NULL;
+ unsigned char *p_buf = NULL;
+ unsigned char *temp = NULL;
+ int planes[MAX_BUFFER_PLANE] = {0, };
+ int ret = MM_ERROR_NONE;
+ int i;
+
+ /* using original width otherwises, app can't know aligned to resize */
+ planes[0] = player->captured.stride_width[0] * player->captured.stride_height[0];
+ planes[1] = planes[2] = (player->captured.stride_width[0] >> 1)
+ * (player->captured.stride_height[0] >> 1);
+
+ src_buffer = (unsigned char *)g_try_malloc(player->captured.stride_width[0]
+ * player->captured.stride_height[0] * 3 / 2);
+
+ if (!src_buffer)
+ return MM_ERROR_PLAYER_NO_FREE_SPACE;
+
+ /* set Y plane */
+ memset(src_buffer, 0x00, planes[0]);
+ p_buf = src_buffer;
+
+ temp = player->captured.data[0];
+
+ for (i = 0; i < player->captured.height[0]; i++) {
+ memcpy(p_buf, temp, player->captured.width[0]);
+ temp += player->captured.stride_width[0];
+ p_buf += player->captured.width[0];
+ }
+
+ /* set U plane */
+ memset(p_buf, 0x00, planes[1]);
+ temp = player->captured.data[1];
+
+ for (i = 0; i < player->captured.height[1]; i++) {
+ memcpy(p_buf, temp, player->captured.width[1]);
+ temp += player->captured.stride_width[1];
+ p_buf += player->captured.width[1];
+ }
+
+ /* set V plane */
+ memset(p_buf, 0x00, planes[2]);
+ temp = player->captured.data[2];
+
+ for (i = 0; i < player->captured.height[2]; i++) {
+ memcpy(p_buf, temp, player->captured.width[2]);
+ temp += player->captured.stride_width[2];
+ p_buf += player->captured.width[2];
+ }
+
+ /* 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);
+ if (ret != MM_ERROR_NONE) {
+ LOGE("failed to convert I420 linear");
+ goto EXIT;
+ }
+#ifdef CAPTURE_OUTPUT_DUMP
+ capture_output_dump(player);
+#endif
+
+EXIT:
+ /* clean */
+ MMPLAYER_FREEIF(src_buffer);
+ /* free captured buf */
+ for (i = 0; i < player->captured.handle_num; i++)
+ MMPLAYER_FREEIF(player->captured.data[i]);
+
+ return ret;
+}