#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>
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);
{
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 */
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;
}
}
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;
}
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);
}
/* 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);
}
/* 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);
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