webrtc_source: Reduce duplicate codes in __build_audiosrc()/__build_custom_audiosrc() 09/274109/2
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 21 Apr 2022 10:47:43 +0000 (19:47 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 21 Apr 2022 11:02:37 +0000 (20:02 +0900)
New sub function is introduced.

[Version] 0.3.91
[Issue Type] Refactoring

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

index 7f4db4306dc2acef0c17ddc873be52deb1e735e6..0ca9f639fec416aa3c2bfb3eb22e373b4e7852e0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.90
+Version:    0.3.91
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 81779e53e66cc112872e2b8f706004f9bd2afc7d..d5b2bf303fc1a188626311439a60d048799c2376 100644 (file)
@@ -1521,37 +1521,27 @@ exit:
        return ret;
 }
 
-static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool use_mic)
+static int __build_rest_of_audiosrc(webrtc_s *webrtc, GstPad *src_pad, GstElement *audiosrc_element, webrtc_gst_slot_s *source)
 {
        int ret = WEBRTC_ERROR_NONE;
-       const char *source_factory_name;
-       GstElement *audiosrc;
+       GList *element_list = NULL;
        GstElement *volume;
        GstElement *capsfilter;
-       GList *element_list = NULL;
-       GstPad *src_pad;
        const ini_item_media_source_s *ini_source;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL");
+       RET_VAL_IF(audiosrc_element == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "audiosrc_element 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");
 
-       ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad);
-       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
-
-       source->media_types = MEDIA_TYPE_AUDIO;
-       source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
-
-       source_factory_name = __get_source_element(webrtc, use_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST);
-       if (!(audiosrc = _create_element(source_factory_name, use_mic ? ELEMENT_NAME_MIC_SRC : NULL)))
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       APPEND_ELEMENT(element_list, audiosrc);
+       APPEND_ELEMENT(element_list, audiosrc_element);
 
        if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
                LOG_ERROR("ini_source is NULL");
                goto exit;
        }
-       _gst_set_element_properties(audiosrc, ini_source->source_element_properties);
+       _gst_set_element_properties(audiosrc_element, ini_source->source_element_properties);
 
        if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
                goto exit;
@@ -1596,6 +1586,30 @@ exit:
        return ret;
 }
 
+static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool use_mic)
+{
+       int ret;
+       const char *source_factory_name;
+       GstPad *src_pad;
+       GstElement *audiosrc;
+
+       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");
+
+       ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
+
+       source->media_types = MEDIA_TYPE_AUDIO;
+       source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
+
+       source_factory_name = __get_source_element(webrtc, use_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST);
+       if (!(audiosrc = _create_element(source_factory_name, use_mic ? ELEMENT_NAME_MIC_SRC : NULL)))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
+       return __build_rest_of_audiosrc(webrtc, src_pad, audiosrc, source);
+}
+
 static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
        int ret = WEBRTC_ERROR_NONE;
@@ -1729,14 +1743,10 @@ exit:
 
 static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
-       int ret = WEBRTC_ERROR_NONE;
+       int ret;
        const char *source_factory_name;
        GstElement *custom_audiosrc;
-       GstElement *volume;
-       GstElement *capsfilter;
-       GList *element_list = NULL;
        GstPad *src_pad;
-       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");
@@ -1751,55 +1761,8 @@ static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        source_factory_name = __get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO);
        if (!(custom_audiosrc = _create_element(source_factory_name, NULL)))
                return WEBRTC_ERROR_INVALID_OPERATION;
-       APPEND_ELEMENT(element_list, custom_audiosrc);
-
-       if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
-               LOG_ERROR("ini_source is NULL");
-               goto exit;
-       }
-       _gst_set_element_properties(custom_audiosrc, ini_source->source_element_properties);
-
-       if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
-               goto exit;
-       APPEND_ELEMENT(element_list, volume);
-
-       source->av[AV_IDX_AUDIO].inbandfec = ini_source->use_inbandfec;
-       source->av[AV_IDX_AUDIO].packet_loss_percentage = ini_source->packet_loss_percentage;
-
-       if ((ret = __create_rest_of_elements(webrtc, source, true, &element_list, true)) != WEBRTC_ERROR_NONE)
-               goto exit;
-
-       if (!__add_elements_to_bin(source->bin, element_list)) {
-               SAFE_G_LIST_FREE(element_list);
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
 
-       if (!__link_elements(element_list)) {
-               ret = WEBRTC_ERROR_INVALID_OPERATION;
-               goto exit_with_remove_from_bin;
-       }
-
-       if (!(capsfilter = gst_bin_get_by_name(source->bin, ELEMENT_NAME_RTP_CAPSFILTER))) {
-               ret = WEBRTC_ERROR_INVALID_OPERATION;
-               goto exit_with_remove_from_bin;
-       }
-       ret = _set_ghost_pad_target(src_pad, capsfilter, true);
-       if (ret != WEBRTC_ERROR_NONE)
-               goto exit_with_remove_from_bin;
-
-       __add_probe_to_pad_for_pause(source, AV_IDX_AUDIO, src_pad, __payloaded_data_probe_cb);
-
-       SAFE_G_LIST_FREE(element_list);
-
-       return WEBRTC_ERROR_NONE;
-
-exit_with_remove_from_bin:
-       __remove_elements_from_bin(source->bin, element_list);
-       SAFE_G_LIST_FREE(element_list);
-       return ret;
-exit:
-       SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
-       return ret;
+       return __build_rest_of_audiosrc(webrtc, src_pad, custom_audiosrc, source);
 }
 
 static int __build_filesrc_bin(webrtc_gst_slot_s *source, media_type_e media_type)