Add error handling for getting gst_caps 61/200761/8 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix accepted/tizen/5.5/unified/20191031.022450 accepted/tizen/5.5/unified/mobile/hotfix/20201027.084432 accepted/tizen/5.5/unified/wearable/hotfix/20201027.115627 accepted/tizen/unified/20190311.220539 submit/tizen/20190311.013617 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185103 submit/tizen_5.5_wearable_hotfix/20201026.184303 tizen_5.5.m2_release
authorjiyong.min <jiyong.min@samsung.com>
Mon, 4 Mar 2019 00:02:51 +0000 (09:02 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Wed, 6 Mar 2019 05:10:16 +0000 (14:10 +0900)
Change-Id: I8a80de7404f8ec9e2c55e958ebf45b5c141c780d

gstcs/include/mm_util_gstcs.h [changed mode: 0755->0644]
gstcs/mm_util_gstcs.c
packaging/libmm-imgp-gstcs.spec

old mode 100755 (executable)
new mode 100644 (file)
index ed130bb..f1a0344 100644 (file)
@@ -27,6 +27,7 @@
 #define MM_UTIL_ROUND_UP_4(num) (((num)+3)&~3)
 #define MM_UTIL_ROUND_UP_8(num) (((num)+7)&~7)
 
+#define SAFE_UNREF_CAPS(caps)  { if (caps)     { gst_caps_unref(caps); caps = NULL; } }
 
 
 static GstFlowReturn
@@ -130,32 +131,37 @@ static int _mm_create_pipeline(gstreamer_s* pGstreamer_s)
        pGstreamer_s->pipeline = gst_pipeline_new("pipeline");
        if (!pGstreamer_s->pipeline) {
                gstcs_error("pipeline could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        pGstreamer_s->appsrc = gst_element_factory_make("appsrc" , "appsrc");
        if (!pGstreamer_s->appsrc) {
                gstcs_error("appsrc could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               gst_object_unref(pGstreamer_s->pipeline);
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        pGstreamer_s->colorspace = gst_element_factory_make("videoconvert" , "convert");
        if (!pGstreamer_s->colorspace) {
                gstcs_error("colorspace could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               gst_object_unref(pGstreamer_s->pipeline);
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        pGstreamer_s->videoscale = gst_element_factory_make("videoscale", "scale");
        if (!pGstreamer_s->videoscale) {
                gstcs_error("videoscale could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               gst_object_unref(pGstreamer_s->pipeline);
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        pGstreamer_s->videoflip = gst_element_factory_make("videoflip", "flip");
        if (!pGstreamer_s->videoflip) {
                gstcs_error("videoflip could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               gst_object_unref(pGstreamer_s->pipeline);
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        pGstreamer_s->appsink = gst_element_factory_make("appsink" , "appsink");
        if (!pGstreamer_s->appsink) {
                gstcs_error("appsink could not be created. Exiting.\n");
-               ret = GSTCS_ERROR_INVALID_PARAMETER;
+               gst_object_unref(pGstreamer_s->pipeline);
+               return GSTCS_ERROR_INVALID_PARAMETER;
        }
        return ret;
 }
@@ -272,6 +278,7 @@ static GstCaps* _mm_get_capabilities(mm_util_color_format_e color_format, unsign
        GstVideoFormat videoFormat = GST_VIDEO_FORMAT_UNKNOWN;
 
        videoFormat = _mm_get_video_format(color_format);
+       gstcs_retvm_if(videoFormat == GST_VIDEO_FORMAT_UNKNOWN, NULL, "Unkown video format (%d)", color_format);
 
        caps = gst_caps_new_simple("video/x-raw",
                        "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
@@ -455,8 +462,10 @@ static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *s
 
        /*create pipeline*/
        ret = _mm_create_pipeline(pGstreamer_s);
-       if (ret != GSTCS_ERROR_NONE)
+       if (ret != GSTCS_ERROR_NONE) {
                gstcs_error("ERROR - mm_create_pipeline ");
+               return ret;
+       }
 
        /* Make appsink emit the "new-preroll" and "new-sample" signals. This option is by default disabled because signal emission is expensive and unneeded when the application prefers to operate in pull mode. */
        gst_app_sink_set_emit_signals((GstAppSink*)pGstreamer_s->appsink, TRUE);
@@ -470,6 +479,13 @@ static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *s
 
        src_caps = _mm_get_capabilities(pImgp_info->src_format, src_stride, src_elevation);
        dst_caps = _mm_get_capabilities(pImgp_info->dst_format, pImgp_info->output_stride, pImgp_info->output_elevation);
+       if (src_caps == NULL || dst_caps == NULL) {
+               gstcs_error("ERROR - _mm_get_capabilities ");
+               SAFE_UNREF_CAPS(src_caps);
+               SAFE_UNREF_CAPS(dst_caps);
+               gst_object_unref(pGstreamer_s->pipeline);
+               return ret;
+       }
 
        gst_app_src_set_caps(GST_APP_SRC(pGstreamer_s->appsrc), src_caps);
        gst_app_sink_set_caps(GST_APP_SINK(pGstreamer_s->appsink), dst_caps);
@@ -482,10 +498,8 @@ static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *s
 
        if (ret != GSTCS_ERROR_NONE) {
                gstcs_error("ERROR - mm_push_buffer_into_pipeline ");
-               if (src_caps)
-                       gst_caps_unref(src_caps);
-               if (dst_caps)
-                       gst_caps_unref(dst_caps);
+               SAFE_UNREF_CAPS(src_caps);
+               SAFE_UNREF_CAPS(dst_caps);
                gst_object_unref(pGstreamer_s->pipeline);
                return ret;
        }
@@ -524,10 +538,8 @@ static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *s
 
        gstcs_debug("Success gst_element_get_state\n");
 
-       if (src_caps)
-               gst_caps_unref(src_caps);
-       if (dst_caps)
-               gst_caps_unref(dst_caps);
+       SAFE_UNREF_CAPS(src_caps);
+       SAFE_UNREF_CAPS(dst_caps);
 
        if (ret_state == GST_STATE_CHANGE_FAILURE) {
                gstcs_error("GST_STATE_CHANGE_FAILURE");
index a6ddc6e..6e5098b 100644 (file)
@@ -1,7 +1,6 @@
-#sbs-git:slp/pkgs/l/libmm-imgp-gstcs libmm-imgp-gstcs 0.1 62b62e6d483557fc5750d1b4986e9a98323f1194
 Name:       libmm-imgp-gstcs
 Summary:    Multimedia Framework Utility Library
-Version:    0.20
+Version:    0.21
 Release:    16
 Group:      System/Libraries
 License:    Apache-2.0