mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
gst/gstbin.c: make state changes work correctly and reentrant (so removing elements from bins during state changes of...
Original commit message from CVS: * gst/gstbin.c: (gst_bin_get_type), (gst_bin_class_init), (gst_bin_fix_state), (gst_bin_add_func), (gst_bin_remove_func), (gst_bin_child_state_change_func), (set_kid_state_func), (gst_bin_set_state), (gst_bin_change_state_norecurse): make state changes work correctly and reentrant (so removing elements from bins during state changes of bins doesn't cause segfaults or even wrong states) add debugging category and debugging output to print children states * gst/gstbin.c: (gst_bin_dispose): add some assertion checks * gst/gstbin.h: * gst/gstbin.c: (gst_bin_sync_children_state): deprecate this function - it just does gst_bin_set_state (bin, GST_STATE (bin)) * testsuite/threads/queue.c: (main): don't use gst_bin_sync_children_state anymore * testsuite/states/Makefile.am: * testsuite/states/bin.c: test that the state changes of bins work as expected * gst/gstthread.c: (gst_thread_class_init), (gst_thread_set_state): some adjustments to change states correctly, too * gst/gstthread.c: (gst_thread_change_state): don't enable/disable "threadsafe" properties, they're unused and cause random segfaults * testsuite/threads/Makefile.am: the queue check randomly passes now, ignore it
This commit is contained in:
parent
d8c591b902
commit
28bf20507e
12 changed files with 446 additions and 152 deletions
29
ChangeLog
29
ChangeLog
|
@ -1,3 +1,32 @@
|
||||||
|
2004-07-21 Benjamin Otte <otte@gnome.org>
|
||||||
|
|
||||||
|
* gst/gstbin.c: (gst_bin_get_type), (gst_bin_class_init),
|
||||||
|
(gst_bin_fix_state), (gst_bin_add_func), (gst_bin_remove_func),
|
||||||
|
(gst_bin_child_state_change_func), (set_kid_state_func),
|
||||||
|
(gst_bin_set_state), (gst_bin_change_state_norecurse):
|
||||||
|
make state changes work correctly and reentrant (so removing
|
||||||
|
elements from bins during state changes of bins doesn't cause
|
||||||
|
segfaults or even wrong states)
|
||||||
|
add debugging category and debugging output to print children states
|
||||||
|
* gst/gstbin.c: (gst_bin_dispose):
|
||||||
|
add some assertion checks
|
||||||
|
* gst/gstbin.h:
|
||||||
|
* gst/gstbin.c: (gst_bin_sync_children_state):
|
||||||
|
deprecate this function - it just does gst_bin_set_state (bin,
|
||||||
|
GST_STATE (bin))
|
||||||
|
* testsuite/threads/queue.c: (main):
|
||||||
|
don't use gst_bin_sync_children_state anymore
|
||||||
|
* testsuite/states/Makefile.am:
|
||||||
|
* testsuite/states/bin.c:
|
||||||
|
test that the state changes of bins work as expected
|
||||||
|
* gst/gstthread.c: (gst_thread_class_init), (gst_thread_set_state):
|
||||||
|
some adjustments to change states correctly, too
|
||||||
|
* gst/gstthread.c: (gst_thread_change_state):
|
||||||
|
don't enable/disable "threadsafe" properties, they're unused and
|
||||||
|
cause random segfaults
|
||||||
|
* testsuite/threads/Makefile.am:
|
||||||
|
the queue check randomly passes now, ignore it
|
||||||
|
|
||||||
2004-07-21 Benjamin Otte <otte@gnome.org>
|
2004-07-21 Benjamin Otte <otte@gnome.org>
|
||||||
|
|
||||||
* gst/gstpad.c:
|
* gst/gstpad.c:
|
||||||
|
|
199
gst/gstbin.c
199
gst/gstbin.c
|
@ -34,6 +34,14 @@
|
||||||
#include "gstindex.h"
|
#include "gstindex.h"
|
||||||
#include "gstutils.h"
|
#include "gstutils.h"
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (bin_debug);
|
||||||
|
#define GST_CAT_DEFAULT bin_debug
|
||||||
|
#define GST_LOG_BIN_CONTENTS(bin, text) GST_LOG_OBJECT ((bin), \
|
||||||
|
text ": %d elements: %u PLAYING, %u PAUSED, %u READY, %u NULL, own state: %s", \
|
||||||
|
(bin)->numchildren, (guint) (bin)->child_states[3], \
|
||||||
|
(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",
|
static GstElementDetails gst_bin_details = GST_ELEMENT_DETAILS ("Generic bin",
|
||||||
"Generic/Bin",
|
"Generic/Bin",
|
||||||
"Simple container object",
|
"Simple container object",
|
||||||
|
@ -46,7 +54,6 @@ static gboolean _gst_boolean_did_something_accumulator (GSignalInvocationHint *
|
||||||
|
|
||||||
static void gst_bin_dispose (GObject * object);
|
static void gst_bin_dispose (GObject * object);
|
||||||
|
|
||||||
static GstElementStateReturn gst_bin_change_state (GstElement * element);
|
|
||||||
static GstElementStateReturn gst_bin_change_state_norecurse (GstBin * bin);
|
static GstElementStateReturn gst_bin_change_state_norecurse (GstBin * bin);
|
||||||
|
|
||||||
#ifndef GST_DISABLE_INDEX
|
#ifndef GST_DISABLE_INDEX
|
||||||
|
@ -116,6 +123,8 @@ gst_bin_get_type (void)
|
||||||
|
|
||||||
_gst_bin_type =
|
_gst_bin_type =
|
||||||
g_type_register_static (GST_TYPE_ELEMENT, "GstBin", &bin_info, 0);
|
g_type_register_static (GST_TYPE_ELEMENT, "GstBin", &bin_info, 0);
|
||||||
|
GST_DEBUG_CATEGORY_INIT (bin_debug, "bin", GST_DEBUG_BOLD,
|
||||||
|
"debugging info for the 'bin' container element");
|
||||||
}
|
}
|
||||||
return _gst_bin_type;
|
return _gst_bin_type;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +172,6 @@ gst_bin_class_init (GstBinClass * klass)
|
||||||
GST_DEBUG_FUNCPTR (gst_bin_restore_thyself);
|
GST_DEBUG_FUNCPTR (gst_bin_restore_thyself);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_bin_change_state);
|
|
||||||
gstelement_class->set_state = GST_DEBUG_FUNCPTR (gst_bin_set_state);
|
gstelement_class->set_state = GST_DEBUG_FUNCPTR (gst_bin_set_state);
|
||||||
#ifndef GST_DISABLE_INDEX
|
#ifndef GST_DISABLE_INDEX
|
||||||
gstelement_class->set_index = GST_DEBUG_FUNCPTR (gst_bin_set_index);
|
gstelement_class->set_index = GST_DEBUG_FUNCPTR (gst_bin_set_index);
|
||||||
|
@ -441,6 +449,34 @@ gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* after adding or removing elements, we need to fix the state of the bin
|
||||||
|
* in a reentrant way. This is done here */
|
||||||
|
static void
|
||||||
|
gst_bin_fix_state (GstBin * bin)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
GstElementState desired;
|
||||||
|
|
||||||
|
while (TRUE) {
|
||||||
|
/* find the highest child state */
|
||||||
|
for (i = GST_NUM_STATES - 1; i > 0; i--) {
|
||||||
|
if (bin->child_states[i] > 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_assert (i < GST_NUM_STATES && i >= 0);
|
||||||
|
desired = 1 << i;
|
||||||
|
if (desired == GST_STATE (bin)) {
|
||||||
|
break;
|
||||||
|
} else if (desired < GST_STATE (bin)) {
|
||||||
|
GST_STATE_PENDING (bin) = GST_STATE (bin) >> 1;
|
||||||
|
} else { /* if (desired > GST_STATE (bin)) */
|
||||||
|
GST_STATE_PENDING (bin) = GST_STATE (bin) << 1;
|
||||||
|
}
|
||||||
|
/* this part is reentrant */
|
||||||
|
gst_bin_change_state_norecurse (bin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_bin_add_func (GstBin * bin, GstElement * element)
|
gst_bin_add_func (GstBin * bin, GstElement * element)
|
||||||
{
|
{
|
||||||
|
@ -459,15 +495,14 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GST_STATE (element) > GST_STATE (bin)) {
|
/* ref to guard unrefs in callbacks */
|
||||||
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, bin,
|
gst_object_ref (GST_OBJECT (bin));
|
||||||
"setting state to receive element \"%s\"", GST_OBJECT_NAME (element));
|
gst_object_ref (GST_OBJECT (element));
|
||||||
gst_element_set_state ((GstElement *) bin, GST_STATE (element));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the element's parent and add the element to the bin's list of children */
|
/* set the element's parent and add the element to the bin's list of children */
|
||||||
gst_object_set_parent (GST_OBJECT (element), GST_OBJECT (bin));
|
gst_object_set_parent (GST_OBJECT (element), GST_OBJECT (bin));
|
||||||
|
|
||||||
|
GST_LOG_BIN_CONTENTS (bin, "before adding element");
|
||||||
bin->children = g_list_append (bin->children, element);
|
bin->children = g_list_append (bin->children, element);
|
||||||
bin->numchildren++;
|
bin->numchildren++;
|
||||||
|
|
||||||
|
@ -485,10 +520,16 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
|
||||||
gst_bin_set_element_sched (element, sched);
|
gst_bin_set_element_sched (element, sched);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if we need to bump state because a high state element was added */
|
||||||
|
gst_bin_fix_state (bin);
|
||||||
GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
|
GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
|
||||||
GST_OBJECT_NAME (element));
|
GST_OBJECT_NAME (element));
|
||||||
|
GST_LOG_BIN_CONTENTS (bin, "after adding element");
|
||||||
|
|
||||||
g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_ADDED], 0, element);
|
g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_ADDED], 0, element);
|
||||||
|
/* we reffed above */
|
||||||
|
gst_object_unref (GST_OBJECT (element));
|
||||||
|
gst_object_unref (GST_OBJECT (bin));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -537,9 +578,13 @@ gst_bin_remove_func (GstBin * bin, GstElement * element)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ref to guard unrefs in callbacks */
|
||||||
|
gst_object_ref (GST_OBJECT (bin));
|
||||||
|
|
||||||
/* remove this element from the list of managed elements */
|
/* remove this element from the list of managed elements */
|
||||||
gst_bin_unset_element_sched (element, GST_ELEMENT_SCHED (bin));
|
gst_bin_unset_element_sched (element, GST_ELEMENT_SCHED (bin));
|
||||||
|
|
||||||
|
GST_LOG_BIN_CONTENTS (bin, "before removing element");
|
||||||
/* now remove the element from the list of elements */
|
/* now remove the element from the list of elements */
|
||||||
bin->children = g_list_remove (bin->children, element);
|
bin->children = g_list_remove (bin->children, element);
|
||||||
bin->numchildren--;
|
bin->numchildren--;
|
||||||
|
@ -550,30 +595,22 @@ gst_bin_remove_func (GstBin * bin, GstElement * element)
|
||||||
state_idx++;
|
state_idx++;
|
||||||
bin->child_states[state_idx]--;
|
bin->child_states[state_idx]--;
|
||||||
|
|
||||||
GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin, "removed child \"%s\"",
|
GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin,
|
||||||
GST_OBJECT_NAME (element));
|
"removed child \"%s\", %d children left", GST_OBJECT_NAME (element),
|
||||||
|
bin->numchildren);
|
||||||
|
|
||||||
/* ref as we're going to emit a signal */
|
/* ref as we're going to emit a signal */
|
||||||
gst_object_ref (GST_OBJECT (element));
|
gst_object_ref (GST_OBJECT (element));
|
||||||
gst_object_unparent (GST_OBJECT (element));
|
gst_object_unparent (GST_OBJECT (element));
|
||||||
|
|
||||||
/* if we're down to zero children, force state to NULL */
|
/* check the state */
|
||||||
while (bin->numchildren == 0 && GST_ELEMENT_SCHED (bin) != NULL &&
|
gst_bin_fix_state (bin);
|
||||||
GST_STATE (bin) > GST_STATE_NULL) {
|
GST_LOG_BIN_CONTENTS (bin, "after removing element");
|
||||||
GstElementState next = GST_STATE (bin) >> 1;
|
|
||||||
|
|
||||||
GST_STATE_PENDING (bin) = next;
|
|
||||||
gst_bin_change_state_norecurse (bin);
|
|
||||||
if (!GST_STATE (bin) == next) {
|
|
||||||
g_warning ("bin %s failed state change to %d", GST_ELEMENT_NAME (bin),
|
|
||||||
next);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_REMOVED], 0, element);
|
g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_REMOVED], 0, element);
|
||||||
|
|
||||||
/* element is really out of our control now */
|
/* element is really out of our control now */
|
||||||
gst_object_unref (GST_OBJECT (element));
|
gst_object_unref (GST_OBJECT (element));
|
||||||
|
gst_object_unref (GST_OBJECT (bin));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -684,7 +721,7 @@ gst_bin_child_state_change_func (GstBin * bin, GstElementState oldstate,
|
||||||
while (new >>= 1)
|
while (new >>= 1)
|
||||||
new_idx++;
|
new_idx++;
|
||||||
|
|
||||||
GST_LOCK (bin);
|
GST_LOG_BIN_CONTENTS (bin, "before child state change");
|
||||||
bin->child_states[old_idx]--;
|
bin->child_states[old_idx]--;
|
||||||
bin->child_states[new_idx]++;
|
bin->child_states[new_idx]++;
|
||||||
|
|
||||||
|
@ -697,18 +734,17 @@ gst_bin_child_state_change_func (GstBin * bin, GstElementState oldstate,
|
||||||
"highest child state is %s, changing bin state accordingly",
|
"highest child state is %s, changing bin state accordingly",
|
||||||
gst_element_state_get_name (state));
|
gst_element_state_get_name (state));
|
||||||
GST_STATE_PENDING (bin) = state;
|
GST_STATE_PENDING (bin) = state;
|
||||||
GST_UNLOCK (bin);
|
|
||||||
gst_bin_change_state_norecurse (bin);
|
gst_bin_change_state_norecurse (bin);
|
||||||
if (state != GST_STATE (bin)) {
|
if (state != GST_STATE (bin)) {
|
||||||
g_warning ("%s: state change in callback %d %d",
|
GST_INFO_OBJECT (bin, "state change in callback %d %d",
|
||||||
GST_ELEMENT_NAME (bin), state, GST_STATE (bin));
|
state, GST_STATE (bin));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GST_UNLOCK (bin);
|
GST_LOG_BIN_CONTENTS (bin, "after child state change");
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef gboolean (*GstBinForeachFunc) (GstBin * bin, GstElement * element,
|
typedef gboolean (*GstBinForeachFunc) (GstBin * bin, GstElement * element,
|
||||||
|
@ -761,6 +797,7 @@ typedef struct
|
||||||
GstElementStateReturn result;
|
GstElementStateReturn result;
|
||||||
}
|
}
|
||||||
SetKidStateData;
|
SetKidStateData;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
set_kid_state_func (GstBin * bin, GstElement * child, gpointer user_data)
|
set_kid_state_func (GstBin * bin, GstElement * child, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
@ -792,7 +829,6 @@ set_kid_state_func (GstBin * bin, GstElement * child, gpointer user_data)
|
||||||
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin,
|
GST_CAT_INFO_OBJECT (GST_CAT_STATES, bin,
|
||||||
"child '%s' is changing state asynchronously",
|
"child '%s' is changing state asynchronously",
|
||||||
GST_ELEMENT_NAME (child));
|
GST_ELEMENT_NAME (child));
|
||||||
data->result = GST_STATE_ASYNC;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case GST_STATE_SUCCESS:
|
case GST_STATE_SUCCESS:
|
||||||
|
@ -800,6 +836,7 @@ set_kid_state_func (GstBin * bin, GstElement * child, gpointer user_data)
|
||||||
"child '%s' changed state to %d(%s) successfully",
|
"child '%s' changed state to %d(%s) successfully",
|
||||||
GST_ELEMENT_NAME (child), data->pending,
|
GST_ELEMENT_NAME (child), data->pending,
|
||||||
gst_element_state_get_name (data->pending));
|
gst_element_state_get_name (data->pending));
|
||||||
|
data->result = GST_STATE_SUCCESS;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -808,87 +845,31 @@ set_kid_state_func (GstBin * bin, GstElement * child, gpointer user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstElementStateReturn
|
|
||||||
gst_bin_change_state (GstElement * element)
|
|
||||||
{
|
|
||||||
GstBin *bin;
|
|
||||||
GstElementStateReturn ret;
|
|
||||||
GstElementState old_state, pending;
|
|
||||||
SetKidStateData data;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_BIN (element), GST_STATE_FAILURE);
|
|
||||||
|
|
||||||
bin = GST_BIN (element);
|
|
||||||
|
|
||||||
old_state = GST_STATE (element);
|
|
||||||
pending = GST_STATE_PENDING (element);
|
|
||||||
|
|
||||||
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
|
|
||||||
"changing state of children from %s to %s",
|
|
||||||
gst_element_state_get_name (old_state),
|
|
||||||
gst_element_state_get_name (pending));
|
|
||||||
|
|
||||||
if (pending == GST_STATE_VOID_PENDING)
|
|
||||||
return GST_STATE_SUCCESS;
|
|
||||||
|
|
||||||
data.pending = pending;
|
|
||||||
data.result = GST_STATE_SUCCESS;
|
|
||||||
if (!gst_bin_foreach (bin, set_kid_state_func, &data)) {
|
|
||||||
GST_STATE_PENDING (element) = old_state;
|
|
||||||
return GST_STATE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
|
|
||||||
"done changing bin's state from %s to %s, now in %s",
|
|
||||||
gst_element_state_get_name (old_state),
|
|
||||||
gst_element_state_get_name (pending),
|
|
||||||
gst_element_state_get_name (GST_STATE (element)));
|
|
||||||
|
|
||||||
if (data.result == GST_STATE_ASYNC)
|
|
||||||
ret = GST_STATE_ASYNC;
|
|
||||||
else {
|
|
||||||
/* FIXME: this should have been done by the children already, no? */
|
|
||||||
if (parent_class->change_state) {
|
|
||||||
ret = parent_class->change_state (element);
|
|
||||||
} else
|
|
||||||
ret = GST_STATE_SUCCESS;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
GstElementStateReturn
|
GstElementStateReturn
|
||||||
gst_bin_set_state (GstElement * element, GstElementState state)
|
gst_bin_set_state (GstElement * element, GstElementState state)
|
||||||
{
|
{
|
||||||
GstBin *bin = GST_BIN (element);
|
GstBin *bin = GST_BIN (element);
|
||||||
|
|
||||||
if (GST_STATE (bin) == state) {
|
|
||||||
SetKidStateData data;
|
SetKidStateData data;
|
||||||
|
|
||||||
data.pending = state;
|
data.pending = state;
|
||||||
data.result = GST_STATE_SUCCESS;
|
data.result = GST_STATE_ASYNC;
|
||||||
if (!gst_bin_foreach (bin, set_kid_state_func, &data)) {
|
if (!gst_bin_foreach (bin, set_kid_state_func, &data)) {
|
||||||
return GST_STATE_FAILURE;
|
return GST_STATE_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
return data.result;
|
return data.result;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, set_state, (element,
|
|
||||||
state), GST_STATE_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstElementStateReturn
|
static GstElementStateReturn
|
||||||
gst_bin_change_state_norecurse (GstBin * bin)
|
gst_bin_change_state_norecurse (GstBin * bin)
|
||||||
{
|
{
|
||||||
GstElementStateReturn ret;
|
GstElementClass *klass;
|
||||||
|
|
||||||
|
klass = GST_ELEMENT_GET_CLASS (bin);
|
||||||
|
g_return_val_if_fail (klass->change_state, GST_STATE_FAILURE);
|
||||||
|
|
||||||
if (parent_class->change_state) {
|
|
||||||
GST_CAT_LOG_OBJECT (GST_CAT_STATES, bin, "setting bin's own state");
|
GST_CAT_LOG_OBJECT (GST_CAT_STATES, bin, "setting bin's own state");
|
||||||
ret = parent_class->change_state (GST_ELEMENT (bin));
|
return klass->change_state (GST_ELEMENT (bin));
|
||||||
|
|
||||||
return ret;
|
|
||||||
} else
|
|
||||||
return GST_STATE_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -905,6 +886,10 @@ gst_bin_dispose (GObject * object)
|
||||||
}
|
}
|
||||||
g_assert (bin->children == NULL);
|
g_assert (bin->children == NULL);
|
||||||
g_assert (bin->numchildren == 0);
|
g_assert (bin->numchildren == 0);
|
||||||
|
g_assert (bin->child_states[3] == 0); /* playing */
|
||||||
|
g_assert (bin->child_states[2] == 0); /* paused */
|
||||||
|
g_assert (bin->child_states[1] == 0); /* ready */
|
||||||
|
g_assert (bin->child_states[0] == 0); /* null */
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
@ -1087,40 +1072,10 @@ gst_bin_get_all_by_interface (GstBin * bin, GType interface)
|
||||||
GstElementStateReturn
|
GstElementStateReturn
|
||||||
gst_bin_sync_children_state (GstBin * bin)
|
gst_bin_sync_children_state (GstBin * bin)
|
||||||
{
|
{
|
||||||
GList *children;
|
|
||||||
GstElement *element;
|
|
||||||
GstElementState state;
|
|
||||||
GstElementStateReturn ret = GST_STATE_SUCCESS;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), GST_STATE_FAILURE);
|
g_return_val_if_fail (GST_IS_BIN (bin), GST_STATE_FAILURE);
|
||||||
|
|
||||||
state = GST_STATE (bin);
|
return gst_element_set_state (GST_ELEMENT (bin),
|
||||||
children = bin->children;
|
gst_element_get_state (GST_ELEMENT (bin)));
|
||||||
GST_CAT_INFO (GST_CAT_STATES,
|
|
||||||
"syncing state of children with bin \"%s\"'s state %s",
|
|
||||||
GST_ELEMENT_NAME (bin), gst_element_state_get_name (state));
|
|
||||||
|
|
||||||
while (children) {
|
|
||||||
element = GST_ELEMENT (children->data);
|
|
||||||
children = children->next;
|
|
||||||
if (GST_STATE (element) != state) {
|
|
||||||
switch (gst_element_set_state (element, state)) {
|
|
||||||
case GST_STATE_SUCCESS:
|
|
||||||
break;
|
|
||||||
case GST_STATE_ASYNC:
|
|
||||||
if (ret == GST_STATE_SUCCESS)
|
|
||||||
ret = GST_STATE_ASYNC;
|
|
||||||
break;
|
|
||||||
case GST_STATE_FAILURE:
|
|
||||||
ret = GST_STATE_FAILURE;
|
|
||||||
default:
|
|
||||||
/* make sure gst_element_set_state never returns this */
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef GST_DISABLE_LOADSAVE
|
#ifndef GST_DISABLE_LOADSAVE
|
||||||
|
|
|
@ -63,6 +63,7 @@ struct _GstBin {
|
||||||
gint numchildren;
|
gint numchildren;
|
||||||
GList *children;
|
GList *children;
|
||||||
|
|
||||||
|
/* FIXME 0.9: important!! make this guint instead of GstElementState */
|
||||||
GstElementState child_states[GST_NUM_STATES];
|
GstElementState child_states[GST_NUM_STATES];
|
||||||
|
|
||||||
gpointer _gst_reserved[GST_PADDING];
|
gpointer _gst_reserved[GST_PADDING];
|
||||||
|
@ -110,7 +111,9 @@ void gst_bin_use_clock (GstBin *bin, GstClock *clock);
|
||||||
GstClock* gst_bin_get_clock (GstBin *bin);
|
GstClock* gst_bin_get_clock (GstBin *bin);
|
||||||
void gst_bin_auto_clock (GstBin *bin);
|
void gst_bin_auto_clock (GstBin *bin);
|
||||||
|
|
||||||
|
#ifndef GST_DISABLE_DEPRECATED
|
||||||
GstElementStateReturn gst_bin_sync_children_state (GstBin *bin);
|
GstElementStateReturn gst_bin_sync_children_state (GstBin *bin);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* internal */
|
/* internal */
|
||||||
/* one of our childs signaled a state change */
|
/* one of our childs signaled a state change */
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "gstmarshal.h"
|
#include "gstmarshal.h"
|
||||||
#include "gstscheduler.h"
|
#include "gstscheduler.h"
|
||||||
#include "gstinfo.h"
|
#include "gstinfo.h"
|
||||||
|
#include "gstutils.h"
|
||||||
|
|
||||||
#define GST_CAT_DEFAULT GST_CAT_THREAD
|
#define GST_CAT_DEFAULT GST_CAT_THREAD
|
||||||
#define STACK_SIZE 0x200000
|
#define STACK_SIZE 0x200000
|
||||||
|
@ -71,6 +72,8 @@ static void gst_thread_set_property (GObject * object, guint prop_id,
|
||||||
static void gst_thread_get_property (GObject * object, guint prop_id,
|
static void gst_thread_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
static GstElementStateReturn gst_thread_change_state (GstElement * element);
|
static GstElementStateReturn gst_thread_change_state (GstElement * element);
|
||||||
|
static GstElementStateReturn gst_thread_set_state (GstElement * element,
|
||||||
|
GstElementState state);
|
||||||
static void gst_thread_child_state_change (GstBin * bin,
|
static void gst_thread_child_state_change (GstBin * bin,
|
||||||
GstElementState oldstate, GstElementState newstate, GstElement * element);
|
GstElementState oldstate, GstElementState newstate, GstElement * element);
|
||||||
|
|
||||||
|
@ -181,6 +184,7 @@ gst_thread_class_init (gpointer g_class, gpointer class_data)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_thread_change_state);
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_thread_change_state);
|
||||||
|
gstelement_class->set_state = GST_DEBUG_FUNCPTR (gst_thread_set_state);
|
||||||
|
|
||||||
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_thread_set_property);
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_thread_set_property);
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_thread_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_thread_get_property);
|
||||||
|
@ -407,6 +411,26 @@ gst_thread_release (GstThread * thread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstElementStateReturn
|
||||||
|
gst_thread_set_state (GstElement * element, GstElementState state)
|
||||||
|
{
|
||||||
|
GstElementStateReturn result;
|
||||||
|
GstThread *thread = GST_THREAD (element);
|
||||||
|
|
||||||
|
if (thread != gst_thread_get_current ()) {
|
||||||
|
gst_thread_catch (thread);
|
||||||
|
g_mutex_unlock (thread->lock);
|
||||||
|
}
|
||||||
|
result =
|
||||||
|
GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, set_state, (element,
|
||||||
|
state), GST_STATE_FAILURE);
|
||||||
|
if (thread != gst_thread_get_current ()) {
|
||||||
|
g_mutex_lock (thread->lock);
|
||||||
|
gst_thread_release (thread);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static GstElementStateReturn
|
static GstElementStateReturn
|
||||||
gst_thread_change_state (GstElement * element)
|
gst_thread_change_state (GstElement * element)
|
||||||
{
|
{
|
||||||
|
@ -451,30 +475,13 @@ gst_thread_change_state (GstElement * element)
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_PLAYING:
|
case GST_STATE_PAUSED_TO_PLAYING:
|
||||||
{
|
{
|
||||||
/* FIXME: recurse into sub-bins */
|
|
||||||
GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
|
||||||
|
|
||||||
while (elements) {
|
|
||||||
gst_element_enable_threadsafe_properties ((GstElement *) elements->
|
|
||||||
data);
|
|
||||||
elements = g_list_next (elements);
|
|
||||||
}
|
|
||||||
/* reset self to spinning */
|
/* reset self to spinning */
|
||||||
if (thread == gst_thread_get_current ())
|
if (thread == gst_thread_get_current ())
|
||||||
GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
|
GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_STATE_PLAYING_TO_PAUSED:
|
case GST_STATE_PLAYING_TO_PAUSED:
|
||||||
{
|
|
||||||
GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
|
||||||
|
|
||||||
while (elements) {
|
|
||||||
gst_element_disable_threadsafe_properties ((GstElement *) elements->
|
|
||||||
data);
|
|
||||||
elements = g_list_next (elements);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
break;
|
break;
|
||||||
case GST_STATE_READY_TO_NULL:
|
case GST_STATE_READY_TO_NULL:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
include ../Rules
|
include ../Rules
|
||||||
|
|
||||||
tests_pass = locked parent
|
tests_pass = locked parent bin
|
||||||
tests_fail =
|
tests_fail =
|
||||||
tests_ignore =
|
tests_ignore =
|
||||||
|
|
||||||
|
|
150
tests/old/testsuite/states/bin.c
Normal file
150
tests/old/testsuite/states/bin.c
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
|
||||||
|
*
|
||||||
|
* bin.c:
|
||||||
|
*
|
||||||
|
* 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/gst.h>
|
||||||
|
|
||||||
|
#define RETURN_NAME(x) ((x) == GST_STATE_SUCCESS ? "GST_STATE_SUCCESS" : \
|
||||||
|
(x) == GST_STATE_ASYNC ? "GST_STATE_ASYNC" : "GST_STATE_FAILURE")
|
||||||
|
static void
|
||||||
|
assert_state (GstElement * element, GstElementState state)
|
||||||
|
{
|
||||||
|
if (gst_element_get_state (element) != state) {
|
||||||
|
g_printerr ("%s: state is %s instead of %s",
|
||||||
|
GST_OBJECT_NAME (element),
|
||||||
|
gst_element_state_get_name (GST_STATE (element)),
|
||||||
|
gst_element_state_get_name (state));
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
assert_state_change (GstElement * element, GstElementState new_state,
|
||||||
|
GstElementStateReturn result, GstElementState result_state)
|
||||||
|
{
|
||||||
|
GstElementStateReturn ret = gst_element_set_state (element, new_state);
|
||||||
|
|
||||||
|
if (ret != result) {
|
||||||
|
g_printerr ("%s: change state to %s returned %s instead of %s",
|
||||||
|
GST_OBJECT_NAME (element), gst_element_state_get_name (new_state),
|
||||||
|
RETURN_NAME (ret), RETURN_NAME (result));
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
assert_state (element, result_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
empty_bin (gchar * bin_name)
|
||||||
|
{
|
||||||
|
/* Test the behaviour of empty bins. Since a bin's state is always the state
|
||||||
|
* of its highest child, nothing should change in here
|
||||||
|
* Return values when no error occured but the state didn't change should be
|
||||||
|
* GST_STATE_ASYNC */
|
||||||
|
GstElement *bin = gst_element_factory_make (bin_name, NULL);
|
||||||
|
|
||||||
|
/* obvious */
|
||||||
|
assert_state (bin, GST_STATE_NULL);
|
||||||
|
/* see above */
|
||||||
|
assert_state_change (bin, GST_STATE_READY, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
assert_state_change (bin, GST_STATE_PAUSED, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
assert_state_change (bin, GST_STATE_PLAYING, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_adding_one_element (GstElement * bin)
|
||||||
|
{
|
||||||
|
/* Tests behaviour of adding/removing elements to/from bins. It makes sure the
|
||||||
|
* state of the bin is always the highest of all contained children. */
|
||||||
|
GstElementState test_states[] = { GST_STATE_READY, GST_STATE_PAUSED,
|
||||||
|
GST_STATE_PLAYING, GST_STATE_PAUSED, GST_STATE_READY, GST_STATE_NULL
|
||||||
|
};
|
||||||
|
GstElement *test = gst_element_factory_make ("identity", NULL);
|
||||||
|
GstElementState bin_state = gst_element_get_state (bin);
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
g_assert (test);
|
||||||
|
gst_object_ref (GST_OBJECT (test));
|
||||||
|
assert_state (test, GST_STATE_NULL);
|
||||||
|
gst_bin_add (GST_BIN (bin), test);
|
||||||
|
assert_state (bin, MAX (bin_state, GST_STATE_NULL));
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
|
||||||
|
GstElementState test_state = test_states[i];
|
||||||
|
|
||||||
|
assert_state_change (test, test_state, GST_STATE_SUCCESS, test_state);
|
||||||
|
assert_state (test, test_state);
|
||||||
|
assert_state (bin, MAX (bin_state, test_state));
|
||||||
|
gst_bin_remove (GST_BIN (bin), test);
|
||||||
|
assert_state (bin, bin_state);
|
||||||
|
gst_bin_add (GST_BIN (bin), test);
|
||||||
|
assert_state (test, test_state);
|
||||||
|
assert_state (bin, MAX (bin_state, test_state));
|
||||||
|
}
|
||||||
|
gst_bin_remove (GST_BIN (bin), test);
|
||||||
|
gst_object_unref (GST_OBJECT (test));
|
||||||
|
assert_state (bin, bin_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_element_in_bin (gchar * bin_name)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
GstElementState test_states[] = { GST_STATE_NULL, GST_STATE_READY,
|
||||||
|
GST_STATE_PAUSED, GST_STATE_PLAYING
|
||||||
|
};
|
||||||
|
GstElement *id, *bin = gst_element_factory_make (bin_name, NULL);
|
||||||
|
|
||||||
|
g_assert (bin);
|
||||||
|
|
||||||
|
/* test correct behaviour in empty bins */
|
||||||
|
test_adding_one_element (bin);
|
||||||
|
|
||||||
|
id = gst_element_factory_make ("identity", NULL);
|
||||||
|
g_assert (id);
|
||||||
|
assert_state (id, GST_STATE_NULL);
|
||||||
|
gst_bin_add (GST_BIN (bin), id);
|
||||||
|
/* test correct behaviour in bins which contain elements in various states */
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
|
||||||
|
GstElementState test_state = test_states[i];
|
||||||
|
|
||||||
|
assert_state_change (bin, test_state, GST_STATE_SUCCESS, test_state);
|
||||||
|
assert_state (id, test_state);
|
||||||
|
test_adding_one_element (bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_object_unref (GST_OBJECT (bin));
|
||||||
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
main (gint argc, gchar * argv[])
|
||||||
|
{
|
||||||
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
|
/* test behaviour of empty bins */
|
||||||
|
empty_bin ("bin");
|
||||||
|
empty_bin ("thread");
|
||||||
|
empty_bin ("pipeline");
|
||||||
|
|
||||||
|
/* test behaviour of adding/removing elements to/from all core bin types */
|
||||||
|
test_element_in_bin ("bin");
|
||||||
|
test_element_in_bin ("thread");
|
||||||
|
test_element_in_bin ("pipeline");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
include ../Rules
|
include ../Rules
|
||||||
|
|
||||||
tests_pass = thread1 thread2 thread3 thread4 threadf
|
tests_pass = thread1 thread2 thread3 thread4 threadf
|
||||||
tests_fail = thread5 threadd queue threadg
|
tests_fail = thread5 threadd threadg
|
||||||
|
|
||||||
tests_ignore = threade threadb threadc
|
tests_ignore = queue threade threadb threadc
|
||||||
|
|
||||||
queue_SOURCES = queue.c
|
queue_SOURCES = queue.c
|
||||||
queue_CFLAGS = $(AM_CFLAGS)
|
queue_CFLAGS = $(AM_CFLAGS)
|
||||||
|
|
|
@ -76,7 +76,7 @@ main (gint argc, gchar * argv[])
|
||||||
gst_element_set_state (thread, GST_STATE_PLAYING);
|
gst_element_set_state (thread, GST_STATE_PLAYING);
|
||||||
g_print ("SLEEPING 1 sec\n");
|
g_print ("SLEEPING 1 sec\n");
|
||||||
sleep (1);
|
sleep (1);
|
||||||
gst_bin_sync_children_state (GST_BIN (pipeline));
|
gst_element_set_state (pipeline, gst_element_get_state (pipeline));
|
||||||
g_print ("SLEEPING 2 sec\n");
|
g_print ("SLEEPING 2 sec\n");
|
||||||
sleep (2);
|
sleep (2);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
include ../Rules
|
include ../Rules
|
||||||
|
|
||||||
tests_pass = locked parent
|
tests_pass = locked parent bin
|
||||||
tests_fail =
|
tests_fail =
|
||||||
tests_ignore =
|
tests_ignore =
|
||||||
|
|
||||||
|
|
150
testsuite/states/bin.c
Normal file
150
testsuite/states/bin.c
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
|
||||||
|
*
|
||||||
|
* bin.c:
|
||||||
|
*
|
||||||
|
* 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/gst.h>
|
||||||
|
|
||||||
|
#define RETURN_NAME(x) ((x) == GST_STATE_SUCCESS ? "GST_STATE_SUCCESS" : \
|
||||||
|
(x) == GST_STATE_ASYNC ? "GST_STATE_ASYNC" : "GST_STATE_FAILURE")
|
||||||
|
static void
|
||||||
|
assert_state (GstElement * element, GstElementState state)
|
||||||
|
{
|
||||||
|
if (gst_element_get_state (element) != state) {
|
||||||
|
g_printerr ("%s: state is %s instead of %s",
|
||||||
|
GST_OBJECT_NAME (element),
|
||||||
|
gst_element_state_get_name (GST_STATE (element)),
|
||||||
|
gst_element_state_get_name (state));
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
assert_state_change (GstElement * element, GstElementState new_state,
|
||||||
|
GstElementStateReturn result, GstElementState result_state)
|
||||||
|
{
|
||||||
|
GstElementStateReturn ret = gst_element_set_state (element, new_state);
|
||||||
|
|
||||||
|
if (ret != result) {
|
||||||
|
g_printerr ("%s: change state to %s returned %s instead of %s",
|
||||||
|
GST_OBJECT_NAME (element), gst_element_state_get_name (new_state),
|
||||||
|
RETURN_NAME (ret), RETURN_NAME (result));
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
assert_state (element, result_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
empty_bin (gchar * bin_name)
|
||||||
|
{
|
||||||
|
/* Test the behaviour of empty bins. Since a bin's state is always the state
|
||||||
|
* of its highest child, nothing should change in here
|
||||||
|
* Return values when no error occured but the state didn't change should be
|
||||||
|
* GST_STATE_ASYNC */
|
||||||
|
GstElement *bin = gst_element_factory_make (bin_name, NULL);
|
||||||
|
|
||||||
|
/* obvious */
|
||||||
|
assert_state (bin, GST_STATE_NULL);
|
||||||
|
/* see above */
|
||||||
|
assert_state_change (bin, GST_STATE_READY, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
assert_state_change (bin, GST_STATE_PAUSED, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
assert_state_change (bin, GST_STATE_PLAYING, GST_STATE_ASYNC, GST_STATE_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_adding_one_element (GstElement * bin)
|
||||||
|
{
|
||||||
|
/* Tests behaviour of adding/removing elements to/from bins. It makes sure the
|
||||||
|
* state of the bin is always the highest of all contained children. */
|
||||||
|
GstElementState test_states[] = { GST_STATE_READY, GST_STATE_PAUSED,
|
||||||
|
GST_STATE_PLAYING, GST_STATE_PAUSED, GST_STATE_READY, GST_STATE_NULL
|
||||||
|
};
|
||||||
|
GstElement *test = gst_element_factory_make ("identity", NULL);
|
||||||
|
GstElementState bin_state = gst_element_get_state (bin);
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
g_assert (test);
|
||||||
|
gst_object_ref (GST_OBJECT (test));
|
||||||
|
assert_state (test, GST_STATE_NULL);
|
||||||
|
gst_bin_add (GST_BIN (bin), test);
|
||||||
|
assert_state (bin, MAX (bin_state, GST_STATE_NULL));
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
|
||||||
|
GstElementState test_state = test_states[i];
|
||||||
|
|
||||||
|
assert_state_change (test, test_state, GST_STATE_SUCCESS, test_state);
|
||||||
|
assert_state (test, test_state);
|
||||||
|
assert_state (bin, MAX (bin_state, test_state));
|
||||||
|
gst_bin_remove (GST_BIN (bin), test);
|
||||||
|
assert_state (bin, bin_state);
|
||||||
|
gst_bin_add (GST_BIN (bin), test);
|
||||||
|
assert_state (test, test_state);
|
||||||
|
assert_state (bin, MAX (bin_state, test_state));
|
||||||
|
}
|
||||||
|
gst_bin_remove (GST_BIN (bin), test);
|
||||||
|
gst_object_unref (GST_OBJECT (test));
|
||||||
|
assert_state (bin, bin_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_element_in_bin (gchar * bin_name)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
GstElementState test_states[] = { GST_STATE_NULL, GST_STATE_READY,
|
||||||
|
GST_STATE_PAUSED, GST_STATE_PLAYING
|
||||||
|
};
|
||||||
|
GstElement *id, *bin = gst_element_factory_make (bin_name, NULL);
|
||||||
|
|
||||||
|
g_assert (bin);
|
||||||
|
|
||||||
|
/* test correct behaviour in empty bins */
|
||||||
|
test_adding_one_element (bin);
|
||||||
|
|
||||||
|
id = gst_element_factory_make ("identity", NULL);
|
||||||
|
g_assert (id);
|
||||||
|
assert_state (id, GST_STATE_NULL);
|
||||||
|
gst_bin_add (GST_BIN (bin), id);
|
||||||
|
/* test correct behaviour in bins which contain elements in various states */
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
|
||||||
|
GstElementState test_state = test_states[i];
|
||||||
|
|
||||||
|
assert_state_change (bin, test_state, GST_STATE_SUCCESS, test_state);
|
||||||
|
assert_state (id, test_state);
|
||||||
|
test_adding_one_element (bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_object_unref (GST_OBJECT (bin));
|
||||||
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
main (gint argc, gchar * argv[])
|
||||||
|
{
|
||||||
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
|
/* test behaviour of empty bins */
|
||||||
|
empty_bin ("bin");
|
||||||
|
empty_bin ("thread");
|
||||||
|
empty_bin ("pipeline");
|
||||||
|
|
||||||
|
/* test behaviour of adding/removing elements to/from all core bin types */
|
||||||
|
test_element_in_bin ("bin");
|
||||||
|
test_element_in_bin ("thread");
|
||||||
|
test_element_in_bin ("pipeline");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
include ../Rules
|
include ../Rules
|
||||||
|
|
||||||
tests_pass = thread1 thread2 thread3 thread4 threadf
|
tests_pass = thread1 thread2 thread3 thread4 threadf
|
||||||
tests_fail = thread5 threadd queue threadg
|
tests_fail = thread5 threadd threadg
|
||||||
|
|
||||||
tests_ignore = threade threadb threadc
|
tests_ignore = queue threade threadb threadc
|
||||||
|
|
||||||
queue_SOURCES = queue.c
|
queue_SOURCES = queue.c
|
||||||
queue_CFLAGS = $(AM_CFLAGS)
|
queue_CFLAGS = $(AM_CFLAGS)
|
||||||
|
|
|
@ -76,7 +76,7 @@ main (gint argc, gchar * argv[])
|
||||||
gst_element_set_state (thread, GST_STATE_PLAYING);
|
gst_element_set_state (thread, GST_STATE_PLAYING);
|
||||||
g_print ("SLEEPING 1 sec\n");
|
g_print ("SLEEPING 1 sec\n");
|
||||||
sleep (1);
|
sleep (1);
|
||||||
gst_bin_sync_children_state (GST_BIN (pipeline));
|
gst_element_set_state (pipeline, gst_element_get_state (pipeline));
|
||||||
g_print ("SLEEPING 2 sec\n");
|
g_print ("SLEEPING 2 sec\n");
|
||||||
sleep (2);
|
sleep (2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue