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