diff options
author | David Schleef <ds@schleef.org> | 2003-12-06 04:03:05 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2003-12-06 04:03:05 +0000 |
commit | 466370d8237846158836c87537e92a64b6ac2d87 (patch) | |
tree | c95c8e813585e63561291eec03738a0646c6e9f4 /gst-libs | |
parent | 9be5abd7cf58a87c9bf7568eed0137577494a92c (diff) | |
download | gst-plugins-bad-466370d8237846158836c87537e92a64b6ac2d87.tar.gz gst-plugins-bad-466370d8237846158836c87537e92a64b6ac2d87.tar.bz2 gst-plugins-bad-466370d8237846158836c87537e92a64b6ac2d87.zip |
A generic audio filter base class
Original commit message from CVS:
A generic audio filter base class
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/audio/Makefile.am | 13 | ||||
-rw-r--r-- | gst-libs/gst/audio/gstaudiofilter.c | 322 | ||||
-rw-r--r-- | gst-libs/gst/audio/gstaudiofilter.h | 84 | ||||
-rw-r--r-- | gst-libs/gst/audio/gstaudiofilterexample.c | 171 |
4 files changed, 588 insertions, 2 deletions
diff --git a/gst-libs/gst/audio/Makefile.am b/gst-libs/gst/audio/Makefile.am index 4f95f4ef..d99cbcc6 100644 --- a/gst-libs/gst/audio/Makefile.am +++ b/gst-libs/gst/audio/Makefile.am @@ -1,12 +1,21 @@ librarydir = $(libdir)/gstreamer-@GST_MAJORMINOR@ -library_LTLIBRARIES = libgstaudio.la +library_LTLIBRARIES = libgstaudio.la libgstaudiofilter.la libgstaudiofilterexample.la libgstaudio_la_SOURCES = audio.c audioclock.c libgstaudioincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/audio -libgstaudioinclude_HEADERS = audio.h audioclock.h +libgstaudioinclude_HEADERS = audio.h audioclock.h gstaudiofilter.h libgstaudio_la_LIBADD = libgstaudio_la_CFLAGS = $(GST_CFLAGS) libgstaudio_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) + +libgstaudiofilter_la_SOURCES = gstaudiofilter.c gstaudiofilter.h +libgstaudiofilter_la_CFLAGS = $(GST_CFLAGS) +libgstaudiofilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) + +libgstaudiofilterexample_la_SOURCES = gstaudiofilterexample.c +libgstaudiofilterexample_la_CFLAGS = $(GST_CFLAGS) +libgstaudiofilterexample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) + diff --git a/gst-libs/gst/audio/gstaudiofilter.c b/gst-libs/gst/audio/gstaudiofilter.c new file mode 100644 index 00000000..c097b5d3 --- /dev/null +++ b/gst-libs/gst/audio/gstaudiofilter.c @@ -0,0 +1,322 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * Copyright (C) <2003> 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/*#define DEBUG_ENABLED */ +#include <gstaudiofilter.h> + +#include <string.h> + + +/* GstAudiofilter signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0, + ARG_METHOD, + /* FILL ME */ +}; + +static void gst_audiofilter_base_init (gpointer g_class); +static void gst_audiofilter_class_init (gpointer g_class, gpointer class_data); +static void gst_audiofilter_init (GTypeInstance *instance, gpointer g_class); + +static void gst_audiofilter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_audiofilter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gst_audiofilter_chain (GstPad *pad, GstData *_data); +GstCaps2 * gst_audiofilter_class_get_capslist(GstAudiofilterClass *klass); + +static GstElementClass *parent_class = NULL; + +GType +gst_audiofilter_get_type (void) +{ + static GType audiofilter_type = 0; + + if (!audiofilter_type) { + static const GTypeInfo audiofilter_info = { + sizeof(GstAudiofilterClass), + gst_audiofilter_base_init, + NULL, + gst_audiofilter_class_init, + NULL, + NULL, + sizeof(GstAudiofilter), + 0, + gst_audiofilter_init, + }; + audiofilter_type = g_type_register_static(GST_TYPE_ELEMENT, + "GstAudiofilter", &audiofilter_info, G_TYPE_FLAG_ABSTRACT); + } + return audiofilter_type; +} + +static void gst_audiofilter_base_init (gpointer g_class) +{ + static GstElementDetails audiofilter_details = { + "Audio filter base class", + "Filter/Effect/Audio", + "Filters audio", + "David Schleef <ds@schleef.org>" + }; + GstAudiofilterClass *klass = (GstAudiofilterClass *) g_class; + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + gst_element_class_set_details (element_class, &audiofilter_details); +} + +static void gst_audiofilter_class_init (gpointer g_class, gpointer class_data) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstAudiofilterClass *klass; + + klass = (GstAudiofilterClass *)g_class; + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_audiofilter_set_property; + gobject_class->get_property = gst_audiofilter_get_property; +} + +static GstCaps2 * +gst_audiofilter_getcaps (GstPad *pad) +{ + GstAudiofilter *audiofilter; + GstCaps2 *othercaps; + GstAudiofilterClass *audiofilter_class; + + GST_DEBUG("gst_audiofilter_sink_getcaps"); + audiofilter = GST_AUDIOFILTER (gst_pad_get_parent (pad)); + + audiofilter_class = GST_AUDIOFILTER_CLASS ( + G_OBJECT_GET_CLASS (audiofilter)); + + if (pad == audiofilter->srcpad) { + othercaps = gst_pad_get_allowed_caps (audiofilter->sinkpad); + } else { + othercaps = gst_pad_get_allowed_caps (audiofilter->srcpad); + } + + return gst_caps2_intersect (othercaps, audiofilter_class->caps); +} + +static GstPadLinkReturn +gst_audiofilter_link (GstPad *pad, const GstCaps2 *caps) +{ + GstAudiofilter *audiofilter; + GstPadLinkReturn ret; + GstPadLinkReturn link_ret; + GstStructure *structure; + GstAudiofilterClass *audiofilter_class; + + GST_DEBUG("gst_audiofilter_link"); + audiofilter = GST_AUDIOFILTER (gst_pad_get_parent (pad)); + audiofilter_class = GST_AUDIOFILTER_CLASS ( + G_OBJECT_GET_CLASS (audiofilter)); + + + if (pad == audiofilter->srcpad) { + link_ret = gst_pad_try_set_caps (audiofilter->sinkpad, caps); + } else { + link_ret = gst_pad_try_set_caps (audiofilter->srcpad, caps); + } + + if (link_ret != GST_PAD_LINK_OK) return link_ret; + + structure = gst_caps2_get_nth_cap (caps, 0); + + if (strcmp (gst_structure_get_name (structure), "audio/x-raw-int") == 0) { + ret = gst_structure_get_int (structure, "depth", &audiofilter->depth); + ret &= gst_structure_get_int (structure, "width", &audiofilter->width); + ret &= gst_structure_get_int (structure, "channels", &audiofilter->channels); + } else if (strcmp (gst_structure_get_name (structure), "audio/x-raw-float") + == 0) { + + } else { + g_assert_not_reached(); + } + ret &= gst_structure_get_int (structure, "rate", &audiofilter->rate); + + if (audiofilter_class->setup) (audiofilter_class->setup) (audiofilter); + + return GST_PAD_LINK_OK; +} + +static void +gst_audiofilter_init (GTypeInstance *instance, gpointer g_class) +{ + GstAudiofilter *audiofilter = GST_AUDIOFILTER (instance); + GstPadTemplate *pad_template; + + GST_DEBUG("gst_audiofilter_init"); + + pad_template = gst_element_class_get_pad_template(GST_ELEMENT_CLASS(g_class), + "sink"); + g_return_if_fail(pad_template != NULL); + audiofilter->sinkpad = gst_pad_new_from_template(pad_template, "sink"); + gst_element_add_pad(GST_ELEMENT(audiofilter),audiofilter->sinkpad); + gst_pad_set_chain_function(audiofilter->sinkpad,gst_audiofilter_chain); + gst_pad_set_link_function(audiofilter->sinkpad,gst_audiofilter_link); + gst_pad_set_getcaps_function(audiofilter->sinkpad,gst_audiofilter_getcaps); + + pad_template = gst_element_class_get_pad_template(GST_ELEMENT_CLASS(g_class), + "src"); + g_return_if_fail(pad_template != NULL); + audiofilter->srcpad = gst_pad_new_from_template(pad_template, "src"); + gst_element_add_pad(GST_ELEMENT(audiofilter),audiofilter->srcpad); + gst_pad_set_link_function(audiofilter->srcpad,gst_audiofilter_link); + gst_pad_set_getcaps_function(audiofilter->srcpad,gst_audiofilter_getcaps); + + audiofilter->inited = FALSE; +} + +static void +gst_audiofilter_chain (GstPad *pad, GstData *data) +{ + GstBuffer *inbuf = GST_BUFFER (data); + GstAudiofilter *audiofilter; + GstBuffer *outbuf; + GstAudiofilterClass *audiofilter_class; + + GST_DEBUG ("gst_audiofilter_chain"); + + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (inbuf != NULL); + + audiofilter = GST_AUDIOFILTER (gst_pad_get_parent (pad)); + //g_return_if_fail (audiofilter->inited); + audiofilter_class = GST_AUDIOFILTER_CLASS ( + G_OBJECT_GET_CLASS (audiofilter)); + + GST_DEBUG ("gst_audiofilter_chain: got buffer of %d bytes in '%s'", + GST_BUFFER_SIZE(inbuf), GST_OBJECT_NAME (audiofilter)); + + if(audiofilter->passthru){ + gst_pad_push(audiofilter->srcpad, data); + return; + } + + if (gst_data_is_writable(data)) { + if (audiofilter_class->filter_inplace) { + (audiofilter_class->filter_inplace) (audiofilter, inbuf); + outbuf = inbuf; + } else { + outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE(inbuf)); + GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(inbuf); + GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(inbuf); + + (audiofilter_class->filter) (audiofilter, outbuf, inbuf); + gst_buffer_unref(inbuf); + } + } else { + outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE(inbuf)); + GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(inbuf); + GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(inbuf); + if (audiofilter_class->filter) { + (audiofilter_class->filter) (audiofilter, outbuf, inbuf); + } else { + memcpy(GST_BUFFER_DATA(outbuf), GST_BUFFER_DATA(inbuf), + GST_BUFFER_SIZE(inbuf)); + + (audiofilter_class->filter_inplace) (audiofilter, outbuf); + } + gst_buffer_unref(inbuf); + } + + gst_pad_push(audiofilter->srcpad, GST_DATA (outbuf)); +} + +static void +gst_audiofilter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstAudiofilter *src; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_AUDIOFILTER(object)); + src = GST_AUDIOFILTER(object); + + GST_DEBUG("gst_audiofilter_set_property"); + switch (prop_id) { + default: + break; + } +} + +static void +gst_audiofilter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstAudiofilter *src; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_AUDIOFILTER(object)); + src = GST_AUDIOFILTER(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +void gst_audiofilter_class_add_pad_templates ( + GstAudiofilterClass *audiofilter_class, const GstCaps2 *caps) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (audiofilter_class); + + audiofilter_class->caps = gst_caps2_copy(caps); + + gst_element_class_add_pad_template (element_class, + gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, + gst_caps2_copy(caps))); + + gst_element_class_add_pad_template (element_class, + gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + gst_caps2_copy(caps))); +} + +static gboolean +plugin_init (GstPlugin *plugin) +{ + return TRUE; +} + +GST_PLUGIN_DEFINE ( + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstaudiofilter", + "Audio filter parent class", + plugin_init, + VERSION, + "LGPL", + NULL, + GST_PACKAGE, + GST_ORIGIN +) diff --git a/gst-libs/gst/audio/gstaudiofilter.h b/gst-libs/gst/audio/gstaudiofilter.h new file mode 100644 index 00000000..f5bb7eaa --- /dev/null +++ b/gst-libs/gst/audio/gstaudiofilter.h @@ -0,0 +1,84 @@ +/* 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_AUDIOFILTER_H__ +#define __GST_AUDIOFILTER_H__ + + +#include <gst/gst.h> + + +G_BEGIN_DECLS + +typedef struct _GstAudiofilter GstAudiofilter; +typedef struct _GstAudiofilterClass GstAudiofilterClass; + +typedef void (*GstAudiofilterFilterFunc)(GstAudiofilter *filter, + GstBuffer *outbuf, GstBuffer *inbuf); +typedef void (*GstAudiofilterInplaceFilterFunc)(GstAudiofilter *filter, + GstBuffer *buffer); + +typedef void (*GstAudiofilterSetupFunc) (GstAudiofilter *filter); + + +#define GST_TYPE_AUDIOFILTER \ + (gst_audiofilter_get_type()) +#define GST_AUDIOFILTER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIOFILTER,GstAudiofilter)) +#define GST_AUDIOFILTER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIOFILTER,GstAudiofilterClass)) +#define GST_IS_AUDIOFILTER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIOFILTER)) +#define GST_IS_AUDIOFILTER_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIOFILTER)) + +struct _GstAudiofilter { + GstElement element; + + GstPad *sinkpad,*srcpad; + + /* audio state */ + gboolean inited; + + int rate; + int width; + int channels; + int depth; + gboolean passthru; + +}; + +struct _GstAudiofilterClass { + GstElementClass parent_class; + + GstCaps2 *caps; + GstAudiofilterSetupFunc setup; + GstAudiofilterInplaceFilterFunc filter_inplace; + GstAudiofilterFilterFunc filter; +}; + +GType gst_audiofilter_get_type(void); + +void gst_audiofilter_class_add_pad_templates (GstAudiofilterClass *audiofilterclass, const GstCaps2 *caps); + +G_END_DECLS + +#endif /* __GST_AUDIOFILTER_H__ */ + diff --git a/gst-libs/gst/audio/gstaudiofilterexample.c b/gst-libs/gst/audio/gstaudiofilterexample.c new file mode 100644 index 00000000..bfa711c2 --- /dev/null +++ b/gst-libs/gst/audio/gstaudiofilterexample.c @@ -0,0 +1,171 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * Copyright (C) <2003> 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include <gst/audio/gstaudiofilter.h> + +typedef struct _GstAudiofilterExample GstAudiofilterExample; +typedef struct _GstAudiofilterExampleClass GstAudiofilterExampleClass; + +#define GST_TYPE_AUDIOFILTER_EXAMPLE \ + (gst_audiofilter_example_get_type()) +#define GST_AUDIOFILTER_EXAMPLE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIOFILTER_EXAMPLE,GstAudiofilterExample)) +#define GST_AUDIOFILTER_EXAMPLE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIOFILTER_EXAMPLE,GstAudiofilterExampleClass)) +#define GST_IS_AUDIOFILTER_EXAMPLE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIOFILTER_EXAMPLE)) +#define GST_IS_AUDIOFILTER_EXAMPLE_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIOFILTER_EXAMPLE)) + +struct _GstAudiofilterExample { + GstAudiofilter audiofilter; + +}; + +struct _GstAudiofilterExampleClass { + GstAudiofilterClass parent_class; + +}; + + +/* GstAudiofilterExample signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0, + ARG_METHOD, + /* FILL ME */ +}; + +static void gst_audiofilter_example_base_init (gpointer g_class); +static void gst_audiofilter_example_class_init (gpointer g_class, gpointer class_data); + +static void gst_audiofilter_example_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_audiofilter_example_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +GType +gst_audiofilter_example_get_type (void) +{ + static GType audiofilter_example_type = 0; + + if (!audiofilter_example_type) { + static const GTypeInfo audiofilter_example_info = { + sizeof(GstAudiofilterExampleClass), + gst_audiofilter_example_base_init, + NULL, + gst_audiofilter_example_class_init, + NULL, + NULL, + sizeof(GstAudiofilterExample), + 0, + NULL, + }; + audiofilter_example_type = g_type_register_static(GST_TYPE_AUDIOFILTER, + "GstAudiofilterExample", &audiofilter_example_info, 0); + } + return audiofilter_example_type; +} + +static void gst_audiofilter_example_base_init (gpointer g_class) +{ + static GstElementDetails audiofilter_example_details = { + "Audio filter example", + "Filter/Effect/Audio", + "Filters audio", + "David Schleef <ds@schleef.org>" + }; + GstAudiofilterExampleClass *klass = (GstAudiofilterExampleClass *) g_class; + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + gst_element_class_set_details (element_class, &audiofilter_example_details); +} + +static void gst_audiofilter_example_class_init (gpointer g_class, gpointer class_data) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstAudiofilterExampleClass *klass; + + klass = (GstAudiofilterExampleClass *)g_class; + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + gobject_class->set_property = gst_audiofilter_example_set_property; + gobject_class->get_property = gst_audiofilter_example_get_property; +} + +static void +gst_audiofilter_example_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstAudiofilterExample *src; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_AUDIOFILTER_EXAMPLE(object)); + src = GST_AUDIOFILTER_EXAMPLE(object); + + GST_DEBUG("gst_audiofilter_example_set_property"); + switch (prop_id) { + default: + break; + } +} + +static void +gst_audiofilter_example_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstAudiofilterExample *src; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_AUDIOFILTER_EXAMPLE(object)); + src = GST_AUDIOFILTER_EXAMPLE(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static gboolean +plugin_init (GstPlugin *plugin) +{ + return TRUE; +} + +GST_PLUGIN_DEFINE ( + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstaudiofilter_example", + "Audio filter example", + plugin_init, + VERSION, + "LGPL", + NULL, + GST_PACKAGE, + GST_ORIGIN +) |