gst/audiofx/: Some small cleanups and port both elements to the new GstAudioFilter base class to save a few lines of ...

Original commit message from CVS:
* gst/audiofx/audioamplify.c: (gst_audio_amplify_base_init),
(gst_audio_amplify_class_init), (gst_audio_amplify_init),
(gst_audio_amplify_set_process_function),
(gst_audio_amplify_setup):
* gst/audiofx/audioamplify.h:
* gst/audiofx/audioinvert.c: (gst_audio_invert_base_init),
(gst_audio_invert_class_init), (gst_audio_invert_setup):
* gst/audiofx/audioinvert.h:
Some small cleanups and port both elements to the new GstAudioFilter
base class to save a few lines of common code.
* gst/audiofx/Makefile.am:
Link against libgstaudio for the above changes
This commit is contained in:
Sebastian Dröge 2007-02-06 11:16:49 +00:00
parent f7935f9a40
commit cdba2c4219
6 changed files with 116 additions and 148 deletions

View file

@ -1,3 +1,18 @@
2007-02-06 Sebastian Dröge <slomo@circular-chaos.org>
* gst/audiofx/audioamplify.c: (gst_audio_amplify_base_init),
(gst_audio_amplify_class_init), (gst_audio_amplify_init),
(gst_audio_amplify_set_process_function),
(gst_audio_amplify_setup):
* gst/audiofx/audioamplify.h:
* gst/audiofx/audioinvert.c: (gst_audio_invert_base_init),
(gst_audio_invert_class_init), (gst_audio_invert_setup):
* gst/audiofx/audioinvert.h:
Some small cleanups and port both elements to the new GstAudioFilter
base class to save a few lines of common code.
* gst/audiofx/Makefile.am:
Link against libgstaudio for the above changes
2007-01-29 Wim Taymans <wim@fluendo.com>
* tests/check/elements/.cvsignore:

View file

@ -11,10 +11,13 @@ libgstaudiofx_la_SOURCES = audiofx.c\
# flags used to compile this plugin
libgstaudiofx_la_CFLAGS = $(GST_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_CONTROLLER_CFLAGS)
$(GST_CONTROLLER_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS)
libgstaudiofx_la_LIBADD = $(GST_LIBS) \
$(GST_BASE_LIBS) \
$(GST_CONTROLLER_LIBS)
$(GST_CONTROLLER_LIBS) \
$(GST_PLUGINS_BASE_LIBS) \
-lgstaudio-$(GST_MAJORMINOR)
libgstaudiofx_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
# headers we need but don't want installed

View file

