Update our internal state counters when adding/removing elements.

Original commit message from CVS:
Update our internal state counters when adding/removing elements.
This commit is contained in:
Wim Taymans 2001-12-10 18:08:35 +00:00
parent d2bceb75d7
commit 970e58ebd3

View file

@ -256,6 +256,9 @@ void
gst_bin_add (GstBin *bin, gst_bin_add (GstBin *bin,
GstElement *element) GstElement *element)
{ {
gint state_idx = 0;
GstElementState state;
g_return_if_fail (bin != NULL); g_return_if_fail (bin != NULL);
g_return_if_fail (GST_IS_BIN (bin)); g_return_if_fail (GST_IS_BIN (bin));
g_return_if_fail (element != NULL); g_return_if_fail (element != NULL);
@ -280,6 +283,11 @@ gst_bin_add (GstBin *bin,
bin->children = g_list_append (bin->children, element); bin->children = g_list_append (bin->children, element);
bin->numchildren++; bin->numchildren++;
// bump our internal state counter
state = GST_STATE (element);
while (state>>=1) state_idx++;
bin->child_states[state_idx]++;
///// now we have to deal with manager stuff ///// now we have to deal with manager stuff
// we can only do this if there's a scheduler: // we can only do this if there's a scheduler:
// if we're not a manager, and aren't attached to anything, we have no sched (yet) // if we're not a manager, and aren't attached to anything, we have no sched (yet)
@ -306,6 +314,9 @@ void
gst_bin_remove (GstBin *bin, gst_bin_remove (GstBin *bin,
GstElement *element) GstElement *element)
{ {
gint state_idx = 0;
GstElementState state;
g_return_if_fail (bin != NULL); g_return_if_fail (bin != NULL);
g_return_if_fail (GST_IS_BIN (bin)); g_return_if_fail (GST_IS_BIN (bin));
g_return_if_fail (element != NULL); g_return_if_fail (element != NULL);
@ -332,6 +343,11 @@ gst_bin_remove (GstBin *bin,
bin->children = g_list_remove (bin->children, element); bin->children = g_list_remove (bin->children, element);
bin->numchildren--; bin->numchildren--;
// bump our internal state counter
state = GST_STATE (element);
while (state>>=1) state_idx++;
bin->child_states[state_idx]--;
GST_INFO_ELEMENT (GST_CAT_PARENTAGE, bin, "removed child %s", GST_ELEMENT_NAME (element)); GST_INFO_ELEMENT (GST_CAT_PARENTAGE, bin, "removed child %s", GST_ELEMENT_NAME (element));
gst_object_unparent (GST_OBJECT (element)); gst_object_unparent (GST_OBJECT (element));
@ -711,7 +727,7 @@ gst_bin_iterate (GstBin *bin)
if (oclass->iterate) if (oclass->iterate)
running = (oclass->iterate) (bin); running = (oclass->iterate) (bin);
GST_DEBUG_LEAVE("(\"%s\")",GST_ELEMENT_NAME (bin)); GST_DEBUG_LEAVE("(\"%s\") %d",GST_ELEMENT_NAME (bin), running);
if (!running) { if (!running) {
if (GST_STATE (bin) == GST_STATE_PLAYING && GST_STATE_PENDING (bin) == GST_STATE_VOID_PENDING) { if (GST_STATE (bin) == GST_STATE_PLAYING && GST_STATE_PENDING (bin) == GST_STATE_VOID_PENDING) {