diff --git a/gst/multifile/gstsplitmuxsink.c b/gst/multifile/gstsplitmuxsink.c index 3c8d23884b..205a910d24 100644 --- a/gst/multifile/gstsplitmuxsink.c +++ b/gst/multifile/gstsplitmuxsink.c @@ -1437,44 +1437,45 @@ create_sink (GstSplitMuxSink * splitmux) { GstElement *provided_sink = NULL; - g_return_val_if_fail (splitmux->active_sink == NULL, TRUE); + if (splitmux->active_sink == NULL) { - GST_OBJECT_LOCK (splitmux); - if (splitmux->provided_sink != NULL) - provided_sink = gst_object_ref (splitmux->provided_sink); - GST_OBJECT_UNLOCK (splitmux); + GST_OBJECT_LOCK (splitmux); + if (splitmux->provided_sink != NULL) + provided_sink = gst_object_ref (splitmux->provided_sink); + GST_OBJECT_UNLOCK (splitmux); - if (provided_sink == NULL) { - if ((splitmux->sink = - create_element (splitmux, DEFAULT_SINK, "sink")) == NULL) - goto fail; - splitmux->active_sink = splitmux->sink; - } else { - if (!gst_bin_add (GST_BIN (splitmux), provided_sink)) { - g_warning ("Could not add sink elements - splitmuxsink will not work"); + if (provided_sink == NULL) { + if ((splitmux->sink = + create_element (splitmux, DEFAULT_SINK, "sink")) == NULL) + goto fail; + splitmux->active_sink = splitmux->sink; + } else { + if (!gst_bin_add (GST_BIN (splitmux), provided_sink)) { + g_warning ("Could not add sink elements - splitmuxsink will not work"); + gst_object_unref (provided_sink); + goto fail; + } + + splitmux->active_sink = provided_sink; + + /* The bin holds a ref now, we can drop our tmp ref */ gst_object_unref (provided_sink); - goto fail; + + /* Find the sink element */ + splitmux->sink = find_sink (splitmux->active_sink); + if (splitmux->sink == NULL) { + g_warning + ("Could not locate sink element in provided sink - splitmuxsink will not work"); + goto fail; + } } - splitmux->active_sink = provided_sink; - - /* The bin holds a ref now, we can drop our tmp ref */ - gst_object_unref (provided_sink); - - /* Find the sink element */ - splitmux->sink = find_sink (splitmux->active_sink); - if (splitmux->sink == NULL) { - g_warning - ("Could not locate sink element in provided sink - splitmuxsink will not work"); + if (!gst_element_link (splitmux->muxer, splitmux->active_sink)) { + g_warning ("Failed to link muxer and sink- splitmuxsink will not work"); goto fail; } } - if (!gst_element_link (splitmux->muxer, splitmux->active_sink)) { - g_warning ("Failed to link muxer and sink- splitmuxsink will not work"); - goto fail; - } - return TRUE; fail: return FALSE; diff --git a/tests/check/elements/splitmux.c b/tests/check/elements/splitmux.c index 31b421c654..bf906946b8 100644 --- a/tests/check/elements/splitmux.c +++ b/tests/check/elements/splitmux.c @@ -216,16 +216,46 @@ GST_START_TEST (test_splitmuxsink) GST_END_TEST; +/* For verifying bug https://bugzilla.gnome.org/show_bug.cgi?id=762893 */ +GST_START_TEST (test_splitmuxsink_reuse_simple) +{ + GstElement *sink; + GstPad *pad; + + sink = gst_element_factory_make ("splitmuxsink", NULL); + pad = gst_element_get_request_pad (sink, "video"); + fail_unless (pad != NULL); + g_object_set (sink, "location", "/dev/null", NULL); + + fail_unless (gst_element_set_state (sink, + GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC); + fail_unless (gst_element_set_state (sink, + GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS); + fail_unless (gst_element_set_state (sink, + GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC); + fail_unless (gst_element_set_state (sink, + GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS); + + gst_element_release_request_pad (sink, pad); + gst_object_unref (pad); + gst_object_unref (sink); +} + +GST_END_TEST; + static Suite * splitmux_suite (void) { Suite *s = suite_create ("splitmux"); TCase *tc_chain = tcase_create ("general"); + TCase *tc_chain_basic = tcase_create ("basic"); suite_add_tcase (s, tc_chain); + suite_add_tcase (s, tc_chain_basic); + + tcase_add_test (tc_chain_basic, test_splitmuxsink_reuse_simple); tcase_add_checked_fixture (tc_chain, tempdir_setup, tempdir_cleanup); - tcase_add_test (tc_chain, test_splitmuxsrc); tcase_add_test (tc_chain, test_splitmuxsink);