gst/volume/: Use GstAudioFilter as base class for the volume element instead of plain GstBaseTransform.
Original commit message from CVS: * gst/volume/Makefile.am: * gst/volume/gstvolume.c: (volume_choose_func), (gst_volume_base_init), (gst_volume_class_init), (gst_volume_init), (volume_setup): * gst/volume/gstvolume.h: Use GstAudioFilter as base class for the volume element instead of plain GstBaseTransform.
This commit is contained in:
parent
a000758477
commit
3ac84ec4ff
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2008-01-03 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
|
* gst/volume/Makefile.am:
|
||||||
|
* gst/volume/gstvolume.c: (volume_choose_func),
|
||||||
|
(gst_volume_base_init), (gst_volume_class_init), (gst_volume_init),
|
||||||
|
(volume_setup):
|
||||||
|
* gst/volume/gstvolume.h:
|
||||||
|
Use GstAudioFilter as base class for the volume element instead of
|
||||||
|
plain GstBaseTransform.
|
||||||
|
|
||||||
2008-01-03 Sebastian Dröge <slomo@circular-chaos.org>
|
2008-01-03 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
* gst-libs/gst/audio/gstaudiofilter.c: (gst_audio_filter_get_type):
|
* gst-libs/gst/audio/gstaudiofilter.c: (gst_audio_filter_get_type):
|
||||||
|
@ -5,6 +5,7 @@ libgstvolume_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CON
|
|||||||
libgstvolume_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
libgstvolume_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
libgstvolume_la_LIBADD = \
|
libgstvolume_la_LIBADD = \
|
||||||
$(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \
|
$(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \
|
||||||
|
$(top_builddir)/gst-libs/gst/audio/libgstaudio-$(GST_MAJORMINOR).la \
|
||||||
$(GST_BASE_LIBS) \
|
$(GST_BASE_LIBS) \
|
||||||
$(GST_CONTROLLER_LIBS) \
|
$(GST_CONTROLLER_LIBS) \
|
||||||
$(GST_LIBS) \
|
$(GST_LIBS) \
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
#include <gst/audio/audio.h>
|
#include <gst/audio/audio.h>
|
||||||
#include <gst/interfaces/mixer.h>
|
#include <gst/interfaces/mixer.h>
|
||||||
#include <gst/controller/gstcontroller.h>
|
#include <gst/controller/gstcontroller.h>
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
|
#include <gst/audio/gstaudiofilter.h>
|
||||||
#include <liboil/liboil.h>
|
#include <liboil/liboil.h>
|
||||||
|
|
||||||
#include "gstvolume.h"
|
#include "gstvolume.h"
|
||||||
@ -102,79 +104,40 @@ enum
|
|||||||
PROP_VOLUME
|
PROP_VOLUME
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstStaticPadTemplate volume_sink_template =
|
#define ALLOWED_CAPS \
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
"audio/x-raw-float, " \
|
||||||
GST_PAD_SINK,
|
"rate = (int) [ 1, MAX ], " \
|
||||||
GST_PAD_ALWAYS,
|
"channels = (int) [ 1, MAX ], " \
|
||||||
GST_STATIC_CAPS ("audio/x-raw-float, "
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"rate = (int) [ 1, MAX ], "
|
"width = (int) {32, 64}; " \
|
||||||
"channels = (int) [ 1, MAX ], "
|
"audio/x-raw-int, " \
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"channels = (int) [ 1, MAX ], " \
|
||||||
"width = (int) {32, 64}; "
|
"rate = (int) [ 1, MAX ], " \
|
||||||
"audio/x-raw-int, "
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"channels = (int) [ 1, MAX ], "
|
"width = (int) 8, " \
|
||||||
"rate = (int) [ 1, MAX ], "
|
"depth = (int) 8, " \
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"signed = (bool) TRUE; " \
|
||||||
"width = (int) 8, "
|
"audio/x-raw-int, " \
|
||||||
"depth = (int) 8, "
|
"channels = (int) [ 1, MAX ], " \
|
||||||
"signed = (bool) TRUE; "
|
"rate = (int) [ 1, MAX ], " \
|
||||||
"audio/x-raw-int, "
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"channels = (int) [ 1, MAX ], "
|
"width = (int) 16, " \
|
||||||
"rate = (int) [ 1, MAX ], "
|
"depth = (int) 16, " \
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"signed = (bool) TRUE; " \
|
||||||
"width = (int) 16, "
|
"audio/x-raw-int, " \
|
||||||
"depth = (int) 16, "
|
"channels = (int) [ 1, MAX ], " \
|
||||||
"signed = (bool) TRUE; "
|
"rate = (int) [ 1, MAX ], " \
|
||||||
"audio/x-raw-int, "
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"channels = (int) [ 1, MAX ], "
|
"width = (int) 24, " \
|
||||||
"rate = (int) [ 1, MAX ], "
|
"depth = (int) 24, " \
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"signed = (bool) TRUE; " \
|
||||||
"width = (int) 24, "
|
"audio/x-raw-int, " \
|
||||||
"depth = (int) 24, "
|
"channels = (int) [ 1, MAX ], " \
|
||||||
"signed = (bool) TRUE; "
|
"rate = (int) [ 1, MAX ], " \
|
||||||
"audio/x-raw-int, "
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"channels = (int) [ 1, MAX ], "
|
"width = (int) 32, " \
|
||||||
"rate = (int) [ 1, MAX ], "
|
"depth = (int) 32, " \
|
||||||
"endianness = (int) BYTE_ORDER, "
|
"signed = (bool) TRUE"
|
||||||
"width = (int) 32, " "depth = (int) 32, " "signed = (bool) TRUE")
|
|
||||||
);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate volume_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, 64}; "
|
|
||||||
"audio/x-raw-int, "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) BYTE_ORDER, "
|
|
||||||
"width = (int) 8, "
|
|
||||||
"depth = (int) 8, "
|
|
||||||
"signed = (bool) TRUE; "
|
|
||||||
"audio/x-raw-int, "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) BYTE_ORDER, "
|
|
||||||
"width = (int) 16, "
|
|
||||||
"depth = (int) 16, "
|
|
||||||
"signed = (bool) TRUE; "
|
|
||||||
"audio/x-raw-int, "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) BYTE_ORDER, "
|
|
||||||
"width = (int) 24, "
|
|
||||||
"depth = (int) 24, "
|
|
||||||
"signed = (bool) TRUE; "
|
|
||||||
"audio/x-raw-int, "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) BYTE_ORDER, "
|
|
||||||
"width = (int) 32, " "depth = (int) 32, " "signed = (bool) TRUE")
|
|
||||||
);
|
|
||||||
|
|
||||||
static void gst_volume_interface_init (GstImplementsInterfaceClass * klass);
|
static void gst_volume_interface_init (GstImplementsInterfaceClass * klass);
|
||||||
static void gst_volume_mixer_init (GstMixerClass * iface);
|
static void gst_volume_mixer_init (GstMixerClass * iface);
|
||||||
@ -197,8 +160,8 @@ static void gst_volume_mixer_init (GstMixerClass * iface);
|
|||||||
g_type_add_interface_static (type, GST_TYPE_MIXER, &volmixer_info); \
|
g_type_add_interface_static (type, GST_TYPE_MIXER, &volmixer_info); \
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_BOILERPLATE_FULL (GstVolume, gst_volume, GstBaseTransform,
|
GST_BOILERPLATE_FULL (GstVolume, gst_volume, GstAudioFilter,
|
||||||
GST_TYPE_BASE_TRANSFORM, _init_interfaces);
|
GST_TYPE_AUDIO_FILTER, _init_interfaces);
|
||||||
|
|
||||||
static void volume_set_property (GObject * object, guint prop_id,
|
static void volume_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
@ -209,8 +172,8 @@ static void volume_update_mute (const GValue * value, gpointer data);
|
|||||||
|
|
||||||
static GstFlowReturn volume_transform_ip (GstBaseTransform * base,
|
static GstFlowReturn volume_transform_ip (GstBaseTransform * base,
|
||||||
GstBuffer * outbuf);
|
GstBuffer * outbuf);
|
||||||
static gboolean volume_set_caps (GstBaseTransform * base, GstCaps * incaps,
|
static gboolean volume_setup (GstAudioFilter * filter,
|
||||||
GstCaps * outcaps);
|
GstRingBufferSpec * format);
|
||||||
|
|
||||||
static void volume_process_double (GstVolume * this, gpointer bytes,
|
static void volume_process_double (GstVolume * this, gpointer bytes,
|
||||||
guint n_bytes);
|
guint n_bytes);
|
||||||
@ -236,13 +199,17 @@ static void volume_process_int8_clamp (GstVolume * this, gpointer bytes,
|
|||||||
|
|
||||||
/* helper functions */
|
/* helper functions */
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
volume_choose_func (GstVolume * this)
|
volume_choose_func (GstVolume * this)
|
||||||
{
|
{
|
||||||
this->process = NULL;
|
this->process = NULL;
|
||||||
switch (this->format) {
|
|
||||||
case GST_VOLUME_FORMAT_INT:
|
if (GST_AUDIO_FILTER (this)->format.caps == NULL)
|
||||||
switch (this->width) {
|
return FALSE;
|
||||||
|
|
||||||
|
switch (GST_AUDIO_FILTER (this)->format.type) {
|
||||||
|
case GST_BUFTYPE_LINEAR:
|
||||||
|
switch (GST_AUDIO_FILTER (this)->format.width) {
|
||||||
case 32:
|
case 32:
|
||||||
/* only clamp if the gain is greater than 1.0
|
/* only clamp if the gain is greater than 1.0
|
||||||
* FIXME: real_vol_i can change while processing the buffer!
|
* FIXME: real_vol_i can change while processing the buffer!
|
||||||
@ -281,8 +248,8 @@ volume_choose_func (GstVolume * this)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GST_VOLUME_FORMAT_FLOAT:
|
case GST_BUFTYPE_FLOAT:
|
||||||
switch (this->width) {
|
switch (GST_AUDIO_FILTER (this)->format.width) {
|
||||||
case 32:
|
case 32:
|
||||||
this->process = volume_process_float;
|
this->process = volume_process_float;
|
||||||
break;
|
break;
|
||||||
@ -294,6 +261,8 @@ volume_choose_func (GstVolume * this)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (this->process != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -419,12 +388,14 @@ static void
|
|||||||
gst_volume_base_init (gpointer g_class)
|
gst_volume_base_init (gpointer g_class)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||||
|
GstAudioFilterClass *filter_class = GST_AUDIO_FILTER_CLASS (g_class);
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&volume_src_template));
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&volume_sink_template));
|
|
||||||
gst_element_class_set_details (element_class, &volume_details);
|
gst_element_class_set_details (element_class, &volume_details);
|
||||||
|
|
||||||
|
caps = gst_caps_from_string (ALLOWED_CAPS);
|
||||||
|
gst_audio_filter_class_add_pad_templates (filter_class, caps);
|
||||||
|
gst_caps_unref (caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -432,9 +403,11 @@ gst_volume_class_init (GstVolumeClass * klass)
|
|||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstBaseTransformClass *trans_class;
|
GstBaseTransformClass *trans_class;
|
||||||
|
GstAudioFilterClass *filter_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
trans_class = (GstBaseTransformClass *) klass;
|
trans_class = (GstBaseTransformClass *) klass;
|
||||||
|
filter_class = (GstAudioFilterClass *) (klass);
|
||||||
|
|
||||||
gobject_class->set_property = volume_set_property;
|
gobject_class->set_property = volume_set_property;
|
||||||
gobject_class->get_property = volume_get_property;
|
gobject_class->get_property = volume_get_property;
|
||||||
@ -452,7 +425,7 @@ gst_volume_class_init (GstVolumeClass * klass)
|
|||||||
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "volume", 0, "Volume gain");
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "volume", 0, "Volume gain");
|
||||||
|
|
||||||
trans_class->transform_ip = GST_DEBUG_FUNCPTR (volume_transform_ip);
|
trans_class->transform_ip = GST_DEBUG_FUNCPTR (volume_transform_ip);
|
||||||
trans_class->set_caps = GST_DEBUG_FUNCPTR (volume_set_caps);
|
filter_class->setup = GST_DEBUG_FUNCPTR (volume_setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -467,7 +440,6 @@ gst_volume_init (GstVolume * this, GstVolumeClass * g_class)
|
|||||||
this->volume_i32 = this->real_vol_i32 = VOLUME_UNITY_INT32;
|
this->volume_i32 = this->real_vol_i32 = VOLUME_UNITY_INT32;
|
||||||
this->volume_f = this->real_vol_f = 1.0;
|
this->volume_f = this->real_vol_f = 1.0;
|
||||||
this->tracklist = NULL;
|
this->tracklist = NULL;
|
||||||
this->format = GST_VOLUME_FORMAT_NONE;
|
|
||||||
|
|
||||||
track = g_object_new (GST_TYPE_MIXER_TRACK, NULL);
|
track = g_object_new (GST_TYPE_MIXER_TRACK, NULL);
|
||||||
|
|
||||||
@ -690,39 +662,15 @@ volume_process_int8_clamp (GstVolume * this, gpointer bytes, guint n_bytes)
|
|||||||
|
|
||||||
/* get notified of caps and plug in the correct process function */
|
/* get notified of caps and plug in the correct process function */
|
||||||
static gboolean
|
static gboolean
|
||||||
volume_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
|
volume_setup (GstAudioFilter * filter, GstRingBufferSpec * format)
|
||||||
{
|
{
|
||||||
GstVolume *this = GST_VOLUME (base);
|
GstVolume *this = GST_VOLUME (filter);
|
||||||
const gchar *mimetype;
|
|
||||||
GstStructure *structure;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (this,
|
|
||||||
"set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
|
|
||||||
|
|
||||||
structure = gst_caps_get_structure (incaps, 0);
|
|
||||||
gst_structure_get_int (structure, "width", &this->width);
|
|
||||||
mimetype = gst_structure_get_name (structure);
|
|
||||||
|
|
||||||
/* based on mimetype, choose the correct volume_process format */
|
|
||||||
if (strcmp (mimetype, "audio/x-raw-int") == 0) {
|
|
||||||
this->format = GST_VOLUME_FORMAT_INT;
|
|
||||||
GST_DEBUG_OBJECT (this, "use int: %u", this->width);
|
|
||||||
} else if (strcmp (mimetype, "audio/x-raw-float") == 0) {
|
|
||||||
this->format = GST_VOLUME_FORMAT_FLOAT;
|
|
||||||
GST_DEBUG_OBJECT (this, "use float: %u", this->width);
|
|
||||||
} else {
|
|
||||||
this->process = NULL;
|
|
||||||
goto invalid_format;
|
|
||||||
}
|
|
||||||
volume_choose_func (this);
|
|
||||||
|
|
||||||
|
if (volume_choose_func (this)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
} else {
|
||||||
/* ERRORS */
|
|
||||||
invalid_format:
|
|
||||||
{
|
|
||||||
GST_ELEMENT_ERROR (this, CORE, NEGOTIATION,
|
GST_ELEMENT_ERROR (this, CORE, NEGOTIATION,
|
||||||
("Invalid incoming caps: %" GST_PTR_FORMAT, incaps), (NULL));
|
("Invalid incoming format"), (NULL));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
#include <gst/base/gstbasetransform.h>
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
|
#include <gst/audio/gstaudiofilter.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -42,19 +44,13 @@ G_BEGIN_DECLS
|
|||||||
typedef struct _GstVolume GstVolume;
|
typedef struct _GstVolume GstVolume;
|
||||||
typedef struct _GstVolumeClass GstVolumeClass;
|
typedef struct _GstVolumeClass GstVolumeClass;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GST_VOLUME_FORMAT_NONE,
|
|
||||||
GST_VOLUME_FORMAT_INT,
|
|
||||||
GST_VOLUME_FORMAT_FLOAT
|
|
||||||
} GstVolumeFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstVolume:
|
* GstVolume:
|
||||||
*
|
*
|
||||||
* Opaque data structure.
|
* Opaque data structure.
|
||||||
*/
|
*/
|
||||||
struct _GstVolume {
|
struct _GstVolume {
|
||||||
GstBaseTransform element;
|
GstAudioFilter element;
|
||||||
|
|
||||||
void (*process)(GstVolume*, gpointer, guint);
|
void (*process)(GstVolume*, gpointer, guint);
|
||||||
|
|
||||||
@ -66,13 +62,11 @@ struct _GstVolume {
|
|||||||
gfloat volume_f, real_vol_f; /* _f(loat) values on each update */
|
gfloat volume_f, real_vol_f; /* _f(loat) values on each update */
|
||||||
|
|
||||||
GList *tracklist;
|
GList *tracklist;
|
||||||
GstVolumeFormat format; /* caps variables */
|
|
||||||
gint width;
|
|
||||||
gboolean silent_buffer; /* flag for silent buffers */
|
gboolean silent_buffer; /* flag for silent buffers */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstVolumeClass {
|
struct _GstVolumeClass {
|
||||||
GstBaseTransformClass parent_class;
|
GstAudioFilterClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_volume_get_type (void);
|
GType gst_volume_get_type (void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user