gst: Update everything for the new GstIterator API

This commit is contained in:
Sebastian Dröge 2011-03-17 11:31:59 +01:00
parent 348563bc19
commit 98d1ee4a8f
8 changed files with 256 additions and 199 deletions

View file

@ -640,6 +640,7 @@ gst_bin_set_index_func (GstElement * element, GstIndex * index)
gboolean done;
GstIterator *it;
GstIndex *old;
GValue data = { 0, };
bin = GST_BIN_CAST (element);
@ -660,18 +661,16 @@ gst_bin_set_index_func (GstElement * element, GstIndex * index)
/* set the index on all elements in the bin */
done = FALSE;
while (!done) {
gpointer data;
switch (gst_iterator_next (it, &data)) {
case GST_ITERATOR_OK:
{
GstElement *child = GST_ELEMENT_CAST (data);
GstElement *child = g_value_get_object (&data);
GST_DEBUG_OBJECT (bin, "setting index on '%s'",
GST_ELEMENT_NAME (child));
gst_element_set_index (child, index);
gst_object_unref (child);
g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
@ -685,6 +684,7 @@ gst_bin_set_index_func (GstElement * element, GstIndex * index)
break;
}
}
g_value_unset (&data);
gst_iterator_free (it);
return;
@ -707,6 +707,7 @@ gst_bin_set_clock_func (GstElement * element, GstClock * clock)
gboolean done;
GstIterator *it;
gboolean res = TRUE;
GValue data = { 0, };
bin = GST_BIN_CAST (element);
@ -714,16 +715,14 @@ gst_bin_set_clock_func (GstElement * element, GstClock * clock)
done = FALSE;
while (!done) {
gpointer data;
switch (gst_iterator_next (it, &data)) {
case GST_ITERATOR_OK:
{
GstElement *child = GST_ELEMENT_CAST (data);
GstElement *child = g_value_get_object (&data);
res &= gst_element_set_clock (child, clock);
gst_object_unref (child);
g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
@ -738,6 +737,7 @@ gst_bin_set_clock_func (GstElement * element, GstClock * clock)
break;
}
}
g_value_unset (&data);
gst_iterator_free (it);
return res;
@ -759,7 +759,8 @@ gst_bin_provide_clock_func (GstElement * element)
GstElement *provider = NULL;
GstBin *bin;
GstIterator *it;
gpointer val;
gboolean done;
GValue val = { 0, };
GstClock **provided_clock_p;
GstElement **clock_provider_p;
@ -772,25 +773,53 @@ gst_bin_provide_clock_func (GstElement * element)
GST_DEBUG_OBJECT (bin, "finding new clock");
it = gst_bin_sort_iterator_new (bin);
GST_OBJECT_UNLOCK (bin);
while (it->next (it, &val) == GST_ITERATOR_OK) {
GstElement *child = GST_ELEMENT_CAST (val);
GstClock *clock;
done = FALSE;
while (!done) {
switch (gst_iterator_next (it, &val)) {
case GST_ITERATOR_OK:
{
GstElement *child = g_value_get_object (&val);
GstClock *clock;
clock = gst_element_provide_clock (child);
if (clock) {
GST_DEBUG_OBJECT (bin, "found candidate clock %p by element %s",
clock, GST_ELEMENT_NAME (child));
if (result) {
gst_object_unref (result);
gst_object_unref (provider);
clock = gst_element_provide_clock (child);
if (clock) {
GST_DEBUG_OBJECT (bin, "found candidate clock %p by element %s",
clock, GST_ELEMENT_NAME (child));
if (result) {
gst_object_unref (result);
gst_object_unref (provider);
}
result = clock;
provider = gst_object_ref (child);
}
g_value_reset (&val);
break;
}
result = clock;
provider = child;
} else {
gst_object_unref (child);
case GST_ITERATOR_RESYNC:
gst_iterator_resync (it);
break;
default:
case GST_ITERATOR_DONE:
done = TRUE;
break;
}
}
g_value_unset (&val);
gst_iterator_free (it);
GST_OBJECT_LOCK (bin);
if (!bin->clock_dirty) {
if (provider)
gst_object_unref (provider);
if (result)
gst_object_unref (result);
result = NULL;
goto not_dirty;
}
provided_clock_p = &bin->provided_clock;
clock_provider_p = &bin->clock_provider;
@ -805,8 +834,6 @@ gst_bin_provide_clock_func (GstElement * element)
gst_object_unref (provider);
GST_OBJECT_UNLOCK (bin);
gst_iterator_free (it);
return result;
not_dirty:
@ -981,10 +1008,13 @@ is_eos (GstBin * bin, guint32 * seqnum)
}
static void
unlink_pads (GstPad * pad)
unlink_pads (const GValue * item, gpointer user_data)
{
GstPad *pad;
GstPad *peer;
pad = g_value_get_object (item);
if ((peer = gst_pad_get_peer (pad))) {
if (gst_pad_get_direction (pad) == GST_PAD_SRC)
gst_pad_unlink (pad, peer);
@ -992,7 +1022,6 @@ unlink_pads (GstPad * pad)
gst_pad_unlink (peer, pad);
gst_object_unref (peer);
}
gst_object_unref (pad);
}
/* vmethod that adds an element to a bin
@ -1114,7 +1143,7 @@ no_state_recalc:
/* unlink all linked pads */
it = gst_element_iterate_pads (element);
gst_iterator_foreach (it, (GFunc) unlink_pads, element);
gst_iterator_foreach (it, (GstIteratorForeachFunction) unlink_pads, NULL);
gst_iterator_free (it);
GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
@ -1240,7 +1269,7 @@ gst_bin_remove_func (GstBin * bin, GstElement * element)
/* unlink all linked pads */
it = gst_element_iterate_pads (element);
gst_iterator_foreach (it, (GFunc) unlink_pads, element);
gst_iterator_foreach (it, (GstIteratorForeachFunction) unlink_pads, NULL);
gst_iterator_free (it);
GST_OBJECT_LOCK (bin);
@ -1505,13 +1534,6 @@ no_function:
}
}
static GstIteratorItem
iterate_child (GstIterator * it, GstElement * child)
{
gst_object_ref (child);
return GST_ITERATOR_ITEM_PASS;
}
/**
* gst_bin_iterate_elements:
* @bin: a #GstBin
@ -1533,26 +1555,19 @@ gst_bin_iterate_elements (GstBin * bin)
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
GST_OBJECT_LOCK (bin);
/* add ref because the iterator refs the bin. When the iterator
* is freed it will unref the bin again using the provided dispose
* function. */
gst_object_ref (bin);
result = gst_iterator_new_list (GST_TYPE_ELEMENT,
GST_OBJECT_GET_LOCK (bin),
&bin->children_cookie,
&bin->children,
bin,
(GstIteratorItemFunction) iterate_child,
(GstIteratorDisposeFunction) gst_object_unref);
&bin->children_cookie, &bin->children, (GObject *) bin, NULL);
GST_OBJECT_UNLOCK (bin);
return result;
}
static GstIteratorItem
iterate_child_recurse (GstIterator * it, GstElement * child)
iterate_child_recurse (GstIterator * it, const GValue * item)
{
gst_object_ref (child);
GstElement *child = g_value_get_object (item);
if (GST_IS_BIN (child)) {
GstIterator *other = gst_bin_iterate_recurse (GST_BIN_CAST (child));
@ -1583,17 +1598,11 @@ gst_bin_iterate_recurse (GstBin * bin)
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
GST_OBJECT_LOCK (bin);
/* add ref because the iterator refs the bin. When the iterator
* is freed it will unref the bin again using the provided dispose
* function. */
gst_object_ref (bin);
result = gst_iterator_new_list (GST_TYPE_ELEMENT,
GST_OBJECT_GET_LOCK (bin),
&bin->children_cookie,
&bin->children,
bin,
(GstIteratorItemFunction) iterate_child_recurse,
(GstIteratorDisposeFunction) gst_object_unref);
(GObject *) bin, (GstIteratorItemFunction) iterate_child_recurse);
GST_OBJECT_UNLOCK (bin);
return result;
@ -1619,17 +1628,12 @@ bin_element_is_sink (GstElement * child, GstBin * bin)
}
static gint
sink_iterator_filter (GstElement * child, GstBin * bin)
sink_iterator_filter (const GValue * vchild, GValue * vbin)
{
if (bin_element_is_sink (child, bin) == 0) {
/* 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 (child);
return 1;
}
GstBin *bin = g_value_get_object (vbin);
GstElement *child = g_value_get_object (vchild);
return (bin_element_is_sink (child, bin));
}
/**
@ -1651,12 +1655,18 @@ gst_bin_iterate_sinks (GstBin * bin)
{
GstIterator *children;
GstIterator *result;
GValue vbin = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_value_init (&vbin, GST_TYPE_BIN);
g_value_set_object (&vbin, bin);
children = gst_bin_iterate_elements (bin);
result = gst_iterator_filter (children,
(GCompareFunc) sink_iterator_filter, bin);
(GCompareFunc) sink_iterator_filter, &vbin);
g_value_unset (&vbin);
return result;
}
@ -1681,17 +1691,12 @@ bin_element_is_src (GstElement * child, GstBin * bin)
}
static gint
src_iterator_filter (GstElement * child, GstBin * bin)
src_iterator_filter (const GValue * vchild, GValue * vbin)
{
if (bin_element_is_src (child, bin) == 0) {
/* 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 (child);
return 1;
}
GstBin *bin = g_value_get_object (vbin);
GstElement *child = g_value_get_object (vchild);
return (bin_element_is_src (child, bin));
}
/**
@ -1713,12 +1718,18 @@ gst_bin_iterate_sources (GstBin * bin)
{
GstIterator *children;
GstIterator *result;
GValue vbin = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_value_init (&vbin, GST_TYPE_BIN);
g_value_set_object (&vbin, bin);
children = gst_bin_iterate_elements (bin);
result = gst_iterator_filter (children,
(GCompareFunc) src_iterator_filter, bin);
(GCompareFunc) src_iterator_filter, &vbin);
g_value_unset (&vbin);
return result;
}
@ -1765,6 +1776,26 @@ typedef struct _GstBinSortIterator
gboolean dirty; /* we detected structure change */
} GstBinSortIterator;
static void
gst_bin_sort_iterator_copy (const GstBinSortIterator * it,
GstBinSortIterator * copy)
{
GHashTableIter iter;
gpointer key, value;
copy->queue = g_queue_copy (it->queue);
g_queue_foreach (copy->queue, (GFunc) gst_object_ref, NULL);
copy->bin = gst_object_ref (it->bin);
if (it->best)
copy->best = gst_object_ref (it->best);
copy->hash = g_hash_table_new (NULL, NULL);
g_hash_table_iter_init (&iter, it->hash);
while (g_hash_table_iter_next (&iter, &key, &value))
g_hash_table_insert (copy->hash, key, value);
}
/* we add and subtract 1 to make sure we don't confuse NULL and 0 */
#define HASH_SET_DEGREE(bit, elem, deg) \
g_hash_table_replace (bit->hash, elem, GINT_TO_POINTER(deg+1))
@ -1944,13 +1975,13 @@ find_element (GstElement * element, GstBinSortIterator * bit)
/* get next element in iterator. the returned element has the
* refcount increased */
static GstIteratorResult
gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
gst_bin_sort_iterator_next (GstBinSortIterator * bit, GValue * result)
{
GstElement *best;
GstBin *bin = bit->bin;
/* empty queue, we have to find a next best element */
if (g_queue_is_empty (bit->queue)) {
GstElement *best;
bit->best = NULL;
bit->best_deg = G_MAXINT;
@ -1967,9 +1998,8 @@ gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
/* best unhandled element, schedule as next element */
GST_DEBUG_OBJECT (bin, "queue empty, next best: %s",
GST_ELEMENT_NAME (best));
gst_object_ref (best);
HASH_SET_DEGREE (bit, best, -1);
*result = best;
g_value_set_object (result, best);
} else {
GST_DEBUG_OBJECT (bin, "queue empty, elements exhausted");
/* no more unhandled elements, we are done */
@ -1977,12 +2007,14 @@ gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
}
} else {
/* everything added to the queue got reffed */
*result = g_queue_pop_head (bit->queue);
best = g_queue_pop_head (bit->queue);
g_value_set_object (result, best);
gst_object_unref (best);
}
GST_DEBUG_OBJECT (bin, "queue head gives %s", GST_ELEMENT_NAME (*result));
GST_DEBUG_OBJECT (bin, "queue head gives %s", GST_ELEMENT_NAME (best));
/* update degrees of linked elements */
update_degree (GST_ELEMENT_CAST (*result), bit);
update_degree (best, bit);
return GST_ITERATOR_OK;
}
@ -2031,6 +2063,7 @@ gst_bin_sort_iterator_new (GstBin * bin)
GST_TYPE_ELEMENT,
GST_OBJECT_GET_LOCK (bin),
&bin->priv->structure_cookie,
(GstIteratorCopyFunction) gst_bin_sort_iterator_copy,
(GstIteratorNextFunction) gst_bin_sort_iterator_next,
(GstIteratorItemFunction) NULL,
(GstIteratorResyncFunction) gst_bin_sort_iterator_resync,
@ -2197,8 +2230,9 @@ unneeded:
/* gst_iterator_fold functions for pads_activate
* Stop the iterator if activating one pad failed. */
static gboolean
activate_pads (GstPad * pad, GValue * ret, gboolean * active)
activate_pads (const GValue * vpad, GValue * ret, gboolean * active)
{
GstPad *pad = g_value_get_object (vpad);
gboolean cont = TRUE;
if (!(cont = gst_pad_set_active (pad, *active)))
@ -2207,7 +2241,6 @@ activate_pads (GstPad * pad, GValue * ret, gboolean * active)
gst_pad_set_caps (pad, NULL);
/* unref the object that was reffed for us by _fold */
gst_object_unref (pad);
return cont;
}
@ -2367,6 +2400,7 @@ gst_bin_change_state_func (GstElement * element, GstStateChange transition)
GstClockTime base_time, start_time;
GstIterator *it;
gboolean done;
GValue data = { 0, };
/* we don't need to take the STATE_LOCK, it is already taken */
current = (GstState) GST_STATE_TRANSITION_CURRENT (transition);
@ -2445,14 +2479,12 @@ restart:
done = FALSE;
while (!done) {
gpointer data;
switch (gst_iterator_next (it, &data)) {
case GST_ITERATOR_OK:
{
GstElement *child;
child = GST_ELEMENT_CAST (data);
child = g_value_get_object (&data);
/* set state and base_time now */
ret = gst_bin_element_set_state (bin, child, base_time, start_time,
@ -2488,7 +2520,6 @@ restart:
parent = gst_object_get_parent (GST_OBJECT_CAST (child));
if (parent == GST_OBJECT_CAST (element)) {
/* element is still in bin, really error now */
gst_object_unref (child);
gst_object_unref (parent);
goto done;
}
@ -2514,7 +2545,7 @@ restart:
g_assert_not_reached ();
break;
}
gst_object_unref (child);
g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
@ -2545,6 +2576,7 @@ restart:
}
done:
g_value_unset (&data);
gst_iterator_free (it);
GST_OBJECT_LOCK (bin);
@ -2620,6 +2652,7 @@ gst_bin_send_event (GstElement * element, GstEvent * event)
GstIterator *iter;
gboolean res = TRUE;
gboolean done = FALSE;
GValue data = { 0, };
if (GST_EVENT_IS_DOWNSTREAM (event)) {
iter = gst_bin_iterate_sources (bin);
@ -2632,17 +2665,14 @@ gst_bin_send_event (GstElement * element, GstEvent * event)
}
while (!done) {
gpointer data;
switch (gst_iterator_next (iter, &data)) {
case GST_ITERATOR_OK:
{
GstElement *child;
GstElement *child = g_value_get_object (&data);;
gst_event_ref (event);
child = GST_ELEMENT_CAST (data);
res &= gst_element_send_event (child, event);
gst_object_unref (child);
g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
@ -2657,6 +2687,7 @@ gst_bin_send_event (GstElement * element, GstEvent * event)
break;
}
}
g_value_unset (&data);
gst_iterator_free (iter);
gst_event_unref (event);
@ -3403,8 +3434,10 @@ bin_query_min_max_init (GstBin * bin, QueryFold * fold)
}
static gboolean
bin_query_duration_fold (GstElement * item, GValue * ret, QueryFold * fold)
bin_query_duration_fold (const GValue * vitem, GValue * ret, QueryFold * fold)
{
GstElement *item = g_value_get_object (vitem);
if (gst_element_query (item, fold->query)) {
gint64 duration;
@ -3418,7 +3451,6 @@ bin_query_duration_fold (GstElement * item, GValue * ret, QueryFold * fold)
fold->max = duration;
}
gst_object_unref (item);
return TRUE;
}
@ -3441,8 +3473,10 @@ bin_query_duration_done (GstBin * bin, QueryFold * fold)
}
static gboolean
bin_query_position_fold (GstElement * item, GValue * ret, QueryFold * fold)
bin_query_position_fold (const GValue * vitem, GValue * ret, QueryFold * fold)
{
GstElement *item = g_value_get_object (vitem);
if (gst_element_query (item, fold->query)) {
gint64 position;
@ -3456,7 +3490,6 @@ bin_query_position_fold (GstElement * item, GValue * ret, QueryFold * fold)
fold->max = position;
}
gst_object_unref (item);
return TRUE;
}
@ -3473,8 +3506,10 @@ bin_query_position_done (GstBin * bin, QueryFold * fold)
}
static gboolean
bin_query_latency_fold (GstElement * item, GValue * ret, QueryFold * fold)
bin_query_latency_fold (const GValue * vitem, GValue * ret, QueryFold * fold)
{
GstElement *item = g_value_get_object (vitem);
if (gst_element_query (item, fold->query)) {
GstClockTime min, max;
gboolean live;
@ -3502,7 +3537,6 @@ bin_query_latency_fold (GstElement * item, GValue * ret, QueryFold * fold)
GST_DEBUG_OBJECT (item, "failed query");
}
gst_object_unref (item);
return TRUE;
}
@ -3520,8 +3554,9 @@ bin_query_latency_done (GstBin * bin, QueryFold * fold)
/* generic fold, return first valid result */
static gboolean
bin_query_generic_fold (GstElement * item, GValue * ret, QueryFold * fold)
bin_query_generic_fold (const GValue * vitem, GValue * ret, QueryFold * fold)
{
GstElement *item = g_value_get_object (vitem);
gboolean res;
if ((res = gst_element_query (item, fold->query))) {
@ -3529,8 +3564,6 @@ bin_query_generic_fold (GstElement * item, GValue * ret, QueryFold * fold)
GST_DEBUG_OBJECT (item, "answered query %p", fold->query);
}
gst_object_unref (item);
/* and stop as soon as we have a valid result */
return !res;
}
@ -3652,17 +3685,15 @@ exit:
}
static gint
compare_name (GstElement * element, const gchar * name)
compare_name (const GValue * velement, const gchar * name)
{
gint eq;
GstElement *element = g_value_get_object (velement);
GST_OBJECT_LOCK (element);
eq = strcmp (GST_ELEMENT_NAME (element), name);
GST_OBJECT_UNLOCK (element);
if (eq != 0) {
gst_object_unref (element);
}
return eq;
}
@ -3684,7 +3715,9 @@ GstElement *
gst_bin_get_by_name (GstBin * bin, const gchar * name)
{
GstIterator *children;
gpointer result;
GValue result = { 0, };
GstElement *element;
gboolean found;
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
@ -3692,11 +3725,18 @@ gst_bin_get_by_name (GstBin * bin, const gchar * name)
GST_ELEMENT_NAME (bin), name);
children = gst_bin_iterate_recurse (bin);
result = gst_iterator_find_custom (children,
(GCompareFunc) compare_name, (gpointer) name);
found = gst_iterator_find_custom (children,
(GCompareFunc) compare_name, &result, (gpointer) name);
gst_iterator_free (children);
return GST_ELEMENT_CAST (result);
if (found) {
element = g_value_dup_object (&result);
g_value_unset (&result);
} else {
element = NULL;
}
return element;
}
/**
@ -3740,17 +3780,15 @@ gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
}
static gint
compare_interface (GstElement * element, gpointer interface)
compare_interface (const GValue * velement, GValue * interface)
{
GType interface_type = (GType) interface;
GstElement *element = g_value_get_object (velement);
GType interface_type = (GType) g_value_get_pointer (interface);
gint ret;
if (G_TYPE_CHECK_INSTANCE_TYPE (element, interface_type)) {
ret = 0;
} else {
/* we did not find the element, need to release the ref
* added by the iterator */
gst_object_unref (element);
ret = 1;
}
return ret;
@ -3775,17 +3813,31 @@ GstElement *
gst_bin_get_by_interface (GstBin * bin, GType iface)
{
GstIterator *children;
gpointer result;
GValue result = { 0, };
GstElement *element;
gboolean found;
GValue viface = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (G_TYPE_IS_INTERFACE (iface), NULL);
g_value_init (&viface, G_TYPE_POINTER);
g_value_set_pointer (&viface, (gpointer) iface);
children = gst_bin_iterate_recurse (bin);
result = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
(gpointer) iface);
found = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
&result, &viface);
gst_iterator_free (children);
return GST_ELEMENT_CAST (result);
if (found) {
element = g_value_dup_object (&result);
g_value_unset (&result);
} else {
element = NULL;
}
g_value_unset (&viface);
return element;
}
/**
@ -3811,13 +3863,19 @@ gst_bin_iterate_all_by_interface (GstBin * bin, GType iface)
{
GstIterator *children;
GstIterator *result;
GValue viface = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (G_TYPE_IS_INTERFACE (iface), NULL);
g_value_init (&viface, G_TYPE_POINTER);
g_value_set_pointer (&viface, (gpointer) iface);
children = gst_bin_iterate_recurse (bin);
result = gst_iterator_filter (children, (GCompareFunc) compare_interface,
(gpointer) iface);
&viface);
g_value_unset (&viface);
return result;
}

View file

@ -1194,27 +1194,15 @@ gst_element_get_pad (GstElement * element, const gchar * name)
}
#endif /* GST_REMOVE_DEPRECATED */
static GstIteratorItem
iterate_pad (GstIterator * it, GstPad * pad)
{
gst_object_ref (pad);
return GST_ITERATOR_ITEM_PASS;
}
static GstIterator *
gst_element_iterate_pad_list (GstElement * element, GList ** padlist)
{
GstIterator *result;
GST_OBJECT_LOCK (element);
gst_object_ref (element);
result = gst_iterator_new_list (GST_TYPE_PAD,
GST_OBJECT_GET_LOCK (element),
&element->pads_cookie,
padlist,
element,
(GstIteratorItemFunction) iterate_pad,
(GstIteratorDisposeFunction) gst_object_unref);
&element->pads_cookie, padlist, (GObject *) element, NULL);
GST_OBJECT_UNLOCK (element);
return result;
@ -2718,24 +2706,26 @@ invalid_return:
/* gst_iterator_fold functions for pads_activate
* Stop the iterator if activating one pad failed. */
static gboolean
activate_pads (GstPad * pad, GValue * ret, gboolean * active)
activate_pads (const GValue * vpad, GValue * ret, gboolean * active)
{
GstPad *pad = g_value_get_object (vpad);
gboolean cont = TRUE;
if (!(cont = gst_pad_set_active (pad, *active)))
g_value_set_boolean (ret, FALSE);
/* unref the object that was reffed for us by _fold */
gst_object_unref (pad);
return cont;
}
/* set the caps on the pad to NULL */
static gboolean
clear_caps (GstPad * pad, GValue * ret, gboolean * active)
clear_caps (const GValue * vpad, GValue * ret, gboolean * active)
{
GstPad *pad = g_value_get_object (vpad);
gst_pad_set_caps (pad, NULL);
gst_object_unref (pad);
return TRUE;
}

