From 5d25c00e4b613b9cdf2c04fa3a68dffa03834a68 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 14 Mar 2004 22:34:33 +0000 Subject: gst-indent Original commit message from CVS: gst-indent --- gst/cutter/gstcutter.c | 322 ++++++++++++++++++++++--------------------------- gst/cutter/gstcutter.h | 59 ++++----- 2 files changed, 175 insertions(+), 206 deletions(-) (limited to 'gst/cutter') diff --git a/gst/cutter/gstcutter.c b/gst/cutter/gstcutter.c index f163c0b6..9b82b057 100644 --- a/gst/cutter/gstcutter.c +++ b/gst/cutter/gstcutter.c @@ -35,14 +35,16 @@ static GstElementDetails cutter_details = { /* Filter signals and args */ -enum { +enum +{ /* FILL ME */ CUT_START, CUT_STOP, LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_THRESHOLD, ARG_THRESHOLD_DB, @@ -51,52 +53,43 @@ enum { ARG_LEAKY }; -static GstStaticPadTemplate cutter_src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; " - GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS - ) -); +static GstStaticPadTemplate cutter_src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; " + GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS) + ); static GstStaticPadTemplate cutter_sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; " - GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS - ) -); - -static void gst_cutter_base_init (gpointer g_class); -static void gst_cutter_class_init (GstCutterClass *klass); -static void gst_cutter_init (GstCutter *filter); - -static void gst_cutter_set_property (GObject *object, guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gst_cutter_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); - -static void gst_cutter_chain (GstPad *pad, GstData *_data); -static double -inline gst_cutter_16bit_ms (gint16* data, guint numsamples); -static double -inline gst_cutter_8bit_ms (gint8* data, guint numsamples); - -void gst_cutter_get_caps (GstPad *pad, GstCutter* filter); + GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; " + GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS) + ); + +static void gst_cutter_base_init (gpointer g_class); +static void gst_cutter_class_init (GstCutterClass * klass); +static void gst_cutter_init (GstCutter * filter); + +static void gst_cutter_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_cutter_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static void gst_cutter_chain (GstPad * pad, GstData * _data); +static double inline gst_cutter_16bit_ms (gint16 * data, guint numsamples); +static double inline gst_cutter_8bit_ms (gint8 * data, guint numsamples); + +void gst_cutter_get_caps (GstPad * pad, GstCutter * filter); static GstElementClass *parent_class = NULL; static guint gst_cutter_signals[LAST_SIGNAL] = { 0 }; GType -gst_cutter_get_type (void) { +gst_cutter_get_type (void) +{ static GType cutter_type = 0; if (!cutter_type) { @@ -109,7 +102,7 @@ gst_cutter_get_type (void) { (GInstanceInitFunc) gst_cutter_init, }; cutter_type = g_type_register_static (GST_TYPE_ELEMENT, "GstCutter", - &cutter_info, 0); + &cutter_info, 0); } return cutter_type; } @@ -119,13 +112,15 @@ gst_cutter_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&cutter_src_factory)); - gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&cutter_sink_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&cutter_src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&cutter_sink_factory)); gst_element_class_set_details (element_class, &cutter_details); } static GstPadLinkReturn -gst_cutter_link (GstPad *pad, const GstCaps*caps) +gst_cutter_link (GstPad * pad, const GstCaps * caps) { GstCutter *filter; GstPad *otherpad; @@ -139,46 +134,46 @@ gst_cutter_link (GstPad *pad, const GstCaps*caps) } static void -gst_cutter_class_init (GstCutterClass *klass) +gst_cutter_class_init (GstCutterClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*) klass; - gstelement_class = (GstElementClass*) klass; + 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_THRESHOLD, - g_param_spec_double ("threshold", "Threshold", - "Volume threshold before trigger", - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); + g_param_spec_double ("threshold", "Threshold", + "Volume threshold before trigger", + -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_THRESHOLD_DB, - g_param_spec_double ("threshold_dB", "Threshold (dB)", - "Volume threshold before trigger (in dB)", - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); + g_param_spec_double ("threshold_dB", "Threshold (dB)", + "Volume threshold before trigger (in dB)", + -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RUN_LENGTH, - g_param_spec_double ("runlength", "Runlength", - "Length of drop below threshold before cut_stop (seconds)", - 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); + g_param_spec_double ("runlength", "Runlength", + "Length of drop below threshold before cut_stop (seconds)", + 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRE_LENGTH, - g_param_spec_double ("prelength", "prelength", - "Length of pre-recording buffer (seconds)", - 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); + g_param_spec_double ("prelength", "prelength", + "Length of pre-recording buffer (seconds)", + 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LEAKY, - g_param_spec_boolean ("leaky", "Leaky", - "do we leak buffers when below threshold ?", - FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("leaky", "Leaky", + "do we leak buffers when below threshold ?", + FALSE, G_PARAM_READWRITE)); gst_cutter_signals[CUT_START] = - g_signal_new ("cut-start", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GstCutterClass, cut_start), NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + g_signal_new ("cut-start", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstCutterClass, cut_start), NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gst_cutter_signals[CUT_STOP] = - g_signal_new ("cut-stop", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GstCutterClass, cut_stop), NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + g_signal_new ("cut-stop", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstCutterClass, cut_stop), NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gobject_class->set_property = gst_cutter_set_property; @@ -186,12 +181,14 @@ gst_cutter_class_init (GstCutterClass *klass) } static void -gst_cutter_init (GstCutter *filter) +gst_cutter_init (GstCutter * filter) { - filter->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get(&cutter_sink_factory),"sink"); - filter->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get(&cutter_src_factory),"src"); + filter->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&cutter_sink_factory), "sink"); + filter->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&cutter_src_factory), "src"); filter->threshold_level = 0.1; filter->threshold_length = 0.5; @@ -208,19 +205,19 @@ gst_cutter_init (GstCutter *filter) gst_pad_set_link_function (filter->sinkpad, gst_cutter_link); gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); - /*gst_pad_set_link_function (filter->srcpad, gst_cutter_link);*/ + /*gst_pad_set_link_function (filter->srcpad, gst_cutter_link); */ } static void -gst_cutter_chain (GstPad *pad, GstData *_data) +gst_cutter_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstCutter *filter; gint16 *in_data; - double RMS = 0.0; /* RMS of signal in buffer */ - double ms = 0.0; /* mean square value of buffer */ - static gboolean silent_prev = FALSE; /* previous value of silent */ - GstBuffer *prebuf; /* pointer to a prebuffer element */ + double RMS = 0.0; /* RMS of signal in buffer */ + double ms = 0.0; /* mean square value of buffer */ + static gboolean silent_prev = FALSE; /* previous value of silent */ + GstBuffer *prebuf; /* pointer to a prebuffer element */ g_return_if_fail (pad != NULL); g_return_if_fail (GST_IS_PAD (pad)); @@ -233,16 +230,14 @@ gst_cutter_chain (GstPad *pad, GstData *_data) if (gst_audio_is_buffer_framed (pad, buf) == FALSE) g_warning ("audio buffer is not framed !\n"); - if (!filter->have_caps) gst_cutter_get_caps (pad, filter); + if (!filter->have_caps) + gst_cutter_get_caps (pad, filter); in_data = (gint16 *) GST_BUFFER_DATA (buf); - GST_DEBUG ( - "length of prerec buffer: %.3f sec", - filter->pre_run_length); + GST_DEBUG ("length of prerec buffer: %.3f sec", filter->pre_run_length); /* calculate mean square value on buffer */ - switch (filter->width) - { + switch (filter->width) { case 16: ms = gst_cutter_16bit_ms (in_data, GST_BUFFER_SIZE (buf) / 2); break; @@ -252,7 +247,7 @@ gst_cutter_chain (GstPad *pad, GstData *_data) default: /* this shouldn't happen */ g_print ("WARNING: no mean square function for width %d\n", - filter->width); + filter->width); break; } @@ -262,13 +257,11 @@ gst_cutter_chain (GstPad *pad, GstData *_data) /* if RMS below threshold, add buffer length to silent run length count * if not, reset */ - GST_DEBUG ( - "buffer stats: ms %f, RMS %f, audio length %f", - ms, RMS, gst_audio_length (filter->srcpad, buf)); + GST_DEBUG ("buffer stats: ms %f, RMS %f, audio length %f", + ms, RMS, gst_audio_length (filter->srcpad, buf)); if (RMS < filter->threshold_level) filter->silent_run_length += gst_audio_length (filter->srcpad, buf); - else - { + else { filter->silent_run_length = 0.0; filter->silent = FALSE; } @@ -280,27 +273,21 @@ gst_cutter_chain (GstPad *pad, GstData *_data) /* has the silent status changed ? if so, send right signal * and, if from silent -> not silent, flush pre_record buffer */ - if (filter->silent != silent_prev) - { - if (filter->silent) - { + if (filter->silent != silent_prev) { + if (filter->silent) { /* g_print ("DEBUG: cutter: cut to here, turning off out\n"); */ g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_STOP], 0); - } - else - { + } else { gint count = 0; + /* g_print ("DEBUG: cutter: start from here, turning on out\n"); */ /* first of all, flush current buffer */ g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_START], 0); - GST_DEBUG ( - "flushing buffer of length %.3f", - filter->pre_run_length); - while (filter->pre_buffer) - { - prebuf = (g_list_first (filter->pre_buffer))->data; - filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf); - gst_pad_push (filter->srcpad, GST_DATA (prebuf)); + GST_DEBUG ("flushing buffer of length %.3f", filter->pre_run_length); + while (filter->pre_buffer) { + prebuf = (g_list_first (filter->pre_buffer))->data; + filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf); + gst_pad_push (filter->srcpad, GST_DATA (prebuf)); ++count; } GST_DEBUG ("flushed %d buffers", count); @@ -309,59 +296,50 @@ gst_cutter_chain (GstPad *pad, GstData *_data) } /* now check if we have to send the new buffer to the internal buffer cache * or to the srcpad */ - if (filter->silent) - { - /* we ref it before putting it in the pre_buffer */ - /* FIXME: we shouldn't probably do this, because the buffer - * arrives reffed already; the plugin should just push it - * or unref it to make it disappear */ - /* - gst_buffer_ref (buf); - */ - filter->pre_buffer = g_list_append (filter->pre_buffer, buf); - filter->pre_run_length += gst_audio_length (filter->srcpad, buf); - while (filter->pre_run_length > filter->pre_length) - { - prebuf = (g_list_first (filter->pre_buffer))->data; - g_assert (GST_IS_BUFFER (prebuf)); - filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf); - filter->pre_run_length -= gst_audio_length (filter->srcpad, prebuf); - /* only pass buffers if we don't leak */ - if (!filter->leaky) - gst_pad_push (filter->srcpad, GST_DATA (prebuf)); - /* we unref it after getting it out of the pre_buffer */ - gst_buffer_unref (prebuf); - } - } - else + if (filter->silent) { + /* we ref it before putting it in the pre_buffer */ + /* FIXME: we shouldn't probably do this, because the buffer + * arrives reffed already; the plugin should just push it + * or unref it to make it disappear */ + /* + gst_buffer_ref (buf); + */ + filter->pre_buffer = g_list_append (filter->pre_buffer, buf); + filter->pre_run_length += gst_audio_length (filter->srcpad, buf); + while (filter->pre_run_length > filter->pre_length) { + prebuf = (g_list_first (filter->pre_buffer))->data; + g_assert (GST_IS_BUFFER (prebuf)); + filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf); + filter->pre_run_length -= gst_audio_length (filter->srcpad, prebuf); + /* only pass buffers if we don't leak */ + if (!filter->leaky) + gst_pad_push (filter->srcpad, GST_DATA (prebuf)); + /* we unref it after getting it out of the pre_buffer */ + gst_buffer_unref (prebuf); + } + } else gst_pad_push (filter->srcpad, GST_DATA (buf)); } static double inline -gst_cutter_16bit_ms (gint16* data, guint num_samples) +gst_cutter_16bit_ms (gint16 * data, guint num_samples) #include "filter.func" - -static double inline -gst_cutter_8bit_ms (gint8* data, guint num_samples) + static double inline gst_cutter_8bit_ms (gint8 * data, guint num_samples) #include "filter.func" - -static void -gst_cutter_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) + static void + gst_cutter_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstCutter *filter; g_return_if_fail (GST_IS_CUTTER (object)); filter = GST_CUTTER (object); - switch (prop_id) - { + switch (prop_id) { case ARG_THRESHOLD: - /* set the level */ + /* set the level */ filter->threshold_level = g_value_get_double (value); - GST_DEBUG ( - "DEBUG: set threshold level to %f", - filter->threshold_level); + GST_DEBUG ("DEBUG: set threshold level to %f", filter->threshold_level); break; case ARG_THRESHOLD_DB: /* set the level given in dB @@ -369,9 +347,7 @@ gst_cutter_set_property (GObject *object, guint prop_id, * values in dB < 0 result in values between 0 and 1 */ filter->threshold_level = pow (10, g_value_get_double (value) / 20); - GST_DEBUG ( - "DEBUG: set threshold level to %f", - filter->threshold_level); + GST_DEBUG ("DEBUG: set threshold level to %f", filter->threshold_level); break; case ARG_RUN_LENGTH: /* set the minimum length of the silent run required */ @@ -392,25 +368,24 @@ gst_cutter_set_property (GObject *object, guint prop_id, } static void -gst_cutter_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +gst_cutter_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstCutter *filter; g_return_if_fail (GST_IS_CUTTER (object)); filter = GST_CUTTER (object); - switch (prop_id) - { + switch (prop_id) { case ARG_RUN_LENGTH: - g_value_set_double (value, filter->threshold_length); - break; + g_value_set_double (value, filter->threshold_length); + break; case ARG_THRESHOLD: - g_value_set_double (value, filter->threshold_level); - break; + g_value_set_double (value, filter->threshold_level); + break; case ARG_THRESHOLD_DB: - g_value_set_double (value, 20 * log (filter->threshold_level)); - break; + g_value_set_double (value, 20 * log (filter->threshold_level)); + break; case ARG_PRE_LENGTH: g_value_set_double (value, filter->pre_length); break; @@ -424,9 +399,9 @@ gst_cutter_get_property (GObject *object, guint prop_id, } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - /* load audio support library */ + /* load audio support library */ if (!gst_library_load ("gstaudio")) return FALSE; @@ -436,25 +411,19 @@ plugin_init (GstPlugin *plugin) return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "cutter", - "Audio Cutter to split audio into non-silent bits", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) - -void -gst_cutter_get_caps (GstPad *pad, GstCutter* filter) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "cutter", + "Audio Cutter to split audio into non-silent bits", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) + + void gst_cutter_get_caps (GstPad * pad, GstCutter * filter) { const GstCaps *caps = NULL; GstStructure *structure; caps = GST_PAD_CAPS (pad); - /* FIXME : Please change this to a better warning method ! */ + /* FIXME : Please change this to a better warning method ! */ g_assert (caps != NULL); if (caps == NULL) printf ("WARNING: get_caps: Could not get caps of pad !\n"); @@ -463,4 +432,3 @@ gst_cutter_get_caps (GstPad *pad, GstCutter* filter) filter->max_sample = gst_audio_highest_sample_value (pad); filter->have_caps = TRUE; } - diff --git a/gst/cutter/gstcutter.h b/gst/cutter/gstcutter.h index 84166636..e1ed9976 100644 --- a/gst/cutter/gstcutter.h +++ b/gst/cutter/gstcutter.h @@ -27,8 +27,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_CUTTER \ @@ -42,44 +43,44 @@ extern "C" { #define GST_IS_CUTTER_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CUTTER)) -typedef struct _GstCutter GstCutter; -typedef struct _GstCutterClass GstCutterClass; + typedef struct _GstCutter GstCutter; + typedef struct _GstCutterClass GstCutterClass; -struct _GstCutter -{ - GstElement element; + struct _GstCutter + { + GstElement element; - GstPad *sinkpad, *srcpad; + GstPad *sinkpad, *srcpad; - double threshold_level; /* level below which to cut */ - double threshold_length; /* how long signal has to remain + double threshold_level; /* level below which to cut */ + double threshold_length; /* how long signal has to remain * below this level before cutting */ - double silent_run_length; /* how long has it been below threshold ? */ - gboolean silent; + double silent_run_length; /* how long has it been below threshold ? */ + gboolean silent; - double pre_length; /* how long can the pre-record buffer be ? */ - double pre_run_length; /* how long is it currently ? */ - GList *pre_buffer; /* list of GstBuffers in pre-record buffer */ - gboolean leaky; /* do we leak an overflowing prebuffer ? */ + double pre_length; /* how long can the pre-record buffer be ? */ + double pre_run_length; /* how long is it currently ? */ + GList *pre_buffer; /* list of GstBuffers in pre-record buffer */ + gboolean leaky; /* do we leak an overflowing prebuffer ? */ - gboolean have_caps; /* did we get the needed caps yet ? */ - gint width; /* bit width of data */ - long max_sample; /* maximum sample value */ -}; + gboolean have_caps; /* did we get the needed caps yet ? */ + gint width; /* bit width of data */ + long max_sample; /* maximum sample value */ + }; -struct _GstCutterClass -{ - GstElementClass parent_class; - void (*cut_start) (GstCutter* filter); - void (*cut_stop) (GstCutter* filter); -}; + struct _GstCutterClass + { + GstElementClass parent_class; + void (*cut_start) (GstCutter * filter); + void (*cut_stop) (GstCutter * filter); + }; -GType gst_cutter_get_type (void); + GType gst_cutter_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_STEREO_H__ */ +#endif /* __GST_STEREO_H__ */ -- cgit