From 3cb5c206bc065527704bf00e54d587b48a4d5c3c Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Mon, 4 Mar 2019 09:02:51 +0900 Subject: Add error handling for getting gst_caps Change-Id: I8a80de7404f8ec9e2c55e958ebf45b5c141c780d --- gstcs/include/mm_util_gstcs.h | 0 gstcs/mm_util_gstcs.c | 42 ++++++++++++++++++++++++++--------------- packaging/libmm-imgp-gstcs.spec | 3 +-- 3 files changed, 28 insertions(+), 17 deletions(-) mode change 100755 => 100644 gstcs/include/mm_util_gstcs.h diff --git a/gstcs/include/mm_util_gstcs.h b/gstcs/include/mm_util_gstcs.h old mode 100755 new mode 100644 diff --git a/gstcs/mm_util_gstcs.c b/gstcs/mm_util_gstcs.c index ed130bb..f1a0344 100644 --- a/gstcs/mm_util_gstcs.c +++ b/gstcs/mm_util_gstcs.c @@ -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"); diff --git a/packaging/libmm-imgp-gstcs.spec b/packaging/libmm-imgp-gstcs.spec index a6ddc6e..6e5098b 100644 --- a/packaging/libmm-imgp-gstcs.spec +++ b/packaging/libmm-imgp-gstcs.spec @@ -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 -- cgit v1.2.3