webrtc_source: Merge __build_audiosrc() with __build_audiotestsrc() 59/259459/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 8 Jun 2021 09:04:49 +0000 (18:04 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 8 Jun 2021 09:05:11 +0000 (18:05 +0900)
[Version] 0.2.6
[Issue Type] Refactoring

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

index 3611f0b15fbcbf9609374d56aa94d881ee05f5a9..48a93cea02e3dd2c6e526387ab0362954911d30b 100644 (file)
@@ -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
index 310ab33fa8ceff39b33bfe8b4a45f6541ec43d3f..c051d01fdb92453f236d9a2530506b661eb2f277 100644 (file)
@@ -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);