mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-03 09:12:19 +00:00
just some code cleanup
Original commit message from CVS: just some code cleanup
This commit is contained in:
parent
d95362aab5
commit
69edaac422
2 changed files with 67 additions and 106 deletions
|
@ -19,15 +19,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gst/gst.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <gst/gst.h>
|
||||||
#include <gst/audio/audio.h>
|
#include <gst/audio/audio.h>
|
||||||
|
|
||||||
#include "gstspeed.h"
|
#include "gstspeed.h"
|
||||||
|
|
||||||
/* buffer size to make if no bufferpool is available, must be divisible by
|
/* buffer size to make if no bufferpool is available, must be divisible by
|
||||||
* sizeof(gfloat) */
|
* sizeof(gfloat) */
|
||||||
#define SPEED_BUFSIZE 4096
|
#define SPEED_BUFSIZE 4096
|
||||||
/* number of buffers to allocate per chunk in sink buffer pool */
|
/* number of buffers to allocate per chunk in sink buffer pool */
|
||||||
|
@ -53,41 +55,40 @@ enum {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ARG_0,
|
ARG_0,
|
||||||
ARG_SILENT,
|
|
||||||
ARG_SPEED
|
ARG_SPEED
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstPadTemplate*
|
static GstPadTemplate*
|
||||||
speed_sink_factory (void)
|
speed_sink_factory (void)
|
||||||
{
|
{
|
||||||
static GstPadTemplate *template = NULL;
|
static GstPadTemplate *template = NULL;
|
||||||
|
|
||||||
if (!template) {
|
if (!template) {
|
||||||
template = gst_pad_template_new
|
template = gst_pad_template_new
|
||||||
("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||||
gst_caps_append(gst_caps_new ("sink_int", "audio/x-raw-int",
|
gst_caps_append(gst_caps_new ("sink_int", "audio/x-raw-int",
|
||||||
GST_AUDIO_INT_MONO_PAD_TEMPLATE_PROPS),
|
GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_PROPS),
|
||||||
gst_caps_new ("sink_float", "audio/x-raw-float",
|
gst_caps_new ("sink_float", "audio/x-raw-float",
|
||||||
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_PROPS)),
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_PROPS)),
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstPadTemplate*
|
static GstPadTemplate*
|
||||||
speed_src_factory (void)
|
speed_src_factory (void)
|
||||||
{
|
{
|
||||||
static GstPadTemplate *template = NULL;
|
static GstPadTemplate *template = NULL;
|
||||||
|
|
||||||
if (!template)
|
if (!template)
|
||||||
template = gst_pad_template_new
|
template = gst_pad_template_new
|
||||||
("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||||
gst_caps_append (gst_caps_new ("src_float", "audio/x-raw-float",
|
gst_caps_append (gst_caps_new ("src_float", "audio/x-raw-float",
|
||||||
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_PROPS),
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_PROPS),
|
||||||
gst_caps_new ("src_int", "audio/x-raw-int",
|
gst_caps_new ("src_int", "audio/x-raw-int",
|
||||||
GST_AUDIO_INT_MONO_PAD_TEMPLATE_PROPS)),
|
GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_PROPS)),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ static GstBufferPool*
|
||||||
speed_sink_get_bufferpool (GstPad *pad)
|
speed_sink_get_bufferpool (GstPad *pad)
|
||||||
{
|
{
|
||||||
GstSpeed *filter;
|
GstSpeed *filter;
|
||||||
|
|
||||||
filter = GST_SPEED (gst_pad_get_parent(pad));
|
filter = GST_SPEED (gst_pad_get_parent(pad));
|
||||||
|
|
||||||
return filter->sinkpool;
|
return filter->sinkpool;
|
||||||
|
@ -115,23 +116,22 @@ static GstElementClass *parent_class = NULL;
|
||||||
/*static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
|
/*static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
|
||||||
|
|
||||||
static GstPadLinkReturn
|
static GstPadLinkReturn
|
||||||
speed_connect (GstPad *pad, GstCaps *caps)
|
speed_link (GstPad *pad, GstCaps *caps)
|
||||||
{
|
{
|
||||||
GstSpeed *filter;
|
GstSpeed *filter;
|
||||||
GstPad *otherpad;
|
GstPad *otherpad;
|
||||||
|
|
||||||
filter = GST_SPEED (gst_pad_get_parent (pad));
|
filter = GST_SPEED (gst_pad_get_parent (pad));
|
||||||
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
||||||
g_return_val_if_fail (GST_IS_SPEED (filter), GST_PAD_LINK_REFUSED);
|
g_return_val_if_fail (GST_IS_SPEED (filter), GST_PAD_LINK_REFUSED);
|
||||||
otherpad = (pad == filter->srcpad ? filter->sinkpad : filter->srcpad);
|
otherpad = (pad == filter->srcpad ? filter->sinkpad : filter->srcpad);
|
||||||
|
|
||||||
if (GST_CAPS_IS_FIXED (caps)) {
|
if (GST_CAPS_IS_FIXED (caps)) {
|
||||||
if (!speed_parse_caps (filter, caps))
|
if (! speed_parse_caps (filter, caps)) return GST_PAD_LINK_REFUSED;
|
||||||
return GST_PAD_LINK_REFUSED;
|
|
||||||
|
|
||||||
return gst_pad_try_set_caps(otherpad, caps);
|
return gst_pad_try_set_caps(otherpad, caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GST_PAD_LINK_DELAYED;
|
return GST_PAD_LINK_DELAYED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,36 +139,24 @@ static gboolean
|
||||||
speed_parse_caps (GstSpeed *filter, GstCaps *caps)
|
speed_parse_caps (GstSpeed *filter, GstCaps *caps)
|
||||||
{
|
{
|
||||||
const gchar *mimetype;
|
const gchar *mimetype;
|
||||||
|
|
||||||
g_return_val_if_fail(filter!=NULL,-1);
|
|
||||||
g_return_val_if_fail(caps!=NULL,-1);
|
|
||||||
|
|
||||||
mimetype = gst_caps_get_mime (caps);
|
g_return_val_if_fail(filter != NULL, FALSE);
|
||||||
|
g_return_val_if_fail(caps != NULL, FALSE);
|
||||||
|
|
||||||
gst_caps_get_int (caps, "rate", &filter->rate);
|
gst_caps_get_int (caps, "rate", &filter->rate);
|
||||||
gst_caps_get_int (caps, "channels", &filter->channels);
|
gst_caps_get_int (caps, "channels", &filter->channels);
|
||||||
gst_caps_get_int (caps, "width", &filter->width);
|
gst_caps_get_int (caps, "width", &filter->width);
|
||||||
gst_caps_get_int (caps, "endianness", &filter->endianness);
|
gst_caps_get_int (caps, "endianness", &filter->endianness);
|
||||||
|
gst_caps_get_int (caps, "buffer-frames", &filter->buffer_frames);
|
||||||
|
|
||||||
if (strcmp(mimetype, "audio/x-raw-int")==0) {
|
mimetype = gst_caps_get_mime (caps);
|
||||||
|
|
||||||
|
if (! strncmp(mimetype, "audio/x-raw-int", 15)) {
|
||||||
filter->format = GST_SPEED_FORMAT_INT;
|
filter->format = GST_SPEED_FORMAT_INT;
|
||||||
gst_caps_get_int (caps, "depth", &filter->depth);
|
gst_caps_get_int (caps, "depth", &filter->depth);
|
||||||
gst_caps_get_boolean (caps, "signed", &filter->is_signed);
|
gst_caps_get_boolean (caps, "signed", &filter->is_signed);
|
||||||
|
} else if (! strncmp(mimetype, "audio/x-raw-float", 17)) {
|
||||||
if (!filter->silent) {
|
|
||||||
g_print ("Speed : channels %d, rate %d\n",
|
|
||||||
filter->channels, filter->rate);
|
|
||||||
g_print ("Speed : format int, bit width %d, endianness %d, signed %s\n",
|
|
||||||
filter->width, filter->endianness, filter->is_signed ? "yes" : "no");
|
|
||||||
}
|
|
||||||
} else if (strcmp(mimetype, "audio/x-raw-float")==0) {
|
|
||||||
filter->format = GST_SPEED_FORMAT_FLOAT;
|
filter->format = GST_SPEED_FORMAT_FLOAT;
|
||||||
|
|
||||||
if (!filter->silent) {
|
|
||||||
g_print ("Speed : channels %d, rate %d\n",
|
|
||||||
filter->channels, filter->rate);
|
|
||||||
g_print ("Speed : format float, width %d\n", filter->width);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -199,43 +187,33 @@ gst_speed_get_type(void) {
|
||||||
static void
|
static void
|
||||||
speed_class_init (GstSpeedClass *klass)
|
speed_class_init (GstSpeedClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class = (GObjectClass*)klass;
|
||||||
GstElementClass *gstelement_class;
|
|
||||||
|
|
||||||
gobject_class = (GObjectClass*)klass;
|
|
||||||
gstelement_class = (GstElementClass*)klass;
|
|
||||||
|
|
||||||
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
||||||
|
|
||||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT,
|
|
||||||
g_param_spec_boolean("silent","silent","silent",
|
|
||||||
TRUE,G_PARAM_READWRITE)); /* CHECKME */
|
|
||||||
|
|
||||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SPEED,
|
|
||||||
g_param_spec_float("speed","speed","speed",
|
|
||||||
0.1,40.0,1.0,G_PARAM_READWRITE));
|
|
||||||
|
|
||||||
gobject_class->set_property = speed_set_property;
|
gobject_class->set_property = speed_set_property;
|
||||||
gobject_class->get_property = speed_get_property;
|
gobject_class->get_property = speed_get_property;
|
||||||
|
|
||||||
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SPEED,
|
||||||
|
g_param_spec_float("speed","speed","speed",
|
||||||
|
0.1,40.0,1.0,G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
speed_init (GstSpeed *filter)
|
speed_init (GstSpeed *filter)
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_template(speed_sink_factory (),"sink");
|
filter->sinkpad = gst_pad_new_from_template(speed_sink_factory (), "sink");
|
||||||
gst_pad_set_link_function(filter->sinkpad,speed_connect);
|
gst_pad_set_link_function(filter->sinkpad, speed_link);
|
||||||
gst_pad_set_bufferpool_function (filter->sinkpad, speed_sink_get_bufferpool);
|
|
||||||
filter->srcpad = gst_pad_new_from_template(speed_src_factory (),"src");
|
|
||||||
gst_pad_set_link_function(filter->srcpad,speed_connect);
|
|
||||||
|
|
||||||
gst_element_add_pad(GST_ELEMENT(filter),filter->sinkpad);
|
gst_element_add_pad(GST_ELEMENT(filter),filter->sinkpad);
|
||||||
|
gst_pad_set_bufferpool_function (filter->sinkpad, speed_sink_get_bufferpool);
|
||||||
|
|
||||||
|
filter->srcpad = gst_pad_new_from_template(speed_src_factory (), "src");
|
||||||
|
gst_pad_set_link_function(filter->srcpad, speed_link);
|
||||||
gst_element_add_pad(GST_ELEMENT(filter),filter->srcpad);
|
gst_element_add_pad(GST_ELEMENT(filter),filter->srcpad);
|
||||||
|
|
||||||
gst_element_set_loop_function(GST_ELEMENT(filter),speed_loop);
|
gst_element_set_loop_function(GST_ELEMENT(filter),speed_loop);
|
||||||
filter->silent = FALSE;
|
|
||||||
filter->speed = 1.0;
|
filter->sinkpool = gst_buffer_pool_get_default(SPEED_BUFSIZE, SPEED_NUMBUF);
|
||||||
|
|
||||||
filter->sinkpool = gst_buffer_pool_get_default(SPEED_BUFSIZE,
|
|
||||||
SPEED_NUMBUF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -245,21 +223,21 @@ speed_loop (GstElement *element)
|
||||||
GstBuffer *in, *out;
|
GstBuffer *in, *out;
|
||||||
guint i, j, nin, nout;
|
guint i, j, nin, nout;
|
||||||
gfloat interp, speed, lower, i_float;
|
gfloat interp, speed, lower, i_float;
|
||||||
|
|
||||||
g_return_if_fail(filter != NULL);
|
g_return_if_fail(filter != NULL);
|
||||||
g_return_if_fail(GST_IS_SPEED(filter));
|
g_return_if_fail(GST_IS_SPEED(filter));
|
||||||
|
|
||||||
filter->srcpool = gst_pad_get_bufferpool(filter->srcpad);
|
filter->srcpool = gst_pad_get_bufferpool(filter->srcpad);
|
||||||
|
|
||||||
i = j = 0;
|
i = j = 0;
|
||||||
speed = filter->speed;
|
speed = filter->speed;
|
||||||
|
|
||||||
in = gst_pad_pull(filter->sinkpad);
|
in = gst_pad_pull(filter->sinkpad);
|
||||||
if (GST_IS_EVENT (in)) {
|
if (GST_IS_EVENT (in)) {
|
||||||
gst_pad_event_default (filter->sinkpad, GST_EVENT (in));
|
gst_pad_event_default (filter->sinkpad, GST_EVENT (in));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (GST_IS_EVENT (in)) {
|
while (GST_IS_EVENT (in)) {
|
||||||
gst_pad_event_default (filter->srcpad, GST_EVENT (in));
|
gst_pad_event_default (filter->srcpad, GST_EVENT (in));
|
||||||
in = gst_pad_pull (filter->sinkpad);
|
in = gst_pad_pull (filter->sinkpad);
|
||||||
|
@ -294,11 +272,8 @@ speed_set_property (GObject *object, guint prop_id, const GValue *value, GParamS
|
||||||
g_return_if_fail(GST_IS_SPEED(object));
|
g_return_if_fail(GST_IS_SPEED(object));
|
||||||
filter = GST_SPEED(object);
|
filter = GST_SPEED(object);
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case ARG_SILENT:
|
|
||||||
filter->silent = g_value_get_boolean (value);
|
|
||||||
break;
|
|
||||||
case ARG_SPEED:
|
case ARG_SPEED:
|
||||||
filter->speed = g_value_get_float (value);
|
filter->speed = g_value_get_float (value);
|
||||||
break;
|
break;
|
||||||
|
@ -317,9 +292,6 @@ speed_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *p
|
||||||
filter = GST_SPEED(object);
|
filter = GST_SPEED(object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_SILENT:
|
|
||||||
g_value_set_boolean (value, filter->silent);
|
|
||||||
break;
|
|
||||||
case ARG_SPEED:
|
case ARG_SPEED:
|
||||||
g_value_set_float (value, filter->speed);
|
g_value_set_float (value, filter->speed);
|
||||||
break;
|
break;
|
||||||
|
@ -334,10 +306,9 @@ plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
{
|
{
|
||||||
GstElementFactory *factory;
|
GstElementFactory *factory;
|
||||||
|
|
||||||
factory = gst_element_factory_new("speed",GST_TYPE_SPEED,
|
factory = gst_element_factory_new("speed", GST_TYPE_SPEED, &speed_details);
|
||||||
&speed_details);
|
|
||||||
g_return_val_if_fail(factory != NULL, FALSE);
|
g_return_val_if_fail(factory != NULL, FALSE);
|
||||||
|
|
||||||
gst_element_factory_add_pad_template (factory, speed_src_factory ());
|
gst_element_factory_add_pad_template (factory, speed_src_factory ());
|
||||||
gst_element_factory_add_pad_template (factory, speed_sink_factory ());
|
gst_element_factory_add_pad_template (factory, speed_sink_factory ());
|
||||||
|
|
||||||
|
|
|
@ -22,23 +22,20 @@
|
||||||
#ifndef __GST_SPEED_H__
|
#ifndef __GST_SPEED_H__
|
||||||
#define __GST_SPEED_H__
|
#define __GST_SPEED_H__
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
/* #include <gst/meta/audioraw.h> */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_TYPE_SPEED \
|
#define GST_TYPE_SPEED \
|
||||||
(gst_speed_get_type())
|
(gst_speed_get_type())
|
||||||
#define GST_SPEED(obj) \
|
#define GST_SPEED(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPEED,GstSpeed))
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPEED,GstSpeed))
|
||||||
#define GST_SPEED_CLASS(klass) \
|
#define GST_SPEED_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstSpeed))
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPEED,GstSpeed))
|
||||||
#define GST_IS_SPEED(obj) \
|
#define GST_IS_SPEED(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPEED))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPEED))
|
||||||
#define GST_IS_SPEED_CLASS(obj) \
|
#define GST_IS_SPEED_CLASS(obj) \
|
||||||
|
@ -59,23 +56,19 @@ struct _GstSpeed {
|
||||||
GstPad *sinkpad, *srcpad;
|
GstPad *sinkpad, *srcpad;
|
||||||
GstBufferPool *sinkpool, *srcpool;
|
GstBufferPool *sinkpool, *srcpool;
|
||||||
|
|
||||||
gboolean silent;
|
|
||||||
gfloat speed;
|
gfloat speed;
|
||||||
|
|
||||||
/* the next are valid for both int and float */
|
/* valid for both int and float */
|
||||||
GstSpeedFormat format;
|
GstSpeedFormat format;
|
||||||
guint rate;
|
guint rate;
|
||||||
guint channels;
|
guint channels;
|
||||||
guint width;
|
guint width;
|
||||||
guint endianness;
|
guint endianness;
|
||||||
|
guint buffer_frames;
|
||||||
|
|
||||||
/* the next are valid only for format==GST_SPEED_FORMAT_INT */
|
/* valid only for format==GST_SPEED_FORMAT_INT */
|
||||||
guint depth;
|
guint depth;
|
||||||
gboolean is_signed;
|
gboolean is_signed;
|
||||||
|
|
||||||
/* the next three are valid only for format==GST_SPEED_FORMAT_FLOAT */
|
|
||||||
gfloat slope;
|
|
||||||
gfloat intercept;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstSpeedClass {
|
struct _GstSpeedClass {
|
||||||
|
@ -84,9 +77,6 @@ struct _GstSpeedClass {
|
||||||
|
|
||||||
GType gst_speed_get_type(void);
|
GType gst_speed_get_type(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
G_END_DECLS
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GST_SPEED_H__ */
|
#endif /* __GST_SPEED_H__ */
|
||||||
|
|
Loading…
Reference in a new issue