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);
- gst_bin_add(sink->bin, decodebin);
+ if (!gst_bin_add(sink->bin, decodebin)) {
+ LOG_ERROR("failed to gst_bin_add(), adding [%s] to [%s]", GST_ELEMENT_NAME(decodebin), GST_ELEMENT_NAME(sink->bin));
+ goto error_before_insert;
+ }
- if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE)
+ if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE) {
+ gst_bin_remove(sink->bin, decodebin);
goto error_before_insert;
+ }
ASSERT(g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink));
return WEBRTC_ERROR_NONE;
error_before_insert:
- if (decodebin)
- gst_object_unref(GST_OBJECT(decodebin));
+ SAFE_GST_OBJECT_UNREF(decodebin);
g_free(track_name);
g_free(sink);
_connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "need-data", G_CALLBACK(__appsrc_need_data_cb), source);
_connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "enough-data", G_CALLBACK(__appsrc_enough_data_cb), source);
- gst_bin_add(source->bin, appsrc);
+ if (!gst_bin_add(source->bin, appsrc)) {
+ LOG_ERROR("failed to gst_bin_add(), adding [%s] to [%s]", GST_ELEMENT_NAME(appsrc), GST_ELEMENT_NAME(source->bin));
+ gst_object_unref(GST_OBJECT(appsrc));
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
return WEBRTC_ERROR_NONE;
}