Add code to check color format before doing transform. and just fix some debug msg 59/170159/2
authorhj kim <backto.kim@samsung.com>
Wed, 14 Feb 2018 01:26:12 +0000 (10:26 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 14 Feb 2018 01:31:37 +0000 (10:31 +0900)
Change-Id: Idd4728e26c503ae8c870d11f92450ead4f56c573

gstcs/include/mm_util_gstcs_internal.h
gstcs/mm_util_gstcs.c

index d35c2ff..2537d8a 100755 (executable)
@@ -42,6 +42,7 @@ extern "C" {
 
 #define FONT_COLOR_RESET    "\033[0m"
 #define FONT_COLOR_RED      "\033[31m"
+#define FONT_COLOR_YELLOW "\033[33m"
 
 #define gstcs_debug(fmt, arg...) do { \
                LOGD(FONT_COLOR_RESET""fmt"", ##arg);     \
@@ -73,6 +74,14 @@ extern "C" {
                } \
        } while (0)
 
+#define gstcs_fenter() do { \
+                       LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \
+               } while (0)
+
+#define gstcs_fleave() do { \
+                       LOGD(FONT_COLOR_YELLOW"<LEAVE>"FONT_COLOR_RESET); \
+               } while (0)
+
 #define GSTCS_FREE(src) { if (src) {g_free(src); src = NULL; } }
 typedef struct _image_format_s {
        mm_util_color_format_e color_format;
index ecc12a7..53dc2b2 100755 (executable)
@@ -18,6 +18,7 @@
  * limitations under the License.
  *
  */
+#include <stdbool.h>
 #include "mm_util_gstcs_internal.h"
 #include <gst/check/gstcheck.h>
 #include <gst/video/video-format.h>
@@ -181,6 +182,8 @@ _mm_check_caps_format(GstCaps* caps)
 static void
 _mm_link_pipeline(gstreamer_s* pGstreamer_s, int value)
 {
+       gstcs_fenter();
+
        /* set property */
        gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL);
        if (!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL))
@@ -196,6 +199,8 @@ _mm_link_pipeline(gstreamer_s* pGstreamer_s, int value)
 
        /*g_object_set(pGstreamer_s->appsink, "drop", TRUE, NULL);*/
        g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
+
+       gstcs_fleave();
 }
 
 static GstVideoFormat _mm_get_video_format(mm_util_color_format_e color_format)
