mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 03:31:05 +00:00
gst/gstpipeline.c: Fix element details.
Original commit message from CVS: 2005-03-01 Andy Wingo <wingo@pobox.com> * gst/gstpipeline.c: Fix element details. (gst_pipeline_set_property, gst_pipeline_get_property): Lock around the whole get/set properties. * gst/gstpad.c (gst_real_pad_set_property): Add a FIXME, the ::active property doesn't make sense any more. (gst_pad_set_active): Check to see if the pad has the right functions to be activated in this mode. (gst_pad_event_default): Handle EOS specially, pausing the task on the pad if necessary. * gst/gstbin.c: Adapt callers of gst_iterator_foreach and gst_iterator_filter to new argument order. * gst/gstiterator.c (gst_iterator_find_custom) (gst_iterator_foreach): Implement on top of gst_iterator_fold instead of using the filter_next internals. A bit cleaner this way. * gst/gstiterator.h: (gst_iterator_filter, gst_iterator_find_custom): Switch the argument order so user_data is last. (gst_iterator_foreach): Return the GstIteratorResult so the caller knows if all elements were called, or if an error or resync happened. (gst_iterator_fold): New procedure. * check/Makefile.am (TESTS): * check/gst/gstiterator.c: New test suite for GstIterator. Checks that iterating through a list hits all members in order, that resync works correctly, and that fold works. * gst/base/gstbasesink.c (gst_basesink_event): Fix Waymans bug.
This commit is contained in:
parent
82a12763e8
commit
b56662cf97
11 changed files with 532 additions and 95 deletions
|
@ -22,6 +22,7 @@ TESTS = $(top_builddir)/tools/gst-register-@GST_MAJORMINOR@ \
|
||||||
gst/gstbus \
|
gst/gstbus \
|
||||||
gst/gstcaps \
|
gst/gstcaps \
|
||||||
gst/gstdata \
|
gst/gstdata \
|
||||||
|
gst/gstiterator \
|
||||||
gst/gstobject \
|
gst/gstobject \
|
||||||
gst/gstpad \
|
gst/gstpad \
|
||||||
gst-libs/gdp \
|
gst-libs/gdp \
|
||||||
|
|
180
check/gst/gstiterator.c
Normal file
180
check/gst/gstiterator.c
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||||
|
*
|
||||||
|
* gstiterator.c: Unit test for iterators
|
||||||
|
*
|
||||||
|
* 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 "../gstcheck.h"
|
||||||
|
|
||||||
|
|
||||||
|
static GList *
|
||||||
|
make_list_of_ints (gint n)
|
||||||
|
{
|
||||||
|
GList *ret = NULL;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
ret = g_list_prepend (ret, GINT_TO_POINTER (i));
|
||||||
|
|
||||||
|
return g_list_reverse (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NUM_ELEMENTS 10
|
||||||
|
|
||||||
|
START_TEST (test_manual_iteration)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gpointer item;
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
if (i < NUM_ELEMENTS) {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == i);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_DONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
START_TEST (test_resync)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gpointer item;
|
||||||
|
gint i = 0;
|
||||||
|
gboolean hacked_list = FALSE;
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
if (i < NUM_ELEMENTS / 2) {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == i);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
} else if (!hacked_list) {
|
||||||
|
/* here's where we test resync */
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
l = g_list_prepend (l, GINT_TO_POINTER (-1));
|
||||||
|
cookie++;
|
||||||
|
hacked_list = TRUE;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_RESYNC);
|
||||||
|
gst_iterator_resync (iter);
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
}
|
||||||
|
END_TEST static void
|
||||||
|
add_fold_func (gpointer item, GValue * ret, gpointer user_data)
|
||||||
|
{
|
||||||
|
g_value_set_int (ret, g_value_get_int (ret) + GPOINTER_TO_INT (item));
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST (test_fold)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gint i, expected;
|
||||||
|
GValue ret = { 0, };
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
expected = 0;
|
||||||
|
for (i = 0; i < NUM_ELEMENTS; i++)
|
||||||
|
expected += i;
|
||||||
|
|
||||||
|
g_value_init (&ret, G_TYPE_INT);
|
||||||
|
g_value_set_int (&ret, 0);
|
||||||
|
|
||||||
|
res = gst_iterator_fold (iter, add_fold_func, &ret, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_DONE);
|
||||||
|
g_return_if_fail (g_value_get_int (&ret) == expected);
|
||||||
|
}
|
||||||
|
END_TEST Suite * gstiterator_suite (void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create ("GstIterator");
|
||||||
|
TCase *tc_chain = tcase_create ("correctness");
|
||||||
|
|
||||||
|
tcase_set_timeout (tc_chain, 0);
|
||||||
|
|
||||||
|
suite_add_tcase (s, tc_chain);
|
||||||
|
tcase_add_test (tc_chain, test_manual_iteration);
|
||||||
|
tcase_add_test (tc_chain, test_resync);
|
||||||
|
tcase_add_test (tc_chain, test_fold);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nf;
|
||||||
|
|
||||||
|
Suite *s = gstiterator_suite ();
|
||||||
|
SRunner *sr = srunner_create (s);
|
||||||
|
|
||||||
|
gst_check_init (&argc, &argv);
|
||||||
|
|
||||||
|
srunner_run_all (sr, CK_NORMAL);
|
||||||
|
nf = srunner_ntests_failed (sr);
|
||||||
|
srunner_free (sr);
|
||||||
|
|
||||||
|
return nf;
|
||||||
|
}
|
|
@ -447,6 +447,7 @@ gst_basesink_event (GstPad * pad, GstEvent * event)
|
||||||
//gint64 value = GST_EVENT_DISCONT_OFFSET (event, 0).value;
|
//gint64 value = GST_EVENT_DISCONT_OFFSET (event, 0).value;
|
||||||
}
|
}
|
||||||
GST_STREAM_UNLOCK (pad);
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
case GST_EVENT_FLUSH:
|
case GST_EVENT_FLUSH:
|
||||||
/* make sure we are not blocked on the clock also clear any pending
|
/* make sure we are not blocked on the clock also clear any pending
|
||||||
* eos state. */
|
* eos state. */
|
||||||
|
|
16
gst/gstbin.c
16
gst/gstbin.c
|
@ -715,8 +715,8 @@ gst_bin_iterate_sinks (GstBin * bin)
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
||||||
|
|
||||||
children = gst_bin_iterate_elements (bin);
|
children = gst_bin_iterate_elements (bin);
|
||||||
result = gst_iterator_filter (children, bin,
|
result = gst_iterator_filter (children,
|
||||||
(GCompareFunc) bin_element_is_sink);
|
(GCompareFunc) bin_element_is_sink, bin);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1049,8 +1049,8 @@ gst_bin_get_by_name (GstBin * bin, const gchar * name)
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
||||||
|
|
||||||
children = gst_bin_iterate_recurse (bin);
|
children = gst_bin_iterate_recurse (bin);
|
||||||
result = gst_iterator_find_custom (children, (gpointer) name,
|
result = gst_iterator_find_custom (children,
|
||||||
(GCompareFunc) compare_name);
|
(GCompareFunc) compare_name, (gpointer) name);
|
||||||
|
|
||||||
return GST_ELEMENT_CAST (result);
|
return GST_ELEMENT_CAST (result);
|
||||||
}
|
}
|
||||||
|
@ -1134,8 +1134,8 @@ gst_bin_get_by_interface (GstBin * bin, GType interface)
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
||||||
|
|
||||||
children = gst_bin_iterate_recurse (bin);
|
children = gst_bin_iterate_recurse (bin);
|
||||||
result = gst_iterator_find_custom (children, GINT_TO_POINTER (interface),
|
result = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
|
||||||
(GCompareFunc) compare_interface);
|
GINT_TO_POINTER (interface));
|
||||||
|
|
||||||
return GST_ELEMENT_CAST (result);
|
return GST_ELEMENT_CAST (result);
|
||||||
}
|
}
|
||||||
|
@ -1162,8 +1162,8 @@ gst_bin_iterate_all_by_interface (GstBin * bin, GType interface)
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
||||||
|
|
||||||
children = gst_bin_iterate_recurse (bin);
|
children = gst_bin_iterate_recurse (bin);
|
||||||
result = gst_iterator_filter (children, GINT_TO_POINTER (interface),
|
result = gst_iterator_filter (children, (GCompareFunc) compare_interface,
|
||||||
(GCompareFunc) compare_interface);
|
GINT_TO_POINTER (interface));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,16 +305,8 @@ typedef struct _GstIteratorFilter
|
||||||
|
|
||||||
GCompareFunc func;
|
GCompareFunc func;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
|
|
||||||
gboolean compare;
|
|
||||||
gboolean first;
|
|
||||||
gboolean found;
|
|
||||||
|
|
||||||
} GstIteratorFilter;
|
} GstIteratorFilter;
|
||||||
|
|
||||||
/* this function can iterate in 3 modes:
|
|
||||||
* filter, foreach and find_custom.
|
|
||||||
*/
|
|
||||||
static GstIteratorResult
|
static GstIteratorResult
|
||||||
filter_next (GstIteratorFilter * it, gpointer * elem)
|
filter_next (GstIteratorFilter * it, gpointer * elem)
|
||||||
{
|
{
|
||||||
|
@ -323,9 +315,6 @@ filter_next (GstIteratorFilter * it, gpointer * elem)
|
||||||
|
|
||||||
*elem = NULL;
|
*elem = NULL;
|
||||||
|
|
||||||
if (G_UNLIKELY (it->found))
|
|
||||||
return GST_ITERATOR_DONE;
|
|
||||||
|
|
||||||
while (G_LIKELY (!done)) {
|
while (G_LIKELY (!done)) {
|
||||||
gpointer item;
|
gpointer item;
|
||||||
|
|
||||||
|
@ -334,15 +323,9 @@ filter_next (GstIteratorFilter * it, gpointer * elem)
|
||||||
case GST_ITERATOR_OK:
|
case GST_ITERATOR_OK:
|
||||||
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
||||||
g_mutex_unlock (GST_ITERATOR (it)->lock);
|
g_mutex_unlock (GST_ITERATOR (it)->lock);
|
||||||
if (it->compare) {
|
if (it->func (item, it->user_data) == 0) {
|
||||||
if (it->func (item, it->user_data) == 0) {
|
*elem = item;
|
||||||
*elem = item;
|
done = TRUE;
|
||||||
done = TRUE;
|
|
||||||
if (it->first)
|
|
||||||
it->found = TRUE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
it->func (item, it->user_data);
|
|
||||||
}
|
}
|
||||||
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
if (G_LIKELY (GST_ITERATOR (it)->lock))
|
||||||
g_mutex_lock (GST_ITERATOR (it)->lock);
|
g_mutex_lock (GST_ITERATOR (it)->lock);
|
||||||
|
@ -363,7 +346,6 @@ static void
|
||||||
filter_resync (GstIteratorFilter * it)
|
filter_resync (GstIteratorFilter * it)
|
||||||
{
|
{
|
||||||
gst_iterator_resync (it->slave);
|
gst_iterator_resync (it->slave);
|
||||||
it->found = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -398,7 +380,7 @@ filter_free (GstIteratorFilter * it)
|
||||||
* MT safe.
|
* MT safe.
|
||||||
*/
|
*/
|
||||||
GstIterator *
|
GstIterator *
|
||||||
gst_iterator_filter (GstIterator * it, gpointer user_data, GCompareFunc func)
|
gst_iterator_filter (GstIterator * it, GCompareFunc func, gpointer user_data)
|
||||||
{
|
{
|
||||||
GstIteratorFilter *result;
|
GstIteratorFilter *result;
|
||||||
|
|
||||||
|
@ -415,13 +397,72 @@ gst_iterator_filter (GstIterator * it, gpointer user_data, GCompareFunc func)
|
||||||
result->func = func;
|
result->func = func;
|
||||||
result->user_data = user_data;
|
result->user_data = user_data;
|
||||||
result->slave = it;
|
result->slave = it;
|
||||||
result->compare = TRUE;
|
|
||||||
result->first = FALSE;
|
|
||||||
result->found = FALSE;
|
|
||||||
|
|
||||||
return GST_ITERATOR (result);
|
return GST_ITERATOR (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_iterator_fold:
|
||||||
|
* @iter: The #GstIterator to fold over
|
||||||
|
* @func: the fold function
|
||||||
|
* @ret: the seed value passed to the fold function
|
||||||
|
* @user_data: user data passed to the fold function
|
||||||
|
*
|
||||||
|
* Folds @func over the elements of @iter. That is to say, @proc will be called
|
||||||
|
* as @proc (object, @ret, @user_data) for each object in @iter. The normal use
|
||||||
|
* of this procedure is to accumulate the results of operating on the objects in
|
||||||
|
* @ret.
|
||||||
|
*
|
||||||
|
* This procedure can be used (and is used internally) to implement the foreach
|
||||||
|
* and find_custom operations.
|
||||||
|
*
|
||||||
|
* Returns: the result of the last call to gst_iterator_next(). This function
|
||||||
|
* stops on a resync.
|
||||||
|
*
|
||||||
|
* MT safe.
|
||||||
|
*/
|
||||||
|
GstIteratorResult
|
||||||
|
gst_iterator_fold (GstIterator * iter, GstIteratorFoldFunction func,
|
||||||
|
GValue * ret, gpointer user_data)
|
||||||
|
{
|
||||||
|
gpointer item;
|
||||||
|
GstIteratorResult result;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
result = gst_iterator_next (iter, &item);
|
||||||
|
switch (result) {
|
||||||
|
case GST_ITERATOR_OK:
|
||||||
|
func (item, ret, user_data);
|
||||||
|
/* fixme: is there a way to ref/unref items? */
|
||||||
|
break;
|
||||||
|
case GST_ITERATOR_RESYNC:
|
||||||
|
case GST_ITERATOR_ERROR:
|
||||||
|
goto fold_interrupted;
|
||||||
|
case GST_ITERATOR_DONE:
|
||||||
|
goto fold_done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fold_interrupted:
|
||||||
|
return result;
|
||||||
|
|
||||||
|
fold_done:
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GFunc func;
|
||||||
|
gpointer user_data;
|
||||||
|
} ForeachFoldData;
|
||||||
|
|
||||||
|
static void
|
||||||
|
foreach_fold_func (gpointer item, GValue * unused, ForeachFoldData * data)
|
||||||
|
{
|
||||||
|
data->func (item, data->user_data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_iterator_foreach:
|
* gst_iterator_foreach:
|
||||||
* @it: The #GstIterator to iterate
|
* @it: The #GstIterator to iterate
|
||||||
|
@ -431,32 +472,35 @@ gst_iterator_filter (GstIterator * it, gpointer user_data, GCompareFunc func)
|
||||||
* Iterate over all element of @it and call the given function for
|
* Iterate over all element of @it and call the given function for
|
||||||
* each element.
|
* each element.
|
||||||
*
|
*
|
||||||
|
* Returns: the result of the last call to gst_iterator_next(). This function
|
||||||
|
* stops on a resync.
|
||||||
|
*
|
||||||
* MT safe.
|
* MT safe.
|
||||||
*/
|
*/
|
||||||
void
|
GstIteratorResult
|
||||||
gst_iterator_foreach (GstIterator * it, GFunc function, gpointer user_data)
|
gst_iterator_foreach (GstIterator * iter, GFunc func, gpointer user_data)
|
||||||
{
|
{
|
||||||
GstIteratorFilter filter;
|
ForeachFoldData data;
|
||||||
gpointer dummy;
|
|
||||||
|
|
||||||
g_return_if_fail (it != NULL);
|
data.func = func;
|
||||||
g_return_if_fail (function != NULL);
|
data.user_data = user_data;
|
||||||
|
|
||||||
gst_iterator_init (GST_ITERATOR (&filter),
|
return gst_iterator_fold (iter, (GstIteratorFoldFunction) foreach_fold_func,
|
||||||
it->lock, it->master_cookie,
|
NULL, &data);
|
||||||
(GstIteratorNextFunction) filter_next,
|
}
|
||||||
(GstIteratorItemFunction) NULL,
|
|
||||||
(GstIteratorResyncFunction) filter_resync,
|
typedef struct
|
||||||
(GstIteratorFreeFunction) filter_uninit);
|
{
|
||||||
it->lock = NULL;
|
GCompareFunc func;
|
||||||
filter.func = (GCompareFunc) function;
|
gpointer user_data;
|
||||||
filter.user_data = user_data;
|
} FindCustomFoldData;
|
||||||
filter.slave = it;
|
|
||||||
filter.compare = FALSE;
|
static void
|
||||||
filter.first = FALSE;
|
find_custom_fold_func (gpointer item, GValue * ret, FindCustomFoldData * data)
|
||||||
filter.found = FALSE;
|
{
|
||||||
gst_iterator_next (GST_ITERATOR (&filter), &dummy);
|
if (!g_value_get_pointer (ret))
|
||||||
gst_iterator_free (GST_ITERATOR (&filter));
|
if (data->func (item, data->user_data))
|
||||||
|
g_value_set_pointer (ret, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -474,31 +518,19 @@ gst_iterator_foreach (GstIterator * it, GFunc function, gpointer user_data)
|
||||||
* MT safe.
|
* MT safe.
|
||||||
*/
|
*/
|
||||||
gpointer
|
gpointer
|
||||||
gst_iterator_find_custom (GstIterator * it, gpointer user_data,
|
gst_iterator_find_custom (GstIterator * iter, GCompareFunc func,
|
||||||
GCompareFunc func)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GstIteratorFilter filter;
|
GValue ret = { 0, };
|
||||||
gpointer result = NULL;
|
FindCustomFoldData data;
|
||||||
|
|
||||||
g_return_val_if_fail (it != NULL, NULL);
|
g_value_init (&ret, G_TYPE_POINTER);
|
||||||
g_return_val_if_fail (func != NULL, NULL);
|
data.func = func;
|
||||||
|
data.user_data = user_data;
|
||||||
|
|
||||||
gst_iterator_init (GST_ITERATOR (&filter),
|
gst_iterator_fold (iter, (GstIteratorFoldFunction) find_custom_fold_func,
|
||||||
it->lock, it->master_cookie,
|
&ret, &data);
|
||||||
(GstIteratorNextFunction) filter_next,
|
|
||||||
(GstIteratorItemFunction) NULL,
|
|
||||||
(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);
|
/* no need to unset, it's just a pointer */
|
||||||
gst_iterator_free (GST_ITERATOR (&filter));
|
return g_value_get_pointer (&ret);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ typedef GstIteratorItem (*GstIteratorItemFunction) (GstIterator *it, gpointer
|
||||||
typedef void (*GstIteratorResyncFunction) (GstIterator *it);
|
typedef void (*GstIteratorResyncFunction) (GstIterator *it);
|
||||||
typedef void (*GstIteratorFreeFunction) (GstIterator *it);
|
typedef void (*GstIteratorFreeFunction) (GstIterator *it);
|
||||||
|
|
||||||
|
typedef void (*GstIteratorFoldFunction) (gpointer item, GValue *ret, gpointer user_data);
|
||||||
|
|
||||||
#define GST_ITERATOR(it) ((GstIterator*)(it))
|
#define GST_ITERATOR(it) ((GstIterator*)(it))
|
||||||
#define GST_ITERATOR_LOCK(it) (GST_ITERATOR(it)->lock)
|
#define GST_ITERATOR_LOCK(it) (GST_ITERATOR(it)->lock)
|
||||||
#define GST_ITERATOR_COOKIE(it) (GST_ITERATOR(it)->cookie)
|
#define GST_ITERATOR_COOKIE(it) (GST_ITERATOR(it)->cookie)
|
||||||
|
@ -90,13 +92,16 @@ void gst_iterator_free (GstIterator *it);
|
||||||
|
|
||||||
void gst_iterator_push (GstIterator *it, GstIterator *other);
|
void gst_iterator_push (GstIterator *it, GstIterator *other);
|
||||||
|
|
||||||
/* special functions that operate on iterators */
|
/* higher-order functions that operate on iterators */
|
||||||
void gst_iterator_foreach (GstIterator *it, GFunc function,
|
GstIterator* gst_iterator_filter (GstIterator *it, GCompareFunc func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gpointer gst_iterator_find_custom (GstIterator *it, gpointer user_data,
|
GstIteratorResult gst_iterator_fold (GstIterator *iter,
|
||||||
GCompareFunc func);
|
GstIteratorFoldFunction func,
|
||||||
GstIterator* gst_iterator_filter (GstIterator *it, gpointer user_data,
|
GValue *ret, gpointer user_data);
|
||||||
GCompareFunc func);
|
GstIteratorResult gst_iterator_foreach (GstIterator *iter,
|
||||||
|
GFunc func, gpointer user_data);
|
||||||
|
gpointer gst_iterator_find_custom (GstIterator *it, GCompareFunc func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
42
gst/gstpad.c
42
gst/gstpad.c
|
@ -275,6 +275,7 @@ gst_real_pad_set_property (GObject * object, guint prop_id,
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case REAL_ARG_ACTIVE:
|
case REAL_ARG_ACTIVE:
|
||||||
|
g_warning ("FIXME: not useful any more!!!");
|
||||||
gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
|
gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -465,6 +466,24 @@ gst_pad_set_active (GstPad * pad, GstActivateMode mode)
|
||||||
GST_PAD_BLOCK_SIGNAL (realpad);
|
GST_PAD_BLOCK_SIGNAL (realpad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (active) {
|
||||||
|
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
|
||||||
|
if (mode == GST_ACTIVATE_PULL) {
|
||||||
|
if (!realpad->getrangefunc)
|
||||||
|
goto wrong_mode;
|
||||||
|
} else {
|
||||||
|
/* we can push if driven by a chain or loop on the sink pad */
|
||||||
|
}
|
||||||
|
} else { /* sink pads */
|
||||||
|
if (mode == GST_ACTIVATE_PULL) {
|
||||||
|
/* the src can drive us with getrange */
|
||||||
|
} else {
|
||||||
|
if (!realpad->chainfunc)
|
||||||
|
goto wrong_mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activatefunc = realpad->activatefunc;
|
activatefunc = realpad->activatefunc;
|
||||||
if (activatefunc) {
|
if (activatefunc) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
@ -499,6 +518,14 @@ lost_ghostpad:
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
wrong_mode:
|
||||||
|
{
|
||||||
|
GST_CAT_DEBUG (GST_CAT_PADS,
|
||||||
|
"pad %s:%s lacks functions to be active in mode %d",
|
||||||
|
GST_DEBUG_PAD_NAME (realpad), mode);
|
||||||
|
GST_UNLOCK (realpad);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
activate_error:
|
activate_error:
|
||||||
{
|
{
|
||||||
GST_CAT_DEBUG (GST_CAT_PADS,
|
GST_CAT_DEBUG (GST_CAT_PADS,
|
||||||
|
@ -3438,7 +3465,20 @@ gst_pad_event_default (GstPad * pad, GstEvent * event)
|
||||||
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
||||||
g_return_val_if_fail (event != NULL, FALSE);
|
g_return_val_if_fail (event != NULL, FALSE);
|
||||||
|
|
||||||
return gst_pad_event_default_dispatch (pad, event);
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_EOS:
|
||||||
|
{
|
||||||
|
GstRealPad *rpad = GST_PAD_REALIZE (pad);
|
||||||
|
|
||||||
|
if (GST_RPAD_TASK (rpad)) {
|
||||||
|
GST_DEBUG_OBJECT (rpad, "pausing task because of eos");
|
||||||
|
gst_task_pause (GST_RPAD_TASK (rpad));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gst_pad_event_default_dispatch (pad, event);
|
||||||
|
default:
|
||||||
|
return gst_pad_event_default_dispatch (pad, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* GStreamer
|
/* GStreamer
|
||||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||||
* 2004 Wim Taymans <wim@fluendo.com>
|
* 2004,2005 Wim Taymans <wim@fluendo.com>
|
||||||
*
|
*
|
||||||
* gstpipeline.c: Overall pipeline management element
|
* gstpipeline.c: Overall pipeline management element
|
||||||
*
|
*
|
||||||
|
@ -31,7 +31,7 @@ static GstElementDetails gst_pipeline_details =
|
||||||
GST_ELEMENT_DETAILS ("Pipeline object",
|
GST_ELEMENT_DETAILS ("Pipeline object",
|
||||||
"Generic/Bin",
|
"Generic/Bin",
|
||||||
"Complete pipeline object",
|
"Complete pipeline object",
|
||||||
"Erik Walthinsen <omega@cse.ogi.edu>" "Wim Taymans <wim@fluendo.com>");
|
"Erik Walthinsen <omega@cse.ogi.edu>, Wim Taymans <wim@fluendo.com>");
|
||||||
|
|
||||||
/* Pipeline signals and args */
|
/* Pipeline signals and args */
|
||||||
enum
|
enum
|
||||||
|
@ -180,21 +180,19 @@ gst_pipeline_set_property (GObject * object, guint prop_id,
|
||||||
{
|
{
|
||||||
GstPipeline *pipeline = GST_PIPELINE (object);
|
GstPipeline *pipeline = GST_PIPELINE (object);
|
||||||
|
|
||||||
|
GST_LOCK (pipeline);
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_DELAY:
|
case ARG_DELAY:
|
||||||
GST_LOCK (pipeline);
|
|
||||||
pipeline->delay = g_value_get_uint64 (value);
|
pipeline->delay = g_value_get_uint64 (value);
|
||||||
GST_UNLOCK (pipeline);
|
|
||||||
break;
|
break;
|
||||||
case ARG_PLAY_TIMEOUT:
|
case ARG_PLAY_TIMEOUT:
|
||||||
GST_LOCK (pipeline);
|
|
||||||
pipeline->play_timeout = g_value_get_uint64 (value);
|
pipeline->play_timeout = g_value_get_uint64 (value);
|
||||||
GST_UNLOCK (pipeline);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
GST_UNLOCK (pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -203,21 +201,19 @@ gst_pipeline_get_property (GObject * object, guint prop_id,
|
||||||
{
|
{
|
||||||
GstPipeline *pipeline = GST_PIPELINE (object);
|
GstPipeline *pipeline = GST_PIPELINE (object);
|
||||||
|
|
||||||
|
GST_LOCK (pipeline);
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_DELAY:
|
case ARG_DELAY:
|
||||||
GST_LOCK (pipeline);
|
|
||||||
g_value_set_uint64 (value, pipeline->delay);
|
g_value_set_uint64 (value, pipeline->delay);
|
||||||
GST_UNLOCK (pipeline);
|
|
||||||
break;
|
break;
|
||||||
case ARG_PLAY_TIMEOUT:
|
case ARG_PLAY_TIMEOUT:
|
||||||
GST_LOCK (pipeline);
|
|
||||||
g_value_set_uint64 (value, pipeline->play_timeout);
|
g_value_set_uint64 (value, pipeline->play_timeout);
|
||||||
GST_UNLOCK (pipeline);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
GST_UNLOCK (pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
@ -447,6 +447,7 @@ gst_basesink_event (GstPad * pad, GstEvent * event)
|
||||||
//gint64 value = GST_EVENT_DISCONT_OFFSET (event, 0).value;
|
//gint64 value = GST_EVENT_DISCONT_OFFSET (event, 0).value;
|
||||||
}
|
}
|
||||||
GST_STREAM_UNLOCK (pad);
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
case GST_EVENT_FLUSH:
|
case GST_EVENT_FLUSH:
|
||||||
/* make sure we are not blocked on the clock also clear any pending
|
/* make sure we are not blocked on the clock also clear any pending
|
||||||
* eos state. */
|
* eos state. */
|
||||||
|
|
|
@ -22,6 +22,7 @@ TESTS = $(top_builddir)/tools/gst-register-@GST_MAJORMINOR@ \
|
||||||
gst/gstbus \
|
gst/gstbus \
|
||||||
gst/gstcaps \
|
gst/gstcaps \
|
||||||
gst/gstdata \
|
gst/gstdata \
|
||||||
|
gst/gstiterator \
|
||||||
gst/gstobject \
|
gst/gstobject \
|
||||||
gst/gstpad \
|
gst/gstpad \
|
||||||
gst-libs/gdp \
|
gst-libs/gdp \
|
||||||
|
|
180
tests/check/gst/gstiterator.c
Normal file
180
tests/check/gst/gstiterator.c
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||||
|
*
|
||||||
|
* gstiterator.c: Unit test for iterators
|
||||||
|
*
|
||||||
|
* 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 "../gstcheck.h"
|
||||||
|
|
||||||
|
|
||||||
|
static GList *
|
||||||
|
make_list_of_ints (gint n)
|
||||||
|
{
|
||||||
|
GList *ret = NULL;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
ret = g_list_prepend (ret, GINT_TO_POINTER (i));
|
||||||
|
|
||||||
|
return g_list_reverse (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NUM_ELEMENTS 10
|
||||||
|
|
||||||
|
START_TEST (test_manual_iteration)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gpointer item;
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
if (i < NUM_ELEMENTS) {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == i);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_DONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
START_TEST (test_resync)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gpointer item;
|
||||||
|
gint i = 0;
|
||||||
|
gboolean hacked_list = FALSE;
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
if (i < NUM_ELEMENTS / 2) {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == i);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
} else if (!hacked_list) {
|
||||||
|
/* here's where we test resync */
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
l = g_list_prepend (l, GINT_TO_POINTER (-1));
|
||||||
|
cookie++;
|
||||||
|
hacked_list = TRUE;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_RESYNC);
|
||||||
|
gst_iterator_resync (iter);
|
||||||
|
res = gst_iterator_next (iter, &item);
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_OK);
|
||||||
|
g_return_if_fail (GPOINTER_TO_INT (item) == -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
}
|
||||||
|
END_TEST static void
|
||||||
|
add_fold_func (gpointer item, GValue * ret, gpointer user_data)
|
||||||
|
{
|
||||||
|
g_value_set_int (ret, g_value_get_int (ret) + GPOINTER_TO_INT (item));
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST (test_fold)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint32 cookie = 0;
|
||||||
|
GMutex *m;
|
||||||
|
GstIterator *iter;
|
||||||
|
GstIteratorResult res;
|
||||||
|
gint i, expected;
|
||||||
|
GValue ret = { 0, };
|
||||||
|
|
||||||
|
l = make_list_of_ints (NUM_ELEMENTS);
|
||||||
|
m = g_mutex_new ();
|
||||||
|
iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL);
|
||||||
|
g_return_if_fail (iter != NULL);
|
||||||
|
|
||||||
|
expected = 0;
|
||||||
|
for (i = 0; i < NUM_ELEMENTS; i++)
|
||||||
|
expected += i;
|
||||||
|
|
||||||
|
g_value_init (&ret, G_TYPE_INT);
|
||||||
|
g_value_set_int (&ret, 0);
|
||||||
|
|
||||||
|
res = gst_iterator_fold (iter, add_fold_func, &ret, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (res == GST_ITERATOR_DONE);
|
||||||
|
g_return_if_fail (g_value_get_int (&ret) == expected);
|
||||||
|
}
|
||||||
|
END_TEST Suite * gstiterator_suite (void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create ("GstIterator");
|
||||||
|
TCase *tc_chain = tcase_create ("correctness");
|
||||||
|
|
||||||
|
tcase_set_timeout (tc_chain, 0);
|
||||||
|
|
||||||
|
suite_add_tcase (s, tc_chain);
|
||||||
|
tcase_add_test (tc_chain, test_manual_iteration);
|
||||||
|
tcase_add_test (tc_chain, test_resync);
|
||||||
|
tcase_add_test (tc_chain, test_fold);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nf;
|
||||||
|
|
||||||
|
Suite *s = gstiterator_suite ();
|
||||||
|
SRunner *sr = srunner_create (s);
|
||||||
|
|
||||||
|
gst_check_init (&argc, &argv);
|
||||||
|
|
||||||
|
srunner_run_all (sr, CK_NORMAL);
|
||||||
|
nf = srunner_ntests_failed (sr);
|
||||||
|
srunner_free (sr);
|
||||||
|
|
||||||
|
return nf;
|
||||||
|
}
|
Loading…
Reference in a new issue