summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2007-08-08 20:47:33 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2007-08-08 20:47:33 +0000
commitede3039046ce875b17ac425f584d29981f2ddcac (patch)
tree572bfd50585cd9d7d4c4dd5cc6f594355070459f
parent47b3e2452d6c4a6625bc32518579abbb279a74df (diff)
downloadgst-plugins-bad-ede3039046ce875b17ac425f584d29981f2ddcac.tar.gz
gst-plugins-bad-ede3039046ce875b17ac425f584d29981f2ddcac.tar.bz2
gst-plugins-bad-ede3039046ce875b17ac425f584d29981f2ddcac.zip
gst/filter/: Use GstAudioFilter as base class and don't leak the memory of the filter kernel and residue.
Original commit message from CVS: * gst/filter/Makefile.am: * gst/filter/gstbpwsinc.c: (gst_bpwsinc_dispose), (gst_bpwsinc_base_init), (gst_bpwsinc_class_init), (gst_bpwsinc_init), (bpwsinc_setup): * gst/filter/gstbpwsinc.h: * gst/filter/gstlpwsinc.c: (gst_lpwsinc_dispose), (gst_lpwsinc_base_init), (gst_lpwsinc_class_init), (gst_lpwsinc_init), (lpwsinc_setup): * gst/filter/gstlpwsinc.h: Use GstAudioFilter as base class and don't leak the memory of the filter kernel and residue.
-rw-r--r--ChangeLog14
-rw-r--r--gst/filter/Makefile.am2
-rw-r--r--gst/filter/gstbpwsinc.c75
-rw-r--r--gst/filter/gstbpwsinc.h6
-rw-r--r--gst/filter/gstlpwsinc.c75
-rw-r--r--gst/filter/gstlpwsinc.h6
6 files changed, 102 insertions, 76 deletions
diff --git a/ChangeLog b/ChangeLog
index 200ce9af..27b8e7bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-08-08 Sebastian Dröge <slomo@circular-chaos.org>
+
+ * gst/filter/Makefile.am:
+ * gst/filter/gstbpwsinc.c: (gst_bpwsinc_dispose),
+ (gst_bpwsinc_base_init), (gst_bpwsinc_class_init),
+ (gst_bpwsinc_init), (bpwsinc_setup):
+ * gst/filter/gstbpwsinc.h:
+ * gst/filter/gstlpwsinc.c: (gst_lpwsinc_dispose),
+ (gst_lpwsinc_base_init), (gst_lpwsinc_class_init),
+ (gst_lpwsinc_init), (lpwsinc_setup):
+ * gst/filter/gstlpwsinc.h:
+ Use GstAudioFilter as base class and don't leak the memory
+ of the filter kernel and residue.
+
2007-08-08 Wim Taymans <wim.taymans@gmail.com>
Patch by: Josep Torre Valles <josep@fluendo.com>
diff --git a/gst/filter/Makefile.am b/gst/filter/Makefile.am
index d17e3d2c..e4f27784 100644
--- a/gst/filter/Makefile.am
+++ b/gst/filter/Makefile.am
@@ -7,6 +7,8 @@ libgstfilter_la_LIBADD = \
$(GST_BASE_LIBS) \
$(GST_LIBS) \
$(GST_CONTROLLER_LIBS) \
+ $(GST_PLUGINS_BASE_LIBS) \
+ -lgstaudio-$(GST_MAJORMINOR) \
$(LIBM)
libgstfilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
diff --git a/gst/filter/gstbpwsinc.c b/gst/filter/gstbpwsinc.c
index 8ba87fd3..7b881ae4 100644
--- a/gst/filter/gstbpwsinc.c
+++ b/gst/filter/gstbpwsinc.c
@@ -27,7 +27,6 @@
*
* FIXME:
* - this filter is totally unoptimized !
- * - we do not destroy the allocated memory for filters and residue
* - this might be improved upon with bytestream
*/
@@ -38,7 +37,7 @@
#include <string.h>
#include <math.h>
#include <gst/gst.h>
-#include <gst/base/gstbasetransform.h>
+#include <gst/audio/gstaudiofilter.h>
#include <gst/controller/gstcontroller.h>
#include "gstbpwsinc.h"
@@ -69,31 +68,18 @@ enum
PROP_UPPER_FREQUENCY
};
-static GstStaticPadTemplate bpwsinc_sink_template =
-GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "rate = (int) [ 1, MAX ], "
- "channels = (int) [ 1, MAX ], "
- "endianness = (int) BYTE_ORDER, " "width = (int) 32")
- );
-
-static GstStaticPadTemplate bpwsinc_src_template = GST_STATIC_PAD_TEMPLATE
- ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "rate = (int) [ 1, MAX ], "
- "channels = (int) [ 1, MAX ], "
- "endianness = (int) BYTE_ORDER, " "width = (int) 32")
- );
+#define ALLOWED_CAPS \
+ "audio/x-raw-float," \
+ " width = (int) 32, " \
+ " endianness = (int) BYTE_ORDER," \
+ " rate = (int) [ 1, MAX ]," \
+ " channels = (int) [ 1, MAX ]"
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_bpwsinc_debug, "bpwsinc", 0, "Band-pass Windowed sinc filter plugin");
-GST_BOILERPLATE_FULL (GstBPWSinc, gst_bpwsinc, GstBaseTransform,
- GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
+GST_BOILERPLATE_FULL (GstBPWSinc, gst_bpwsinc, GstAudioFilter,
+ GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
static void bpwsinc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@@ -102,14 +88,26 @@ static void bpwsinc_get_property (GObject * object, guint prop_id,
static GstFlowReturn bpwsinc_transform_ip (GstBaseTransform * base,
GstBuffer * outbuf);
-static gboolean bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps,
- GstCaps * outcaps);
+static gboolean bpwsinc_setup (GstAudioFilter * base,
+ GstRingBufferSpec * format);
/* Element class */
static void
gst_bpwsinc_dispose (GObject * object)
{
+ GstBPWSinc *this = GST_BPWSINC (object);
+
+ if (this->residue) {
+ g_free (this->residue);
+ this->residue = NULL;
+ }
+
+ if (this->kernel) {
+ g_free (this->kernel);
+ this->kernel = NULL;
+ }
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -117,12 +115,14 @@ static void
gst_bpwsinc_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+ GstCaps *caps;
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&bpwsinc_src_template));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&bpwsinc_sink_template));
gst_element_class_set_details (element_class, &bpwsinc_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
@@ -152,7 +152,7 @@ gst_bpwsinc_class_init (GstBPWSincClass * klass)
1, G_MAXINT, 1, G_PARAM_READWRITE));
trans_class->transform_ip = GST_DEBUG_FUNCPTR (bpwsinc_transform_ip);
- trans_class->set_caps = GST_DEBUG_FUNCPTR (bpwsinc_set_caps);
+ GST_AUDIO_FILTER_CLASS (klass)->setup = GST_DEBUG_FUNCPTR (bpwsinc_setup);
}
static void
@@ -162,14 +162,15 @@ gst_bpwsinc_init (GstBPWSinc * this, GstBPWSincClass * g_class)
this->lower_frequency = 0.25;
this->upper_frequency = 0.3;
this->kernel = NULL;
+ this->residue = NULL;
}
-/* GstBaseTransform vmethod implementations */
+/* GstAudioFilter vmethod implementations */
/* get notified of caps and plug in the correct process function */
static gboolean
-bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
+bpwsinc_setup (GstAudioFilter * base, GstRingBufferSpec * format)
{
int i = 0;
double sum = 0.0;
@@ -177,9 +178,6 @@ bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
double *kernel_lp, *kernel_hp;
GstBPWSinc *this = GST_BPWSINC (base);
- GST_DEBUG_OBJECT (this,
- "set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
-
len = this->wing_size;
/* fill the lp kernel
* FIXME: refactor to own function, this is not caps related
@@ -230,6 +228,8 @@ bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
kernel_hp[i] /= sum;
/* combine the two thiss */
+ if (this->kernel)
+ g_free (this->kernel);
this->kernel = (double *) g_malloc (sizeof (double) * (2 * len + 1));
for (i = 0; i <= len * 2; ++i)
@@ -245,6 +245,9 @@ bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
g_free (kernel_hp);
/* set up the residue memory space */
+ if (this->residue)
+ g_free (this->residue);
+
this->residue = (gfloat *) g_malloc (sizeof (gfloat) * (len * 2 + 1));
for (i = 0; i <= len * 2; ++i)
this->residue[i] = 0.0;
@@ -252,6 +255,8 @@ bpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
return TRUE;
}
+/* GstBaseTransform vmethod implementations */
+
static GstFlowReturn
bpwsinc_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
{
diff --git a/gst/filter/gstbpwsinc.h b/gst/filter/gstbpwsinc.h
index 1d825dec..af5938d5 100644
--- a/gst/filter/gstbpwsinc.h
+++ b/gst/filter/gstbpwsinc.h
@@ -36,7 +36,7 @@
#include "gstfilter.h"
#include <gst/gst.h>
-#include <gst/base/gstbasetransform.h>
+#include <gst/audio/gstaudiofilter.h>
G_BEGIN_DECLS
@@ -60,7 +60,7 @@ typedef struct _GstBPWSincClass GstBPWSincClass;
* Opaque data structure.
*/
struct _GstBPWSinc {
- GstBaseTransform element;
+ GstAudioFilter element;
double frequency;
double lower_frequency, upper_frequency;
@@ -72,7 +72,7 @@ struct _GstBPWSinc {
};
struct _GstBPWSincClass {
- GstBaseTransformClass parent_class;
+ GstAudioFilterClass parent_class;
};
G_END_DECLS
diff --git a/gst/filter/gstlpwsinc.c b/gst/filter/gstlpwsinc.c
index c182a626..98a2e4dd 100644
--- a/gst/filter/gstlpwsinc.c
+++ b/gst/filter/gstlpwsinc.c
@@ -27,7 +27,6 @@
*
* FIXME:
* - this filter is totally unoptimized !
- * - we do not destroy the allocated memory for filters and residue
* - this might be improved upon with bytestream
*/
@@ -38,7 +37,7 @@
#include <string.h>
#include <math.h>
#include <gst/gst.h>
-#include <gst/base/gstbasetransform.h>
+#include <gst/audio/gstaudiofilter.h>
#include <gst/controller/gstcontroller.h>
#include "gstlpwsinc.h"
@@ -68,31 +67,18 @@ enum
PROP_FREQUENCY
};
-static GstStaticPadTemplate lpwsinc_sink_template =
-GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "rate = (int) [ 1, MAX ], "
- "channels = (int) [ 1, MAX ], "
- "endianness = (int) BYTE_ORDER, " "width = (int) 32")
- );
-
-static GstStaticPadTemplate lpwsinc_src_template = GST_STATIC_PAD_TEMPLATE
- ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "rate = (int) [ 1, MAX ], "
- "channels = (int) [ 1, MAX ], "
- "endianness = (int) BYTE_ORDER, " "width = (int) 32")
- );
+#define ALLOWED_CAPS \
+ "audio/x-raw-float," \
+ " width = (int) 32, " \
+ " endianness = (int) BYTE_ORDER," \
+ " rate = (int) [ 1, MAX ]," \
+ " channels = (int) [ 1, MAX ]"
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_lpwsinc_debug, "lpwsinc", 0, "Low-pass Windowed sinc filter plugin");
-GST_BOILERPLATE_FULL (GstLPWSinc, gst_lpwsinc, GstBaseTransform,
- GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
+GST_BOILERPLATE_FULL (GstLPWSinc, gst_lpwsinc, GstAudioFilter,
+ GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
static void lpwsinc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@@ -101,14 +87,26 @@ static void lpwsinc_get_property (GObject * object, guint prop_id,
static GstFlowReturn lpwsinc_transform_ip (GstBaseTransform * base,
GstBuffer * outbuf);
-static gboolean lpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps,
- GstCaps * outcaps);
+static gboolean lpwsinc_setup (GstAudioFilter * base,
+ GstRingBufferSpec * format);
/* Element class */
static void
gst_lpwsinc_dispose (GObject * object)
{
+ GstLPWSinc *this = GST_LPWSINC (object);
+
+ if (this->residue) {
+ g_free (this->residue);
+ this->residue = NULL;
+ }
+
+ if (this->kernel) {
+ g_free (this->kernel);
+ this->kernel = NULL;
+ }
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -116,12 +114,14 @@ static void
gst_lpwsinc_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+ GstCaps *caps;
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&lpwsinc_src_template));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&lpwsinc_sink_template));
gst_element_class_set_details (element_class, &lpwsinc_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
@@ -148,7 +148,7 @@ gst_lpwsinc_class_init (GstLPWSincClass * klass)
1, G_MAXINT, 1, G_PARAM_READWRITE));
trans_class->transform_ip = GST_DEBUG_FUNCPTR (lpwsinc_transform_ip);
- trans_class->set_caps = GST_DEBUG_FUNCPTR (lpwsinc_set_caps);
+ GST_AUDIO_FILTER_CLASS (klass)->setup = GST_DEBUG_FUNCPTR (lpwsinc_setup);
}
static void
@@ -157,28 +157,29 @@ gst_lpwsinc_init (GstLPWSinc * this, GstLPWSincClass * g_class)
this->wing_size = 50;
this->frequency = 0.25;
this->kernel = NULL;
+ this->residue = NULL;
}
-/* GstBaseTransform vmethod implementations */
+/* GstAudioFilter vmethod implementations */
/* get notified of caps and plug in the correct process function */
static gboolean
-lpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
+lpwsinc_setup (GstAudioFilter * base, GstRingBufferSpec * format)
{
int i = 0;
double sum = 0.0;
int len = 0;
GstLPWSinc *this = GST_LPWSINC (base);
- GST_DEBUG_OBJECT (this,
- "set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
-
/* FIXME: remember to free it */
/* fill the kernel */
g_print ("DEBUG: initing filter kernel\n");
len = this->wing_size;
GST_DEBUG ("lpwsinc: initializing filter kernel of length %d", len * 2 + 1);
+
+ if (this->kernel)
+ g_free (this->kernel);
this->kernel = (double *) g_malloc (sizeof (double) * (2 * len + 1));
for (i = 0; i <= len * 2; ++i) {
@@ -199,6 +200,8 @@ lpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
this->kernel[i] /= sum;
/* set up the residue memory space */
+ if (this->residue)
+ g_free (this->residue);
this->residue = (gfloat *) g_malloc (sizeof (gfloat) * (len * 2 + 1));
for (i = 0; i <= len * 2; ++i)
this->residue[i] = 0.0;
@@ -206,6 +209,8 @@ lpwsinc_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
return TRUE;
}
+/* GstBaseTransform vmethod implementations */
+
static GstFlowReturn
lpwsinc_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
{
diff --git a/gst/filter/gstlpwsinc.h b/gst/filter/gstlpwsinc.h
index 58d5ec99..14791b51 100644
--- a/gst/filter/gstlpwsinc.h
+++ b/gst/filter/gstlpwsinc.h
@@ -36,7 +36,7 @@
#include "gstfilter.h"
#include <gst/gst.h>
-#include <gst/base/gstbasetransform.h>
+#include <gst/audio/gstaudiofilter.h>
G_BEGIN_DECLS
@@ -60,7 +60,7 @@ typedef struct _GstLPWSincClass GstLPWSincClass;
* Opaque data structure.
*/
struct _GstLPWSinc {
- GstBaseTransform element;
+ GstAudioFilter element;
void (*process)(GstLPWSinc*, gpointer, gint);
@@ -73,7 +73,7 @@ struct _GstLPWSinc {
};
struct _GstLPWSincClass {
- GstBaseTransformClass parent_class;
+ GstAudioFilterClass parent_class;
};
G_END_DECLS