From: Sangchul Lee Date: Thu, 21 Apr 2022 10:47:43 +0000 (+0900) Subject: webrtc_source: Reduce duplicate codes in __build_audiosrc()/__build_custom_audiosrc() X-Git-Tag: submit/tizen/20220426.020921~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F274109%2F2;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Reduce duplicate codes in __build_audiosrc()/__build_custom_audiosrc() New sub function is introduced. [Version] 0.3.91 [Issue Type] Refactoring Change-Id: I0e0a6f678c710912c864b9652e10dc57689efaf3 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 7f4db430..0ca9f639 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 81779e53..d5b2bf30 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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)