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");
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;
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)