+2006-05-28 Stefan Kost <ensonic@users.sf.net>
+
+ * 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 <edward@fluendo.com>
* tests/check/pipelines/simple-launch-lines.c:
-Subproject commit 764c5f25101d20da7f26942c36ba840ba65c63d7
+Subproject commit 2f06c5cbc778e158d2429b09efc6740ff5281295
#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",
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;
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 \
/* 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
+GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
+
static const GstElementDetails volume_details = GST_ELEMENT_DETAILS ("Volume",
"Filter/Effect/Audio",
"Set volume on audio/raw streams",
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)
{
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
this->mute = mute;
- 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
klass->set_mute = gst_volume_set_mute;
}
+/* Element class */
+
static void
gst_volume_dispose (GObject * object)
{
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);
}
}
}
-/* 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.
+ */
static void
volume_process_float (GstVolume * this, GstClockTime tstamp,
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);
+ */
}
static void
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 {
for (i = 0; i < num_samples; i++) {
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;
GstVolume *this = GST_VOLUME (base);
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))
this->mute = (g_value_get_int (value) == 1);
}
- 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
this->volume_f = g_value_get_double (value);
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
(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:
*
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;
};
-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)
#include <unistd.h>
+#include <gst/base/gstbasetransform.h>
#include <gst/check/gstcheck.h>
GList *buffers = NULL;
GstBuffer *inbuffer, *outbuffer;
GstCaps *caps;
gint16 in[2] = { 16384, -256 };
+ gint16 *res;
volume = setup_volume ();
fail_unless (gst_element_set_state (volume,
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 */
GstCaps *caps;
gint16 in[2] = { 16384, -256 };
gint16 out[2] = { 8192, -128 };
+ gint16 *res;
volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
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", out[0], out[1], res[0],
+ res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
/* cleanup */
GstCaps *caps;
gint16 in[2] = { 16384, -256 };
gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */
+ gint16 *res;
volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
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", out[0], out[1], res[0],
+ res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
/* cleanup */
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 };
+ gint16 *res;
+
+ 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 */
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+ 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", out[0], out[1], res[0],
+ res[1]);
+ 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;
GST_END_TEST;
+GST_START_TEST (test_passthrough)
+{
+ GstElement *volume;
+ GstBuffer *inbuffer, *outbuffer;
+ GstCaps *caps;
+ gint16 in[2] = { 16384, -256 };
+ gint16 *res;
+
+ volume = setup_volume ();
+ g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
+ gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (volume), TRUE);
+ 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);
+ caps = gst_caps_from_string (VOLUME_CAPS_STRING);
+ gst_buffer_set_caps (inbuffer, caps);
+ gst_caps_unref (caps);
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference ... */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
+ /* ... but it ends up being collected on the global buffer list */
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+ 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 */
+ cleanup_volume (volume);
+}
+
+GST_END_TEST;
+
+
Suite *
volume_suite (void)
{
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;
}
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);
}