webrtc_sink: Add sub-function to set ghost pad target and link pads 27/277227/5
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jul 2022 03:58:22 +0000 (12:58 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jul 2022 11:22:32 +0000 (20:22 +0900)
[Version] 0.3.143
[Issue Type] Refactoring

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

index 5748d9d60ad1ceca01565b435c7281f2a0332390..6a1165803c3b50c30e7959ba11d7e7933b0eff1d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.142
+Version:    0.3.143
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 9c1feb229334d66a6e164cd5bae90fd4818933da..b3db26b23547a4a9327faa90d908cbf2060a4cfe 100644 (file)
@@ -545,13 +545,49 @@ static int __alloc_sink_slot(webrtc_s *webrtc, const gchar *pad_name, bool forwa
        return WEBRTC_ERROR_NONE;
 }
 
+static int __link_pads(webrtc_s *webrtc, GstPad *src_pad, webrtc_gst_slot_s *sink, GstElement *sink_target_elem)
+{
+       GstPad *sink_pad = NULL;
+
+       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(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink is NULL");
+       RET_VAL_IF(sink_target_elem == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink_target_elem is NULL");
+
+       if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE)
+               goto error;
+
+       if (_set_ghost_pad_target(sink_pad, sink_target_elem, false) != WEBRTC_ERROR_NONE)
+               goto error;
+
+       if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(sink->bin))) {
+               LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(sink->bin), GST_ELEMENT_NAME(webrtc->gst.pipeline));
+               goto error;
+       }
+
+       if (gst_pad_link(src_pad, sink_pad) != GST_PAD_LINK_OK) {
+               LOG_ERROR("failed to gst_pad_link(), %s:%s", GST_PAD_NAME(src_pad), GST_PAD_NAME(sink_pad));
+               goto error;
+       }
+
+       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
+               GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_PAD_NAME(src_pad), GST_ELEMENT_NAME(sink->bin), GST_PAD_NAME(sink_pad));
+
+       return WEBRTC_ERROR_NONE;
+
+error:
+       if (sink_pad)
+               gst_object_unref(sink_pad);
+
+       return WEBRTC_ERROR_INVALID_OPERATION;
+}
+
 int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
 {
        gchar *bin_name;
        gchar *track_name;
        webrtc_gst_slot_s *sink;
        GstElement *decodebin;
-       GstPad *sink_pad = NULL;
 
        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");
@@ -563,36 +599,19 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
 
        g_free(bin_name);
 
-       decodebin = _create_element("decodebin", track_name);
-       if (!decodebin)
+       if (!(decodebin = _create_element("decodebin", track_name)))
                goto error_before_insert;
 
        sink->av[GET_AV_IDX(is_audio)].pt = _get_payload_type_from_pad(src_pad);
 
-       gst_bin_add(sink->bin, decodebin);
-
        g_signal_connect(decodebin, "pad-added", G_CALLBACK(__decodebin_pad_added_cb), webrtc);
        g_signal_connect(decodebin, "autoplug-select", G_CALLBACK(_decodebin_autoplug_select_cb), webrtc);
        g_signal_connect(decodebin, "element-added", G_CALLBACK(__decodebin_element_added_cb), sink);
 
-       if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE)
-               goto error_before_insert;
-
-       if (_set_ghost_pad_target(sink_pad, decodebin, false) != WEBRTC_ERROR_NONE)
-               goto error_before_insert;
-
-       if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(sink->bin))) {
-               LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(sink->bin), GST_ELEMENT_NAME(webrtc->gst.pipeline));
-               goto error_before_insert;
-       }
+       gst_bin_add(sink->bin, decodebin);
 
-       if (gst_pad_link(src_pad, sink_pad) != GST_PAD_LINK_OK) {
-               LOG_ERROR("failed to gst_pad_link(), %s:%s", GST_PAD_NAME(src_pad), GST_PAD_NAME(sink_pad));
+       if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE)
                goto error_before_insert;
-       }
-
-       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
-               GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_PAD_NAME(src_pad), GST_ELEMENT_NAME(sink->bin), GST_PAD_NAME(sink_pad));
 
        if (!g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)) {
                LOG_ERROR("should not be reached here, track_name[%s] already exist, sink id[%u] will be removed", track_name, sink->id);
@@ -611,8 +630,8 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
        return WEBRTC_ERROR_NONE;
 
 error_before_insert:
-       if (sink_pad)
-               gst_object_unref(sink_pad);
+       if (decodebin)
+               gst_object_unref(GST_OBJECT(decodebin));
        g_free(track_name);
        g_free(sink);
 
@@ -892,7 +911,6 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
        GstElement *fakesink = NULL;
        GstCaps *sink_caps;
        webrtc_gst_slot_s *sink;
-       GstPad *sink_pad = NULL;
 
        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");
@@ -908,15 +926,13 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
        if (!depayloader)
                goto error_before_insert;
 
-       fakesink = _create_element(DEFAULT_ELEMENT_FAKESINK, NULL);
-       if (!fakesink)
+       if (!(fakesink = _create_element(DEFAULT_ELEMENT_FAKESINK, NULL)))
                goto error_before_insert;
 
        g_object_set(G_OBJECT(fakesink), "signal-handoffs", TRUE, NULL);
        _connect_and_append_signal(&sink->signals, (GObject *)fakesink, "handoff", G_CALLBACK(__encoded_stream_cb), sink);
 
-       capsfilter = _create_element(DEFAULT_ELEMENT_CAPSFILTER, NULL);
-       if (!capsfilter)
+       if (!(capsfilter = _create_element(DEFAULT_ELEMENT_CAPSFILTER, NULL)))
                goto error_before_insert;
 
        if ((sink_caps = __make_caps_if_h264_or_h265(src_pad))) {
@@ -927,29 +943,13 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
 
        gst_bin_add_many(sink->bin, depayloader, capsfilter, fakesink, NULL);
 
-       if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE)
-               goto error_before_insert;
-
-       if (_set_ghost_pad_target(sink_pad, depayloader, false) != WEBRTC_ERROR_NONE)
-               goto error_before_insert;
-
        if (!gst_element_link_many(depayloader, capsfilter, fakesink, NULL)) {
                LOG_ERROR("failed to gst_element_link_many()");
                goto error_before_insert;
        }
 
-       if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(sink->bin))) {
-               LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(sink->bin), GST_ELEMENT_NAME(webrtc->gst.pipeline));
-               goto error_before_insert;
-       }
-
-       if (gst_pad_link(src_pad, sink_pad) != GST_PAD_LINK_OK) {
-               LOG_ERROR("failed to gst_pad_link(), %s:%s", GST_PAD_NAME(src_pad), GST_PAD_NAME(sink_pad));
+       if (__link_pads(webrtc, src_pad, sink, depayloader) != WEBRTC_ERROR_NONE)
                goto error_before_insert;
-       }
-
-       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
-               GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_PAD_NAME(src_pad), GST_ELEMENT_NAME(sink->bin), GST_PAD_NAME(sink_pad));
 
        if (!g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)) {
                LOG_ERROR("should not be reached here, track_name[%s] already exist, sink id[%u] will be removed", track_name, sink->id);
@@ -973,10 +973,10 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
        return WEBRTC_ERROR_NONE;
 
 error_before_insert:
-       if (sink_pad)
-               gst_object_unref(GST_OBJECT(sink_pad));
        if (depayloader)
                gst_object_unref(GST_OBJECT(depayloader));
+       if (capsfilter)
+               gst_object_unref(GST_OBJECT(capsfilter));
        if (fakesink)
                gst_object_unref(GST_OBJECT(fakesink));
        g_free(track_name);