2004-12-08 18:05:14 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
|
|
|
|
*
|
2005-01-06 18:17:12 +00:00
|
|
|
* gstiterator.h: Base class for iterating datastructures.
|
2004-12-08 18:05:14 +00:00
|
|
|
*
|
|
|
|
* 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_private.h"
|
|
|
|
#include <gst/gstiterator.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_iterator_init (GstIterator * it,
|
|
|
|
GMutex * lock,
|
|
|
|
guint32 * master_cookie,
|
|
|
|
GstIteratorNextFunction next,
|
2005-01-26 10:56:09 +00:00
|
|
|
GstIteratorItemFunction item,
|
2004-12-08 18:05:14 +00:00
|
|
|
GstIteratorResyncFunction resync, GstIteratorFreeFunction free)
|
|
|
|
{
|
|
|
|
it->lock = lock;
|
|
|
|
it->master_cookie = master_cookie;
|
|
|
|
it->cookie = *master_cookie;
|
|
|
|
it->next = next;
|
2005-01-26 10:56:09 +00:00
|
|
|
it->item = item;
|
2004-12-08 18:05:14 +00:00
|
|
|
it->resync = resync;
|
|
|
|
it->free = free;
|
2005-01-26 10:56:09 +00:00
|
|
|
it->pushed = NULL;
|
2004-12-08 18:05:14 +00:00
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_new:
|
|
|
|
* @size: the size of the iterator structure
|
|
|
|
* @lock: pointer to a #GMutex.
|
|
|
|
* @master_cookie: pointer to a guint32 to protect the iterated object.
|
|
|
|
* @next: function to get next item
|
2005-01-26 10:56:09 +00:00
|
|
|
* @item: function to call on each item retrieved
|
2005-01-06 18:17:12 +00:00
|
|
|
* @resync: function to resync the iterator
|
|
|
|
* @free: function to free the iterator
|
|
|
|
*
|
|
|
|
* Create a new iterator. This function is mainly used for objects
|
|
|
|
* implementing the next/resync/free function to iterate a data structure.
|
|
|
|
*
|
|
|
|
* Returns: the new #GstIterator.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
GstIterator *
|
|
|
|
gst_iterator_new (guint size,
|
|
|
|
GMutex * lock,
|
|
|
|
guint32 * master_cookie,
|
|
|
|
GstIteratorNextFunction next,
|
2005-01-26 10:56:09 +00:00
|
|
|
GstIteratorItemFunction item,
|
2004-12-08 18:05:14 +00:00
|
|
|
GstIteratorResyncFunction resync, GstIteratorFreeFunction free)
|
|
|
|
{
|
|
|
|
GstIterator *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (size >= sizeof (GstIterator), NULL);
|
|
|
|
g_return_val_if_fail (master_cookie != NULL, NULL);
|
|
|
|
g_return_val_if_fail (next != NULL, NULL);
|
|
|
|
g_return_val_if_fail (resync != NULL, NULL);
|
|
|
|
g_return_val_if_fail (free != NULL, NULL);
|
|
|
|
|
|
|
|
result = g_malloc (size);
|
2005-01-26 10:56:09 +00:00
|
|
|
gst_iterator_init (result, lock, master_cookie, next, item, resync, free);
|
2004-12-08 18:05:14 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
More MT fixes, added design document describing refcounting policies used in GStreamer and locking involved.
Original commit message from CVS:
* docs/design/part-MT-refcounting.txt:
* docs/design/part-conventions.txt:
* gst/gstbin.c: (gst_bin_set_index), (gst_bin_set_clock),
(gst_bin_add_func), (gst_bin_remove_func),
(gst_bin_iterate_elements), (gst_bin_change_state),
(gst_bin_dispose), (gst_bin_get_by_name_recurse_up):
* gst/gstcaps.c:
* gst/gstelement.c: (gst_element_add_pad),
(gst_element_remove_pad), (pad_compare_name),
(gst_element_get_static_pad), (gst_element_get_request_pad),
(gst_element_get_pad), (gst_element_iterate_pads),
(gst_element_class_get_pad_template_list),
(gst_element_class_get_pad_template), (gst_element_get_random_pad),
(gst_element_get_event_masks), (gst_element_send_event),
(gst_element_seek), (gst_element_get_query_types),
(gst_element_query), (gst_element_get_formats),
(gst_element_convert), (gst_element_post_message),
(gst_element_set_locked_state), (gst_element_get_state),
(gst_element_set_state), (gst_element_pads_activate),
(gst_element_dispose), (gst_element_set_manager_func),
(gst_element_get_manager):
* gst/gstelement.h:
* gst/gstiterator.c: (gst_iterator_new), (gst_list_iterator_next),
(gst_list_iterator_resync), (gst_list_iterator_free),
(gst_iterator_new_list):
* gst/gstiterator.h:
* gst/gstmessage.c: (_gst_message_copy):
* gst/gstobject.c: (gst_object_class_init), (gst_object_init),
(gst_object_ref), (gst_object_unref), (gst_object_sink),
(gst_object_replace), (gst_object_dispose),
(gst_object_dispatch_properties_changed), (gst_object_set_name),
(gst_object_set_parent), (gst_object_get_parent),
(gst_object_unparent), (gst_object_check_uniqueness),
(gst_object_get_path_string):
* gst/gstobject.h:
* gst/gstpad.c: (gst_pad_dispose), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_set_blocked_async),
(gst_pad_is_blocked), (gst_pad_unlink), (gst_pad_is_linked),
(gst_pad_link_prepare_filtered), (gst_pad_link_filtered),
(gst_pad_get_real_parent), (gst_pad_relink_filtered),
(gst_pad_get_peer), (gst_pad_realize), (gst_pad_get_allowed_caps),
(gst_pad_alloc_buffer), (gst_pad_push), (gst_pad_pull),
(gst_pad_pull_range), (gst_pad_push_event):
* gst/gstpad.h:
* gst/gstpipeline.c: (gst_pipeline_init), (gst_pipeline_dispose),
(is_eos), (pipeline_bus_handler):
* gst/gstutils.c: (gst_element_get_compatible_pad_filtered),
(gst_element_link_pads_filtered), (gst_element_unlink):
* gst/parse/grammar.y:
* tools/gst-compprep.c: (main):
* tools/gst-inspect.c: (print_pad_info):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (print_element_info):
More MT fixes, added design document describing refcounting
policies used in GStreamer and locking involved.
Fixed unsafe ghostpad dereffing.
Removed old unsafe methods.
2004-12-13 11:33:55 +00:00
|
|
|
/*
|
|
|
|
* list iterator
|
|
|
|
*/
|
|
|
|
typedef struct _GstListIterator
|
|
|
|
{
|
|
|
|
GstIterator iterator;
|
|
|
|
gpointer owner;
|
|
|
|
GList **orig;
|
|
|
|
GList *list; /* pointer in list */
|
|
|
|
GstIteratorDisposeFunction freefunc;
|
|
|
|
} GstListIterator;
|
|
|
|
|
|
|
|
static GstIteratorResult
|
|
|
|
gst_list_iterator_next (GstListIterator * it, gpointer * elem)
|
|
|
|
{
|
|
|
|
if (it->list == NULL)
|
|
|
|
return GST_ITERATOR_DONE;
|
|
|
|
|
|
|
|
*elem = it->list->data;
|
|
|
|
it->list = g_list_next (it->list);
|
|
|
|
|
|
|
|
return GST_ITERATOR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_list_iterator_resync (GstListIterator * it)
|
|
|
|
{
|
|
|
|
it->list = *it->orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_list_iterator_free (GstListIterator * it)
|
|
|
|
{
|
|
|
|
if (it->freefunc) {
|
|
|
|
it->freefunc (it->owner);
|
|
|
|
}
|
|
|
|
g_free (it);
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_new_list:
|
|
|
|
* @lock: pointer to a #GMutex protecting the list.
|
|
|
|
* @master_cookie: pointer to a guint32 to protect the list.
|
|
|
|
* @list: pointer to the list
|
|
|
|
* @owner: object owning the list
|
|
|
|
* @ref: function to ref each item
|
|
|
|
* @unref: function to unref each item
|
|
|
|
* @free: function to free the owner of the list
|
|
|
|
*
|
|
|
|
* Create a new iterator designed for iterating @list.
|
|
|
|
*
|
|
|
|
* Returns: the new #GstIterator for @list.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
More MT fixes, added design document describing refcounting policies used in GStreamer and locking involved.
Original commit message from CVS:
* docs/design/part-MT-refcounting.txt:
* docs/design/part-conventions.txt:
* gst/gstbin.c: (gst_bin_set_index), (gst_bin_set_clock),
(gst_bin_add_func), (gst_bin_remove_func),
(gst_bin_iterate_elements), (gst_bin_change_state),
(gst_bin_dispose), (gst_bin_get_by_name_recurse_up):
* gst/gstcaps.c:
* gst/gstelement.c: (gst_element_add_pad),
(gst_element_remove_pad), (pad_compare_name),
(gst_element_get_static_pad), (gst_element_get_request_pad),
(gst_element_get_pad), (gst_element_iterate_pads),
(gst_element_class_get_pad_template_list),
(gst_element_class_get_pad_template), (gst_element_get_random_pad),
(gst_element_get_event_masks), (gst_element_send_event),
(gst_element_seek), (gst_element_get_query_types),
(gst_element_query), (gst_element_get_formats),
(gst_element_convert), (gst_element_post_message),
(gst_element_set_locked_state), (gst_element_get_state),
(gst_element_set_state), (gst_element_pads_activate),
(gst_element_dispose), (gst_element_set_manager_func),
(gst_element_get_manager):
* gst/gstelement.h:
* gst/gstiterator.c: (gst_iterator_new), (gst_list_iterator_next),
(gst_list_iterator_resync), (gst_list_iterator_free),
(gst_iterator_new_list):
* gst/gstiterator.h:
* gst/gstmessage.c: (_gst_message_copy):
* gst/gstobject.c: (gst_object_class_init), (gst_object_init),
(gst_object_ref), (gst_object_unref), (gst_object_sink),
(gst_object_replace), (gst_object_dispose),
(gst_object_dispatch_properties_changed), (gst_object_set_name),
(gst_object_set_parent), (gst_object_get_parent),
(gst_object_unparent), (gst_object_check_uniqueness),
(gst_object_get_path_string):
* gst/gstobject.h:
* gst/gstpad.c: (gst_pad_dispose), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_set_blocked_async),
(gst_pad_is_blocked), (gst_pad_unlink), (gst_pad_is_linked),
(gst_pad_link_prepare_filtered), (gst_pad_link_filtered),
(gst_pad_get_real_parent), (gst_pad_relink_filtered),
(gst_pad_get_peer), (gst_pad_realize), (gst_pad_get_allowed_caps),
(gst_pad_alloc_buffer), (gst_pad_push), (gst_pad_pull),
(gst_pad_pull_range), (gst_pad_push_event):
* gst/gstpad.h:
* gst/gstpipeline.c: (gst_pipeline_init), (gst_pipeline_dispose),
(is_eos), (pipeline_bus_handler):
* gst/gstutils.c: (gst_element_get_compatible_pad_filtered),
(gst_element_link_pads_filtered), (gst_element_unlink):
* gst/parse/grammar.y:
* tools/gst-compprep.c: (main):
* tools/gst-inspect.c: (print_pad_info):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (print_element_info):
More MT fixes, added design document describing refcounting
policies used in GStreamer and locking involved.
Fixed unsafe ghostpad dereffing.
Removed old unsafe methods.
2004-12-13 11:33:55 +00:00
|
|
|
GstIterator *
|
|
|
|
gst_iterator_new_list (GMutex * lock,
|
|
|
|
guint32 * master_cookie,
|
|
|
|
GList ** list,
|
|
|
|
gpointer owner,
|
2005-01-26 10:56:09 +00:00
|
|
|
GstIteratorItemFunction item, GstIteratorDisposeFunction free)
|
More MT fixes, added design document describing refcounting policies used in GStreamer and locking involved.
Original commit message from CVS:
* docs/design/part-MT-refcounting.txt:
* docs/design/part-conventions.txt:
* gst/gstbin.c: (gst_bin_set_index), (gst_bin_set_clock),
(gst_bin_add_func), (gst_bin_remove_func),
(gst_bin_iterate_elements), (gst_bin_change_state),
(gst_bin_dispose), (gst_bin_get_by_name_recurse_up):
* gst/gstcaps.c:
* gst/gstelement.c: (gst_element_add_pad),
(gst_element_remove_pad), (pad_compare_name),
(gst_element_get_static_pad), (gst_element_get_request_pad),
(gst_element_get_pad), (gst_element_iterate_pads),
(gst_element_class_get_pad_template_list),
(gst_element_class_get_pad_template), (gst_element_get_random_pad),
(gst_element_get_event_masks), (gst_element_send_event),
(gst_element_seek), (gst_element_get_query_types),
(gst_element_query), (gst_element_get_formats),
(gst_element_convert), (gst_element_post_message),
(gst_element_set_locked_state), (gst_element_get_state),
(gst_element_set_state), (gst_element_pads_activate),
(gst_element_dispose), (gst_element_set_manager_func),
(gst_element_get_manager):
* gst/gstelement.h:
* gst/gstiterator.c: (gst_iterator_new), (gst_list_iterator_next),
(gst_list_iterator_resync), (gst_list_iterator_free),
(gst_iterator_new_list):
* gst/gstiterator.h:
* gst/gstmessage.c: (_gst_message_copy):
* gst/gstobject.c: (gst_object_class_init), (gst_object_init),
(gst_object_ref), (gst_object_unref), (gst_object_sink),
(gst_object_replace), (gst_object_dispose),
(gst_object_dispatch_properties_changed), (gst_object_set_name),
(gst_object_set_parent), (gst_object_get_parent),
(gst_object_unparent), (gst_object_check_uniqueness),
(gst_object_get_path_string):
* gst/gstobject.h:
* gst/gstpad.c: (gst_pad_dispose), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_set_blocked_async),
(gst_pad_is_blocked), (gst_pad_unlink), (gst_pad_is_linked),
(gst_pad_link_prepare_filtered), (gst_pad_link_filtered),
(gst_pad_get_real_parent), (gst_pad_relink_filtered),
(gst_pad_get_peer), (gst_pad_realize), (gst_pad_get_allowed_caps),
(gst_pad_alloc_buffer), (gst_pad_push), (gst_pad_pull),
(gst_pad_pull_range), (gst_pad_push_event):
* gst/gstpad.h:
* gst/gstpipeline.c: (gst_pipeline_init), (gst_pipeline_dispose),
(is_eos), (pipeline_bus_handler):
* gst/gstutils.c: (gst_element_get_compatible_pad_filtered),
(gst_element_link_pads_filtered), (gst_element_unlink):
* gst/parse/grammar.y:
* tools/gst-compprep.c: (main):
* tools/gst-inspect.c: (print_pad_info):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (print_element_info):
More MT fixes, added design document describing refcounting
policies used in GStreamer and locking involved.
Fixed unsafe ghostpad dereffing.
Removed old unsafe methods.
2004-12-13 11:33:55 +00:00
|
|
|
{
|
|
|
|
GstListIterator *result;
|
|
|
|
|
|
|
|
/* no need to lock, nothing can change here */
|
|
|
|
result = (GstListIterator *) gst_iterator_new (sizeof (GstListIterator),
|
|
|
|
lock,
|
|
|
|
master_cookie,
|
|
|
|
(GstIteratorNextFunction) gst_list_iterator_next,
|
2005-01-26 10:56:09 +00:00
|
|
|
(GstIteratorItemFunction) item,
|
More MT fixes, added design document describing refcounting policies used in GStreamer and locking involved.
Original commit message from CVS:
* docs/design/part-MT-refcounting.txt:
* docs/design/part-conventions.txt:
* gst/gstbin.c: (gst_bin_set_index), (gst_bin_set_clock),
(gst_bin_add_func), (gst_bin_remove_func),
(gst_bin_iterate_elements), (gst_bin_change_state),
(gst_bin_dispose), (gst_bin_get_by_name_recurse_up):
* gst/gstcaps.c:
* gst/gstelement.c: (gst_element_add_pad),
(gst_element_remove_pad), (pad_compare_name),
(gst_element_get_static_pad), (gst_element_get_request_pad),
(gst_element_get_pad), (gst_element_iterate_pads),
(gst_element_class_get_pad_template_list),
(gst_element_class_get_pad_template), (gst_element_get_random_pad),
(gst_element_get_event_masks), (gst_element_send_event),
(gst_element_seek), (gst_element_get_query_types),
(gst_element_query), (gst_element_get_formats),
(gst_element_convert), (gst_element_post_message),
(gst_element_set_locked_state), (gst_element_get_state),
(gst_element_set_state), (gst_element_pads_activate),
(gst_element_dispose), (gst_element_set_manager_func),
(gst_element_get_manager):
* gst/gstelement.h:
* gst/gstiterator.c: (gst_iterator_new), (gst_list_iterator_next),
(gst_list_iterator_resync), (gst_list_iterator_free),
(gst_iterator_new_list):
* gst/gstiterator.h:
* gst/gstmessage.c: (_gst_message_copy):
* gst/gstobject.c: (gst_object_class_init), (gst_object_init),
(gst_object_ref), (gst_object_unref), (gst_object_sink),
(gst_object_replace), (gst_object_dispose),
(gst_object_dispatch_properties_changed), (gst_object_set_name),
(gst_object_set_parent), (gst_object_get_parent),
(gst_object_unparent), (gst_object_check_uniqueness),
(gst_object_get_path_string):
* gst/gstobject.h:
* gst/gstpad.c: (gst_pad_dispose), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_set_blocked_async),
(gst_pad_is_blocked), (gst_pad_unlink), (gst_pad_is_linked),
(gst_pad_link_prepare_filtered), (gst_pad_link_filtered),
(gst_pad_get_real_parent), (gst_pad_relink_filtered),
(gst_pad_get_peer), (gst_pad_realize), (gst_pad_get_allowed_caps),
(gst_pad_alloc_buffer), (gst_pad_push), (gst_pad_pull),
(gst_pad_pull_range), (gst_pad_push_event):
* gst/gstpad.h:
* gst/gstpipeline.c: (gst_pipeline_init), (gst_pipeline_dispose),
(is_eos), (pipeline_bus_handler):
* gst/gstutils.c: (gst_element_get_compatible_pad_filtered),
(gst_element_link_pads_filtered), (gst_element_unlink):
* gst/parse/grammar.y:
* tools/gst-compprep.c: (main):
* tools/gst-inspect.c: (print_pad_info):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (print_element_info):
More MT fixes, added design document describing refcounting
policies used in GStreamer and locking involved.
Fixed unsafe ghostpad dereffing.
Removed old unsafe methods.
2004-12-13 11:33:55 +00:00
|
|
|
(GstIteratorResyncFunction) gst_list_iterator_resync,
|
|
|
|
(GstIteratorFreeFunction) gst_list_iterator_free);
|
|
|
|
|
|
|
|
result->owner = owner;
|
|
|
|
result->orig = list;
|
|
|
|
result->list = *list;
|
|
|
|
result->freefunc = free;
|
|
|
|
|
|
|
|
return GST_ITERATOR (result);
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:56:09 +00:00
|
|
|
static void
|
|
|
|
gst_iterator_pop (GstIterator * it)
|
|
|
|
{
|
|
|
|
if (it->pushed) {
|
|
|
|
gst_iterator_free (it->pushed);
|
|
|
|
it->pushed = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_next:
|
|
|
|
* @it: The #GstIterator to iterate
|
|
|
|
* @elem: pointer to hold next element
|
|
|
|
*
|
|
|
|
* Get the next item from the iterator.
|
|
|
|
*
|
|
|
|
* Returns: The result of the iteration.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
GstIteratorResult
|
|
|
|
gst_iterator_next (GstIterator * it, gpointer * elem)
|
|
|
|
{
|
|
|
|
GstIteratorResult result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (it != NULL, GST_ITERATOR_ERROR);
|
|
|
|
g_return_val_if_fail (elem != NULL, GST_ITERATOR_ERROR);
|
|
|
|
|
2005-01-26 10:56:09 +00:00
|
|
|
restart:
|
|
|
|
if (it->pushed) {
|
|
|
|
result = gst_iterator_next (it->pushed, elem);
|
|
|
|
if (result == GST_ITERATOR_DONE) {
|
|
|
|
/* we are done with this iterator, pop it and
|
|
|
|
* fallthrough iterating the main iterator again. */
|
|
|
|
gst_iterator_pop (it);
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (it->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_lock (it->lock);
|
2005-01-26 10:56:09 +00:00
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_UNLIKELY (*it->master_cookie != it->cookie)) {
|
2004-12-08 18:05:14 +00:00
|
|
|
result = GST_ITERATOR_RESYNC;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = it->next (it, elem);
|
2005-01-26 10:56:09 +00:00
|
|
|
if (it->item) {
|
|
|
|
GstIteratorItem itemres;
|
|
|
|
|
|
|
|
itemres = it->item (it, *elem);
|
|
|
|
switch (itemres) {
|
|
|
|
case GST_ITERATOR_ITEM_SKIP:
|
|
|
|
if (G_LIKELY (it->lock))
|
|
|
|
g_mutex_unlock (it->lock);
|
|
|
|
goto restart;
|
|
|
|
case GST_ITERATOR_ITEM_END:
|
|
|
|
result = GST_ITERATOR_DONE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_ITEM_PASS:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-08 18:05:14 +00:00
|
|
|
|
|
|
|
done:
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (it->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_unlock (it->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_resync:
|
|
|
|
* @it: The #GstIterator to resync
|
|
|
|
*
|
|
|
|
* Resync the iterator. this function is mostly called
|
|
|
|
* after #gst_iterator_next() returned #GST_ITERATOR_RESYNC.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
void
|
|
|
|
gst_iterator_resync (GstIterator * it)
|
|
|
|
{
|
|
|
|
g_return_if_fail (it != NULL);
|
|
|
|
|
2005-01-26 10:56:09 +00:00
|
|
|
gst_iterator_pop (it);
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (it->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_lock (it->lock);
|
|
|
|
it->resync (it);
|
|
|
|
it->cookie = *it->master_cookie;
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (it->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_unlock (it->lock);
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_free:
|
|
|
|
* @it: The #GstIterator to free
|
|
|
|
*
|
|
|
|
* Free the iterator.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
void
|
|
|
|
gst_iterator_free (GstIterator * it)
|
|
|
|
{
|
|
|
|
g_return_if_fail (it != NULL);
|
|
|
|
|
2005-01-26 10:56:09 +00:00
|
|
|
gst_iterator_pop (it);
|
|
|
|
|
2004-12-08 18:05:14 +00:00
|
|
|
it->free (it);
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:56:09 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_push:
|
|
|
|
* @it: The #GstIterator to use
|
|
|
|
* @other: The #GstIterator to push
|
|
|
|
*
|
|
|
|
* Pushes @other iterator onto @it. All calls performed on @it are
|
|
|
|
* forwarded tot @other. If @other returns #GST_ITERATOR_DONE, it is
|
|
|
|
* popped again and calls are handled by @it again.
|
|
|
|
*
|
|
|
|
* This function is mainly used by objects implementing the iterator
|
|
|
|
* next function to recurse into substructures.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_iterator_push (GstIterator * it, GstIterator * other)
|
|
|
|
{
|
|
|
|
g_return_if_fail (it != NULL);
|
|
|
|
g_return_if_fail (other != NULL);
|
|
|
|
|
|
|
|
it->pushed = other;
|
|
|
|
}
|
|
|
|
|
2004-12-08 18:05:14 +00:00
|
|
|
typedef struct _GstIteratorFilter
|
|
|
|
{
|
|
|
|
GstIterator iterator;
|
|
|
|
GstIterator *slave;
|
|
|
|
|
|
|
|
GCompareFunc func;
|
|
|
|
gpointer user_data;
|
|
|
|
|
|
|
|
gboolean compare;
|
|
|
|
gboolean first;
|
|
|
|
gboolean found;
|
|
|
|
|
|
|
|
} GstIteratorFilter;
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/* this function can iterate in 3 modes:
|
|
|
|
* filter, foreach and find_custom.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
static GstIteratorResult
|
|
|
|
filter_next (GstIteratorFilter * it, gpointer * elem)
|
|
|
|
{
|
|
|
|
GstIteratorResult result;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
|
|
|
|
*elem = NULL;
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_UNLIKELY (it->found))
|
2004-12-08 18:05:14 +00:00
|
|
|
return GST_ITERATOR_DONE;
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
while (G_LIKELY (!done)) {
|
2004-12-08 18:05:14 +00:00
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
result = gst_iterator_next (it->slave, &item);
|
|
|
|
switch (result) {
|
|
|
|
case GST_ITERATOR_OK:
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_unlock (GST_ITERATOR (it)->lock);
|
|
|
|
if (it->compare) {
|
|
|
|
if (it->func (item, it->user_data) == 0) {
|
|
|
|
*elem = item;
|
|
|
|
done = TRUE;
|
|
|
|
if (it->first)
|
|
|
|
it->found = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
it->func (item, it->user_data);
|
|
|
|
}
|
2005-01-06 18:17:12 +00:00
|
|
|
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
2004-12-08 18:05:14 +00:00
|
|
|
g_mutex_lock (GST_ITERATOR (it)->lock);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filter_resync (GstIteratorFilter * it)
|
|
|
|
{
|
|
|
|
gst_iterator_resync (it->slave);
|
|
|
|
it->found = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filter_uninit (GstIteratorFilter * it)
|
|
|
|
{
|
|
|
|
it->slave->lock = GST_ITERATOR (it)->lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filter_free (GstIteratorFilter * it)
|
|
|
|
{
|
|
|
|
filter_uninit (it);
|
|
|
|
gst_iterator_free (it->slave);
|
|
|
|
g_free (it);
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_filter:
|
|
|
|
* @it: The #GstIterator to filter
|
|
|
|
* @user_data: user data passed to the compare function
|
|
|
|
* @func: the compare function to select elements
|
|
|
|
*
|
|
|
|
* Create a new iterator from an existing iterator. The new iterator
|
|
|
|
* will only return those elements that match the given compare function.
|
|
|
|
* The GCompareFunc should return 0 for elements that should be included
|
|
|
|
* in the iterator.
|
|
|
|
*
|
|
|
|
* When this iterator is freed, @it will also be freed.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstIterator.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
GstIterator *
|
|
|
|
gst_iterator_filter (GstIterator * it, gpointer user_data, GCompareFunc func)
|
|
|
|
{
|
|
|
|
GstIteratorFilter *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (it != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
|
|
|
result = (GstIteratorFilter *) gst_iterator_new (sizeof (GstIteratorFilter),
|
|
|
|
it->lock, it->master_cookie,
|
|
|
|
(GstIteratorNextFunction) filter_next,
|
2005-01-26 10:56:09 +00:00
|
|
|
(GstIteratorItemFunction) NULL,
|
2004-12-08 18:05:14 +00:00
|
|
|
(GstIteratorResyncFunction) filter_resync,
|
|
|
|
(GstIteratorFreeFunction) filter_free);
|
|
|
|
it->lock = NULL;
|
|
|
|
result->func = func;
|
|
|
|
result->user_data = user_data;
|
|
|
|
result->slave = it;
|
|
|
|
result->compare = TRUE;
|
|
|
|
result->first = FALSE;
|
|
|
|
result->found = FALSE;
|
|
|
|
|
|
|
|
return GST_ITERATOR (result);
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_foreach:
|
|
|
|
* @it: The #GstIterator to iterate
|
|
|
|
* @function: the function to call for each element.
|
|
|
|
* @user_data: user data passed to the function
|
|
|
|
*
|
|
|
|
* Iterate over all element of @it and call the given function for
|
|
|
|
* each element.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
void
|
|
|
|
gst_iterator_foreach (GstIterator * it, GFunc function, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstIteratorFilter filter;
|
|
|
|
gpointer dummy;
|
|
|
|
|
|
|
|
g_return_if_fail (it != NULL);
|
|
|
|
g_return_if_fail (function != NULL);
|
|
|
|
|
|
|
|
gst_iterator_init (GST_ITERATOR (&filter),
|
|
|
|
it->lock, it->master_cookie,
|
|
|
|
(GstIteratorNextFunction) filter_next,
|
2005-01-26 10:56:09 +00:00
|
|
|
(GstIteratorItemFunction) NULL,
|
2004-12-08 18:05:14 +00:00
|
|
|
(GstIteratorResyncFunction) filter_resync,
|
|
|
|
(GstIteratorFreeFunction) filter_uninit);
|
|
|
|
it->lock = NULL;
|
|
|
|
filter.func = (GCompareFunc) function;
|
|
|
|
filter.user_data = user_data;
|
|
|
|
filter.slave = it;
|
|
|
|
filter.compare = FALSE;
|
|
|
|
filter.first = FALSE;
|
|
|
|
filter.found = FALSE;
|
|
|
|
gst_iterator_next (GST_ITERATOR (&filter), &dummy);
|
|
|
|
gst_iterator_free (GST_ITERATOR (&filter));
|
|
|
|
}
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
/**
|
|
|
|
* gst_iterator_find_custom:
|
|
|
|
* @it: The #GstIterator to iterate
|
|
|
|
* @user_data: user data passed to the compare function
|
|
|
|
* @func: the compare function to use
|
|
|
|
*
|
|
|
|
* Find the first element in @it that matches the compare function.
|
|
|
|
* The compare function should return 0 when the element is found.
|
|
|
|
*
|
|
|
|
* Returns: The element in the iterator that matches the compare
|
|
|
|
* function or NULL when no element matched.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2004-12-08 18:05:14 +00:00
|
|
|
gpointer
|
|
|
|
gst_iterator_find_custom (GstIterator * it, gpointer user_data,
|
|
|
|
GCompareFunc func)
|
|
|
|
{
|
|
|
|
GstIteratorFilter filter;
|
|
|
|
gpointer result = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (it != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
|
|
|
gst_iterator_init (GST_ITERATOR (&filter),
|
|
|
|
it->lock, it->master_cookie,
|
|
|
|
(GstIteratorNextFunction) filter_next,
|
2005-01-26 10:56:09 +00:00
|
|
|
(GstIteratorItemFunction) NULL,
|
2004-12-08 18:05:14 +00:00
|
|
|
(GstIteratorResyncFunction) filter_resync,
|
|
|
|
(GstIteratorFreeFunction) filter_uninit);
|
|
|
|
it->lock = NULL;
|
|
|
|
filter.func = func;
|
|
|
|
filter.user_data = user_data;
|
|
|
|
filter.slave = it;
|
|
|
|
filter.compare = TRUE;
|
|
|
|
filter.first = TRUE;
|
|
|
|
filter.found = FALSE;
|
|
|
|
|
|
|
|
gst_iterator_next (GST_ITERATOR (&filter), &result);
|
|
|
|
gst_iterator_free (GST_ITERATOR (&filter));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|