diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2007-08-09 17:39:47 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2007-08-09 17:39:47 +0000 |
commit | cf74a6136d5b03386d7326757479b9ac59cca162 (patch) | |
tree | be515cc893d7cb5c9a781073652d1c5b4f97ab33 /gst | |
parent | 227f1e3965c2b536fd792af9af20a9aaa4232ed9 (diff) | |
download | gst-plugins-bad-cf74a6136d5b03386d7326757479b9ac59cca162.tar.gz gst-plugins-bad-cf74a6136d5b03386d7326757479b9ac59cca162.tar.bz2 gst-plugins-bad-cf74a6136d5b03386d7326757479b9ac59cca162.zip |
Port the stereo element to GStreamer 0.10.
Original commit message from CVS:
* configure.ac:
* gst/stereo/Makefile.am:
* gst/stereo/gststereo.c: (gst_stereo_base_init),
(gst_stereo_class_init), (gst_stereo_init),
(gst_stereo_transform_ip), (gst_stereo_set_property),
(gst_stereo_get_property):
* gst/stereo/gststereo.h:
Port the stereo element to GStreamer 0.10.
Diffstat (limited to 'gst')
-rw-r--r-- | gst/stereo/Makefile.am | 4 | ||||
-rw-r--r-- | gst/stereo/gststereo.c | 127 | ||||
-rw-r--r-- | gst/stereo/gststereo.h | 20 |
3 files changed, 63 insertions, 88 deletions
diff --git a/gst/stereo/Makefile.am b/gst/stereo/Makefile.am index fc9ceaac..970de511 100644 --- a/gst/stereo/Makefile.am +++ b/gst/stereo/Makefile.am @@ -2,8 +2,8 @@ plugin_LTLIBRARIES = libgststereo.la libgststereo_la_SOURCES = gststereo.c -libgststereo_la_CFLAGS = $(GST_CFLAGS) -libgststereo_la_LIBADD = +libgststereo_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) +libgststereo_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(GST_CONTROLLER_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) libgststereo_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) noinst_HEADERS = gststereo.h diff --git a/gst/stereo/gststereo.c b/gst/stereo/gststereo.c index d99da157..405449e2 100644 --- a/gst/stereo/gststereo.c +++ b/gst/stereo/gststereo.c @@ -27,6 +27,13 @@ #endif #include "gststereo.h" +#include <gst/gst.h> +#include <gst/base/gstbasetransform.h> +#include <gst/audio/audio.h> +#include <gst/audio/gstaudiofilter.h> +#include <gst/controller/gstcontroller.h> + + /* elementfactory information */ static const GstElementDetails stereo_details = GST_ELEMENT_DETAILS ("Stereo effect", @@ -35,6 +42,15 @@ GST_ELEMENT_DETAILS ("Stereo effect", "Erik Walthinsen <omega@cse.ogi.edu>"); +#define ALLOWED_CAPS \ + "audio/x-raw-int," \ + " depth = (int) 16, " \ + " width = (int) 16, " \ + " endianness = (int) BYTE_ORDER," \ + " rate = (int) [ 1, MAX ]," \ + " channels = (int) 2, " \ + " signed = (boolean) TRUE" + /* Stereo signals and args */ enum { @@ -49,112 +65,83 @@ enum ARG_STEREO }; - -static void gst_stereo_base_init (gpointer g_class); -static void gst_stereo_class_init (GstStereoClass * klass); -static void gst_stereo_init (GstStereo * stereo); - static void gst_stereo_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_stereo_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static void gst_stereo_chain (GstPad * pad, GstData * _data); - -static GstElementClass *parent_class = NULL; +static GstFlowReturn gst_stereo_transform_ip (GstBaseTransform * base, + GstBuffer * outbuf); /*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; */ -GType -gst_stereo_get_type (void) -{ - static GType stereo_type = 0; - - if (!stereo_type) { - static const GTypeInfo stereo_info = { - sizeof (GstStereoClass), - gst_stereo_base_init, - NULL, - (GClassInitFunc) gst_stereo_class_init, - NULL, - NULL, - sizeof (GstStereo), - 0, - (GInstanceInitFunc) gst_stereo_init, - }; - - stereo_type = - g_type_register_static (GST_TYPE_ELEMENT, "GstStereo", &stereo_info, 0); - } - return stereo_type; -} +GST_BOILERPLATE (GstStereo, gst_stereo, GstAudioFilter, GST_TYPE_AUDIO_FILTER); static void gst_stereo_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GstCaps *caps; gst_element_class_set_details (element_class, &stereo_details); + + caps = gst_caps_from_string (ALLOWED_CAPS); + gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (g_class), + caps); + gst_caps_unref (caps); } + static void gst_stereo_class_init (GstStereoClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; + GstBaseTransformClass *trans_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; + trans_class = (GstBaseTransformClass *) klass; parent_class = g_type_class_peek_parent (klass); - 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 */ - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STEREO, g_param_spec_float ("stereo", "stereo", "stereo", 0.0, 1.0, 0.0, G_PARAM_READWRITE)); /* CHECKME */ + gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_stereo_set_property); + gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_stereo_get_property); + + g_object_class_install_property (gobject_class, ARG_ACTIVE, + g_param_spec_boolean ("active", "active", "active", + TRUE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); - gobject_class->set_property = gst_stereo_set_property; - gobject_class->get_property = gst_stereo_get_property; + g_object_class_install_property (gobject_class, ARG_STEREO, + g_param_spec_float ("stereo", "stereo", "stereo", + 0.0, 1.0, 0.1, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + + trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_stereo_transform_ip); } static void -gst_stereo_init (GstStereo * stereo) +gst_stereo_init (GstStereo * stereo, GstStereoClass * klass) { - stereo->sinkpad = gst_pad_new ("sink", GST_PAD_SINK); - gst_element_add_pad (GST_ELEMENT (stereo), stereo->sinkpad); - gst_pad_set_chain_function (stereo->sinkpad, gst_stereo_chain); - stereo->srcpad = gst_pad_new ("src", GST_PAD_SRC); - gst_element_add_pad (GST_ELEMENT (stereo), stereo->srcpad); - - stereo->active = FALSE; - stereo->stereo = 2.5; + stereo->active = TRUE; + stereo->stereo = 0.1; } -static void -gst_stereo_chain (GstPad * pad, GstData * _data) +static GstFlowReturn +gst_stereo_transform_ip (GstBaseTransform * base, GstBuffer * outbuf) { - GstBuffer *buf = GST_BUFFER (_data); - GstStereo *stereo; - gint16 *data; - gint samples; + GstStereo *stereo = GST_STEREO (base); + gint16 *data = (gint16 *) GST_BUFFER_DATA (outbuf); + gint samples = GST_BUFFER_SIZE (outbuf) / 2; gint i; - gdouble avg, ldiff, rdiff, tmp, mul; - - g_return_if_fail (pad != NULL); - g_return_if_fail (GST_IS_PAD (pad)); - g_return_if_fail (buf != NULL); + gdouble avg, ldiff, rdiff, tmp; + gdouble mul = stereo->stereo; - stereo = GST_STEREO (GST_OBJECT_PARENT (pad)); - g_return_if_fail (stereo != NULL); - g_return_if_fail (GST_IS_STEREO (stereo)); + if (!gst_buffer_is_writable (outbuf)) + return GST_FLOW_OK; -/* FIXME */ -/* if (buf->meta) */ -/* memcpy(&stereo->meta,buf->meta,sizeof(stereo->meta)); */ + if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (outbuf))) + gst_object_sync_values (G_OBJECT (stereo), GST_BUFFER_TIMESTAMP (outbuf)); if (stereo->active) { - - /*if (stereo->meta.channels == 2 && stereo->meta.format == AFMT_S16_LE) { */ - data = (gint16 *) GST_BUFFER_DATA (buf); - samples = GST_BUFFER_SIZE (buf) / 2; - mul = stereo->stereo; for (i = 0; i < samples / 2; i += 2) { avg = (data[i] + data[i + 1]) / 2; ldiff = data[i] - avg; @@ -174,10 +161,9 @@ gst_stereo_chain (GstPad * pad, GstData * _data) tmp = 32767; data[i + 1] = tmp; } - /*} */ } - gst_pad_push (stereo->srcpad, GST_DATA (buf)); + return GST_FLOW_OK; } static void @@ -191,12 +177,13 @@ gst_stereo_set_property (GObject * object, guint prop_id, const GValue * value, switch (prop_id) { case ARG_ACTIVE: - stereo->active = g_value_get_int (value); + stereo->active = g_value_get_boolean (value); break; case ARG_STEREO: stereo->stereo = g_value_get_float (value) * 10.0; break; default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } @@ -212,7 +199,7 @@ gst_stereo_get_property (GObject * object, guint prop_id, GValue * value, switch (prop_id) { case ARG_ACTIVE: - g_value_set_int (value, stereo->active); + g_value_set_boolean (value, stereo->active); break; case ARG_STEREO: g_value_set_float (value, stereo->stereo / 10.0); diff --git a/gst/stereo/gststereo.h b/gst/stereo/gststereo.h index 6c4954dd..27724646 100644 --- a/gst/stereo/gststereo.h +++ b/gst/stereo/gststereo.h @@ -23,12 +23,7 @@ #include <gst/gst.h> - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - +#include <gst/audio/gstaudiofilter.h> #define GST_TYPE_STEREO \ (gst_stereo_get_type()) @@ -45,23 +40,16 @@ typedef struct _GstStereo GstStereo; typedef struct _GstStereoClass GstStereoClass; struct _GstStereo { - GstElement element; + GstAudioFilter element; - GstPad *sinkpad,*srcpad; - - gint8 active; + gboolean active; gfloat stereo; }; struct _GstStereoClass { - GstElementClass parent_class; + GstAudioFilterClass parent_class; }; GType gst_stereo_get_type(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - #endif /* __GST_STEREO_H__ */ |