Commit 2153c459 authored by Wim Taymans's avatar Wim Taymans
Browse files

check/: Check fixes, use API as stated in design docs, remove hacks.

Original commit message from CVS:
* check/Makefile.am:
* check/generic/states.c: (GST_START_TEST):
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST), (gst_pipeline_suite):
* check/states/sinks.c: (GST_START_TEST):
* check/states/sinks2.c: (GST_START_TEST), (gst_object_suite),
(main):
Check fixes, use API as stated in design docs, remove hacks.

* gst/base/gstbasesink.c: (gst_base_sink_handle_object),
(gst_base_sink_change_state):
Catch stopping our task while we're shutting down.

* gst/gstbin.c: (gst_bin_init), (gst_bin_add_func),
(gst_bin_remove_func), (gst_bin_get_state_func),
(gst_bin_recalc_state), (gst_bin_change_state_func),
(bin_bus_handler):
* gst/gstbin.h:
* gst/gstelement.c: (gst_element_init),
(gst_element_get_state_func), (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state),
(gst_element_set_state), (gst_element_change_state),
(gst_element_change_state_func):
* gst/gstelement.h:
New state change algorithm (see #318116)

* gst/gstpipeline.c: (gst_pipeline_class_init),
(gst_pipeline_init), (gst_pipeline_set_property),
(gst_pipeline_get_property), (do_pipeline_seek),
(gst_pipeline_change_state), (gst_pipeline_provide_clock_func):
* gst/gstpipeline.h:
Remove crude state change hacks.

* gst/gstutils.h:
Remove crude hacks.

* tools/gst-launch.c: (main):
Fixes for state change. Needs some more work to fully use the
new stuff.
parent b77f6b0e
2005-10-10 Wim Taymans <wim@fluendo.com>
* check/Makefile.am:
* check/generic/states.c: (GST_START_TEST):
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST), (gst_pipeline_suite):
* check/states/sinks.c: (GST_START_TEST):
* check/states/sinks2.c: (GST_START_TEST), (gst_object_suite),
(main):
Check fixes, use API as stated in design docs, remove hacks.
* gst/base/gstbasesink.c: (gst_base_sink_handle_object),
(gst_base_sink_change_state):
Catch stopping our task while we're shutting down.
* gst/gstbin.c: (gst_bin_init), (gst_bin_add_func),
(gst_bin_remove_func), (gst_bin_get_state_func),
(gst_bin_recalc_state), (gst_bin_change_state_func),
(bin_bus_handler):
* gst/gstbin.h:
* gst/gstelement.c: (gst_element_init),
(gst_element_get_state_func), (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state),
(gst_element_set_state), (gst_element_change_state),
(gst_element_change_state_func):
* gst/gstelement.h:
New state change algorithm (see #318116)
* gst/gstpipeline.c: (gst_pipeline_class_init),
(gst_pipeline_init), (gst_pipeline_set_property),
(gst_pipeline_get_property), (do_pipeline_seek),
(gst_pipeline_change_state), (gst_pipeline_provide_clock_func):
* gst/gstpipeline.h:
Remove crude state change hacks.
* gst/gstutils.h:
Remove crude hacks.
* tools/gst-launch.c: (main):
Fixes for state change. Needs some more work to fully use the
new stuff.
2005-10-10 Andy Wingo <wingo@pobox.com>
* tests/Makefile.am (noinst_PROGRAMS): No more init.c.
......
......@@ -54,6 +54,7 @@ check_PROGRAMS = \
pipelines/simple_launch_lines \
pipelines/cleanup \
states/sinks \
states/sinks2 \
gst-libs/controller \
gst-libs/gdp
......
......@@ -42,8 +42,7 @@ GST_START_TEST (test_state_changes)
gst_element_set_state (element, GST_STATE_READY);
gst_element_set_state (element, GST_STATE_PAUSED);
gst_element_set_state (element, GST_STATE_PLAYING);
/* Sleep to give any pad tasks time to start */
g_usleep (0.2 * G_USEC_PER_SEC);
gst_element_set_state (element, GST_STATE_PAUSED);
gst_element_set_state (element, GST_STATE_READY);
gst_element_set_state (element, GST_STATE_NULL);
......@@ -52,6 +51,7 @@ GST_START_TEST (test_state_changes)
gst_element_set_state (element, GST_STATE_PLAYING);
gst_element_set_state (element, GST_STATE_PAUSED);
gst_element_set_state (element, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (element));
}
gst_task_cleanup_all ();
......
......@@ -262,7 +262,7 @@ GST_START_TEST (test_message_state_changed_children)
/* change state to PAUSED, spawning three messages */
GST_DEBUG ("setting pipeline to PAUSED");
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
ret =
gst_element_get_state (GST_ELEMENT (pipeline), &current, &pending, NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
......@@ -364,19 +364,13 @@ GST_START_TEST (test_watch_for_state_change)
fail_unless (gst_element_link (src, sink), "could not link src and sink");
/* change state, spawning two times three messages, minus one async */
/* change state, spawning two times three messages */
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
ret = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
pop_messages (bus, 5);
fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus");
gst_bin_watch_for_state_change (GST_BIN (bin));
/* should get the bin's state change message now */
pop_messages (bus, 1);
pop_messages (bus, 6);
fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus");
......@@ -388,8 +382,7 @@ GST_START_TEST (test_watch_for_state_change)
/* this one might return either SUCCESS or ASYNC, likely SUCCESS */
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
gst_bin_watch_for_state_change (GST_BIN (bin));
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, NULL);
pop_messages (bus, 3);
......@@ -482,6 +475,7 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
{
GstElement *src, *identity, *sink, *pipeline;
GstStateChangeReturn ret;
GstState current, pending;
GstBus *bus;
pipeline = gst_pipeline_new (NULL);
......@@ -506,7 +500,12 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
/* (1) Test state change with fakesink being a regular sink */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
fail_if (ret != GST_STATE_CHANGE_ASYNC,
"State change to PLAYING did not return ASYNC");
ret = gst_element_get_state (pipeline, &current, &pending, NULL);
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
fail_if (pending != GST_STATE_VOID_PENDING, "State change to PLAYING failed");
/* NULL => READY */
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_NULL, GST_STATE_READY, 101);
......@@ -602,7 +601,7 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
GST_FLAG_UNSET (sink, GST_ELEMENT_IS_SINK); /* <======== */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
fail_if (ret != GST_STATE_CHANGE_ASYNC, "State change to PLAYING not ASYNC");
ret = gst_element_get_state (pipeline, &current, &pending, NULL);
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
......
......@@ -28,7 +28,6 @@ GST_START_TEST (test_async_state_change_empty)
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
fail_unless (pipeline != NULL, "Could not create pipeline");
g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
GST_STATE_PLAYING), GST_STATE_CHANGE_SUCCESS);
......@@ -45,7 +44,6 @@ GST_START_TEST (test_async_state_change_fake_ready)
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
fail_unless (pipeline != NULL, "Could not create pipeline");
g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
src = gst_element_factory_make ("fakesrc", NULL);
sink = gst_element_factory_make ("fakesink", NULL);
......@@ -71,7 +69,6 @@ GST_START_TEST (test_async_state_change_fake)
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
fail_unless (pipeline != NULL, "Could not create pipeline");
g_object_set (G_OBJECT (pipeline), "play-timeout", 0LL, NULL);
src = gst_element_factory_make ("fakesrc", NULL);
sink = gst_element_factory_make ("fakesink", NULL);
......@@ -81,7 +78,7 @@ GST_START_TEST (test_async_state_change_fake)
bus = gst_pipeline_get_bus (pipeline);
fail_unless_equals_int (gst_element_set_state_async (GST_ELEMENT (pipeline),
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
while (!done) {
......@@ -98,7 +95,6 @@ GST_START_TEST (test_async_state_change_fake)
}
}
g_object_set (G_OBJECT (pipeline), "play-timeout", 3 * GST_SECOND, NULL);
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
GST_STATE_NULL), GST_STATE_CHANGE_SUCCESS);
......@@ -175,7 +171,6 @@ GST_START_TEST (test_bus)
pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline");
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
g_object_set (pipeline, "play-timeout", 0LL, NULL);
src = gst_element_factory_make ("fakesrc", NULL);
fail_unless (src != NULL);
......@@ -193,7 +188,7 @@ GST_START_TEST (test_bus)
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline after add_watch", 1);
ASSERT_OBJECT_REFCOUNT (bus, "bus after add_watch", 3);
gst_element_set_state_async (pipeline, GST_STATE_PLAYING);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
loop = g_main_loop_new (NULL, FALSE);
GST_DEBUG ("going into main loop");
g_main_loop_run (loop);
......@@ -207,9 +202,6 @@ GST_START_TEST (test_bus)
/* cleanup */
GST_DEBUG ("cleanup");
/* current semantics require us to go step by step; this will change */
gst_element_set_state (pipeline, GST_STATE_PAUSED);
gst_element_set_state (pipeline, GST_STATE_READY);
gst_element_set_state (pipeline, GST_STATE_NULL);
fail_unless (gst_element_get_state (pipeline, &current, NULL, NULL) ==
GST_STATE_CHANGE_SUCCESS);
......@@ -238,6 +230,8 @@ gst_pipeline_suite (void)
Suite *s = suite_create ("GstPipeline");
TCase *tc_chain = tcase_create ("pipeline tests");
tcase_set_timeout (tc_chain, 0);
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_async_state_change_empty);
tcase_add_test (tc_chain, test_async_state_change_fake_ready);
......
......@@ -42,7 +42,7 @@ GST_START_TEST (test_sink)
ret = gst_element_get_state (sink, &current, &pending, &tv);
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not changing state async");
fail_unless (current == GST_STATE_PAUSED, "bad current state");
fail_unless (current == GST_STATE_READY, "bad current state");
fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
ret = gst_element_set_state (sink, GST_STATE_PAUSED);
......@@ -81,6 +81,7 @@ GST_START_TEST (test_src_sink)
gst_object_unref (sinkpad);
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
......@@ -139,8 +140,7 @@ GST_START_TEST (test_livesrc_remove)
ret = gst_element_get_state (pipeline, &current, &pending, &tv);
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
fail_unless (current == GST_STATE_PAUSED, "not paused");
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
fail_unless (pending == GST_STATE_PAUSED, "not paused");
}
GST_END_TEST
......
/* GStreamer
*
* unit test for sinks
*
* Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gst/check/gstcheck.h>
/* a sink should go ASYNC to PAUSE and PLAYING. */
GST_START_TEST (test_sink)
{
GstElement *sink, *src;
GstStateChangeReturn ret;
GstState current, pending;
GTimeVal tv;
sink = gst_element_factory_make ("fakesink", "sink");
ret = gst_element_set_state (sink, GST_STATE_PLAYING);
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
GST_TIME_TO_TIMEVAL ((GstClockTime) 0, tv);
ret = gst_element_get_state (sink, &current, &pending, &tv);
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not changing state async");
fail_unless (current == GST_STATE_READY, "bad current state");
fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
src = gst_element_factory_make ("fakesrc", "src");
gst_element_link (src, sink);
ret = gst_element_set_state (src, GST_STATE_PLAYING);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
/* now wait for final state */
ret = gst_element_get_state (sink, &current, &pending, NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to change state");
fail_unless (current == GST_STATE_PLAYING, "bad current state");
fail_unless (pending == GST_STATE_VOID_PENDING, "bad pending state");
ret = gst_element_set_state (sink, GST_STATE_NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
ret = gst_element_set_state (src, GST_STATE_NULL);
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
gst_object_unref (sink);
gst_object_unref (src);
}
GST_END_TEST
/* test: try changing state of sinks */
Suite * gst_object_suite (void)
{
Suite *s = suite_create ("Sinks");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_sink);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = gst_object_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}
......@@ -622,6 +622,7 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
if (length == 1) {
gint t;
GstTask *task;
basesink->have_preroll = TRUE;
/* we are prerolling */
......@@ -636,8 +637,21 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
g_warning ("STREAM_LOCK should have been locked !!");
}
/* now we commit our state */
GST_STATE_LOCK (basesink);
/* now we commit our state, this will also automatically proceed to
* the next pending state. */
/* FIXME */
if ((task = GST_PAD_TASK (pad))) {
while (!GST_STATE_TRYLOCK (basesink)) {
GST_DEBUG_OBJECT (basesink,
"state change happening, checking shutdown");
GST_LOCK (pad);
if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
goto task_stopped;
GST_UNLOCK (pad);
}
} else {
GST_STATE_LOCK (basesink);
}
GST_DEBUG_OBJECT (basesink, "commit state");
gst_element_commit_state (GST_ELEMENT (basesink));
GST_STATE_UNLOCK (basesink);
......@@ -742,6 +756,12 @@ playing_async:
return ret;
}
task_stopped:
{
GST_UNLOCK (pad);
GST_DEBUG_OBJECT (basesink, "task is stopped");
return GST_FLOW_WRONG_STATE;
}
flushing:
{
GST_UNLOCK (pad);
......@@ -1514,7 +1534,8 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
* we need to wait for a preroll */
GST_DEBUG_OBJECT (basesink, "have_preroll: %d, EOS: %d",
basesink->have_preroll, basesink->eos);
if (!basesink->have_preroll && !basesink->eos) {
if (!basesink->have_preroll && !basesink->eos
&& GST_STATE_PENDING (basesink) == GST_STATE_PAUSED) {
GST_DEBUG_OBJECT (basesink, "PLAYING to PAUSED, need preroll to TRUE");
basesink->need_preroll = TRUE;
ret = GST_STATE_CHANGE_ASYNC;
......
......@@ -76,7 +76,6 @@ GST_DEBUG_CATEGORY_STATIC (bin_debug);
(guint) (bin)->child_states[2], (bin)->child_states[1], \
(bin)->child_states[0], gst_element_state_get_name (GST_STATE (bin)))
static GstElementDetails gst_bin_details = GST_ELEMENT_DETAILS ("Generic bin",
"Generic/Bin",
"Simple container object",
......@@ -86,6 +85,7 @@ GType _gst_bin_type = 0;
static void gst_bin_dispose (GObject * object);
static void gst_bin_recalc_state (GstBin * bin, gboolean force);
static GstStateChangeReturn gst_bin_change_state_func (GstElement * element,
GstStateChange transition);
static GstStateChangeReturn gst_bin_get_state_func (GstElement * element,
......@@ -292,6 +292,8 @@ gst_bin_init (GstBin * bin)
bin->children = NULL;
bin->children_cookie = 0;
bin->eosed = NULL;
bin->polling = FALSE;
bin->state_dirty = FALSE;
/* Set up a bus for listening to child elements */
bus = g_object_new (gst_bus_get_type (), NULL);
......@@ -483,7 +485,7 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
gst_element_set_base_time (element, GST_ELEMENT (bin)->base_time);
GST_DEBUG_OBJECT (element, "setting clock %p", GST_ELEMENT_CLOCK (bin));
gst_element_set_clock (element, GST_ELEMENT_CLOCK (bin));
bin->state_dirty = TRUE;
GST_UNLOCK (bin);
/* unlink all linked pads */
......@@ -619,6 +621,7 @@ gst_bin_remove_func (GstBin * bin, GstElement * element)
GST_FLAG_UNSET (bin, GST_ELEMENT_IS_SINK);
}
}
bin->state_dirty = TRUE;
GST_UNLOCK (bin);
GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin, "removed child \"%s\"",
......@@ -872,14 +875,7 @@ gst_bin_iterate_sinks (GstBin * bin)
return result;
}
/* 2 phases:
* 1) check state of all children with 0 timeout to find ERROR and
* NO_PREROLL elements. return if found.
* 2) perform full blocking wait with requested timeout.
*
* 2) cannot be performed when 1) returns results as the sinks might
* not be able to complete the state change making 2) block forever.
*
/*
* MT safe
*/
static GstStateChangeReturn
......@@ -887,6 +883,18 @@ gst_bin_get_state_func (GstElement * element, GstState * state,
GstState * pending, GTimeVal * timeout)
{
GstBin *bin = GST_BIN (element);
GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "getting state");
/* do a non forced recalculation of the state */
gst_bin_recalc_state (bin, FALSE);
return parent_class->get_state (element, state, pending, timeout);
}
static void
gst_bin_recalc_state (GstBin * bin, gboolean force)
{
GstStateChangeReturn ret;
GList *children;
guint32 children_cookie;
......@@ -894,12 +902,21 @@ gst_bin_get_state_func (GstElement * element, GstState * state,
gboolean have_async;
GTimeVal tv;
GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "getting state");
ret = GST_STATE_CHANGE_SUCCESS;
/* lock bin, no element can be added or removed while we have this lock */
GST_LOCK (bin);
/* no point in scanning if nothing changed and it's no forced recalc */
if (!force && !bin->state_dirty)
goto not_dirty;
/* no point in having two scans run concurrently */
if (bin->polling)
goto was_polling;
bin->polling = TRUE;
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin, "recalc state");
restart:
have_no_preroll = FALSE;
......@@ -935,7 +952,7 @@ restart:
switch (ret) {
case GST_STATE_CHANGE_FAILURE:
/* report FAILURE immediately */
/* report FAILURE immediatly */
goto done;
case GST_STATE_CHANGE_NO_PREROLL:
/* we have to continue scanning as there might be
......@@ -957,59 +974,15 @@ restart:
/* if we have NO_PREROLL, return that */
if (have_no_preroll) {
ret = GST_STATE_CHANGE_NO_PREROLL;
goto done;
}
/* else return SUCCESS if no async elements were found */
else if (!have_async) {
ret = GST_STATE_CHANGE_SUCCESS;
goto done;
}
/* next we poll all children for their state to see if one of them
* is still busy with its state change. We did not release the bin lock
* yet so the elements are the same as the ones from the quick scan. */
children = bin->children;
children_cookie = bin->children_cookie;
while (children) {
GstElement *child = GST_ELEMENT_CAST (children->data);
gst_object_ref (child);
/* now we release the lock to enter the potentialy blocking wait */
GST_UNLOCK (bin);
/* ret is ASYNC if some child is still performing the state change
* ater the timeout. */
ret = gst_element_get_state (child, NULL, NULL, timeout);
gst_object_unref (child);
/* now grab the lock to iterate to the next child */
GST_LOCK (bin);
if (G_UNLIKELY (children_cookie != bin->children_cookie)) {
/* child added/removed during state change, restart. We need
* to restart with the quick check as a no-preroll element could
* have been added here and we don't want to block on sinks then.*/
goto restart;
}
switch (ret) {
case GST_STATE_CHANGE_SUCCESS:
break;
case GST_STATE_CHANGE_FAILURE:
case GST_STATE_CHANGE_NO_PREROLL:
/* report FAILURE and NO_PREROLL immediatly */
goto done;
case GST_STATE_CHANGE_ASYNC:
goto done;
default:
g_assert_not_reached ();
}
children = g_list_next (children);
/* else return ASYNC if async elements where found. */
else if (have_async) {
ret = GST_STATE_CHANGE_ASYNC;
}
/* if we got here, all elements can do preroll */
have_no_preroll = FALSE;
done:
bin->state_dirty = FALSE;
bin->polling = FALSE;
GST_UNLOCK (bin);
/* now we can take the state lock, it is possible that new elements
......@@ -1019,33 +992,45 @@ done:
GST_STATE_LOCK (bin);
switch (ret) {
case GST_STATE_CHANGE_SUCCESS:
gst_element_commit_state (element);
case GST_STATE_CHANGE_NO_PREROLL:
gst_element_commit_state (GST_ELEMENT_CAST (bin));
break;
case GST_STATE_CHANGE_ASYNC:
gst_element_lost_state (GST_ELEMENT_CAST (bin));
break;
case GST_STATE_CHANGE_FAILURE:
gst_element_abort_state (element);
gst_element_abort_state (GST_ELEMENT_CAST (bin));
break;
default:
/* other cases are just passed along */
break;
goto unknown_state;
}
/* and report the state if needed */
if (state)
*state = GST_STATE (element);
if (pending)
*pending = GST_STATE_PENDING (element);
GST_STATE_NO_PREROLL (element) = have_no_preroll;
GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
"state current: %s, pending: %s, error: %d, no_preroll: %d, result: %d",
gst_element_state_get_name (GST_STATE (element)),
gst_element_state_get_name (GST_STATE_PENDING (element)),
GST_STATE_ERROR (element), GST_STATE_NO_PREROLL (element), ret);
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin, "return now %d",
GST_STATE_RETURN (bin));
GST_STATE_UNLOCK (bin);
return;
return ret;
not_dirty:
{
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin, "not dirty");
GST_UNLOCK (bin);
return;
}
was_polling:
{
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin, "was polling");
GST_UNLOCK (bin);
return;
}
unknown_state:
{
/* somebody added a GST_STATE_ and forgot to do stuff here ! */
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin,
"unknown return value %d from a state change function", ret);
g_critical ("unknown return value %d from a state change function", ret);
GST_STATE_RETURN (bin) = GST_STATE_CHANGE_FAILURE;
GST_STATE_UNLOCK (bin);
return;
}
}
/***********************************************
......@@ -1340,16 +1325,13 @@ gst_bin_change_state_func (GstElement * element, GstStateChange transition)
gboolean done;
/* we don't need to take the STATE_LOCK, it is already taken */
current = GST_STATE (element);