@@ -401,7 +406,7 @@ static int _mm_setup_image_size(mm_util_color_format_e color_format, int width,
 {
        int size = 0;
 
-       gstcs_debug("color_format: %d", color_format);
+       gstcs_debug("color_format [%d] width [%d] height [%d]", color_format, width, height);
 
        switch (color_format) {
        case MM_UTIL_COLOR_YUV420:
@@ -445,30 +450,29 @@ static int _mm_setup_image_size(mm_util_color_format_e color_format, int width,
        return size;
 }
 
-static int
-_mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
+static int _mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
 {
        int ret = GSTCS_ERROR_NONE;
+       gsize data_size = 0;
+       GstBuffer* gst_buf = NULL;
 
-       if (pGstreamer_s->pipeline == NULL) {
-               gstcs_error("pipeline is NULL\n");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       gstcs_fenter();
 
-       gsize data_size = _mm_setup_image_size(pImgp_info->src_format, pImgp_info->src_width, pImgp_info->src_height);
-       GstBuffer* gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
+       gstcs_retvm_if(pGstreamer_s->pipeline == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid pipeline");
 
-       if (gst_buf == NULL) {
-               gstcs_error("buffer is NULL\n");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       data_size = _mm_setup_image_size(pImgp_info->src_format, pImgp_info->src_width, pImgp_info->src_height);
+       gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
+
+       gstcs_retvm_if(gst_buf == NULL, GSTCS_ERROR_INVALID_OPERATION, "buffer is NULL");
 
        gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
+
+       gstcs_fleave();
+
        return ret;
 }
 
-static int
-_mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *src, gstreamer_s * pGstreamer_s)
+static int _mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *src, gstreamer_s * pGstreamer_s)
 {
        int ret = GSTCS_ERROR_NONE;
        GstBuffer *gst_buf = NULL;
@@ -477,25 +481,20 @@ _mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *s
        unsigned int stride = input_format->stride;
        unsigned int elevation = input_format->elevation;
 
-       if (pGstreamer_s->pipeline == NULL) {
-               gstcs_error("pipeline is NULL\n");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       gstcs_fenter();
+
+       gstcs_retvm_if(pGstreamer_s->pipeline == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid pipeline");
 
-       gstcs_debug("stride: %d, elevation: %d", stride, elevation);
        src_size = _mm_setup_image_size(input_format->color_format, stride, elevation);
-       gstcs_debug("buffer size (src): %d", src_size);
 
        int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->color_format);
        unsigned int src_row = input_format->width * byte_per_pixcel;
        unsigned int stride_row = stride * byte_per_pixcel;
        unsigned int i = 0, y = 0;
-       gstcs_debug("padding will be inserted to buffer");
+
        data = (unsigned char *) malloc(src_size);
-       if (data == NULL) {
-               gstcs_error("app_buffer is NULL\n");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       gstcs_retvm_if(data == NULL, GSTCS_ERROR_OUT_OF_MEMORY, "data is NULL");
+
        for (y = 0; y < (unsigned int)(input_format->height); y++) {
                guint8 *pLine = (guint8 *) &(src[src_row * y]);
                for (i = 0; i < src_row; i++)
@@ -517,16 +516,20 @@ _mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *s
        }
 
        gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
+
+       gstcs_fleave();
+
        return ret;
 }
 
-static int
-_mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigned char **dst, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
+static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigned char **dst, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
 {
        GstBus *bus = NULL;
        GstStateChangeReturn ret_state;
        int ret = GSTCS_ERROR_NONE;
 
+       gstcs_fenter();
+
        /*create pipeline*/
        ret = _mm_create_pipeline(pGstreamer_s);
        if (ret != GSTCS_ERROR_NONE)
@@ -543,10 +546,8 @@ _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigne
        gst_app_sink_set_caps(GST_APP_SINK(pGstreamer_s->appsink), output_format->caps);
 
        if ((input_format->width != input_format->stride) || (input_format->height != input_format->elevation)) {
-               gstcs_debug("Start _mm_push_buffer_into_pipeline_new");
                ret = _mm_push_buffer_into_pipeline_new(input_format, src, pGstreamer_s);
        } else {
-               gstcs_debug("Start mm_push_buffer_into_pipeline");
                ret = _mm_push_buffer_into_pipeline(pImgp_info, src, pGstreamer_s);
        }
 
@@ -555,12 +556,9 @@ _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigne
                gst_object_unref(pGstreamer_s->pipeline);
                return ret;
        }
-       gstcs_debug("End mm_push_buffer_into_pipeline");
 
        /*link pipeline*/
-       gstcs_debug("Start mm_link_pipeline");
        _mm_link_pipeline(pGstreamer_s, pImgp_info->angle);
-       gstcs_debug("End mm_link_pipeline");
 
        /* Conecting to the new-sample signal emited by the appsink*/
        gstcs_debug("Start G_CALLBACK(_mm_sink_sample)");
@@ -635,23 +633,19 @@ _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigne
        gst_object_unref(pGstreamer_s->pipeline);
        pGstreamer_s->output_buffer = NULL;
 
-       gstcs_debug("End gstreamer processing");
        gstcs_debug("dst: %p", *dst);
+       gstcs_fleave();
+
        return ret;
 }
 
 static int _gstcs_create_default_thread(gstreamer_s *gstreamer)
 {
-       if (gstreamer == NULL) {
-               gstcs_error("ERROR - gstreamer is null ");
-               return GSTCS_ERROR_INVALID_OPERATION;
-       }
+       gstcs_retvm_if(gstreamer == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid gstreamer");
 
        gstreamer->context = g_main_context_new();
-       if (gstreamer->context == NULL) {
-               gstcs_error("ERROR - g_main_context_new ");
-               return GSTCS_ERROR_INVALID_OPERATION;
-       }
+       gstcs_retvm_if(gstreamer->context == NULL, GSTCS_ERROR_INVALID_OPERATION, "ERROR - g_main_context_new");
+
        gstreamer->loop = g_main_loop_new(gstreamer->context, FALSE);
        if (gstreamer->loop == NULL) {
                gstcs_error("ERROR - g_main_loop_new ");
@@ -660,15 +654,13 @@ static int _gstcs_create_default_thread(gstreamer_s *gstreamer)
        }
 
        g_main_context_push_thread_default(gstreamer->context);
+
        return GSTCS_ERROR_NONE;
 }
 
 static int _gstcs_destroy_default_thread(gstreamer_s *gstreamer)
 {
-       if (gstreamer == NULL) {
-               gstcs_error("ERROR - gstreamer is null ");
-               return GSTCS_ERROR_INVALID_OPERATION;
-       }
+       gstcs_retvm_if(gstreamer == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid gstreamer");
 
        if (gstreamer->loop != NULL)
                g_main_loop_unref(gstreamer->loop);
@@ -689,10 +681,8 @@ static int _gstcs_init(gstreamer_s** gstreamer)
 
        argv = malloc(sizeof(gchar*) * max_argc);
 
-       if (!argv) {
-               gstcs_error("argv is not allocated");
-               return GSTCS_ERROR_OUT_OF_MEMORY;
-       }
+       gstcs_retvm_if(argv == NULL, GSTCS_ERROR_OUT_OF_MEMORY, "argv is not allocated");
+
        memset(argv, 0, sizeof(gchar*) * max_argc);
 
        argv[argc] = g_strdup("mmutil_gstcs");
@@ -738,8 +728,8 @@ static int _mm_imgp_gstcs(imgp_info_s* pImgp_info, unsigned char *src, unsigned
        int ret = GSTCS_ERROR_NONE;
 
        /* Print debug message for inout structure */
-       gstcs_debug("src_width [%d] src_height [%d]  dst_width [%d] dst_height [%d] rotation [%d]",
-       pImgp_info->src_width, pImgp_info->src_height, pImgp_info->dst_width, pImgp_info->dst_height, pImgp_info->angle);
+       gstcs_debug("src_width [%d] src_height [%d] src_format [%d] dst_width [%d] dst_height [%d] dst_format [%d] rotation [%d]",
+       pImgp_info->src_width, pImgp_info->src_height, pImgp_info->src_format, pImgp_info->dst_width, pImgp_info->dst_height, pImgp_info->dst_format, pImgp_info->angle);
 
        /* Initialize gstreamer */
        ret = _gstcs_init(&pGstreamer_s);
@@ -775,7 +765,6 @@ static int _mm_imgp_gstcs(imgp_info_s* pImgp_info, unsigned char *src, unsigned
        }
 
        /* Do gstreamer processing */
-       gstcs_debug("Start _mm_imgp_gstcs_processing ");
        ret = _mm_imgp_gstcs_processing(pGstreamer_s, src, dst, input_format, output_format, pImgp_info); /* input: buffer pointer for input image , input image format, input image width, input image height, output: buffer porinter for output image */
 
        if (ret == GSTCS_ERROR_NONE)
@@ -795,22 +784,22 @@ static int _mm_imgp_gstcs(imgp_info_s* pImgp_info, unsigned char *src, unsigned
        return ret;
 }
 
-int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst, imgp_type_e _imgp_type)
+static bool _mm_imgp_check_format(mm_util_color_format_e color_format)
 {
-       if (pImgp_info == NULL) {
-               gstcs_error("Error: input vaule is NULL");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       if ((color_format >= MM_UTIL_COLOR_YUV420) && (color_format <= MM_UTIL_COLOR_BGRX))
+               return TRUE;
 
-       if (src == NULL || dst == NULL) {
-               gstcs_error("Error: src | dst is NULL");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+       return FALSE;
+}
 
-       if (_imgp_type < 0 || _imgp_type > IMGP_MAX) {
-               gstcs_error("Error: imgp_type is wrong");
-               return GSTCS_ERROR_INVALID_PARAMETER;
-       }
+int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst, imgp_type_e _imgp_type)
+{
+       gstcs_retvm_if(pImgp_info == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid info");
+       gstcs_retvm_if(src == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid src");
+       gstcs_retvm_if(dst == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid dst");
+       gstcs_retvm_if((_imgp_type < 0 || _imgp_type > IMGP_MAX), GSTCS_ERROR_INVALID_PARAMETER, "Invalid _imgp_type[%d]", _imgp_type);
+       gstcs_retvm_if((_mm_imgp_check_format(pImgp_info->src_format) == FALSE), GSTCS_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", pImgp_info->src_format);
+       gstcs_retvm_if((_mm_imgp_check_format(pImgp_info->dst_format) == FALSE), GSTCS_ERROR_NOT_SUPPORTED_FORMAT, "not supported dst_format [%d]", pImgp_info->dst_format);
 
        gstcs_debug("[src %p] [dst %p]", src, dst);