From ab5ba6271c2ba15b8a105120300091f4b645d36d Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sat, 14 May 2005 18:01:12 +0000 Subject: [PATCH] gst/gstbin.c (gst_bin_iterate_sinks): Use sink_iterator_filter so as to get the refs right. Original commit message from CVS: 2005-05-14 Andy Wingo * gst/gstbin.c (gst_bin_iterate_sinks): Use sink_iterator_filter so as to get the refs right. (sink_iterator_filter): New function, wraps bin_element_is_sink, unreffing objects that don't pass the filter. --- ChangeLog | 5 +++++ gst/gstbin.c | 33 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f17c229d93..46471816d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-05-14 Andy Wingo + * gst/gstbin.c (gst_bin_iterate_sinks): Use sink_iterator_filter + so as to get the refs right. + (sink_iterator_filter): New function, wraps bin_element_is_sink, + unreffing objects that don't pass the filter. + * gst/gstpipeline.c (gst_pipeline_init): Drop ref on bus after gst_element_set_bus. (gst_pipeline_dispose): Set the bus on the pipeline to NULL. In diff --git a/gst/gstbin.c b/gst/gstbin.c index 46d0a55821..86e83a8361 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -685,16 +685,10 @@ gst_bin_iterate_recurse (GstBin * bin) return result; } -/* returns 0 if the element is a sink, this is made so that - * we can use this function as a filter - * - * MT safe - */ +/* MT safe */ static gint bin_element_is_sink (GstElement * child, GstBin * bin) { - gint ret; - /* we lock the child here for the remainder of the function to * get its name safely. */ GST_LOCK (child); @@ -702,14 +696,28 @@ bin_element_is_sink (GstElement * child, GstBin * bin) GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, bin, "finding child %s as sink", GST_OBJECT_NAME (child)); GST_UNLOCK (child); - ret = 0; + /* returns 0 because this is a GCompareFunc */ + return 0; } else { GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, bin, "child %s is not a sink", GST_OBJECT_NAME (child)); GST_UNLOCK (child); - ret = 1; + return 1; + } +} + +static gint +sink_iterator_filter (GstElement * child, GstBin * bin) +{ + if (bin_element_is_sink (child, bin)) { + /* returns 0 because this is a GCompareFunc */ + return 0; + } else { + /* child carries a ref from gst_bin_iterate_elements -- drop if not passing + through */ + gst_object_unref ((GstObject *) child); + return 1; } - return ret; } /** @@ -736,7 +744,7 @@ gst_bin_iterate_sinks (GstBin * bin) children = gst_bin_iterate_elements (bin); result = gst_iterator_filter (children, - (GCompareFunc) bin_element_is_sink, bin); + (GCompareFunc) sink_iterator_filter, bin); return result; } @@ -877,9 +885,6 @@ restart: GST_UNLOCK (bin); if (bin_element_is_sink (child, bin) == 0) { - /* this also keeps the refcount on the element, note that - * the _is_sink function unrefs the element when it is not - * a sink. */ g_queue_push_tail (elem_queue, child); } else { g_queue_push_tail (temp, child);