{
int ret = WEBRTC_ERROR_NONE;
GstElement *camerasrc;
- GstElement *capsfilter;
- GstElement *videoenc;
- GstElement *videopay;
- GstElement *queue;
- GstElement *capsfilter2;
+ GstElement *capsfilter = NULL;
+ GstElement *videoenc = NULL;
+ GstElement *videopay = NULL;
+ GstElement *queue = NULL;
+ GstElement *capsfilter2 = NULL;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
g_object_set(G_OBJECT(camerasrc), "empty-buffer-timeout", 0, NULL);
if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE)
- return ret;
+ goto exit;
gst_bin_add_many(source->bin, camerasrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL);
if (!gst_element_link_many(camerasrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL)) {
LOG_ERROR("failed to gst_element_link_many()");
- return WEBRTC_ERROR_INVALID_OPERATION;
+ ret = WEBRTC_ERROR_INVALID_OPERATION;
+ goto exit_with_remove_from_bin;
}
- return _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ ret = _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ if (ret != WEBRTC_ERROR_NONE)
+ goto exit_with_remove_from_bin;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ /* elements will be dereferenced */
+ gst_bin_remove_many(source->bin, camerasrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL);
+ return ret;
+exit:
+ SAFE_GST_OBJECT_UNREF(camerasrc);
+ SAFE_GST_OBJECT_UNREF(capsfilter);
+ SAFE_GST_OBJECT_UNREF(videoenc);
+ SAFE_GST_OBJECT_UNREF(videopay);
+ SAFE_GST_OBJECT_UNREF(queue);
+ SAFE_GST_OBJECT_UNREF(capsfilter2);
+ return ret;
}
static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
GstElement *audiosrc;
- GstElement *capsfilter;
- GstElement *audioenc;
- GstElement *audiopay;
- GstElement *queue;
- GstElement *capsfilter2;
+ GstElement *capsfilter = NULL;
+ GstElement *audioenc = NULL;
+ GstElement *audiopay = NULL;
+ GstElement *queue = NULL;
+ GstElement *capsfilter2 = NULL;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
}
if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE)
- return ret;
+ goto exit;
gst_bin_add_many(source->bin, audiosrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
if (!gst_element_link_many(audiosrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL)) {
LOG_ERROR("failed to gst_element_link_many()");
- return WEBRTC_ERROR_INVALID_OPERATION;
+ ret = WEBRTC_ERROR_INVALID_OPERATION;
+ goto exit_with_remove_from_bin;
}
- return _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ ret = _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ if (ret != WEBRTC_ERROR_NONE)
+ goto exit_with_remove_from_bin;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ /* elements will be dereferenced */
+ gst_bin_remove_many(source->bin, audiosrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
+ return ret;
+exit:
+ SAFE_GST_OBJECT_UNREF(audiosrc);
+ SAFE_GST_OBJECT_UNREF(capsfilter);
+ SAFE_GST_OBJECT_UNREF(audioenc);
+ SAFE_GST_OBJECT_UNREF(audiopay);
+ SAFE_GST_OBJECT_UNREF(queue);
+ SAFE_GST_OBJECT_UNREF(capsfilter2);
+ return ret;
}
static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
GstElement *videotestsrc;
- GstElement *capsfilter;
- GstElement *videoenc;
- GstElement *videopay;
- GstElement *queue;
- GstElement *capsfilter2;
+ GstElement *capsfilter = NULL;
+ GstElement *videoenc = NULL;
+ GstElement *videopay = NULL;
+ GstElement *queue = NULL;
+ GstElement *capsfilter2 = NULL;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
g_object_set(G_OBJECT(videotestsrc), "is-live", TRUE, "pattern", 18, NULL); /* 18: ball */
if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &videoenc, &videopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE)
- return ret;
+ goto exit;
gst_bin_add_many(source->bin, videotestsrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL);
if (!gst_element_link_many(videotestsrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL)) {
LOG_ERROR("failed to gst_element_link_many()");
- return WEBRTC_ERROR_INVALID_OPERATION;
+ ret = WEBRTC_ERROR_INVALID_OPERATION;
+ goto exit_with_remove_from_bin;
}
- return _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ ret = _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ if (ret != WEBRTC_ERROR_NONE)
+ goto exit_with_remove_from_bin;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ /* elements will be dereferenced */
+ gst_bin_remove_many(source->bin, videotestsrc, capsfilter, videoenc, videopay, queue, capsfilter2, NULL);
+ return ret;
+exit:
+ SAFE_GST_OBJECT_UNREF(videotestsrc);
+ SAFE_GST_OBJECT_UNREF(capsfilter);
+ SAFE_GST_OBJECT_UNREF(videoenc);
+ SAFE_GST_OBJECT_UNREF(videopay);
+ SAFE_GST_OBJECT_UNREF(queue);
+ SAFE_GST_OBJECT_UNREF(capsfilter2);
+ return ret;
}
static int __build_audiotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
GstElement *audiotestsrc;
- GstElement *capsfilter;
- GstElement *audioenc;
- GstElement *audiopay;
- GstElement *queue;
- GstElement *capsfilter2;
+ GstElement *capsfilter = NULL;
+ GstElement *audioenc = NULL;
+ GstElement *audiopay = NULL;
+ GstElement *queue = NULL;
+ GstElement *capsfilter2 = NULL;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
g_object_set(G_OBJECT(audiotestsrc), "is-live", TRUE, NULL);
if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE)
- return ret;
+ goto exit;
gst_bin_add_many(source->bin, audiotestsrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
if (!gst_element_link_many(audiotestsrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL)) {
LOG_ERROR("failed to gst_element_link_many()");
- return WEBRTC_ERROR_INVALID_OPERATION;
+ ret = WEBRTC_ERROR_INVALID_OPERATION;
+ goto exit_with_remove_from_bin;
}
- return _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ ret = _set_ghost_pad_target(source->src_pad, capsfilter2, true);
+ if (ret != WEBRTC_ERROR_NONE)
+ goto exit_with_remove_from_bin;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ /* elements will be dereferenced */
+ gst_bin_remove_many(source->bin, audiotestsrc, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
+ return ret;
+exit:
+ SAFE_GST_OBJECT_UNREF(audiotestsrc);
+ SAFE_GST_OBJECT_UNREF(capsfilter);
+ SAFE_GST_OBJECT_UNREF(audioenc);
+ SAFE_GST_OBJECT_UNREF(audiopay);
+ SAFE_GST_OBJECT_UNREF(queue);
+ SAFE_GST_OBJECT_UNREF(capsfilter2);
+ return ret;
}
static void _appsrc_need_data_cb(GstElement *appsrc, guint size, gpointer data)