webrtc_source_private: move _link_source_with_webrtcbin() to webrtc_source_private.c 20/278720/2
authorhj kim <backto.kim@samsung.com>
Mon, 25 Jul 2022 09:21:21 +0000 (18:21 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 25 Jul 2022 23:53:01 +0000 (08:53 +0900)
[Version] 0.3.169
[Issue Type] Refactoring

Change-Id: I8989d95945111ce7b84aaf19a22cca19a873a445

include/webrtc_source_private.h
packaging/capi-media-webrtc.spec
src/webrtc_source.c
src/webrtc_source_private.c

index 341d72ca0d643e137acccae6ce4bbe3bd9337814..f940dfef0f45f4873ff0abe73d301cc1520f4a42 100644 (file)
@@ -106,5 +106,6 @@ void _remove_probe_from_pad_for_render(webrtc_gst_slot_s *source, unsigned int i
 rtp_payload_info_s * _get_payload_info(webrtc_transceiver_codec_e codec);
 rtp_payload_info_s * _get_payload_info_by_encoding_name(const char *encoding_name);
 int _add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, rtp_payload_info_s *payload_info);
+int _link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin);
 
 #endif /* __TIZEN_MEDIA_WEBRTC_SOURCE_COMMON_H__ */
index de71b7008509f711e3a1db7bc629bda299cc1fcf..1c9d17f555a1b681be4ae14666999b0e534b6895 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.168
+Version:    0.3.169
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 172f6ac9f492ea728b4d065c76919c2cba8dc8ba..1806f60b4d34d5488775d547f7abfff3e3074287 100644 (file)
@@ -33,7 +33,6 @@ static direction_info_s __direction_info[] = {
        [WEBRTC_TRANSCEIVER_DIRECTION_SENDRECV] = { "SENDRECV", GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV }
 };
 
-static int __link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin);
 static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad,  GstPadProbeInfo *info, gpointer u_data);
 
 static GstCaps *__make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source, webrtc_ini_s *ini, int width, int height)
@@ -710,7 +709,7 @@ static int __complete_rest_of_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *sour
        if (_set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true) != WEBRTC_ERROR_NONE)
                goto exit_with_remove_from_bin;
 
-       if (__link_source_with_webrtcbin(source, webrtc->gst.webrtcbin) != WEBRTC_ERROR_NONE)
+       if (_link_source_with_webrtcbin(source, webrtc->gst.webrtcbin) != WEBRTC_ERROR_NONE)
                goto exit_with_remove_from_bin;
 
        _add_probe_to_pad_for_pause(source, AV_IDX_VIDEO, source->av[AV_IDX_VIDEO].src_pad, _payloaded_data_probe_cb);
@@ -824,7 +823,7 @@ static int __complete_rest_of_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *sour
        if (_set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter, true) != WEBRTC_ERROR_NONE)
                goto exit_with_remove_from_bin;
 
-       if (__link_source_with_webrtcbin(source, webrtc->gst.webrtcbin) != WEBRTC_ERROR_NONE)
+       if (_link_source_with_webrtcbin(source, webrtc->gst.webrtcbin) != WEBRTC_ERROR_NONE)
                goto exit_with_remove_from_bin;
 
        _add_probe_to_pad_for_pause(source, AV_IDX_AUDIO, source->av[AV_IDX_AUDIO].src_pad, _payloaded_data_probe_cb);
@@ -1426,9 +1425,9 @@ static void __filesrc_pipeline_decodebin_pad_added_cb(GstElement *element, GstPa
                return;
        }
 
-       ret = __link_source_with_webrtcbin(source, source->webrtc->gst.webrtcbin);
+       ret = _link_source_with_webrtcbin(source, source->webrtc->gst.webrtcbin);
        if (ret != WEBRTC_ERROR_NONE) {
-               LOG_ERROR("failed to __link_source_with_webrtcbin()");
+               LOG_ERROR("failed to _link_source_with_webrtcbin()");
                __remove_rest_of_elements_for_filesrc_pipeline(source, is_audio);
                g_hash_table_remove(source->webrtc->gst.source_slots, GST_ELEMENT_NAME(source->bin));
                return;
@@ -1736,86 +1735,6 @@ void _source_slot_destroy_cb(gpointer data)
        g_free(source);
 }
 
