webrtc_source: Postpone the link timing in case of media packet source 72/251872/5
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 20 Jan 2021 07:34:35 +0000 (16:34 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 25 Jan 2021 05:41:25 +0000 (14:41 +0900)
These is an issue that could not set transceiver direction to media
packet source. In case of media packet source, the media type is
determined when setting the format of the source by API. It affects
this issue because the media type which is not set yet is used inside
of the new transceiver callback triggered by reqeust pad to the webrtcbin
to link with the source.

This patch postphones the link timing including trigger of new transceiver
callback to avoid the fault.

[Version] 0.1.84
[Issue Type] Bug fix

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

index 9763151f2f59523a29520f967ca926807ca03e74..198c77251a7ac77909ba727acc0c32f3bffb5c24 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.83
+Version:    0.1.84
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 8a3b17ad2043ada0632dd2872d4dab56cd664a75..2a7a54ca0ee28e3130118417c7f20622350611c4 100644 (file)
@@ -1096,15 +1096,51 @@ void _source_slot_destroy_cb(gpointer data)
        g_free(source);
 }
 
+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_get_request_pad(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;
+       }
+       srcpad_name = g_strdup_printf("src_%u", source->id);
+       if (!gst_element_link_pads(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;
+}
+
 int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigned int *source_id)
 {
        int ret = WEBRTC_ERROR_NONE;
        unsigned int id;
        webrtc_gst_slot_s *source = NULL;
        gchar *bin_name = NULL;
-       GstPad *webrtc_sinkpad;
-       gchar *webrtc_sinkpad_name;
-       gchar *bin_srcpad_name = NULL;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
@@ -1138,34 +1174,20 @@ int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigne
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
 
-       if (!(webrtc_sinkpad = gst_element_get_request_pad(webrtc->gst.webrtcbin, "sink_%u"))) {
-               LOG_ERROR("failed to gst_element_get_request_pad()");
-               goto error_after_insert;
-       }
-       if (!(webrtc_sinkpad_name = gst_pad_get_name(webrtc_sinkpad))) {
-               LOG_ERROR("failed to gst_pad_get_name()");
-               goto error_after_insert;
-       }
-       bin_srcpad_name = g_strdup_printf("src_%u", id);
-       if (!gst_element_link_pads(source->bin, bin_srcpad_name, webrtc->gst.webrtcbin, webrtc_sinkpad_name)) {
-               LOG_ERROR("failed to link pads, [%s:%s] - [%s:%s]",
-                       GST_ELEMENT_NAME(source->bin), bin_srcpad_name, GST_ELEMENT_NAME(webrtc->gst.webrtcbin), webrtc_sinkpad_name);
+       if (type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET &&
+               __link_source_with_webrtcbin(source, webrtc->gst.webrtcbin) != WEBRTC_ERROR_NONE) {
+               LOG_ERROR("failed to __link_source_with_webrtcbin()");
                goto error_after_insert;
        }
-       LOG_DEBUG("link pads successfully, [%s:%s] - [%s:%s]",
-               GST_ELEMENT_NAME(source->bin), bin_srcpad_name, GST_ELEMENT_NAME(webrtc->gst.webrtcbin), webrtc_sinkpad_name);
 
        *source_id = id;
 
        LOG_INFO("added a source slot[%p, id:%u]", source, source->id);
 
-       g_free(bin_srcpad_name);
-
        return WEBRTC_ERROR_NONE;
 
 error_after_insert:
        g_hash_table_remove(webrtc->gst.source_slots, bin_name);
-       g_free(bin_srcpad_name);
 
        return WEBRTC_ERROR_INVALID_OPERATION;
 
@@ -1244,7 +1266,7 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f
                return ret;
        }
 
-       return WEBRTC_ERROR_NONE;
+       return __link_source_with_webrtcbin(source, webrtc->gst.webrtcbin);
 }
 
 static gboolean __check_format_is_not_set_cb(gpointer key, gpointer value, gpointer user_data)