From: Sangchul Lee Date: Tue, 8 Jun 2021 09:04:49 +0000 (+0900) Subject: webrtc_source: Merge __build_audiosrc() with __build_audiotestsrc() X-Git-Tag: submit/tizen/20210729.023123~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F59%2F259459%2F1;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Merge __build_audiosrc() with __build_audiotestsrc() [Version] 0.2.6 [Issue Type] Refactoring Change-Id: Ice41abc6e0b92de41bacc95fac7dc2dd620df018 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 3611f0b1..48a93cea 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.2.5 +Version: 0.2.6 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 310ab33f..c051d01f 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -1001,9 +1001,10 @@ exit: return ret; } -static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) +static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool is_mic) { int ret = WEBRTC_ERROR_NONE; + const char *source_factory_name; GstElement *audiosrc; GstElement *volume = NULL; GstElement *capsfilter = NULL; @@ -1022,9 +1023,13 @@ static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) source->media_types = MEDIA_TYPE_AUDIO; source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types); - if (!(audiosrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_MIC), NULL))) + source_factory_name = __get_source_element(webrtc, is_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST); + if (!(audiosrc = _create_element(source_factory_name, NULL))) return WEBRTC_ERROR_INVALID_OPERATION; + if (!is_mic) + g_object_set(G_OBJECT(audiosrc), "is-live", TRUE, NULL); + if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME))) goto exit; @@ -1118,68 +1123,6 @@ exit: return ret; } -static int __build_audiotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) -{ - int ret = WEBRTC_ERROR_NONE; - GstElement *audiotestsrc; - GstElement *volume = NULL; - GstElement *capsfilter = NULL; - GstElement *audioenc = NULL; - GstElement *audiopay = NULL; - GstElement *queue = NULL; - GstElement *capsfilter2 = NULL; - - 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, &source->av[AV_IDX_AUDIO].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); - - if (!(audiotestsrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST), NULL))) - return WEBRTC_ERROR_INVALID_OPERATION; - - g_object_set(G_OBJECT(audiotestsrc), "is-live", TRUE, NULL); - - if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME))) - goto exit; - - if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE) - goto exit; - - gst_bin_add_many(source->bin, audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL); - if (!gst_element_link_many(audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL)) { - LOG_ERROR("failed to gst_element_link_many()"); - ret = WEBRTC_ERROR_INVALID_OPERATION; - goto exit_with_remove_from_bin; - } - - ret = _set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter2, true); - if (ret != WEBRTC_ERROR_NONE) - goto exit_with_remove_from_bin; - - __add_probe_to_pad(source->av[AV_IDX_AUDIO].src_pad, MEDIA_TYPE_AUDIO, source); - - return WEBRTC_ERROR_NONE; - -exit_with_remove_from_bin: - /* elements will be dereferenced */ - gst_bin_remove_many(source->bin, audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL); - return ret; -exit: - SAFE_GST_OBJECT_UNREF(audiotestsrc); - SAFE_GST_OBJECT_UNREF(volume); - SAFE_GST_OBJECT_UNREF(capsfilter); - SAFE_GST_OBJECT_UNREF(audioenc); - SAFE_GST_OBJECT_UNREF(audiopay); - SAFE_GST_OBJECT_UNREF(queue); - SAFE_GST_OBJECT_UNREF(capsfilter2); - return ret; -} - static void _appsrc_need_data_cb(GstElement *appsrc, guint size, gpointer data) { webrtc_gst_slot_s *source = (webrtc_gst_slot_s*)data; @@ -1393,13 +1336,13 @@ static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source) return __build_camerasrc(webrtc, source); case WEBRTC_MEDIA_SOURCE_TYPE_MIC: - return __build_audiosrc(webrtc, source); + return __build_audiosrc(webrtc, source, true); case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: return __build_videotestsrc(webrtc, source); case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: - return __build_audiotestsrc(webrtc, source); + return __build_audiosrc(webrtc, source, false); case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET: return __build_mediapacketsrc(webrtc, source);