View file

@ -257,8 +257,7 @@ gst_format_iterate_definitions (void)
g_static_mutex_lock (&mutex);
/* FIXME: register a boxed type for GstFormatDefinition */
result = gst_iterator_new_list (G_TYPE_POINTER,
g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_formats,
NULL, NULL, NULL);
g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_formats, NULL, NULL);
g_static_mutex_unlock (&mutex);
return result;

View file

@ -131,9 +131,12 @@ gst_proxy_pad_do_iterate_internal_links (GstPad * pad)
GstPad *internal = GST_PROXY_PAD_INTERNAL (pad);
if (internal) {
res =
gst_iterator_new_single (GST_TYPE_PAD, internal,
(GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
GValue v = { 0, };
g_value_init (&v, GST_TYPE_PAD);
g_value_set_object (&v, internal);
res = gst_iterator_new_single (GST_TYPE_PAD, &v);
g_value_unset (&v);
}
return res;
@ -720,9 +723,12 @@ gst_ghost_pad_do_iterate_internal_links (GstPad * pad)
GstPad *internal = GST_PROXY_PAD_INTERNAL (GST_GHOST_PAD_CAST (pad));
if (internal) {
res =
gst_iterator_new_single (GST_TYPE_PAD, internal,
(GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
GValue v = { 0, };
g_value_init (&v, GST_TYPE_PAD);
g_value_set_object (&v, internal);
res = gst_iterator_new_single (GST_TYPE_PAD, &v);
g_value_unset (&v);
}
return res;

View file

@ -2862,13 +2862,6 @@ no_peer:
}
}
static GstIteratorItem
iterate_pad (GstIterator * it, GstPad * pad)
{
gst_object_ref (pad);
return GST_ITERATOR_ITEM_PASS;
}
/**
* gst_pad_iterate_internal_links_default:
* @pad: the #GstPad to get the internal links of.
@ -2893,7 +2886,6 @@ gst_pad_iterate_internal_links_default (GstPad * pad)
guint32 *cookie;
GMutex *lock;
gpointer owner;
GstIteratorDisposeFunction dispose;
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
@ -2917,13 +2909,11 @@ gst_pad_iterate_internal_links_default (GstPad * pad)
cookie = &parent->pads_cookie;
owner = parent;
dispose = (GstIteratorDisposeFunction) gst_object_unref;
lock = GST_OBJECT_GET_LOCK (parent);
}
res = gst_iterator_new_list (GST_TYPE_PAD,
lock, cookie, padlist, owner, (GstIteratorItemFunction) iterate_pad,
dispose);
lock, cookie, padlist, (GObject *) owner, NULL);
return res;
@ -2973,7 +2963,7 @@ gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
gboolean result = FALSE;
GstIterator *iter;
gboolean done = FALSE;
gpointer item;
GValue item = { 0, };
GstPad *eventpad;
GList *pushed_pads = NULL;
@ -2988,11 +2978,11 @@ gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
while (!done) {
switch (gst_iterator_next (iter, &item)) {
case GST_ITERATOR_OK:
eventpad = GST_PAD_CAST (item);
eventpad = g_value_get_object (&item);
/* if already pushed, skip */
if (g_list_find (pushed_pads, eventpad)) {
gst_object_unref (item);
g_value_reset (&item);
break;
}
@ -3017,7 +3007,7 @@ gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
pushed_pads = g_list_prepend (pushed_pads, eventpad);
gst_object_unref (item);
g_value_reset (&item);
break;
case GST_ITERATOR_RESYNC:
/* We don't reset the result here because we don't push the event
@ -3034,6 +3024,7 @@ gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
break;
}
}
g_value_unset (&item);
gst_iterator_free (iter);
no_iter:
@ -3110,7 +3101,7 @@ gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
gboolean res = FALSE;
GstIterator *iter = NULL;
gboolean done = FALSE;
gpointer item;
GValue item = { 0, };
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
g_return_val_if_fail (dispatch != NULL, FALSE);
@ -3124,7 +3115,7 @@ gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
switch (gst_iterator_next (iter, &item)) {
case GST_ITERATOR_OK:
{
GstPad *int_pad = GST_PAD_CAST (item);
GstPad *int_pad = g_value_get_object (&item);
GstPad *int_peer = gst_pad_get_peer (int_pad);
if (int_peer) {
@ -3135,8 +3126,8 @@ gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
} else {
GST_DEBUG_OBJECT (int_pad, "no peer");
}
g_value_reset (&item);
}
gst_object_unref (item);
break;
case GST_ITERATOR_RESYNC:
gst_iterator_resync (iter);
@ -3150,6 +3141,7 @@ gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
break;
}
}
g_value_unset (&item);
gst_iterator_free (iter);
GST_DEBUG_OBJECT (pad, "done, result %d", res);

View file

@ -303,8 +303,7 @@ gst_query_type_iterate_definitions (void)
g_static_mutex_lock (&mutex);
/* FIXME: register a boxed type for GstQueryTypeDefinition */
result = gst_iterator_new_list (G_TYPE_POINTER,
g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries,
NULL, NULL, NULL);
g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL);
g_static_mutex_unlock (&mutex);
return result;

View file

@ -1088,6 +1088,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
GstCaps *templcaps;
GstPad *foundpad = NULL;
gboolean done;
GValue padptr = { 0, };
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
@ -1110,8 +1111,6 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
}
while (!done) {
gpointer padptr;
switch (gst_iterator_next (pads, &padptr)) {
case GST_ITERATOR_OK:
{
@ -1120,7 +1119,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
GstPad *srcpad;
GstPad *sinkpad;
current = GST_PAD (padptr);
current = g_value_get_object (&padptr);
GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
GST_DEBUG_PAD_NAME (current));
@ -1158,6 +1157,9 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
GST_DEBUG_PAD_NAME (current));
gst_iterator_free (pads);
current = gst_object_ref (current);
g_value_unset (&padptr);
return current;
} else {
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "incompatible pads");
@ -1168,7 +1170,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
}
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
gst_object_unref (current);
g_value_reset (&padptr);
if (peer)
gst_object_unref (peer);
break;
@ -1184,6 +1186,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
break;
}
}
g_value_unset (&padptr);
gst_iterator_free (pads);
GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element,
@ -2172,6 +2175,7 @@ gst_element_unlink (GstElement * src, GstElement * dest)
{
GstIterator *pads;
gboolean done = FALSE;
GValue data = { 0, };
g_return_if_fail (GST_IS_ELEMENT (src));
g_return_if_fail (GST_IS_ELEMENT (dest));
@ -2181,12 +2185,10 @@ gst_element_unlink (GstElement * src, GstElement * dest)
pads = gst_element_iterate_pads (src);
while (!done) {
gpointer data;
switch (gst_iterator_next (pads, &data)) {
case GST_ITERATOR_OK:
{
GstPad *pad = GST_PAD_CAST (data);
GstPad *pad = g_value_get_object (&data);
if (GST_PAD_IS_SRC (pad)) {
GstPad *peerpad = gst_pad_get_peer (pad);
@ -2206,7 +2208,7 @@ gst_element_unlink (GstElement * src, GstElement * dest)
gst_object_unref (peerpad);
}
}
gst_object_unref (pad);
g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
@ -2220,6 +2222,7 @@ gst_element_unlink (GstElement * src, GstElement * dest)
break;
}
}
g_value_unset (&data);
gst_iterator_free (pads);
}
@ -2734,8 +2737,9 @@ gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
static gboolean
getcaps_fold_func (GstPad * pad, GValue * ret, GstPad * orig)
getcaps_fold_func (const GValue * vpad, GValue * ret, GstPad * orig)
{
GstPad *pad = g_value_get_object (vpad);
gboolean empty = FALSE;
GstCaps *peercaps, *existing;
@ -2750,7 +2754,6 @@ getcaps_fold_func (GstPad * pad, GValue * ret, GstPad * orig)
gst_caps_unref (existing);
gst_caps_unref (peercaps);
}
gst_object_unref (pad);
return !empty;
}
@ -2866,15 +2869,15 @@ typedef struct
} SetCapsFoldData;
static gboolean
setcaps_fold_func (GstPad * pad, GValue * ret, SetCapsFoldData * data)
setcaps_fold_func (const GValue * vpad, GValue * ret, SetCapsFoldData * data)
{
gboolean success = TRUE;
GstPad *pad = g_value_get_object (vpad);
if (pad != data->orig) {
success = gst_pad_set_caps (pad, data->caps);
g_value_set_boolean (ret, success);
}
gst_object_unref (pad);
return success;
}
@ -3473,11 +3476,11 @@ gst_element_found_tags_for_pad (GstElement * element,
}
static void
push_and_ref (GstPad * pad, GstEvent * event)
push_and_ref (const GValue * vpad, GstEvent * event)
{
GstPad *pad = g_value_get_object (vpad);
gst_pad_push_event (pad, gst_event_ref (event));
/* iterator refs pad, we unref when we are done with it */
gst_object_unref (pad);
}
/**
@ -3502,7 +3505,7 @@ gst_element_found_tags (GstElement * element, GstTagList * list)
iter = gst_element_iterate_src_pads (element);
event = gst_event_new_tag (gst_tag_list_copy (list));
gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
gst_iterator_foreach (iter, (GstIteratorForeachFunction) push_and_ref, event);
gst_iterator_free (iter);
gst_event_unref (event);
@ -3516,6 +3519,7 @@ element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
GstIterator *iter;
GstPad *unlinked_pad = NULL;
gboolean done;
GValue data = { 0, };
switch (direction) {
case GST_PAD_SRC:
@ -3530,26 +3534,25 @@ element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
done = FALSE;
while (!done) {
gpointer pad;
switch (gst_iterator_next (iter, &pad)) {
switch (gst_iterator_next (iter, &data)) {
case GST_ITERATOR_OK:{
GstPad *peer;
GstPad *pad = g_value_get_object (&data);
GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
GST_DEBUG_PAD_NAME (pad));
peer = gst_pad_get_peer (GST_PAD (pad));
peer = gst_pad_get_peer (pad);
if (peer == NULL) {
unlinked_pad = pad;
unlinked_pad = gst_object_ref (pad);
done = TRUE;
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
"found existing unlinked pad %s:%s",
GST_DEBUG_PAD_NAME (unlinked_pad));
} else {
gst_object_unref (pad);
gst_object_unref (peer);
}
g_value_reset (&data);
break;
}
case GST_ITERATOR_DONE:
@ -3563,7 +3566,7 @@ element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
break;
}
}
g_value_unset (&data);
gst_iterator_free (iter);
return unlinked_pad;
@ -3590,6 +3593,7 @@ gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
GstIterator *iter;
gboolean done;
GstPad *pad = NULL;
GValue data = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
@ -3597,15 +3601,16 @@ gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
done = FALSE;
iter = gst_bin_iterate_recurse (bin);
while (!done) {
gpointer element;
switch (gst_iterator_next (iter, &data)) {
case GST_ITERATOR_OK:{
GstElement *element = g_value_get_object (&data);
switch (gst_iterator_next (iter, &element)) {
case GST_ITERATOR_OK:
pad = element_find_unlinked_pad (GST_ELEMENT (element), direction);
gst_object_unref (element);
pad = element_find_unlinked_pad (element, direction);
if (pad != NULL)
done = TRUE;
g_value_reset (&data);
break;
}
case GST_ITERATOR_DONE:
done = TRUE;
break;
@ -3617,7 +3622,7 @@ gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
break;
}
}
g_value_unset (&data);
gst_iterator_free (iter);
return pad;

View file

@ -2416,9 +2416,12 @@ gst_value_serialize_enum (const GValue * value)
}
static gint
gst_value_deserialize_enum_iter_cmp (const GstFormatDefinition * format_def,
gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
const gchar * s)
{
const GstFormatDefinition *format_def =
g_value_get_pointer (format_def_value);
if (g_ascii_strcasecmp (s, format_def->nick) == 0)
return 0;
@ -2446,16 +2449,21 @@ gst_value_deserialize_enum (GValue * dest, const gchar * s)
/* might be one of the custom formats registered later */
if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
GValue res = { 0, };
const GstFormatDefinition *format_def;
GstIterator *iter;
gboolean found;
iter = gst_format_iterate_definitions ();
format_def = gst_iterator_find_custom (iter,
(GCompareFunc) gst_value_deserialize_enum_iter_cmp, (gpointer) s);
found = gst_iterator_find_custom (iter,
(GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
g_return_val_if_fail (found, FALSE);
format_def = g_value_get_pointer (&res);
g_return_val_if_fail (format_def != NULL, FALSE);
g_value_set_enum (dest, (gint) format_def->value);
g_value_unset (&res);
gst_iterator_free (iter);
return TRUE;
}