@ -43,6 +43,8 @@
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiofilter.h>
#include <gst/controller/gstcontroller.h>
#include "audioamplify.h"
@ -100,47 +102,33 @@ gst_audio_amplify_clipping_method_get_type (void)
return gtype;
}
static GstStaticPadTemplate 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; "
"audio/x-raw-int, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) BYTE_ORDER, "
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
);
static GstStaticPadTemplate 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; "
"audio/x-raw-int, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) BYTE_ORDER, "
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
);
#define ALLOWED_CAPS \
"audio/x-raw-int," \
" depth=(int)16," \
" width=(int)16," \
" endianness=(int)BYTE_ORDER," \
" signed=(bool)TRUE," \
" rate=(int)[1,MAX]," \
" channels=(int)[1,MAX]; " \
"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_audio_amplify_debug, "audioamplify", 0, "audioamplify element");
GST_BOILERPLATE_FULL (GstAudioAmplify, gst_audio_amplify, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
GST_BOILERPLATE_FULL (GstAudioAmplify, gst_audio_amplify, GstAudioFilter,
GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
static void gst_audio_amplify_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_audio_amplify_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_audio_amplify_set_caps (GstBaseTransform * base,
GstCaps * incaps, GstCaps * outcaps);
static gboolean gst_audio_amplify_setup (GstAudioFilter * filter,
GstRingBufferSpec * format);
static GstFlowReturn gst_audio_amplify_transform_ip (GstBaseTransform * base,
GstBuffer * buf);
@ -179,12 +167,14 @@ static void
gst_audio_amplify_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstCaps *caps;
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
gst_element_class_set_details (element_class, &element_details);
caps = gst_caps_from_string (ALLOWED_CAPS);
gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (klass),
caps);
gst_caps_unref (caps);
}
static void
@ -215,8 +205,8 @@ gst_audio_amplify_class_init (GstAudioAmplifyClass * klass)
GST_TYPE_AUDIO_AMPLIFY_CLIPPING_METHOD, METHOD_CLIP,
G_PARAM_READWRITE));
GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
GST_DEBUG_FUNCPTR (gst_audio_amplify_set_caps);
GST_AUDIO_FILTER_CLASS (klass)->setup =
GST_DEBUG_FUNCPTR (gst_audio_amplify_setup);
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip =
GST_DEBUG_FUNCPTR (gst_audio_amplify_transform_ip);
}
@ -227,24 +217,22 @@ gst_audio_amplify_init (GstAudioAmplify * filter, GstAudioAmplifyClass * klass)
filter->amplification = 1.0;
filter->clipping_method = METHOD_CLIP;
filter->width = 0;
filter->format_float = FALSE;
filter->format_index = 0;
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
}
static gboolean
gst_audio_amplify_set_process_function (GstAudioAmplify * filter)
{
gint format_index, method_index;
gint method_index;
/* set processing function */
format_index = (filter->format_float) ? 1 : 0;
method_index = filter->clipping_method;
if (method_index >= NUM_METHODS || method_index < 0)
method_index = METHOD_CLIP;
filter->process = processing_functions[format_index][method_index];
filter->process = processing_functions[filter->format_index][method_index];
return TRUE;
}
@ -289,43 +277,30 @@ gst_audio_amplify_get_property (GObject * object, guint prop_id,
}
}
/* GstBaseTransform vmethod implementations */
/* GstAudioFilter vmethod implementations */
static gboolean
gst_audio_amplify_set_caps (GstBaseTransform * base, GstCaps * incaps,
GstCaps * outcaps)
gst_audio_amplify_setup (GstAudioFilter * base, GstRingBufferSpec * format)
{
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (base);
const GstStructure *structure;
gboolean ret;
gint width;
const gchar *fmt;
/*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
filter->width = format->width / 8;
structure = gst_caps_get_structure (incaps, 0);
ret = gst_structure_get_int (structure, "width", &width);
if (!ret)
goto no_width;
filter->width = width / 8;
fmt = gst_structure_get_name (structure);
if (!strcmp (fmt, "audio/x-raw-int"))
filter->format_float = FALSE;
if (format->type == GST_BUFTYPE_LINEAR && format->width == 16)
filter->format_index = 0;
else if (format->type == GST_BUFTYPE_FLOAT && format->width == 32)
filter->format_index = 1;
else
filter->format_float = TRUE;
goto wrong_format;
GST_DEBUG ("try to process %s input", fmt);
ret = gst_audio_amplify_set_process_function (filter);
if (!ret)
GST_WARNING ("can't process input");
return TRUE;
return ret;
no_width:
GST_DEBUG ("no width in caps");
wrong_format:
GST_DEBUG ("wrong format");
return FALSE;
}
@ -434,8 +409,7 @@ gst_audio_amplify_transform_float_wrap_positive (GstAudioAmplify * filter,
}
}
/* this function does the actual processing
*/
/* GstBaseTransform vmethod implementations */
static GstFlowReturn
gst_audio_amplify_transform_ip (GstBaseTransform * base, GstBuffer * buf)
{

View file

@ -24,6 +24,8 @@
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiofilter.h>
G_BEGIN_DECLS
#define GST_TYPE_AUDIO_AMPLIFY (gst_audio_amplify_get_type())
@ -39,7 +41,7 @@ typedef void (*GstAudioAmplifyProcessFunc) (GstAudioAmplify *, guint8 *, guint);
struct _GstAudioAmplify
{
GstBaseTransform element;
GstAudioFilter audiofilter;
gfloat amplification;
@ -47,12 +49,12 @@ struct _GstAudioAmplify
GstAudioAmplifyProcessFunc process;
gint clipping_method;
gint width;
gboolean format_float;
gint format_index;
};
struct _GstAudioAmplifyClass
{
GstBaseTransformClass parent;
GstAudioFilterClass parent;
};
GType gst_audio_amplify_get_type (void);

View file

@ -44,6 +44,8 @@
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiofilter.h>
#include <gst/controller/gstcontroller.h>
#include "audioinvert.h"
@ -70,47 +72,33 @@ enum
PROP_DEGREE
};
static GstStaticPadTemplate 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; "
"audio/x-raw-int, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) BYTE_ORDER, "
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
);
static GstStaticPadTemplate 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; "
"audio/x-raw-int, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) BYTE_ORDER, "
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
);
#define ALLOWED_CAPS \
"audio/x-raw-int," \
" depth=(int)16," \
" width=(int)16," \
" endianness=(int)BYTE_ORDER," \
" signed=(bool)TRUE," \
" rate=(int)[1,MAX]," \
" channels=(int)[1,MAX]; " \
"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_audio_invert_debug, "audioinvert", 0, "audioinvert element");
GST_BOILERPLATE_FULL (GstAudioInvert, gst_audio_invert, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
GST_BOILERPLATE_FULL (GstAudioInvert, gst_audio_invert, GstAudioFilter,
GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
static void gst_audio_invert_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_audio_invert_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_audio_invert_set_caps (GstBaseTransform * base,
GstCaps * incaps, GstCaps * outcaps);
static gboolean gst_audio_invert_setup (GstAudioFilter * filter,
GstRingBufferSpec * format);
static GstFlowReturn gst_audio_invert_transform_ip (GstBaseTransform * base,
GstBuffer * buf);
@ -125,12 +113,14 @@ static void
gst_audio_invert_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstCaps *caps;
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
gst_element_class_set_details (element_class, &element_details);
caps = gst_caps_from_string (ALLOWED_CAPS);
gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (klass),
caps);
gst_caps_unref (caps);
}
static void
@ -147,8 +137,8 @@ gst_audio_invert_class_init (GstAudioInvertClass * klass)
"Degree of inversion", 0.0, 1.0,
0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
GST_DEBUG_FUNCPTR (gst_audio_invert_set_caps);
GST_AUDIO_FILTER_CLASS (klass)->setup =
GST_DEBUG_FUNCPTR (gst_audio_invert_setup);
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip =
GST_DEBUG_FUNCPTR (gst_audio_invert_transform_ip);
}
@ -195,41 +185,26 @@ gst_audio_invert_get_property (GObject * object, guint prop_id,
}
}
/* GstBaseTransform vmethod implementations */
/* GstAudioFilter vmethod implementations */
static gboolean
gst_audio_invert_set_caps (GstBaseTransform * base, GstCaps * incaps,
GstCaps * outcaps)
gst_audio_invert_setup (GstAudioFilter * base, GstRingBufferSpec * format)
{
GstAudioInvert *filter = GST_AUDIO_INVERT (base);
const GstStructure *structure;
gboolean ret;
gint width;
const gchar *fmt;
gboolean ret = TRUE;
/*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
structure = gst_caps_get_structure (incaps, 0);
ret = gst_structure_get_int (structure, "width", &width);
if (!ret)
goto no_width;
filter->width = width / 8;
fmt = gst_structure_get_name (structure);
if (!strcmp (fmt, "audio/x-raw-int"))
if (format->type == GST_BUFTYPE_FLOAT && format->width == 32)
filter->process = (GstAudioInvertProcessFunc)
gst_audio_invert_transform_float;
else if (format->type == GST_BUFTYPE_LINEAR && format->width == 16)
filter->process = (GstAudioInvertProcessFunc)
gst_audio_invert_transform_int;
else
filter->process = (GstAudioInvertProcessFunc)
gst_audio_invert_transform_float;
ret = FALSE;
return TRUE;
filter->width = format->width / 8;
no_width:
GST_DEBUG ("no width in caps");
return FALSE;
return ret;
}
static void
@ -260,9 +235,7 @@ gst_audio_invert_transform_float (GstAudioInvert * filter,
}
}
/* this function does the actual processing
*/
/* GstBaseTransform vmethod implementations */
static GstFlowReturn
gst_audio_invert_transform_ip (GstBaseTransform * base, GstBuffer * buf)
{

View file

@ -24,37 +24,38 @@
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiofilter.h>
G_BEGIN_DECLS
#define GST_TYPE_AUDIO_INVERT (gst_audio_invert_get_type())
#define GST_AUDIO_INVERT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_INVERT,GstAudioInvert))
#define GST_IS_AUDIO_INVERT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_INVERT))
#define GST_AUDIO_INVERT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_AUDIO_INVERT,GstAudioInvertClass))
#define GST_IS_AUDIO_INVERT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_AUDIO_INVERT))
#define GST_AUDIO_INVERT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_AUDIO_INVERT,GstAudioInvertClass))
typedef struct _GstAudioInvert GstAudioInvert;
typedef struct _GstAudioInvert GstAudioInvert;
typedef struct _GstAudioInvertClass GstAudioInvertClass;
typedef void (*GstAudioInvertProcessFunc)(GstAudioInvert*, guint8*, guint);
typedef void (*GstAudioInvertProcessFunc) (GstAudioInvert *, guint8 *, guint);
struct _GstAudioInvert {
GstBaseTransform element;
struct _GstAudioInvert
{
GstAudioFilter audiofilter;
gfloat degree;
/* < private > */
GstAudioInvertProcessFunc process;
gint width;
};
struct _GstAudioInvertClass {
GstBaseTransformClass parent;
struct _GstAudioInvertClass
{
GstAudioFilterClass parent;
};
GType gst_audio_invert_get_type (void);
G_END_DECLS
#endif /* __GST_AUDIO_INVERT_H__ */