#include <gmodule.h>
#include <limits.h>
-#include <inttypes.h>
#include "mm_util_private.h"
#include "mm_util_imgp.h"
#include "mm_util_imgp_internal.h"
#define GST "gstcs"
typedef gboolean(*IMGPInfoFunc) (imgp_info_s *, const unsigned char *, unsigned char *, imgp_plugin_type_e);
-static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet);
+static int __mm_util_transform_exec(mm_util_s *handle, color_image_data_s *source_image);
static int check_valid_picture_size(int width, int height)
{
return mm_util_imgp_func;
}
-static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, int err, void *userdata)
-{
- mm_util_debug("==> finalize callback func is called [%d]", err);
- return MEDIA_PACKET_FINALIZE;
-}
-
static int __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s)
{
int ret = MM_UTIL_ERROR_NONE;
}
/* private values init */
- handle->src = NULL;
handle->dst = NULL;
handle->dst_format = MM_UTIL_IMG_FMT_NUM;
- handle->dst_rotation = MM_UTIL_ROTATION_NONE;
+ handle->rotation = MM_UTIL_ROTATION_NONE;
handle->start_x = -1;
handle->start_y = -1;
- handle->src_width = 0;
- handle->src_height = 0;
handle->dst_width = 0;
handle->dst_height = 0;
handle->is_completed = FALSE;
return ret;
}
-static int __mm_util_handle_refresh(mm_util_s *handle)
-{
- int ret = MM_UTIL_ERROR_NONE;
-
- if (!handle) {
- mm_util_error("[ERROR] - handle");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- /* restore original settings */
- if (handle->set_rotate && (handle->set_crop || handle->set_resize)) {
- if ((handle->dst_rotation == MM_UTIL_ROTATION_90) || (handle->dst_rotation == MM_UTIL_ROTATION_270)) {
- unsigned int temp = 0;
- temp = handle->dst_width;
- handle->dst_width = handle->dst_height;
- handle->dst_height = temp;
- }
- }
-
- handle->is_completed = FALSE;
-
- handle->dst_packet = NULL;
-
- return ret;
-}
-
-static media_format_mimetype_e __mm_util_mapping_imgp_format_to_mime(mm_util_img_format format)
-{
- media_format_mimetype_e mimetype = -1;
-
- switch (format) {
- case MM_UTIL_IMG_FMT_NV12:
- mimetype = MEDIA_FORMAT_NV12;
- break;
- case MM_UTIL_IMG_FMT_NV16:
- mimetype = MEDIA_FORMAT_NV16;
- break;
- case MM_UTIL_IMG_FMT_YUYV:
- mimetype = MEDIA_FORMAT_YUYV;
- break;
- case MM_UTIL_IMG_FMT_UYVY:
- mimetype = MEDIA_FORMAT_UYVY;
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- mimetype = MEDIA_FORMAT_422P;
- break;
- case MM_UTIL_IMG_FMT_I420:
- mimetype = MEDIA_FORMAT_I420;
- break;
- case MM_UTIL_IMG_FMT_YUV420:
- mimetype = MEDIA_FORMAT_YV12;
- break;
- case MM_UTIL_IMG_FMT_RGB565:
- mimetype = MEDIA_FORMAT_RGB565;
- break;
- case MM_UTIL_IMG_FMT_RGB888:
- mimetype = MEDIA_FORMAT_RGB888;
- break;
- case MM_UTIL_IMG_FMT_RGBA8888:
- mimetype = MEDIA_FORMAT_RGBA;
- break;
- case MM_UTIL_IMG_FMT_BGRA8888:
- mimetype = MEDIA_FORMAT_BGRA;
- break;
- case MM_UTIL_IMG_FMT_ARGB8888:
- mimetype = MEDIA_FORMAT_ARGB;
- break;
- case MM_UTIL_IMG_FMT_NV12_TILED:
- mimetype = MEDIA_FORMAT_NV12T;
- break;
- default:
- mimetype = -1;
- mm_util_error("Not Supported Format [%d]", format);
- break;
- }
-
- mm_util_debug("imgp fmt: %d mimetype fmt: %d", format, mimetype);
-
- return mimetype;
-}
-
-static mm_util_img_format __mm_util_mapping_mime_format_to_imgp(media_format_mimetype_e mimetype)
-{
- mm_util_img_format format = -1;
-
- switch (mimetype) {
- case MEDIA_FORMAT_NV12:
- format = MM_UTIL_IMG_FMT_NV12;
- break;
- case MEDIA_FORMAT_NV16:
- format = MM_UTIL_IMG_FMT_NV16;
- break;
- case MEDIA_FORMAT_YUYV:
- format = MM_UTIL_IMG_FMT_YUYV;
- break;
- case MEDIA_FORMAT_UYVY:
- format = MM_UTIL_IMG_FMT_UYVY;
- break;
- case MEDIA_FORMAT_422P:
- format = MM_UTIL_IMG_FMT_YUV422;
- break;
- case MEDIA_FORMAT_I420:
- format = MM_UTIL_IMG_FMT_I420;
- break;
- case MEDIA_FORMAT_YV12:
- format = MM_UTIL_IMG_FMT_YUV420;
- break;
- case MEDIA_FORMAT_RGB565:
- format = MM_UTIL_IMG_FMT_RGB565;
- break;
- case MEDIA_FORMAT_RGB888:
- format = MM_UTIL_IMG_FMT_RGB888;
- break;
- case MEDIA_FORMAT_RGBA:
- format = MM_UTIL_IMG_FMT_RGBA8888;
- break;
- case MEDIA_FORMAT_BGRA:
- format = MM_UTIL_IMG_FMT_BGRA8888;
- break;
- case MEDIA_FORMAT_ARGB:
- format = MM_UTIL_IMG_FMT_ARGB8888;
- break;
- case MEDIA_FORMAT_NV12T:
- format = MM_UTIL_IMG_FMT_NV12_TILED;
- break;
- default:
- format = -1;
- mm_util_error("Not Supported Format [%d]", mimetype);
- break;
- }
-
- mm_util_debug("mimetype: %d imgp fmt: %d", mimetype, format);
-
- return format;
-}
-
gpointer _mm_util_thread_repeate(gpointer data)
{
mm_util_s *handle = (mm_util_s *) data;
int ret = MM_UTIL_ERROR_NONE;
- media_packet_h pop_data = NULL;
+ mm_util_color_image_h pop_data = NULL;
if (!handle) {
mm_util_error("[ERROR] - handle");
while (!handle->is_finish) {
mm_util_debug("waiting...");
- pop_data = (media_packet_h) g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND);
+ pop_data = (mm_util_color_image_h)g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND);
mm_util_debug("get from data or timeout");
if (pop_data == NULL) {
continue;
}
- ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */
+ ret = __mm_util_transform_exec(handle, (color_image_data_s *)pop_data); /* Need to block */
if (ret == MM_UTIL_ERROR_NONE)
mm_util_debug("Success - transform_exec");
else
mm_util_error("Error - transform_exec");
if (handle->_util_cb->completed_cb) {
- mm_util_debug("completed_cb");
- handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data);
- mm_util_debug("completed_cb %p", &handle->dst);
+ mm_util_debug("completed_cb is called");
+ handle->_util_cb->completed_cb(handle->dst, ret, handle->_util_cb->user_data);
}
- __mm_util_handle_refresh(handle);
+ mm_util_destroy_color_image(pop_data);
+ mm_util_destroy_color_image(handle->dst);
+ handle->is_completed = FALSE;
}
mm_util_debug("exit thread");
unsigned char *dst_buf[4] = {NULL,};
unsigned int dst_buf_size = 0;
unsigned int src_width = 0, src_height = 0;
- mm_util_img_format src_format;
+ mm_util_img_format src_format = -1;
unsigned int src_index = 0, dst_index = 0;
if (handle == NULL) {
mm_util_debug("src: %p, dst: %p", handle->src, handle->dst);
- dst_buf[src_index] = calloc(1, handle->src_buf_size);
- src_width = handle->src_width;
- src_height = handle->src_height;
- src_format = handle->src_format;
+ dst_buf[src_index] = calloc(1, handle->src->buffer_size);
+ src_width = handle->src->width;
+ src_height = handle->src->height;
+ src_format = handle->src->format;
if (dst_buf[src_index] == NULL) {
mm_util_error("[multi func] memory allocation error");
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- memcpy(dst_buf[src_index], handle->src, handle->src_buf_size);
+ memcpy(dst_buf[src_index], handle->src->buffer, handle->src->buffer_size);
if (handle->set_crop) {
dst_index++;
__mm_util_get_crop_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
}
src_index = dst_index;
src_format = handle->dst_format;
- handle->dst_width = src_width;
- handle->dst_height = src_height;
}
if (handle->set_rotate) {
dst_index++;
- switch (handle->dst_rotation) {
+ switch (handle->rotation) {
case MM_UTIL_ROTATION_90:
case MM_UTIL_ROTATION_270:
mm_util_get_image_size(src_format, src_height, src_width, &dst_buf_size);
__mm_destroy_temp_buffer(dst_buf);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height, handle->dst_rotation);
+ ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height, handle->rotation);
if (ret != MM_UTIL_ERROR_NONE) {
__mm_destroy_temp_buffer(dst_buf);
mm_util_error("mm_util_rotate_image failed");
}
if (dst_buf[dst_index] != NULL && dst_buf_size != 0) {
- handle->dst = calloc(1, dst_buf_size);
- if (handle->dst == NULL) {
- __mm_destroy_temp_buffer(dst_buf);
- mm_util_error("memory allocation failed");
- return MM_UTIL_ERROR_OUT_OF_MEMORY;
- }
- memcpy(handle->dst, dst_buf[dst_index], dst_buf_size);
- handle->dst_buf_size = dst_buf_size;
+ ret = mm_util_set_color_image((mm_util_color_image_h)handle->dst, (int)src_width, (int)src_height, src_format, (void *)dst_buf[dst_index], (size_t)dst_buf_size);
+ if (ret != MM_UTIL_ERROR_NONE)
+ mm_util_error("mm_util_set_color_image failed");
}
__mm_destroy_temp_buffer(dst_buf);
return ret;
}
-static int __mm_get_info_from_media_packet(media_packet_h pkt, mm_util_s *handle)
-{
- int err = MEDIA_PACKET_ERROR_NONE;
- media_format_mimetype_e mimetype = 0;
- int width = 0, height = 0;
- uint64_t size = 0;
- void *ptr = NULL;
- media_format_h fmt = NULL;
-
- if ((pkt == NULL) || (handle == NULL)) {
- mm_util_error("Invalid parameter");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- err = media_packet_get_format(pkt, &fmt);
- if (err != MEDIA_PACKET_ERROR_NONE) {
- mm_util_error("media_packet_get_format failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- err = media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
- if (err != MEDIA_FORMAT_ERROR_NONE) {
- mm_util_error("media_packet_get_format failed (%d)", err);
- media_format_unref(fmt);
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
- media_format_unref(fmt);
-
- err = media_packet_get_buffer_size(pkt, &size);
- if (err != MEDIA_PACKET_ERROR_NONE) {
- mm_util_error("media_packet_get_buffer_size failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (size) {
- handle->src = NULL;
- err = media_packet_get_buffer_data_ptr(pkt, &ptr);
- if (err != MM_UTIL_ERROR_NONE) {
- mm_util_error("[src] media_packet_get_extra");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
- mm_util_debug("src buffer pointer: %p", ptr);
- }
-
- mm_util_debug("[Fotmat: %u] W x H : %d x %d", mimetype, width, height);
- if ((width == 0) || (height == 0) || (size == 0) || (ptr == NULL)) {
- mm_util_error("Invalid source packet");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- handle->src_format = __mm_util_mapping_mime_format_to_imgp(mimetype);
- handle->src_width = width;
- handle->src_height = height;
- handle->src_buf_size = (guint)size;
- handle->src = ptr;
-
- if (handle->dst_format == MM_UTIL_IMG_FMT_NUM) {
- mm_util_debug("dst format is equal to src format");
- handle->dst_format = handle->src_format;
- }
-
- return MM_UTIL_ERROR_NONE;
-}
-
-static int __mm_create_media_format(mm_util_img_format format, unsigned int width, unsigned int height, media_format_h *new_fmt)
-{
- int err = MEDIA_FORMAT_ERROR_NONE;
-
- if ((new_fmt == NULL) || (width == 0) || (height == 0)) {
- mm_util_error("Invalid parameter");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- err = media_format_create(new_fmt);
- if (err != MEDIA_FORMAT_ERROR_NONE) {
- mm_util_error("media_format_make_writable failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = media_format_set_video_mime(*new_fmt, __mm_util_mapping_imgp_format_to_mime(format));
- if (err != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(*new_fmt);
- mm_util_error("media_format_set_video_mime failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = media_format_set_video_width(*new_fmt, width);
- if (err != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(*new_fmt);
- mm_util_error("media_format_set_video_width failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = media_format_set_video_height(*new_fmt, height);
- if (err != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(*new_fmt);
- mm_util_error("media_format_set_video_height failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- return MM_UTIL_ERROR_NONE;
-}
-
-static int __mm_create_media_packet_with_buffer(media_format_h fmt, void *buffer, guint buffer_size, media_packet_h *pkt)
-{
- int err = MEDIA_PACKET_ERROR_NONE;
- uint64_t packet_buffer_size = 0;
- size_t size = 0;
- void *ptr = NULL;
-
- if ((fmt == NULL) || (pkt == NULL) || (buffer == NULL) || (buffer_size == 0)) {
- mm_util_error("Invalid parameter");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- err = media_packet_create_alloc(fmt, (media_packet_finalize_cb)_mm_util_transform_packet_finalize_callback, NULL, pkt);
- if (err != MEDIA_PACKET_ERROR_NONE) {
- mm_util_error("media_packet_create_alloc failed (%d)", err);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = media_packet_get_buffer_size(*pkt, &packet_buffer_size);
- if (err != MEDIA_PACKET_ERROR_NONE) {
- mm_util_error("media_packet_get_buffer_size failed (%d)", err);
- media_packet_destroy(*pkt);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = media_packet_get_buffer_data_ptr(*pkt, &ptr);
- if (err != MM_UTIL_ERROR_NONE) {
- mm_util_error("media_packet_get_buffer_data_ptr failed (%d)", err);
- media_packet_destroy(*pkt);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- if (ptr == NULL || packet_buffer_size == 0) {
- mm_util_error("The ptr(%p) and size(%" PRIu64 ") was wrong", ptr, packet_buffer_size);
- media_packet_destroy(*pkt);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- if ((uint64_t)buffer_size < packet_buffer_size) {
- size = (size_t)buffer_size;
- } else {
- size = (size_t)packet_buffer_size;
- }
-
- mm_util_error("Size: result(%u) media_packet(%" PRIu64 ") use(%zu)", buffer_size, packet_buffer_size, size);
- mm_util_debug("Success - media_packet is created (%p, %" PRIu64 ")", *pkt, packet_buffer_size);
-
- memcpy(ptr, buffer, size);
-
- return MM_UTIL_ERROR_NONE;
-}
-
-static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet)
+static int __mm_util_transform_exec(mm_util_s *handle, color_image_data_s *source_image)
{
int ret = MM_UTIL_ERROR_NONE;
- media_format_h dst_fmt = NULL;
- if ((handle == NULL) || (src_packet == NULL)) {
+ if ((handle == NULL) || (source_image == NULL)) {
mm_util_error("Invalid parameter");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- ret = __mm_get_info_from_media_packet(src_packet, handle);
+ mm_util_debug("orig_image: %p [%zu] %d X %d (%d)", source_image->buffer, source_image->buffer_size,
+ source_image->width, source_image->height, source_image->format);
+
+ handle->src = source_image;
+ ret = mm_util_create_color_image((mm_util_color_image_h *)&handle->dst);
if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("__mm_get_info_from_packet failed (%d)", ret);
+ mm_util_error("mm_util_create_color_image failed");
return ret;
}
- mm_util_debug("src: %p (%u X %u)", src_packet, handle->src_width, handle->src_height);
ret = __mm_util_processing(handle);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_processing failed (%d)", ret);
- handle->dst_packet = NULL;
- return ret;
- }
-
- mm_util_debug("handle->src: %p [%d] %d X %d (%d) => handle->dst: %p [%d] %d X %d (%d)",
- handle->src, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
- handle->dst, handle->dst_format, handle->dst_width, handle->dst_height, handle->dst_buf_size);
-
- ret = __mm_create_media_format(handle->dst_format, handle->dst_width, handle->dst_height, &dst_fmt);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("__mm_create_media_format failed (%d)", ret);
- MMUTIL_SAFE_FREE(handle->dst);
- return ret;
- }
-
- ret = __mm_create_media_packet_with_buffer(dst_fmt, handle->dst, handle->dst_buf_size, &handle->dst_packet);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("__mm_create_media_packet failed (%d)", ret);
- media_format_unref(dst_fmt);
- MMUTIL_SAFE_FREE(handle->dst);
return ret;
}
- media_format_unref(dst_fmt);
- MMUTIL_SAFE_FREE(handle->dst);
+ mm_util_debug("result_image: %p [%zu] %d X %d (%u)", handle->dst->buffer, handle->dst->buffer_size,
+ handle->dst->width, handle->dst->height, handle->dst->format);
return ret;
}
}
handle->set_rotate = TRUE;
- handle->dst_rotation = rotation;
+ handle->rotation = rotation;
return ret;
}
return ret;
}
-int mm_util_transform(mm_util_imgp_h imgp_handle, media_packet_h src_packet, mm_util_completed_callback completed_callback, void *user_data)
+int mm_util_create_color_image(mm_util_color_image_h *image)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ color_image_data_s *color_image = NULL;
+
+ if (image == NULL) {
+ mm_util_error("[ERROR] - image");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ mm_util_error("Memory allocation s");
+
+ color_image = (color_image_data_s *)calloc(1, sizeof(color_image_data_s));
+ if (color_image == NULL) {
+ mm_util_error("Memory allocation failed");
+ return MM_UTIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ mm_util_error("Memory allocation e");
+
+ *image = (mm_util_color_image_h)color_image;
+
+ return ret;
+}
+
+int mm_util_set_color_image(mm_util_color_image_h image, int width, int height, mm_util_img_format format, void *buffer, size_t buffer_size)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ color_image_data_s *color_image = (color_image_data_s *)image;
+
+ if (color_image == NULL) {
+ mm_util_error("[ERROR] - raw_image");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (buffer == NULL || buffer_size == 0) {
+ mm_util_error("[ERROR] - Invalid parameters");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ color_image->buffer = calloc(1, buffer_size);
+ if (color_image->buffer == NULL) {
+ mm_util_error("Memory allocation failed");
+ return MM_UTIL_ERROR_OUT_OF_MEMORY;
+ }
+ memcpy(color_image->buffer, buffer, buffer_size);
+ color_image->buffer_size = buffer_size;
+ color_image->width = width;
+ color_image->height = height;
+ color_image->format = format;
+
+ return ret;
+}
+
+int mm_util_get_color_image(mm_util_color_image_h image, int *width, int *height, mm_util_img_format *format, void **buffer, size_t *buffer_size)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ color_image_data_s *color_image = (color_image_data_s *)image;
+
+ if (color_image == NULL) {
+ mm_util_error("[ERROR] - raw_image");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (width != NULL)
+ *width = color_image->width;
+
+ if (height != NULL)
+ *height = color_image->height;
+
+ if (format != NULL)
+ *format = color_image->format;
+
+ if (buffer != NULL)
+ *buffer = color_image->buffer;
+
+ if (buffer_size != NULL)
+ *buffer_size = color_image->buffer_size;
+
+ return ret;
+}
+
+
+void mm_util_destroy_color_image(mm_util_color_image_h image)
+{
+ color_image_data_s *color_image = (color_image_data_s *)image;
+
+ if (color_image == NULL) {
+ mm_util_error("[ERROR] - image");
+ return;
+ }
+
+ MMUTIL_SAFE_FREE(color_image->buffer);
+ MMUTIL_SAFE_FREE(color_image);
+}
+
+int mm_util_transform(mm_util_imgp_h imgp_handle, mm_util_color_image_h image, mm_util_completed_callback completed_callback, void *user_data)
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_s *handle = (mm_util_s *) imgp_handle;
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- if (!src_packet) {
- mm_util_error("[ERROR] - src_packet");
+ if (!image) {
+ mm_util_error("[ERROR] - image");
return MM_UTIL_ERROR_INVALID_PARAMETER;
} else {
- mm_util_debug("src: %p", src_packet);
+ mm_util_debug("image: %p", image);
}
if (!completed_callback) {
if (handle->queue) {
mm_util_debug("g_async_queue_push");
- g_async_queue_push(handle->queue, GINT_TO_POINTER(src_packet));
+ g_async_queue_push(handle->queue, GINT_TO_POINTER(image));
ret = __mm_util_create_thread(handle);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("ERROR - Create thread");
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
-
-#include <media_packet.h>
-#include "mm_util_imgp.h"
+#include <errno.h>
+#include <mm_util_imgp.h>
#define MAX_STRING_LEN 128
#define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } }
-mm_util_imgp_h imgp_handle = 0;
+mm_util_imgp_h imgp_handle = NULL;
bool completed = false;
GCond g_thread_cond;
g_mutex_unlock(&g_thread_mutex);
}
-media_format_mimetype_e _format_to_mime(mm_util_img_format colorspace)
-{
- media_format_mimetype_e mimetype = -1;
-
- switch (colorspace) {
- case MM_UTIL_IMG_FMT_NV12:
- mimetype = MEDIA_FORMAT_NV12;
- break;
- case MM_UTIL_IMG_FMT_NV16:
- mimetype = MEDIA_FORMAT_NV16;
- break;
- case MM_UTIL_IMG_FMT_YUYV:
- mimetype = MEDIA_FORMAT_YUYV;
- break;
- case MM_UTIL_IMG_FMT_UYVY:
- mimetype = MEDIA_FORMAT_UYVY;
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- mimetype = MEDIA_FORMAT_422P;
- break;
- case MM_UTIL_IMG_FMT_I420:
- mimetype = MEDIA_FORMAT_I420;
- break;
- case MM_UTIL_IMG_FMT_RGB565:
- mimetype = MEDIA_FORMAT_RGB565;
- break;
- case MM_UTIL_IMG_FMT_RGB888:
- mimetype = MEDIA_FORMAT_RGB888;
- break;
- case MM_UTIL_IMG_FMT_RGBA8888:
- mimetype = MEDIA_FORMAT_RGBA;
- break;
- case MM_UTIL_IMG_FMT_ARGB8888:
- mimetype = MEDIA_FORMAT_ARGB;
- break;
- case MM_UTIL_IMG_FMT_BGRA8888:
- case MM_UTIL_IMG_FMT_BGRX8888:
- case MM_UTIL_IMG_FMT_NV61:
- default:
- mimetype = -1;
- fprintf(stderr, "Not Supported Format\n");
- break;
- }
-
- fprintf(stderr, "imgp fmt: %d mimetype fmt: %d\n", colorspace, mimetype);
- return mimetype;
-}
-
-int _packet_finalize_callback(media_packet_h packet, int err, void *user_data)
-{
- fprintf(stderr, "==> finalize callback func is called [%d] \n", err);
- return MEDIA_PACKET_FINALIZE;
-}
-
-bool _transform_completed_cb(media_packet_h *packet, int error, void *user_data)
+bool _transform_completed_cb(mm_util_color_image_h image, int error, void *user_data)
{
- uint64_t size = 0;
+ int err = MM_UTIL_ERROR_NONE;
+ size_t size = 0;
char* output_file = (char *)user_data;
fprintf(stderr, "imgp_handle: %p\n", imgp_handle);
fprintf(stderr, "completed\n");
FILE *fp = fopen(output_file, "w");
if (fp) {
- media_packet_get_buffer_size(*packet, &size);
void *dst = NULL;
- int err = media_packet_get_buffer_data_ptr(*packet, &dst);
- if (err != MEDIA_PACKET_ERROR_NONE) {
+ err = mm_util_get_color_image(image, NULL, NULL, NULL, &dst, &size);
+ if (err != MM_UTIL_ERROR_NONE) {
IMGP_FREE(dst);
fclose(fp);
fprintf(stderr, "Error media_packet_get_buffer_data_ptr (%d)\n", err);
_signal();
return FALSE;
}
- fprintf(stderr, "dst: %p [%" PRIu64 "]\n", dst, size);
+ fprintf(stderr, "dst: %p [%zu]\n", dst, size);
fwrite(dst, 1, size, fp);
fprintf(stderr, "FREE\n");
fclose(fp);
}
completed = true;
- fprintf(stderr, "Destory - dst packet\n");
- media_packet_destroy(*packet);
+ fprintf(stderr, "Destory - destroy image\n");
_signal();
unsigned char *dst = NULL;
if (argc < 12) {
- fprintf(stderr, "Usage: mm_util_imgp_testsuite sync {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n");
- fprintf(stderr, "Usage: mm_util_imgp_testsuite async {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n");
- fprintf(stderr, "ex: mm_util_imgp_testsuite sync test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n");
+ fprintf(stderr, "Usage: %s sync {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n", argv[0]);
+ fprintf(stderr, "Usage: %s async {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n", argv[0]);
+ fprintf(stderr, "ex: %s sync test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n", argv[0]);
return ret;
}
- uint64_t src_size = 0;
- uint64_t dst_size = 0;
+ size_t src_size = 0;
+ size_t dst_size = 0;
bool sync_mode = (strcmp(argv[1], "sync") == 0) ? TRUE : FALSE;
char *filename = strdup(argv[2]);
char *command = strdup(argv[3]);
char output_file[40] = {};
/* async mode */
- media_packet_h src_packet;
- void *ptr = NULL;
- media_format_h fmt;
+ mm_util_color_image_h orig_image = NULL;
unsigned int size = 0;
/* mem allocation for src dst buffer */
mm_util_get_image_size(src_format, src_width, src_height, &size);
- src_size = (uint64_t)size;
+ src_size = (size_t)size;
mm_util_get_image_size(dst_format, dst_width, dst_height, &size);
- dst_size = (uint64_t)size;
+ dst_size = (size_t)size;
src = calloc(1, src_size);
dst = calloc(1, dst_size);
goto TEST_FAIL;
}
- if (fread(src, 1, (int)src_size, fp) == src_size)
+ if (fread(src, 1, src_size, fp) == src_size)
fprintf(stderr, "#Success# fread\n");
else
fprintf(stderr, "#Error# fread\n");
{ /* write output file */
FILE *fpout = fopen(output_file, "w");
if (fpout) {
- fprintf(stderr, "dst: %p [%" PRIu64 "]\n", dst, dst_size);
+ fprintf(stderr, "dst: %p [%zu]\n", dst, dst_size);
fwrite(dst, 1, dst_size, fpout);
fprintf(stderr, "FREE\n");
fclose(fpout);
fprintf(stderr, "ERROR - Create Transcode Handle\n");
goto TEST_FAIL;
}
- if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
- if (media_format_set_video_mime(fmt, _format_to_mime(src_format)) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- fprintf(stderr, "[Error] Set - video mime\n");
- goto TEST_FAIL;
- }
-
- if (media_format_set_video_width(fmt, src_width) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- fprintf(stderr, "[Error] Set - video width\n");
- goto TEST_FAIL;
- }
- if (media_format_set_video_height(fmt, src_height) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- fprintf(stderr, "[Error] Set - video height\n");
- goto TEST_FAIL;
- }
-
- if (media_format_set_video_avg_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- fprintf(stderr, "[Error] Set - video avg bps\n");
- goto TEST_FAIL;
- }
-
- if (media_format_set_video_max_bps(fmt, 20000000) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- fprintf(stderr, "[Error] Set - video max bps\n");
- goto TEST_FAIL;
- }
-
- fprintf(stderr, "media_format_set_video_info success! w:%d, h:%d, format:%d\n", src_width, src_height, src_format);
+ ret = mm_util_create_color_image(&orig_image);
+ if (ret == MM_UTIL_ERROR_NONE) {
+ fprintf(stderr, "Success - mm_util_create_color_image\n");
} else {
- fprintf(stderr, "media_format_create failed...\n");
+ fprintf(stderr, "ERROR - mm_util_create_color_image\n");
+ goto TEST_FAIL;
}
- /* Set Source */
- ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)_packet_finalize_callback, NULL, &src_packet);
+ ret = mm_util_set_color_image(orig_image, src_width, src_height, src_format, src, src_size);
if (ret == MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "Success - Create Media Packet(%p)\n", src_packet);
- uint64_t buffer_size = (uint64_t)size;
- if (media_packet_get_buffer_size(src_packet, &buffer_size) == MEDIA_PACKET_ERROR_NONE) {
- ptr = calloc(1, buffer_size);
- if (ptr == NULL) {
- fprintf(stderr, "\tmemory allocation failed\n");
- goto TEST_FAIL;
- }
- if (media_packet_get_buffer_data_ptr(src_packet, &ptr) == MEDIA_PACKET_ERROR_NONE) {
- if (src != NULL && src_size > 0) {
- memcpy(ptr, src, buffer_size);
- fprintf(stderr, "memcpy\n");
- }
- }
- }
+ fprintf(stderr, "Success - mm_util_create_color_image\n");
} else {
- fprintf(stderr, "ERROR - Create Media Packet\n");
- return ret;
+ fprintf(stderr, "ERROR - mm_util_create_color_image\n");
+ goto TEST_FAIL;
}
ret = mm_util_set_hardware_acceleration(imgp_handle, FALSE);
}
/* Transform */
- ret = mm_util_transform(imgp_handle, src_packet, (mm_util_completed_callback) _transform_completed_cb, output_file);
+ ret = mm_util_transform(imgp_handle, orig_image, (mm_util_completed_callback) _transform_completed_cb, output_file);
if (ret == MM_UTIL_ERROR_NONE) {
fprintf(stderr, "Success - Transform\n");
} else {
IMGP_FREE(command);
IMGP_FREE(filename);
if (!sync_mode) {
- media_format_unref(fmt);
- fprintf(stderr, "Destory - src packet\n");
- media_packet_destroy(src_packet);
+ mm_util_destroy_color_image(orig_image);
fprintf(stderr, "destroy\n");
}