CVS Root: /cvs/gstreamer Module: gst-plugins-base Changes by: ensonic Date: Sun May 28 2006 19:42:39 UTC Log message: * gst/adder/gstadder.c: (gst_adder_get_type): Make it easier to copy&paste * gst/volume/Makefile.am: * gst/volume/gstvolume.c: (volume_update_real_volume), (gst_volume_set_volume), (gst_volume_set_mute), (gst_volume_class_init), (volume_process_int16), (volume_set_caps), (volume_transform_ip), (volume_update_mute), (volume_update_volume): * gst/volume/gstvolume.h: Add own debug category, move duplicate code to helper function, fix property texts, add more comments and prepare ffor liboil-goodness * tests/check/Makefile.am: * tests/check/elements/volume.c: (GST_START_TEST), (volume_suite): add test for mute and passtrough case, be a bit more verbose to track failure * tests/check/generic/states.c: (GST_START_TEST): catch elements that fail to instantiate Modified files: . : ChangeLog gst/adder : gstadder.c gst/volume : Makefile.am gstvolume.c gstvolume.h tests/check : Makefile.am tests/check/elements: volume.c tests/check/generic: states.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/ChangeLog.diff?r1=1.2670&r2=1.2671 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/gst/adder/gstadder.c.diff?r1=1.80&r2=1.81 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/gst/volume/Makefile.am.diff?r1=1.20&r2=1.21 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/gst/volume/gstvolume.c.diff?r1=1.79&r2=1.80 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/gst/volume/gstvolume.h.diff?r1=1.15&r2=1.16 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/tests/check/Makefile.am.diff?r1=1.36&r2=1.37 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/tests/check/elements/volume.c.diff?r1=1.10&r2=1.11 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/tests/check/generic/states.c.diff?r1=1.7&r2=1.8 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-plugins-base/ChangeLog,v retrieving revision 1.2670 retrieving revision 1.2671 diff -u -d -r1.2670 -r1.2671 --- ChangeLog 28 May 2006 09:37:17 -0000 1.2670 +++ ChangeLog 28 May 2006 19:42:27 -0000 1.2671 @@ -1,3 +1,26 @@ +2006-05-28 Stefan Kost <en...@us...> + + * gst/adder/gstadder.c: (gst_adder_get_type): + Make it easier to copy&paste + + * gst/volume/Makefile.am: + * gst/volume/gstvolume.c: (volume_update_real_volume), + (gst_volume_set_volume), (gst_volume_set_mute), + (gst_volume_class_init), (volume_process_int16), (volume_set_caps), + (volume_transform_ip), (volume_update_mute), + (volume_update_volume): + * gst/volume/gstvolume.h: + Add own debug category, move duplicate code to helper function, fix + property texts, add more comments and prepare ffor liboil-goodness + * tests/check/Makefile.am: + * tests/check/elements/volume.c: (GST_START_TEST), (volume_suite): + add test for mute and passtrough case, be a bit more verbose to track + failure + * tests/check/generic/states.c: (GST_START_TEST): + catch elements that fail to instantiate 2006-05-28 Edward Hervey <ed...@fl...> * tests/check/pipelines/simple-launch-lines.c: Index: gstadder.c RCS file: /cvs/gstreamer/gst-plugins-base/gst/adder/gstadder.c,v retrieving revision 1.80 retrieving revision 1.81 diff -u -d -r1.80 -r1.81 --- gstadder.c 10 May 2006 11:54:36 -0000 1.80 +++ gstadder.c 28 May 2006 19:42:27 -0000 1.81 @@ -65,8 +65,8 @@ #define MIN_UINT_16 ((guint16)(0x0000)) #define MIN_UINT_8 ((guint8) (0x00)) -GST_DEBUG_CATEGORY_STATIC (gst_adder_debug); #define GST_CAT_DEFAULT gst_adder_debug +GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); /* elementfactory information */ static const GstElementDetails adder_details = GST_ELEMENT_DETAILS ("Adder", @@ -124,7 +124,7 @@ adder_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAdder", &adder_info, 0); - GST_DEBUG_CATEGORY_INIT (gst_adder_debug, "adder", 0, + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "adder", 0, "audio channel mixing element"); } return adder_type; Index: Makefile.am RCS file: /cvs/gstreamer/gst-plugins-base/gst/volume/Makefile.am,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Makefile.am 30 Dec 2005 14:54:05 -0000 1.20 +++ Makefile.am 28 May 2006 19:42:27 -0000 1.21 @@ -1,7 +1,7 @@ plugin_LTLIBRARIES = libgstvolume.la libgstvolume_la_SOURCES = gstvolume.c -libgstvolume_la_CFLAGS = $(GST_CFLAGS) $(GST_CONTROLLER_CFLAGS) +libgstvolume_la_CFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GST_CONTROLLER_CFLAGS) libgstvolume_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstvolume_la_LIBADD = \ $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \ Index: gstvolume.c RCS file: /cvs/gstreamer/gst-plugins-base/gst/volume/gstvolume.c,v retrieving revision 1.79 diff -u -d -r1.79 -r1.80 --- gstvolume.c 3 May 2006 08:58:13 -0000 1.79 +++ gstvolume.c 28 May 2006 19:42:27 -0000 1.80 @@ -66,6 +66,9 @@ /* number of steps we use for the mixer interface to go from 0.0 to 1.0 */ # define VOLUME_STEPS 100 +#define GST_CAT_DEFAULT gst_volume_debug static const GstElementDetails volume_details = GST_ELEMENT_DETAILS ("Volume", "Filter/Effect/Audio", "Set volume on audio/raw streams", @@ -159,6 +162,22 @@ static void volume_process_int16 (GstVolume * this, GstClockTime tstamp, gpointer bytes, gint n_bytes); +/* helper functions */ +static void +volume_update_real_volume (GstVolume * this) +{ + if (this->mute) { + this->real_vol_f = 0.0; + this->real_vol_i = 0; + } else { + this->real_vol_f = this->volume_f; + this->real_vol_i = this->volume_i; + } +} +/* Mixer interface */ static gboolean gst_volume_interface_supported (GstImplementsInterface * iface, GType type) { @@ -194,13 +213,7 @@ this->volume_f = (gfloat) volumes[0] / VOLUME_STEPS; this->volume_i = this->volume_f * VOLUME_UNITY_INT; - if (this->mute) { - this->real_vol_f = 0.0; - this->real_vol_i = 0; - } else { - this->real_vol_f = this->volume_f; - this->real_vol_i = this->volume_i; - } + volume_update_real_volume (this); } static void @@ -224,13 +237,7 @@ this->mute = mute; @@ -245,6 +252,8 @@ klass->set_mute = gst_volume_set_mute; +/* Element class */ gst_volume_dispose (GObject * object) @@ -290,10 +299,12 @@ FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_VOLUME, - g_param_spec_double ("volume", "volume", "volume", + g_param_spec_double ("volume", "Volume", "volume factor", 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "volume", 0, "Volume gain"); trans_class->transform_ip = GST_DEBUG_FUNCPTR (volume_transform_ip); trans_class->set_caps = GST_DEBUG_FUNCPTR (volume_set_caps); @@ -322,21 +333,10 @@ -/* based on the caps' structure, install the correct volume_process method */ -static void -volume_funcfind (GstVolume * this, const GstStructure * structure) -{ - const gchar *mimetype; - - mimetype = gst_structure_get_name (structure); - if (strcmp (mimetype, "audio/x-raw-int") == 0) - this->process = volume_process_int16; - else if (strcmp (mimetype, "audio/x-raw-float") == 0) - this->process = volume_process_float; - else - this->process = NULL; -} +/* NOTE: although it might be tempting to have volume_process_mute() which uses + * memset(bytes, 0, nbytes) for the vol=0 case, this has the downside that + * unmuting would unly take place after processing a buffer. + */ volume_process_float (GstVolume * this, GstClockTime tstamp, @@ -351,6 +351,9 @@ for (i = 0; i < num_samples; i++) { *data++ *= this->real_vol_f; + /* FIXME: need... liboil... + oil_scalarmultiply_f32_ns (data, data, &this->real_vol_f, num_samples); + */ @@ -363,16 +366,20 @@ data = (gint16 *) bytes; num_samples = n_bytes / sizeof (gint16); - /* FIXME: need... liboil... */ - /* only clamp if the gain is greater than 1.0 */ + /* FIXME: need... liboil... + * oil_scalarmultiply_s16_ns ? + /* only clamp if the gain is greater than 1.0 + * FIXME: real_vol_i can change while processing the buffer! 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 ((this->real_vol_i * - val) >> VOLUME_UNITY_BIT_SHIFT, VOLUME_MIN_INT16, - VOLUME_MAX_INT16); + (gint16) CLAMP ((this->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT, + VOLUME_MIN_INT16, VOLUME_MAX_INT16); } } else { @@ -390,14 +397,22 @@ volume_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps) GstVolume *this = GST_VOLUME (base); + const gchar *mimetype; GST_DEBUG_OBJECT (this, "set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps); - volume_funcfind (this, gst_caps_get_structure (incaps, 0)); + mimetype = gst_structure_get_name (gst_caps_get_structure (incaps, 0)); - if (!this->process) + /* based on mimetype, install the correct volume_process method */ + if (strcmp (mimetype, "audio/x-raw-int") == 0) + this->process = volume_process_int16; + else if (strcmp (mimetype, "audio/x-raw-float") == 0) + this->process = volume_process_float; + else { + this->process = NULL; goto invalid_format; return TRUE; @@ -420,6 +435,10 @@ GstClockTime timestamp; + /* don't process data in passthrough-mode (requires #343196) + if (!gst_buffer_is_writable (outbuf)) return GST_FLOW_OK; timestamp = GST_BUFFER_TIMESTAMP (outbuf); if (GST_CLOCK_TIME_IS_VALID (timestamp)) @@ -444,13 +463,7 @@ this->mute = (g_value_get_int (value) == 1); @@ -462,13 +475,8 @@ this->volume_f = g_value_get_double (value); Index: gstvolume.h RCS file: /cvs/gstreamer/gst-plugins-base/gst/volume/gstvolume.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gstvolume.h 1 Mar 2006 17:39:28 -0000 1.15 +++ gstvolume.h 28 May 2006 19:42:27 -0000 1.16 @@ -36,17 +36,12 @@ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VOLUME,GstVolume)) #define GST_IS_VOLUME(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VOLUME)) -#define GST_IS_VOLUME_CLASS(obj) \ +#define GST_IS_VOLUME_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VOLUME)) typedef struct _GstVolume GstVolume; typedef struct _GstVolumeClass GstVolumeClass; -typedef enum { - GST_VOLUME_FORMAT_INT=1, - GST_VOLUME_FORMAT_FLOAT -} GstVolumeFormat; /** * GstVolume: * @@ -60,7 +55,7 @@ gboolean mute; gint volume_i, real_vol_i; /* the _i(nt) values get synchronized with the */ gfloat volume_f, real_vol_f; /* _f(loat) values on each update */ + GList *tracklist; }; RCS file: /cvs/gstreamer/gst-plugins-base/tests/check/Makefile.am,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- Makefile.am 27 May 2006 13:34:03 -0000 1.36 +++ Makefile.am 28 May 2006 19:42:27 -0000 1.37 @@ -102,6 +102,14 @@ -I$(top_srcdir)/gst-libs \ $(CFLAGS) $(AM_CFLAGS) +elements_volume_LDADD = \ + $(GST_BASE_LIBS) \ + $(LDADD) +elements_volume_CFLAGS = \ + $(GST_BASE_CFLAGS) \ + $(CFLAGS) $(AM_CFLAGS) libs_video_LDADD = \ $(top_builddir)/gst-libs/gst/video/libgstvideo-@GST_MAJORMINOR@.la \ $(LDADD) Index: volume.c RCS file: /cvs/gstreamer/gst-plugins-base/tests/check/elements/volume.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- volume.c 6 Dec 2005 19:42:02 -0000 1.10 +++ volume.c 28 May 2006 19:42:27 -0000 1.11 @@ -22,6 +22,7 @@ #include <unistd.h> +#include <gst/base/gstbasetransform.h> #include <gst/check/gstcheck.h> GList *buffers = NULL; @@ -107,6 +108,7 @@ GstBuffer *inbuffer, *outbuffer; GstCaps *caps; gint16 in[2] = { 16384, -256 }; + gint16 *res; volume = setup_volume (); fail_unless (gst_element_set_state (volume, @@ -127,6 +129,9 @@ fail_unless_equals_int (g_list_length (buffers), 1); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_unless (inbuffer == outbuffer); + res = (gint16 *) GST_BUFFER_DATA (outbuffer); + GST_INFO ("expected %+5ld %+5ld real %+5ld %+5ld", in[0], in[1], res[0], + res[1]); fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); /* cleanup */ @@ -143,6 +148,7 @@ gint16 out[2] = { 8192, -128 }; g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); @@ -170,6 +176,9 @@ + GST_INFO ("expected %+5ld %+5ld real %+5ld %+5ld", out[0], out[1], res[0], fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); @@ -186,6 +195,7 @@ gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */ g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); @@ -213,6 +223,9 @@ @@ -221,6 +234,55 @@ GST_END_TEST; +GST_START_TEST (test_mute) + GstElement *volume; + GstBuffer *inbuffer; + GstBuffer *outbuffer; + GstCaps *caps; + gint16 in[2] = { 16384, -256 }; + gint16 out[2] = { 0, 0 }; + volume = setup_volume (); + g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); + fail_unless (gst_element_set_state (volume, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + inbuffer = gst_buffer_new_and_alloc (4); + memcpy (GST_BUFFER_DATA (inbuffer), in, 4); + fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); + caps = gst_caps_from_string (VOLUME_CAPS_STRING); + gst_buffer_set_caps (inbuffer, caps); + gst_caps_unref (caps); + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + /* FIXME: reffing the inbuffer should make the transformation not be + * inplace + gst_buffer_ref (inbuffer); + /* pushing gives away my reference ... */ + fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); + /* ... but it ends up being modified inplace and + * collected on the global buffer list */ + fail_unless_equals_int (g_list_length (buffers), 1); + fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); + fail_unless (inbuffer == outbuffer); + fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); + /* cleanup */ + cleanup_volume (volume); +GST_END_TEST; GST_START_TEST (test_wrong_caps) GstElement *volume; @@ -269,6 +331,47 @@ +GST_START_TEST (test_passthrough) + GstBuffer *inbuffer, *outbuffer; + g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); + gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (volume), TRUE); + /* ... but it ends up being collected on the global buffer list */ Suite * volume_suite (void) @@ -279,7 +382,9 @@ tcase_add_test (tc_chain, test_unity); tcase_add_test (tc_chain, test_half); tcase_add_test (tc_chain, test_double); + tcase_add_test (tc_chain, test_mute); tcase_add_test (tc_chain, test_wrong_caps); + tcase_add_test (tc_chain, test_passthrough); return s; Index: states.c RCS file: /cvs/gstreamer/gst-plugins-base/tests/check/generic/states.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- states.c 29 Dec 2005 11:49:11 -0000 1.7 +++ states.c 28 May 2006 19:42:27 -0000 1.8 @@ -62,6 +62,11 @@ GST_DEBUG ("testing element %s", name); element = gst_element_factory_make (name, name); + if (!element) { + GST_WARNING ("failed to create element %s", name); + continue; + } if (GST_IS_PIPELINE (element)) { GST_DEBUG ("element %s is a pipeline", name); } |