From: <tho...@fr...> - 2005-08-20 18:07:23
|
CVS Root: /cvs/gstreamer Module: gst-plugins-base Changes by: thomasvs Date: Sat Aug 20 2005 11:07:22 PDT Log message: add tests to gst-plugins-base add a volume element test clean up volume a little more for basetransform Modified files: . : Makefile.am configure.ac gst/volume : gstvolume.c Added files: check : .cvsignore Makefile.am check/elements : .cvsignore volume.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/Makefile.am.diff?r1=1.61&r2=1.62 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/configure.ac.diff?r1=1.561&r2=1.562 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/check/.cvsignore?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/check/Makefile.am?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/check/elements/.cvsignore?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/check/elements/volume.c?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/gst/volume/gstvolume.c.diff?r1=1.54&r2=1.55 ====Begin Diffs==== Index: Makefile.am =================================================================== RCS file: /cvs/gstreamer/gst-plugins-base/Makefile.am,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- Makefile.am 7 Jul 2005 16:44:32 -0000 1.61 +++ Makefile.am 20 Aug 2005 18:07:09 -0000 1.62 @@ -28,6 +28,7 @@ $(SUBDIRS_EXAMPLES) \ tools \ $(SUBDIRS_GCONF) \ + check \ docs \ po \ common \ @@ -35,6 +36,7 @@ pkgconfig DIST_SUBDIRS = \ gst-libs \ gst sys ext \ Index: configure.ac RCS file: /cvs/gstreamer/gst-plugins-base/configure.ac,v retrieving revision 1.561 retrieving revision 1.562 diff -u -d -r1.561 -r1.562 --- configure.ac 5 Aug 2005 17:12:57 -0000 1.561 +++ configure.ac 20 Aug 2005 18:07:09 -0000 1.562 @@ -238,6 +238,12 @@ AC_SUBST(GST_BASE_LIBS) +PKG_CHECK_MODULES(GST_CHECK, gstreamer-check-$GST_MAJORMINOR >= $GST_REQ, + HAVE_GST_CHECK="yes", HAVE_GST_CHECK="no") + +AC_PATH_PROG(VALGRIND_PATH, valgrind, no) +AM_CONDITIONAL(HAVE_VALGRIND, test ! "x$VALGRIND_PATH" = "xno") dnl Determine endianness AC_C_BIGENDIAN @@ -927,6 +933,7 @@ pkgconfig/Makefile pkgconfig/gstreamer-plugins-base.pc pkgconfig/gstreamer-plugins-base-uninstalled.pc +check/Makefile docs/Makefile docs/libs/Makefile docs/plugins/Makefile --- NEW FILE: .cvsignore --- test-registry.xml --- NEW FILE: Makefile.am --- include $(top_srcdir)/common/check.mak CHECK_REGISTRY=$(top_builddir)/check/test-registry.xml TESTS_ENVIRONMENT=\ GST_REGISTRY=$(CHECK_REGISTRY) # ths core dumps of some machines have PIDs appended CLEANFILES = core.* test-registry.xml clean-local: clean-local-check $(CHECK_REGISTRY): $(TESTS_ENVIRONMENT) \ GST_PLUGIN_PATH_ONLY=yes \ GST_PLUGIN_PATH=$(top_builddir)/gst \ $(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@ TESTS = $(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@ \ $(check_PROGRAMS) check_PROGRAMS = elements/volume AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) # valgrind testing VALGRIND_TESTS_DISABLE = \ SUPPRESSIONS = $(top_srcdir)/common/gst.supp .dirstamp volume --- NEW FILE: volume.c --- /* GStreamer * * unit test for volume * 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; #define VOLUME_CAPS_TEMPLATE_STRING \ "audio/x-raw-int, " \ "channels = (int) [ 1, MAX ], " \ "rate = (int) [ 1, MAX ], " \ "endianness = (int) BYTE_ORDER, " \ "width = (int) 16, " \ "depth = (int) 16, " \ "signed = (bool) TRUE" #define VOLUME_CAPS_STRING \ "channels = (int) 1, " \ "rate = (int) 44100, " \ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING) ); static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GstFlowReturn chain_func (GstPad * pad, GstBuffer * buffer) { GST_DEBUG ("chain_func: received buffer %p", buffer); buffers = g_list_append (buffers, buffer); return GST_FLOW_OK; } gboolean event_func (GstPad * pad, GstEvent * event) if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { /* we take the lock here because it's good practice to so, even though * no buffers will be pushed anymore anyway */ GST_STREAM_LOCK (pad); have_eos = TRUE; GST_STREAM_UNLOCK (pad); gst_event_unref (event); return TRUE; } gst_event_unref (event); return FALSE; GstElement * setup_volume () GstElement *volume; GstPad *srcpad, *sinkpad; GST_DEBUG ("setup_volume"); volume = gst_element_factory_make ("volume", "volume"); fail_if (volume == NULL, "Could not create a volume"); /* sending pad */ mysrcpad = gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate), "src"); fail_if (mysrcpad == NULL, "Could not create a mysrcpad"); ASSERT_OBJECT_REFCOUNT (mysrcpad, "mysrcpad", 1); sinkpad = gst_element_get_pad (volume, "sink"); fail_if (sinkpad == NULL, "Could not get source pad from volume"); ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); gst_pad_set_caps (mysrcpad, NULL); fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK, "Could not link source and volume sink pads"); gst_object_unref (sinkpad); /* because we got it higher up */ ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1); /* receiving pad */ mysinkpad = gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate), "sink"); fail_if (mysinkpad == NULL, "Could not create a mysinkpad"); srcpad = gst_element_get_pad (volume, "src"); fail_if (srcpad == NULL, "Could not get source pad from volume"); gst_pad_set_caps (mysinkpad, NULL); gst_pad_set_chain_function (mysinkpad, chain_func); gst_pad_set_event_function (mysinkpad, event_func); fail_unless (gst_pad_link (srcpad, mysinkpad) == GST_PAD_LINK_OK, "Could not link volume source and mysink pads"); gst_object_unref (srcpad); /* because we got it higher up */ ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); return volume; void cleanup_volume (GstElement * volume) GST_DEBUG ("cleanup_volume"); fail_unless (gst_element_set_state (volume, GST_STATE_NULL) == GST_STATE_SUCCESS, "could not set to null"); ASSERT_OBJECT_REFCOUNT (volume, "volume", 1); /* clean up floating src pad */ gst_pad_unlink (mysrcpad, sinkpad); /* pad refs held by both creator and this function (through _get) */ ASSERT_OBJECT_REFCOUNT (mysrcpad, "srcpad", 1); gst_object_unref (mysrcpad); mysrcpad = NULL; gst_object_unref (sinkpad); /* one more ref is held by volume itself */ /* clean up floating sink pad */ gst_pad_unlink (srcpad, mysinkpad); ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 2); gst_object_unref (srcpad); ASSERT_OBJECT_REFCOUNT (mysinkpad, "mysinkpad", 1); gst_object_unref (mysinkpad); mysinkpad = NULL; gst_object_unref (volume); GST_START_TEST (test_unity) GstBuffer *inbuffer, *outbuffer; gint16 in[2] = { 16384, -256 }; volume = setup_volume (); fail_unless (gst_element_set_state (volume, GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing"); inbuffer = gst_buffer_new_and_alloc (4); memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_set_caps (inbuffer, gst_caps_from_string (VOLUME_CAPS_STRING)); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); /* pushing gives away my reference ... */ gst_pad_push (mysrcpad, inbuffer); /* ... but it ends up being collected on the global buffer list */ fail_unless (g_list_length (buffers) == 1); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_unless (inbuffer == outbuffer); fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); /* cleanup */ cleanup_volume (volume); GST_END_TEST; GST_START_TEST (test_half) GstBuffer *inbuffer; GstBuffer *outbuffer; gint16 out[2] = { 8192, -128 }; g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); /* FIXME: reffing the inbuffer should make the transformation not be * inplace gst_buffer_ref (inbuffer); */ /* ... but it ends up being modified inplace and * collected on the global buffer list */ fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); GST_START_TEST (test_double) gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */ g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); Suite * volume_suite (void) Suite *s = suite_create ("volume"); TCase *tc_chain = tcase_create ("general"); suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_unity); tcase_add_test (tc_chain, test_half); tcase_add_test (tc_chain, test_double); return s; int main (int argc, char **argv) int nf; Suite *s = volume_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; Index: gstvolume.c RCS file: /cvs/gstreamer/gst-plugins-base/gst/volume/gstvolume.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- gstvolume.c 17 Aug 2005 21:07:21 -0000 1.54 +++ gstvolume.c 20 Aug 2005 18:07:10 -0000 1.55 @@ -1,6 +1,7 @@ /* -*- c-basic-offset: 2 -*- * GStreamer * Copyright (C) 1999-2001 Erik Walthinsen <om...@cs...> + * Copyright (C) 2005 Andy Wingo <wi...@po...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -101,28 +102,27 @@ static void gst_volume_interface_init (GstImplementsInterfaceClass * klass); static void gst_volume_mixer_init (GstMixerClass * iface); -#define _init_interfaces(type) \ - { \ - static const GInterfaceInfo voliface_info = { \ - (GInterfaceInitFunc) gst_volume_interface_init, \ - NULL, \ - NULL \ - }; \ - static const GInterfaceInfo volmixer_info = { \ - (GInterfaceInitFunc) gst_volume_mixer_init, \ - \ - g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, \ - &voliface_info); \ - g_type_add_interface_static (type, GST_TYPE_MIXER, &volmixer_info); \ +#define _init_interfaces(type) \ + { \ + static const GInterfaceInfo voliface_info = { \ + (GInterfaceInitFunc) gst_volume_interface_init, \ + NULL, \ + NULL \ + }; \ + static const GInterfaceInfo volmixer_info = { \ + (GInterfaceInitFunc) gst_volume_mixer_init, \ + \ + g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, \ + &voliface_info); \ + g_type_add_interface_static (type, GST_TYPE_MIXER, &volmixer_info); \ } GST_BOILERPLATE_FULL (GstVolume, gst_volume, GstBaseTransform, GST_TYPE_BASE_TRANSFORM, _init_interfaces); - static void volume_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void volume_get_property (GObject * object, guint prop_id, @@ -132,9 +132,13 @@ static GstFlowReturn volume_transform (GstBaseTransform * base, GstBuffer * inbuf, GstBuffer * outbuf); -static void volume_process_float (GstVolume * filter, GstClockTime tstamp, +gboolean volume_set_caps (GstBaseTransform * base, GstCaps * incaps, + GstCaps * outcaps); +static void volume_process_float (GstVolume * this, GstClockTime tstamp, gpointer bytes, gint n_bytes); -static void volume_process_int16 (GstVolume * filter, GstClockTime tstamp, +static void volume_process_int16 (GstVolume * this, GstClockTime tstamp, static gboolean @@ -153,61 +157,61 @@ static const GList * gst_volume_list_tracks (GstMixer * mixer) { - GstVolume *filter = GST_VOLUME (mixer); + GstVolume *this = GST_VOLUME (mixer); - g_return_val_if_fail (filter != NULL, NULL); - g_return_val_if_fail (GST_IS_VOLUME (filter), NULL); + g_return_val_if_fail (this != NULL, NULL); + g_return_val_if_fail (GST_IS_VOLUME (this), NULL); - return filter->tracklist; + return this->tracklist; } static void gst_volume_set_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes) - g_return_if_fail (filter != NULL); - g_return_if_fail (GST_IS_VOLUME (filter)); + g_return_if_fail (this != NULL); + g_return_if_fail (GST_IS_VOLUME (this)); - filter->volume_f = (gfloat) volumes[0] / VOLUME_STEPS; - filter->volume_i = filter->volume_f * VOLUME_UNITY_INT; + this->volume_f = (gfloat) volumes[0] / VOLUME_STEPS; + this->volume_i = this->volume_f * VOLUME_UNITY_INT; - if (filter->mute) { - filter->real_vol_f = 0.0; - filter->real_vol_i = 0; + if (this->mute) { + this->real_vol_f = 0.0; + this->real_vol_i = 0; } else { - filter->real_vol_f = filter->volume_f; - filter->real_vol_i = filter->volume_i; + this->real_vol_f = this->volume_f; + this->real_vol_i = this->volume_i; gst_volume_get_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes) - volumes[0] = (gint) filter->volume_f * VOLUME_STEPS; + volumes[0] = (gint) this->volume_f * VOLUME_STEPS; gst_volume_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute) - filter->mute = mute; + this->mute = mute; @@ -269,19 +273,21 @@ GST_BASE_TRANSFORM_CLASS (klass)->transform = GST_DEBUG_FUNCPTR (volume_transform); + GST_BASE_TRANSFORM_CLASS (klass)->set_caps = + GST_DEBUG_FUNCPTR (volume_set_caps); -gst_volume_init (GstVolume * filter) +gst_volume_init (GstVolume * this) GstMixerTrack *track = NULL; - filter->mute = FALSE; - filter->volume_i = VOLUME_UNITY_INT; - filter->volume_f = 1.0; - filter->real_vol_i = VOLUME_UNITY_INT; - filter->real_vol_f = 1.0; - filter->tracklist = NULL; + this->mute = FALSE; + this->volume_i = VOLUME_UNITY_INT; + this->volume_f = 1.0; + this->real_vol_i = VOLUME_UNITY_INT; + this->real_vol_f = 1.0; + this->tracklist = NULL; track = g_object_new (GST_TYPE_MIXER_TRACK, NULL); @@ -291,50 +297,26 @@ track->min_volume = 0; track->max_volume = VOLUME_STEPS; track->flags = GST_MIXER_TRACK_SOFTWARE; - filter->tracklist = g_list_append (filter->tracklist, track); + this->tracklist = g_list_append (this->tracklist, track); +/* based on the caps' structure, install the correct volume_process method */ -volume_typefind (GstVolume * filter, const GstStructure * structure) +volume_funcfind (GstVolume * this, const GstStructure * structure) const gchar *mimetype; mimetype = gst_structure_get_name (structure); if (strcmp (mimetype, "audio/x-raw-int") == 0) - filter->process = volume_process_int16; + this->process = volume_process_int16; else if (strcmp (mimetype, "audio/x-raw-float") == 0) - filter->process = volume_process_float; -} -static GstFlowReturn -volume_transform (GstBaseTransform * base, GstBuffer * inbuf, - GstBuffer * outbuf) -{ - GstVolume *filter = GST_VOLUME (base); - if (G_UNLIKELY (!filter->process)) { - GstCaps *caps = GST_BUFFER_CAPS (inbuf); - if (gst_caps_get_size (caps) == 1) - volume_typefind (filter, gst_caps_get_structure (caps, 0)); - if (!filter->process) { - GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION, - ("Invalid caps on first buffer"), NULL); - return GST_FLOW_UNEXPECTED; - } - } - filter->process (filter, GST_BUFFER_TIMESTAMP (outbuf), - GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); - return GST_FLOW_OK; + this->process = volume_process_float; -volume_process_float (GstVolume * filter, GstClockTime tstamp, +volume_process_float (GstVolume * this, GstClockTime tstamp, gpointer bytes, gint n_bytes) gfloat *data; @@ -344,12 +326,12 @@ num_samples = n_bytes / sizeof (gfloat); for (i = 0; i < num_samples; i++) { - *data++ *= filter->real_vol_f; + *data++ *= this->real_vol_f; -volume_process_int16 (GstVolume * filter, GstClockTime tstamp, +volume_process_int16 (GstVolume * this, GstClockTime tstamp, gint16 *data; @@ -358,14 +340,14 @@ data = (gint16 *) bytes; num_samples = n_bytes / sizeof (gint16); - /* need... liboil... */ + /* FIXME: need... liboil... */ /* only clamp if the gain is greater than 1.0 */ - if (filter->real_vol_i > VOLUME_UNITY_INT) { + if (this->real_vol_i > VOLUME_UNITY_INT) { for (i = 0; i < num_samples; i++) { /* we use bitshifting instead of dividing by UNITY_INT for speed */ val = (gint) * data; *data++ = - (gint16) CLAMP ((filter->real_vol_i * + (gint16) CLAMP ((this->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT, VOLUME_MIN_INT16, VOLUME_MAX_INT16); } @@ -373,48 +355,82 @@ - *data++ = (gint16) ((filter->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT); + *data++ = (gint16) ((this->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT); +/* GstBaseTransform vmethod implementations */ +/* get notified of caps and plug in the correct process function */ +gboolean +volume_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps) +{ + GstVolume *this = GST_VOLUME (base); + volume_funcfind (this, gst_caps_get_structure (incaps, 0)); + if (!this->process) { + GST_ELEMENT_ERROR (this, CORE, NEGOTIATION, + ("Invalid incoming caps: %" GST_PTR_FORMAT, incaps), NULL); + return FALSE; + } + return TRUE; +} +/* call the plugged-in process function for this instance + * needs to be done with this indirection since volume_transform is + * a class-global method + */ +static GstFlowReturn +volume_transform (GstBaseTransform * base, GstBuffer * inbuf, + GstBuffer * outbuf) + this->process (this, GST_BUFFER_TIMESTAMP (outbuf), + GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); + return GST_FLOW_OK; volume_update_mute (const GValue * value, gpointer data) - GstVolume *filter = (GstVolume *) data; + GstVolume *this = (GstVolume *) data; if (G_VALUE_HOLDS_BOOLEAN (value)) { - filter->mute = g_value_get_boolean (value); + this->mute = g_value_get_boolean (value); } else if (G_VALUE_HOLDS_INT (value)) { - filter->mute = (g_value_get_int (value) == 1); + this->mute = (g_value_get_int (value) == 1); volume_update_volume (const GValue * value, gpointer data) - filter->volume_f = g_value_get_double (value); + this->volume_f = g_value_get_double (value); @@ -422,14 +438,14 @@ volume_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) - GstVolume *filter = GST_VOLUME (object); + GstVolume *this = GST_VOLUME (object); switch (prop_id) { case PROP_MUTE: - volume_update_mute (value, filter); + volume_update_mute (value, this); break; case PROP_VOLUME: - volume_update_volume (value, filter); + volume_update_volume (value, this); default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -441,14 +457,14 @@ volume_get_property (GObject * object, guint prop_id, GValue * value, - g_value_set_boolean (value, filter->mute); + g_value_set_boolean (value, this->mute); - g_value_set_double (value, filter->volume_f); + g_value_set_double (value, this->volume_f); @@ -467,4 +483,4 @@ GST_VERSION_MINOR, "volume", "element for controlling audio volume", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN); |