[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)
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);
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);
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;
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;
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;
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;
+}