webrtc_source: Add sub-function to check params and get ini source 63/276863/5
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 27 Jun 2022 06:54:02 +0000 (15:54 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jul 2022 06:50:07 +0000 (15:50 +0900)
[Version] 0.3.142
[Issue Type] Refactoring

Change-Id: I27dc6ea768b64e730e2e06d9ed1327fbd289c75a
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_source.c

index 49308471ce01dae54dfb4fb6e5d83ef57c8abaee..5748d9d60ad1ceca01565b435c7281f2a0332390 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.141
+Version:    0.3.142
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index c3b04717c6e9b1c640d6ba784a00079a1d223117..2ac34d9645c6b978b40b86a6d57fd92a611263b2 100644 (file)
@@ -1379,6 +1379,21 @@ static bool __set_default_video_info(webrtc_gst_slot_s *source, const ini_item_m
        return true;
 }
 
+static int __build_src_check_params_and_get_ini_source(webrtc_s *webrtc, webrtc_gst_slot_s *source, const ini_item_media_source_s **ini_source)
+{
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+       RET_VAL_IF(ini_source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ini_source is NULL");
+       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
+
+       if (!(*ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
+               LOG_ERROR("ini_source is NULL");
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+
+       return WEBRTC_ERROR_NONE;
+}
+
 static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
        int ret;
@@ -1388,14 +1403,8 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        GstElement *videoswitch = NULL;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               goto exit;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
@@ -1620,14 +1629,8 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        GstElement *camerasrc;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
@@ -1665,20 +1668,15 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 
 static int __complete_rest_of_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
+       int ret;
        GList *element_list = NULL;
        GstElement *audiosrc;
        GstElement *volume;
        GstElement *capsfilter;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        /* skip when it is already completed. e.g) start() -> stop() -> start() again */
        if (source->av[AV_IDX_AUDIO].render.src_pad_probe_id > 0)
@@ -1799,14 +1797,8 @@ static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool us
        GstElement *audiosrc;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_AUDIO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
@@ -1837,14 +1829,8 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        GstElement *videotestsrc;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
@@ -1878,14 +1864,8 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        GstElement *custom_videosrc;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
@@ -1918,14 +1898,8 @@ static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        GstElement *custom_audiosrc;
        const ini_item_media_source_s *ini_source;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()");
 
        ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_AUDIO].src_pad);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");