-static bool __is_linked_pad(webrtc_gst_slot_s *source, const char *pad_name)
-{
-       GstIterator *iter = NULL;
-       GValue item = { 0, };
-       GstPad *pad = NULL;
-       bool linked = false;
-
-       RET_VAL_IF(source == NULL, false, "source is NULL");
-
-       iter = gst_element_iterate_src_pads(GST_ELEMENT(source->bin));
-
-       while (GST_ITERATOR_OK == gst_iterator_next(iter, &item)) {
-               pad = g_value_get_object(&item);
-               if (g_strrstr(GST_PAD_NAME(pad), pad_name)) {
-                       if (gst_pad_is_linked(pad))
-                               linked = true;
-                       break;
-               }
-               g_value_reset(&item);
-       }
-       g_value_unset(&item);
-       gst_iterator_free(iter);
-
-       return linked;
-}
-
-static int __link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin)
-{
-       int ret = WEBRTC_ERROR_NONE;
-       GstPad *sinkpad;
-       gchar *sinkpad_name = NULL;
-       gchar *srcpad_name = NULL;
-
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(webrtcbin == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtcbin is NULL");
-
-       if (!(sinkpad = gst_element_request_pad_simple(webrtcbin, "sink_%u"))) {
-               LOG_ERROR("failed to gst_element_get_request_pad()");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
-       if (!(sinkpad_name = gst_pad_get_name(sinkpad))) {
-               LOG_ERROR("failed to gst_pad_get_name()");
-               ret = WEBRTC_ERROR_INVALID_OPERATION;
-               goto exit;
-       }
-
-       if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) {
-               if ((source->media_types & MEDIA_TYPE_AUDIO) && !__is_linked_pad(source, "audio"))
-                       srcpad_name = g_strdup_printf("audio_src_%u", source->id);
-               else if ((source->media_types & MEDIA_TYPE_VIDEO) && !__is_linked_pad(source, "video"))
-                       srcpad_name = g_strdup_printf("video_src_%u", source->id);
-
-               if (!srcpad_name) {
-                       LOG_ERROR("fail to get srcpad_name");
-                       ret = WEBRTC_ERROR_INVALID_OPERATION;
-                       goto exit;
-               }
-       } else {
-               srcpad_name = g_strdup_printf("src_%u", source->id);
-       }
-
-       if (!gst_element_link_pads(GST_ELEMENT(source->bin), srcpad_name, webrtcbin, sinkpad_name)) {
-               LOG_ERROR("failed to link pads, [%s:%s] - [%s:%s]",
-                       GST_ELEMENT_NAME(source->bin), srcpad_name, GST_ELEMENT_NAME(webrtcbin), sinkpad_name);
-               ret = WEBRTC_ERROR_INVALID_OPERATION;
-               goto exit;
-       }
-       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
-               GST_ELEMENT_NAME(source->bin), srcpad_name, GST_ELEMENT_NAME(webrtcbin), sinkpad_name);
-
-exit:
-       g_free(sinkpad_name);
-       g_free(srcpad_name);
-       if (ret != WEBRTC_ERROR_NONE) {
-               gst_element_release_request_pad(webrtcbin, sinkpad);
-               g_object_unref(sinkpad);
-       }
-       return ret;
-}
-
 static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **source, gchar **name)
 {
        unsigned int id;
@@ -2573,7 +2492,7 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f
                goto error;
        }
 
-       ret = __link_source_with_webrtcbin(source, webrtc->gst.webrtcbin);
+       ret = _link_source_with_webrtcbin(source, webrtc->gst.webrtcbin);
        if (ret != WEBRTC_ERROR_NONE)
                goto error;
 
index 337d33079121c5608b3e26938a6db88607a266c9..7b2341630b93fa67b24fbaf6c8e50fa3158b6917 100644 (file)
@@ -651,3 +651,83 @@ int _add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e media_type,
 
        return WEBRTC_ERROR_NONE;
 }
+
+static bool __is_linked_pad(webrtc_gst_slot_s *source, const char *pad_name)
+{
+       GstIterator *iter = NULL;
+       GValue item = { 0, };
+       GstPad *pad = NULL;
+       bool linked = false;
+
+       RET_VAL_IF(source == NULL, false, "source is NULL");
+
+       iter = gst_element_iterate_src_pads(GST_ELEMENT(source->bin));
+
+       while (GST_ITERATOR_OK == gst_iterator_next(iter, &item)) {
+               pad = g_value_get_object(&item);
+               if (g_strrstr(GST_PAD_NAME(pad), pad_name)) {
+                       if (gst_pad_is_linked(pad))
+                               linked = true;
+                       break;
+               }
+               g_value_reset(&item);
+       }
+       g_value_unset(&item);
+       gst_iterator_free(iter);
+
+       return linked;
+}
+
+int _link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       GstPad *sinkpad;
+       gchar *sinkpad_name = NULL;
+       gchar *srcpad_name = NULL;
+
+       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+       RET_VAL_IF(webrtcbin == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtcbin is NULL");
+
+       if (!(sinkpad = gst_element_request_pad_simple(webrtcbin, "sink_%u"))) {
+               LOG_ERROR("failed to gst_element_get_request_pad()");
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+       if (!(sinkpad_name = gst_pad_get_name(sinkpad))) {
+               LOG_ERROR("failed to gst_pad_get_name()");
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit;
+       }
+
+       if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) {
+               if ((source->media_types & MEDIA_TYPE_AUDIO) && !__is_linked_pad(source, "audio"))
+                       srcpad_name = g_strdup_printf("audio_src_%u", source->id);
+               else if ((source->media_types & MEDIA_TYPE_VIDEO) && !__is_linked_pad(source, "video"))
+                       srcpad_name = g_strdup_printf("video_src_%u", source->id);
+
+               if (!srcpad_name) {
+                       LOG_ERROR("fail to get srcpad_name");
+                       ret = WEBRTC_ERROR_INVALID_OPERATION;
+                       goto exit;
+               }
+       } else {
+               srcpad_name = g_strdup_printf("src_%u", source->id);
+       }
+
+       if (!gst_element_link_pads(GST_ELEMENT(source->bin), srcpad_name, webrtcbin, sinkpad_name)) {
+               LOG_ERROR("failed to link pads, [%s:%s] - [%s:%s]",
+                       GST_ELEMENT_NAME(source->bin), srcpad_name, GST_ELEMENT_NAME(webrtcbin), sinkpad_name);
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit;
+       }
+       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
+               GST_ELEMENT_NAME(source->bin), srcpad_name, GST_ELEMENT_NAME(webrtcbin), sinkpad_name);
+
+exit:
+       g_free(sinkpad_name);
+       g_free(srcpad_name);
+       if (ret != WEBRTC_ERROR_NONE) {
+               gst_element_release_request_pad(webrtcbin, sinkpad);
+               g_object_unref(sinkpad);
+       }
+       return ret;
+}