コード例 #1
0
ファイル: gstiterator.c プロジェクト: WangCrystal/gstreamer
/**
 * gst_iterator_new_list:
 * @type: #GType of elements
 * @lock: pointer to a #GMutex protecting the list.
 * @master_cookie: pointer to a guint32 that is incremented when the list
 *     is changed.
 * @list: pointer to the list
 * @owner: object owning the list
 * @item: function to call for each item
 * @free: function to call when the iterator is freed
 *
 * Create a new iterator designed for iterating @list.
 *
 * The list you iterate is usually part of a data structure @owner and is
 * protected with @lock. 
 *
 * The iterator will use @lock to retrieve the next item of the list and it
 * will then call the @item function before releasing @lock again.
 *
 * The @item function usualy makes sure that the item remains alive while
 * @lock is released and the application is using the item. The application is
 * responsible for freeing/unreffing the item after usage as explained in
 * gst_iterator_next().
 *
 * When a concurrent update to the list is performed, usually by @owner while
 * holding @lock, @master_cookie will be updated. The iterator implementation
 * will notice the update of the cookie and will return #GST_ITERATOR_RESYNC to
 * the user of the iterator in the next call to gst_iterator_next().
 *
 * @owner will be passed to the @free function when the iterator is freed.
 *
 * Returns: the new #GstIterator for @list.
 *
 * MT safe.
 */
GstIterator *
gst_iterator_new_list (GType type,
    GMutex * lock,
    guint32 * master_cookie,
    GList ** list,
    gpointer owner,
    GstIteratorItemFunction item, GstIteratorDisposeFunction free)
{
  GstListIterator *result;

  /* no need to lock, nothing can change here */
  result = (GstListIterator *) gst_iterator_new (sizeof (GstListIterator),
      type,
      lock,
      master_cookie,
      (GstIteratorNextFunction) gst_list_iterator_next,
      (GstIteratorItemFunction) item,
      (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);
}
コード例 #2
0
static GstIterator *
rsn_stream_selector_iterate_linked_pads (GstPad * pad)
{
  RsnStreamSelector *sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
  RsnStreamSelectorIterator *it = (RsnStreamSelectorIterator *)
      gst_iterator_new (sizeof (RsnStreamSelectorIterator),
      GST_TYPE_PAD,
      GST_OBJECT_CAST (sel)->lock,
      &GST_ELEMENT_CAST (sel)->pads_cookie,
      _iterate_next, _iterate_item, _iterate_resync, _iterate_free);

  it->pad = gst_object_ref (pad);
  it->start = TRUE;

  gst_object_unref (sel);

  return (GstIterator *) it;
}
コード例 #3
0
ファイル: gstiterator.c プロジェクト: WangCrystal/gstreamer
/**
 * gst_iterator_filter:
 * @it: The #GstIterator to filter
 * @func: the compare function to select elements
 * @user_data: user data passed to the compare function
 *
 * Create a new iterator from an existing iterator. The new iterator
 * will only return those elements that match the given compare function @func.
 * @func 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.
 */
GstIterator *
gst_iterator_filter (GstIterator * it, GCompareFunc func, gpointer user_data)
{
  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->type, it->lock, it->master_cookie,
      (GstIteratorNextFunction) filter_next,
      (GstIteratorItemFunction) NULL,
      (GstIteratorResyncFunction) filter_resync,
      (GstIteratorFreeFunction) filter_free);
  it->lock = NULL;
  result->func = func;
  result->user_data = user_data;
  result->slave = it;

  return GST_ITERATOR (result);
}