mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
move all of these under tests
Original commit message from CVS: move all of these under tests
This commit is contained in:
parent
b0f15be3c1
commit
7533cf8523
215 changed files with 266 additions and 22251 deletions
218
ChangeLog
218
ChangeLog
|
@ -1,3 +1,221 @@
|
|||
2005-11-30 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* Makefile.am:
|
||||
* check/.cvsignore:
|
||||
* check/Makefile.am:
|
||||
* check/elements/.cvsignore:
|
||||
* check/elements/fakesrc.c:
|
||||
* check/elements/fdsrc.c:
|
||||
* check/elements/identity.c:
|
||||
* check/generic/.cvsignore:
|
||||
* check/generic/states.c:
|
||||
* check/gst-libs/.cvsignore:
|
||||
* check/gst-libs/controller.c:
|
||||
* check/gst-libs/gdp.c:
|
||||
* check/gst/.cvsignore:
|
||||
* check/gst/capslist.h:
|
||||
* check/gst/gst.c:
|
||||
* check/gst/gstbin.c:
|
||||
* check/gst/gstbuffer.c:
|
||||
* check/gst/gstbus.c:
|
||||
* check/gst/gstcaps.c:
|
||||
* check/gst/gstelement.c:
|
||||
* check/gst/gstevent.c:
|
||||
* check/gst/gstghostpad.c:
|
||||
* check/gst/gstiterator.c:
|
||||
* check/gst/gstmessage.c:
|
||||
* check/gst/gstminiobject.c:
|
||||
* check/gst/gstobject.c:
|
||||
* check/gst/gstpad.c:
|
||||
* check/gst/gstpipeline.c:
|
||||
* check/gst/gstplugin.c:
|
||||
* check/gst/gstsegment.c:
|
||||
* check/gst/gststructure.c:
|
||||
* check/gst/gstsystemclock.c:
|
||||
* check/gst/gsttag.c:
|
||||
* check/gst/gstutils.c:
|
||||
* check/gst/gstvalue.c:
|
||||
* check/net/.cvsignore:
|
||||
* check/net/gstnetclientclock.c:
|
||||
* check/net/gstnettimeprovider.c:
|
||||
* check/pipelines/.cvsignore:
|
||||
* check/pipelines/cleanup.c:
|
||||
* check/pipelines/simple_launch_lines.c:
|
||||
* check/pipelines/stress.c:
|
||||
* check/states/.cvsignore:
|
||||
* check/states/sinks.c:
|
||||
* configure.ac:
|
||||
* examples/Makefile.am:
|
||||
* examples/appreader/.cvsignore:
|
||||
* examples/appreader/Makefile.am:
|
||||
* examples/appreader/appreader.c:
|
||||
* examples/controller/.cvsignore:
|
||||
* examples/controller/Makefile.am:
|
||||
* examples/controller/audio-example.c:
|
||||
* examples/cutter/.cvsignore:
|
||||
* examples/cutter/Makefile.am:
|
||||
* examples/cutter/cutter.c:
|
||||
* examples/cutter/cutter.h:
|
||||
* examples/events/Makefile.am:
|
||||
* examples/events/seek.c:
|
||||
* examples/helloworld/.cvsignore:
|
||||
* examples/helloworld/Makefile.am:
|
||||
* examples/helloworld/helloworld.c:
|
||||
* examples/helloworld2/.cvsignore:
|
||||
* examples/helloworld2/Makefile.am:
|
||||
* examples/helloworld2/helloworld2.c:
|
||||
* examples/launch/.cvsignore:
|
||||
* examples/launch/Makefile.am:
|
||||
* examples/launch/mp3parselaunch.c:
|
||||
* examples/launch/mp3play:
|
||||
* examples/manual/.cvsignore:
|
||||
* examples/manual/Makefile.am:
|
||||
* examples/manual/extract.pl:
|
||||
* examples/metadata/Makefile.am:
|
||||
* examples/metadata/read-metadata.c:
|
||||
* examples/mixer/.cvsignore:
|
||||
* examples/mixer/Makefile.am:
|
||||
* examples/mixer/mixer.c:
|
||||
* examples/mixer/mixer.h:
|
||||
* examples/pingpong/.cvsignore:
|
||||
* examples/pingpong/Makefile.am:
|
||||
* examples/pingpong/pingpong.c:
|
||||
* examples/plugins/.cvsignore:
|
||||
* examples/plugins/Makefile.am:
|
||||
* examples/plugins/example.c:
|
||||
* examples/plugins/example.h:
|
||||
* examples/pwg/.cvsignore:
|
||||
* examples/pwg/Makefile.am:
|
||||
* examples/pwg/extract.pl:
|
||||
* examples/queue/.cvsignore:
|
||||
* examples/queue/Makefile.am:
|
||||
* examples/queue/queue.c:
|
||||
* examples/queue2/.cvsignore:
|
||||
* examples/queue2/Makefile.am:
|
||||
* examples/queue2/queue2.c:
|
||||
* examples/queue3/.cvsignore:
|
||||
* examples/queue3/Makefile.am:
|
||||
* examples/queue3/queue3.c:
|
||||
* examples/queue4/.cvsignore:
|
||||
* examples/queue4/Makefile.am:
|
||||
* examples/queue4/queue4.c:
|
||||
* examples/retag/.cvsignore:
|
||||
* examples/retag/Makefile.am:
|
||||
* examples/retag/retag.c:
|
||||
* examples/retag/transcode.c:
|
||||
* examples/thread/.cvsignore:
|
||||
* examples/thread/Makefile.am:
|
||||
* examples/thread/thread.c:
|
||||
* examples/typefind/.cvsignore:
|
||||
* examples/typefind/Makefile.am:
|
||||
* examples/typefind/typefind.c:
|
||||
* examples/xml/.cvsignore:
|
||||
* examples/xml/Makefile.am:
|
||||
* examples/xml/createxml.c:
|
||||
* examples/xml/runxml.c:
|
||||
* tests/Makefile.am:
|
||||
* tests/check/Makefile.am:
|
||||
* testsuite/.cvsignore:
|
||||
* testsuite/Makefile.am:
|
||||
* testsuite/Rules:
|
||||
* testsuite/caps/.cvsignore:
|
||||
* testsuite/caps/Makefile.am:
|
||||
* testsuite/caps/app_fixate.c:
|
||||
* testsuite/caps/audioscale.c:
|
||||
* testsuite/caps/caps.c:
|
||||
* testsuite/caps/caps.h:
|
||||
* testsuite/caps/caps_strings:
|
||||
* testsuite/caps/compatibility.c:
|
||||
* testsuite/caps/deserialize.c:
|
||||
* testsuite/caps/enumcaps.c:
|
||||
* testsuite/caps/eratosthenes.c:
|
||||
* testsuite/caps/filtercaps.c:
|
||||
* testsuite/caps/fixed.c:
|
||||
* testsuite/caps/fraction-convert.c:
|
||||
* testsuite/caps/fraction-multiply-and-zero.c:
|
||||
* testsuite/caps/intersect2.c:
|
||||
* testsuite/caps/intersection.c:
|
||||
* testsuite/caps/normalisation.c:
|
||||
* testsuite/caps/random.c:
|
||||
* testsuite/caps/renegotiate.c:
|
||||
* testsuite/caps/sets.c:
|
||||
* testsuite/caps/simplify.c:
|
||||
* testsuite/caps/string-conversions.c:
|
||||
* testsuite/caps/structure.c:
|
||||
* testsuite/caps/subtract.c:
|
||||
* testsuite/caps/union.c:
|
||||
* testsuite/debug/.cvsignore:
|
||||
* testsuite/debug/Makefile.am:
|
||||
* testsuite/debug/category.c:
|
||||
* testsuite/debug/commandline.c:
|
||||
* testsuite/debug/global.c:
|
||||
* testsuite/debug/output.c:
|
||||
* testsuite/debug/printf_extension.c:
|
||||
* testsuite/dlopen/.cvsignore:
|
||||
* testsuite/dlopen/Makefile.am:
|
||||
* testsuite/dlopen/dlopen_gst.c:
|
||||
* testsuite/dlopen/loadgst.c:
|
||||
* testsuite/elements/.cvsignore:
|
||||
* testsuite/elements/Makefile.am:
|
||||
* testsuite/elements/gst-inspect-check.in:
|
||||
* testsuite/elements/struct_i386.h:
|
||||
* testsuite/elements/struct_size.c:
|
||||
* testsuite/indexers/.cvsignore:
|
||||
* testsuite/indexers/Makefile.am:
|
||||
* testsuite/indexers/cache1.c:
|
||||
* testsuite/indexers/indexdump.c:
|
||||
* testsuite/parse/.cvsignore:
|
||||
* testsuite/parse/Makefile.am:
|
||||
* testsuite/parse/parse1.c:
|
||||
* testsuite/parse/parse2.c:
|
||||
* testsuite/plugin/.cvsignore:
|
||||
* testsuite/plugin/Makefile.am:
|
||||
* testsuite/plugin/README:
|
||||
* testsuite/plugin/dynamic.c:
|
||||
* testsuite/plugin/linked.c:
|
||||
* testsuite/plugin/loading.c:
|
||||
* testsuite/plugin/registry.c:
|
||||
* testsuite/plugin/static.c:
|
||||
* testsuite/plugin/static2.c:
|
||||
* testsuite/plugin/testplugin.c:
|
||||
* testsuite/plugin/testplugin2.c:
|
||||
* testsuite/plugin/testplugin2_s.c:
|
||||
* testsuite/plugin/testplugin_s.c:
|
||||
* testsuite/refcounting/.cvsignore:
|
||||
* testsuite/refcounting/Makefile.am:
|
||||
* testsuite/refcounting/bin.c:
|
||||
* testsuite/refcounting/element.c:
|
||||
* testsuite/refcounting/element_pad.c:
|
||||
* testsuite/refcounting/mainloop.c:
|
||||
* testsuite/refcounting/mem.c:
|
||||
* testsuite/refcounting/mem.h:
|
||||
* testsuite/refcounting/object.c:
|
||||
* testsuite/refcounting/pad.c:
|
||||
* testsuite/refcounting/sched.c:
|
||||
* testsuite/refcounting/thread.c:
|
||||
* testsuite/states/.cvsignore:
|
||||
* testsuite/states/Makefile.am:
|
||||
* testsuite/states/bin.c:
|
||||
* testsuite/states/locked.c:
|
||||
* testsuite/states/parent.c:
|
||||
* testsuite/threads/.cvsignore:
|
||||
* testsuite/threads/159566.c:
|
||||
* testsuite/threads/159852.c:
|
||||
* testsuite/threads/Makefile.am:
|
||||
* testsuite/threads/queue.c:
|
||||
* testsuite/threads/signals.c:
|
||||
* testsuite/threads/staticrec.c:
|
||||
* testsuite/threads/thread.c:
|
||||
* testsuite/threads/threadb.c:
|
||||
* testsuite/threads/threadc.c:
|
||||
* testsuite/threads/threadd.c:
|
||||
* testsuite/threads/threade.c:
|
||||
* testsuite/threads/threadf.c:
|
||||
* testsuite/threads/threadg.c:
|
||||
* testsuite/threads/threadh.c:
|
||||
* testsuite/threads/threadi.c:
|
||||
move all of these under tests
|
||||
|
||||
2005-11-30 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* configure.ac:
|
||||
|
|
32
Makefile.am
32
Makefile.am
|
@ -1,27 +1,5 @@
|
|||
DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --enable-docbook
|
||||
|
||||
if BUILD_TESTS
|
||||
## SUBDIRS_TESTS = tests testsuite
|
||||
## FIXME: write tests from scratch
|
||||
SUBDIRS_TESTS =
|
||||
if HAVE_CHECK
|
||||
SUBDIRS_CHECK = check
|
||||
else
|
||||
SUBDIRS_CHECK =
|
||||
endif
|
||||
else
|
||||
SUBDIRS_TESTS =
|
||||
SUBDIRS_CHECK =
|
||||
endif
|
||||
|
||||
if BUILD_EXAMPLES
|
||||
## FIXME: write examples from scratch
|
||||
# SUBDIRS_EXAMPLES = examples
|
||||
SUBDIRS_EXAMPLES =
|
||||
else
|
||||
SUBDIRS_EXAMPLES =
|
||||
endif
|
||||
|
||||
all-local: gst-element-check-@GST_MAJORMINOR@.m4
|
||||
|
||||
gst-element-check-@GST_MAJORMINOR@.m4: gst-element-check.m4
|
||||
|
@ -34,9 +12,6 @@ aclocal_DATA = gst-element-check-@GST_MAJORMINOR@.m4
|
|||
|
||||
SUBDIRS = \
|
||||
gst libs plugins tools \
|
||||
$(SUBDIRS_CHECK) \
|
||||
$(SUBDIRS_TESTS) \
|
||||
$(SUBDIRS_EXAMPLES) \
|
||||
docs \
|
||||
pkgconfig po \
|
||||
common
|
||||
|
@ -44,9 +19,6 @@ SUBDIRS = \
|
|||
# These are all the possible subdirs
|
||||
DIST_SUBDIRS = \
|
||||
gst libs plugins tools \
|
||||
check \
|
||||
tests testsuite \
|
||||
examples \
|
||||
docs \
|
||||
pkgconfig po \
|
||||
common
|
||||
|
@ -119,10 +91,10 @@ endif
|
|||
|
||||
if HAVE_CHECK
|
||||
check-valgrind:
|
||||
cd check && make check-valgrind
|
||||
cd tests/check && make check-valgrind
|
||||
|
||||
check-torture:
|
||||
cd check && make torture
|
||||
cd tests/check && make torture
|
||||
else
|
||||
check-valgrind:
|
||||
echo "'check' library not installed, skipping"
|
||||
|
|
2
check/.gitignore
vendored
2
check/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
test-registry.xml
|
||||
*.gcno
|
|
@ -1,110 +0,0 @@
|
|||
include $(top_srcdir)/common/check.mak
|
||||
|
||||
CHECK_REGISTRY = $(top_builddir)/check/test-registry.xml
|
||||
|
||||
GST_TOOLS_DIR = $(top_builddir)/tools
|
||||
|
||||
REGISTRY_ENVIRONMENT = \
|
||||
GST_REGISTRY=$(CHECK_REGISTRY)
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
$(REGISTRY_ENVIRONMENT) \
|
||||
GST_PLUGIN_SYSTEM_PATH= \
|
||||
GST_PLUGIN_PATH=$(top_builddir)/plugins
|
||||
|
||||
plugindir = $(libdir)/gstreamer-@GST_MAJORMINOR@
|
||||
|
||||
# override to _not_ install the test plugins
|
||||
install-pluginLTLIBRARIES:
|
||||
|
||||
# ths core dumps of some machines have PIDs appended
|
||||
CLEANFILES = core.* test-registry.xml
|
||||
|
||||
SUPPRESSIONS = $(top_srcdir)/common/gst.supp
|
||||
|
||||
clean-local: clean-local-check
|
||||
|
||||
# checks to fix
|
||||
# gst/gstplugin
|
||||
|
||||
check_PROGRAMS = \
|
||||
gst/gst \
|
||||
gst/gstbin \
|
||||
gst/gstbuffer \
|
||||
gst/gstbus \
|
||||
gst/gstcaps \
|
||||
gst/gstelement \
|
||||
gst/gstevent \
|
||||
gst/gstghostpad \
|
||||
gst/gstiterator \
|
||||
gst/gstmessage \
|
||||
gst/gstminiobject \
|
||||
gst/gstobject \
|
||||
gst/gstpad \
|
||||
gst/gstplugin \
|
||||
gst/gstsegment \
|
||||
gst/gstsystemclock \
|
||||
gst/gststructure \
|
||||
gst/gsttag \
|
||||
gst/gstutils \
|
||||
gst/gstvalue \
|
||||
elements/fakesrc \
|
||||
elements/identity \
|
||||
elements/fdsrc \
|
||||
generic/states \
|
||||
pipelines/simple_launch_lines \
|
||||
pipelines/stress \
|
||||
pipelines/cleanup \
|
||||
states/sinks \
|
||||
gst-libs/controller \
|
||||
gst-libs/gdp \
|
||||
net/gstnetclientclock \
|
||||
net/gstnettimeprovider
|
||||
|
||||
# failing tests
|
||||
noinst_PROGRAMS = \
|
||||
gst/gstpipeline
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
noinst_HEADERS = gst/capslist.h
|
||||
|
||||
AM_CFLAGS = $(GST_OBJ_CFLAGS) $(CHECK_CFLAGS)
|
||||
LDADD = $(top_builddir)/libs/gst/check/libgstcheck-@GST_MAJORMINOR@.la \
|
||||
$(GST_OBJ_LIBS) \
|
||||
$(CHECK_LIBS)
|
||||
|
||||
gst_libs_gdp_SOURCES = \
|
||||
gst-libs/gdp.c \
|
||||
$(top_srcdir)/libs/gst/dataprotocol/dataprotocol.c
|
||||
gst_libs_gdp_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
elements_fdsrc_CFLAGS=$(GST_OBJ_CFLAGS) $(CHECK_CFLAGS) -DTESTFILE=\"$(top_srcdir)/configure.ac\"
|
||||
|
||||
gst_libs_controller_LDADD = \
|
||||
$(top_builddir)/libs/gst/controller/libgstcontroller-@GST_MAJORMINOR@.la \
|
||||
$(LDADD)
|
||||
|
||||
net_gstnetclientclock_LDADD = \
|
||||
$(top_builddir)/libs/gst/net/libgstnet-@GST_MAJORMINOR@.la \
|
||||
$(LDADD)
|
||||
net_gstnettimeprovider_LDADD = \
|
||||
$(top_builddir)/libs/gst/net/libgstnet-@GST_MAJORMINOR@.la \
|
||||
$(LDADD)
|
||||
|
||||
# valgrind testing
|
||||
# these just need valgrind fixing, period
|
||||
VALGRIND_TO_FIX =
|
||||
|
||||
VALGRIND_IGNORE = \
|
||||
pipelines/stress
|
||||
|
||||
# these need fixing because the threads cause segfaults under valgrind
|
||||
TESTS_THREADED = \
|
||||
gst/gstminiobject \
|
||||
gst/gstobject
|
||||
|
||||
VALGRIND_TESTS_DISABLE = \
|
||||
$(TESTS_THREADED) \
|
||||
$(VALGRIND_IGNORE) \
|
||||
$(VALGRIND_TO_FIX)
|
4
check/elements/.gitignore
vendored
4
check/elements/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
.dirstamp
|
||||
fakesrc
|
||||
fdsrc
|
||||
identity
|
|
@ -1,273 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for fakesrc
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
gboolean have_eos = FALSE;
|
||||
|
||||
GstPad *mysinkpad;
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
|
||||
gboolean
|
||||
event_func (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
||||
have_eos = TRUE;
|
||||
gst_event_unref (event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gst_event_unref (event);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GstElement *
|
||||
setup_fakesrc ()
|
||||
{
|
||||
GstElement *fakesrc;
|
||||
|
||||
GST_DEBUG ("setup_fakesrc");
|
||||
fakesrc = gst_check_setup_element ("fakesrc");
|
||||
mysinkpad = gst_check_setup_sink_pad (fakesrc, &sinktemplate, NULL);
|
||||
gst_pad_set_event_function (mysinkpad, event_func);
|
||||
gst_pad_set_active (mysinkpad, TRUE);
|
||||
return fakesrc;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup_fakesrc (GstElement * fakesrc)
|
||||
{
|
||||
gst_check_teardown_sink_pad (fakesrc);
|
||||
gst_check_teardown_element (fakesrc);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_num_buffers)
|
||||
{
|
||||
GstElement *src;
|
||||
|
||||
src = setup_fakesrc ();
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
while (!have_eos) {
|
||||
g_usleep (1000);
|
||||
}
|
||||
|
||||
fail_unless (g_list_length (buffers) == 3);
|
||||
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fakesrc (src);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_sizetype_empty)
|
||||
{
|
||||
GstElement *src;
|
||||
GList *l;
|
||||
|
||||
src = setup_fakesrc ();
|
||||
|
||||
g_object_set (G_OBJECT (src), "sizetype", 1, NULL);
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
while (!have_eos) {
|
||||
g_usleep (1000);
|
||||
}
|
||||
|
||||
fail_unless (g_list_length (buffers) == 100);
|
||||
l = buffers;
|
||||
while (l) {
|
||||
GstBuffer *buf = l->data;
|
||||
|
||||
fail_unless (GST_BUFFER_SIZE (buf) == 0);
|
||||
l = l->next;
|
||||
}
|
||||
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fakesrc (src);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_sizetype_fixed)
|
||||
{
|
||||
GstElement *src;
|
||||
GList *l;
|
||||
|
||||
src = setup_fakesrc ();
|
||||
|
||||
g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
|
||||
g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
while (!have_eos) {
|
||||
g_usleep (1000);
|
||||
}
|
||||
|
||||
fail_unless (g_list_length (buffers) == 100);
|
||||
l = buffers;
|
||||
while (l) {
|
||||
GstBuffer *buf = l->data;
|
||||
|
||||
fail_unless (GST_BUFFER_SIZE (buf) == 8192);
|
||||
l = l->next;
|
||||
}
|
||||
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fakesrc (src);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_sizetype_random)
|
||||
{
|
||||
GstElement *src;
|
||||
GList *l;
|
||||
|
||||
src = setup_fakesrc ();
|
||||
|
||||
g_object_set (G_OBJECT (src), "sizetype", 3, NULL);
|
||||
g_object_set (G_OBJECT (src), "sizemin", 4096, NULL);
|
||||
g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
while (!have_eos) {
|
||||
g_usleep (1000);
|
||||
}
|
||||
|
||||
fail_unless (g_list_length (buffers) == 100);
|
||||
l = buffers;
|
||||
while (l) {
|
||||
GstBuffer *buf = l->data;
|
||||
|
||||
fail_if (GST_BUFFER_SIZE (buf) > 8192);
|
||||
fail_if (GST_BUFFER_SIZE (buf) < 4096);
|
||||
l = l->next;
|
||||
}
|
||||
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fakesrc (src);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_no_preroll)
|
||||
{
|
||||
GstElement *src;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
src = setup_fakesrc ();
|
||||
|
||||
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
|
||||
|
||||
ret = gst_element_set_state (src, GST_STATE_PAUSED);
|
||||
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"error going to paused the first time");
|
||||
|
||||
ret = gst_element_set_state (src, GST_STATE_PAUSED);
|
||||
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"error going to paused the second time");
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fakesrc (src);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
fakesrc_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("fakesrc");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_num_buffers);
|
||||
tcase_add_test (tc_chain, test_sizetype_empty);
|
||||
tcase_add_test (tc_chain, test_sizetype_fixed);
|
||||
tcase_add_test (tc_chain, test_sizetype_random);
|
||||
tcase_add_test (tc_chain, test_no_preroll);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = fakesrc_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;
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for fdsrc
|
||||
*
|
||||
* Copyright (C) <2005> Jan Schmidt <thaytan at mad dot scientist dot com>
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
gboolean have_eos = FALSE;
|
||||
|
||||
GstPad *mysinkpad;
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
|
||||
gboolean
|
||||
event_func (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
||||
have_eos = TRUE;
|
||||
gst_event_unref (event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gst_event_unref (event);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GstElement *
|
||||
setup_fdsrc ()
|
||||
{
|
||||
GstElement *fdsrc;
|
||||
|
||||
GST_DEBUG ("setup_fdsrc");
|
||||
fdsrc = gst_check_setup_element ("fdsrc");
|
||||
mysinkpad = gst_check_setup_sink_pad (fdsrc, &sinktemplate, NULL);
|
||||
gst_pad_set_event_function (mysinkpad, event_func);
|
||||
gst_pad_set_active (mysinkpad, TRUE);
|
||||
return fdsrc;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup_fdsrc (GstElement * fdsrc)
|
||||
{
|
||||
gst_check_teardown_sink_pad (fdsrc);
|
||||
gst_check_teardown_element (fdsrc);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_num_buffers)
|
||||
{
|
||||
GstElement *src;
|
||||
gint pipe_fd[2];
|
||||
gchar data[4096];
|
||||
|
||||
fail_if (pipe (pipe_fd) < 0);
|
||||
|
||||
src = setup_fdsrc ();
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
|
||||
g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
memset (data, 0, 4096);
|
||||
while (!have_eos) {
|
||||
fail_if (write (pipe_fd[1], data, 4096) < 0);
|
||||
g_usleep (100);
|
||||
}
|
||||
|
||||
fail_unless (g_list_length (buffers) == 3);
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fdsrc (src);
|
||||
close (pipe_fd[0]);
|
||||
close (pipe_fd[1]);
|
||||
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_nonseeking)
|
||||
{
|
||||
GstElement *src;
|
||||
GstQuery *seeking_query;
|
||||
gint pipe_fd[2];
|
||||
gchar data[4096];
|
||||
gboolean seekable;
|
||||
|
||||
fail_if (pipe (pipe_fd) < 0);
|
||||
|
||||
src = setup_fdsrc ();
|
||||
g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
|
||||
g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to paused");
|
||||
|
||||
memset (data, 0, 4096);
|
||||
fail_if (write (pipe_fd[1], data, 4096) < 0);
|
||||
|
||||
/* Test that fdsrc is non-seekable with a pipe */
|
||||
fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
|
||||
!= NULL);
|
||||
fail_unless (gst_element_query (src, seeking_query) == TRUE);
|
||||
gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
|
||||
fail_unless (seekable == FALSE);
|
||||
gst_query_unref (seeking_query);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fdsrc (src);
|
||||
close (pipe_fd[0]);
|
||||
close (pipe_fd[1]);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_seeking)
|
||||
{
|
||||
GstElement *src;
|
||||
gint in_fd;
|
||||
GstQuery *seeking_query;
|
||||
gboolean seekable;
|
||||
|
||||
#ifndef TESTFILE
|
||||
#error TESTFILE not defined
|
||||
#endif
|
||||
fail_if ((in_fd = open (TESTFILE, O_RDONLY)) < 0);
|
||||
src = setup_fdsrc ();
|
||||
|
||||
g_object_set (G_OBJECT (src), "fd", in_fd, NULL);
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to paused");
|
||||
|
||||
/* Test that fdsrc is seekable with a file fd */
|
||||
fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
|
||||
!= NULL);
|
||||
fail_unless (gst_element_query (src, seeking_query) == TRUE);
|
||||
gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
|
||||
fail_unless (seekable == TRUE);
|
||||
gst_query_unref (seeking_query);
|
||||
|
||||
fail_unless (gst_element_set_state (src,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
|
||||
/* cleanup */
|
||||
cleanup_fdsrc (src);
|
||||
close (in_fd);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
fdsrc_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("fdsrc");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_num_buffers);
|
||||
tcase_add_test (tc_chain, test_nonseeking);
|
||||
tcase_add_test (tc_chain, test_seeking);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = fdsrc_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;
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for identity
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
GList *buffers = NULL;
|
||||
gboolean have_eos = FALSE;
|
||||
|
||||
/* For ease of programming we use globals to keep refs for our floating
|
||||
* src and sink pads we create; otherwise we always have to do get_pad,
|
||||
* get_peer, and then remove references in every test function */
|
||||
GstPad *mysrcpad, *mysinkpad;
|
||||
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
|
||||
gboolean
|
||||
event_func (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
||||
have_eos = TRUE;
|
||||
gst_event_unref (event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gst_event_unref (event);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GstElement *
|
||||
setup_identity ()
|
||||
{
|
||||
GstElement *identity;
|
||||
|
||||
GST_DEBUG ("setup_identity");
|
||||
|
||||
identity = gst_check_setup_element ("identity");
|
||||
mysrcpad = gst_check_setup_src_pad (identity, &srctemplate, NULL);
|
||||
mysinkpad = gst_check_setup_sink_pad (identity, &sinktemplate, NULL);
|
||||
gst_pad_set_event_function (mysinkpad, event_func);
|
||||
gst_pad_set_active (mysrcpad, TRUE);
|
||||
gst_pad_set_active (mysinkpad, TRUE);
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup_identity (GstElement * identity)
|
||||
{
|
||||
GST_DEBUG ("cleanup_identity");
|
||||
|
||||
gst_check_teardown_src_pad (identity);
|
||||
gst_check_teardown_sink_pad (identity);
|
||||
gst_check_teardown_element (identity);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_one_buffer)
|
||||
{
|
||||
GstElement *identity;
|
||||
GstBuffer *buffer;
|
||||
|
||||
identity = setup_identity ();
|
||||
fail_unless (gst_element_set_state (identity,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
||||
"could not set to playing");
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
memcpy (GST_BUFFER_DATA (buffer), "data", 4);
|
||||
/* pushing gives away my reference ... */
|
||||
gst_pad_push (mysrcpad, buffer);
|
||||
/* ... but it should end up being collected on the global buffer list */
|
||||
fail_unless (g_list_length (buffers) == 1);
|
||||
fail_unless ((GstBuffer *) (g_list_first (buffers)->data) == buffer);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
|
||||
/* cleanup */
|
||||
cleanup_identity (identity);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
identity_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("identity");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_one_buffer);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = identity_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;
|
||||
}
|
2
check/generic/.gitignore
vendored
2
check/generic/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
.dirstamp
|
||||
states
|
|
@ -1,93 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for state changes on all elements
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_state_changes)
|
||||
{
|
||||
GstElement *element;
|
||||
GList *features, *f;
|
||||
|
||||
features = gst_registry_get_feature_list (gst_registry_get_default (),
|
||||
GST_TYPE_ELEMENT_FACTORY);
|
||||
|
||||
for (f = features; f; f = f->next) {
|
||||
GstPluginFeature *feature = f->data;
|
||||
const gchar *name = gst_plugin_feature_get_name (feature);
|
||||
|
||||
GST_DEBUG ("testing element %s", name);
|
||||
element = gst_element_factory_make (name, name);
|
||||
|
||||
gst_element_set_state (element, GST_STATE_READY);
|
||||
gst_element_set_state (element, GST_STATE_PAUSED);
|
||||
gst_element_set_state (element, GST_STATE_PLAYING);
|
||||
|
||||
gst_element_set_state (element, GST_STATE_PAUSED);
|
||||
gst_element_set_state (element, GST_STATE_READY);
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
gst_element_set_state (element, GST_STATE_PAUSED);
|
||||
gst_element_set_state (element, GST_STATE_READY);
|
||||
gst_element_set_state (element, GST_STATE_PLAYING);
|
||||
gst_element_set_state (element, GST_STATE_PAUSED);
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
|
||||
gst_object_unref (GST_OBJECT (element));
|
||||
}
|
||||
gst_task_cleanup_all ();
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
states_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("states");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
/* Use a long timeout, as we test all elements and take
|
||||
* at least 0.2 seconds each */
|
||||
tcase_set_timeout (tc_chain, 120);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_state_changes);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = states_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;
|
||||
}
|
3
check/gst-libs/.gitignore
vendored
3
check/gst-libs/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
.dirstamp
|
||||
gdp
|
||||
controller
|
|
@ -1,629 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for the controller library
|
||||
*
|
||||
* Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dor net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <gst/gst.h>
|
||||
#include <gst/check/gstcheck.h>
|
||||
#include <gst/controller/gstcontroller.h>
|
||||
|
||||
/* LOCAL TEST ELEMENT */
|
||||
|
||||
enum
|
||||
{
|
||||
ARG_ULONG = 1,
|
||||
ARG_DOUBLE,
|
||||
ARG_BOOLEAN,
|
||||
ARG_READONLY,
|
||||
ARG_STATIC,
|
||||
ARG_CONSTRUCTONLY,
|
||||
ARG_COUNT
|
||||
};
|
||||
|
||||
#define GST_TYPE_TEST_MONO_SOURCE (gst_test_mono_source_get_type ())
|
||||
#define GST_TEST_MONO_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSource))
|
||||
#define GST_TEST_MONO_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSourceClass))
|
||||
#define GST_IS_TEST_MONO_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TEST_MONO_SOURCE))
|
||||
#define GST_IS_TEST_MONO_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TEST_MONO_SOURCE))
|
||||
#define GST_TEST_MONO_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSourceClass))
|
||||
|
||||
typedef struct _GstTestMonoSource GstTestMonoSource;
|
||||
typedef struct _GstTestMonoSourceClass GstTestMonoSourceClass;
|
||||
|
||||
struct _GstTestMonoSource
|
||||
{
|
||||
GstElement parent;
|
||||
gulong val_ulong;
|
||||
gdouble val_double;
|
||||
gboolean val_boolean;
|
||||
};
|
||||
struct _GstTestMonoSourceClass
|
||||
{
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_test_mono_source_get_type (void);
|
||||
|
||||
static void
|
||||
gst_test_mono_source_get_property (GObject * object,
|
||||
guint property_id, GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case ARG_ULONG:
|
||||
g_value_set_ulong (value, self->val_ulong);
|
||||
break;
|
||||
case ARG_DOUBLE:
|
||||
g_value_set_double (value, self->val_double);
|
||||
break;
|
||||
case ARG_BOOLEAN:
|
||||
g_value_set_boolean (value, self->val_boolean);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_test_mono_source_set_property (GObject * object,
|
||||
guint property_id, const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case ARG_ULONG:
|
||||
self->val_ulong = g_value_get_ulong (value);
|
||||
break;
|
||||
case ARG_DOUBLE:
|
||||
self->val_double = g_value_get_double (value);
|
||||
break;
|
||||
case ARG_BOOLEAN:
|
||||
self->val_boolean = g_value_get_boolean (value);
|
||||
break;
|
||||
case ARG_CONSTRUCTONLY:
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_test_mono_source_class_init (GstTestMonoSourceClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gobject_class->set_property = gst_test_mono_source_set_property;
|
||||
gobject_class->get_property = gst_test_mono_source_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_ULONG,
|
||||
g_param_spec_ulong ("ulong",
|
||||
"ulong prop",
|
||||
"ulong number parameter for the test_mono_source",
|
||||
0, G_MAXULONG, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_DOUBLE,
|
||||
g_param_spec_double ("double",
|
||||
"double prop",
|
||||
"double number parameter for the test_mono_source",
|
||||
0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_BOOLEAN,
|
||||
g_param_spec_boolean ("boolean",
|
||||
"boolean prop",
|
||||
"boolean parameter for the test_mono_source",
|
||||
FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_READONLY,
|
||||
g_param_spec_ulong ("readonly",
|
||||
"readonly prop",
|
||||
"readonly parameter for the test_mono_source",
|
||||
0, G_MAXULONG, 0, G_PARAM_READABLE | GST_PARAM_CONTROLLABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_STATIC,
|
||||
g_param_spec_ulong ("static",
|
||||
"static prop",
|
||||
"static parameter for the test_mono_source",
|
||||
0, G_MAXULONG, 0, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_CONSTRUCTONLY,
|
||||
g_param_spec_ulong ("construct-only",
|
||||
"construct-only prop",
|
||||
"construct-only parameter for the test_mono_source",
|
||||
0, G_MAXULONG, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_test_mono_source_base_init (GstTestMonoSourceClass * klass)
|
||||
{
|
||||
static const GstElementDetails details = {
|
||||
"Monophonic source for unit tests",
|
||||
"Source/Audio/MonoSource",
|
||||
"Use in unit tests",
|
||||
"Stefan Kost <ensonic@users.sf.net>"
|
||||
};
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gst_element_class_set_details (element_class, &details);
|
||||
}
|
||||
|
||||
GType
|
||||
gst_test_mono_source_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (type == 0) {
|
||||
static const GTypeInfo info = {
|
||||
(guint16) sizeof (GstTestMonoSourceClass),
|
||||
(GBaseInitFunc) gst_test_mono_source_base_init, // base_init
|
||||
NULL, // base_finalize
|
||||
(GClassInitFunc) gst_test_mono_source_class_init, // class_init
|
||||
NULL, // class_finalize
|
||||
NULL, // class_data
|
||||
(guint16) sizeof (GstTestMonoSource),
|
||||
0, // n_preallocs
|
||||
NULL, // instance_init
|
||||
NULL // value_table
|
||||
};
|
||||
type =
|
||||
g_type_register_static (GST_TYPE_ELEMENT, "GstTestMonoSource", &info,
|
||||
0);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
|
||||
res &= gst_element_register (plugin, "testmonosource", GST_RANK_NONE,
|
||||
GST_TYPE_TEST_MONO_SOURCE);
|
||||
return res;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"gst-test",
|
||||
"controller test plugin - several unit test support elements",
|
||||
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|
||||
|
||||
/*
|
||||
static void __attribute__ ((constructor))
|
||||
_gst_plugin_static_init__plugin_init (void)
|
||||
{
|
||||
static GstPluginDesc plugin_desc_ = {
|
||||
GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"gst-test",
|
||||
"controller test plugin - several unit test support elements",
|
||||
plugin_init,
|
||||
VERSION,
|
||||
GST_LICENSE,
|
||||
PACKAGE,
|
||||
GST_PACKAGE,
|
||||
GST_ORIGIN,
|
||||
GST_PADDING_INIT
|
||||
};
|
||||
_gst_plugin_register_static (&plugin_desc_);
|
||||
}
|
||||
*/
|
||||
/* TESTS */
|
||||
/* double init should not harm */
|
||||
GST_START_TEST (controller_init)
|
||||
{
|
||||
gst_controller_init (NULL, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for an element with no controlled params */
|
||||
GST_START_TEST (controller_new_fail1)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("fakesrc", "test_source");
|
||||
|
||||
/* that property should not exist */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "_schrompf_", NULL);
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for an element with controlled params, but none given */
|
||||
GST_START_TEST (controller_new_fail2)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* no property given */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), NULL);
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for readonly params */
|
||||
GST_START_TEST (controller_new_fail3)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and but is readonly */
|
||||
ASSERT_CRITICAL (ctrl =
|
||||
gst_controller_new (G_OBJECT (elem), "readonly", NULL));
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for static params */
|
||||
GST_START_TEST (controller_new_fail4)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and but is not controlable */
|
||||
ASSERT_CRITICAL (ctrl = gst_controller_new (G_OBJECT (elem), "static", NULL));
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for static params */
|
||||
GST_START_TEST (controller_new_fail5)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and but is construct-only */
|
||||
ASSERT_CRITICAL (ctrl =
|
||||
gst_controller_new (G_OBJECT (elem), "construct-only", NULL));
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/* tests for an element with controlled params */
|
||||
GST_START_TEST (controller_new_okay1)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests for an element with several controlled params */
|
||||
GST_START_TEST (controller_new_okay2)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "double", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* controlling several params should return the same controller */
|
||||
GST_START_TEST (controller_new_okay3)
|
||||
{
|
||||
GstController *ctrl1, *ctrl2;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl1 = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl1 != NULL, NULL);
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl2 = gst_controller_new (G_OBJECT (elem), "double", NULL);
|
||||
fail_unless (ctrl2 != NULL, NULL);
|
||||
fail_unless (ctrl1 == ctrl2, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl1)->ref_count);
|
||||
g_object_unref (ctrl1);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* controlling a params twice should be handled */
|
||||
GST_START_TEST (controller_param_twice)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
gboolean res;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
/* it should have been added at least once, let remove it */
|
||||
res = gst_controller_remove_properties (ctrl, "ulong", NULL);
|
||||
fail_unless (res, NULL);
|
||||
|
||||
/* removing it agian should not work */
|
||||
res = gst_controller_remove_properties (ctrl, "ulong", NULL);
|
||||
fail_unless (!res, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests if we cleanup properly */
|
||||
GST_START_TEST (controller_finalize)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
/* free the controller */
|
||||
g_object_unref (ctrl);
|
||||
|
||||
/* object shouldn't have a controller anymore */
|
||||
ctrl = gst_object_get_controller (G_OBJECT (elem));
|
||||
fail_unless (ctrl == NULL, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test timed value handling without interpolation */
|
||||
GST_START_TEST (controller_interpolate_none)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
gboolean res;
|
||||
GValue val_ulong = { 0, };
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
/* set interpolation mode */
|
||||
gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
|
||||
|
||||
/* set control values */
|
||||
g_value_init (&val_ulong, G_TYPE_ULONG);
|
||||
g_value_set_ulong (&val_ulong, 0);
|
||||
res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
g_value_set_ulong (&val_ulong, 100);
|
||||
res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
|
||||
/* now pull in values for some timestamps */
|
||||
gst_controller_sync_values (ctrl, 0 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
|
||||
gst_controller_sync_values (ctrl, 1 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
|
||||
gst_controller_sync_values (ctrl, 2 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test timed value handling in trigger mode */
|
||||
GST_START_TEST (controller_interpolate_trigger)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
gboolean res;
|
||||
GValue val_ulong = { 0, };
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
/* set interpolation mode */
|
||||
gst_controller_set_interpolation_mode (ctrl, "ulong",
|
||||
GST_INTERPOLATE_TRIGGER);
|
||||
|
||||
/* set control values */
|
||||
g_value_init (&val_ulong, G_TYPE_ULONG);
|
||||
g_value_set_ulong (&val_ulong, 50);
|
||||
res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
g_value_set_ulong (&val_ulong, 100);
|
||||
res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
|
||||
/* now pull in values for some timestamps */
|
||||
gst_controller_sync_values (ctrl, 0 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
|
||||
GST_TEST_MONO_SOURCE (elem)->val_ulong = 0;
|
||||
gst_controller_sync_values (ctrl, 1 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
|
||||
gst_controller_sync_values (ctrl, 2 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test timed value handling with linear interpolation */
|
||||
GST_START_TEST (controller_interpolate_linear)
|
||||
{
|
||||
GstController *ctrl;
|
||||
GstElement *elem;
|
||||
gboolean res;
|
||||
GValue val_ulong = { 0, };
|
||||
|
||||
elem = gst_element_factory_make ("testmonosource", "test_source");
|
||||
|
||||
/* that property should exist and should be controllable */
|
||||
ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
|
||||
fail_unless (ctrl != NULL, NULL);
|
||||
|
||||
/* set interpolation mode */
|
||||
gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
|
||||
|
||||
/* set control values */
|
||||
g_value_init (&val_ulong, G_TYPE_ULONG);
|
||||
g_value_set_ulong (&val_ulong, 0);
|
||||
res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
g_value_set_ulong (&val_ulong, 100);
|
||||
res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
|
||||
fail_unless (res, NULL);
|
||||
|
||||
/* now pull in values for some timestamps */
|
||||
gst_controller_sync_values (ctrl, 0 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
|
||||
gst_controller_sync_values (ctrl, 1 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
|
||||
gst_controller_sync_values (ctrl, 2 * GST_SECOND);
|
||||
fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
|
||||
|
||||
GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
|
||||
g_object_unref (ctrl);
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests if we can run helper methods against any GObject */
|
||||
GST_START_TEST (controller_helper_any_gobject)
|
||||
{
|
||||
GstElement *elem;
|
||||
gboolean res;
|
||||
|
||||
elem = gst_element_factory_make ("bin", "test_elem");
|
||||
|
||||
/* that element is not controllable */
|
||||
res = gst_object_sync_values (G_OBJECT (elem), 0LL);
|
||||
fail_unless (res == FALSE, NULL);
|
||||
|
||||
gst_object_unref (elem);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
Suite *
|
||||
gst_controller_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Controller");
|
||||
TCase *tc = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc);
|
||||
tcase_add_test (tc, controller_init);
|
||||
tcase_add_test (tc, controller_new_fail1);
|
||||
tcase_add_test (tc, controller_new_fail2);
|
||||
tcase_add_test (tc, controller_new_fail3);
|
||||
tcase_add_test (tc, controller_new_fail4);
|
||||
tcase_add_test (tc, controller_new_fail5);
|
||||
tcase_add_test (tc, controller_new_okay1);
|
||||
tcase_add_test (tc, controller_new_okay2);
|
||||
tcase_add_test (tc, controller_new_okay3);
|
||||
tcase_add_test (tc, controller_param_twice);
|
||||
tcase_add_test (tc, controller_finalize);
|
||||
tcase_add_test (tc, controller_interpolate_none);
|
||||
tcase_add_test (tc, controller_interpolate_trigger);
|
||||
tcase_add_test (tc, controller_interpolate_linear);
|
||||
tcase_add_test (tc, controller_helper_any_gobject);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_controller_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
gst_controller_init (NULL, NULL);
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
|
@ -1,312 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for data protocol
|
||||
*
|
||||
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
#include <gst/dataprotocol/dataprotocol.h>
|
||||
#include "libs/gst/dataprotocol/dp-private.h" /* private header */
|
||||
|
||||
/* test our method of reading and writing headers using TO/FROM_BE */
|
||||
GST_START_TEST (test_conversion)
|
||||
{
|
||||
guint8 array[9];
|
||||
guint8 write_array[9];
|
||||
guint16 read_two, expect_two;
|
||||
guint32 read_four, expect_four;
|
||||
guint64 read_eight, expect_eight;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 9; ++i) {
|
||||
array[i] = i * 0x10;
|
||||
}
|
||||
|
||||
/* read 8 16 bits */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
read_two = GST_READ_UINT16_BE (array + i);
|
||||
expect_two = array[i] * (1 << 8) + array[i + 1];
|
||||
fail_unless (read_two == expect_two,
|
||||
"GST_READ_UINT16_BE %d: read %d != %d\n", i, read_two, expect_two);
|
||||
}
|
||||
|
||||
/* write 8 16 bits */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
GST_WRITE_UINT16_BE (&write_array[i], read_two);
|
||||
fail_unless (memcmp (array + 7, write_array + i, 2) == 0,
|
||||
"GST_WRITE_UINT16_BE %d: memcmp failed", i);
|
||||
}
|
||||
|
||||
/* read 5 32 bits */
|
||||
for (i = 0; i < 5; ++i) {
|
||||
read_four = GST_READ_UINT32_BE (array + i);
|
||||
expect_four = array[i] * (1 << 24) + array[i + 1] * (1 << 16)
|
||||
+ array[i + 2] * (1 << 8) + array[i + 3];
|
||||
fail_unless (read_four == expect_four,
|
||||
"GST_READ_UINT32_BE %d: read %d != %d\n", i, read_four, expect_four);
|
||||
}
|
||||
|
||||
/* read 2 64 bits */
|
||||
for (i = 0; i < 2; ++i) {
|
||||
read_eight = GST_READ_UINT64_BE (array + i);
|
||||
expect_eight = array[i] * (1LL << 56) + array[i + 1] * (1LL << 48)
|
||||
+ array[i + 2] * (1LL << 40) + array[i + 3] * (1LL << 32)
|
||||
+ array[i + 4] * (1 << 24) + array[i + 5] * (1 << 16)
|
||||
+ array[i + 6] * (1 << 8) + array[i + 7];
|
||||
fail_unless (read_eight == expect_eight,
|
||||
"GST_READ_UINT64_BE %d: read %" G_GUINT64_FORMAT
|
||||
" != %" G_GUINT64_FORMAT "\n", i, read_eight, expect_eight);
|
||||
}
|
||||
|
||||
/* write 1 64 bit */
|
||||
GST_WRITE_UINT64_BE (&write_array[0], read_eight);
|
||||
fail_unless (memcmp (array + 1, write_array, 8) == 0,
|
||||
"GST_WRITE_UINT64_BE: memcmp failed");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test creation of header from buffer and back again */
|
||||
GST_START_TEST (test_buffer)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstBuffer *newbuffer;
|
||||
|
||||
guint header_length;
|
||||
guint8 *header;
|
||||
|
||||
/* create buffer */
|
||||
g_message ("Creating a new 8-byte buffer with ts 0.5 sec, dur 1 sec\n");
|
||||
buffer = gst_buffer_new_and_alloc (8);
|
||||
GST_BUFFER_TIMESTAMP (buffer) = (GstClockTime) (GST_SECOND * 0.5);
|
||||
GST_BUFFER_DURATION (buffer) = (GstClockTime) GST_SECOND;
|
||||
GST_BUFFER_OFFSET (buffer) = (guint64) 10;
|
||||
GST_BUFFER_OFFSET_END (buffer) = (guint64) 19;
|
||||
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
|
||||
memmove (GST_BUFFER_DATA (buffer), "a buffer", 8);
|
||||
|
||||
/* create a buffer with CRC checking */
|
||||
fail_unless (gst_dp_header_from_buffer (buffer, GST_DP_HEADER_FLAG_CRC,
|
||||
&header_length, &header), "Could not create header from buffer.");
|
||||
|
||||
/* validate the header */
|
||||
fail_unless (gst_dp_validate_header (header_length, header),
|
||||
"Could not validate header");
|
||||
/* create a new, empty buffer with the right size */
|
||||
newbuffer = gst_dp_buffer_from_header (header_length, header);
|
||||
fail_unless (newbuffer != NULL, "Could not create a new buffer from header");
|
||||
fail_unless (GST_IS_BUFFER (newbuffer), "Created buffer is not a GstBuffer");
|
||||
/* read/copy the data */
|
||||
memmove (GST_BUFFER_DATA (newbuffer), GST_BUFFER_DATA (buffer),
|
||||
GST_BUFFER_SIZE (buffer));
|
||||
/* validate the buffer */
|
||||
fail_unless (gst_dp_validate_payload (header_length, header,
|
||||
GST_BUFFER_DATA (newbuffer)), "Could not validate payload");
|
||||
|
||||
g_message ("new buffer timestamp: %" GST_TIME_FORMAT "\n",
|
||||
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (newbuffer)));
|
||||
g_message ("new buffer duration: %" GST_TIME_FORMAT "\n",
|
||||
GST_TIME_ARGS (GST_BUFFER_DURATION (newbuffer)));
|
||||
g_message ("new buffer offset: %" G_GUINT64_FORMAT "\n",
|
||||
GST_BUFFER_OFFSET (newbuffer));
|
||||
g_message ("new buffer offset_end: %" G_GUINT64_FORMAT "\n",
|
||||
GST_BUFFER_OFFSET_END (newbuffer));
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (newbuffer) ==
|
||||
GST_BUFFER_TIMESTAMP (buffer), "Timestamps don't match !");
|
||||
fail_unless (GST_BUFFER_DURATION (newbuffer) == GST_BUFFER_DURATION (buffer),
|
||||
"Durations don't match !");
|
||||
fail_unless (GST_BUFFER_OFFSET (newbuffer) == GST_BUFFER_OFFSET (buffer),
|
||||
"Offsets don't match !");
|
||||
fail_unless (GST_BUFFER_OFFSET_END (newbuffer) ==
|
||||
GST_BUFFER_OFFSET_END (buffer), "Offset ends don't match !");
|
||||
fail_unless (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_FLAG_IN_CAPS),
|
||||
"GST_BUFFER_IN_CAPS flag should have been copied !");
|
||||
|
||||
/* clean up */
|
||||
gst_buffer_unref (buffer);
|
||||
gst_buffer_unref (newbuffer);
|
||||
g_free (header);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_caps)
|
||||
{
|
||||
gchar *string, *newstring;
|
||||
GstCaps *caps, *newcaps;
|
||||
|
||||
guint header_length;
|
||||
guint8 *header, *payload;
|
||||
|
||||
caps = gst_caps_from_string ("audio/x-raw-float, "
|
||||
"rate = (int) [ 11025, 48000 ], "
|
||||
"channels = (int) [ 1, 2 ], " "endianness = (int) BYTE_ORDER, "
|
||||
"width = (int) 32, " "buffer-frames = (int) 0");
|
||||
string = gst_caps_to_string (caps);
|
||||
g_message ("Created caps: %s\n", string);
|
||||
fail_unless (gst_dp_packet_from_caps (caps, 0, &header_length, &header,
|
||||
&payload), "Could not create packet from caps.");
|
||||
|
||||
/* validate the packet */
|
||||
fail_unless (gst_dp_validate_packet (header_length, header, payload),
|
||||
"Could not validate packet");
|
||||
newcaps = gst_dp_caps_from_packet (header_length, header, payload);
|
||||
fail_unless (newcaps != NULL, "Could not create caps from packet");
|
||||
fail_unless (GST_IS_CAPS (newcaps));
|
||||
newstring = gst_caps_to_string (newcaps);
|
||||
g_message ("Received caps: %s\n", newstring);
|
||||
fail_unless (strcmp (string, newstring) == 0,
|
||||
"Created caps do not match original caps");
|
||||
|
||||
/* cleanup */
|
||||
gst_caps_unref (caps);
|
||||
gst_caps_unref (newcaps);
|
||||
g_free (header);
|
||||
g_free (payload);
|
||||
g_free (string);
|
||||
g_free (newstring);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_event)
|
||||
{
|
||||
GstEvent *send;
|
||||
GstEvent *receive;
|
||||
guint header_length;
|
||||
guint8 *header, *payload;
|
||||
|
||||
g_message ("Testing EOS event at 1s\n");
|
||||
send = gst_event_new_eos ();
|
||||
GST_EVENT_TIMESTAMP (send) = GST_SECOND;
|
||||
fail_unless (gst_dp_packet_from_event (send, GST_DP_HEADER_FLAG_CRC,
|
||||
&header_length, &header, &payload),
|
||||
"Could not create packet from eos event");
|
||||
|
||||
receive = gst_dp_event_from_packet (header_length, header, payload);
|
||||
|
||||
g_message ("EOS, timestamp %" GST_TIME_FORMAT "\n",
|
||||
GST_TIME_ARGS (GST_EVENT_TIMESTAMP (receive)));
|
||||
fail_unless (GST_EVENT_TYPE (receive) == GST_EVENT_EOS,
|
||||
"Received event is not EOS");
|
||||
fail_unless (GST_EVENT_TIMESTAMP (receive) == GST_SECOND,
|
||||
"EOS timestamp is not 1.0 sec");
|
||||
|
||||
/* clean up */
|
||||
g_free (header);
|
||||
g_free (payload);
|
||||
gst_event_unref (send);
|
||||
gst_event_unref (receive);
|
||||
|
||||
g_message ("Testing FLUSH event at 2s\n");
|
||||
send = gst_event_new_flush_start ();
|
||||
GST_EVENT_TIMESTAMP (send) = GST_SECOND * 2;
|
||||
fail_unless (gst_dp_packet_from_event (send, GST_DP_HEADER_FLAG_CRC,
|
||||
&header_length, &header, &payload),
|
||||
"Could not create packet from flush event");
|
||||
|
||||
receive = gst_dp_event_from_packet (header_length, header, payload);
|
||||
|
||||
g_message ("Flush, timestamp %" GST_TIME_FORMAT "\n",
|
||||
GST_TIME_ARGS (GST_EVENT_TIMESTAMP (receive)));
|
||||
fail_unless (GST_EVENT_TYPE (receive) == GST_EVENT_FLUSH_START,
|
||||
"Received event is not flush");
|
||||
fail_unless (GST_EVENT_TIMESTAMP (receive) == GST_SECOND * 2,
|
||||
"Flush timestamp is not 2.0 sec");
|
||||
|
||||
/* clean up */
|
||||
g_free (header);
|
||||
g_free (payload);
|
||||
gst_event_unref (send);
|
||||
gst_event_unref (receive);
|
||||
|
||||
g_message ("Testing SEEK event with 1 second at 3 seconds\n");
|
||||
send =
|
||||
gst_event_new_seek (1.0, GST_FORMAT_TIME, 0, GST_SEEK_TYPE_SET,
|
||||
GST_SECOND, GST_SEEK_TYPE_NONE, 0);
|
||||
GST_EVENT_TIMESTAMP (send) = GST_SECOND * 3;
|
||||
fail_unless (gst_dp_packet_from_event (send, GST_DP_HEADER_FLAG_CRC,
|
||||
&header_length, &header, &payload),
|
||||
"Could not create packet from seek event");
|
||||
|
||||
receive = gst_dp_event_from_packet (header_length, header, payload);
|
||||
|
||||
{
|
||||
gdouble rate;
|
||||
GstFormat format;
|
||||
GstSeekFlags flags;
|
||||
GstSeekType cur_type, stop_type;
|
||||
gint64 cur, stop;
|
||||
|
||||
gst_event_parse_seek (receive, &rate, &format, &flags,
|
||||
&cur_type, &cur, &stop_type, &stop);
|
||||
|
||||
g_message ("Seek, timestamp %" GST_TIME_FORMAT ", to %" GST_TIME_FORMAT
|
||||
"\n", GST_TIME_ARGS (GST_EVENT_TIMESTAMP (receive)),
|
||||
GST_TIME_ARGS (cur));
|
||||
fail_unless (GST_EVENT_TYPE (receive) == GST_EVENT_SEEK,
|
||||
"Returned event is not seek");
|
||||
fail_unless (GST_EVENT_TIMESTAMP (receive) == GST_SECOND * 3,
|
||||
"Seek timestamp is not 3.0 sec");
|
||||
fail_unless (format == GST_FORMAT_TIME, "Seek format is not time");
|
||||
fail_unless (cur == GST_SECOND, "Seek cur is not 1.0 sec");
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
g_free (header);
|
||||
g_free (payload);
|
||||
gst_event_unref (send);
|
||||
gst_event_unref (receive);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_data_protocol_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("data protocol");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_conversion);
|
||||
tcase_add_test (tc_chain, test_buffer);
|
||||
tcase_add_test (tc_chain, test_caps);
|
||||
tcase_add_test (tc_chain, test_event);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_data_protocol_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
gst_dp_init ();
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
23
check/gst/.gitignore
vendored
23
check/gst/.gitignore
vendored
|
@ -1,23 +0,0 @@
|
|||
.dirstamp
|
||||
gst
|
||||
gstbin
|
||||
gstbuffer
|
||||
gstbus
|
||||
gstcaps
|
||||
gstdata
|
||||
gstelement
|
||||
gstevent
|
||||
gstghostpad
|
||||
gstiterator
|
||||
gstmessage
|
||||
gstminiobject
|
||||
gstobject
|
||||
gstpad
|
||||
gstpipeline
|
||||
gstplugin
|
||||
gstsegment
|
||||
gststructure
|
||||
gstsystemclock
|
||||
gsttag
|
||||
gstutils
|
||||
gstvalue
|
|
@ -1,31 +0,0 @@
|
|||
#include <glib.h>
|
||||
|
||||
/* defines an array of strings named caps_list, that contains a list of caps for
|
||||
general tests. So if you don't know what caps to use to write a test, just
|
||||
include this file */
|
||||
|
||||
static const gchar *caps_list[] = {
|
||||
"audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)g726; audio/x-adpcm, layout=(string)g726",
|
||||
"video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)I420; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUY2; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)16711680, green_mask=(int)65280, blue_mask=(int)255, endianness=(int)4321; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)255, green_mask=(int)65280, blue_mask=(int)16711680, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y42B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)32, depth=(int)24, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUV9; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y41B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, endianness=(int)1234; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)15, red_mask=(int)31744, green_mask=(int)992, blue_mask=(int)31, endianness=(int)1234",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-jpeg, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-divx, divxversion=(int)[ 3, 5 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-xvid, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-3ivx, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-msmpeg, msmpegversion=(int)[ 41, 43 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/mpeg, mpegversion=(int)1, systemstream=(boolean)false, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-h263, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-dv, systemstream=(boolean)false, width=(int)720, height=(int){ 576, 480 }; video/x-huffyuv, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; image/jpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-divx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], divxversion=(int)[ 3, 5 ]; video/x-xvid, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-3ivx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-msmpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], msmpegversion=(int)[ 41, 43 ]; video/mpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], mpegversion=(int)1, systemstream=(boolean)false; video/x-h263, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-dv, width=(int)720, height=(int){ 576, 480 }, systemstream=(boolean)false; video/x-huffyuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)-16777216, green_mask=(int)16711680, blue_mask=(int)65280, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0x000000FF, framerate = (double) [ 0, max ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0xFF000000, framerate = (double) [ 0, max ]",
|
||||
"video/x-raw-rgb,\\ bpp=(int)32",
|
||||
/* Test fraction type */
|
||||
"test/gst-fraction, fraction = (fraction) 1/8",
|
||||
"test/gst-fraction, fraction = (fraction) MIN",
|
||||
"test/gst-fraction, fraction = (fraction) MAX",
|
||||
/* Test fraction range */
|
||||
"test/gst-fraction-range, fraction = (fraction) [ 1/3, 1/4 ]",
|
||||
"test/gst-fraction-range, fraction = (fraction) [ MIN, MAX ]",
|
||||
/* Test lists of fractions and fraction ranges */
|
||||
"test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], 1/8 }",
|
||||
"test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], [ 1/8, 2/8 ] }",
|
||||
"ANY",
|
||||
"EMPTY"
|
||||
};
|
||||
|
111
check/gst/gst.c
111
check/gst/gst.c
|
@ -1,111 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gst.c: Unit test for gst.c
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_init)
|
||||
{
|
||||
/* don't segfault with NULL, NULL */
|
||||
gst_init (NULL, NULL);
|
||||
/* allow calling twice. well, actually, thrice. */
|
||||
gst_init (NULL, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_deinit)
|
||||
{
|
||||
gst_init (NULL, NULL);
|
||||
|
||||
gst_deinit ();
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_deinit_sysclock)
|
||||
{
|
||||
GstClock *clock;
|
||||
|
||||
gst_init (NULL, NULL);
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
gst_object_unref (clock);
|
||||
|
||||
gst_deinit ();
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests if we can create an element from a compiled-in plugin */
|
||||
GST_START_TEST (test_new_pipeline)
|
||||
{
|
||||
GstElement *pipeline;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* tests if we can load an element from a plugin */
|
||||
GST_START_TEST (test_new_fakesrc)
|
||||
{
|
||||
GstElement *element;
|
||||
|
||||
element = gst_element_factory_make ("fakesrc", NULL);
|
||||
gst_object_unref (element);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
Suite *
|
||||
gst_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Gst");
|
||||
TCase *tc_chain = tcase_create ("gst tests");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_init);
|
||||
tcase_add_test (tc_chain, test_deinit);
|
||||
tcase_add_test (tc_chain, test_deinit_sysclock);
|
||||
tcase_add_test (tc_chain, test_new_pipeline);
|
||||
tcase_add_test (tc_chain, test_new_fakesrc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_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;
|
||||
}
|
|
@ -1,817 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
|
||||
* Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstbin.c: Unit test for GstBin
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
static void
|
||||
pop_messages (GstBus * bus, int count)
|
||||
{
|
||||
GstMessage *message;
|
||||
|
||||
int i;
|
||||
|
||||
GST_DEBUG ("popping %d messages", count);
|
||||
for (i = 0; i < count; ++i) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
|
||||
|
||||
fail_unless (message && GST_MESSAGE_TYPE (message)
|
||||
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
GST_DEBUG ("popped %d messages", count);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_interface)
|
||||
{
|
||||
GstBin *bin, *bin2;
|
||||
GstElement *filesrc;
|
||||
GstIterator *it;
|
||||
gpointer item;
|
||||
|
||||
bin = GST_BIN (gst_bin_new (NULL));
|
||||
fail_unless (bin != NULL, "Could not create bin");
|
||||
|
||||
filesrc = gst_element_factory_make ("filesrc", NULL);
|
||||
fail_unless (filesrc != NULL, "Could not create filesrc");
|
||||
fail_unless (GST_IS_URI_HANDLER (filesrc), "Filesrc not a URI handler");
|
||||
gst_bin_add (bin, filesrc);
|
||||
|
||||
fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
|
||||
it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
|
||||
fail_unless (it != NULL);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (item == (gpointer) filesrc);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
|
||||
gst_iterator_free (it);
|
||||
|
||||
gst_bin_add_many (bin,
|
||||
gst_element_factory_make ("identity", NULL),
|
||||
gst_element_factory_make ("identity", NULL),
|
||||
gst_element_factory_make ("identity", NULL), NULL);
|
||||
fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
|
||||
it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
|
||||
fail_unless (it != NULL);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (item == (gpointer) filesrc);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
|
||||
gst_iterator_free (it);
|
||||
|
||||
bin2 = bin;
|
||||
bin = GST_BIN (gst_bin_new (NULL));
|
||||
fail_unless (bin != NULL);
|
||||
gst_bin_add_many (bin,
|
||||
gst_element_factory_make ("identity", NULL),
|
||||
gst_element_factory_make ("identity", NULL),
|
||||
GST_ELEMENT (bin2), gst_element_factory_make ("identity", NULL), NULL);
|
||||
fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
|
||||
it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (item == (gpointer) filesrc);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
|
||||
gst_iterator_free (it);
|
||||
|
||||
gst_bin_add (bin, gst_element_factory_make ("filesrc", NULL));
|
||||
gst_bin_add (bin2, gst_element_factory_make ("filesrc", NULL));
|
||||
it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
|
||||
fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
|
||||
gst_iterator_free (it);
|
||||
|
||||
gst_object_unref (bin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_message_state_changed)
|
||||
{
|
||||
GstBin *bin;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
bin = GST_BIN (gst_bin_new (NULL));
|
||||
fail_unless (bin != NULL, "Could not create bin");
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
|
||||
|
||||
bus = g_object_new (gst_bus_get_type (), NULL);
|
||||
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
|
||||
|
||||
/* change state, spawning a message, causing an incref on the bin */
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
|
||||
|
||||
/* get and unref the message, causing a decref on the bin */
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
|
||||
|
||||
fail_unless (message && GST_MESSAGE_TYPE (message)
|
||||
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
|
||||
|
||||
gst_message_unref (message);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
|
||||
|
||||
/* clean up */
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (bin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_message_state_changed_child)
|
||||
{
|
||||
GstBin *bin;
|
||||
GstElement *src;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
bin = GST_BIN (gst_bin_new (NULL));
|
||||
fail_unless (bin != NULL, "Could not create bin");
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
|
||||
|
||||
bus = g_object_new (gst_bus_get_type (), NULL);
|
||||
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
gst_bin_add (bin, src);
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
|
||||
/* change state, spawning two messages:
|
||||
* - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc
|
||||
* - second for bin, causing an incref on the bin */
|
||||
GST_DEBUG ("setting bin to READY");
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
|
||||
|
||||
/* get and unref the message, causing a decref on the src */
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
|
||||
fail_unless (message && GST_MESSAGE_TYPE (message)
|
||||
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
|
||||
|
||||
fail_unless (message->src == GST_OBJECT (src));
|
||||
gst_message_unref (message);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 2);
|
||||
|
||||
/* get and unref message 2, causing a decref on the bin */
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
|
||||
fail_unless (message && GST_MESSAGE_TYPE (message)
|
||||
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
|
||||
|
||||
fail_unless (message->src == GST_OBJECT (bin));
|
||||
gst_message_unref (message);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
|
||||
|
||||
/* clean up */
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (bin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_message_state_changed_children)
|
||||
{
|
||||
GstPipeline *pipeline;
|
||||
GstElement *src, *sink;
|
||||
GstBus *bus;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
|
||||
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
/* need to silence the element as the deep_notify refcounts the
|
||||
* parents while running */
|
||||
g_object_set (G_OBJECT (src), "silent", TRUE, NULL);
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
/* need to silence the element as the deep_notify refcounts the
|
||||
* parents while running */
|
||||
g_object_set (G_OBJECT (sink), "silent", TRUE, NULL);
|
||||
fail_if (sink == NULL, "Could not create fakesink");
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
fail_unless (gst_element_link (src, sink), "could not link src and sink");
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
|
||||
bus = gst_pipeline_get_bus (pipeline);
|
||||
|
||||
/* change state to READY, spawning three messages */
|
||||
GST_DEBUG ("setting pipeline to READY");
|
||||
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
/* each object is referenced by a message */
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2);
|
||||
|
||||
pop_messages (bus, 3);
|
||||
fail_if (gst_bus_have_pending (bus), "unexpected pending messages");
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
/* change state to PAUSED, spawning three messages */
|
||||
GST_DEBUG ("setting pipeline to PAUSED");
|
||||
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
||||
ret =
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), ¤t, &pending,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
fail_unless (current == GST_STATE_PAUSED);
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING);
|
||||
|
||||
/* wait for async thread to settle down */
|
||||
while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 2)
|
||||
THREAD_SWITCH ();
|
||||
|
||||
/* each object is referenced by a message;
|
||||
* base_src is blocked in the push and has an extra refcount.
|
||||
* base_sink_chain has taken a refcount on the sink, and is blocked on
|
||||
* preroll */
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2);
|
||||
|
||||
pop_messages (bus, 3);
|
||||
fail_if ((gst_bus_pop (bus)) != NULL);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
/* change state to PLAYING, spawning three messages */
|
||||
GST_DEBUG ("setting pipeline to PLAYING");
|
||||
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
ret =
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), ¤t, &pending,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
fail_unless (current == GST_STATE_PLAYING);
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING);
|
||||
|
||||
/* each object is referenced by one message
|
||||
* src might have an extra reference if it's still pushing
|
||||
* sink might have an extra reference if it's still blocked on preroll
|
||||
* pipeline posted a new-clock message too. */
|
||||
ASSERT_OBJECT_REFCOUNT_BETWEEN (src, "src", 2, 3);
|
||||
ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 2, 3);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 3);
|
||||
|
||||
pop_messages (bus, 3);
|
||||
fail_if ((gst_bus_pop (bus)) != NULL);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
/* src might have an extra reference if it's still pushing */
|
||||
ASSERT_OBJECT_REFCOUNT_BETWEEN (src, "src", 1, 2);
|
||||
/* sink might have an extra reference if it's still blocked on preroll */
|
||||
ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 2);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
/* go back to READY, spawning six messages */
|
||||
GST_DEBUG ("setting pipeline to READY");
|
||||
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
/* each object is referenced by two messages */
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 3);
|
||||
|
||||
pop_messages (bus, 6);
|
||||
fail_if ((gst_bus_pop (bus)) != NULL);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
/* setting pipeline to NULL flushes the bus automatically */
|
||||
ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
/* clean up */
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_watch_for_state_change)
|
||||
{
|
||||
GstElement *src, *sink, *bin;
|
||||
GstBus *bus;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
bin = gst_element_factory_make ("bin", NULL);
|
||||
fail_unless (bin != NULL, "Could not create bin");
|
||||
|
||||
bus = g_object_new (gst_bus_get_type (), NULL);
|
||||
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink == NULL, "Could not create fakesink");
|
||||
|
||||
gst_bin_add (GST_BIN (bin), sink);
|
||||
gst_bin_add (GST_BIN (bin), src);
|
||||
|
||||
fail_unless (gst_element_link (src, sink), "could not link src and sink");
|
||||
|
||||
/* change state, spawning two times three messages */
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
||||
ret =
|
||||
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
pop_messages (bus, 6);
|
||||
|
||||
fail_unless (gst_bus_have_pending (bus) == FALSE,
|
||||
"Unexpected messages on bus");
|
||||
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
pop_messages (bus, 3);
|
||||
|
||||
/* this one might return either SUCCESS or ASYNC, likely SUCCESS */
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
|
||||
gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
pop_messages (bus, 3);
|
||||
|
||||
fail_unless (gst_bus_have_pending (bus) == FALSE,
|
||||
"Unexpected messages on bus");
|
||||
|
||||
/* setting bin to NULL flushes the bus automatically */
|
||||
ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
/* clean up */
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (bin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* adding an element with linked pads to a bin unlinks the
|
||||
* pads */
|
||||
GST_START_TEST (test_add_linked)
|
||||
{
|
||||
GstElement *src, *sink;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstElement *pipeline;
|
||||
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink == NULL, "Could not create fakesink");
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
fail_unless (srcpad != NULL);
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
fail_unless (sinkpad != NULL);
|
||||
|
||||
fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
|
||||
|
||||
/* pads are linked now */
|
||||
fail_unless (gst_pad_is_linked (srcpad));
|
||||
fail_unless (gst_pad_is_linked (sinkpad));
|
||||
|
||||
/* adding element to bin voids hierarchy so pads are unlinked */
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
|
||||
/* check if pads really are unlinked */
|
||||
fail_unless (!gst_pad_is_linked (srcpad));
|
||||
fail_unless (!gst_pad_is_linked (sinkpad));
|
||||
|
||||
/* cannot link pads in wrong hierarchy */
|
||||
fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_WRONG_HIERARCHY);
|
||||
|
||||
/* adding other element to bin as well */
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
/* now we can link again */
|
||||
fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
|
||||
|
||||
/* check if pads really are linked */
|
||||
fail_unless (gst_pad_is_linked (srcpad));
|
||||
fail_unless (gst_pad_is_linked (sinkpad));
|
||||
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* g_print ("%10s: %4d => %4d\n", GST_OBJECT_NAME (msg->src), old, new); */
|
||||
|
||||
#define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \
|
||||
{ \
|
||||
GstMessage *msg; \
|
||||
GstState old = 0, new = 0, pending = 0; \
|
||||
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \
|
||||
fail_if (msg == NULL, "No state change message within 1 second (#" \
|
||||
G_STRINGIFY (num) ")"); \
|
||||
gst_message_parse_state_changed (msg, &old, &new, &pending); \
|
||||
fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \
|
||||
" should have changed state next (#" G_STRINGIFY (num) ")"); \
|
||||
fail_if (old != old_state || new != new_state, "state change is not " \
|
||||
G_STRINGIFY (old_state) " => " G_STRINGIFY (new_state)); \
|
||||
gst_message_unref (msg); \
|
||||
}
|
||||
|
||||
GST_START_TEST (test_children_state_change_order_flagged_sink)
|
||||
{
|
||||
GstElement *src, *identity, *sink, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstBus *bus;
|
||||
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
fail_unless (bus != NULL, "Pipeline has no bus?!");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
|
||||
identity = gst_element_factory_make ("identity", NULL);
|
||||
fail_if (identity == NULL, "Could not create identity");
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink == NULL, "Could not create fakesink");
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
|
||||
|
||||
fail_unless (gst_element_link (src, identity) == TRUE);
|
||||
fail_unless (gst_element_link (identity, sink) == TRUE);
|
||||
|
||||
/* (1) Test state change with fakesink being a regular sink */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_if (ret != GST_STATE_CHANGE_ASYNC,
|
||||
"State change to PLAYING did not return ASYNC");
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
|
||||
fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
|
||||
fail_if (pending != GST_STATE_VOID_PENDING, "State change to PLAYING failed");
|
||||
|
||||
/* NULL => READY */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_NULL, GST_STATE_READY, 101);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 102);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 103);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 104);
|
||||
|
||||
/* READY => PAUSED */
|
||||
/* because of pre-rolling, sink will return ASYNC on state
|
||||
* change and change state later when it has a buffer */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
105);
|
||||
#if 0
|
||||
/* From here on, all bets are off. Usually the source changes state next,
|
||||
* but it might just as well be that the first buffer produced by the
|
||||
* source reaches the sink before the source has finished its state change,
|
||||
* in which case the sink will commit its new state before the source ... */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_READY, GST_STATE_PAUSED, 106);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_READY, GST_STATE_PAUSED, 107);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
108);
|
||||
|
||||
/* PAUSED => PLAYING */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_PAUSED, GST_STATE_PLAYING, 109);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_PAUSED, GST_STATE_PLAYING,
|
||||
110);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_PAUSED, GST_STATE_PLAYING, 111);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_PAUSED, GST_STATE_PLAYING,
|
||||
112);
|
||||
#else
|
||||
pop_messages (bus, 3); /* pop remaining ready => paused messages off the bus */
|
||||
pop_messages (bus, 4); /* pop paused => playing messages off the bus */
|
||||
#endif
|
||||
|
||||
/* don't set to NULL that will set the bus flushing and kill our messages */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
|
||||
ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
|
||||
|
||||
/* TODO: do we need to check downwards state change order as well? */
|
||||
pop_messages (bus, 4); /* pop playing => paused messages off the bus */
|
||||
pop_messages (bus, 4); /* pop paused => ready messages off the bus */
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_children_state_change_order_semi_sink)
|
||||
{
|
||||
GstElement *src, *identity, *sink, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstBus *bus;
|
||||
|
||||
/* (2) Now again, but check other code path where we don't have
|
||||
* a proper sink correctly flagged as such, but a 'semi-sink' */
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
fail_unless (bus != NULL, "Pipeline has no bus?!");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
|
||||
identity = gst_element_factory_make ("identity", NULL);
|
||||
fail_if (identity == NULL, "Could not create identity");
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink == NULL, "Could not create fakesink");
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
|
||||
|
||||
fail_unless (gst_element_link (src, identity) == TRUE);
|
||||
fail_unless (gst_element_link (identity, sink) == TRUE);
|
||||
|
||||
/* this is not very nice but should work just fine in this case. */
|
||||
GST_OBJECT_FLAG_UNSET (sink, GST_ELEMENT_IS_SINK); /* <======== */
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_if (ret != GST_STATE_CHANGE_ASYNC, "State change to PLAYING not ASYNC");
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to PLAYING failed");
|
||||
fail_if (current != GST_STATE_PLAYING, "State change to PLAYING failed");
|
||||
fail_if (pending != GST_STATE_VOID_PENDING, "State change to PLAYING failed");
|
||||
|
||||
/* NULL => READY */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_NULL, GST_STATE_READY, 201);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 202);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 203);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 204);
|
||||
|
||||
/* READY => PAUSED */
|
||||
/* because of pre-rolling, sink will return ASYNC on state
|
||||
* change and change state later when it has a buffer */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
205);
|
||||
#if 0
|
||||
/* From here on, all bets are off. Usually the source changes state next,
|
||||
* but it might just as well be that the first buffer produced by the
|
||||
* source reaches the sink before the source has finished its state change,
|
||||
* in which case the sink will commit its new state before the source ... */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_READY, GST_STATE_PAUSED, 206);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_READY, GST_STATE_PAUSED, 207);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
208);
|
||||
|
||||
/* PAUSED => PLAYING */
|
||||
ASSERT_STATE_CHANGE_MSG (bus, sink, GST_STATE_PAUSED, GST_STATE_PLAYING, 209);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_PAUSED, GST_STATE_PLAYING,
|
||||
210);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_PAUSED, GST_STATE_PLAYING, 211);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_PAUSED, GST_STATE_PLAYING,
|
||||
212);
|
||||
#else
|
||||
pop_messages (bus, 3); /* pop remaining ready => paused messages off the bus */
|
||||
pop_messages (bus, 4); /* pop paused => playing messages off the bus */
|
||||
#endif
|
||||
|
||||
/* don't set to NULL that will set the bus flushing and kill our messages */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
|
||||
|
||||
/* TODO: do we need to check downwards state change order as well? */
|
||||
pop_messages (bus, 4); /* pop playing => paused messages off the bus */
|
||||
pop_messages (bus, 4); /* pop paused => ready messages off the bus */
|
||||
|
||||
while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 1)
|
||||
THREAD_SWITCH ();
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_children_state_change_order_two_sink)
|
||||
{
|
||||
GstElement *src, *tee, *identity, *sink1, *sink2, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstBus *bus;
|
||||
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
fail_unless (bus != NULL, "Pipeline has no bus?!");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_if (src == NULL, "Could not create fakesrc");
|
||||
|
||||
tee = gst_element_factory_make ("tee", NULL);
|
||||
fail_if (tee == NULL, "Could not create tee");
|
||||
|
||||
identity = gst_element_factory_make ("identity", NULL);
|
||||
fail_if (identity == NULL, "Could not create identity");
|
||||
|
||||
sink1 = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink1 == NULL, "Could not create fakesink1");
|
||||
|
||||
sink2 = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_if (sink2 == NULL, "Could not create fakesink2");
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, tee, identity, sink1, sink2, NULL);
|
||||
|
||||
fail_unless (gst_element_link (src, tee) == TRUE);
|
||||
fail_unless (gst_element_link (tee, identity) == TRUE);
|
||||
fail_unless (gst_element_link (identity, sink1) == TRUE);
|
||||
fail_unless (gst_element_link (tee, sink2) == TRUE);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to READY failed");
|
||||
|
||||
/* NULL => READY */
|
||||
{
|
||||
GstMessage *msg;
|
||||
GstState old = 0, new = 0, pending = 0;
|
||||
GstObject *first, *second;
|
||||
|
||||
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
|
||||
fail_if (msg == NULL, "No state change message within 1 second (#201)");
|
||||
|
||||
gst_message_parse_state_changed (msg, &old, &new, &pending);
|
||||
first = gst_object_ref (msg->src);
|
||||
|
||||
fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2),
|
||||
"sink1 or sink2 should have changed state next #(202)");
|
||||
gst_message_unref (msg);
|
||||
|
||||
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
|
||||
fail_if (msg == NULL, "No state change message within 1 second (#201)");
|
||||
|
||||
gst_message_parse_state_changed (msg, &old, &new, &pending);
|
||||
second = gst_object_ref (msg->src);
|
||||
|
||||
fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2),
|
||||
"sink1 or sink2 should have changed state next #(202)");
|
||||
gst_message_unref (msg);
|
||||
|
||||
fail_if (second == first, "got state change from same object");
|
||||
|
||||
gst_object_unref (first);
|
||||
gst_object_unref (second);
|
||||
}
|
||||
ASSERT_STATE_CHANGE_MSG (bus, identity, GST_STATE_NULL, GST_STATE_READY, 203);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, tee, GST_STATE_NULL, GST_STATE_READY, 204);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, src, GST_STATE_NULL, GST_STATE_READY, 205);
|
||||
ASSERT_STATE_CHANGE_MSG (bus, pipeline, GST_STATE_NULL, GST_STATE_READY, 206);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (tee, "tee", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (identity, "identity", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink1, "sink1", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "State change to NULL failed");
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (tee, "tee", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (identity, "identity", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink1, "sink1", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_bin_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstBin");
|
||||
TCase *tc_chain = tcase_create ("bin tests");
|
||||
|
||||
tcase_set_timeout (tc_chain, 0);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_interface);
|
||||
tcase_add_test (tc_chain, test_children_state_change_order_flagged_sink);
|
||||
tcase_add_test (tc_chain, test_children_state_change_order_semi_sink);
|
||||
tcase_add_test (tc_chain, test_children_state_change_order_two_sink);
|
||||
tcase_add_test (tc_chain, test_message_state_changed);
|
||||
tcase_add_test (tc_chain, test_message_state_changed_child);
|
||||
tcase_add_test (tc_chain, test_message_state_changed_children);
|
||||
tcase_add_test (tc_chain, test_watch_for_state_change);
|
||||
tcase_add_test (tc_chain, test_add_linked);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_bin_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;
|
||||
}
|
|
@ -1,302 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for GstBuffer
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_caps)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstCaps *caps, *caps2;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
caps = gst_caps_from_string ("audio/x-raw-int");
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
|
||||
|
||||
gst_buffer_set_caps (buffer, caps);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
|
||||
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == caps);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
|
||||
|
||||
caps2 = gst_caps_from_string ("audio/x-raw-float");
|
||||
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
|
||||
|
||||
gst_buffer_set_caps (buffer, caps2);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
|
||||
|
||||
gst_buffer_set_caps (buffer, NULL);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
|
||||
|
||||
/* clean up, with caps2 still set as caps */
|
||||
gst_buffer_set_caps (buffer, caps2);
|
||||
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
|
||||
gst_buffer_unref (buffer);
|
||||
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
|
||||
gst_caps_unref (caps);
|
||||
gst_caps_unref (caps2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_subbuffer)
|
||||
{
|
||||
GstBuffer *buffer, *sub;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
memset (GST_BUFFER_DATA (buffer), 0, 4);
|
||||
|
||||
sub = gst_buffer_create_sub (buffer, 1, 2);
|
||||
fail_if (sub == NULL, "create_sub of buffer returned NULL");
|
||||
fail_unless (GST_BUFFER_SIZE (sub) == 2, "subbuffer has wrong size");
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 1, GST_BUFFER_DATA (sub),
|
||||
2) == 0, "subbuffer contains the wrong data");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 2);
|
||||
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
|
||||
|
||||
/* clean up */
|
||||
gst_buffer_unref (sub);
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_is_span_fast)
|
||||
{
|
||||
GstBuffer *buffer, *sub1, *sub2;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
sub1 = gst_buffer_create_sub (buffer, 0, 2);
|
||||
fail_if (sub1 == NULL, "create_sub of buffer returned NULL");
|
||||
|
||||
sub2 = gst_buffer_create_sub (buffer, 2, 2);
|
||||
fail_if (sub2 == NULL, "create_sub of buffer returned NULL");
|
||||
|
||||
fail_if (gst_buffer_is_span_fast (buffer, sub2) == TRUE,
|
||||
"a parent buffer can't be span_fasted");
|
||||
|
||||
fail_if (gst_buffer_is_span_fast (sub1, buffer) == TRUE,
|
||||
"a parent buffer can't be span_fasted");
|
||||
|
||||
fail_if (gst_buffer_is_span_fast (sub1, sub2) == FALSE,
|
||||
"two subbuffers next to each other should be span_fast");
|
||||
|
||||
/* clean up */
|
||||
gst_buffer_unref (sub1);
|
||||
gst_buffer_unref (sub2);
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_span)
|
||||
{
|
||||
GstBuffer *buffer, *sub1, *sub2, *span;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
memcpy (GST_BUFFER_DATA (buffer), "data", 4);
|
||||
|
||||
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, NULL, 2));
|
||||
ASSERT_CRITICAL (gst_buffer_span (buffer, 1, NULL, 2));
|
||||
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, buffer, 2));
|
||||
ASSERT_CRITICAL (gst_buffer_span (buffer, 0, buffer, 10));
|
||||
|
||||
sub1 = gst_buffer_create_sub (buffer, 0, 2);
|
||||
fail_if (sub1 == NULL, "create_sub of buffer returned NULL");
|
||||
|
||||
sub2 = gst_buffer_create_sub (buffer, 2, 2);
|
||||
fail_if (sub2 == NULL, "create_sub of buffer returned NULL");
|
||||
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
|
||||
/* span will create a new subbuffer from the parent */
|
||||
span = gst_buffer_span (sub1, 0, sub2, 4);
|
||||
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (span), "data", 4) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
|
||||
/* span from non-contiguous buffers will create new buffers */
|
||||
span = gst_buffer_span (sub2, 0, sub1, 4);
|
||||
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (span), "tada", 4) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
|
||||
/* span with different sizes */
|
||||
span = gst_buffer_span (sub1, 1, sub2, 3);
|
||||
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (span), "ata", 3) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
|
||||
span = gst_buffer_span (sub2, 0, sub1, 3);
|
||||
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (span), "tad", 3) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
|
||||
/* clean up */
|
||||
gst_buffer_unref (sub1);
|
||||
gst_buffer_unref (sub2);
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
static const char ro_memory[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
static GstBuffer *
|
||||
create_read_only_buffer (void)
|
||||
{
|
||||
GstBuffer *buf;
|
||||
|
||||
buf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER);
|
||||
|
||||
/* assign some read-only data to the new buffer */
|
||||
GST_BUFFER_DATA (buf) = (guint8 *) ro_memory;
|
||||
GST_BUFFER_SIZE (buf) = sizeof (ro_memory);
|
||||
|
||||
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_make_writable)
|
||||
{
|
||||
GstBuffer *buf, *buf2;
|
||||
|
||||
/* create read-only buffer and make it writable */
|
||||
buf = create_read_only_buffer ();
|
||||
fail_unless (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY),
|
||||
"read-only buffer should have read-only flag set");
|
||||
buf = gst_buffer_make_writable (buf);
|
||||
fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY),
|
||||
"writable buffer must not have read-only flag set");
|
||||
GST_BUFFER_DATA (buf)[4] = 'a';
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
/* alloc'ed buffer with refcount 1 should be writable */
|
||||
buf = gst_buffer_new_and_alloc (32);
|
||||
fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY),
|
||||
"_new_and_alloc'ed buffer must not have read-only flag set");
|
||||
buf2 = gst_buffer_make_writable (buf);
|
||||
fail_unless (buf == buf2,
|
||||
"_make_writable() should have returned same buffer");
|
||||
gst_buffer_unref (buf2);
|
||||
|
||||
/* alloc'ed buffer with refcount >1 should be copied */
|
||||
buf = gst_buffer_new_and_alloc (32);
|
||||
fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY),
|
||||
"_new_and_alloc'ed buffer must not have read-only flag set");
|
||||
gst_buffer_ref (buf);
|
||||
buf2 = gst_buffer_make_writable (buf);
|
||||
fail_unless (buf != buf2, "_make_writable() should have returned a copy!");
|
||||
gst_buffer_unref (buf2);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_subbuffer_make_writable)
|
||||
{
|
||||
GstBuffer *buf, *sub_buf;
|
||||
|
||||
/* create sub-buffer of read-only buffer and make it writable */
|
||||
buf = create_read_only_buffer ();
|
||||
fail_unless (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY),
|
||||
"read-only buffer should have read-only flag set");
|
||||
|
||||
sub_buf = gst_buffer_create_sub (buf, 0, 8);
|
||||
fail_unless (GST_BUFFER_FLAG_IS_SET (sub_buf, GST_BUFFER_FLAG_READONLY),
|
||||
"sub-buffer of read-only buffer should have read-only flag set");
|
||||
|
||||
sub_buf = gst_buffer_make_writable (sub_buf);
|
||||
fail_unless (!GST_BUFFER_FLAG_IS_SET (sub_buf, GST_BUFFER_FLAG_READONLY),
|
||||
"writable buffer must not have read-only flag set");
|
||||
GST_BUFFER_DATA (sub_buf)[4] = 'a';
|
||||
gst_buffer_unref (sub_buf);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_test_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstBuffer");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_caps);
|
||||
tcase_add_test (tc_chain, test_subbuffer);
|
||||
tcase_add_test (tc_chain, test_subbuffer_make_writable);
|
||||
tcase_add_test (tc_chain, test_make_writable);
|
||||
tcase_add_test (tc_chain, test_is_span_fast);
|
||||
tcase_add_test (tc_chain, test_span);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_test_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;
|
||||
}
|
|
@ -1,256 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
*
|
||||
* gstbus.c: Unit test for the message bus
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
static GstBus *test_bus = NULL;
|
||||
static GMainLoop *main_loop;
|
||||
|
||||
#define NUM_MESSAGES 1000
|
||||
#define NUM_THREADS 10
|
||||
|
||||
static gpointer
|
||||
pound_bus_with_messages (gpointer data)
|
||||
{
|
||||
gint thread_id = GPOINTER_TO_INT (data);
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < NUM_MESSAGES; i++) {
|
||||
GstMessage *m;
|
||||
GstStructure *s;
|
||||
|
||||
s = gst_structure_new ("test_message",
|
||||
"thread_id", G_TYPE_INT, thread_id, "msg_id", G_TYPE_INT, i, NULL);
|
||||
m = gst_message_new_application (NULL, s);
|
||||
gst_bus_post (test_bus, m);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
pull_messages ()
|
||||
{
|
||||
GstMessage *m;
|
||||
const GstStructure *s;
|
||||
guint message_ids[NUM_THREADS];
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < NUM_THREADS; i++)
|
||||
message_ids[i] = 0;
|
||||
|
||||
while (1) {
|
||||
gint _t, _i;
|
||||
|
||||
m = gst_bus_pop (test_bus);
|
||||
if (!m)
|
||||
break;
|
||||
g_return_if_fail (GST_MESSAGE_TYPE (m) == GST_MESSAGE_APPLICATION);
|
||||
|
||||
s = gst_message_get_structure (m);
|
||||
if (!gst_structure_get_int (s, "thread_id", &_t))
|
||||
g_critical ("Invalid message");
|
||||
if (!gst_structure_get_int (s, "msg_id", &_i))
|
||||
g_critical ("Invalid message");
|
||||
|
||||
g_return_if_fail (_t < NUM_THREADS);
|
||||
g_return_if_fail (_i == message_ids[_t]++);
|
||||
|
||||
gst_message_unref (m);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_THREADS; i++)
|
||||
g_return_if_fail (message_ids[i] == NUM_MESSAGES);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_hammer_bus)
|
||||
{
|
||||
GThread *threads[NUM_THREADS];
|
||||
gint i;
|
||||
|
||||
test_bus = gst_bus_new ();
|
||||
|
||||
for (i = 0; i < NUM_THREADS; i++)
|
||||
threads[i] = g_thread_create (pound_bus_with_messages, GINT_TO_POINTER (i),
|
||||
TRUE, NULL);
|
||||
|
||||
for (i = 0; i < NUM_THREADS; i++)
|
||||
g_thread_join (threads[i]);
|
||||
|
||||
pull_messages ();
|
||||
|
||||
gst_object_unref ((GstObject *) test_bus);
|
||||
}
|
||||
GST_END_TEST static gboolean
|
||||
message_func_eos (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
const GstStructure *s;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS, FALSE);
|
||||
|
||||
GST_DEBUG ("got EOS message");
|
||||
|
||||
s = gst_message_get_structure (message);
|
||||
if (!gst_structure_get_int (s, "msg_id", &i))
|
||||
g_critical ("Invalid message");
|
||||
|
||||
return i != 9;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
message_func_app (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
const GstStructure *s;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_APPLICATION,
|
||||
FALSE);
|
||||
|
||||
GST_DEBUG ("got APP message");
|
||||
|
||||
s = gst_message_get_structure (message);
|
||||
if (!gst_structure_get_int (s, "msg_id", &i))
|
||||
g_critical ("Invalid message");
|
||||
|
||||
return i != 9;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
send_messages (gpointer data)
|
||||
{
|
||||
GstMessage *m;
|
||||
GstStructure *s;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
s = gst_structure_new ("test_message", "msg_id", G_TYPE_INT, i, NULL);
|
||||
m = gst_message_new_application (NULL, s);
|
||||
gst_bus_post (test_bus, m);
|
||||
s = gst_structure_new ("test_message", "msg_id", G_TYPE_INT, i, NULL);
|
||||
m = gst_message_new_custom (GST_MESSAGE_EOS, NULL, s);
|
||||
gst_bus_post (test_bus, m);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* test if adding a signal watch for different message types calls the
|
||||
* respective callbacks. */
|
||||
GST_START_TEST (test_watch)
|
||||
{
|
||||
guint id;
|
||||
|
||||
test_bus = gst_bus_new ();
|
||||
|
||||
main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
id = gst_bus_add_watch (test_bus, gst_bus_async_signal_func, NULL);
|
||||
g_signal_connect (test_bus, "message::eos", (GCallback) message_func_eos,
|
||||
NULL);
|
||||
g_signal_connect (test_bus, "message::application",
|
||||
(GCallback) message_func_app, NULL);
|
||||
|
||||
g_idle_add ((GSourceFunc) send_messages, NULL);
|
||||
while (g_main_context_pending (NULL))
|
||||
g_main_context_iteration (NULL, FALSE);
|
||||
|
||||
g_source_remove (id);
|
||||
g_main_loop_unref (main_loop);
|
||||
|
||||
gst_object_unref ((GstObject *) test_bus);
|
||||
}
|
||||
GST_END_TEST static gint messages_seen = 0;
|
||||
|
||||
static void
|
||||
message_func (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_APPLICATION);
|
||||
|
||||
messages_seen++;
|
||||
}
|
||||
|
||||
static void
|
||||
send_10_app_messages (void)
|
||||
{
|
||||
GstMessage *m;
|
||||
GstStructure *s;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
s = gst_structure_new ("test_message", "msg_id", G_TYPE_INT, i, NULL);
|
||||
m = gst_message_new_application (NULL, s);
|
||||
gst_bus_post (test_bus, m);
|
||||
}
|
||||
}
|
||||
|
||||
/* test that you get the same messages from a poll as from signal watches. */
|
||||
GST_START_TEST (test_watch_with_poll)
|
||||
{
|
||||
guint i;
|
||||
|
||||
test_bus = gst_bus_new ();
|
||||
|
||||
gst_bus_add_signal_watch (test_bus);
|
||||
g_signal_connect (test_bus, "message", (GCallback) message_func, NULL);
|
||||
|
||||
send_10_app_messages ();
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
gst_message_unref (gst_bus_poll (test_bus, GST_MESSAGE_APPLICATION,
|
||||
GST_CLOCK_TIME_NONE));
|
||||
|
||||
fail_if (gst_bus_have_pending (test_bus), "unexpected messages on bus");
|
||||
fail_unless (messages_seen == 10, "signal handler didn't get 10 messages");
|
||||
|
||||
gst_bus_remove_signal_watch (test_bus);
|
||||
|
||||
gst_object_unref (test_bus);
|
||||
}
|
||||
GST_END_TEST Suite * gstbus_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstBus");
|
||||
TCase *tc_chain = tcase_create ("stresstest");
|
||||
|
||||
tcase_set_timeout (tc_chain, 20);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_hammer_bus);
|
||||
tcase_add_test (tc_chain, test_watch);
|
||||
tcase_add_test (tc_chain, test_watch_with_poll);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gstbus_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;
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstcaps.c: Unit test for GstCaps
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
#include "capslist.h"
|
||||
|
||||
GST_START_TEST (test_from_string)
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstCaps *caps2;
|
||||
gchar *to_str;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
|
||||
caps = gst_caps_from_string (caps_list[i]);
|
||||
fail_if (caps == NULL,
|
||||
"Could not create caps from string %s\n", caps_list[i]);
|
||||
to_str = gst_caps_to_string (caps);
|
||||
fail_if (to_str == NULL,
|
||||
"Could not convert caps back to string %s\n", caps_list[i]);
|
||||
caps2 = gst_caps_from_string (caps_list[i]);
|
||||
fail_if (caps2 == NULL, "Could not create caps from string %s\n", to_str);
|
||||
|
||||
fail_unless (gst_caps_is_equal (caps, caps2));
|
||||
|
||||
g_free (caps);
|
||||
g_free (caps2);
|
||||
g_free (to_str);
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_buffer)
|
||||
{
|
||||
GstCaps *c1;
|
||||
GstBuffer *buffer;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (1000);
|
||||
c1 = gst_caps_new_simple ("audio/x-raw-int",
|
||||
"buffer", GST_TYPE_BUFFER, buffer, NULL);
|
||||
|
||||
GST_DEBUG ("caps: %" GST_PTR_FORMAT, c1);
|
||||
|
||||
gst_buffer_set_caps (buffer, c1); /* gives away our c1 ref */
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_double_append)
|
||||
{
|
||||
GstStructure *s1;
|
||||
GstCaps *c1;
|
||||
|
||||
c1 = gst_caps_new_any ();
|
||||
s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
|
||||
gst_caps_append_structure (c1, s1);
|
||||
ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
|
||||
|
||||
gst_caps_unref (c1);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_mutability)
|
||||
{
|
||||
GstStructure *s1;
|
||||
GstCaps *c1;
|
||||
gint ret;
|
||||
|
||||
c1 = gst_caps_new_any ();
|
||||
s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
|
||||
gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
|
||||
gst_caps_append_structure (c1, s1);
|
||||
gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
|
||||
gst_caps_ref (c1);
|
||||
ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
|
||||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 22500);
|
||||
ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
|
||||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 22500);
|
||||
gst_caps_unref (c1);
|
||||
gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
|
||||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 11250);
|
||||
gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
|
||||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 1);
|
||||
gst_caps_unref (c1);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_static_caps)
|
||||
{
|
||||
GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw-int,rate=44100");
|
||||
GstCaps *caps1;
|
||||
GstCaps *caps2;
|
||||
|
||||
/* caps creation */
|
||||
caps1 = gst_static_caps_get (&scaps);
|
||||
fail_unless (caps1 != NULL);
|
||||
/* 1 refcount core, one from us */
|
||||
fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
|
||||
|
||||
/* caps should be the same */
|
||||
caps2 = gst_static_caps_get (&scaps);
|
||||
fail_unless (caps2 != NULL);
|
||||
/* 1 refcount core, two from us */
|
||||
fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
|
||||
/* caps must be equal */
|
||||
fail_unless (caps1 == caps2);
|
||||
|
||||
gst_caps_unref (caps1);
|
||||
gst_caps_unref (caps2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static const gchar non_simple_caps_string[] =
|
||||
"video/x-raw-yuv, format=(fourcc)I420, framerate=(fraction)[ 1/100, 100 ], "
|
||||
"width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
|
||||
"format=(fourcc)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
|
||||
"height=(int)[ 16, 4096 ]; video/x-raw-rgb, bpp=(int)8, depth=(int)8, "
|
||||
"endianness=(int)1234, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
|
||||
"height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
|
||||
"format=(fourcc){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
|
||||
"height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
|
||||
|
||||
static gboolean
|
||||
check_fourcc_list (const GValue * format_value)
|
||||
{
|
||||
const GValue *fourcc_value;
|
||||
gboolean got_yv12 = FALSE;
|
||||
gboolean got_i420 = FALSE;
|
||||
gboolean got_yuy2 = FALSE;
|
||||
guint32 fourcc;
|
||||
|
||||
fourcc_value = gst_value_list_get_value (format_value, 0);
|
||||
fail_unless (fourcc_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
|
||||
fourcc = gst_value_get_fourcc (fourcc_value);
|
||||
fail_unless (fourcc != 0);
|
||||
got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
|
||||
got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
|
||||
got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
|
||||
|
||||
fourcc_value = gst_value_list_get_value (format_value, 1);
|
||||
fail_unless (fourcc_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
|
||||
fourcc = gst_value_get_fourcc (fourcc_value);
|
||||
fail_unless (fourcc != 0);
|
||||
got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
|
||||
got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
|
||||
got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
|
||||
|
||||
fourcc_value = gst_value_list_get_value (format_value, 2);
|
||||
fail_unless (fourcc_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
|
||||
fourcc = gst_value_get_fourcc (fourcc_value);
|
||||
fail_unless (fourcc != 0);
|
||||
got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
|
||||
got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
|
||||
got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
|
||||
|
||||
return (got_i420 && got_yuy2 && got_yv12);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_simplify)
|
||||
{
|
||||
GstStructure *s1, *s2;
|
||||
gboolean did_simplify;
|
||||
GstCaps *caps;
|
||||
|
||||
caps = gst_caps_from_string (non_simple_caps_string);
|
||||
fail_unless (caps != NULL,
|
||||
"gst_caps_from_string (non_simple_caps_string) failed");
|
||||
|
||||
did_simplify = gst_caps_do_simplify (caps);
|
||||
fail_unless (did_simplify == TRUE,
|
||||
"gst_caps_do_simplify() should have worked");
|
||||
|
||||
/* check simplified caps, should be:
|
||||
*
|
||||
* video/x-raw-rgb, bpp=(int)8, depth=(int)8, endianness=(int)1234,
|
||||
* framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ],
|
||||
* height=(int)[ 16, 4096 ];
|
||||
* video/x-raw-yuv, format=(fourcc){ YV12, YUY2, I420 },
|
||||
* width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
|
||||
* framerate=(fraction)[ 1/100, 100 ]
|
||||
*/
|
||||
fail_unless (gst_caps_get_size (caps) == 2);
|
||||
s1 = gst_caps_get_structure (caps, 0);
|
||||
s2 = gst_caps_get_structure (caps, 1);
|
||||
fail_unless (s1 != NULL);
|
||||
fail_unless (s2 != NULL);
|
||||
|
||||
if (!gst_structure_has_name (s1, "video/x-raw-rgb")) {
|
||||
GstStructure *tmp;
|
||||
|
||||
tmp = s1;
|
||||
s1 = s2;
|
||||
s2 = tmp;
|
||||
}
|
||||
|
||||
fail_unless (gst_structure_has_name (s1, "video/x-raw-rgb"));
|
||||
{
|
||||
const GValue *framerate_value;
|
||||
const GValue *width_value;
|
||||
const GValue *height_value;
|
||||
const GValue *val_fps;
|
||||
GValue test_fps = { 0, };
|
||||
gint bpp, depth, endianness;
|
||||
gint min_width, max_width;
|
||||
gint min_height, max_height;
|
||||
|
||||
fail_unless (gst_structure_get_int (s1, "bpp", &bpp));
|
||||
fail_unless (bpp == 8);
|
||||
|
||||
fail_unless (gst_structure_get_int (s1, "depth", &depth));
|
||||
fail_unless (depth == 8);
|
||||
|
||||
fail_unless (gst_structure_get_int (s1, "endianness", &endianness));
|
||||
fail_unless (endianness == G_LITTLE_ENDIAN);
|
||||
|
||||
g_value_init (&test_fps, GST_TYPE_FRACTION);
|
||||
framerate_value = gst_structure_get_value (s1, "framerate");
|
||||
fail_unless (framerate_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
|
||||
|
||||
val_fps = gst_value_get_fraction_range_min (framerate_value);
|
||||
gst_value_set_fraction (&test_fps, 1, 100);
|
||||
fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
|
||||
|
||||
val_fps = gst_value_get_fraction_range_max (framerate_value);
|
||||
gst_value_set_fraction (&test_fps, 100, 1);
|
||||
fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
|
||||
|
||||
g_value_unset (&test_fps);
|
||||
|
||||
width_value = gst_structure_get_value (s1, "width");
|
||||
fail_unless (width_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
|
||||
min_width = gst_value_get_int_range_min (width_value);
|
||||
max_width = gst_value_get_int_range_max (width_value);
|
||||
fail_unless (min_width == 16 && max_width == 4096);
|
||||
|
||||
height_value = gst_structure_get_value (s1, "height");
|
||||
fail_unless (height_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
|
||||
min_height = gst_value_get_int_range_min (height_value);
|
||||
max_height = gst_value_get_int_range_max (height_value);
|
||||
fail_unless (min_height == 16 && max_height == 4096);
|
||||
}
|
||||
|
||||
fail_unless (gst_structure_has_name (s2, "video/x-raw-yuv"));
|
||||
{
|
||||
const GValue *framerate_value;
|
||||
const GValue *format_value;
|
||||
const GValue *width_value;
|
||||
const GValue *height_value;
|
||||
const GValue *val_fps;
|
||||
GValue test_fps = { 0, };
|
||||
gint min_width, max_width;
|
||||
gint min_height, max_height;
|
||||
|
||||
format_value = gst_structure_get_value (s2, "format");
|
||||
fail_unless (format_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_LIST (format_value));
|
||||
fail_unless (gst_value_list_get_size (format_value) == 3);
|
||||
fail_unless (check_fourcc_list (format_value) == TRUE);
|
||||
|
||||
g_value_init (&test_fps, GST_TYPE_FRACTION);
|
||||
framerate_value = gst_structure_get_value (s2, "framerate");
|
||||
fail_unless (framerate_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
|
||||
|
||||
val_fps = gst_value_get_fraction_range_min (framerate_value);
|
||||
gst_value_set_fraction (&test_fps, 1, 100);
|
||||
fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
|
||||
|
||||
val_fps = gst_value_get_fraction_range_max (framerate_value);
|
||||
gst_value_set_fraction (&test_fps, 100, 1);
|
||||
fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
|
||||
|
||||
g_value_unset (&test_fps);
|
||||
|
||||
width_value = gst_structure_get_value (s2, "width");
|
||||
fail_unless (width_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
|
||||
min_width = gst_value_get_int_range_min (width_value);
|
||||
max_width = gst_value_get_int_range_max (width_value);
|
||||
fail_unless (min_width == 16 && max_width == 4096);
|
||||
|
||||
height_value = gst_structure_get_value (s2, "height");
|
||||
fail_unless (height_value != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
|
||||
min_height = gst_value_get_int_range_min (height_value);
|
||||
max_height = gst_value_get_int_range_max (height_value);
|
||||
fail_unless (min_height == 16 && max_height == 4096);
|
||||
}
|
||||
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_caps_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstCaps");
|
||||
TCase *tc_chain = tcase_create ("mutability");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string);
|
||||
tcase_add_test (tc_chain, test_double_append);
|
||||
tcase_add_test (tc_chain, test_mutability);
|
||||
tcase_add_test (tc_chain, test_buffer);
|
||||
tcase_add_test (tc_chain, test_static_caps);
|
||||
tcase_add_test (tc_chain, test_simplify);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_caps_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;
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstelement.c: Unit test for GstElement
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_add_remove_pad)
|
||||
{
|
||||
GstElement *e;
|
||||
GstPad *p;
|
||||
|
||||
/* getting an existing element class is cheating, but easier */
|
||||
e = gst_element_factory_make ("fakesrc", "source");
|
||||
|
||||
/* create a new floating pad with refcount 1 */
|
||||
p = gst_pad_new ("source", GST_PAD_SRC);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
||||
/* ref it for ourselves */
|
||||
gst_object_ref (p);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
||||
/* adding it sinks the pad -> not floating, same refcount */
|
||||
gst_element_add_pad (e, p);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
||||
|
||||
/* removing it reduces the refcount */
|
||||
gst_element_remove_pad (e, p);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
||||
|
||||
/* clean up our own reference */
|
||||
gst_object_unref (p);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_add_pad_unref_element)
|
||||
{
|
||||
GstElement *e;
|
||||
GstPad *p;
|
||||
|
||||
/* getting an existing element class is cheating, but easier */
|
||||
e = gst_element_factory_make ("fakesrc", "source");
|
||||
|
||||
/* create a new floating pad with refcount 1 */
|
||||
p = gst_pad_new ("source", GST_PAD_SRC);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
||||
/* ref it for ourselves */
|
||||
gst_object_ref (p);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
||||
/* adding it sinks the pad -> not floating, same refcount */
|
||||
gst_element_add_pad (e, p);
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
|
||||
|
||||
/* unreffing the element should clean it up */
|
||||
gst_object_unref (GST_OBJECT (e));
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
|
||||
|
||||
/* clean up our own reference */
|
||||
gst_object_unref (p);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_error_no_bus)
|
||||
{
|
||||
GstElement *e;
|
||||
|
||||
e = gst_element_factory_make ("fakesrc", "source");
|
||||
|
||||
/* I don't want errors shown */
|
||||
gst_debug_set_default_threshold (GST_LEVEL_NONE);
|
||||
|
||||
GST_ELEMENT_ERROR (e, RESOURCE, OPEN_READ, ("I could not read"), ("debug"));
|
||||
|
||||
gst_object_unref (e);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* link and run two elements without putting them in a pipeline */
|
||||
GST_START_TEST (test_link)
|
||||
{
|
||||
GstElement *src, *sink;
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", "source");
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
fail_unless (gst_element_link_pads (src, "src", sink, "sink"));
|
||||
|
||||
/* do sink to source state change */
|
||||
gst_element_set_state (sink, GST_STATE_PAUSED);
|
||||
gst_element_set_state (src, GST_STATE_PAUSED);
|
||||
|
||||
/* wait for preroll */
|
||||
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
/* play some more */
|
||||
gst_element_set_state (sink, GST_STATE_PLAYING);
|
||||
gst_element_set_state (src, GST_STATE_PLAYING);
|
||||
|
||||
g_usleep (G_USEC_PER_SEC);
|
||||
|
||||
/* and stop */
|
||||
gst_element_set_state (sink, GST_STATE_PAUSED);
|
||||
gst_element_set_state (src, GST_STATE_PAUSED);
|
||||
|
||||
/* wait for preroll */
|
||||
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
gst_element_set_state (sink, GST_STATE_NULL);
|
||||
gst_element_set_state (src, GST_STATE_NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* linking two elements without pads should fail */
|
||||
GST_START_TEST (test_link_no_pads)
|
||||
{
|
||||
GstElement *src, *sink;
|
||||
|
||||
src = gst_bin_new ("src");
|
||||
sink = gst_bin_new ("sink");
|
||||
|
||||
fail_if (gst_element_link (src, sink));
|
||||
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_element_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstElement");
|
||||
TCase *tc_chain = tcase_create ("element tests");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_add_remove_pad);
|
||||
tcase_add_test (tc_chain, test_add_pad_unref_element);
|
||||
tcase_add_test (tc_chain, test_error_no_bus);
|
||||
tcase_add_test (tc_chain, test_link);
|
||||
tcase_add_test (tc_chain, test_link_no_pads);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_element_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;
|
||||
}
|
|
@ -1,416 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
|
||||
*
|
||||
* gstevent.c: Unit test for event handling
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (create_custom_events)
|
||||
{
|
||||
GstEvent *event, *event2;
|
||||
GstStructure *structure;
|
||||
|
||||
/* FLUSH_START */
|
||||
{
|
||||
event = gst_event_new_flush_start ();
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START);
|
||||
fail_unless (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_SERIALIZED (event));
|
||||
gst_event_unref (event);
|
||||
}
|
||||
/* FLUSH_STOP */
|
||||
{
|
||||
event = gst_event_new_flush_stop ();
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP);
|
||||
fail_unless (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_SERIALIZED (event));
|
||||
gst_event_unref (event);
|
||||
}
|
||||
/* EOS */
|
||||
{
|
||||
event = gst_event_new_eos ();
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_EOS);
|
||||
fail_if (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_SERIALIZED (event));
|
||||
gst_event_unref (event);
|
||||
}
|
||||
/* NEWSEGMENT */
|
||||
{
|
||||
gdouble rate;
|
||||
GstFormat format;
|
||||
gint64 start, end, base;
|
||||
gboolean update;
|
||||
|
||||
event =
|
||||
gst_event_new_new_segment (FALSE, 0.5, GST_FORMAT_TIME, 1, G_MAXINT64,
|
||||
0xdeadbeef);
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT);
|
||||
fail_if (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_SERIALIZED (event));
|
||||
|
||||
gst_event_parse_new_segment (event, &update, &rate, &format, &start, &end,
|
||||
&base);
|
||||
fail_unless (update == FALSE);
|
||||
fail_unless (rate == 0.5);
|
||||
fail_unless (format == GST_FORMAT_TIME);
|
||||
fail_unless (start == 1);
|
||||
fail_unless (end == G_MAXINT64);
|
||||
fail_unless (base == 0xdeadbeef);
|
||||
|
||||
gst_event_unref (event);
|
||||
}
|
||||
/* TAGS */
|
||||
{
|
||||
GstTagList *taglist = gst_tag_list_new ();
|
||||
GstTagList *tl2 = NULL;
|
||||
|
||||
event = gst_event_new_tag (taglist);
|
||||
fail_if (taglist == NULL);
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_TAG);
|
||||
fail_if (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_unless (GST_EVENT_IS_SERIALIZED (event));
|
||||
|
||||
gst_event_parse_tag (event, &tl2);
|
||||
fail_unless (taglist == tl2);
|
||||
gst_event_unref (event);
|
||||
}
|
||||
|
||||
/* FIXME: Add tests for QOS when it is implemented. */
|
||||
|
||||
/* SEEK */
|
||||
{
|
||||
gdouble rate;
|
||||
GstFormat format;
|
||||
GstSeekFlags flags;
|
||||
GstSeekType cur_type, stop_type;
|
||||
gint64 cur, stop;
|
||||
|
||||
event = gst_event_new_seek (0.5, GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
|
||||
GST_SEEK_TYPE_SET, 1, GST_SEEK_TYPE_NONE, 0xdeadbeef);
|
||||
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
|
||||
fail_unless (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_SERIALIZED (event));
|
||||
|
||||
gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur,
|
||||
&stop_type, &stop);
|
||||
fail_unless (rate == 0.5);
|
||||
fail_unless (format == GST_FORMAT_BYTES);
|
||||
fail_unless (flags == (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE));
|
||||
fail_unless (cur_type == GST_SEEK_TYPE_SET);
|
||||
fail_unless (cur == 1);
|
||||
fail_unless (stop_type == GST_SEEK_TYPE_NONE);
|
||||
fail_unless (stop == 0xdeadbeef);
|
||||
|
||||
gst_event_unref (event);
|
||||
}
|
||||
|
||||
/* NAVIGATION */
|
||||
{
|
||||
structure = gst_structure_new ("application/x-gst-navigation", "event",
|
||||
G_TYPE_STRING, "key-press", "key", G_TYPE_STRING, "mon", NULL);
|
||||
fail_if (structure == NULL);
|
||||
event = gst_event_new_navigation (structure);
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION);
|
||||
fail_unless (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_SERIALIZED (event));
|
||||
|
||||
fail_unless (gst_event_get_structure (event) == structure);
|
||||
gst_event_unref (event);
|
||||
}
|
||||
|
||||
/* Custom event types */
|
||||
{
|
||||
structure = gst_structure_empty_new ("application/x-custom");
|
||||
fail_if (structure == NULL);
|
||||
event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
|
||||
fail_if (event == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_CUSTOM_UPSTREAM);
|
||||
fail_unless (GST_EVENT_IS_UPSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_DOWNSTREAM (event));
|
||||
fail_if (GST_EVENT_IS_SERIALIZED (event));
|
||||
fail_unless (gst_event_get_structure (event) == structure);
|
||||
gst_event_unref (event);
|
||||
|
||||
/* Decided not to test the other custom enum types, as they
|
||||
* only differ by the value of the enum passed to gst_event_new_custom
|
||||
*/
|
||||
}
|
||||
|
||||
/* Event copying */
|
||||
{
|
||||
structure = gst_structure_empty_new ("application/x-custom");
|
||||
fail_if (structure == NULL);
|
||||
event = gst_event_new_custom (GST_EVENT_CUSTOM_BOTH, structure);
|
||||
|
||||
fail_if (event == NULL);
|
||||
event2 = gst_event_copy (event);
|
||||
fail_if (event2 == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_TYPE (event2));
|
||||
|
||||
/* The structure should have been duplicated */
|
||||
fail_if (gst_event_get_structure (event) ==
|
||||
gst_event_get_structure (event2));
|
||||
gst_event_unref (event);
|
||||
gst_event_unref (event2);
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GTimeVal sent_event_time;
|
||||
GstEvent *got_event_before_q, *got_event_after_q;
|
||||
GTimeVal got_event_time;
|
||||
|
||||
static gboolean
|
||||
event_probe (GstPad * pad, GstMiniObject ** data, gpointer user_data)
|
||||
{
|
||||
gboolean before_q = (gboolean) GPOINTER_TO_INT (user_data);
|
||||
|
||||
fail_unless (GST_IS_EVENT (data));
|
||||
|
||||
if (before_q) {
|
||||
switch (GST_EVENT_TYPE (GST_EVENT (data))) {
|
||||
case GST_EVENT_CUSTOM_UPSTREAM:
|
||||
case GST_EVENT_CUSTOM_BOTH:
|
||||
case GST_EVENT_CUSTOM_BOTH_OOB:
|
||||
if (got_event_before_q != NULL)
|
||||
break;
|
||||
gst_event_ref (data);
|
||||
g_get_current_time (&got_event_time);
|
||||
got_event_before_q = GST_EVENT (data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (GST_EVENT_TYPE (GST_EVENT (data))) {
|
||||
case GST_EVENT_CUSTOM_DOWNSTREAM:
|
||||
case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
|
||||
case GST_EVENT_CUSTOM_BOTH:
|
||||
case GST_EVENT_CUSTOM_BOTH_OOB:
|
||||
if (got_event_after_q != NULL)
|
||||
break;
|
||||
gst_event_ref (data);
|
||||
g_get_current_time (&got_event_time);
|
||||
got_event_after_q = GST_EVENT (data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void test_event
|
||||
(GstBin * pipeline, GstEventType type, GstPad * pad,
|
||||
gboolean expect_before_q, GstPad * fake_srcpad)
|
||||
{
|
||||
GstEvent *event;
|
||||
gint i;
|
||||
|
||||
got_event_before_q = got_event_after_q = NULL;
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
|
||||
event = gst_event_new_custom (type,
|
||||
gst_structure_empty_new ("application/x-custom"));
|
||||
g_get_current_time (&sent_event_time);
|
||||
got_event_time.tv_sec = 0;
|
||||
got_event_time.tv_usec = 0;
|
||||
|
||||
fail_unless (gst_pad_set_blocked (fake_srcpad, TRUE) == TRUE);
|
||||
gst_pad_push_event (pad, event);
|
||||
fail_unless (gst_pad_set_blocked (fake_srcpad, FALSE) == TRUE);
|
||||
|
||||
/* Wait up to 5 seconds for the event to appear */
|
||||
if (expect_before_q) {
|
||||
for (i = 0; i < 500; i++) {
|
||||
g_usleep (G_USEC_PER_SEC / 100);
|
||||
if (got_event_before_q != NULL)
|
||||
break;
|
||||
}
|
||||
fail_if (got_event_before_q == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (got_event_before_q) == type);
|
||||
} else {
|
||||
for (i = 0; i < 500; i++) {
|
||||
g_usleep (G_USEC_PER_SEC / 100);
|
||||
if (got_event_after_q != NULL)
|
||||
break;
|
||||
}
|
||||
fail_if (got_event_after_q == NULL);
|
||||
fail_unless (GST_EVENT_TYPE (got_event_after_q) == type);
|
||||
}
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
|
||||
if (got_event_before_q)
|
||||
gst_event_unref (got_event_before_q);
|
||||
if (got_event_after_q)
|
||||
gst_event_unref (got_event_after_q);
|
||||
|
||||
got_event_before_q = got_event_after_q = NULL;
|
||||
}
|
||||
|
||||
static gint64
|
||||
timediff (GTimeVal * end, GTimeVal * start)
|
||||
{
|
||||
return (end->tv_sec - start->tv_sec) * G_USEC_PER_SEC +
|
||||
(end->tv_usec - start->tv_usec);
|
||||
}
|
||||
|
||||
GST_START_TEST (send_custom_events)
|
||||
{
|
||||
/* Run some tests on custom events. Checking for serialisation and whatnot.
|
||||
* pipeline is fakesrc ! queue ! fakesink */
|
||||
GstBin *pipeline;
|
||||
GstElement *fakesrc, *fakesink, *queue;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
fail_if ((pipeline = (GstBin *) gst_pipeline_new ("testpipe")) == NULL);
|
||||
fail_if ((fakesrc = gst_element_factory_make ("fakesrc", NULL)) == NULL);
|
||||
fail_if ((fakesink = gst_element_factory_make ("fakesink", NULL)) == NULL);
|
||||
fail_if ((queue = gst_element_factory_make ("queue", NULL)) == NULL);
|
||||
|
||||
gst_bin_add_many (pipeline, fakesrc, queue, fakesink, NULL);
|
||||
fail_unless (gst_element_link_many (fakesrc, queue, fakesink, NULL));
|
||||
|
||||
g_object_set (G_OBJECT (fakesink), "sync", FALSE, NULL);
|
||||
|
||||
/* Send 100 buffers per sec */
|
||||
g_object_set (G_OBJECT (fakesrc), "silent", TRUE, "datarate", 100,
|
||||
"sizemax", 1, "sizetype", 2, NULL);
|
||||
g_object_set (G_OBJECT (queue), "max-size-buffers", 0, "max-size-time",
|
||||
(guint64) GST_SECOND, "max-size-bytes", 0, NULL);
|
||||
g_object_set (G_OBJECT (fakesink), "silent", TRUE, "sync", TRUE, NULL);
|
||||
|
||||
fail_if ((srcpad = gst_element_get_pad (fakesrc, "src")) == NULL);
|
||||
gst_pad_add_event_probe (srcpad, (GCallback) event_probe,
|
||||
GINT_TO_POINTER (TRUE));
|
||||
|
||||
fail_if ((sinkpad = gst_element_get_pad (fakesink, "sink")) == NULL);
|
||||
gst_pad_add_event_probe (sinkpad, (GCallback) event_probe,
|
||||
GINT_TO_POINTER (FALSE));
|
||||
|
||||
/* Upstream events */
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_UPSTREAM, sinkpad, TRUE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) < G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_UP took to long to reach source: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_BOTH, sinkpad, TRUE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) < G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_BOTH took to long to reach source: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, sinkpad, TRUE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) < G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_BOTH_OOB took to long to reach source: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
/* Out of band downstream events */
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM_OOB, srcpad, FALSE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) < G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_DS_OOB took to long to reach source: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, srcpad, FALSE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) < G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_BOTH_OOB took to long to reach source: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
/* In-band downstream events are expected to take at least 1 second
|
||||
* to traverse the the queue */
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM, srcpad, FALSE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) >= G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_DS arrived too quickly for an in-band event: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
test_event (pipeline, GST_EVENT_CUSTOM_BOTH, srcpad, FALSE, srcpad);
|
||||
fail_unless (timediff (&got_event_time,
|
||||
&sent_event_time) >= G_USEC_PER_SEC / 2,
|
||||
"GST_EVENT_CUSTOM_BOTH arrived too quickly for an in-band event: %"
|
||||
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time));
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gstevents_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstEvent");
|
||||
TCase *tc_chain = tcase_create ("customevents");
|
||||
|
||||
tcase_set_timeout (tc_chain, 20);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, create_custom_events);
|
||||
tcase_add_test (tc_chain, send_custom_events);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gstevents_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;
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
|
||||
*
|
||||
* gstghostpad.c: Unit test for GstGhostPad
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
/* test if removing a bin also cleans up the ghostpads
|
||||
*/
|
||||
GST_START_TEST (test_remove1)
|
||||
{
|
||||
GstElement *b1, *b2, *src, *sink;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstPadLinkReturn ret;
|
||||
|
||||
b1 = gst_element_factory_make ("pipeline", NULL);
|
||||
b2 = gst_element_factory_make ("bin", NULL);
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
fail_unless (gst_bin_add (GST_BIN (b2), sink));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), src));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
||||
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_element_add_pad (b2, gst_ghost_pad_new ("sink", sinkpad));
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
/* get the ghostpad */
|
||||
sinkpad = gst_element_get_pad (b2, "sink");
|
||||
|
||||
ret = gst_pad_link (srcpad, sinkpad);
|
||||
fail_unless (ret == GST_PAD_LINK_OK);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
/* now remove the bin with the ghostpad, b2 is disposed
|
||||
* now. */
|
||||
gst_bin_remove (GST_BIN (b1), b2);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
/* pad cannot be linked now */
|
||||
fail_if (gst_pad_is_linked (srcpad));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test if removing a bin also cleans up the ghostpads
|
||||
*/
|
||||
GST_START_TEST (test_remove2)
|
||||
{
|
||||
GstElement *b1, *b2, *src, *sink;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstPadLinkReturn ret;
|
||||
|
||||
b1 = gst_element_factory_make ("pipeline", NULL);
|
||||
b2 = gst_element_factory_make ("bin", NULL);
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
fail_unless (gst_bin_add (GST_BIN (b2), sink));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), src));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
||||
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_element_add_pad (b2, gst_ghost_pad_new ("sink", sinkpad));
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
/* get the ghostpad */
|
||||
sinkpad = gst_element_get_pad (b2, "sink");
|
||||
|
||||
ret = gst_pad_link (srcpad, sinkpad);
|
||||
fail_unless (ret == GST_PAD_LINK_OK);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
/* now remove the sink from the bin */
|
||||
gst_bin_remove (GST_BIN (b2), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
/* pad is still linked to ghostpad */
|
||||
fail_if (!gst_pad_is_linked (srcpad));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
#if 0
|
||||
/* test if a ghost pad without a target can be linked
|
||||
* It can't because it has incompatible caps...
|
||||
*/
|
||||
GST_START_TEST (test_ghost_pad_notarget)
|
||||
{
|
||||
GstElement *b1, *b2, *sink;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstPadLinkReturn ret;
|
||||
|
||||
b1 = gst_element_factory_make ("pipeline", NULL);
|
||||
b2 = gst_element_factory_make ("bin", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), sink));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
||||
|
||||
srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
|
||||
fail_unless (srcpad != NULL);
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
fail_unless (sinkpad != NULL);
|
||||
|
||||
ret = gst_pad_link (srcpad, sinkpad);
|
||||
fail_unless (ret == GST_PAD_LINK_OK);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
#endif
|
||||
|
||||
/* test if linking fails over different bins using a pipeline
|
||||
* like this:
|
||||
*
|
||||
* fakesrc num_buffers=10 ! ( fakesink )
|
||||
*
|
||||
*/
|
||||
GST_START_TEST (test_link)
|
||||
{
|
||||
GstElement *b1, *b2, *src, *sink;
|
||||
GstPad *srcpad, *sinkpad, *gpad;
|
||||
GstPadLinkReturn ret;
|
||||
|
||||
b1 = gst_element_factory_make ("pipeline", NULL);
|
||||
b2 = gst_element_factory_make ("bin", NULL);
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
fail_unless (gst_bin_add (GST_BIN (b2), sink));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), src));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
fail_unless (srcpad != NULL);
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
fail_unless (sinkpad != NULL);
|
||||
|
||||
/* linking in different hierarchies should fail */
|
||||
ret = gst_pad_link (srcpad, sinkpad);
|
||||
fail_unless (ret == GST_PAD_LINK_WRONG_HIERARCHY);
|
||||
|
||||
/* now setup a ghostpad */
|
||||
gpad = gst_ghost_pad_new ("sink", sinkpad);
|
||||
gst_object_unref (sinkpad);
|
||||
/* need to ref as _add_pad takes ownership */
|
||||
gst_object_ref (gpad);
|
||||
gst_element_add_pad (b2, gpad);
|
||||
|
||||
/* our new sinkpad */
|
||||
sinkpad = gpad;
|
||||
|
||||
/* and linking should work now */
|
||||
ret = gst_pad_link (srcpad, sinkpad);
|
||||
fail_unless (ret == GST_PAD_LINK_OK);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test if ghostpads are created automagically when using
|
||||
* gst_element_link_pads.
|
||||
*
|
||||
* fakesrc num_buffers=10 ! ( identity ) ! fakesink
|
||||
*/
|
||||
GST_START_TEST (test_ghost_pads)
|
||||
{
|
||||
GstElement *b1, *b2, *src, *i1, *sink;
|
||||
GstPad *gsink, *gsrc, *gisrc, *gisink, *isink, *isrc, *fsrc, *fsink;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
b1 = gst_element_factory_make ("pipeline", NULL);
|
||||
b2 = gst_element_factory_make ("bin", NULL);
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
g_object_set (src, "num-buffers", (int) 10, NULL);
|
||||
i1 = gst_element_factory_make ("identity", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
fail_unless (gst_bin_add (GST_BIN (b2), i1));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), src));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
||||
fail_unless (gst_bin_add (GST_BIN (b1), sink));
|
||||
fail_unless (gst_element_link_pads (src, NULL, i1, NULL));
|
||||
fail_unless (gst_element_link_pads (i1, NULL, sink, NULL));
|
||||
GST_OBJECT_LOCK (b2);
|
||||
fail_unless (b2->numsinkpads == 1);
|
||||
fail_unless (GST_IS_GHOST_PAD (b2->sinkpads->data));
|
||||
fail_unless (b2->numsrcpads == 1);
|
||||
fail_unless (GST_IS_GHOST_PAD (b2->srcpads->data));
|
||||
GST_OBJECT_UNLOCK (b2);
|
||||
|
||||
fsrc = gst_element_get_pad (src, "src");
|
||||
fail_unless (fsrc != NULL);
|
||||
gsink = GST_PAD (gst_object_ref (b2->sinkpads->data));
|
||||
fail_unless (gsink != NULL);
|
||||
gsrc = GST_PAD (gst_object_ref (b2->srcpads->data));
|
||||
fail_unless (gsrc != NULL);
|
||||
fsink = gst_element_get_pad (sink, "sink");
|
||||
fail_unless (fsink != NULL);
|
||||
|
||||
isink = gst_element_get_pad (i1, "sink");
|
||||
fail_unless (isink != NULL);
|
||||
isrc = gst_element_get_pad (i1, "src");
|
||||
fail_unless (isrc != NULL);
|
||||
gisrc = gst_pad_get_peer (isink);
|
||||
fail_unless (gisrc != NULL);
|
||||
gisink = gst_pad_get_peer (isrc);
|
||||
fail_unless (gisink != NULL);
|
||||
|
||||
/* all objects above have one refcount owned by us as well */
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 3); /* parent and gisrc */
|
||||
ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 2); /* parent */
|
||||
ASSERT_OBJECT_REFCOUNT (gsrc, "gsrc", 2); /* parent */
|
||||
ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 3); /* parent and gisink */
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 2); /* parent */
|
||||
ASSERT_OBJECT_REFCOUNT (isink, "isink", 3); /* parent and gsink */
|
||||
ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 2); /* parent */
|
||||
ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 3); /* parent and gsrc */
|
||||
|
||||
ret = gst_element_set_state (b1, GST_STATE_PLAYING);
|
||||
ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
ret = gst_element_set_state (b1, GST_STATE_NULL);
|
||||
ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (b1);
|
||||
/* unreffing the bin will unref all elements, which will unlink and unparent
|
||||
* all pads */
|
||||
|
||||
/* wait for thread to settle down */
|
||||
while (GST_OBJECT_REFCOUNT_VALUE (fsrc) > 2)
|
||||
THREAD_SWITCH ();
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2); /* gisrc */
|
||||
ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (gsrc, "gsink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2); /* gisink */
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1); /* gsink */
|
||||
ASSERT_OBJECT_REFCOUNT (isink, "isink", 2); /* gsink */
|
||||
ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1); /* gsrc */
|
||||
ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 2); /* gsrc */
|
||||
|
||||
gst_object_unref (gsink);
|
||||
ASSERT_OBJECT_REFCOUNT (isink, "isink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2); /* gisrc */
|
||||
gst_object_unref (gisrc);
|
||||
ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
|
||||
|
||||
gst_object_unref (gsrc);
|
||||
ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2); /* gisrc */
|
||||
gst_object_unref (gisink);
|
||||
ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
|
||||
|
||||
gst_object_unref (fsrc);
|
||||
gst_object_unref (isrc);
|
||||
gst_object_unref (isink);
|
||||
gst_object_unref (fsink);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_ghost_pads_bin)
|
||||
{
|
||||
GstBin *pipeline;
|
||||
GstBin *srcbin;
|
||||
GstBin *sinkbin;
|
||||
GstElement *src;
|
||||
GstElement *sink;
|
||||
GstPad *srcghost;
|
||||
GstPad *sinkghost;
|
||||
|
||||
pipeline = GST_BIN (gst_pipeline_new ("pipe"));
|
||||
|
||||
srcbin = GST_BIN (gst_bin_new ("srcbin"));
|
||||
gst_bin_add (pipeline, GST_ELEMENT (srcbin));
|
||||
|
||||
sinkbin = GST_BIN (gst_bin_new ("sinkbin"));
|
||||
gst_bin_add (pipeline, GST_ELEMENT (sinkbin));
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
gst_bin_add (srcbin, src);
|
||||
srcghost = gst_ghost_pad_new ("src", gst_element_get_pad (src, "src"));
|
||||
gst_element_add_pad (GST_ELEMENT (srcbin), srcghost);
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
gst_bin_add (sinkbin, sink);
|
||||
sinkghost = gst_ghost_pad_new ("sink", gst_element_get_pad (sink, "sink"));
|
||||
gst_element_add_pad (GST_ELEMENT (sinkbin), sinkghost);
|
||||
|
||||
gst_element_link (GST_ELEMENT (srcbin), GST_ELEMENT (sinkbin));
|
||||
|
||||
fail_unless (GST_PAD_PEER (srcghost) != NULL);
|
||||
fail_unless (GST_PAD_PEER (sinkghost) != NULL);
|
||||
fail_unless (GST_PAD_PEER (gst_ghost_pad_get_target (GST_GHOST_PAD
|
||||
(srcghost))) != NULL);
|
||||
fail_unless (GST_PAD_PEER (gst_ghost_pad_get_target (GST_GHOST_PAD
|
||||
(sinkghost))) != NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_ghost_pad_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstGhostPad");
|
||||
TCase *tc_chain = tcase_create ("ghost pad tests");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_remove1);
|
||||
tcase_add_test (tc_chain, test_remove2);
|
||||
tcase_add_test (tc_chain, test_link);
|
||||
tcase_add_test (tc_chain, test_ghost_pads);
|
||||
tcase_add_test (tc_chain, test_ghost_pads_bin);
|
||||
/* tcase_add_test (tc_chain, test_ghost_pad_notarget); */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_ghost_pad_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;
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
/* 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 <gst/check/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
|
||||
|
||||
GST_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 (G_TYPE_INT, m, &cookie, &l, NULL, NULL, NULL);
|
||||
|
||||
fail_unless (iter != NULL);
|
||||
|
||||
while (1) {
|
||||
res = gst_iterator_next (iter, &item);
|
||||
if (i < NUM_ELEMENTS) {
|
||||
fail_unless (res == GST_ITERATOR_OK);
|
||||
fail_unless (GPOINTER_TO_INT (item) == i);
|
||||
i++;
|
||||
continue;
|
||||
} else {
|
||||
fail_unless (res == GST_ITERATOR_DONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
gst_iterator_free (iter);
|
||||
g_mutex_free (m);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_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 (G_TYPE_INT, m, &cookie, &l, NULL, NULL, NULL);
|
||||
|
||||
fail_unless (iter != NULL);
|
||||
|
||||
while (1) {
|
||||
res = gst_iterator_next (iter, &item);
|
||||
if (i < NUM_ELEMENTS / 2) {
|
||||
fail_unless (res == GST_ITERATOR_OK);
|
||||
fail_unless (GPOINTER_TO_INT (item) == i);
|
||||
i++;
|
||||
continue;
|
||||
} else if (!hacked_list) {
|
||||
/* here's where we test resync */
|
||||
fail_unless (res == GST_ITERATOR_OK);
|
||||
l = g_list_prepend (l, GINT_TO_POINTER (-1));
|
||||
cookie++;
|
||||
hacked_list = TRUE;
|
||||
continue;
|
||||
} else {
|
||||
fail_unless (res == GST_ITERATOR_RESYNC);
|
||||
gst_iterator_resync (iter);
|
||||
res = gst_iterator_next (iter, &item);
|
||||
fail_unless (res == GST_ITERATOR_OK);
|
||||
fail_unless (GPOINTER_TO_INT (item) == -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
gst_iterator_free (iter);
|
||||
g_mutex_free (m);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static gboolean
|
||||
add_fold_func (gpointer item, GValue * ret, gpointer user_data)
|
||||
{
|
||||
g_value_set_int (ret, g_value_get_int (ret) + GPOINTER_TO_INT (item));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_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 (G_TYPE_INT, m, &cookie, &l, NULL, NULL, NULL);
|
||||
fail_unless (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);
|
||||
|
||||
fail_unless (res == GST_ITERATOR_DONE);
|
||||
fail_unless (g_value_get_int (&ret) == expected);
|
||||
|
||||
/* clean up */
|
||||
gst_iterator_free (iter);
|
||||
g_mutex_free (m);
|
||||
}
|
||||
|
||||
GST_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;
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for GstMessage
|
||||
*
|
||||
* Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
static GQuark domain;
|
||||
|
||||
GST_START_TEST (test_parsing)
|
||||
{
|
||||
GstMessage *message;
|
||||
|
||||
domain = g_quark_from_string ("test");
|
||||
|
||||
/* GST_MESSAGE_EOS */
|
||||
{
|
||||
message = gst_message_new_eos (NULL);
|
||||
fail_if (message == NULL);
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
||||
gst_message_unref (message);
|
||||
}
|
||||
/* GST_MESSAGE_ERROR */
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar *debug;
|
||||
|
||||
error = g_error_new (domain, 10, "test error");
|
||||
fail_if (error == NULL);
|
||||
message = gst_message_new_error (NULL, error, "error string");
|
||||
fail_if (message == NULL);
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
||||
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
debug = NULL;
|
||||
|
||||
gst_message_parse_error (message, &error, &debug);
|
||||
fail_if (error == NULL);
|
||||
fail_if (debug == NULL);
|
||||
fail_unless (strcmp (error->message, "test error") == 0);
|
||||
fail_unless (error->domain == domain);
|
||||
fail_unless (error->code == 10);
|
||||
fail_unless (strcmp (debug, "error string") == 0);
|
||||
|
||||
gst_message_unref (message);
|
||||
g_error_free (error);
|
||||
g_free (debug);
|
||||
}
|
||||
/* GST_MESSAGE_WARNING */
|
||||
{
|
||||
GError *warning = NULL;
|
||||
gchar *debug;
|
||||
|
||||
warning = g_error_new (domain, 10, "test warning");
|
||||
fail_if (warning == NULL);
|
||||
message = gst_message_new_warning (NULL, warning, "warning string");
|
||||
fail_if (message == NULL);
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
||||
|
||||
g_error_free (warning);
|
||||
warning = NULL;
|
||||
debug = NULL;
|
||||
|
||||
gst_message_parse_warning (message, &warning, &debug);
|
||||
fail_if (warning == NULL);
|
||||
fail_if (debug == NULL);
|
||||
fail_unless (strcmp (warning->message, "test warning") == 0);
|
||||
fail_unless (warning->domain == domain);
|
||||
fail_unless (warning->code == 10);
|
||||
fail_unless (strcmp (debug, "warning string") == 0);
|
||||
|
||||
gst_message_unref (message);
|
||||
g_error_free (warning);
|
||||
g_free (debug);
|
||||
}
|
||||
/* GST_MESSAGE_INFO */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_TAG */
|
||||
{
|
||||
GstTagList *tag;
|
||||
|
||||
/* FIXME, do some more tag adding */
|
||||
tag = gst_tag_list_new ();
|
||||
fail_if (tag == NULL);
|
||||
message = gst_message_new_tag (NULL, tag);
|
||||
fail_if (message == NULL);
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
||||
tag = NULL;
|
||||
gst_message_parse_tag (message, &tag);
|
||||
fail_if (tag == NULL);
|
||||
/* FIXME, check the actual tags */
|
||||
gst_message_unref (message);
|
||||
gst_tag_list_free (tag);
|
||||
}
|
||||
/* GST_MESSAGE_BUFFERING */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_STATE_CHANGED */
|
||||
{
|
||||
GstState oldstate, newstate, pending;
|
||||
|
||||
oldstate = GST_STATE_PAUSED;
|
||||
newstate = GST_STATE_PLAYING;
|
||||
pending = GST_STATE_VOID_PENDING;
|
||||
|
||||
message = gst_message_new_state_changed (NULL, oldstate, newstate, pending);
|
||||
fail_if (message == NULL);
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
||||
|
||||
/* set some wrong values to check if the parse method overwrites them
|
||||
* with the good values */
|
||||
oldstate = GST_STATE_READY;
|
||||
newstate = GST_STATE_READY;
|
||||
pending = GST_STATE_READY;
|
||||
gst_message_parse_state_changed (message, &oldstate, &newstate, &pending);
|
||||
fail_unless (oldstate == GST_STATE_PAUSED);
|
||||
fail_unless (newstate == GST_STATE_PLAYING);
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING);
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
/* GST_MESSAGE_STEP_DONE */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_NEW_CLOCK */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_STRUCTURE_CHANGE */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_STREAM_STATUS */
|
||||
{
|
||||
}
|
||||
/* GST_MESSAGE_APPLICATION */
|
||||
{
|
||||
GstStructure *structure;
|
||||
const GstStructure *struc;
|
||||
gint some_int;
|
||||
gdouble a_double;
|
||||
|
||||
structure = gst_structure_new ("test_struct",
|
||||
"some_int", G_TYPE_INT, 10,
|
||||
"a_double", G_TYPE_DOUBLE, (gdouble) 1.8, NULL);
|
||||
fail_if (structure == NULL);
|
||||
message = gst_message_new_application (NULL, structure);
|
||||
fail_if (message == NULL);
|
||||
struc = gst_message_get_structure (message);
|
||||
fail_if (struc == NULL);
|
||||
fail_unless (gst_structure_get_int (struc, "some_int", &some_int));
|
||||
fail_unless (gst_structure_get_double (struc, "a_double", &a_double));
|
||||
fail_unless (some_int == 10);
|
||||
fail_unless (a_double == 1.8);
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
|
||||
/*
|
||||
void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list);
|
||||
void gst_message_parse_state_changed (GstMessage *message, GstState *old_state,
|
||||
GstState *new_state);
|
||||
void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug);
|
||||
void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST Suite *
|
||||
gst_data_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstMessage");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_parsing);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_data_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;
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for GstMiniObject
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_copy)
|
||||
{
|
||||
GstBuffer *buffer, *copy;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
copy = GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT (buffer)));
|
||||
|
||||
fail_if (copy == NULL, "Copy of buffer returned NULL");
|
||||
fail_unless (GST_BUFFER_SIZE (copy) == 4,
|
||||
"Copy of buffer has different size");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_is_writable)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstMiniObject *mobj;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
mobj = GST_MINI_OBJECT (buffer);
|
||||
|
||||
fail_unless (gst_mini_object_is_writable (mobj),
|
||||
"A buffer with one ref should be writable");
|
||||
|
||||
GST_MINI_OBJECT_FLAG_SET (mobj, GST_MINI_OBJECT_FLAG_READONLY);
|
||||
fail_if (gst_mini_object_is_writable (mobj),
|
||||
"A buffer with READONLY set should not be writable");
|
||||
GST_MINI_OBJECT_FLAG_UNSET (mobj, GST_MINI_OBJECT_FLAG_READONLY);
|
||||
fail_unless (gst_mini_object_is_writable (mobj),
|
||||
"A buffer with one ref and READONLY not set should be writable");
|
||||
|
||||
fail_if (gst_mini_object_ref (mobj) == NULL, "Could not ref the mobj");
|
||||
|
||||
fail_if (gst_mini_object_is_writable (mobj),
|
||||
"A buffer with two refs should not be writable");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_make_writable)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstMiniObject *mobj, *mobj2, *mobj3;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
mobj = GST_MINI_OBJECT (buffer);
|
||||
|
||||
mobj2 = gst_mini_object_make_writable (mobj);
|
||||
fail_unless (GST_IS_BUFFER (mobj2), "make_writable did not return a buffer");
|
||||
fail_unless (mobj == mobj2,
|
||||
"make_writable returned a copy for a buffer with refcount 1");
|
||||
|
||||
mobj2 = gst_mini_object_ref (mobj);
|
||||
mobj3 = gst_mini_object_make_writable (mobj);
|
||||
fail_unless (GST_IS_BUFFER (mobj3), "make_writable did not return a buffer");
|
||||
fail_if (mobj == mobj3,
|
||||
"make_writable returned same object for a buffer with refcount > 1");
|
||||
|
||||
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (mobj) == 1,
|
||||
"refcount of original mobj object should be back to 1");
|
||||
|
||||
mobj2 = gst_mini_object_make_writable (mobj);
|
||||
fail_unless (GST_IS_BUFFER (mobj2), "make_writable did not return a buffer");
|
||||
fail_unless (mobj == mobj2,
|
||||
"make_writable returned a copy for a buffer with refcount 1");
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
gint num_threads = 10;
|
||||
gint refs_per_thread = 10000;
|
||||
|
||||
/* test thread-safe refcounting of GstMiniObject */
|
||||
void
|
||||
thread_ref (GstMiniObject * mobj)
|
||||
{
|
||||
int j;
|
||||
|
||||
THREAD_START ();
|
||||
|
||||
for (j = 0; j < refs_per_thread; ++j) {
|
||||
gst_mini_object_ref (mobj);
|
||||
|
||||
if (j % num_threads == 0)
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
GST_DEBUG ("thread stopped");
|
||||
}
|
||||
|
||||
GST_START_TEST (test_ref_threaded)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstMiniObject *mobj;
|
||||
gint expected;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
mobj = GST_MINI_OBJECT (buffer);
|
||||
|
||||
MAIN_START_THREADS (num_threads, thread_ref, mobj);
|
||||
|
||||
MAIN_STOP_THREADS ();
|
||||
|
||||
expected = num_threads * refs_per_thread + 1;
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (mobj, "miniobject", expected);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
void
|
||||
thread_unref (GstMiniObject * mobj)
|
||||
{
|
||||
int j;
|
||||
|
||||
THREAD_START ();
|
||||
|
||||
for (j = 0; j < refs_per_thread; ++j) {
|
||||
gst_mini_object_unref (mobj);
|
||||
|
||||
if (j % num_threads == 0)
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
}
|
||||
|
||||
GST_START_TEST (test_unref_threaded)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstMiniObject *mobj;
|
||||
int i;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
mobj = GST_MINI_OBJECT (buffer);
|
||||
|
||||
for (i = 0; i < num_threads * refs_per_thread; ++i)
|
||||
gst_mini_object_ref (mobj);
|
||||
|
||||
MAIN_START_THREADS (num_threads, thread_unref, mobj);
|
||||
|
||||
MAIN_STOP_THREADS ();
|
||||
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (mobj, "miniobject", 1);
|
||||
|
||||
/* final unref */
|
||||
gst_mini_object_unref (mobj);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_mini_object_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstMiniObject");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
/* turn off timeout */
|
||||
tcase_set_timeout (tc_chain, 60);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_copy);
|
||||
tcase_add_test (tc_chain, test_is_writable);
|
||||
tcase_add_test (tc_chain, test_make_writable);
|
||||
tcase_add_test (tc_chain, test_ref_threaded);
|
||||
tcase_add_test (tc_chain, test_unref_threaded);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_mini_object_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;
|
||||
}
|
|
@ -1,474 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for GstObject
|
||||
*
|
||||
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
/*
|
||||
Create a fake subclass
|
||||
*/
|
||||
typedef struct _GstFakeObjectClass GstFakeObjectClass;
|
||||
typedef struct _GstFakeObject GstFakeObject;
|
||||
|
||||
struct _GstFakeObject
|
||||
{
|
||||
GstObject object;
|
||||
};
|
||||
|
||||
struct _GstFakeObjectClass
|
||||
{
|
||||
GstObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType _gst_fake_object_type = 0;
|
||||
|
||||
//static GstObjectClass *parent_class = NULL;
|
||||
//static guint gst_fake_object_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GType
|
||||
gst_fake_object_get_type (void)
|
||||
{
|
||||
if (!_gst_fake_object_type) {
|
||||
static const GTypeInfo fake_object_info = {
|
||||
sizeof (GstFakeObjectClass),
|
||||
NULL, //gst_fake_object_base_class_init,
|
||||
NULL, //gst_fake_object_base_class_finalize,
|
||||
NULL, //(GClassInitFunc) gst_fake_object_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstFakeObject),
|
||||
0,
|
||||
NULL, //(GInstanceInitFunc) gst_fake_object_init,
|
||||
NULL
|
||||
};
|
||||
|
||||
_gst_fake_object_type = g_type_register_static (GST_TYPE_OBJECT,
|
||||
"GstFakeObject", &fake_object_info, 0);
|
||||
}
|
||||
return _gst_fake_object_type;
|
||||
}
|
||||
|
||||
/* g_object_new on abstract GstObject should fail */
|
||||
GST_START_TEST (test_fail_abstract_new)
|
||||
{
|
||||
GstObject *object;
|
||||
|
||||
ASSERT_CRITICAL (object = g_object_new (gst_object_get_type (), NULL));
|
||||
fail_unless (object == NULL, "Created an instance of abstract GstObject");
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* g_object_new on GstFakeObject should succeed */
|
||||
GST_START_TEST (test_fake_object_new)
|
||||
{
|
||||
GstObject *object;
|
||||
|
||||
object = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
fail_if (object == NULL, "Failed to create instance of GstFakeObject");
|
||||
fail_unless (GST_IS_OBJECT (object),
|
||||
"GstFakeObject instance is not a GstObject");
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* GstFakeObject name tests */
|
||||
GST_START_TEST (test_fake_object_name)
|
||||
{
|
||||
GstObject *object;
|
||||
gchar *name;
|
||||
gchar *name2;
|
||||
|
||||
object = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
|
||||
name = gst_object_get_name (object);
|
||||
fail_if (name == NULL, "Newly created object has no name");
|
||||
fail_if (strncmp (name, "fakeobject", 10) != 0,
|
||||
"Random name %s does not start with Gst", name);
|
||||
|
||||
/* give a random name by setting with NULL;
|
||||
* GstFakeObject class -> fakeobject%d */
|
||||
gst_object_set_name (object, NULL);
|
||||
name = gst_object_get_name (object);
|
||||
fail_if (name == NULL, "Random name was not assigned");
|
||||
fail_if (strncmp (name, "fakeobject", 10) != 0,
|
||||
"Random name %s does not start with Gst", name);
|
||||
g_free (name);
|
||||
|
||||
gst_object_set_name (object, "fake");
|
||||
name = gst_object_get_name (object);
|
||||
fail_if (name == NULL, "Failed to get name of GstFakeObject");
|
||||
fail_if (strcmp (name, "fake") != 0, "Name of GstFakeObject is not 'fake'");
|
||||
|
||||
/* change the gotten name to see that it's a copy and not the original */
|
||||
name[0] = 'm';
|
||||
name2 = gst_object_get_name (object);
|
||||
fail_if (strcmp (name2, "fake") != 0,
|
||||
"Copy of object name affected actual object name");
|
||||
g_free (name);
|
||||
g_free (name2);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* thread function for threaded name change test */
|
||||
gpointer thread_name_object (GstObject * object)
|
||||
{
|
||||
gchar *thread_id = g_strdup_printf ("%p", g_thread_self ());
|
||||
|
||||
THREAD_START ();
|
||||
|
||||
/* give main thread a head start */
|
||||
g_usleep (100000);
|
||||
|
||||
/* write our name repeatedly */
|
||||
g_message ("THREAD %s: starting loop\n", thread_id);
|
||||
while (THREAD_TEST_RUNNING ()) {
|
||||
gst_object_set_name (object, thread_id);
|
||||
/* a minimal sleep invokes a thread switch */
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
|
||||
/* thread is done, so let's return */
|
||||
g_message ("THREAD %s: set name\n", thread_id);
|
||||
g_free (thread_id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* main thread sets and gets name while other threads set the name
|
||||
* constantly; fails because lock is released inbetween set and get
|
||||
*/
|
||||
|
||||
GST_START_TEST (test_fake_object_name_threaded_wrong)
|
||||
{
|
||||
GstObject *object;
|
||||
gchar *name;
|
||||
gint i;
|
||||
gboolean expected_failure = FALSE;
|
||||
|
||||
g_message ("\nTEST: set/get without lock\n");
|
||||
|
||||
object = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
gst_object_set_name (object, "main");
|
||||
|
||||
MAIN_START_THREADS (5, thread_name_object, object);
|
||||
|
||||
/* start looping and set/get name repeatedly */
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
gst_object_set_name (object, "main");
|
||||
THREAD_SWITCH ();
|
||||
name = gst_object_get_name (object);
|
||||
if (strcmp (name, "main") != 0) {
|
||||
g_message ("MAIN: expected failure during run %d\n", i);
|
||||
expected_failure = TRUE;
|
||||
g_free (name);
|
||||
break;
|
||||
}
|
||||
g_free (name);
|
||||
}
|
||||
MAIN_STOP_THREADS ();
|
||||
|
||||
fail_unless (expected_failure, "name did not get changed");
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/*
|
||||
* main thread sets and gets name directly on struct inside the object lock
|
||||
* succeed because lock is held during set/get, and threads are locked out
|
||||
*/
|
||||
GST_START_TEST (test_fake_object_name_threaded_right)
|
||||
{
|
||||
GstObject *object;
|
||||
gchar *name;
|
||||
gint i;
|
||||
|
||||
g_message ("\nTEST: set/get inside lock\n");
|
||||
|
||||
object = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
gst_object_set_name (object, "main");
|
||||
|
||||
MAIN_START_THREADS (5, thread_name_object, object);
|
||||
|
||||
/* start looping and set/get name repeatedly */
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
GST_OBJECT_LOCK (object);
|
||||
g_free (GST_OBJECT_NAME (object));
|
||||
GST_OBJECT_NAME (object) = g_strdup ("main");
|
||||
THREAD_SWITCH ();
|
||||
name = g_strdup (GST_OBJECT_NAME (object));
|
||||
GST_OBJECT_UNLOCK (object);
|
||||
|
||||
fail_unless (strcmp (name, "main") == 0,
|
||||
"Name got changed while lock held during run %d", i);
|
||||
g_free (name);
|
||||
}
|
||||
MAIN_STOP_THREADS ();
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/*
|
||||
* main thread creates lots of objects
|
||||
* child threads sets default names on objects
|
||||
* then main thread checks uniqueness of object names
|
||||
*/
|
||||
GList * object_list = NULL;
|
||||
gint num_objects = 1000;
|
||||
gint num_threads = 5;
|
||||
|
||||
/* thread function for threaded default name change test */
|
||||
gpointer
|
||||
thread_name_object_default (int *i)
|
||||
{
|
||||
int j;
|
||||
|
||||
THREAD_START ();
|
||||
|
||||
for (j = *i; j < num_objects; j += num_threads) {
|
||||
GstObject *o = GST_OBJECT (g_list_nth_data (object_list, j));
|
||||
|
||||
/* g_message ("THREAD %p: setting default name on object %d\n",
|
||||
g_thread_self (), j); */
|
||||
gst_object_set_name (o, NULL);
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
|
||||
/* thread is done, so let's return */
|
||||
g_message ("THREAD %p: set name\n", g_thread_self ());
|
||||
g_free (i);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_object_name_compare (GstObject * o, GstObject * p)
|
||||
{
|
||||
gint result;
|
||||
|
||||
GST_OBJECT_LOCK (o);
|
||||
GST_OBJECT_LOCK (p);
|
||||
|
||||
if (o->name == NULL && p->name == NULL) {
|
||||
result = 0;
|
||||
} else if (o->name == NULL) {
|
||||
result = -1;
|
||||
} else if (p->name == NULL) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = strcmp (o->name, p->name);
|
||||
}
|
||||
|
||||
GST_OBJECT_UNLOCK (p);
|
||||
GST_OBJECT_UNLOCK (o);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_fake_object_name_threaded_unique)
|
||||
{
|
||||
GstObject *object;
|
||||
gint i;
|
||||
gint *ip;
|
||||
gchar *name1, *name2;
|
||||
GList *l;
|
||||
|
||||
g_message ("\nTEST: uniqueness of default names\n");
|
||||
|
||||
for (i = 0; i < num_objects; ++i) {
|
||||
object = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
object_list = g_list_append (object_list, object);
|
||||
}
|
||||
|
||||
MAIN_INIT ();
|
||||
|
||||
mark_point ();
|
||||
for (i = 0; i < num_threads; ++i) {
|
||||
ip = g_new (gint, 1);
|
||||
*ip = i;
|
||||
MAIN_START_THREAD_FUNCTION (i, thread_name_object_default, ip);
|
||||
}
|
||||
|
||||
mark_point ();
|
||||
MAIN_SYNCHRONIZE ();
|
||||
mark_point ();
|
||||
MAIN_STOP_THREADS ();
|
||||
|
||||
/* sort GList based on object name */
|
||||
/* FIXME: sort and test */
|
||||
g_list_sort (object_list, (GCompareFunc) gst_object_name_compare);
|
||||
|
||||
name1 = gst_object_get_name (GST_OBJECT (object_list->data));
|
||||
for (l = object_list->next; l->next; l = l->next) {
|
||||
g_message ("object with name %s\n", name1);
|
||||
name2 = gst_object_get_name (GST_OBJECT (l->data));
|
||||
fail_if (strcmp (name1, name2) == 0, "Two objects with name %s", name2);
|
||||
g_free (name1);
|
||||
name1 = name2;
|
||||
}
|
||||
|
||||
/* free stuff */
|
||||
g_list_foreach (object_list, (GFunc) g_object_unref, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* parentage test on GstFakeObject */
|
||||
GST_START_TEST (test_fake_object_parentage)
|
||||
{
|
||||
GstObject *object1, *object2;
|
||||
GstObject *parent;
|
||||
gboolean result;
|
||||
|
||||
/* create new object */
|
||||
object1 = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
fail_if (object1 == NULL, "Failed to create instance of GstFakeObject");
|
||||
fail_unless (GST_IS_OBJECT (object1),
|
||||
"GstFakeObject instance is not a GstObject");
|
||||
fail_unless (GST_OBJECT_IS_FLOATING (object1),
|
||||
"GstFakeObject instance is not floating");
|
||||
|
||||
/* check the parent */
|
||||
parent = gst_object_get_parent (object1);
|
||||
fail_if (parent != NULL, "GstFakeObject has parent");
|
||||
/* try to set a NULL parent, this should give a warning */
|
||||
ASSERT_CRITICAL (result = gst_object_set_parent (object1, NULL));
|
||||
fail_if (result == TRUE, "GstFakeObject accepted NULL parent");
|
||||
/* try to set itself as parent, we expect a warning here */
|
||||
ASSERT_CRITICAL (result = gst_object_set_parent (object1, object1));
|
||||
fail_if (result == TRUE, "GstFakeObject accepted itself as parent");
|
||||
|
||||
/* should still be floating */
|
||||
fail_unless (GST_OBJECT_IS_FLOATING (object1),
|
||||
"GstFakeObject instance is not floating");
|
||||
|
||||
/* create another object */
|
||||
object2 = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
fail_if (object2 == NULL,
|
||||
"Failed to create another instance of GstFakeObject");
|
||||
fail_unless (GST_IS_OBJECT (object2),
|
||||
"second GstFakeObject instance is not a GstObject");
|
||||
fail_unless (GST_OBJECT_IS_FLOATING (object1),
|
||||
"GstFakeObject instance is not floating");
|
||||
|
||||
/* try to set other object as parent */
|
||||
result = gst_object_set_parent (object1, object2);
|
||||
fail_if (result == FALSE,
|
||||
"GstFakeObject could not accept other object as parent");
|
||||
|
||||
/* should not be floating anymore */
|
||||
fail_if (GST_OBJECT_IS_FLOATING (object1),
|
||||
"GstFakeObject instance is still floating");
|
||||
/* parent should still be floating */
|
||||
fail_unless (GST_OBJECT_IS_FLOATING (object2),
|
||||
"GstFakeObject instance is not floating");
|
||||
|
||||
/* check the parent */
|
||||
parent = gst_object_get_parent (object1);
|
||||
fail_if (parent != object2, "GstFakeObject has wrong parent");
|
||||
gst_object_unref (parent);
|
||||
/* try to set other object as parent again */
|
||||
result = gst_object_set_parent (object1, object2);
|
||||
fail_if (result == TRUE, "GstFakeObject could set parent twice");
|
||||
|
||||
/* ref before unparenting */
|
||||
gst_object_ref (object1);
|
||||
/* clear parent of object */
|
||||
gst_object_unparent (object1);
|
||||
|
||||
/* check the parent */
|
||||
parent = gst_object_get_parent (object1);
|
||||
fail_if (parent != NULL, "GstFakeObject has parent");
|
||||
|
||||
/* object should not be floating */
|
||||
fail_if (GST_OBJECT_IS_FLOATING (object1),
|
||||
"GstFakeObject instance is floating again");
|
||||
|
||||
gst_object_unref (object1);
|
||||
gst_object_unref (object2);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* parentage test dispose on GstFakeObject, since our testcase
|
||||
* does not handle the parent relation completely, the parent does
|
||||
* not hold a ref to the child, we cannot dispose the parent to
|
||||
* dipose the child as well. This test needs to be run with DEBUG
|
||||
* info to check if the finalize methods are called correctly. */
|
||||
GST_START_TEST (test_fake_object_parentage_dispose)
|
||||
{
|
||||
GstObject *object1, *object2;
|
||||
gboolean result;
|
||||
|
||||
object1 = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
fail_if (object1 == NULL, "Failed to create instance of GstFakeObject");
|
||||
|
||||
object2 = g_object_new (gst_fake_object_get_type (), NULL);
|
||||
fail_if (object2 == NULL, "Failed to create instance of GstFakeObject");
|
||||
|
||||
/* try to set other object as parent */
|
||||
result = gst_object_set_parent (object1, object2);
|
||||
fail_if (result == FALSE,
|
||||
"GstFakeObject could not accept other object as parent");
|
||||
|
||||
/* clear parent of object */
|
||||
gst_object_unparent (object1);
|
||||
|
||||
/* now dispose parent */
|
||||
gst_object_unref (object2);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* test: try renaming a parented object, make sure it fails */
|
||||
Suite * gst_object_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstObject");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
/* turn off timeout */
|
||||
tcase_set_timeout (tc_chain, 60);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_fake_object_new);
|
||||
tcase_add_test (tc_chain, test_fake_object_name);
|
||||
tcase_add_test (tc_chain, test_fake_object_name_threaded_wrong);
|
||||
tcase_add_test (tc_chain, test_fake_object_name_threaded_right);
|
||||
tcase_add_test (tc_chain, test_fake_object_name_threaded_unique);
|
||||
tcase_add_test (tc_chain, test_fake_object_parentage);
|
||||
tcase_add_test (tc_chain, test_fake_object_parentage_dispose);
|
||||
//tcase_add_checked_fixture (tc_chain, setup, teardown);
|
||||
|
||||
/* SEGV tests go last so we can debug the others */
|
||||
tcase_add_test_raise_signal (tc_chain, test_fail_abstract_new, SIGSEGV);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_object_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;
|
||||
}
|
|
@ -1,419 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstpad.c: Unit test for GstPad
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_link)
|
||||
{
|
||||
GstPad *src, *sink;
|
||||
GstPadTemplate *srct;
|
||||
|
||||
GstPadLinkReturn ret;
|
||||
gchar *name;
|
||||
|
||||
src = gst_pad_new ("source", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
|
||||
|
||||
name = gst_pad_get_name (src);
|
||||
fail_unless (strcmp (name, "source") == 0);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
|
||||
g_free (name);
|
||||
|
||||
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
fail_if (sink == NULL);
|
||||
|
||||
/* linking without templates or caps should fail */
|
||||
ret = gst_pad_link (src, sink);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink pad", 1);
|
||||
fail_unless (ret == GST_PAD_LINK_NOFORMAT);
|
||||
|
||||
ASSERT_CRITICAL (gst_pad_get_pad_template (NULL));
|
||||
|
||||
srct = gst_pad_get_pad_template (src);
|
||||
fail_unless (srct == NULL);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
|
||||
|
||||
/* clean up */
|
||||
ASSERT_OBJECT_REFCOUNT (src, "source pad", 1);
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* threaded link/unlink */
|
||||
/* use globals */
|
||||
GstPad *src, *sink;
|
||||
|
||||
void
|
||||
thread_link_unlink (gpointer data)
|
||||
{
|
||||
THREAD_START ();
|
||||
|
||||
while (THREAD_TEST_RUNNING ()) {
|
||||
gst_pad_link (src, sink);
|
||||
gst_pad_unlink (src, sink);
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
}
|
||||
|
||||
GST_START_TEST (test_link_unlink_threaded)
|
||||
{
|
||||
GstCaps *caps;
|
||||
int i;
|
||||
|
||||
src = gst_pad_new ("source", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
fail_if (sink == NULL);
|
||||
|
||||
caps = gst_caps_from_string ("foo/bar");
|
||||
gst_pad_set_caps (src, caps);
|
||||
gst_pad_set_caps (sink, caps);
|
||||
|
||||
MAIN_START_THREADS (5, thread_link_unlink, NULL);
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
gst_pad_is_linked (src);
|
||||
gst_pad_is_linked (sink);
|
||||
THREAD_SWITCH ();
|
||||
}
|
||||
MAIN_STOP_THREADS ();
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_refcount)
|
||||
{
|
||||
GstPad *src, *sink;
|
||||
GstCaps *caps;
|
||||
GstPadLinkReturn plr;
|
||||
|
||||
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
fail_if (sink == NULL);
|
||||
|
||||
src = gst_pad_new ("src", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
|
||||
caps = gst_caps_from_string ("foo/bar");
|
||||
/* one for me */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
|
||||
gst_pad_set_caps (src, caps);
|
||||
gst_pad_set_caps (sink, caps);
|
||||
/* one for me and one for each set_caps */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
plr = gst_pad_link (src, sink);
|
||||
fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
gst_pad_unlink (src, sink);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
/* cleanup */
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_get_allowed_caps)
|
||||
{
|
||||
GstPad *src, *sink;
|
||||
GstCaps *caps, *gotcaps;
|
||||
GstBuffer *buffer;
|
||||
GstPadLinkReturn plr;
|
||||
|
||||
ASSERT_CRITICAL (gst_pad_get_allowed_caps (NULL));
|
||||
|
||||
buffer = gst_buffer_new ();
|
||||
ASSERT_CRITICAL (gst_pad_get_allowed_caps ((GstPad *) buffer));
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
ASSERT_CRITICAL (gst_pad_get_allowed_caps (sink));
|
||||
|
||||
src = gst_pad_new ("src", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
caps = gst_pad_get_allowed_caps (src);
|
||||
fail_unless (caps == NULL);
|
||||
|
||||
caps = gst_caps_from_string ("foo/bar");
|
||||
|
||||
gst_pad_set_caps (src, caps);
|
||||
gst_pad_set_caps (sink, caps);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
plr = gst_pad_link (src, sink);
|
||||
fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
|
||||
|
||||
gotcaps = gst_pad_get_allowed_caps (src);
|
||||
fail_if (gotcaps == NULL);
|
||||
fail_unless (gst_caps_is_equal (gotcaps, caps));
|
||||
|
||||
ASSERT_CAPS_REFCOUNT (gotcaps, "gotcaps", 1);
|
||||
gst_caps_unref (gotcaps);
|
||||
|
||||
gst_pad_unlink (src, sink);
|
||||
|
||||
/* cleanup */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static gboolean
|
||||
name_is_valid (const gchar * name, GstPadPresence presence)
|
||||
{
|
||||
GstPadTemplate *new;
|
||||
|
||||
new = gst_pad_template_new (name, GST_PAD_SRC, presence, GST_CAPS_ANY);
|
||||
if (new) {
|
||||
gst_object_unref (GST_OBJECT (new));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_name_is_valid)
|
||||
{
|
||||
gboolean result = FALSE;
|
||||
|
||||
fail_unless (name_is_valid ("src", GST_PAD_ALWAYS));
|
||||
ASSERT_WARNING (name_is_valid ("src%", GST_PAD_ALWAYS));
|
||||
ASSERT_WARNING (result = name_is_valid ("src%d", GST_PAD_ALWAYS));
|
||||
fail_if (result);
|
||||
|
||||
fail_unless (name_is_valid ("src", GST_PAD_REQUEST));
|
||||
ASSERT_WARNING (name_is_valid ("src%s%s", GST_PAD_REQUEST));
|
||||
ASSERT_WARNING (name_is_valid ("src%c", GST_PAD_REQUEST));
|
||||
ASSERT_WARNING (name_is_valid ("src%", GST_PAD_REQUEST));
|
||||
ASSERT_WARNING (name_is_valid ("src%dsrc", GST_PAD_REQUEST));
|
||||
|
||||
fail_unless (name_is_valid ("src", GST_PAD_SOMETIMES));
|
||||
fail_unless (name_is_valid ("src%c", GST_PAD_SOMETIMES));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static gboolean
|
||||
_probe_handler (GstPad * pad, GstBuffer * buffer, gpointer userdata)
|
||||
{
|
||||
gint ret = GPOINTER_TO_INT (userdata);
|
||||
|
||||
if (ret == 1)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_push_unlinked)
|
||||
{
|
||||
GstPad *src;
|
||||
GstCaps *caps;
|
||||
GstBuffer *buffer;
|
||||
gulong id;
|
||||
|
||||
src = gst_pad_new ("src", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
caps = gst_pad_get_allowed_caps (src);
|
||||
fail_unless (caps == NULL);
|
||||
|
||||
caps = gst_caps_from_string ("foo/bar");
|
||||
|
||||
gst_pad_set_caps (src, caps);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
|
||||
|
||||
/* pushing on an unlinked pad will drop the buffer */
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_LINKED);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* adding a probe that returns FALSE will drop the buffer without trying
|
||||
* to chain */
|
||||
id = gst_pad_add_buffer_probe (src, (GCallback) _probe_handler,
|
||||
GINT_TO_POINTER (0));
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
gst_pad_remove_buffer_probe (src, id);
|
||||
|
||||
/* adding a probe that returns TRUE will still chain the buffer,
|
||||
* and hence drop because pad is unlinked */
|
||||
id = gst_pad_add_buffer_probe (src, (GCallback) _probe_handler,
|
||||
GINT_TO_POINTER (1));
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_LINKED);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
gst_pad_remove_buffer_probe (src, id);
|
||||
|
||||
|
||||
/* cleanup */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
|
||||
gst_object_unref (src);
|
||||
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_push_linked)
|
||||
{
|
||||
GstPad *src, *sink;
|
||||
GstPadLinkReturn plr;
|
||||
GstCaps *caps;
|
||||
GstBuffer *buffer;
|
||||
ulong id;
|
||||
|
||||
/* setup */
|
||||
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
fail_if (sink == NULL);
|
||||
gst_pad_set_chain_function (sink, gst_check_chain_func);
|
||||
|
||||
src = gst_pad_new ("src", GST_PAD_SRC);
|
||||
fail_if (src == NULL);
|
||||
|
||||
caps = gst_caps_from_string ("foo/bar");
|
||||
/* one for me */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
|
||||
gst_pad_set_caps (src, caps);
|
||||
gst_pad_set_caps (sink, caps);
|
||||
/* one for me and one for each set_caps */
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
plr = gst_pad_link (src, sink);
|
||||
fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
|
||||
/* test */
|
||||
/* pushing on a linked pad will drop the ref to the buffer */
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 2);
|
||||
gst_buffer_unref (buffer);
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
buffer = GST_BUFFER (buffers->data);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
g_list_free (buffers);
|
||||
buffers = NULL;
|
||||
|
||||
/* adding a probe that returns FALSE will drop the buffer without trying
|
||||
* to chain */
|
||||
id = gst_pad_add_buffer_probe (src, (GCallback) _probe_handler,
|
||||
GINT_TO_POINTER (0));
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
gst_pad_remove_buffer_probe (src, id);
|
||||
fail_unless_equals_int (g_list_length (buffers), 0);
|
||||
|
||||
/* adding a probe that returns TRUE will still chain the buffer */
|
||||
id = gst_pad_add_buffer_probe (src, (GCallback) _probe_handler,
|
||||
GINT_TO_POINTER (1));
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_ref (buffer);
|
||||
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
|
||||
gst_pad_remove_buffer_probe (src, id);
|
||||
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 2);
|
||||
gst_buffer_unref (buffer);
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
buffer = GST_BUFFER (buffers->data);
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
|
||||
gst_buffer_unref (buffer);
|
||||
g_list_free (buffers);
|
||||
buffers = NULL;
|
||||
|
||||
/* teardown */
|
||||
gst_pad_unlink (src, sink);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
|
||||
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
Suite *
|
||||
gst_pad_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstPad");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
/* turn off timeout */
|
||||
tcase_set_timeout (tc_chain, 60);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_link);
|
||||
tcase_add_test (tc_chain, test_refcount);
|
||||
tcase_add_test (tc_chain, test_get_allowed_caps);
|
||||
tcase_add_test (tc_chain, test_link_unlink_threaded);
|
||||
tcase_add_test (tc_chain, test_name_is_valid);
|
||||
tcase_add_test (tc_chain, test_push_unlinked);
|
||||
tcase_add_test (tc_chain, test_push_linked);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_pad_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;
|
||||
}
|
|
@ -1,525 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstpipeline.c: Unit test for GstPipeline
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
#define WAIT_TIME (300 * GST_MSECOND)
|
||||
|
||||
/* an empty pipeline can go to PLAYING in one go */
|
||||
GST_START_TEST (test_async_state_change_empty)
|
||||
{
|
||||
GstPipeline *pipeline;
|
||||
|
||||
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
|
||||
GST_STATE_PLAYING), GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_async_state_change_fake_ready)
|
||||
{
|
||||
GstPipeline *pipeline;
|
||||
GstElement *src, *sink;
|
||||
|
||||
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
||||
gst_element_link (src, sink);
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
|
||||
GST_STATE_READY), GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_async_state_change_fake)
|
||||
{
|
||||
GstPipeline *pipeline;
|
||||
GstElement *src, *sink;
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
|
||||
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
||||
gst_element_link (src, sink);
|
||||
|
||||
bus = gst_pipeline_get_bus (pipeline);
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
|
||||
GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
|
||||
|
||||
while (!done) {
|
||||
GstMessage *message;
|
||||
GstState old, new, pending;
|
||||
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
|
||||
if (message) {
|
||||
gst_message_parse_state_changed (message, &old, &new, &pending);
|
||||
GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new);
|
||||
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING)
|
||||
done = TRUE;
|
||||
gst_message_unref (message);
|
||||
}
|
||||
}
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (GST_ELEMENT (pipeline),
|
||||
GST_STATE_NULL), GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_get_bus)
|
||||
{
|
||||
GstPipeline *pipeline;
|
||||
GstBus *bus;
|
||||
|
||||
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
bus = gst_pipeline_get_bus (pipeline);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline after get_bus", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus after unref pipeline", 1);
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GMainLoop *loop = NULL;
|
||||
|
||||
gboolean
|
||||
message_received (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
GstElement *pipeline = GST_ELEMENT (data);
|
||||
GstMessageType type = message->type;
|
||||
|
||||
GST_DEBUG ("message received");
|
||||
switch (type) {
|
||||
case GST_MESSAGE_STATE_CHANGED:
|
||||
{
|
||||
GstState old, new, pending;
|
||||
|
||||
GST_DEBUG ("state change message received");
|
||||
gst_message_parse_state_changed (message, &old, &new, &pending);
|
||||
GST_DEBUG ("new state %d", new);
|
||||
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) {
|
||||
GST_DEBUG ("quitting main loop");
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GST_MESSAGE_ERROR:
|
||||
{
|
||||
g_print ("error\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_bus)
|
||||
{
|
||||
GstElement *pipeline;
|
||||
GstElement *src, *sink;
|
||||
GstBus *bus;
|
||||
guint id;
|
||||
GstState current;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
fail_unless (pipeline != NULL, "Could not create pipeline");
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", NULL);
|
||||
fail_unless (src != NULL);
|
||||
sink = gst_element_factory_make ("fakesink", NULL);
|
||||
fail_unless (sink != NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
||||
fail_unless (gst_element_link (src, sink));
|
||||
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline after get_bus", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
|
||||
id = gst_bus_add_watch (bus, message_received, pipeline);
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline after add_watch", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus after add_watch", 3);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
GST_DEBUG ("going into main loop");
|
||||
g_main_loop_run (loop);
|
||||
GST_DEBUG ("left main loop");
|
||||
|
||||
/* PLAYING now */
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "pipeline after gone to playing", 1,
|
||||
3);
|
||||
|
||||
/* cleanup */
|
||||
GST_DEBUG ("cleanup");
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
ret = gst_element_get_state (pipeline, ¤t, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
||||
fail_unless (current == GST_STATE_NULL, "state is not NULL but %d", current);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline at start of cleanup", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus at start of cleanup", 3);
|
||||
|
||||
fail_unless (g_source_remove (id));
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus after removing source", 2);
|
||||
|
||||
GST_DEBUG ("unreffing pipeline");
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus after unref pipeline", 1);
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static GMutex *probe_lock;
|
||||
static GCond *probe_cond;
|
||||
|
||||
static gboolean
|
||||
sink_pad_probe (GstPad * pad, GstBuffer * buffer,
|
||||
GstClockTime * first_timestamp)
|
||||
{
|
||||
fail_if (GST_BUFFER_TIMESTAMP (buffer) == GST_CLOCK_TIME_NONE,
|
||||
"testing if buffer timestamps are right, but got CLOCK_TIME_NONE");
|
||||
|
||||
if (*first_timestamp == GST_CLOCK_TIME_NONE) {
|
||||
*first_timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
||||
}
|
||||
|
||||
g_mutex_lock (probe_lock);
|
||||
g_cond_signal (probe_cond);
|
||||
g_mutex_unlock (probe_lock);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_base_time)
|
||||
{
|
||||
GstElement *pipeline, *fakesrc, *fakesink;
|
||||
GstPad *sink;
|
||||
GstClockTime observed, lower, upper, base, stream;
|
||||
GstClock *clock;
|
||||
|
||||
pipeline = gst_element_factory_make ("pipeline", "pipeline");
|
||||
fakesrc = gst_element_factory_make ("fakesrc", "fakesrc");
|
||||
fakesink = gst_element_factory_make ("fakesink", "fakesink");
|
||||
|
||||
fail_unless (pipeline && fakesrc && fakesink, "couldn't make elements");
|
||||
|
||||
g_object_set (fakesrc, "is-live", (gboolean) TRUE, NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
sink = gst_element_get_pad (fakesink, "sink");
|
||||
gst_pad_add_buffer_probe (sink, G_CALLBACK (sink_pad_probe), &observed);
|
||||
|
||||
fail_unless (gst_element_set_state (pipeline, GST_STATE_PAUSED)
|
||||
== GST_STATE_CHANGE_NO_PREROLL, "expected no-preroll from live pipeline");
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
fail_unless (clock && GST_IS_CLOCK (clock), "i want a clock dammit");
|
||||
gst_pipeline_use_clock (GST_PIPELINE (pipeline), clock);
|
||||
|
||||
fail_unless (gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline)) == 0,
|
||||
"stream time doesn't start off at 0");
|
||||
|
||||
probe_lock = g_mutex_new ();
|
||||
probe_cond = g_cond_new ();
|
||||
|
||||
/* test the first: that base time is being distributed correctly, timestamps
|
||||
are correct relative to the running clock and base time */
|
||||
{
|
||||
lower = gst_clock_get_time (clock);
|
||||
|
||||
observed = GST_CLOCK_TIME_NONE;
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_SUCCESS, "failed state change");
|
||||
|
||||
g_mutex_lock (probe_lock);
|
||||
while (observed == GST_CLOCK_TIME_NONE)
|
||||
g_cond_wait (probe_cond, probe_lock);
|
||||
g_mutex_unlock (probe_lock);
|
||||
|
||||
/* now something a little more than lower was distributed as the base time,
|
||||
* and the buffer was timestamped between 0 and upper-base
|
||||
*/
|
||||
|
||||
base = gst_element_get_base_time (pipeline);
|
||||
fail_if (base == GST_CLOCK_TIME_NONE);
|
||||
|
||||
/* set stream time */
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
/* pulling upper here makes sure that the pipeline's new stream time has
|
||||
already been computed */
|
||||
upper = gst_clock_get_time (clock);
|
||||
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_NO_PREROLL, "failed state change");
|
||||
|
||||
fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded");
|
||||
|
||||
fail_unless (base >= lower, "early base time: %" GST_TIME_FORMAT " < %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (base), GST_TIME_ARGS (lower));
|
||||
fail_unless (upper >= base, "bogus base time: %" GST_TIME_FORMAT " > %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (base), GST_TIME_ARGS (upper));
|
||||
|
||||
stream = gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline));
|
||||
|
||||
fail_unless (stream > 0, "bogus new stream time: %" GST_TIME_FORMAT " > %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (stream), GST_TIME_ARGS (0));
|
||||
fail_unless (stream <= upper,
|
||||
"bogus new stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (stream), GST_TIME_ARGS (upper));
|
||||
|
||||
fail_unless (observed <= stream, "timestamps outrun stream time: %"
|
||||
GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (stream));
|
||||
fail_unless (observed >= 0, "early timestamp: %" GST_TIME_FORMAT " < %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (observed),
|
||||
GST_TIME_ARGS (lower - base));
|
||||
fail_unless (observed <= upper - base,
|
||||
"late timestamp: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base));
|
||||
}
|
||||
|
||||
/* test the second: that the base time is redistributed when we go to PLAYING
|
||||
again */
|
||||
{
|
||||
GstClockID clock_id;
|
||||
GstClockTime oldbase = base, oldstream = stream;
|
||||
|
||||
/* let some time pass */
|
||||
clock_id = gst_clock_new_single_shot_id (clock, upper + WAIT_TIME);
|
||||
fail_unless (gst_clock_id_wait (clock_id, NULL) == GST_CLOCK_OK,
|
||||
"unexpected clock_id_wait return");
|
||||
gst_clock_id_unref (clock_id);
|
||||
|
||||
lower = gst_clock_get_time (clock);
|
||||
fail_if (lower == GST_CLOCK_TIME_NONE);
|
||||
|
||||
observed = GST_CLOCK_TIME_NONE;
|
||||
|
||||
fail_unless (lower >= upper + WAIT_TIME, "clock did not advance?");
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_SUCCESS, "failed state change");
|
||||
|
||||
g_mutex_lock (probe_lock);
|
||||
while (observed == GST_CLOCK_TIME_NONE)
|
||||
g_cond_wait (probe_cond, probe_lock);
|
||||
g_mutex_unlock (probe_lock);
|
||||
|
||||
/* now the base time should have advanced by more than WAIT_TIME compared
|
||||
* to what it was. The buffer will be timestamped between the last stream
|
||||
* time and upper minus base.
|
||||
*/
|
||||
|
||||
base = gst_element_get_base_time (pipeline);
|
||||
fail_if (base == GST_CLOCK_TIME_NONE);
|
||||
|
||||
/* set stream time */
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
/* new stream time already set */
|
||||
upper = gst_clock_get_time (clock);
|
||||
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_NO_PREROLL, "failed state change");
|
||||
|
||||
fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded");
|
||||
|
||||
stream = gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline));
|
||||
|
||||
fail_unless (base >= oldbase + WAIT_TIME, "base time not reset");
|
||||
fail_unless (upper >= base + stream, "bogus base time: %"
|
||||
GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (base),
|
||||
GST_TIME_ARGS (upper));
|
||||
|
||||
fail_unless (lower >= base);
|
||||
fail_unless (observed >= lower - base, "early timestamp: %"
|
||||
GST_TIME_FORMAT " < %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (lower - base));
|
||||
fail_unless (observed <= upper - base, "late timestamp: %"
|
||||
GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base));
|
||||
fail_unless (stream - oldstream <= upper - lower,
|
||||
"insufficient stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (upper));
|
||||
}
|
||||
|
||||
/* test the third: that if I set CLOCK_TIME_NONE as the stream time, that the
|
||||
base time is not changed */
|
||||
{
|
||||
GstClockID clock_id;
|
||||
GstClockTime oldbase = base, oldobserved = observed;
|
||||
GstClockReturn ret;
|
||||
|
||||
/* let some time pass */
|
||||
clock_id = gst_clock_new_single_shot_id (clock, upper + WAIT_TIME);
|
||||
ret = gst_clock_id_wait (clock_id, NULL);
|
||||
fail_unless (ret == GST_CLOCK_OK,
|
||||
"unexpected clock_id_wait return %d", ret);
|
||||
gst_clock_id_unref (clock_id);
|
||||
|
||||
lower = gst_clock_get_time (clock);
|
||||
|
||||
observed = GST_CLOCK_TIME_NONE;
|
||||
|
||||
fail_unless (lower >= upper + WAIT_TIME, "clock did not advance?");
|
||||
|
||||
/* bling */
|
||||
gst_pipeline_set_new_stream_time (GST_PIPELINE (pipeline),
|
||||
GST_CLOCK_TIME_NONE);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_SUCCESS, "failed state change");
|
||||
|
||||
g_mutex_lock (probe_lock);
|
||||
while (observed == GST_CLOCK_TIME_NONE)
|
||||
g_cond_wait (probe_cond, probe_lock);
|
||||
g_mutex_unlock (probe_lock);
|
||||
|
||||
/* now the base time should be the same as it was, and the timestamp should
|
||||
* be more than WAIT_TIME past what it was.
|
||||
*/
|
||||
|
||||
base = gst_element_get_base_time (pipeline);
|
||||
|
||||
/* set stream time */
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
/* new stream time already set */
|
||||
upper = gst_clock_get_time (clock);
|
||||
|
||||
fail_unless (gst_element_get_state (pipeline, NULL, NULL,
|
||||
GST_CLOCK_TIME_NONE)
|
||||
== GST_STATE_CHANGE_NO_PREROLL, "failed state change");
|
||||
|
||||
fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded");
|
||||
|
||||
fail_unless (gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline))
|
||||
== GST_CLOCK_TIME_NONE, "stream time was reset");
|
||||
|
||||
fail_unless (base == oldbase, "base time was reset");
|
||||
|
||||
fail_unless (observed >= lower - base, "early timestamp: %"
|
||||
GST_TIME_FORMAT " < %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (lower - base));
|
||||
fail_unless (observed <= upper - base, "late timestamp: %"
|
||||
GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base));
|
||||
fail_unless (observed - oldobserved >= WAIT_TIME,
|
||||
"insufficient tstamp delta: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (observed), GST_TIME_ARGS (oldobserved));
|
||||
}
|
||||
|
||||
gst_object_unref (sink);
|
||||
gst_object_unref (clock);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_pipeline_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstPipeline");
|
||||
TCase *tc_chain = tcase_create ("pipeline tests");
|
||||
|
||||
tcase_set_timeout (tc_chain, 0);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_async_state_change_empty);
|
||||
tcase_add_test (tc_chain, test_async_state_change_fake_ready);
|
||||
tcase_add_test (tc_chain, test_async_state_change_fake);
|
||||
tcase_add_test (tc_chain, test_get_bus);
|
||||
tcase_add_test (tc_chain, test_bus);
|
||||
tcase_add_test (tc_chain, test_base_time);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_pipeline_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
srunner_set_log (sr, "test.log");
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
|
@ -1,331 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for GstPlugin
|
||||
*
|
||||
* Copyright 2004 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
* Copyright 2005 David Schleef <ds@schleef.org>
|
||||
*
|
||||
* 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 "config.h"
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
static gboolean
|
||||
register_check_elements (GstPlugin * plugin)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstPluginDesc plugin_desc = {
|
||||
GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"check elements",
|
||||
"check elements",
|
||||
register_check_elements,
|
||||
VERSION,
|
||||
GST_LICENSE,
|
||||
PACKAGE,
|
||||
GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN,
|
||||
|
||||
GST_PADDING_INIT
|
||||
};
|
||||
|
||||
GST_START_TEST (test_register_static)
|
||||
{
|
||||
GstPlugin *plugin;
|
||||
|
||||
_gst_plugin_register_static (&plugin_desc);
|
||||
|
||||
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
|
||||
|
||||
gst_object_unref (plugin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_registry)
|
||||
{
|
||||
GList *g;
|
||||
GstRegistry *registry;
|
||||
|
||||
registry = gst_registry_get_default ();
|
||||
|
||||
for (g = registry->plugins; g; g = g->next) {
|
||||
GstPlugin *plugin = GST_PLUGIN (g->data);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 1);
|
||||
GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
|
||||
plugin->desc.name);
|
||||
}
|
||||
for (g = registry->features; g; g = g->next) {
|
||||
GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 1,
|
||||
"Feature in registry should have refcount of 1");
|
||||
GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
|
||||
feature->name);
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_load_gstelements)
|
||||
{
|
||||
GstPlugin *unloaded_plugin;
|
||||
GstPlugin *loaded_plugin;
|
||||
|
||||
unloaded_plugin = gst_default_registry_find_plugin ("gstelements");
|
||||
fail_if (unloaded_plugin == NULL, "Failed to find gstelements plugin");
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 2,
|
||||
"Refcount of unloaded plugin in registry initially should be 2");
|
||||
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
|
||||
|
||||
loaded_plugin = gst_plugin_load (unloaded_plugin);
|
||||
fail_if (loaded_plugin == NULL, "Failed to load plugin");
|
||||
|
||||
if (loaded_plugin != unloaded_plugin) {
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (loaded_plugin) != 2,
|
||||
"Refcount of loaded plugin in registry should be 2");
|
||||
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (loaded_plugin));
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 1,
|
||||
"Refcount of replaced plugin should be 1");
|
||||
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
|
||||
}
|
||||
|
||||
gst_object_unref (unloaded_plugin);
|
||||
gst_object_unref (loaded_plugin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_registry_get_plugin_list)
|
||||
{
|
||||
GList *list;
|
||||
GstPlugin *plugin;
|
||||
|
||||
plugin = gst_default_registry_find_plugin ("gstelements");
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
||||
"Refcount of plugin in registry should be 2");
|
||||
|
||||
list = gst_registry_get_plugin_list (gst_registry_get_default ());
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
|
||||
"Refcount of plugin in registry+list should be 3");
|
||||
|
||||
gst_plugin_list_free (list);
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
||||
"Refcount of plugin in after list free should be 2");
|
||||
|
||||
gst_object_unref (plugin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_find_plugin)
|
||||
{
|
||||
GstPlugin *plugin;
|
||||
|
||||
plugin = gst_registry_find_plugin (gst_registry_get_default (),
|
||||
"gstelements");
|
||||
fail_if (plugin == NULL, "Failed to find gstelements plugin");
|
||||
ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
|
||||
|
||||
fail_unless_equals_string (plugin->desc.version, VERSION);
|
||||
fail_unless_equals_string (plugin->desc.license, "LGPL");
|
||||
fail_unless_equals_string (plugin->desc.source, "gstreamer");
|
||||
fail_unless_equals_string (plugin->desc.package, GST_PACKAGE_NAME);
|
||||
fail_unless_equals_string (plugin->desc.origin, GST_PACKAGE_ORIGIN);
|
||||
|
||||
gst_object_unref (plugin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_find_feature)
|
||||
{
|
||||
GstPluginFeature *feature;
|
||||
|
||||
feature = gst_registry_find_feature (gst_registry_get_default (),
|
||||
"identity", GST_TYPE_ELEMENT_FACTORY);
|
||||
fail_if (feature == NULL, "Failed to find identity element factory");
|
||||
fail_if (strcmp (feature->plugin_name, "gstelements"),
|
||||
"Expected identity to be from gstelements plugin");
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
|
||||
"Refcount of feature should be 2");
|
||||
GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
|
||||
|
||||
gst_object_unref (feature);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_find_element)
|
||||
{
|
||||
GstElementFactory *element_factory;
|
||||
|
||||
element_factory = gst_element_factory_find ("identity");
|
||||
fail_if (element_factory == NULL, "Failed to find identity element factory");
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
|
||||
"Refcount of plugin in registry+feature should be 2");
|
||||
|
||||
gst_object_unref (element_factory);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
#if 0
|
||||
guint8 *
|
||||
peek (gpointer data, gint64 offset, guint size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
suggest (gpointer data, guint probability, const GstCaps * caps)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GST_START_TEST (test_typefind)
|
||||
{
|
||||
GstPlugin *plugin;
|
||||
GstPluginFeature *feature;
|
||||
GstTypeFind typefind = {
|
||||
peek,
|
||||
suggest,
|
||||
NULL,
|
||||
NULL,
|
||||
GST_PADDING_INIT
|
||||
};
|
||||
|
||||
plugin = gst_default_registry_find_plugin ("typefindfunctions");
|
||||
fail_if (plugin == NULL, "Failed to find typefind functions");
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
|
||||
"Refcount of plugin in registry should be 2");
|
||||
fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
|
||||
|
||||
feature = gst_registry_find_feature (gst_registry_get_default (),
|
||||
"audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
|
||||
fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
|
||||
fail_if (feature->plugin != plugin,
|
||||
"Expected identity to be from gstelements plugin");
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
|
||||
"Refcount of plugin in registry+feature should be 3");
|
||||
|
||||
gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
|
||||
&typefind);
|
||||
|
||||
gst_object_unref (feature->plugin);
|
||||
|
||||
fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
|
||||
"Refcount of plugin in after list free should be 1");
|
||||
|
||||
gst_object_unref (plugin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
#endif
|
||||
|
||||
GST_START_TEST (test_version_checks)
|
||||
{
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
|
||||
"Unexpected version check result");
|
||||
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
|
||||
"Unexpected version check result");
|
||||
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
|
||||
"Unexpected version check result");
|
||||
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) == TRUE,
|
||||
"Unexpected version check result");
|
||||
|
||||
if (GST_VERSION_MAJOR > 0) {
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
|
||||
GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
|
||||
}
|
||||
|
||||
if (GST_VERSION_MINOR > 0) {
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
|
||||
GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
|
||||
}
|
||||
|
||||
if (GST_VERSION_MICRO > 0) {
|
||||
fail_if (gst_default_registry_check_feature_version ("identity",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR,
|
||||
GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
|
||||
}
|
||||
|
||||
fail_if (gst_default_registry_check_feature_version ("entityid",
|
||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
|
||||
"Unexpected version check result");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_plugin_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstPlugin");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
/* turn off timeout */
|
||||
tcase_set_timeout (tc_chain, 60);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_register_static);
|
||||
tcase_add_test (tc_chain, test_registry);
|
||||
tcase_add_test (tc_chain, test_load_gstelements);
|
||||
tcase_add_test (tc_chain, test_registry_get_plugin_list);
|
||||
tcase_add_test (tc_chain, test_find_plugin);
|
||||
tcase_add_test (tc_chain, test_find_feature);
|
||||
tcase_add_test (tc_chain, test_find_element);
|
||||
tcase_add_test (tc_chain, test_version_checks);
|
||||
//tcase_add_test (tc_chain, test_typefind);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_plugin_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;
|
||||
}
|
|
@ -1,532 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
|
||||
*
|
||||
* gstsegment.c: Unit test for segments
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
/* mess with the segment structure in the bytes format */
|
||||
GST_START_TEST (segment_seek_nosize)
|
||||
{
|
||||
GstSegment segment;
|
||||
gboolean res;
|
||||
gint64 cstart, cstop;
|
||||
gboolean update;
|
||||
|
||||
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
||||
|
||||
/* configure segment to start 100 */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == -1);
|
||||
|
||||
/* configure segment to stop relative, should not do anything since
|
||||
* size is unknown. */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == -1);
|
||||
|
||||
/* do some clipping on the open range */
|
||||
/* completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* inside, touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
100, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* completely inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
150, 200, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 200);
|
||||
|
||||
/* invalid start */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* start on lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* start inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* add 100 to start, set stop to 300 */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 300);
|
||||
|
||||
/* add 100 to start (to 300), set stop to 200, this is not allowed.
|
||||
* nothing should be updated in the segment. */
|
||||
ASSERT_CRITICAL (gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update));
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 300);
|
||||
|
||||
/* seek relative to end, should not do anything since size is
|
||||
* unknown. */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update);
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 300);
|
||||
|
||||
/* completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 200, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 250, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 200);
|
||||
fail_unless (cstop == 250);
|
||||
|
||||
/* inside, touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
200, 250, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 200);
|
||||
fail_unless (cstop == 250);
|
||||
|
||||
/* completely inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
250, 290, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 250);
|
||||
fail_unless (cstop == 290);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
250, 350, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 250);
|
||||
fail_unless (cstop == 300);
|
||||
|
||||
/* invalid start */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 200);
|
||||
fail_unless (cstop == 300);
|
||||
|
||||
/* start on lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 200);
|
||||
fail_unless (cstop == 300);
|
||||
|
||||
/* start inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 250);
|
||||
fail_unless (cstop == 300);
|
||||
|
||||
/* start outside on boundary */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 300, -1, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 350, -1, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* mess with the segment structure in the bytes format */
|
||||
GST_START_TEST (segment_seek_size)
|
||||
{
|
||||
GstSegment segment;
|
||||
gboolean res;
|
||||
gint64 cstart, cstop;
|
||||
gboolean update;
|
||||
|
||||
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
||||
gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
|
||||
|
||||
/* configure segment to start 100 */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == -1);
|
||||
|
||||
/* configure segment to stop relative, does not update stop
|
||||
* since we did not set it before. */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == -1);
|
||||
|
||||
/* do some clipping on the open range */
|
||||
/* completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* inside, touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
100, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* completely inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
150, 200, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 200);
|
||||
|
||||
/* partially inside, clip to size */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
150, 300, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 200);
|
||||
|
||||
/* invalid start */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* start on lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* start inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == -1);
|
||||
|
||||
/* add 100 to start, set stop to 300, stop clips to 200 */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 200);
|
||||
|
||||
/* add 100 to start (to 300), set stop to 200, this clips start
|
||||
* to duration */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update);
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 200);
|
||||
|
||||
/* seek relative to end */
|
||||
gst_segment_set_seek (&segment, 1.0,
|
||||
GST_FORMAT_BYTES,
|
||||
GST_SEEK_FLAG_NONE,
|
||||
GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update);
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == 180);
|
||||
|
||||
/* completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* inside, touching lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
100, 150, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 150);
|
||||
|
||||
/* completely inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
150, 170, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 170);
|
||||
|
||||
/* partially inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
|
||||
150, 250, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 180);
|
||||
|
||||
/* invalid start */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 180);
|
||||
|
||||
/* start on lower bound */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 100);
|
||||
fail_unless (cstop == 180);
|
||||
|
||||
/* start inside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
|
||||
fail_unless (res == TRUE);
|
||||
fail_unless (cstart == 150);
|
||||
fail_unless (cstop == 180);
|
||||
|
||||
/* start outside on boundary */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 180, -1, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
|
||||
/* start completely outside */
|
||||
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
|
||||
fail_unless (res == FALSE);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* mess with the segment structure in the bytes format */
|
||||
GST_START_TEST (segment_newsegment_open)
|
||||
{
|
||||
GstSegment segment;
|
||||
|
||||
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
||||
|
||||
/* time should also work for starting from 0 */
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
|
||||
|
||||
fail_unless (segment.rate == 1.0);
|
||||
fail_unless (segment.format == GST_FORMAT_BYTES);
|
||||
fail_unless (segment.flags == 0);
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 0);
|
||||
fail_unless (segment.last_stop == -1);
|
||||
fail_unless (segment.duration == -1);
|
||||
|
||||
/* we set stop but in the wrong format, stop stays open. */
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
|
||||
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 0);
|
||||
|
||||
/* update, nothing changes */
|
||||
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
|
||||
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 0);
|
||||
|
||||
/* update */
|
||||
gst_segment_set_newsegment (&segment, TRUE, 1.0,
|
||||
GST_FORMAT_BYTES, 100, -1, 100);
|
||||
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 100);
|
||||
fail_unless (segment.accum == 100);
|
||||
|
||||
/* last_stop unknown, accum does not change */
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
|
||||
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 100);
|
||||
|
||||
gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
|
||||
|
||||
/* last_stop 200, accum changes */
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
|
||||
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == -1);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 300);
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/* mess with the segment structure in the bytes format */
|
||||
GST_START_TEST (segment_newsegment_closed)
|
||||
{
|
||||
GstSegment segment;
|
||||
|
||||
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
||||
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0,
|
||||
GST_FORMAT_BYTES, 0, 200, 0);
|
||||
|
||||
fail_unless (segment.rate == 1.0);
|
||||
fail_unless (segment.format == GST_FORMAT_BYTES);
|
||||
fail_unless (segment.flags == 0);
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == 200);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 0);
|
||||
fail_unless (segment.last_stop == -1);
|
||||
fail_unless (segment.duration == -1);
|
||||
|
||||
/* do an update */
|
||||
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
|
||||
|
||||
fail_unless (segment.start == 0);
|
||||
fail_unless (segment.stop == 300);
|
||||
fail_unless (segment.time == 0);
|
||||
fail_unless (segment.accum == 0);
|
||||
|
||||
/* and a new accumulated one */
|
||||
gst_segment_set_newsegment (&segment, FALSE, 1.0,
|
||||
GST_FORMAT_BYTES, 100, 400, 300);
|
||||
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == 400);
|
||||
fail_unless (segment.time == 300);
|
||||
fail_unless (segment.accum == 300);
|
||||
|
||||
/* and a new updated one */
|
||||
gst_segment_set_newsegment (&segment, TRUE, 1.0,
|
||||
GST_FORMAT_BYTES, 100, 500, 300);
|
||||
|
||||
fail_unless (segment.start == 100);
|
||||
fail_unless (segment.stop == 500);
|
||||
fail_unless (segment.time == 300);
|
||||
fail_unless (segment.accum == 300);
|
||||
|
||||
/* and a new partially updated one */
|
||||
gst_segment_set_newsegment (&segment, TRUE, 1.0,
|
||||
GST_FORMAT_BYTES, 200, 500, 400);
|
||||
|
||||
fail_unless (segment.start == 200);
|
||||
fail_unless (segment.stop == 500);
|
||||
fail_unless (segment.time == 400);
|
||||
fail_unless (segment.accum == 400);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gstsegments_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstSegment");
|
||||
TCase *tc_chain = tcase_create ("segments");
|
||||
|
||||
tcase_set_timeout (tc_chain, 20);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, segment_seek_nosize);
|
||||
tcase_add_test (tc_chain, segment_seek_size);
|
||||
tcase_add_test (tc_chain, segment_newsegment_open);
|
||||
tcase_add_test (tc_chain, segment_newsegment_closed);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gstsegments_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;
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gststructure.c: Unit tests for GstStructure
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
|
||||
GST_START_TEST (test_from_string_int)
|
||||
{
|
||||
const char *strings[] = {
|
||||
"video/x-raw-rgb, width = (int) 123456",
|
||||
"video/x-raw-rgb, stride = (int) -123456",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x0000FFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x7FFFFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x80000000",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFF000000",
|
||||
/* result from
|
||||
* gst-launch ... ! "video/x-raw-rgb, red_mask=(int)0xFF000000" ! ... */
|
||||
"video/x-raw-rgb,\\ red_mask=(int)0xFF000000",
|
||||
};
|
||||
gint results[] = {
|
||||
123456,
|
||||
-123456,
|
||||
0xFFFF,
|
||||
0xFFFF,
|
||||
0x7FFFFFFF,
|
||||
0x80000000,
|
||||
0xFF000000,
|
||||
0xFF000000,
|
||||
};
|
||||
GstStructure *structure;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
const char *s;
|
||||
const gchar *name;
|
||||
gint value;
|
||||
|
||||
s = strings[i];
|
||||
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
name = gst_structure_nth_field_name (structure, 0);
|
||||
fail_unless (gst_structure_get_int (structure, name, &value));
|
||||
fail_unless (value == results[i],
|
||||
"Value %d is not the expected result %d for string %s",
|
||||
value, results[i], s);
|
||||
|
||||
/* cleanup */
|
||||
gst_structure_free (structure);
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* Test type conversions from string */
|
||||
GST_START_TEST (test_from_string)
|
||||
{
|
||||
GstStructure *structure;
|
||||
const gchar *s;
|
||||
const GValue *val;
|
||||
|
||||
s = "test-string,value=1";
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
|
||||
fail_unless (G_VALUE_HOLDS_INT (val));
|
||||
gst_structure_free (structure);
|
||||
|
||||
s = "test-string,value=1.0";
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
|
||||
fail_unless (G_VALUE_HOLDS_DOUBLE (val));
|
||||
gst_structure_free (structure);
|
||||
|
||||
s = "test-string,value=1/1";
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
|
||||
fail_unless (GST_VALUE_HOLDS_FRACTION (val));
|
||||
gst_structure_free (structure);
|
||||
|
||||
s = "test-string,value=bar";
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
|
||||
fail_unless (G_VALUE_HOLDS_STRING (val));
|
||||
gst_structure_free (structure);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_value_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstStructure");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string_int);
|
||||
return s;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_structure_new)
|
||||
{
|
||||
GstStructure *s;
|
||||
GError *e;
|
||||
GQuark domain;
|
||||
|
||||
s = gst_structure_new ("name", "key", G_TYPE_STRING, "value", NULL);
|
||||
fail_unless (strcmp (gst_structure_get_string (s, "key"), "value") == 0);
|
||||
gst_structure_free (s);
|
||||
|
||||
domain = g_quark_from_string ("test");
|
||||
e = g_error_new (domain, 0, "a test error");
|
||||
s = gst_structure_new ("name", "key", GST_TYPE_G_ERROR, e, NULL);
|
||||
g_error_free (e);
|
||||
gst_structure_free (s);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_structure_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstStructure");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string_int);
|
||||
tcase_add_test (tc_chain, test_from_string);
|
||||
tcase_add_test (tc_chain, test_structure_new);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_structure_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;
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
|
||||
*
|
||||
* gstsystemclock.c: Unit test for GstSystemClock
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
GST_START_TEST (test_signedness)
|
||||
{
|
||||
GstClockTime time[] = { 0, 1, G_MAXUINT64 / GST_SECOND };
|
||||
GstClockTimeDiff diff[] =
|
||||
{ 0, 1, -1, G_MAXINT64 / GST_SECOND, G_MININT64 / GST_SECOND };
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (time); i++) {
|
||||
fail_if (time[i] != (time[i] * GST_SECOND / GST_SECOND));
|
||||
}
|
||||
for (i = 0; i < G_N_ELEMENTS (diff); i++) {
|
||||
fail_if (diff[i] != (diff[i] * GST_SECOND / GST_SECOND));
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
#define TIME_UNIT (GST_SECOND / 5)
|
||||
static void
|
||||
gst_clock_debug (GstClock * clock)
|
||||
{
|
||||
GstClockTime time;
|
||||
|
||||
time = gst_clock_get_time (clock);
|
||||
g_message ("Clock info: time %" G_GUINT64_FORMAT "\n", time);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ok_callback (GstClock * clock, GstClockTime time,
|
||||
GstClockID id, gpointer user_data)
|
||||
{
|
||||
g_message ("unlocked async id %p\n", id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
error_callback (GstClock * clock, GstClockTime time,
|
||||
GstClockID id, gpointer user_data)
|
||||
{
|
||||
g_message ("unlocked unscheduled async id %p, this is wrong\n", id);
|
||||
fail_if (TRUE);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_single_shot)
|
||||
{
|
||||
GstClock *clock;
|
||||
GstClockID id, id2;
|
||||
GstClockTime base;
|
||||
GstClockReturn result;
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
fail_unless (clock != NULL, "Could not create instance of GstSystemClock");
|
||||
|
||||
gst_clock_debug (clock);
|
||||
base = gst_clock_get_time (clock);
|
||||
|
||||
id = gst_clock_new_single_shot_id (clock, base + TIME_UNIT);
|
||||
fail_unless (id != NULL, "Could not create single shot id");
|
||||
|
||||
g_message ("waiting one second\n");
|
||||
result = gst_clock_id_wait (id, NULL);
|
||||
gst_clock_debug (clock);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
|
||||
g_message ("waiting in the past\n");
|
||||
result = gst_clock_id_wait (id, NULL);
|
||||
gst_clock_debug (clock);
|
||||
fail_unless (result == GST_CLOCK_EARLY, "Waiting did not return EARLY");
|
||||
gst_clock_id_unref (id);
|
||||
|
||||
id = gst_clock_new_single_shot_id (clock, base + 2 * TIME_UNIT);
|
||||
g_message ("waiting one second async id %p\n", id);
|
||||
result = gst_clock_id_wait_async (id, ok_callback, NULL);
|
||||
gst_clock_id_unref (id);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
|
||||
id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT);
|
||||
g_message ("waiting one second async, with cancel on id %p\n", id);
|
||||
result = gst_clock_id_wait_async (id, error_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
g_message ("cancel id %p after half a time unit\n", id);
|
||||
gst_clock_id_unschedule (id);
|
||||
gst_clock_id_unref (id);
|
||||
g_message ("canceled id %p\n", id);
|
||||
|
||||
g_message ("waiting multiple one second async, with cancel\n");
|
||||
id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT);
|
||||
id2 = gst_clock_new_single_shot_id (clock, base + 6 * TIME_UNIT);
|
||||
g_message ("waiting id %p\n", id);
|
||||
result = gst_clock_id_wait_async (id, ok_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
gst_clock_id_unref (id);
|
||||
g_message ("waiting id %p\n", id2);
|
||||
result = gst_clock_id_wait_async (id2, error_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
g_message ("cancel id %p after half a time unit\n", id2);
|
||||
gst_clock_id_unschedule (id2);
|
||||
g_message ("canceled id %p\n", id2);
|
||||
gst_clock_id_unref (id2);
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
GST_START_TEST (test_periodic_shot)
|
||||
{
|
||||
GstClock *clock;
|
||||
GstClockID id, id2;
|
||||
GstClockTime base;
|
||||
GstClockReturn result;
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
fail_unless (clock != NULL, "Could not create instance of GstSystemClock");
|
||||
|
||||
gst_clock_debug (clock);
|
||||
base = gst_clock_get_time (clock);
|
||||
|
||||
/* signal every half a time unit */
|
||||
id = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2);
|
||||
fail_unless (id != NULL, "Could not create periodic id");
|
||||
|
||||
g_message ("waiting one time unit\n");
|
||||
result = gst_clock_id_wait (id, NULL);
|
||||
gst_clock_debug (clock);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
|
||||
g_message ("waiting for the next\n");
|
||||
result = gst_clock_id_wait (id, NULL);
|
||||
gst_clock_debug (clock);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
|
||||
g_message ("waiting for the next async %p\n", id);
|
||||
result = gst_clock_id_wait_async (id, ok_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
|
||||
g_message ("waiting some more for the next async %p\n", id);
|
||||
result = gst_clock_id_wait_async (id, ok_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
|
||||
id2 = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2);
|
||||
fail_unless (id2 != NULL, "Could not create second periodic id");
|
||||
|
||||
g_message ("waiting some more for another async %p\n", id2);
|
||||
result = gst_clock_id_wait_async (id2, ok_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
|
||||
g_message ("unschedule %p\n", id);
|
||||
gst_clock_id_unschedule (id);
|
||||
|
||||
/* entry cannot be used again */
|
||||
result = gst_clock_id_wait_async (id, error_callback, NULL);
|
||||
fail_unless (result == GST_CLOCK_UNSCHEDULED,
|
||||
"Waiting did not return UNSCHEDULED");
|
||||
result = gst_clock_id_wait (id, NULL);
|
||||
fail_unless (result == GST_CLOCK_UNSCHEDULED,
|
||||
"Waiting did not return UNSCHEDULED");
|
||||
g_usleep (TIME_UNIT / (2 * 1000));
|
||||
|
||||
/* clean up */
|
||||
gst_clock_id_unref (id);
|
||||
}
|
||||
|
||||
GST_END_TEST Suite * gst_systemclock_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstSystemClock");
|
||||
TCase *tc_chain = tcase_create ("waiting");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_signedness);
|
||||
tcase_add_test (tc_chain, test_single_shot);
|
||||
tcase_add_test (tc_chain, test_periodic_shot);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_systemclock_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;
|
||||
}
|
|
@ -1,244 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
||||
*
|
||||
* parse1.c: Test various parsing stuff
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* multiple artists are possible */
|
||||
#define UTAG GST_TAG_ARTIST
|
||||
#define UNFIXED1 "Britney Spears"
|
||||
#define UNFIXED2 "Evanescence"
|
||||
#define UNFIXED3 "AC/DC"
|
||||
#define UNFIXED4 "The Prodigy"
|
||||
|
||||
/* license is fixed */
|
||||
#define FTAG GST_TAG_LICENSE
|
||||
#define FIXED1 "Lesser General Public License"
|
||||
#define FIXED2 "Microsoft End User License Agreement"
|
||||
#define FIXED3 "Mozilla Public License"
|
||||
#define FIXED4 "Public Domain"
|
||||
|
||||
/* checks that a tag contains the given values and not more values */
|
||||
static void
|
||||
check_tags (const GstTagList * list, const gchar * tag, gchar * value, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
guint i = 0;
|
||||
|
||||
va_start (args, value);
|
||||
while (value != NULL) {
|
||||
fail_unless (gst_tag_list_get_string_index (list, tag, i, &str));
|
||||
fail_unless (strcmp (value, str) == 0);
|
||||
g_free (str);
|
||||
|
||||
value = va_arg (args, gchar *);
|
||||
i++;
|
||||
}
|
||||
fail_unless (i == gst_tag_list_get_tag_size (list, tag));
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
#define NEW_LIST_FIXED(mode) \
|
||||
G_STMT_START { \
|
||||
if (list) gst_tag_list_free (list); \
|
||||
list = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list, mode, FTAG, FIXED1, FTAG, FIXED2, \
|
||||
FTAG, FIXED3, FTAG, FIXED4, NULL); \
|
||||
} G_STMT_END;
|
||||
|
||||
#define NEW_LIST_UNFIXED(mode) \
|
||||
G_STMT_START { \
|
||||
if (list) gst_tag_list_free (list); \
|
||||
list = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list, mode, UTAG, UNFIXED1, UTAG, UNFIXED2, \
|
||||
UTAG, UNFIXED3, UTAG, UNFIXED4, NULL); \
|
||||
} G_STMT_END;
|
||||
|
||||
#define NEW_LISTS_FIXED(mode) \
|
||||
G_STMT_START { \
|
||||
if (list) gst_tag_list_free (list); \
|
||||
list = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, FTAG, FIXED1, \
|
||||
FTAG, FIXED2, NULL); \
|
||||
if (list2) gst_tag_list_free (list2); \
|
||||
list2 = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, FTAG, FIXED3, \
|
||||
FTAG, FIXED4, NULL); \
|
||||
if (merge) gst_tag_list_free (merge); \
|
||||
merge = gst_tag_list_merge (list, list2, mode); \
|
||||
} G_STMT_END;
|
||||
|
||||
#define NEW_LISTS_UNFIXED(mode) \
|
||||
G_STMT_START { \
|
||||
if (list) gst_tag_list_free (list); \
|
||||
list = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, UTAG, UNFIXED1, \
|
||||
UTAG, UNFIXED2, NULL); \
|
||||
if (list2) gst_tag_list_free (list2); \
|
||||
list2 = gst_tag_list_new (); \
|
||||
gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, UTAG, UNFIXED3,\
|
||||
UTAG, UNFIXED4, NULL); \
|
||||
if (merge) gst_tag_list_free (merge); \
|
||||
merge = gst_tag_list_merge (list, list2, mode); \
|
||||
} G_STMT_END;
|
||||
|
||||
|
||||
GST_START_TEST (test_merge)
|
||||
{
|
||||
GstTagList *list = NULL, *list2 = NULL, *merge = NULL;
|
||||
|
||||
/* make sure the assumptions work */
|
||||
fail_unless (gst_tag_is_fixed (FTAG));
|
||||
fail_unless (!gst_tag_is_fixed (UTAG));
|
||||
/* we check string here only */
|
||||
fail_unless (gst_tag_get_type (FTAG) == G_TYPE_STRING);
|
||||
fail_unless (gst_tag_get_type (UTAG) == G_TYPE_STRING);
|
||||
|
||||
/* check additions */
|
||||
|
||||
/* unfixed */
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE_ALL);
|
||||
check_tags (list, UTAG, UNFIXED4, NULL);
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE);
|
||||
check_tags (list, UTAG, UNFIXED4, NULL);
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_PREPEND);
|
||||
check_tags (list, UTAG, UNFIXED4, UNFIXED3, UNFIXED2, UNFIXED1, NULL);
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_APPEND);
|
||||
check_tags (list, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL);
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP);
|
||||
check_tags (list, UTAG, UNFIXED1, NULL);
|
||||
NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP_ALL);
|
||||
check_tags (list, UTAG, NULL);
|
||||
|
||||
/* fixed */
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE_ALL);
|
||||
check_tags (list, FTAG, FIXED4, NULL);
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE);
|
||||
check_tags (list, FTAG, FIXED4, NULL);
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_PREPEND);
|
||||
check_tags (list, FTAG, FIXED4, NULL);
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_APPEND);
|
||||
check_tags (list, FTAG, FIXED1, NULL);
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_KEEP);
|
||||
check_tags (list, FTAG, FIXED1, NULL);
|
||||
NEW_LIST_FIXED (GST_TAG_MERGE_KEEP_ALL);
|
||||
check_tags (list, FTAG, NULL);
|
||||
|
||||
/* check merging */
|
||||
/* unfixed */
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE_ALL);
|
||||
check_tags (merge, UTAG, UNFIXED3, UNFIXED4, NULL);
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE);
|
||||
check_tags (merge, UTAG, UNFIXED3, UNFIXED4, NULL);
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_PREPEND);
|
||||
check_tags (merge, UTAG, UNFIXED3, UNFIXED4, UNFIXED1, UNFIXED2, NULL);
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_APPEND);
|
||||
check_tags (merge, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL);
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP);
|
||||
check_tags (merge, UTAG, UNFIXED1, UNFIXED2, NULL);
|
||||
NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP_ALL);
|
||||
check_tags (merge, UTAG, UNFIXED1, UNFIXED2, NULL);
|
||||
|
||||
/* fixed */
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE_ALL);
|
||||
check_tags (merge, FTAG, FIXED3, NULL);
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE);
|
||||
check_tags (merge, FTAG, FIXED3, NULL);
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_PREPEND);
|
||||
check_tags (merge, FTAG, FIXED3, NULL);
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_APPEND);
|
||||
check_tags (merge, FTAG, FIXED1, NULL);
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP);
|
||||
check_tags (merge, FTAG, FIXED1, NULL);
|
||||
NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP_ALL);
|
||||
check_tags (merge, FTAG, FIXED1, NULL);
|
||||
|
||||
/* clean up */
|
||||
if (list)
|
||||
gst_tag_list_free (list);
|
||||
if (list2)
|
||||
gst_tag_list_free (list2);
|
||||
if (merge)
|
||||
gst_tag_list_free (merge);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
GST_START_TEST (test_date_tags)
|
||||
{
|
||||
GstTagList *tag_list, *tag_list2;
|
||||
GDate *date, *date2;
|
||||
gchar *str;
|
||||
|
||||
date = g_date_new_dmy (14, 10, 2005);
|
||||
tag_list = gst_tag_list_new ();
|
||||
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_DATE, date, NULL);
|
||||
|
||||
str = gst_structure_to_string (tag_list);
|
||||
fail_if (str == NULL);
|
||||
fail_if (strstr (str, "2005-10-14") == NULL);
|
||||
|
||||
tag_list2 = gst_structure_from_string (str, NULL);
|
||||
fail_if (tag_list2 == NULL);
|
||||
fail_if (!gst_tag_list_get_date (tag_list2, GST_TAG_DATE, &date2));
|
||||
gst_tag_list_free (tag_list2);
|
||||
g_free (str);
|
||||
|
||||
fail_if (g_date_compare (date, date2) != 0);
|
||||
fail_if (g_date_get_day (date) != 14);
|
||||
fail_if (g_date_get_month (date) != 10);
|
||||
fail_if (g_date_get_year (date) != 2005);
|
||||
fail_if (g_date_get_day (date2) != 14);
|
||||
fail_if (g_date_get_month (date2) != 10);
|
||||
fail_if (g_date_get_year (date2) != 2005);
|
||||
g_date_free (date2);
|
||||
|
||||
gst_tag_list_free (tag_list);
|
||||
g_date_free (date);
|
||||
}
|
||||
GST_END_TEST Suite * gst_tag_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstTag");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_merge);
|
||||
tcase_add_test (tc_chain, test_date_tags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_tag_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;
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstutils.c: Unit test for functions in gstutils
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
#define SPECIAL_POINTER(x) ((void*)(19283847+(x)))
|
||||
|
||||
static int n_data_probes = 0;
|
||||
static int n_buffer_probes = 0;
|
||||
static int n_event_probes = 0;
|
||||
|
||||
static gboolean
|
||||
data_probe (GstPad * pad, GstMiniObject * obj, gpointer data)
|
||||
{
|
||||
n_data_probes++;
|
||||
g_assert (GST_IS_MINI_OBJECT (obj));
|
||||
g_assert (data == SPECIAL_POINTER (0));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
buffer_probe (GstPad * pad, GstBuffer * obj, gpointer data)
|
||||
{
|
||||
n_buffer_probes++;
|
||||
g_assert (GST_IS_BUFFER (obj));
|
||||
g_assert (data == SPECIAL_POINTER (1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
event_probe (GstPad * pad, GstEvent * obj, gpointer data)
|
||||
{
|
||||
n_event_probes++;
|
||||
g_assert (GST_IS_EVENT (obj));
|
||||
g_assert (data == SPECIAL_POINTER (2));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_buffer_probe_n_times)
|
||||
{
|
||||
GstElement *pipeline, *fakesrc, *fakesink;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
GstPad *pad;
|
||||
|
||||
pipeline = gst_element_factory_make ("pipeline", NULL);
|
||||
fakesrc = gst_element_factory_make ("fakesrc", NULL);
|
||||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
g_object_set (fakesrc, "num-buffers", (int) 10, NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
pad = gst_element_get_pad (fakesink, "sink");
|
||||
gst_pad_add_data_probe (pad, G_CALLBACK (data_probe), SPECIAL_POINTER (0));
|
||||
gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe),
|
||||
SPECIAL_POINTER (1));
|
||||
gst_pad_add_event_probe (pad, G_CALLBACK (event_probe), SPECIAL_POINTER (2));
|
||||
gst_object_unref (pad);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
|
||||
gst_message_unref (message);
|
||||
gst_object_unref (bus);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
g_assert (n_buffer_probes == 10); /* one for every buffer */
|
||||
g_assert (n_event_probes == 2); /* new segment and eos */
|
||||
g_assert (n_data_probes == 12); /* duh */
|
||||
} GST_END_TEST;
|
||||
|
||||
static int n_data_probes_once = 0;
|
||||
static int n_buffer_probes_once = 0;
|
||||
static int n_event_probes_once = 0;
|
||||
|
||||
static gboolean
|
||||
data_probe_once (GstPad * pad, GstMiniObject * obj, guint * data)
|
||||
{
|
||||
n_data_probes_once++;
|
||||
g_assert (GST_IS_MINI_OBJECT (obj));
|
||||
|
||||
gst_pad_remove_data_probe (pad, *data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
buffer_probe_once (GstPad * pad, GstBuffer * obj, guint * data)
|
||||
{
|
||||
n_buffer_probes_once++;
|
||||
g_assert (GST_IS_BUFFER (obj));
|
||||
|
||||
gst_pad_remove_buffer_probe (pad, *data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
event_probe_once (GstPad * pad, GstEvent * obj, guint * data)
|
||||
{
|
||||
n_event_probes_once++;
|
||||
g_assert (GST_IS_EVENT (obj));
|
||||
|
||||
gst_pad_remove_event_probe (pad, *data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_buffer_probe_once)
|
||||
{
|
||||
GstElement *pipeline, *fakesrc, *fakesink;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
GstPad *pad;
|
||||
guint id1, id2, id3;
|
||||
|
||||
pipeline = gst_element_factory_make ("pipeline", NULL);
|
||||
fakesrc = gst_element_factory_make ("fakesrc", NULL);
|
||||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
g_object_set (fakesrc, "num-buffers", (int) 10, NULL);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
pad = gst_element_get_pad (fakesink, "sink");
|
||||
id1 = gst_pad_add_data_probe (pad, G_CALLBACK (data_probe_once), &id1);
|
||||
id2 = gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_once), &id2);
|
||||
id3 = gst_pad_add_event_probe (pad, G_CALLBACK (event_probe_once), &id3);
|
||||
gst_object_unref (pad);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
|
||||
gst_message_unref (message);
|
||||
gst_object_unref (bus);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
g_assert (n_buffer_probes_once == 1); /* can we hit it and quit? */
|
||||
g_assert (n_event_probes_once == 1); /* i said, can we hit it and quit? */
|
||||
g_assert (n_data_probes_once == 1); /* let's hit it and quit!!! */
|
||||
} GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_math_scale)
|
||||
{
|
||||
fail_if (gst_util_uint64_scale_int (1, 1, 1) != 1);
|
||||
|
||||
fail_if (gst_util_uint64_scale_int (10, 10, 1) != 100);
|
||||
fail_if (gst_util_uint64_scale_int (10, 10, 2) != 50);
|
||||
|
||||
fail_if (gst_util_uint64_scale_int (0, 10, 2) != 0);
|
||||
fail_if (gst_util_uint64_scale_int (0, 0, 2) != 0);
|
||||
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 5, 1) != G_MAXUINT32 * 5LL);
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 10, 2) != G_MAXUINT32 * 5LL);
|
||||
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 1, 5) != G_MAXUINT32 / 5LL);
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 2, 10) != G_MAXUINT32 / 5LL);
|
||||
|
||||
/* not quite overflow */
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, 10,
|
||||
10) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, G_MAXINT32,
|
||||
G_MAXINT32) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 100, G_MAXINT32,
|
||||
G_MAXINT32) != G_MAXUINT64 - 100);
|
||||
|
||||
/* overflow */
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, 10, 1) != G_MAXUINT64);
|
||||
fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, G_MAXINT32,
|
||||
1) != G_MAXUINT64);
|
||||
|
||||
} GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_math_scale_uint64)
|
||||
{
|
||||
fail_if (gst_util_uint64_scale (1, 1, 1) != 1);
|
||||
|
||||
fail_if (gst_util_uint64_scale (10, 10, 1) != 100);
|
||||
fail_if (gst_util_uint64_scale (10, 10, 2) != 50);
|
||||
|
||||
fail_if (gst_util_uint64_scale (0, 10, 2) != 0);
|
||||
fail_if (gst_util_uint64_scale (0, 0, 2) != 0);
|
||||
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT32, 5, 1) != G_MAXUINT32 * 5LL);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT32, 10, 2) != G_MAXUINT32 * 5LL);
|
||||
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT32, 1, 5) != G_MAXUINT32 / 5LL);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT32, 2, 10) != G_MAXUINT32 / 5LL);
|
||||
|
||||
/* not quite overflow */
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 10) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT32,
|
||||
G_MAXUINT32) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 100, G_MAXUINT32,
|
||||
G_MAXUINT32) != G_MAXUINT64 - 100);
|
||||
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 10) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT64,
|
||||
G_MAXUINT64) != G_MAXUINT64 - 1);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 100, G_MAXUINT64,
|
||||
G_MAXUINT64) != G_MAXUINT64 - 100);
|
||||
|
||||
/* overflow */
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 1) != G_MAXUINT64);
|
||||
fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT64,
|
||||
1) != G_MAXUINT64);
|
||||
|
||||
} GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_math_scale_random)
|
||||
{
|
||||
guint64 val, num, denom, res;
|
||||
GRand *rand;
|
||||
gint i;
|
||||
|
||||
rand = g_rand_new ();
|
||||
|
||||
i = 1000000;
|
||||
while (i--) {
|
||||
guint64 check, diff;
|
||||
|
||||
val = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
|
||||
num = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
|
||||
denom = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
|
||||
|
||||
res = gst_util_uint64_scale (val, num, denom);
|
||||
check = gst_gdouble_to_guint64 (gst_guint64_to_gdouble (val) *
|
||||
gst_guint64_to_gdouble (num) / gst_guint64_to_gdouble (denom));
|
||||
|
||||
if (res < G_MAXUINT64 && check < G_MAXUINT64) {
|
||||
if (res > check)
|
||||
diff = res - check;
|
||||
else
|
||||
diff = check - res;
|
||||
|
||||
/* some arbitrary value, really.. someone do the proper math to get
|
||||
* the upper bound */
|
||||
if (diff > 20000)
|
||||
fail_if (diff > 20000);
|
||||
}
|
||||
}
|
||||
g_rand_free (rand);
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_utils_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstUtils");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_buffer_probe_n_times);
|
||||
tcase_add_test (tc_chain, test_buffer_probe_once);
|
||||
tcase_add_test (tc_chain, test_math_scale);
|
||||
tcase_add_test (tc_chain, test_math_scale_uint64);
|
||||
tcase_add_test (tc_chain, test_math_scale_random);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_utils_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;
|
||||
}
|
1407
check/gst/gstvalue.c
1407
check/gst/gstvalue.c
File diff suppressed because it is too large
Load diff
3
check/net/.gitignore
vendored
3
check/net/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
.dirstamp
|
||||
gstnetclientclock
|
||||
gstnettimeprovider
|
|
@ -1,143 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
*
|
||||
* gstnetclientclock.c: Unit test for the network client clock
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
#include <gst/net/gstnet.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
GST_START_TEST (test_instantiation)
|
||||
{
|
||||
GstClock *client, *local;
|
||||
|
||||
local = gst_system_clock_obtain ();
|
||||
client = gst_net_client_clock_new (NULL, "127.0.0.1", 1234, GST_SECOND);
|
||||
fail_unless (local != NULL, "failed to get system clock");
|
||||
fail_unless (client != NULL, "failed to get network client clock");
|
||||
|
||||
/* one for gstreamer, one for us */
|
||||
ASSERT_OBJECT_REFCOUNT (local, "system clock", 2);
|
||||
ASSERT_OBJECT_REFCOUNT (client, "network client clock", 1);
|
||||
|
||||
gst_object_unref (client);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (local, "system clock", 2);
|
||||
|
||||
gst_object_unref (local);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_functioning)
|
||||
{
|
||||
GstNetTimeProvider *ntp;
|
||||
GstClock *client, *server;
|
||||
GstClockTime basex, basey, rate_num, rate_denom;
|
||||
GstClockTime servtime, clienttime;
|
||||
gint port;
|
||||
|
||||
server = gst_system_clock_obtain ();
|
||||
fail_unless (server != NULL, "failed to get system clock");
|
||||
|
||||
/* move the clock ahead 100 seconds */
|
||||
gst_clock_get_calibration (server, &basex, &basey, &rate_num, &rate_denom);
|
||||
basey += 100 * GST_SECOND;
|
||||
gst_clock_set_calibration (server, basex, basey, rate_num, rate_denom);
|
||||
|
||||
ntp = gst_net_time_provider_new (server, "127.0.0.1", 0);
|
||||
fail_unless (ntp != NULL, "failed to create network time provider");
|
||||
|
||||
g_object_get (ntp, "port", &port, NULL);
|
||||
|
||||
client = gst_net_client_clock_new (NULL, "127.0.0.1", port, GST_SECOND);
|
||||
fail_unless (client != NULL, "failed to get network client clock");
|
||||
|
||||
g_object_get (client, "port", &port, NULL);
|
||||
|
||||
/* let the clocks synchronize */
|
||||
g_usleep (G_USEC_PER_SEC / 2);
|
||||
|
||||
servtime = gst_clock_get_time (server);
|
||||
clienttime = gst_clock_get_time (client);
|
||||
|
||||
/* can't in general make a precise assertion here, because this depends on
|
||||
* system load and a lot of things. however within half a second they should
|
||||
* at least be within 1/10 of a second of each other... */
|
||||
if (servtime > clienttime)
|
||||
fail_unless (servtime - clienttime < 100 * GST_MSECOND,
|
||||
"clocks not in sync (%" GST_TIME_FORMAT ")",
|
||||
GST_TIME_ARGS (servtime - clienttime));
|
||||
else
|
||||
fail_unless (clienttime - servtime < 100 * GST_MSECOND,
|
||||
"clocks not in sync (%" GST_TIME_FORMAT ")",
|
||||
GST_TIME_ARGS (clienttime - servtime));
|
||||
|
||||
/*
|
||||
g_print ("diff: %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (servtime > clienttime ? servtime - clienttime
|
||||
: clienttime - servtime));
|
||||
*/
|
||||
|
||||
/* one for gstreamer, one for ntp, one for us */
|
||||
ASSERT_OBJECT_REFCOUNT (server, "system clock", 3);
|
||||
ASSERT_OBJECT_REFCOUNT (client, "network client clock", 1);
|
||||
|
||||
gst_object_unref (ntp);
|
||||
|
||||
ASSERT_OBJECT_REFCOUNT (server, "system clock", 2);
|
||||
|
||||
gst_object_unref (client);
|
||||
gst_object_unref (server);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_net_client_clock_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstNetClientClock");
|
||||
TCase *tc_chain = tcase_create ("generic tests");
|
||||
|
||||
tcase_set_timeout (tc_chain, 0);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_instantiation);
|
||||
tcase_add_test (tc_chain, test_functioning);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_net_client_clock_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;
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
*
|
||||
* gstnettimeprovider.c: Unit test for the network time provider
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
#include <gst/net/gstnet.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
GST_START_TEST (test_refcounts)
|
||||
{
|
||||
GstNetTimeProvider *ntp;
|
||||
GstClock *clock;
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
fail_unless (clock != NULL, "failed to get system clock");
|
||||
|
||||
/* one for gstreamer, one for us */
|
||||
ASSERT_OBJECT_REFCOUNT (clock, "system clock", 2);
|
||||
|
||||
ntp = gst_net_time_provider_new (clock, NULL, 0);
|
||||
fail_unless (ntp != NULL, "failed to create net time provider");
|
||||
|
||||
/* one for ntp, one for gstreamer, one for us */
|
||||
ASSERT_OBJECT_REFCOUNT (clock, "system clock", 3);
|
||||
/* one for us */
|
||||
ASSERT_OBJECT_REFCOUNT (ntp, "net time provider", 1);
|
||||
|
||||
gst_object_unref (ntp);
|
||||
ASSERT_OBJECT_REFCOUNT (clock, "net time provider", 2);
|
||||
|
||||
gst_object_unref (clock);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_functioning)
|
||||
{
|
||||
GstNetTimeProvider *ntp;
|
||||
GstNetTimePacket *packet;
|
||||
GstClock *clock;
|
||||
GstClockTime local;
|
||||
struct sockaddr_in servaddr;
|
||||
gint port = -1, sockfd, ret;
|
||||
socklen_t len;
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
fail_unless (clock != NULL, "failed to get system clock");
|
||||
ntp = gst_net_time_provider_new (clock, "127.0.0.1", 0);
|
||||
fail_unless (ntp != NULL, "failed to create net time provider");
|
||||
|
||||
g_object_get (ntp, "port", &port, NULL);
|
||||
fail_unless (port > 0);
|
||||
|
||||
sockfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
fail_if (sockfd < 0, "socket failed");
|
||||
|
||||
memset (&servaddr, 0, sizeof (servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons (port);
|
||||
inet_aton ("127.0.0.1", &servaddr.sin_addr);
|
||||
|
||||
packet = gst_net_time_packet_new (NULL);
|
||||
fail_unless (packet != NULL, "failed to create packet");
|
||||
|
||||
packet->local_time = local = gst_clock_get_time (clock);
|
||||
|
||||
len = sizeof (servaddr);
|
||||
ret = gst_net_time_packet_send (packet, sockfd,
|
||||
(struct sockaddr *) &servaddr, len);
|
||||
|
||||
fail_unless (ret == GST_NET_TIME_PACKET_SIZE, "failed to send packet");
|
||||
|
||||
g_free (packet);
|
||||
|
||||
packet = gst_net_time_packet_receive (sockfd, (struct sockaddr *) &servaddr,
|
||||
&len);
|
||||
|
||||
fail_unless (packet != NULL, "failed to receive packet");
|
||||
fail_unless (packet->local_time == local, "local time is not the same");
|
||||
fail_unless (packet->remote_time > local, "remote time not after local time");
|
||||
fail_unless (packet->remote_time < gst_clock_get_time (clock),
|
||||
"remote time in the future");
|
||||
|
||||
g_free (packet);
|
||||
|
||||
close (sockfd);
|
||||
|
||||
gst_object_unref (ntp);
|
||||
gst_object_unref (clock);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_net_time_provider_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstNetTimeProvider");
|
||||
TCase *tc_chain = tcase_create ("generic tests");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_refcounts);
|
||||
tcase_add_test (tc_chain, test_functioning);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_net_time_provider_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;
|
||||
}
|
4
check/pipelines/.gitignore
vendored
4
check/pipelines/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
.dirstamp
|
||||
cleanup
|
||||
simple_launch_lines
|
||||
stress
|
|
@ -1,132 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* cleanup.c: Unit test for cleanup of pipelines
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
|
||||
static GstElement *
|
||||
setup_pipeline (gchar * pipe_descr)
|
||||
{
|
||||
GstElement *pipeline;
|
||||
|
||||
pipeline = gst_parse_launch (pipe_descr, NULL);
|
||||
g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
/* events is a mask of expected events. tevent is the expected terminal event.
|
||||
the poll call will time out after half a second.
|
||||
*/
|
||||
static void
|
||||
run_pipeline (GstElement * pipeline, gchar * descr,
|
||||
GstMessageType events, GstMessageType tevent)
|
||||
{
|
||||
GstBus *bus;
|
||||
GstMessageType revent;
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
g_assert (bus);
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
while (1) {
|
||||
GstMessage *message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
|
||||
|
||||
if (message) {
|
||||
revent = GST_MESSAGE_TYPE (message);
|
||||
gst_message_unref (message);
|
||||
} else {
|
||||
revent = GST_MESSAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (revent == tevent) {
|
||||
break;
|
||||
} else if (revent == GST_MESSAGE_UNKNOWN) {
|
||||
g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
|
||||
tevent, descr);
|
||||
break;
|
||||
} else if (revent & events) {
|
||||
continue;
|
||||
}
|
||||
g_critical ("Unexpected message received of type %d, looking for %d: %s",
|
||||
revent, tevent, descr);
|
||||
}
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_pipeline_unref)
|
||||
{
|
||||
gchar *s;
|
||||
GstElement *pipeline, *src, *sink;
|
||||
|
||||
s = "fakesrc name=src num-buffers=20 ! fakesink name=sink";
|
||||
pipeline = setup_pipeline (s);
|
||||
/* get_by_name takes a ref */
|
||||
src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
|
||||
fail_if (src == NULL);
|
||||
sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
|
||||
fail_if (sink == NULL);
|
||||
|
||||
run_pipeline (pipeline, s, GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
|
||||
GST_MESSAGE_EOS);
|
||||
while (GST_OBJECT_REFCOUNT_VALUE (src) > 1)
|
||||
THREAD_SWITCH ();
|
||||
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (sink);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
cleanup_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Pipeline cleanup");
|
||||
TCase *tc_chain = tcase_create ("linear");
|
||||
|
||||
/* time out after 20s, not the default 3 */
|
||||
tcase_set_timeout (tc_chain, 20);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_pipeline_unref);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = cleanup_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;
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
*
|
||||
* simple_launch_lines.c: Unit test for simple pipelines
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
|
||||
static GstElement *
|
||||
setup_pipeline (gchar * pipe_descr)
|
||||
{
|
||||
GstElement *pipeline;
|
||||
|
||||
pipeline = gst_parse_launch (pipe_descr, NULL);
|
||||
fail_unless (GST_IS_PIPELINE (pipeline));
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
/*
|
||||
* run_pipeline:
|
||||
* @pipe: the pipeline to run
|
||||
* @desc: the description for use in messages
|
||||
* @message_types: is a mask of expected message_types
|
||||
* @tmessage: is the expected terminal message
|
||||
*
|
||||
* the poll call will time out after half a second.
|
||||
*/
|
||||
static void
|
||||
run_pipeline (GstElement * pipeline, gchar * descr,
|
||||
GstMessageType message_types, GstMessageType tmessage)
|
||||
{
|
||||
GstBus *bus;
|
||||
GstMessageType rmessage;
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
fail_if (pipeline == NULL);
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
fail_if (bus == NULL);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
if (ret != GST_STATE_CHANGE_SUCCESS) {
|
||||
g_critical ("Couldn't set pipeline to PLAYING");
|
||||
goto done;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
GstMessage *message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
|
||||
|
||||
if (message) {
|
||||
rmessage = GST_MESSAGE_TYPE (message);
|
||||
gst_message_unref (message);
|
||||
} else {
|
||||
rmessage = GST_MESSAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (rmessage == tmessage) {
|
||||
break;
|
||||
} else if (rmessage == GST_MESSAGE_UNKNOWN) {
|
||||
g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
|
||||
tmessage, descr);
|
||||
break;
|
||||
} else if (rmessage & message_types) {
|
||||
continue;
|
||||
}
|
||||
g_critical ("Unexpected message received of type %d, looking for %d: %s",
|
||||
rmessage, tmessage, descr);
|
||||
}
|
||||
|
||||
done:
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_2_elements)
|
||||
{
|
||||
gchar *s;
|
||||
|
||||
s = "fakesrc can-activate-push=false ! fakesink can-activate-pull=true";
|
||||
run_pipeline (setup_pipeline (s), s,
|
||||
GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_UNKNOWN);
|
||||
|
||||
s = "fakesrc can-activate-push=true ! fakesink can-activate-pull=false";
|
||||
run_pipeline (setup_pipeline (s), s,
|
||||
GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_UNKNOWN);
|
||||
|
||||
s = "fakesrc can-activate-push=false num-buffers=10 ! fakesink can-activate-pull=true";
|
||||
run_pipeline (setup_pipeline (s), s,
|
||||
GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_EOS);
|
||||
|
||||
s = "fakesrc can-activate-push=true num-buffers=10 ! fakesink can-activate-pull=false";
|
||||
run_pipeline (setup_pipeline (s), s,
|
||||
GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_EOS);
|
||||
|
||||
s = "fakesrc can-activate-push=false ! fakesink can-activate-pull=false";
|
||||
ASSERT_CRITICAL (run_pipeline (setup_pipeline (s), s,
|
||||
GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
|
||||
GST_MESSAGE_UNKNOWN));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static void
|
||||
got_handoff (GstElement * sink, GstBuffer * buf, GstPad * pad, gpointer unused)
|
||||
{
|
||||
gst_element_post_message
|
||||
(sink, gst_message_new_application (NULL, gst_structure_new ("foo",
|
||||
NULL)));
|
||||
}
|
||||
|
||||
static void
|
||||
assert_live_count (GType type, gint live)
|
||||
{
|
||||
GstAllocTrace *trace;
|
||||
const gchar *name;
|
||||
|
||||
if (gst_alloc_trace_available ()) {
|
||||
name = g_type_name (type);
|
||||
fail_if (name == NULL);
|
||||
trace = gst_alloc_trace_get (name);
|
||||
if (trace) {
|
||||
g_return_if_fail (trace->live == live);
|
||||
}
|
||||
} else {
|
||||
g_print ("\nSkipping live count tests; recompile with traces to enable\n");
|
||||
}
|
||||
}
|
||||
|
||||
GST_START_TEST (test_stop_from_app)
|
||||
{
|
||||
GstElement *fakesrc, *fakesink, *pipeline;
|
||||
GstBus *bus;
|
||||
GstMessageType rmessage;
|
||||
GstMessage *message;
|
||||
|
||||
assert_live_count (GST_TYPE_BUFFER, 0);
|
||||
|
||||
fakesrc = gst_element_factory_make ("fakesrc", NULL);
|
||||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
pipeline = gst_element_factory_make ("pipeline", NULL);
|
||||
|
||||
fail_unless (fakesrc && fakesink && pipeline);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
g_object_set (fakesink, "signal-handoffs", (gboolean) TRUE, NULL);
|
||||
g_signal_connect (fakesink, "handoff", G_CALLBACK (got_handoff), NULL);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
fail_if (bus == NULL);
|
||||
|
||||
/* will time out after half a second */
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_APPLICATION, GST_SECOND / 2);
|
||||
if (message) {
|
||||
rmessage = GST_MESSAGE_TYPE (message);
|
||||
gst_message_unref (message);
|
||||
} else {
|
||||
rmessage = GST_MESSAGE_UNKNOWN;
|
||||
}
|
||||
fail_unless (rmessage == GST_MESSAGE_APPLICATION,
|
||||
"polled message is not APPLICATION but %s",
|
||||
gst_message_type_get_name (rmessage));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
gst_object_unref (bus);
|
||||
|
||||
assert_live_count (GST_TYPE_BUFFER, 0);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
simple_launch_lines_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Pipelines");
|
||||
TCase *tc_chain = tcase_create ("linear");
|
||||
|
||||
/* time out after 20s, not the default 3 */
|
||||
tcase_set_timeout (tc_chain, 0);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_2_elements);
|
||||
tcase_add_test (tc_chain, test_stop_from_app);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = simple_launch_lines_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;
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
*
|
||||
* simple_launch_lines.c: Unit test for simple pipelines
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
|
||||
GST_START_TEST (test_stress)
|
||||
{
|
||||
GstElement *fakesrc, *fakesink, *pipeline;
|
||||
gint i;
|
||||
|
||||
fakesrc = gst_element_factory_make ("fakesrc", NULL);
|
||||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
pipeline = gst_element_factory_make ("pipeline", NULL);
|
||||
|
||||
g_return_if_fail (fakesrc && fakesink && pipeline);
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
i = 100;
|
||||
while (i--) {
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
}
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST Suite *
|
||||
simple_launch_lines_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("stress");
|
||||
TCase *tc_chain = tcase_create ("linear");
|
||||
|
||||
/* time out after 20s, not the default 3 */
|
||||
tcase_set_timeout (tc_chain, 0);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_stress);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = simple_launch_lines_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;
|
||||
}
|
2
check/states/.gitignore
vendored
2
check/states/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
sinks
|
||||
.dirstamp
|
|
@ -1,470 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for sinks
|
||||
*
|
||||
* Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
|
||||
*
|
||||
* 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/check/gstcheck.h>
|
||||
|
||||
static void
|
||||
pop_state_change_message (GstBus * bus, GstElement * src, GstState old,
|
||||
GstState new, GstState pending)
|
||||
{
|
||||
GstMessage *message = NULL;
|
||||
GstState _old, _new, _pending;
|
||||
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
|
||||
fail_unless (message != NULL,
|
||||
"Expected state change message, but got nothing");
|
||||
|
||||
gst_message_parse_state_changed (message, &_old, &_new, &_pending);
|
||||
|
||||
fail_unless (GST_MESSAGE_SRC (message) == (GstObject *) src,
|
||||
"Unexpected state change order");
|
||||
fail_unless (old == _old, "Unexpected old state");
|
||||
fail_unless (new == _new, "Unexpected new state");
|
||||
fail_unless (pending == _pending, "Unexpected pending state");
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
|
||||
/* a sink should go ASYNC to PAUSE. forcing PLAYING is possible */
|
||||
GST_START_TEST (test_sink)
|
||||
{
|
||||
GstElement *sink;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no forced async state change");
|
||||
|
||||
ret = gst_element_get_state (sink, ¤t, &pending, 0);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not changing state async");
|
||||
fail_unless (current == GST_STATE_READY, "bad current state");
|
||||
fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async going back to paused");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to ready");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
|
||||
|
||||
gst_object_unref (sink);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* a sink should go ASYNC to PAUSE and PLAYING, when linking a src, it
|
||||
* should complete the state change. */
|
||||
GST_START_TEST (test_sink_completion)
|
||||
{
|
||||
GstElement *sink, *src;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
|
||||
|
||||
ret = gst_element_get_state (sink, ¤t, &pending, 0);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not changing state async");
|
||||
fail_unless (current == GST_STATE_READY, "bad current state");
|
||||
fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
|
||||
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
gst_element_link (src, sink);
|
||||
|
||||
ret = gst_element_set_state (src, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
|
||||
|
||||
/* now wait for final state */
|
||||
ret = gst_element_get_state (sink, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to change state");
|
||||
fail_unless (current == GST_STATE_PLAYING, "bad current state");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "bad pending state");
|
||||
|
||||
ret = gst_element_set_state (sink, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
|
||||
|
||||
ret = gst_element_set_state (src, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
|
||||
|
||||
gst_object_unref (sink);
|
||||
gst_object_unref (src);
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* a sink should go ASYNC to PAUSE. PAUSE should complete when
|
||||
* prerolled. */
|
||||
GST_START_TEST (test_src_sink)
|
||||
{
|
||||
GstElement *sink, *src, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
|
||||
ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot start play");
|
||||
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
|
||||
fail_unless (current == GST_STATE_PLAYING, "not playing");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot null pipeline");
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* a pipeline with live source should return NO_PREROLL in
|
||||
* PAUSE. When removing the live source it should return ASYNC
|
||||
* from the sink */
|
||||
GST_START_TEST (test_livesrc_remove)
|
||||
{
|
||||
GstElement *sink, *src, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"no no_preroll state return");
|
||||
|
||||
ret = gst_element_get_state (src, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
|
||||
fail_unless (current == GST_STATE_PAUSED, "not paused");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
gst_bin_remove (GST_BIN (pipeline), src);
|
||||
|
||||
ret = gst_element_get_state (pipeline, ¤t, &pending, 0);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
|
||||
fail_unless (current == GST_STATE_PAUSED, "not paused");
|
||||
fail_unless (pending == GST_STATE_PAUSED, "not paused");
|
||||
}
|
||||
|
||||
GST_END_TEST
|
||||
/* the sink should go ASYNC to PAUSE. The live source should go
|
||||
* NO_PREROLL to PAUSE. the pipeline returns NO_PREROLL. An
|
||||
* attempt to go to PLAYING will return ASYNC. polling state
|
||||
* completion should return SUCCESS when the sink is gone to
|
||||
* PLAYING. */
|
||||
GST_START_TEST (test_livesrc_sink)
|
||||
{
|
||||
GstElement *sink, *src, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstBus *bus;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"no no_preroll state return");
|
||||
|
||||
pop_state_change_message (bus, sink, GST_STATE_NULL, GST_STATE_READY,
|
||||
GST_STATE_VOID_PENDING);
|
||||
pop_state_change_message (bus, src, GST_STATE_NULL, GST_STATE_READY,
|
||||
GST_STATE_VOID_PENDING);
|
||||
pop_state_change_message (bus, pipeline, GST_STATE_NULL, GST_STATE_READY,
|
||||
GST_STATE_PAUSED);
|
||||
|
||||
/* this order only holds true for live sources because they do not push
|
||||
buffers in PAUSED */
|
||||
pop_state_change_message (bus, src, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
GST_STATE_VOID_PENDING);
|
||||
pop_state_change_message (bus, pipeline, GST_STATE_READY, GST_STATE_PAUSED,
|
||||
GST_STATE_VOID_PENDING);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"no no_preroll state return the second time");
|
||||
|
||||
ret = gst_element_get_state (src, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
|
||||
fail_unless (current == GST_STATE_PAUSED, "not paused");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
/* don't block here */
|
||||
ret = gst_element_get_state (sink, ¤t, &pending, 0);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
|
||||
fail_unless (current == GST_STATE_READY, "not ready");
|
||||
fail_unless (pending == GST_STATE_PAUSED, "not paused");
|
||||
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
|
||||
fail_unless (current == GST_STATE_PAUSED, "not paused");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
|
||||
fail_unless (current == GST_STATE_PLAYING, "not playing");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
/* now we have four messages on the bus: src from paused to playing, sink from
|
||||
ready to paused and paused to playing, and pipeline from paused to playing.
|
||||
the pipeline message should be last, and the sink messages should go in
|
||||
order, but the src message can be interleaved with the sink one. */
|
||||
{
|
||||
GstMessage *m;
|
||||
GstState old, new, pending;
|
||||
gint n_src = 1, n_sink = 2;
|
||||
|
||||
while (n_src + n_sink > 0) {
|
||||
m = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
|
||||
fail_unless (m != NULL, "expected state change message");
|
||||
gst_message_parse_state_changed (m, &old, &new, &pending);
|
||||
if (GST_MESSAGE_SRC (m) == (GstObject *) src) {
|
||||
fail_unless (n_src == 1, "already got one message from the src");
|
||||
n_src--;
|
||||
fail_unless (old == GST_STATE_PAUSED, "unexpected old");
|
||||
fail_unless (new == GST_STATE_PLAYING, "unexpected new (got %d)", new);
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "unexpected pending");
|
||||
} else if (GST_MESSAGE_SRC (m) == (GstObject *) sink) {
|
||||
if (n_sink == 2) {
|
||||
fail_unless (old == GST_STATE_READY, "unexpected old");
|
||||
fail_unless (new == GST_STATE_PAUSED, "unexpected new");
|
||||
fail_unless (pending == GST_STATE_PLAYING, "unexpected pending");
|
||||
} else if (n_sink == 1) {
|
||||
fail_unless (old == GST_STATE_PAUSED, "unexpected old");
|
||||
fail_unless (new == GST_STATE_PLAYING, "unexpected new");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "unexpected pending");
|
||||
} else {
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
n_sink--;
|
||||
} else {
|
||||
g_critical
|
||||
("Unexpected state change message src %s (%d src %d sink pending)",
|
||||
GST_OBJECT_NAME (GST_MESSAGE_SRC (m)), n_src, n_sink);
|
||||
}
|
||||
gst_message_unref (m);
|
||||
}
|
||||
}
|
||||
|
||||
pop_state_change_message (bus, pipeline, GST_STATE_PAUSED, GST_STATE_PLAYING,
|
||||
GST_STATE_VOID_PENDING);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* The sink should go ASYNC to PLAYING. The source should go
|
||||
* to PLAYING with SUCCESS. The pipeline returns ASYNC. */
|
||||
GST_START_TEST (test_livesrc2_sink)
|
||||
{
|
||||
GstElement *sink, *src, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
|
||||
|
||||
ret = gst_element_get_state (src, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
|
||||
fail_unless (current == GST_STATE_PLAYING, "not playing");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
|
||||
fail_unless (current == GST_STATE_PLAYING, "not playing");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
/* and back down */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
|
||||
"no no_preroll state return");
|
||||
|
||||
ret = gst_element_get_state (src, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not no_preroll");
|
||||
fail_unless (current == GST_STATE_PAUSED, "not paused");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not paused");
|
||||
|
||||
/* sink state is not known.. it might be prerolled or not */
|
||||
|
||||
/* and to READY */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
|
||||
|
||||
ret = gst_element_get_state (src, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not success");
|
||||
fail_unless (current == GST_STATE_READY, "not ready");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not ready");
|
||||
|
||||
ret = gst_element_get_state (sink, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not success");
|
||||
fail_unless (current == GST_STATE_READY, "not ready");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not ready");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_livesrc3_sink)
|
||||
{
|
||||
GstElement *sink, *src, *pipeline;
|
||||
GstStateChangeReturn ret;
|
||||
GstState current, pending;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), src);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
gst_object_unref (srcpad);
|
||||
gst_object_unref (sinkpad);
|
||||
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
|
||||
|
||||
ret =
|
||||
gst_element_get_state (pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
|
||||
fail_unless (current == GST_STATE_PLAYING, "not playing");
|
||||
fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
|
||||
|
||||
/* and back down */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
/* test: try changing state of sinks */
|
||||
Suite *
|
||||
gst_object_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Sinks");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_sink);
|
||||
tcase_add_test (tc_chain, test_sink_completion);
|
||||
tcase_add_test (tc_chain, test_src_sink);
|
||||
tcase_add_test (tc_chain, test_livesrc_remove);
|
||||
tcase_add_test (tc_chain, test_livesrc_sink);
|
||||
tcase_add_test (tc_chain, test_livesrc2_sink);
|
||||
tcase_add_test (tc_chain, test_livesrc3_sink);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_object_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;
|
||||
}
|
29
configure.ac
29
configure.ac
|
@ -485,36 +485,9 @@ plugins/Makefile
|
|||
plugins/indexers/Makefile
|
||||
plugins/elements/Makefile
|
||||
po/Makefile.in
|
||||
check/Makefile
|
||||
tests/Makefile
|
||||
tests/benchmarks/Makefile
|
||||
testsuite/Makefile
|
||||
testsuite/caps/Makefile
|
||||
testsuite/debug/Makefile
|
||||
testsuite/dlopen/Makefile
|
||||
testsuite/elements/Makefile
|
||||
testsuite/indexers/Makefile
|
||||
testsuite/parse/Makefile
|
||||
testsuite/plugin/Makefile
|
||||
testsuite/refcounting/Makefile
|
||||
testsuite/states/Makefile
|
||||
testsuite/threads/Makefile
|
||||
examples/Makefile
|
||||
examples/controller/Makefile
|
||||
examples/cutter/Makefile
|
||||
examples/helloworld/Makefile
|
||||
examples/launch/Makefile
|
||||
examples/manual/Makefile
|
||||
examples/mixer/Makefile
|
||||
examples/metadata/Makefile
|
||||
examples/pingpong/Makefile
|
||||
examples/plugins/Makefile
|
||||
examples/pwg/Makefile
|
||||
examples/queue/Makefile
|
||||
examples/retag/Makefile
|
||||
examples/thread/Makefile
|
||||
examples/typefind/Makefile
|
||||
examples/xml/Makefile
|
||||
tests/check/Makefile
|
||||
tools/Makefile
|
||||
common/Makefile
|
||||
common/m4/Makefile
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
if GST_DISABLE_LOADSAVE
|
||||
GST_LOADSAVE_DIRS =
|
||||
else
|
||||
GST_LOADSAVE_DIRS = xml typefind
|
||||
endif
|
||||
|
||||
dirs = \
|
||||
helloworld \
|
||||
queue \
|
||||
launch \
|
||||
thread \
|
||||
plugins \
|
||||
mixer \
|
||||
metadata \
|
||||
controller \
|
||||
cutter \
|
||||
pingpong \
|
||||
manual \
|
||||
pwg \
|
||||
retag
|
||||
|
||||
#queue2 \
|
||||
#queue3 \
|
||||
#queue4
|
||||
|
||||
SUBDIRS = $(dirs) \
|
||||
$(GST_LOADSAVE_DIRS)
|
||||
|
||||
DIST_SUBDIRS = $(dirs) xml typefind
|
1
examples/appreader/.gitignore
vendored
1
examples/appreader/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
appreader
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = appreader
|
||||
|
||||
appreader_LDADD = $(GST_OBJ_LIBS)
|
||||
appreader_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* 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/gst.h>
|
||||
|
||||
static void
|
||||
fill_queue (GstElement * queue, gint level, GstBin * pipeline)
|
||||
{
|
||||
/* this needs to iterate till something is pushed
|
||||
* in the queue */
|
||||
gst_bin_iterate (pipeline);
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc, gchar * argv[])
|
||||
{
|
||||
GstElement *queue, *src, *pipeline;
|
||||
GstBuffer *buffer;
|
||||
gboolean done = FALSE;
|
||||
GstPad *pad;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
g_object_set (G_OBJECT (queue), "signal_marks", TRUE, NULL);
|
||||
|
||||
src = gst_element_factory_make ("filesrc", "src");
|
||||
g_object_set (G_OBJECT (src), "location", "appreader.c", NULL);
|
||||
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), src, queue, NULL);
|
||||
|
||||
gst_element_link_many (src, queue, NULL);
|
||||
|
||||
pad = gst_element_get_pad (queue, "src");
|
||||
g_signal_connect (G_OBJECT (queue), "low_watermark", G_CALLBACK (fill_queue),
|
||||
pipeline);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
do {
|
||||
/* get buffer into the app */
|
||||
buffer = GST_RPAD_GETFUNC (pad) (pad);
|
||||
|
||||
/* just exit on any event */
|
||||
if (GST_IS_EVENT (buffer)) {
|
||||
done = TRUE;
|
||||
} else {
|
||||
gst_util_dump_mem (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
||||
}
|
||||
gst_data_unref (GST_DATA (buffer));
|
||||
|
||||
} while (!done);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
return 0;
|
||||
}
|
4
examples/controller/.gitignore
vendored
4
examples/controller/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
audio-example
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = audio-example
|
||||
|
||||
audio_example_CFLAGS = $(GST_OBJ_CFLAGS) -I$(top_builddir)/libs
|
||||
audio_example_LDADD = $(GST_OBJ_LIBS)
|
||||
audio_example_LDFLAGS = $(top_builddir)/libs/gst/controller/libgstcontroller-@GST_MAJORMINOR@.la
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* audio-example.c
|
||||
*
|
||||
* Build a pipeline with testaudiosource->alsasink
|
||||
* and sweep frequency and volume
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/controller/gstcontroller.h>
|
||||
|
||||
gint
|
||||
main (gint argc, gchar ** argv)
|
||||
{
|
||||
gint res = 1;
|
||||
GstElement *src, *sink;
|
||||
GstElement *bin;
|
||||
GstController *ctrl;
|
||||
GstClock *clock;
|
||||
GstClockID clock_id;
|
||||
GstClockReturn wait_ret;
|
||||
GValue vol = { 0, };
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
gst_controller_init (&argc, &argv);
|
||||
|
||||
// build pipeline
|
||||
bin = gst_pipeline_new ("pipeline");
|
||||
clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
|
||||
src = gst_element_factory_make ("audiotestsrc", "gen_audio");
|
||||
sink = gst_element_factory_make ("alsasink", "play_audio");
|
||||
gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
|
||||
if (!gst_element_link (src, sink)) {
|
||||
GST_WARNING ("can't link elements");
|
||||
goto Error;
|
||||
}
|
||||
// add a controller to the source
|
||||
if (!(ctrl = gst_controller_new (G_OBJECT (src), "freq", "volume", NULL))) {
|
||||
GST_WARNING ("can't control source element");
|
||||
goto Error;
|
||||
}
|
||||
// set interpolation
|
||||
gst_controller_set_interpolation_mode (ctrl, "volume",
|
||||
GST_INTERPOLATE_LINEAR);
|
||||
gst_controller_set_interpolation_mode (ctrl, "freq", GST_INTERPOLATE_LINEAR);
|
||||
|
||||
// set control values
|
||||
g_value_init (&vol, G_TYPE_DOUBLE);
|
||||
g_value_set_double (&vol, 0.0);
|
||||
gst_controller_set (ctrl, "volume", 0 * GST_SECOND, &vol);
|
||||
g_value_set_double (&vol, 1.0);
|
||||
gst_controller_set (ctrl, "volume", 5 * GST_SECOND, &vol);
|
||||
g_value_set_double (&vol, 440.0);
|
||||
gst_controller_set (ctrl, "freq", 0 * GST_SECOND, &vol);
|
||||
g_value_set_double (&vol, 3520.0);
|
||||
gst_controller_set (ctrl, "freq", 3 * GST_SECOND, &vol);
|
||||
g_value_set_double (&vol, 880.0);
|
||||
gst_controller_set (ctrl, "freq", 6 * GST_SECOND, &vol);
|
||||
|
||||
clock_id =
|
||||
gst_clock_new_single_shot_id (clock,
|
||||
gst_clock_get_time (clock) + (7 * GST_SECOND));
|
||||
|
||||
// run for 7 seconds
|
||||
if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
|
||||
if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
|
||||
GST_WARNING ("clock_id_wait returned: %d", wait_ret);
|
||||
}
|
||||
gst_element_set_state (bin, GST_STATE_NULL);
|
||||
}
|
||||
// cleanup
|
||||
g_object_unref (G_OBJECT (ctrl));
|
||||
g_object_unref (G_OBJECT (clock));
|
||||
g_object_unref (G_OBJECT (bin));
|
||||
res = 0;
|
||||
Error:
|
||||
return (res);
|
||||
}
|
4
examples/cutter/.gitignore
vendored
4
examples/cutter/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
cutter
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = cutter
|
||||
noinst_HEADERS = cutter.h
|
||||
|
||||
cutter_LDADD = $(GST_OBJ_LIBS)
|
||||
cutter_CFLAGS = $(GST_OBJ_CFLAGS)
|
|
@ -1,203 +0,0 @@
|
|||
/*
|
||||
* cutter.c - cut audio into pieces based on silence - thomas@apestaart.org
|
||||
*
|
||||
* construct a simple pipeline osssrc ! cutter ! filesink
|
||||
* pause when necessary, change output
|
||||
*
|
||||
* Latest change : 03/06/2001
|
||||
*
|
||||
* Version : 0.3
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
gboolean playing = TRUE;
|
||||
gboolean cut_start_signalled = FALSE;
|
||||
gboolean cut_stop_signalled = FALSE;
|
||||
|
||||
int id = 0; /* increment this for each new cut */
|
||||
GstElement *main_bin;
|
||||
GstElement *audiosrc;
|
||||
GstElement *queue;
|
||||
GstElement *thread;
|
||||
GstElement *cutter;
|
||||
GstElement *filesink;
|
||||
GstElement *encoder;
|
||||
char buffer[255];
|
||||
|
||||
/* signal callbacks */
|
||||
|
||||
void
|
||||
cut_start (GstElement * element)
|
||||
{
|
||||
g_print ("\nDEBUG: main: cut start\n");
|
||||
/* we should pause the pipeline, unlink cutter and filesink
|
||||
* create a new filesink to a real file, relink, and set to play
|
||||
*/
|
||||
g_print ("DEBUG: cut_start: main_bin pausing\n");
|
||||
gst_element_set_state (main_bin, GST_STATE_PAUSED);
|
||||
g_print ("DEBUG: cut_start: main_bin paused\n");
|
||||
|
||||
{
|
||||
time_t seconds;
|
||||
struct tm *ct;
|
||||
|
||||
time (&seconds);
|
||||
ct = localtime (&seconds);
|
||||
/* sprintf (buffer, "/news/incoming/audio/cutter.%06d.wav", id); */
|
||||
sprintf (buffer,
|
||||
"/news/incoming/audio/cutter.%04d%02d%02d.%02d%02d%02d.wav",
|
||||
ct->tm_year + 1900, ct->tm_mon, ct->tm_mday, ct->tm_hour, ct->tm_min,
|
||||
ct->tm_sec);
|
||||
}
|
||||
g_print ("DEBUG: cut_start: setting new location to %s\n", buffer);
|
||||
g_object_set (G_OBJECT (filesink), "location", buffer, NULL);
|
||||
g_object_set (G_OBJECT (filesink), "type", 4, NULL);
|
||||
|
||||
gst_element_set_state (main_bin, GST_STATE_PLAYING);
|
||||
++id;
|
||||
g_print ("start_cut_signal done\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cut_start_signal (GstElement * element)
|
||||
{
|
||||
g_print ("\nDEBUG: main: cut start signal\n");
|
||||
cut_start_signalled = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
cut_stop (GstElement * element)
|
||||
{
|
||||
g_print ("\nDEBUG: main: cut stop\n");
|
||||
/* we should pause the pipeline, unlink filesink, create a fake filesink,
|
||||
* link to pipeline, and set to play
|
||||
*/
|
||||
g_print ("DEBUG: cut_stop: main_bin paused\n");
|
||||
gst_element_set_state (main_bin, GST_STATE_PAUSED);
|
||||
|
||||
g_print ("DEBUG: cut_stop: setting new location\n");
|
||||
g_object_set (G_OBJECT (filesink), "location", "/dev/null", NULL);
|
||||
|
||||
gst_element_set_state (main_bin, GST_STATE_PLAYING);
|
||||
g_print ("stop_cut_signal done\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cut_stop_signal (GstElement * element)
|
||||
{
|
||||
g_print ("\nDEBUG: main: cut stop signal\n");
|
||||
cut_stop_signalled = TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
/*int i, j; */
|
||||
/*gboolean done; */
|
||||
|
||||
/*char buffer[20]; */
|
||||
|
||||
/*output_channel_t *channel_out; */
|
||||
|
||||
GstElement *audiosrc;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
/*
|
||||
if (argc == 1)
|
||||
{
|
||||
g_print("usage: %s <filename1> <filename2> <...>\n", argv[0]);
|
||||
exit(-1);
|
||||
}*/
|
||||
|
||||
/* set up input channel and main bin */
|
||||
|
||||
g_print ("creating main bin\n");
|
||||
/* create cutter */
|
||||
cutter = gst_element_factory_make ("cutter", "cutter");
|
||||
|
||||
g_object_set (G_OBJECT (cutter),
|
||||
"threshold_dB", -40.0, "runlength", 0.5, "prelength", 1.0, NULL);
|
||||
|
||||
/* create an audio src */
|
||||
if (!(audiosrc = gst_element_factory_make ("osssrc", "audio_src")))
|
||||
g_error ("Could not create 'osssrc' element !\n");
|
||||
|
||||
/* set params */
|
||||
|
||||
g_object_set (G_OBJECT (audiosrc), "frequency", 44100,
|
||||
"channels", 1, "format", 16, NULL);
|
||||
|
||||
if (!(encoder = gst_element_factory_make ("passthrough", "encoder")))
|
||||
g_error ("Could not create 'passthrough' element !\n");
|
||||
|
||||
if (!(filesink = gst_element_factory_make ("afsink", "disk_sink")))
|
||||
g_error ("Could not create 'afsink' element !\n");
|
||||
|
||||
g_object_set (G_OBJECT (filesink), "location", "/dev/null", NULL);
|
||||
|
||||
thread = gst_thread_new ("thread");
|
||||
g_assert (thread != NULL);
|
||||
|
||||
/* create main bin */
|
||||
main_bin = gst_pipeline_new ("bin");
|
||||
g_assert (main_bin != NULL);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
g_assert (queue);
|
||||
|
||||
/* add elements to bin */
|
||||
gst_bin_add (GST_BIN (main_bin), audiosrc);
|
||||
gst_bin_add (GST_BIN (thread), queue);
|
||||
|
||||
gst_bin_add_many (GST_BIN (thread), cutter, encoder, filesink, NULL);
|
||||
|
||||
gst_element_link_many (audiosrc, queue, cutter, encoder, filesink, NULL);
|
||||
gst_bin_add (GST_BIN (main_bin), thread);
|
||||
|
||||
/* set signal handlers */
|
||||
g_print ("setting signal handlers\n");
|
||||
g_signal_connect (G_OBJECT (cutter), "cut_start",
|
||||
(GCallback) cut_start_signal, NULL);
|
||||
g_signal_connect (G_OBJECT (cutter), "cut_stop",
|
||||
(GCallback) cut_stop_signal, NULL);
|
||||
|
||||
/* start playing */
|
||||
g_print ("setting to play\n");
|
||||
gst_element_set_state (main_bin, GST_STATE_PLAYING);
|
||||
/*
|
||||
g_print ("setting thread to play\n");
|
||||
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
|
||||
*/
|
||||
while (playing) {
|
||||
/* g_print ("> "); */
|
||||
gst_bin_iterate (GST_BIN (main_bin));
|
||||
/* g_print (" <"); */
|
||||
if (cut_start_signalled) {
|
||||
g_print ("\nDEBUG: main: cut_start_signalled true !\n");
|
||||
cut_start (cutter);
|
||||
cut_start_signalled = FALSE;
|
||||
}
|
||||
if (cut_stop_signalled) {
|
||||
g_print ("\nDEBUG: main: cut_stop_signalled true !\n");
|
||||
cut_stop (cutter);
|
||||
cut_stop_signalled = FALSE;
|
||||
}
|
||||
}
|
||||
g_print ("we're done iterating.\n");
|
||||
/* stop the bin */
|
||||
|
||||
gst_element_set_state (main_bin, GST_STATE_NULL);
|
||||
|
||||
gst_object_unref (filesink);
|
||||
gst_object_unref (main_bin);
|
||||
|
||||
exit (0);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* cutter.h header file
|
||||
* thomas@apestaart.org
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstElement *pipe;
|
||||
GstElement *filesink;
|
||||
GstElement *audiosink;
|
||||
|
||||
char *location;
|
||||
int channel_id;
|
||||
} output_channel_t;
|
|
@ -1,4 +0,0 @@
|
|||
noinst_PROGRAMS = seek
|
||||
|
||||
LDADD = $(GST_OBJ_LIBS)
|
||||
AM_CFLAGS = $(GST_OBJ_CFLAGS)
|
|
@ -1,68 +0,0 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstBin *bin;
|
||||
GstElement *src, *sink;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
/* _gst_plugin_spew = TRUE; */
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
bin = GST_BIN (gst_pipeline_new ("pipeline"));
|
||||
g_return_val_if_fail (bin != NULL, -1);
|
||||
|
||||
g_print ("--- creating src and sink elements\n");
|
||||
src = gst_element_factory_make ("fakesrc", "src");
|
||||
g_return_val_if_fail (src != NULL, -1);
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
g_return_val_if_fail (sink != NULL, -1);
|
||||
|
||||
g_print ("--- about to add the elements to the bin\n");
|
||||
gst_bin_add (bin, GST_ELEMENT (src));
|
||||
gst_bin_add (bin, GST_ELEMENT (sink));
|
||||
|
||||
g_print ("--- getting pads\n");
|
||||
srcpad = gst_element_get_pad (src, "src");
|
||||
g_return_val_if_fail (srcpad != NULL, -1);
|
||||
sinkpad = gst_element_get_pad (sink, "sink");
|
||||
g_return_val_if_fail (srcpad != NULL, -1);
|
||||
|
||||
g_print ("--- linking\n");
|
||||
gst_pad_link (srcpad, sinkpad);
|
||||
|
||||
g_print ("--- setting up\n");
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
|
||||
|
||||
g_print ("--- iterating\n");
|
||||
gst_bin_iterate (bin);
|
||||
gst_bin_iterate (bin);
|
||||
|
||||
g_print ("--- seek to 100\n");
|
||||
gst_pad_send_event (srcpad, gst_event_new_seek (GST_SEEK_ANY, 100, FALSE));
|
||||
|
||||
g_print ("--- seek done, iterating\n");
|
||||
gst_bin_iterate (bin);
|
||||
gst_bin_iterate (bin);
|
||||
|
||||
g_print ("--- seek to 200 with flush\n");
|
||||
gst_pad_send_event (srcpad, gst_event_new_seek (GST_SEEK_ANY, 200, TRUE));
|
||||
|
||||
g_print ("--- seek done, iterating\n");
|
||||
gst_bin_iterate (bin);
|
||||
gst_bin_iterate (bin);
|
||||
gst_bin_iterate (bin);
|
||||
|
||||
g_print ("--- flush\n");
|
||||
gst_pad_send_event (srcpad, gst_event_new_flush ());
|
||||
|
||||
g_print ("--- flush done, iterating\n");
|
||||
gst_bin_iterate (bin);
|
||||
gst_bin_iterate (bin);
|
||||
|
||||
g_print ("--- cleaning up\n");
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
|
||||
return 0;
|
||||
}
|
4
examples/helloworld/.gitignore
vendored
4
examples/helloworld/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
helloworld
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,4 +0,0 @@
|
|||
noinst_PROGRAMS = helloworld
|
||||
|
||||
helloworld_LDADD = $(GST_OBJ_LIBS)
|
||||
helloworld_CFLAGS = $(GST_OBJ_CFLAGS)
|
|
@ -1,87 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
static void
|
||||
event_loop (GstElement * pipe)
|
||||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *bin, *filesrc, *decoder, *audiosink;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <mp3 file>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
bin = gst_pipeline_new ("pipeline");
|
||||
g_assert (bin);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
|
||||
/* now it's time to get the decoder */
|
||||
decoder = gst_element_factory_make ("mad", "decode");
|
||||
if (!decoder) {
|
||||
g_print ("could not find plugin \"mad\"");
|
||||
return -1;
|
||||
}
|
||||
/* and an audio sink */
|
||||
audiosink = gst_element_factory_make ("alsasink", "play_audio");
|
||||
g_assert (audiosink);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, audiosink, NULL);
|
||||
|
||||
/* link the elements */
|
||||
gst_element_link_many (filesrc, decoder, audiosink, NULL);
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (bin, GST_STATE_PLAYING);
|
||||
|
||||
/* Run event loop listening for bus messages until EOS or ERROR */
|
||||
event_loop (bin);
|
||||
|
||||
/* stop the bin */
|
||||
gst_element_set_state (bin, GST_STATE_NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
1
examples/helloworld2/.gitignore
vendored
1
examples/helloworld2/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
helloworld2
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = helloworld2
|
||||
|
||||
helloworld2_LDADD = $(GST_OBJ_LIBS)
|
||||
helloworld2_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
static void
|
||||
gst_play_have_type (GstElement * typefind, GstCaps * caps,
|
||||
GstElement * pipeline)
|
||||
{
|
||||
GstElement *osssink;
|
||||
GstElement *new_element;
|
||||
GstAutoplug *autoplug;
|
||||
GstElement *autobin;
|
||||
GstElement *filesrc;
|
||||
GstElement *cache;
|
||||
|
||||
GST_DEBUG ("GstPipeline: play have type");
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
||||
autobin = gst_bin_get_by_name (GST_BIN (pipeline), "autobin");
|
||||
cache = gst_bin_get_by_name (GST_BIN (autobin), "cache");
|
||||
|
||||
/* unlink_pads the typefind from the pipeline and remove it */
|
||||
gst_element_unlink_pads (cache, "src", typefind, "sink");
|
||||
gst_bin_remove (GST_BIN (autobin), typefind);
|
||||
|
||||
/* and an audio sink */
|
||||
osssink = gst_element_factory_make ("osssink", "play_audio");
|
||||
g_assert (osssink != NULL);
|
||||
|
||||
autoplug = gst_autoplug_factory_make ("staticrender");
|
||||
g_assert (autoplug != NULL);
|
||||
|
||||
new_element = gst_autoplug_to_renderers (autoplug, caps, osssink, NULL);
|
||||
|
||||
if (!new_element) {
|
||||
g_print ("could not autoplug, no suitable codecs found...\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
gst_element_set_name (new_element, "new_element");
|
||||
|
||||
gst_bin_add (GST_BIN (autobin), new_element);
|
||||
|
||||
g_object_set (G_OBJECT (cache), "reset", TRUE, NULL);
|
||||
|
||||
gst_element_link_pads (cache, "src", new_element, "sink");
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_play_cache_empty (GstElement * element, GstElement * pipeline)
|
||||
{
|
||||
GstElement *autobin;
|
||||
GstElement *filesrc;
|
||||
GstElement *cache;
|
||||
GstElement *new_element;
|
||||
|
||||
fprintf (stderr, "have cache empty\n");
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
||||
autobin = gst_bin_get_by_name (GST_BIN (pipeline), "autobin");
|
||||
cache = gst_bin_get_by_name (GST_BIN (autobin), "cache");
|
||||
new_element = gst_bin_get_by_name (GST_BIN (autobin), "new_element");
|
||||
|
||||
gst_element_unlink_pads (filesrc, "src", cache, "sink");
|
||||
gst_element_unlink_pads (cache, "src", new_element, "sink");
|
||||
gst_bin_remove (GST_BIN (autobin), cache);
|
||||
gst_element_link_pads (filesrc, "src", new_element, "sink");
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
fprintf (stderr, "done with cache_empty\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc;
|
||||
GstElement *pipeline;
|
||||
GstElement *autobin;
|
||||
GstElement *typefind;
|
||||
GstElement *cache;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new pipeline to hold the elements */
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
g_assert (pipeline != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
gst_bin_add (GST_BIN (pipeline), filesrc);
|
||||
|
||||
autobin = gst_bin_new ("autobin");
|
||||
cache = gst_element_factory_make ("autoplugcache", "cache");
|
||||
g_signal_connect (G_OBJECT (cache), "cache_empty",
|
||||
G_CALLBACK (gst_play_cache_empty), pipeline);
|
||||
|
||||
typefind = gst_element_factory_make ("typefind", "typefind");
|
||||
g_signal_connect (G_OBJECT (typefind), "have_type",
|
||||
G_CALLBACK (gst_play_have_type), pipeline);
|
||||
gst_bin_add (GST_BIN (autobin), cache);
|
||||
gst_bin_add (GST_BIN (autobin), typefind);
|
||||
|
||||
gst_element_link_pads (cache, "src", typefind, "sink");
|
||||
gst_element_add_ghost_pad (autobin, gst_element_get_pad (cache, "sink"),
|
||||
"sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), autobin);
|
||||
gst_element_link_pads (filesrc, "src", autobin, "sink");
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
||||
|
||||
while (gst_bin_iterate (GST_BIN (pipeline)));
|
||||
|
||||
/* stop the pipeline */
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
exit (0);
|
||||
}
|
5
examples/launch/.gitignore
vendored
5
examples/launch/.gitignore
vendored
|
@ -1,5 +0,0 @@
|
|||
mp3play
|
||||
mp3parselaunch
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,7 +0,0 @@
|
|||
noinst_PROGRAMS = mp3parselaunch
|
||||
|
||||
mp3parselaunch_LDADD = $(GST_OBJ_LIBS)
|
||||
mp3parselaunch_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
||||
noinst_SCRIPTS = mp3play
|
||||
EXTRA_DIST = mp3play
|
|
@ -1,35 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *pipeline;
|
||||
GstElement *filesrc;
|
||||
GError *error = NULL;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pipeline = (GstElement *)
|
||||
gst_parse_launch ("filesrc name=my_filesrc ! mad ! osssink", &error);
|
||||
if (!pipeline) {
|
||||
fprintf (stderr, "Parse error: %s", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "my_filesrc");
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
while (gst_bin_iterate (GST_BIN (pipeline)));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
#! /bin/sh
|
||||
for loc in "$@"; do
|
||||
../../tools/gst-launch filesrc location="$loc" ! mp3parse ! mad ! osssink
|
||||
done
|
39
examples/manual/.gitignore
vendored
39
examples/manual/.gitignore
vendored
|
@ -1,39 +0,0 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
*.c
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
||||
|
||||
dynamic
|
||||
elementget
|
||||
elementmake
|
||||
gnome
|
||||
fakesrc
|
||||
helloworld
|
||||
helloworld2
|
||||
init
|
||||
popt
|
||||
queue
|
||||
threads
|
||||
bin
|
||||
decodebin
|
||||
elementcreate
|
||||
elementfactory
|
||||
elementlink
|
||||
ghostpad
|
||||
pad
|
||||
playbin
|
||||
query
|
||||
typefind
|
||||
|
||||
xml-mp3
|
||||
xml
|
||||
xmlTest.gst
|
||||
README
|
||||
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,104 +0,0 @@
|
|||
if HAVE_LIBGNOMEUI
|
||||
GNOME=gnome
|
||||
else
|
||||
GNOME=
|
||||
endif
|
||||
|
||||
if GST_DISABLE_LOADSAVE
|
||||
GST_LOADSAVE_SRC =
|
||||
else
|
||||
GST_LOADSAVE_SRC = xml-mp3
|
||||
endif
|
||||
|
||||
INCLUDES = $(GST_OBJ_CFLAGS)
|
||||
|
||||
goption_CFLAGS = -DGETTEXT_PACKAGE="\"gstreamer-0.9\""
|
||||
|
||||
#dynamic_LDADD = $(GST_OBJ_LIBS) $(LIBGNOMEUI_LIBS)
|
||||
#dynamic_CFLAGS = $(GST_OBJ_CFLAGS) $(LIBGNOMEUI_CFLAGS)
|
||||
gnome_LDADD = $(GST_OBJ_LIBS) $(LIBGNOMEUI_LIBS)
|
||||
gnome_CFLAGS = $(GST_OBJ_CFLAGS) $(LIBGNOMEUI_CFLAGS)
|
||||
|
||||
EXTRA_DIST = extract.pl
|
||||
|
||||
EXAMPLES = \
|
||||
bus \
|
||||
dynamic \
|
||||
$(GNOME) \
|
||||
elementcreate \
|
||||
elementmake \
|
||||
elementfactory \
|
||||
elementget \
|
||||
elementlink \
|
||||
bin \
|
||||
pad \
|
||||
ghostpad \
|
||||
helloworld \
|
||||
init \
|
||||
goption \
|
||||
query \
|
||||
typefind \
|
||||
probe \
|
||||
fakesrc \
|
||||
playbin \
|
||||
decodebin \
|
||||
$(GST_LOADSAVE_SRC)
|
||||
|
||||
elementmake.c elementcreate.c elementget.c elementlink.c elementfactory.c: $(top_srcdir)/docs/manual/basics-elements.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-elements.xml
|
||||
|
||||
bin.c : $(top_srcdir)/docs/manual/basics-bins.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-bins.xml
|
||||
|
||||
bus.c: $(top_srcdir)/docs/manual/basics-bus.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-bus.xml
|
||||
|
||||
pad.c ghostpad.c: $(top_srcdir)/docs/manual/basics-pads.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-pads.xml
|
||||
|
||||
gnome.c: $(top_srcdir)/docs/manual/appendix-integration.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/appendix-integration.xml
|
||||
|
||||
helloworld.c: $(top_srcdir)/docs/manual/basics-helloworld.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-helloworld.xml
|
||||
|
||||
init.c goption.c: $(top_srcdir)/docs/manual/basics-init.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/basics-init.xml
|
||||
|
||||
query.c: $(top_srcdir)/docs/manual/advanced-position.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/advanced-position.xml
|
||||
|
||||
typefind.c dynamic.c: $(top_srcdir)/docs/manual/advanced-autoplugging.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/advanced-autoplugging.xml
|
||||
|
||||
probe.c fakesrc.c: $(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
||||
|
||||
playbin.c decodebin.c: $(top_srcdir)/docs/manual/highlevel-components.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/highlevel-components.xml
|
||||
|
||||
xml-mp3.c: $(top_srcdir)/docs/manual/highlevel-xml.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/manual/highlevel-xml.xml
|
||||
|
||||
# we use some of the examples as testsuite apps, to verify that
|
||||
# they actually run
|
||||
include $(top_srcdir)/testsuite/Rules
|
||||
|
||||
tests_pass = elementmake elementget init goption
|
||||
tests_fail =
|
||||
tests_ignore =
|
||||
|
||||
noinst_PROGRAMS = $(EXAMPLES)
|
||||
LDADD = $(GST_OBJ_LIBS)
|
|
@ -1,78 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# extract code fragments from xml program listings
|
||||
# first argument: source code file to find
|
||||
# second argument: xml files to extract code from
|
||||
|
||||
# main
|
||||
|
||||
# decodes xml by translating & < > back to what they should be
|
||||
# and also ignore
|
||||
# <![CDATA[ and ]]> and <!-- and -->
|
||||
sub
|
||||
xml_decode ($)
|
||||
{
|
||||
my $input = shift;
|
||||
|
||||
$input =~ s/\&/&/g;
|
||||
$input =~ s/</</g;
|
||||
$input =~ s/>/>/g;
|
||||
|
||||
if ($input =~ /<!\[CDATA\[/) { $input = ""; }
|
||||
if ($input =~ /]]>/) { $input = ""; }
|
||||
if ($input =~ /<!--/) { $input = ""; }
|
||||
if ($input =~ /-->/) { $input = ""; }
|
||||
|
||||
#print "Returning line $input";
|
||||
return $input;
|
||||
}
|
||||
|
||||
# main
|
||||
my $output = shift @ARGV;
|
||||
|
||||
$found = 0;
|
||||
%blocks = ();
|
||||
|
||||
foreach $file (@ARGV)
|
||||
{
|
||||
open FILE, $file or die "Cannot open file $file";
|
||||
|
||||
while ($line = <FILE>)
|
||||
{
|
||||
if ($line =~ /<!-- example-begin $output (.*?)-->/)
|
||||
{
|
||||
$found = 1;
|
||||
$block_id = $1;
|
||||
$block = "\n/*** block $block_id from $file ***/\n";
|
||||
|
||||
print "Extracting $output block $block_id from $file\n";
|
||||
|
||||
while ($line = <FILE>)
|
||||
{
|
||||
if ($line =~ /<!-- example-end $output (.*?)-->/)
|
||||
{
|
||||
last;
|
||||
}
|
||||
$block .= xml_decode ($line);
|
||||
}
|
||||
$blocks{$block_id} = $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$found)
|
||||
{
|
||||
print "Could not find $output example !\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# now output all the blocks in the right order
|
||||
open OUTPUT, ">$output";
|
||||
@block_ids = keys %blocks;
|
||||
foreach $block_id (sort @block_ids)
|
||||
{
|
||||
print "Writing $output block $block_id\n";
|
||||
print OUTPUT $blocks{$block_id};
|
||||
}
|
||||
close OUTPUT;
|
|
@ -1,4 +0,0 @@
|
|||
noinst_PROGRAMS = read-metadata
|
||||
|
||||
read_metadata_LDADD = $(GST_OBJ_LIBS)
|
||||
read_metadata_CFLAGS = $(GST_OBJ_CFLAGS)
|
|
@ -1,207 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2003 Thomas Vander Stichele <thomas@apestaart.org>
|
||||
* 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
||||
* 2005 Andy Wingo <wingo@pobox.com>
|
||||
* 2005 Jan Schmidt <thaytan@mad.scientist.com>
|
||||
*
|
||||
* gst-metadata.c: Use GStreamer to display metadata within files.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
char *filename = NULL;
|
||||
GstElement *pipeline = NULL;
|
||||
GstElement *source = NULL;
|
||||
|
||||
#define NEW_PIPE_PER_FILE
|
||||
|
||||
static gboolean
|
||||
message_loop (GstElement * element, GstTagList ** tags)
|
||||
{
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
|
||||
bus = gst_element_get_bus (element);
|
||||
g_return_val_if_fail (bus != NULL, FALSE);
|
||||
g_return_val_if_fail (tags != NULL, FALSE);
|
||||
|
||||
while (!done) {
|
||||
GstMessage *message;
|
||||
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, 0);
|
||||
if (message == NULL)
|
||||
/* All messages read, we're done */
|
||||
break;
|
||||
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return TRUE;
|
||||
case GST_MESSAGE_TAG:
|
||||
{
|
||||
GstTagList *new_tags;
|
||||
|
||||
gst_message_parse_tag (message, &new_tags);
|
||||
if (*tags)
|
||||
*tags = gst_tag_list_merge (*tags, new_tags, GST_TAG_MERGE_KEEP_ALL);
|
||||
else
|
||||
*tags = new_tags;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
make_pipeline ()
|
||||
{
|
||||
GstElement *decodebin;
|
||||
|
||||
if (pipeline != NULL)
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
pipeline = gst_pipeline_new (NULL);
|
||||
|
||||
source = gst_element_factory_make ("filesrc", "source");
|
||||
g_assert (GST_IS_ELEMENT (source));
|
||||
decodebin = gst_element_factory_make ("decodebin", "decodebin");
|
||||
g_assert (GST_IS_ELEMENT (decodebin));
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), source, decodebin, NULL);
|
||||
gst_element_link (source, decodebin);
|
||||
}
|
||||
|
||||
static void
|
||||
print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
|
||||
{
|
||||
gint i, count;
|
||||
|
||||
count = gst_tag_list_get_tag_size (list, tag);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
gchar *str;
|
||||
|
||||
if (gst_tag_get_type (tag) == G_TYPE_STRING) {
|
||||
if (!gst_tag_list_get_string_index (list, tag, i, &str))
|
||||
g_assert_not_reached ();
|
||||
} else {
|
||||
str =
|
||||
g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
g_print (" %15s: %s\n", gst_tag_get_nick (tag), str);
|
||||
} else {
|
||||
g_print (" : %s\n", str);
|
||||
}
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
guint i = 1;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
g_print ("Please give filenames to read metadata from\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
make_pipeline ();
|
||||
while (i < argc) {
|
||||
GstStateChangeReturn sret;
|
||||
GstState state;
|
||||
GstTagList *tags = NULL;
|
||||
|
||||
filename = argv[i];
|
||||
g_object_set (source, "location", filename, NULL);
|
||||
|
||||
GST_DEBUG ("Starting reading for %s", filename);
|
||||
|
||||
/* Decodebin will only commit to PAUSED if it actually finds a type;
|
||||
* otherwise the state change fails */
|
||||
sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
||||
|
||||
if (GST_STATE_CHANGE_ASYNC == sret) {
|
||||
if (GST_STATE_CHANGE_SUCCESS !=
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
|
||||
5 * GST_SECOND)) {
|
||||
g_print ("State change failed for %s. Aborting\n", filename);
|
||||
break;
|
||||
}
|
||||
} else if (sret != GST_STATE_CHANGE_SUCCESS) {
|
||||
g_print ("%s - Could not read file\n", filename);
|
||||
goto next_file;
|
||||
}
|
||||
|
||||
if (!message_loop (GST_ELEMENT (pipeline), &tags)) {
|
||||
g_print ("Failed in message reading for %s\n", argv[i]);
|
||||
}
|
||||
|
||||
if (tags) {
|
||||
g_print ("Metadata for %s:\n", argv[i]);
|
||||
gst_tag_list_foreach (tags, print_tag, NULL);
|
||||
gst_tag_list_free (tags);
|
||||
tags = NULL;
|
||||
} else
|
||||
g_print ("No metadata found for %s\n", argv[i]);
|
||||
|
||||
sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
#ifndef NEW_PIPE_PER_FILE
|
||||
if (GST_STATE_CHANGE_ASYNC == sret) {
|
||||
if (GST_STATE_CHANGE_FAILURE ==
|
||||
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
|
||||
GST_CLOCK_TIME_NONE)) {
|
||||
g_print ("State change failed. Aborting");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
next_file:
|
||||
i++;
|
||||
|
||||
#ifdef NEW_PIPE_PER_FILE
|
||||
make_pipeline ();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pipeline)
|
||||
gst_object_unref (pipeline);
|
||||
return 0;
|
||||
}
|
5
examples/mixer/.gitignore
vendored
5
examples/mixer/.gitignore
vendored
|
@ -1,5 +0,0 @@
|
|||
helloworld
|
||||
mixer
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = mixer
|
||||
noinst_HEADERS = mixer.h
|
||||
|
||||
mixer_LDADD = $(GST_OBJ_LIBS)
|
||||
mixer_CFLAGS = $(GST_OBJ_CFLAGS)
|
|
@ -1,398 +0,0 @@
|
|||
/*
|
||||
* mixer.c - stereo audio mixer - thomas@apestaart.org
|
||||
* example based on helloworld
|
||||
* demonstrates the adder plugin and the volume envelope plugin
|
||||
* work in progress but do try it out
|
||||
*
|
||||
* Latest change : 28/08/2001
|
||||
* trying to adapt to incsched
|
||||
* delayed start for channels > 1
|
||||
* now works by quickhacking the
|
||||
* adder plugin to set
|
||||
* GST_ELEMENT_COTHREAD_STOPPING
|
||||
* Version : 0.5.1
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
#include "mixer.h"
|
||||
#include <unistd.h>
|
||||
|
||||
/*#define WITH_BUG */
|
||||
/*#define WITH_BUG2 */
|
||||
/*#define DEBUG */
|
||||
/*#define AUTOPLUG * define if you want autoplugging of input channels * */
|
||||
/* function prototypes */
|
||||
|
||||
input_channel_t *create_input_channel (int id, char *location);
|
||||
void destroy_input_channel (input_channel_t * pipe);
|
||||
void env_register_cp (GstElement * volenv, double cp_time, double cp_level);
|
||||
|
||||
|
||||
gboolean playing;
|
||||
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement * element)
|
||||
{
|
||||
g_print ("have eos, quitting ?\n");
|
||||
|
||||
/* playing = FALSE; */
|
||||
}
|
||||
|
||||
G_GNUC_UNUSED static GstCaps *
|
||||
gst_play_type_find (GstBin * bin, GstElement * element)
|
||||
{
|
||||
GstElement *typefind;
|
||||
GstElement *pipeline;
|
||||
GstCaps *caps = NULL;
|
||||
|
||||
GST_DEBUG ("GstPipeline: typefind for element \"%s\"",
|
||||
GST_ELEMENT_NAME (element));
|
||||
|
||||
pipeline = gst_pipeline_new ("autoplug_pipeline");
|
||||
|
||||
typefind = gst_element_factory_make ("typefind", "typefind");
|
||||
g_return_val_if_fail (typefind != NULL, FALSE);
|
||||
|
||||
gst_pad_link (gst_element_get_pad (element, "src"),
|
||||
gst_element_get_pad (typefind, "sink"));
|
||||
gst_bin_add (bin, typefind);
|
||||
gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (bin));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
|
||||
/* push a buffer... the have_type signal handler will set the found flag */
|
||||
gst_bin_iterate (GST_BIN (pipeline));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
|
||||
caps = gst_pad_get_caps (gst_element_get_pad (element, "src"));
|
||||
|
||||
gst_pad_unlink (gst_element_get_pad (element, "src"),
|
||||
gst_element_get_pad (typefind, "sink"));
|
||||
gst_bin_remove (bin, typefind);
|
||||
gst_bin_remove (GST_BIN (pipeline), GST_ELEMENT (bin));
|
||||
gst_object_unref (typefind);
|
||||
gst_object_unref (pipeline);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
int num_channels;
|
||||
|
||||
char buffer[20];
|
||||
|
||||
GList *input_channels; /* structure holding all the input channels */
|
||||
|
||||
input_channel_t *channel_in;
|
||||
|
||||
GstElement *main_bin;
|
||||
GstElement *adder;
|
||||
GstElement *audiosink;
|
||||
|
||||
GstPad *pad; /* to request pads for the adder */
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc == 1) {
|
||||
g_print ("usage: %s <filename1> <filename2> <...>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
num_channels = argc - 1;
|
||||
|
||||
/* set up output channel and main bin */
|
||||
|
||||
/* create adder */
|
||||
adder = gst_element_factory_make ("adder", "adderel");
|
||||
|
||||
/* create an audio sink */
|
||||
audiosink = gst_element_factory_make ("esdsink", "play_audio");
|
||||
|
||||
/* create main bin */
|
||||
main_bin = gst_pipeline_new ("bin");
|
||||
|
||||
/* link adder and output to bin */
|
||||
GST_INFO ("main: adding adder to bin");
|
||||
gst_bin_add (GST_BIN (main_bin), adder);
|
||||
GST_INFO ("main: adding audiosink to bin");
|
||||
gst_bin_add (GST_BIN (main_bin), audiosink);
|
||||
|
||||
/* link adder and audiosink */
|
||||
|
||||
gst_pad_link (gst_element_get_pad (adder, "src"),
|
||||
gst_element_get_pad (audiosink, "sink"));
|
||||
|
||||
/* start looping */
|
||||
input_channels = NULL;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
printf ("Opening channel %d from file %s...\n", i, argv[i]);
|
||||
channel_in = create_input_channel (i, argv[i]);
|
||||
input_channels = g_list_append (input_channels, channel_in);
|
||||
|
||||
if (i > 1)
|
||||
gst_element_set_state (main_bin, GST_STATE_PAUSED);
|
||||
gst_bin_add (GST_BIN (main_bin), channel_in->pipe);
|
||||
|
||||
/* request pads and link to adder */
|
||||
GST_INFO ("requesting pad\n");
|
||||
pad = gst_element_get_request_pad (adder, "sink%d");
|
||||
printf ("\tGot new adder sink pad %s\n", gst_pad_get_name (pad));
|
||||
sprintf (buffer, "channel%d", i);
|
||||
gst_pad_link (gst_element_get_pad (channel_in->pipe, buffer), pad);
|
||||
|
||||
/* register a volume envelope */
|
||||
printf ("\tregistering volume envelope...\n");
|
||||
|
||||
/*
|
||||
* this is the volenv :
|
||||
* each song gets a slot of 5 seconds, with a 5 second fadeout
|
||||
* at the end of that, all audio streams play simultaneously
|
||||
* at a level ensuring no distortion
|
||||
* example for three songs :
|
||||
* song1 : starts at full level, plays 5 seconds, faded out at 10 seconds,
|
||||
* sleep until 25, fade to end level at 30
|
||||
* song2 : starts silent, fades in at 5 seconds, full blast at 10 seconds,
|
||||
* full level until 15, faded out at 20, sleep until 25, fade to end at 30
|
||||
* song3 : starts muted, fades in from 15, full at 20, until 25, fade to end level
|
||||
*/
|
||||
|
||||
if (i == 1) {
|
||||
/* first song gets special treatment for end style */
|
||||
env_register_cp (channel_in->volenv, 0.0, 1.0);
|
||||
} else {
|
||||
env_register_cp (channel_in->volenv, 0.0, 0.0000001); /* start muted */
|
||||
env_register_cp (channel_in->volenv, i * 10.0 - 15.0, 0.0000001); /* start fade in */
|
||||
env_register_cp (channel_in->volenv, i * 10.0 - 10.0, 1.0);
|
||||
}
|
||||
env_register_cp (channel_in->volenv, i * 10.0 - 5.0, 1.0); /* end of full level */
|
||||
|
||||
if (i != num_channels) {
|
||||
env_register_cp (channel_in->volenv, i * 10.0, 0.0000001); /* fade to black */
|
||||
env_register_cp (channel_in->volenv, num_channels * 10.0 - 5.0, 0.0000001); /* start fade in */
|
||||
}
|
||||
env_register_cp (channel_in->volenv, num_channels * 10.0, 1.0 / num_channels); /* to end level */
|
||||
|
||||
#ifndef GST_DISABLE_LOADSAVE
|
||||
gst_xml_write_file (GST_ELEMENT (main_bin), fopen ("mixer.xml", "w"));
|
||||
#endif
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (main_bin, GST_STATE_PLAYING);
|
||||
|
||||
/* write out the schedule */
|
||||
gst_scheduler_show (GST_ELEMENT_SCHEDULER (main_bin));
|
||||
playing = TRUE;
|
||||
|
||||
j = 0;
|
||||
/*printf ("main: start iterating from 0"); */
|
||||
while (playing && j < 100) {
|
||||
/* printf ("main: iterating %d\n", j); */
|
||||
gst_bin_iterate (GST_BIN (main_bin));
|
||||
/*fprintf(stderr,"after iterate()\n"); */
|
||||
++j;
|
||||
}
|
||||
}
|
||||
printf ("main: all the channels are open\n");
|
||||
while (playing) {
|
||||
gst_bin_iterate (GST_BIN (main_bin));
|
||||
/*fprintf(stderr,"after iterate()\n"); */
|
||||
}
|
||||
/* stop the bin */
|
||||
gst_element_set_state (main_bin, GST_STATE_NULL);
|
||||
|
||||
while (input_channels) {
|
||||
destroy_input_channel (input_channels->data);
|
||||
input_channels = g_list_next (input_channels);
|
||||
}
|
||||
g_list_free (input_channels);
|
||||
|
||||
gst_object_unref (audiosink);
|
||||
|
||||
gst_object_unref (main_bin);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
input_channel_t *
|
||||
create_input_channel (int id, char *location)
|
||||
{
|
||||
/* create an input channel, reading from location
|
||||
* return a pointer to the channel
|
||||
* return NULL if failed
|
||||
*/
|
||||
|
||||
input_channel_t *channel;
|
||||
|
||||
char buffer[20]; /* hold the names */
|
||||
|
||||
/* GstAutoplug *autoplug;
|
||||
GstCaps *srccaps; */
|
||||
GstElement *new_element;
|
||||
GstElement *decoder;
|
||||
|
||||
GST_DEBUG ("c_i_p : creating channel with id %d for file %s", id, location);
|
||||
|
||||
/* allocate channel */
|
||||
|
||||
channel = (input_channel_t *) malloc (sizeof (input_channel_t));
|
||||
if (channel == NULL) {
|
||||
printf ("create_input_channel : could not allocate memory for channel !\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create channel */
|
||||
|
||||
GST_DEBUG ("c_i_p : creating pipeline");
|
||||
|
||||
sprintf (buffer, "pipeline%d", id);
|
||||
channel->pipe = gst_bin_new (buffer);
|
||||
g_assert (channel->pipe != NULL);
|
||||
|
||||
/* create elements */
|
||||
|
||||
GST_DEBUG ("c_i_p : creating filesrc");
|
||||
|
||||
sprintf (buffer, "filesrc%d", id);
|
||||
channel->filesrc = gst_element_factory_make ("filesrc", buffer);
|
||||
g_assert (channel->filesrc != NULL);
|
||||
|
||||
GST_DEBUG ("c_i_p : setting location");
|
||||
g_object_set (G_OBJECT (channel->filesrc), "location", location, NULL);
|
||||
|
||||
/* add filesrc to the bin before autoplug */
|
||||
gst_bin_add (GST_BIN (channel->pipe), channel->filesrc);
|
||||
|
||||
/* link signal to eos of filesrc */
|
||||
g_signal_connect (G_OBJECT (channel->filesrc), "eos", G_CALLBACK (eos), NULL);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : c_i_p : creating volume envelope\n");
|
||||
#endif
|
||||
|
||||
sprintf (buffer, "volenv%d", id);
|
||||
channel->volenv = gst_element_factory_make ("volenv", buffer);
|
||||
g_assert (channel->volenv != NULL);
|
||||
|
||||
/* autoplug the pipe */
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : c_i_p : getting srccaps\n");
|
||||
#endif
|
||||
|
||||
#ifdef WITH_BUG
|
||||
srccaps = gst_play_type_find (GST_BIN (channel->pipe), channel->filesrc);
|
||||
#endif
|
||||
#ifdef WITH_BUG2
|
||||
{
|
||||
GstElement *pipeline;
|
||||
|
||||
pipeline = gst_pipeline_new ("autoplug_pipeline");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), channel->pipe);
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_bin_remove (GST_BIN (pipeline), channel->pipe);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef AUTOPLUG
|
||||
if (!srccaps) {
|
||||
g_print ("could not autoplug, unknown media type...\n");
|
||||
exit (-1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : c_i_p : creating autoplug\n");
|
||||
#endif
|
||||
|
||||
autoplug = gst_autoplug_factory_make ("static");
|
||||
g_assert (autoplug != NULL);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : c_i_p : autoplugging\n");
|
||||
#endif
|
||||
|
||||
new_element = gst_autoplug_to_caps (autoplug, srccaps,
|
||||
gst_caps_new ("audio/raw", NULL), NULL);
|
||||
|
||||
if (!new_element) {
|
||||
g_print ("could not autoplug, no suitable codecs found...\n");
|
||||
exit (-1);
|
||||
}
|
||||
#else
|
||||
|
||||
new_element = gst_bin_new ("autoplug_bin");
|
||||
|
||||
/* static plug, use mad plugin and assume mp3 input */
|
||||
printf ("using static plugging for input channel\n");
|
||||
decoder = gst_element_factory_make ("mad", "mpg123");
|
||||
if (!decoder) {
|
||||
fprintf (stderr, "Could not get a decoder element !\n");
|
||||
exit (1);
|
||||
}
|
||||
gst_bin_add (GST_BIN (new_element), decoder);
|
||||
|
||||
gst_element_add_ghost_pad (new_element,
|
||||
gst_element_get_pad (decoder, "sink"), "sink");
|
||||
gst_element_add_ghost_pad (new_element,
|
||||
gst_element_get_pad (decoder, "src"), "src_00");
|
||||
|
||||
#endif
|
||||
#ifndef GST_DISABLE_LOADSAVE
|
||||
gst_xml_write_file (GST_ELEMENT (new_element), fopen ("mixer.gst", "w"));
|
||||
#endif
|
||||
|
||||
gst_bin_add (GST_BIN (channel->pipe), channel->volenv);
|
||||
gst_bin_add (GST_BIN (channel->pipe), new_element);
|
||||
|
||||
gst_element_link_pads (channel->filesrc, "src", new_element, "sink");
|
||||
gst_element_link_pads (new_element, "src_00", channel->volenv, "sink");
|
||||
|
||||
/* add a ghost pad */
|
||||
sprintf (buffer, "channel%d", id);
|
||||
gst_element_add_ghost_pad (channel->pipe,
|
||||
gst_element_get_pad (channel->volenv, "src"), buffer);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : c_i_p : end function\n");
|
||||
#endif
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
void
|
||||
destroy_input_channel (input_channel_t * channel)
|
||||
{
|
||||
/*
|
||||
* destroy an input channel
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("DEBUG : d_i_p : start\n");
|
||||
#endif
|
||||
|
||||
/* destroy elements */
|
||||
|
||||
gst_object_unref (channel->pipe);
|
||||
|
||||
free (channel);
|
||||
}
|
||||
|
||||
void
|
||||
env_register_cp (GstElement * volenv, double cp_time, double cp_level)
|
||||
{
|
||||
char buffer[30];
|
||||
|
||||
sprintf (buffer, "%f:%f", cp_time, cp_level);
|
||||
g_object_set (G_OBJECT (volenv), "controlpoint", buffer, NULL);
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* mixer.h header file
|
||||
* thomas@apestaart.org
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstElement *pipe, *filesrc, *volenv;
|
||||
|
||||
char *location;
|
||||
int channel_id;
|
||||
} input_channel_t;
|
12
examples/pingpong/.gitignore
vendored
12
examples/pingpong/.gitignore
vendored
|
@ -1,12 +0,0 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
||||
|
||||
pingpong
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = pingpong
|
||||
|
||||
pingpong_LDADD = $(GST_OBJ_LIBS)
|
||||
pingpong_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* 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/gst.h>
|
||||
|
||||
static GstElement *
|
||||
make_bin (gint count)
|
||||
{
|
||||
GstElement *bin;
|
||||
GstElement *src;
|
||||
char *name;
|
||||
|
||||
name = g_strdup_printf ("bin%d", count);
|
||||
bin = gst_bin_new (name);
|
||||
g_free (name);
|
||||
|
||||
name = g_strdup_printf ("fakesrc%d", count);
|
||||
src = gst_element_factory_make ("fakesrc", name);
|
||||
g_free (name);
|
||||
|
||||
gst_bin_add (GST_BIN (bin), src);
|
||||
|
||||
gst_element_add_ghost_pad (bin, gst_element_get_pad (src, "src"), "src");
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc, gchar * argv[])
|
||||
{
|
||||
GstElement *pipeline;
|
||||
GstElement *aggregator, *sink;
|
||||
GstElement *bin1, *bin2;
|
||||
GstPad *pad1, *pad2;
|
||||
gint i;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
pipeline = gst_pipeline_new ("main");
|
||||
g_signal_connect (pipeline, "deep_notify",
|
||||
G_CALLBACK (gst_element_default_deep_notify), NULL);
|
||||
|
||||
aggregator = gst_element_factory_make ("aggregator", "mixer");
|
||||
sink = gst_element_factory_make ("fakesink", "sink");
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), aggregator);
|
||||
gst_bin_add (GST_BIN (pipeline), sink);
|
||||
|
||||
gst_element_link_pads (aggregator, "src", sink, "sink");
|
||||
|
||||
bin1 = make_bin (1);
|
||||
pad1 = gst_element_get_request_pad (aggregator, "sink%d");
|
||||
gst_pad_link (gst_element_get_pad (bin1, "src"), pad1);
|
||||
gst_bin_add (GST_BIN (pipeline), bin1);
|
||||
|
||||
bin2 = make_bin (2);
|
||||
pad2 = gst_element_get_request_pad (aggregator, "sink%d");
|
||||
gst_pad_link (gst_element_get_pad (bin2, "src"), pad2);
|
||||
gst_bin_add (GST_BIN (pipeline), bin2);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
i = 2;
|
||||
while (i--)
|
||||
gst_bin_iterate (GST_BIN (pipeline));
|
||||
|
||||
g_print ("pause bin1\n");
|
||||
gst_element_set_state (bin1, GST_STATE_PAUSED);
|
||||
|
||||
i = 4;
|
||||
while (i--)
|
||||
gst_bin_iterate (GST_BIN (pipeline));
|
||||
|
||||
g_print ("playing bin1\n");
|
||||
gst_element_set_state (bin1, GST_STATE_PLAYING);
|
||||
|
||||
i = 4;
|
||||
while (i--)
|
||||
gst_bin_iterate (GST_BIN (pipeline));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
|
||||
return 0;
|
||||
}
|
10
examples/plugins/.gitignore
vendored
10
examples/plugins/.gitignore
vendored
|
@ -1,10 +0,0 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
plugin_LTLIBRARIES = libgstexample.la
|
||||
|
||||
libgstexample_la_SOURCES = example.c
|
||||
libgstexample_la_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
libgstexample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||
|
||||
noinst_HEADERS = example.h
|
||||
|
||||
## ... but we don't want them installed so we override the install target
|
||||
install:
|
||||
@true
|
|
@ -1,426 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* First, include the header file for the plugin, to bring in the
|
||||
* object definition and other useful things.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "example.h"
|
||||
|
||||
/* The ElementDetails structure gives a human-readable description of the
|
||||
* plugin, as well as author and version data. Use the GST_ELEMENT_DETAILS
|
||||
* macro when defining it.
|
||||
*/
|
||||
static GstElementDetails example_details =
|
||||
GST_ELEMENT_DETAILS ("An example plugin",
|
||||
"Example/FirstExample",
|
||||
"Shows the basic structure of a plugin",
|
||||
"your name <your.name@your.isp>");
|
||||
|
||||
/* These are the signals that this element can fire. They are zero-
|
||||
* based because the numbers themselves are private to the object.
|
||||
* LAST_SIGNAL is used for initialization of the signal array.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
ASDF,
|
||||
/* FILL ME */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
/* Arguments are identified the same way, but cannot be zero, so you
|
||||
* must leave the ARG_0 entry in as a placeholder.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
ARG_0,
|
||||
ARG_ACTIVE
|
||||
/* FILL ME */
|
||||
};
|
||||
|
||||
/* The PadFactory structures describe what pads the element has or
|
||||
* can have. They can be quite complex, but for this example plugin
|
||||
* they are rather simple.
|
||||
*/
|
||||
GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", /* The name of the pad */
|
||||
GST_PAD_SINK, /* Direction of the pad */
|
||||
GST_PAD_ALWAYS, /* The pad exists for every instance */
|
||||
GST_STATIC_CAPS ("unknown/unknown, " /* The MIME media type */
|
||||
"foo:int=1, " /* an integer property */
|
||||
"bar:boolean=true, " /* a boolean property */
|
||||
"baz:int={ 1, 3 }" /* a list of values */
|
||||
)
|
||||
);
|
||||
|
||||
/* This factory is much simpler, and defines the source pad. */
|
||||
GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("unknown/unknown")
|
||||
);
|
||||
|
||||
|
||||
/* A number of function prototypes are given so we can refer to them later. */
|
||||
static void gst_example_class_init (GstExampleClass * klass);
|
||||
static void gst_example_init (GstExample * example);
|
||||
|
||||
static void gst_example_chain (GstPad * pad, GstData * _data);
|
||||
|
||||
static void gst_example_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_example_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
static GstStateChangeReturn gst_example_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
/* The parent class pointer needs to be kept around for some object
|
||||
* operations.
|
||||
*/
|
||||
static GstElementClass *parent_class = NULL;
|
||||
|
||||
/* This array holds the ids of the signals registered for this object.
|
||||
* The array indexes are based on the enum up above.
|
||||
*/
|
||||
static guint gst_example_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
/* This function is used to register and subsequently return the type
|
||||
* identifier for this object class. On first invocation, it will
|
||||
* register the type, providing the name of the class, struct sizes,
|
||||
* and pointers to the various functions that define the class.
|
||||
*/
|
||||
GType
|
||||
gst_example_get_type (void)
|
||||
{
|
||||
static GType example_type = 0;
|
||||
|
||||
if (!example_type) {
|
||||
static const GTypeInfo example_info = {
|
||||
sizeof (GstExampleClass),
|
||||
NULL,
|
||||
NULL,
|
||||
(GClassInitFunc) gst_example_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstExample),
|
||||
0,
|
||||
(GInstanceInitFunc) gst_example_init,
|
||||
};
|
||||
example_type =
|
||||
g_type_register_static (GST_TYPE_ELEMENT, "GstExample", &example_info,
|
||||
0);
|
||||
}
|
||||
return example_type;
|
||||
}
|
||||
|
||||
/* In order to create an instance of an object, the class must be
|
||||
* initialized by this function. GObject will take care of running
|
||||
* it, based on the pointer to the function provided above.
|
||||
*/
|
||||
static void
|
||||
gst_example_class_init (GstExampleClass * klass)
|
||||
{
|
||||
/* Class pointers are needed to supply pointers to the private
|
||||
* implementations of parent class methods.
|
||||
*/
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
/* Since the example class contains the parent classes, you can simply
|
||||
* cast the pointer to get access to the parent classes.
|
||||
*/
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
/* The parent class is needed for class method overrides. */
|
||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||
|
||||
/* Here we add an argument to the object. This argument is an integer,
|
||||
* and can be both read and written.
|
||||
*/
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ACTIVE, g_param_spec_int ("active", "active", "active", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
||||
|
||||
/* Here we add a signal to the object. This is a very useless signal
|
||||
* called asdf. The signal will also pass a pointer to the listeners
|
||||
* which happens to be the example element itself */
|
||||
gst_example_signals[ASDF] =
|
||||
g_signal_new ("asdf", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GstExampleClass, asdf), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, GST_TYPE_EXAMPLE);
|
||||
|
||||
|
||||
/* The last thing is to provide the functions that implement get and set
|
||||
* of arguments.
|
||||
*/
|
||||
gobject_class->set_property = gst_example_set_property;
|
||||
gobject_class->get_property = gst_example_get_property;
|
||||
|
||||
/* we also override the default state change handler with our own
|
||||
* implementation */
|
||||
gstelement_class->change_state = gst_example_change_state;
|
||||
/* We can now provide the details for this element, that we defined earlier. */
|
||||
gst_element_class_set_details (gstelement_class, &example_details);
|
||||
/* The pad templates can be easily generated from the factories above,
|
||||
* and then added to the list of padtemplates for the class.
|
||||
*/
|
||||
gst_element_class_add_pad_template (gstelement_class,
|
||||
gst_static_pad_template_get (&sink_template));
|
||||
gst_element_class_add_pad_template (gstelement_class,
|
||||
gst_static_pad_template_get (&src_template));
|
||||
}
|
||||
|
||||
/* This function is responsible for initializing a specific instance of
|
||||
* the plugin.
|
||||
*/
|
||||
static void
|
||||
gst_example_init (GstExample * example)
|
||||
{
|
||||
/* First we create the sink pad, which is the input to the element.
|
||||
* We will use the template constructed by the factory.
|
||||
*/
|
||||
example->sinkpad =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
||||
"sink");
|
||||
/* Setting the chain function allows us to supply the function that will
|
||||
* actually be performing the work. Without this, the element would do
|
||||
* nothing, with undefined results (assertion failures and such).
|
||||
*/
|
||||
gst_pad_set_chain_function (example->sinkpad, gst_example_chain);
|
||||
/* We then must add this pad to the element's list of pads. The base
|
||||
* element class manages the list of pads, and provides accessors to it.
|
||||
*/
|
||||
gst_element_add_pad (GST_ELEMENT (example), example->sinkpad);
|
||||
|
||||
/* The src pad, the output of the element, is created and registered
|
||||
* in the same way, with the exception of the chain function. Source
|
||||
* pads don't have chain functions, because they can't accept buffers,
|
||||
* they only produce them.
|
||||
*/
|
||||
example->srcpad =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
||||
"src");
|
||||
gst_element_add_pad (GST_ELEMENT (example), example->srcpad);
|
||||
|
||||
/* Initialization of element's private variables. */
|
||||
example->active = FALSE;
|
||||
}
|
||||
|
||||
/* The chain function is the heart of the element. It's where all the
|
||||
* work is done. It is passed a pointer to the pad in question, as well
|
||||
* as the buffer provided by the peer element.
|
||||
*/
|
||||
static void
|
||||
gst_example_chain (GstPad * pad, GstData * _data)
|
||||
{
|
||||
GstBuffer *buf = GST_BUFFER (_data);
|
||||
GstExample *example;
|
||||
GstBuffer *outbuf;
|
||||
|
||||
/* Some of these checks are of dubious value, since if there were not
|
||||
* already true, the chain function would never be called.
|
||||
*/
|
||||
g_return_if_fail (pad != NULL);
|
||||
g_return_if_fail (GST_IS_PAD (pad));
|
||||
g_return_if_fail (buf != NULL);
|
||||
|
||||
/* We need to get a pointer to the element this pad belongs to. */
|
||||
example = GST_EXAMPLE (gst_pad_get_parent (pad));
|
||||
|
||||
/* A few more sanity checks to make sure that the element that owns
|
||||
* this pad is the right kind of element, in case something got confused.
|
||||
*/
|
||||
g_return_if_fail (example != NULL);
|
||||
g_return_if_fail (GST_IS_EXAMPLE (example));
|
||||
|
||||
/* If we are supposed to be doing something, here's where it happens. */
|
||||
if (example->active) {
|
||||
/* In this example we're going to copy the buffer to another one,
|
||||
* so we need to allocate a new buffer first. */
|
||||
outbuf = gst_buffer_new ();
|
||||
|
||||
/* We need to copy the size and offset of the buffer at a minimum. */
|
||||
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf);
|
||||
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buf);
|
||||
|
||||
/* Then allocate the memory for the new buffer */
|
||||
GST_BUFFER_DATA (outbuf) = (guchar *) g_malloc (GST_BUFFER_SIZE (outbuf));
|
||||
|
||||
/* Then copy the data in the incoming buffer into the new buffer. */
|
||||
memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (buf),
|
||||
GST_BUFFER_SIZE (outbuf));
|
||||
|
||||
/* we don't need the incomming buffer anymore so we unref it. When we are
|
||||
* the last plugin with a handle to the buffer, its memory will be freed */
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
/* When we're done with the buffer, we push it on to the next element
|
||||
* in the pipeline, through the element's source pad, which is stored
|
||||
* in the element's structure.
|
||||
*/
|
||||
gst_pad_push (example->srcpad, GST_DATA (outbuf));
|
||||
|
||||
/* For fun we'll emit our useless signal here */
|
||||
g_signal_emit (G_OBJECT (example), gst_example_signals[ASDF], 0, example);
|
||||
|
||||
/* If we're not doing something, just send the original incoming buffer. */
|
||||
} else {
|
||||
gst_pad_push (example->srcpad, GST_DATA (buf));
|
||||
}
|
||||
}
|
||||
|
||||
/* Properties are part of the GLib+ object system, and these functions
|
||||
* enable the element to respond to various properties.
|
||||
*/
|
||||
static void
|
||||
gst_example_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
g_return_if_fail (GST_IS_EXAMPLE (object));
|
||||
|
||||
/* Get a pointer of the right type. */
|
||||
example = GST_EXAMPLE (object);
|
||||
|
||||
/* Check the argument id to see which argument we're setting. */
|
||||
switch (prop_id) {
|
||||
case ARG_ACTIVE:
|
||||
/* Here we simply copy the value of the argument to our private
|
||||
* storage. More complex operations can be done, but beware that
|
||||
* they may occur at any time, possibly even while your chain function
|
||||
* is running, if you are using threads.
|
||||
*/
|
||||
example->active = g_value_get_int (value);
|
||||
g_print ("example: set active to %d\n", example->active);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* The set function is simply the inverse of the get fuction. */
|
||||
static void
|
||||
gst_example_get_property (GObject * object, guint prop_id, GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
g_return_if_fail (GST_IS_EXAMPLE (object));
|
||||
|
||||
example = GST_EXAMPLE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_ACTIVE:
|
||||
g_value_set_int (value, example->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is the state change function that will be called when
|
||||
* the element goes through the different state changes.
|
||||
* The plugin can prepare itself and its internal data structures
|
||||
* in the various state transitions.
|
||||
*/
|
||||
static GstStateChangeReturn
|
||||
gst_example_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
/* cast to our plugin */
|
||||
example = GST_EXAMPLE (element);
|
||||
|
||||
/* we perform our actions based on the state transition
|
||||
* of the element */
|
||||
switch (transition) {
|
||||
/* The NULL to READY transition is used to
|
||||
* create threads (if any), and/or open devices */
|
||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
break;
|
||||
/* In the PAUSED to PLAYING state, the element should
|
||||
* prepare itself for operation or continue after a PAUSE */
|
||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||
break;
|
||||
/* In the PLAYING to PAUSED state, the element should
|
||||
* PAUSE itself and make sure it can resume operation */
|
||||
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
||||
break;
|
||||
/* In the PAUSED to READY state, the element should reset
|
||||
* its internal state and close any devices. */
|
||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||
break;
|
||||
/* The element should free all resources, terminate threads
|
||||
* and put itself into its initial state again */
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Then we call the parent state change handler */
|
||||
return parent_class->change_state (element, transition);
|
||||
}
|
||||
|
||||
|
||||
/* This is the entry into the plugin itself. When the plugin loads,
|
||||
* this function is called to register everything that the plugin provides.
|
||||
*/
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
/* We need to register each element we provide with the plugin. This consists
|
||||
* of the name of the element, a rank that gives the importance of the element
|
||||
* when compared to similar plugins and the GType identifier.
|
||||
*/
|
||||
if (!gst_element_register (plugin, "example", GST_RANK_MARGINAL,
|
||||
GST_TYPE_EXAMPLE))
|
||||
return FALSE;
|
||||
|
||||
/* Now we can return successfully. */
|
||||
return TRUE;
|
||||
|
||||
/* At this point, the GStreamer core registers the plugin, its
|
||||
* elementfactories, padtemplates, etc., for use in your application.
|
||||
*/
|
||||
}
|
||||
|
||||
/* This structure describes the plugin to the system for dynamically loading
|
||||
* plugins, so that the version number and name can be checked in a uniform
|
||||
* way.
|
||||
*
|
||||
* The symbol pointing to this structure is the only symbol looked up when
|
||||
* loading the plugin.
|
||||
*/
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, /* The major version of the core that this was built with */
|
||||
GST_VERSION_MINOR, /* The minor version of the core that this was built with */
|
||||
"example", /* The name of the plugin. This must be unique: plugins with
|
||||
* the same name will be assumed to be identical, and only
|
||||
* one will be loaded. */
|
||||
"an example plugin", /* a short description of the plugin in English */
|
||||
plugin_init, /* Pointer to the initialisation function for the plugin. */
|
||||
"0.1", /* The version number of the plugin */
|
||||
"LGPL", /* effective license the plugin can be shipped with. Must be
|
||||
* valid for all libraries it links to, too. */
|
||||
"my nifty plugin package",
|
||||
/* package this plugin belongs to. */
|
||||
"http://www.mydomain.com"
|
||||
/* originating URL for this plugin. This is the place to look
|
||||
* for updates, information and so on. */
|
||||
);
|
|
@ -1,87 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_EXAMPLE_H__
|
||||
#define __GST_EXAMPLE_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* This is the definition of the element's object structure. */
|
||||
typedef struct _GstExample GstExample;
|
||||
|
||||
/* The structure itself is derived from GstElement, as can be seen by the
|
||||
* fact that there's a complete instance of the GstElement structure at
|
||||
* the beginning of the object. This allows the element to be cast to
|
||||
* an Element or even an Object.
|
||||
*/
|
||||
struct _GstExample {
|
||||
GstElement element;
|
||||
|
||||
/* We need to keep track of our pads, so we do so here. */
|
||||
GstPad *sinkpad,*srcpad;
|
||||
|
||||
/* We'll use this to decide whether to do anything to the data we get. */
|
||||
gboolean active;
|
||||
};
|
||||
|
||||
/* The other half of the object is its class. The class also derives from
|
||||
* the same parent, though it must be the class structure this time.
|
||||
* Function pointers for polymophic methods and signals are placed in this
|
||||
* structure. */
|
||||
typedef struct _GstExampleClass GstExampleClass;
|
||||
|
||||
struct _GstExampleClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*asdf) (GstElement *element, GstExample *example);
|
||||
};
|
||||
|
||||
/* Five standard preprocessing macros are used in the GLib object system.
|
||||
* The first uses the object's _get_type function to return the GType
|
||||
* of the object.
|
||||
*/
|
||||
#define GST_TYPE_EXAMPLE \
|
||||
(gst_example_get_type())
|
||||
/* The second is a checking cast to the correct type. If the object passed
|
||||
* is not the right type, a warning will be generated on stderr.
|
||||
*/
|
||||
#define GST_EXAMPLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EXAMPLE,GstExample))
|
||||
/* The third is a checking cast of the class instead of the object. */
|
||||
#define GST_EXAMPLE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EXAMPLE,GstExampleClass))
|
||||
/* The last two simply check to see if the passed pointer is an object or
|
||||
* class of the correct type. */
|
||||
#define GST_IS_EXAMPLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EXAMPLE))
|
||||
#define GST_IS_EXAMPLE_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EXAMPLE))
|
||||
|
||||
/* This is the only prototype needed, because it is used in the above
|
||||
* GST_TYPE_EXAMPLE macro.
|
||||
*/
|
||||
GType gst_example_get_type(void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_EXAMPLE_H__ */
|
18
examples/pwg/.gitignore
vendored
18
examples/pwg/.gitignore
vendored
|
@ -1,18 +0,0 @@
|
|||
boilerplate.c
|
||||
caps.func
|
||||
chain2.c
|
||||
chain.c
|
||||
chain.func
|
||||
convertcaps.c
|
||||
filter.h
|
||||
forwardcaps.c
|
||||
getcaps.c
|
||||
init.func
|
||||
pads.c
|
||||
properties.c
|
||||
range.c
|
||||
register.func
|
||||
state.c
|
||||
state.func
|
||||
task.c
|
||||
test.c
|
|
@ -1,88 +0,0 @@
|
|||
INCLUDES = $(GST_OBJ_CFLAGS) \
|
||||
-DVERSION="\"0.0.1\""
|
||||
|
||||
libboilerplate_la_SOURCES = boilerplate.c
|
||||
libpads_la_SOURCES = pads.c
|
||||
libchain_la_SOURCES = chain.c
|
||||
libchain2_la_SOURCES = chain2.c
|
||||
libstate_la_SOURCES = state.c
|
||||
libproperties_la_SOURCES = properties.c
|
||||
libforwardcaps_la_SOURCES = forwardcaps.c
|
||||
libconvertcaps_la_SOURCES = convertcaps.c
|
||||
libgetcaps_la_SOURCES = getcaps.c
|
||||
libtask_la_SOURCES = task.c
|
||||
librange_la_SOURCES = range.c
|
||||
DISTCLEANFILES = \
|
||||
boilerplate.c pads.c chain.c chain2.c state.c properties.c \
|
||||
forwardcaps.c convertcaps.c getcaps.c task.c range.c \
|
||||
init.func caps.func chain.func state.func register.func filter.h
|
||||
|
||||
EXTRA_DIST = extract.pl
|
||||
|
||||
EXAMPLES = \
|
||||
libboilerplate.la \
|
||||
libpads.la \
|
||||
libchain.la \
|
||||
libchain2.la \
|
||||
libstate.la \
|
||||
libproperties.la \
|
||||
libforwardcaps.la \
|
||||
libconvertcaps.la \
|
||||
libgetcaps.la \
|
||||
libtask.la \
|
||||
librange.la
|
||||
|
||||
EXAMPLE_APPS = \
|
||||
test
|
||||
|
||||
filter.h register.func: $(top_srcdir)/docs/pwg/building-boiler.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-boiler.xml
|
||||
|
||||
boilerplate.c: $(top_srcdir)/docs/pwg/building-boiler.xml filter.h register.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-boiler.xml
|
||||
|
||||
caps.func init.func: $(top_srcdir)/docs/pwg/building-pads.xml filter.h
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-pads.xml
|
||||
|
||||
pads.c: $(top_srcdir)/docs/pwg/building-pads.xml register.func caps.func init.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-pads.xml
|
||||
|
||||
chain.func: $(top_srcdir)/docs/pwg/building-chainfn.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-chainfn.xml
|
||||
|
||||
chain.c chain2.c: $(top_srcdir)/docs/pwg/building-chainfn.xml register.func caps.func init.func chain.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-chainfn.xml
|
||||
|
||||
state.func: $(top_srcdir)/docs/pwg/building-state.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-state.xml
|
||||
|
||||
state.c: $(top_srcdir)/docs/pwg/building-state.xml register.func caps.func init.func chain.func state.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-state.xml
|
||||
|
||||
properties.c: $(top_srcdir)/docs/pwg/building-props.xml filter.h register.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-props.xml
|
||||
|
||||
test.c: $(top_srcdir)/docs/pwg/building-testapp.xml
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/building-testapp.xml
|
||||
|
||||
forwardcaps.c convertcaps.c getcaps.c: $(top_srcdir)/docs/pwg/advanced-negotiation.xml init.func register.func chain.func state.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/advanced-negotiation.xml
|
||||
|
||||
task.c range.c: $(top_srcdir)/docs/pwg/advanced-scheduling.xml register.func
|
||||
$(PERL_PATH) $(srcdir)/extract.pl $@ \
|
||||
$(top_srcdir)/docs/pwg/advanced-scheduling.xml
|
||||
|
||||
noinst_PROGRAMS = $(EXAMPLE_APPS)
|
||||
noinst_LTLIBRARIES = $(EXAMPLES)
|
||||
LDADD = $(GST_OBJ_LIBS)
|
|
@ -1,78 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# extract code fragments from xml program listings
|
||||
# first argument: source code file to find
|
||||
# second argument: xml files to extract code from
|
||||
|
||||
# main
|
||||
|
||||
# decodes xml by translating & < > back to what they should be
|
||||
# and also ignore
|
||||
# <![CDATA[ and ]]> and <!-- and -->
|
||||
sub
|
||||
xml_decode ($)
|
||||
{
|
||||
my $input = shift;
|
||||
|
||||
$input =~ s/\&/&/g;
|
||||
$input =~ s/</</g;
|
||||
$input =~ s/>/>/g;
|
||||
|
||||
if ($input =~ /<!\[CDATA\[/) { $input = ""; }
|
||||
if ($input =~ /]]>/) { $input = ""; }
|
||||
if ($input =~ /<!--/) { $input = ""; }
|
||||
if ($input =~ /-->/) { $input = ""; }
|
||||
|
||||
#print "Returning line $input";
|
||||
return $input;
|
||||
}
|
||||
|
||||
# main
|
||||
my $output = shift @ARGV;
|
||||
|
||||
$found = 0;
|
||||
%blocks = ();
|
||||
|
||||
foreach $file (@ARGV)
|
||||
{
|
||||
open FILE, $file or die "Cannot open file $file";
|
||||
|
||||
while ($line = <FILE>)
|
||||
{
|
||||
if ($line =~ /<!-- example-begin $output (.*?)-->/)
|
||||
{
|
||||
$found = 1;
|
||||
$block_id = $1;
|
||||
$block = "\n/*** block $block_id from $file ***/\n";
|
||||
|
||||
print "Extracting $output block $block_id from $file\n";
|
||||
|
||||
while ($line = <FILE>)
|
||||
{
|
||||
if ($line =~ /<!-- example-end $output (.*?)-->/)
|
||||
{
|
||||
last;
|
||||
}
|
||||
$block .= xml_decode ($line);
|
||||
}
|
||||
$blocks{$block_id} = $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$found)
|
||||
{
|
||||
print "Could not find $output example !\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# now output all the blocks in the right order
|
||||
open OUTPUT, ">$output";
|
||||
@block_ids = keys %blocks;
|
||||
foreach $block_id (sort @block_ids)
|
||||
{
|
||||
print "Writing $output block $block_id\n";
|
||||
print OUTPUT $blocks{$block_id};
|
||||
}
|
||||
close OUTPUT;
|
4
examples/queue/.gitignore
vendored
4
examples/queue/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
queue
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = queue
|
||||
|
||||
queue_LDADD = $(GST_OBJ_LIBS)
|
||||
queue_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
/* This example uses the queue element to create a buffer between 2 elements.
|
||||
* The scheduler automatically uses 2 threads, 1 to feed and another to consume
|
||||
* data from the queue buffer
|
||||
*/
|
||||
|
||||
/* Event loop to listen to events posted on the GstBus from the pipeline. Exits
|
||||
* on EOS or ERROR events
|
||||
*/
|
||||
static void
|
||||
event_loop (GstElement * pipe)
|
||||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *audiosink, *decode, *queue;
|
||||
GstElement *pipeline;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new pipeline to hold the elements */
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
g_assert (pipeline != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
|
||||
decode = gst_element_factory_make ("mad", "decode");
|
||||
g_assert (decode != NULL);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
g_assert (queue != NULL);
|
||||
|
||||
/* and an audio sink */
|
||||
audiosink = gst_element_factory_make ("alsasink", "play_audio");
|
||||
g_assert (audiosink != NULL);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
gst_bin_add_many (GST_BIN (pipeline), filesrc, decode, queue, audiosink,
|
||||
NULL);
|
||||
|
||||
gst_element_link_many (filesrc, decode, queue, audiosink, NULL);
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
||||
|
||||
/* Listen for EOS */
|
||||
event_loop (pipeline);
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
4
examples/queue2/.gitignore
vendored
4
examples/queue2/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
queue2
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = queue2
|
||||
|
||||
queue2_LDADD = $(GST_OBJ_LIBS)
|
||||
queue2_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
gboolean playing;
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement * element, gpointer data)
|
||||
{
|
||||
g_print ("have eos, quitting\n");
|
||||
|
||||
playing = FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *audiosink, *queue;
|
||||
GstElement *pipeline;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
g_assert (pipeline != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
|
||||
/* and an audio sink */
|
||||
audiosink = gst_element_factory_make ("alsasink", "play_audio");
|
||||
g_assert (audiosink != NULL);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
/*
|
||||
gst_pipeline_add_src(GST_PIPELINE(pipeline), filesrc);
|
||||
gst_pipeline_add_sink(GST_PIPELINE(pipeline), queue);
|
||||
|
||||
gst_bin_add(GST_BIN (pipeline), audiosink);
|
||||
|
||||
gst_pad_link(gst_element_get_pad(queue,"src"),
|
||||
gst_element_get_pad(audiosink,"sink"));
|
||||
|
||||
if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
|
||||
g_print("cannot autoplug pipeline\n");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
|
||||
gst_bin_add (GST_BIN (pipeline), thread);
|
||||
|
||||
/* make it ready */
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
||||
|
||||
playing = TRUE;
|
||||
|
||||
while (playing) {
|
||||
gst_bin_iterate (GST_BIN (pipeline));
|
||||
}
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
4
examples/queue3/.gitignore
vendored
4
examples/queue3/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
queue3
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = queue3
|
||||
|
||||
queue3_LDADD = $(GST_OBJ_LIBS)
|
||||
queue3_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
gboolean playing;
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement * element, gpointer data)
|
||||
{
|
||||
g_print ("have eos, quitting\n");
|
||||
|
||||
playing = FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *osssink, *queue, *parse, *decode;
|
||||
GstElement *bin;
|
||||
GstElement *thread;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new thread to hold the elements */
|
||||
thread = gst_thread_new ("thread");
|
||||
g_assert (thread != NULL);
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
bin = gst_bin_new ("bin");
|
||||
g_assert (bin != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
|
||||
/* and an audio sink */
|
||||
osssink = gst_element_factory_make ("osssink", "play_audio");
|
||||
g_assert (osssink != NULL);
|
||||
|
||||
parse = gst_element_factory_make ("mp3parse", "parse");
|
||||
decode = gst_element_factory_make ("mpg123", "decode");
|
||||
|
||||
/* add objects to the main bin */
|
||||
gst_bin_add (GST_BIN (bin), filesrc);
|
||||
gst_bin_add (GST_BIN (bin), queue);
|
||||
|
||||
gst_bin_add (GST_BIN (thread), parse);
|
||||
gst_bin_add (GST_BIN (thread), decode);
|
||||
gst_bin_add (GST_BIN (thread), osssink);
|
||||
|
||||
gst_element_link_many (filesrc, queue, parse, decode, osssink, NULL);
|
||||
|
||||
/* make it ready */
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
|
||||
|
||||
playing = TRUE;
|
||||
|
||||
while (playing) {
|
||||
gst_bin_iterate (GST_BIN (bin));
|
||||
}
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
4
examples/queue4/.gitignore
vendored
4
examples/queue4/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
queue4
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
|
@ -1,5 +0,0 @@
|
|||
noinst_PROGRAMS = queue4
|
||||
|
||||
queue4_LDADD = $(GST_OBJ_LIBS)
|
||||
queue4_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
gboolean playing;
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement * element, gpointer data)
|
||||
{
|
||||
g_print ("have eos, quitting\n");
|
||||
|
||||
playing = FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *osssink, *queue, *queue2, *parse, *decode;
|
||||
GstElement *bin;
|
||||
GstElement *thread, *thread2;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* create a new thread to hold the elements */
|
||||
thread = gst_thread_new ("thread");
|
||||
g_assert (thread != NULL);
|
||||
thread2 = gst_thread_new ("thread2");
|
||||
g_assert (thread2 != NULL);
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
bin = gst_bin_new ("bin");
|
||||
g_assert (bin != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||
g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
|
||||
|
||||
queue = gst_element_factory_make ("queue", "queue");
|
||||
queue2 = gst_element_factory_make ("queue", "queue2");
|
||||
|
||||
/* and an audio sink */
|
||||
osssink = gst_element_factory_make ("osssink", "play_audio");
|
||||
g_assert (osssink != NULL);
|
||||
|
||||
parse = gst_element_factory_make ("mp3parse", "parse");
|
||||
decode = gst_element_factory_make ("mpg123", "decode");
|
||||
|
||||
/* add objects to the main bin */
|
||||
gst_bin_add (GST_BIN (bin), filesrc);
|
||||
gst_bin_add (GST_BIN (bin), queue);
|
||||
|
||||
gst_bin_add (GST_BIN (thread), parse);
|
||||
gst_bin_add (GST_BIN (thread), decode);
|
||||
gst_bin_add (GST_BIN (thread), queue2);
|
||||
|
||||
gst_bin_add (GST_BIN (thread2), osssink);
|
||||
|
||||
gst_element_link_many (filesrc, queue, parse, decode, queue2, osssink, NULL);
|
||||
|
||||
gst_bin_add (GST_BIN (bin), thread);
|
||||
gst_bin_add (GST_BIN (bin), thread2);
|
||||
|
||||
/* make it ready */
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
|
||||
|
||||
playing = TRUE;
|
||||
|
||||
while (playing) {
|
||||
gst_bin_iterate (GST_BIN (bin));
|
||||
}
|
||||
|
||||
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue