2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:31 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
#include <gst/gst.h>
|
2001-12-23 04:38:37 +00:00
|
|
|
#include <gst/audio/audio.h>
|
|
|
|
#include "gstcutter.h"
|
2001-12-22 23:27:31 +00:00
|
|
|
#include "math.h"
|
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2001-12-22 23:27:31 +00:00
|
|
|
static GstElementDetails cutter_details = {
|
|
|
|
"Cutter",
|
2002-04-20 21:42:51 +00:00
|
|
|
"Filter/Audio/Effect",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2001-12-22 23:27:31 +00:00
|
|
|
"Audio Cutter to split audio into non-silent bits",
|
|
|
|
VERSION,
|
|
|
|
"Thomas <thomas@apestaart.org>",
|
|
|
|
"(C) 2001",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
CUT_START,
|
|
|
|
CUT_STOP,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_THRESHOLD,
|
|
|
|
ARG_THRESHOLD_DB,
|
|
|
|
ARG_RUN_LENGTH,
|
2003-05-10 16:57:38 +00:00
|
|
|
ARG_PRE_LENGTH,
|
|
|
|
ARG_LEAKY
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (cutter_src_factory,
|
2001-12-22 23:27:31 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"test_src",
|
|
|
|
"audio/raw",
|
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (cutter_sink_factory,
|
2001-12-22 23:27:31 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"test_src",
|
|
|
|
"audio/raw",
|
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
static void gst_cutter_class_init (GstCutterClass *klass);
|
|
|
|
static void gst_cutter_init (GstCutter *filter);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
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);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
static void gst_cutter_chain (GstPad *pad, GstBuffer *buf);
|
|
|
|
static double
|
|
|
|
inline gst_cutter_16bit_ms (gint16* data, guint numsamples);
|
|
|
|
static double
|
|
|
|
inline gst_cutter_8bit_ms (gint8* data, guint numsamples);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
void gst_cutter_get_caps (GstPad *pad, GstCutter* filter);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_cutter_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_cutter_get_type (void) {
|
2001-12-22 23:27:31 +00:00
|
|
|
static GType cutter_type = 0;
|
|
|
|
|
|
|
|
if (!cutter_type) {
|
|
|
|
static const GTypeInfo cutter_info = {
|
2003-05-10 16:57:38 +00:00
|
|
|
sizeof (GstCutterClass), NULL, NULL,
|
|
|
|
(GClassInitFunc) gst_cutter_class_init, NULL, NULL,
|
|
|
|
sizeof (GstCutter), 0,
|
|
|
|
(GInstanceInitFunc) gst_cutter_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
2003-05-10 16:57:38 +00:00
|
|
|
cutter_type = g_type_register_static (GST_TYPE_ELEMENT, "GstCutter",
|
|
|
|
&cutter_info, 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
return cutter_type;
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_cutter_link (GstPad *pad, GstCaps *caps)
|
2002-07-12 21:15:31 +00:00
|
|
|
{
|
|
|
|
GstCutter *filter;
|
|
|
|
GstPad *otherpad;
|
2003-05-10 16:57:38 +00:00
|
|
|
|
2002-07-12 21:15:31 +00:00
|
|
|
filter = GST_CUTTER (gst_pad_get_parent (pad));
|
2003-01-10 10:22:25 +00:00
|
|
|
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
g_return_val_if_fail (GST_IS_CUTTER (filter), GST_PAD_LINK_REFUSED);
|
2002-07-12 21:15:31 +00:00
|
|
|
otherpad = (pad == filter->srcpad ? filter->sinkpad : filter->srcpad);
|
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
if (GST_CAPS_IS_FIXED (caps))
|
2002-09-10 09:31:40 +00:00
|
|
|
return gst_pad_try_set_caps (otherpad, caps);
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-07-12 21:15:31 +00:00
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
|
|
|
gst_cutter_class_init (GstCutterClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
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_THRESHOLD,
|
2003-05-10 16:57:38 +00:00
|
|
|
g_param_spec_double ("threshold", "Threshold",
|
|
|
|
"Volume threshold before trigger",
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
|
2001-12-22 23:27:31 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_THRESHOLD_DB,
|
2003-05-10 16:57:38 +00:00
|
|
|
g_param_spec_double ("threshold_dB", "Threshold (dB)",
|
|
|
|
"Volume threshold before trigger (in dB)",
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
|
2001-12-22 23:27:31 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RUN_LENGTH,
|
2003-05-10 16:57:38 +00:00
|
|
|
g_param_spec_double ("runlength", "Runlength",
|
|
|
|
"Length of drop below threshold before cut_stop (seconds)",
|
|
|
|
0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
|
2001-12-22 23:27:31 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRE_LENGTH,
|
2003-05-10 16:57:38 +00:00
|
|
|
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));
|
|
|
|
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);
|
|
|
|
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);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_cutter_set_property;
|
|
|
|
gobject_class->get_property = gst_cutter_get_property;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_cutter_init (GstCutter *filter)
|
|
|
|
{
|
|
|
|
filter->sinkpad = gst_pad_new_from_template (cutter_sink_factory (),"sink");
|
|
|
|
filter->srcpad = gst_pad_new_from_template (cutter_src_factory (),"src");
|
|
|
|
|
|
|
|
filter->threshold_level = 0.1;
|
|
|
|
filter->threshold_length = 0.5;
|
|
|
|
filter->silent_run_length = 0.0;
|
|
|
|
filter->silent = TRUE;
|
|
|
|
|
|
|
|
filter->pre_length = 0.2;
|
|
|
|
filter->pre_run_length = 0.0;
|
|
|
|
filter->pre_buffer = NULL;
|
2003-05-10 16:57:38 +00:00
|
|
|
filter->leaky = FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_cutter_chain);
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_pad_set_link_function (filter->sinkpad, gst_cutter_link);
|
2001-12-22 23:27:31 +00:00
|
|
|
filter->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_pad_set_link_function (filter->srcpad, gst_cutter_link);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_cutter_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
|
|
|
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 */
|
2002-07-12 21:15:31 +00:00
|
|
|
GstBuffer *prebuf; /* pointer to a prebuffer element */
|
2003-05-10 16:57:38 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
filter = GST_CUTTER (GST_OBJECT_PARENT (pad));
|
|
|
|
g_return_if_fail (filter != NULL);
|
|
|
|
g_return_if_fail (GST_IS_CUTTER (filter));
|
|
|
|
|
2002-07-12 21:15:31 +00:00
|
|
|
if (gst_audio_is_buffer_framed (pad, buf) == FALSE)
|
2003-05-10 16:57:38 +00:00
|
|
|
g_warning ("audio buffer is not framed !\n");
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
if (!filter->have_caps) gst_cutter_get_caps (pad, filter);
|
|
|
|
|
|
|
|
in_data = (gint16 *) GST_BUFFER_DATA (buf);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG (
|
2003-05-10 16:57:38 +00:00
|
|
|
"length of prerec buffer: %.3f sec",
|
2002-09-09 08:47:32 +00:00
|
|
|
filter->pre_run_length);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* calculate mean square value on buffer */
|
2003-05-10 16:57:38 +00:00
|
|
|
switch (filter->width)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
ms = gst_cutter_16bit_ms (in_data, GST_BUFFER_SIZE (buf) / 2);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
ms = gst_cutter_8bit_ms ((gint8 *) in_data, GST_BUFFER_SIZE (buf));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* this shouldn't happen */
|
|
|
|
g_print ("WARNING: no mean square function for width %d\n",
|
|
|
|
filter->width);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
silent_prev = filter->silent;
|
|
|
|
|
|
|
|
RMS = sqrt (ms) / (double) filter->max_sample;
|
2003-05-10 16:57:38 +00:00
|
|
|
/* if RMS below threshold, add buffer length to silent run length count
|
2001-12-22 23:27:31 +00:00
|
|
|
* if not, reset
|
|
|
|
*/
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG (
|
2003-05-10 16:57:38 +00:00
|
|
|
"buffer stats: ms %f, RMS %f, audio length %f",
|
2002-07-12 21:15:31 +00:00
|
|
|
ms, RMS, gst_audio_length (filter->srcpad, buf));
|
2001-12-22 23:27:31 +00:00
|
|
|
if (RMS < filter->threshold_level)
|
|
|
|
filter->silent_run_length += gst_audio_length (filter->srcpad, buf);
|
|
|
|
else
|
2003-05-10 16:57:38 +00:00
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
filter->silent_run_length = 0.0;
|
|
|
|
filter->silent = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter->silent_run_length > filter->threshold_length)
|
|
|
|
/* it has been silent long enough, flag it */
|
|
|
|
filter->silent = TRUE;
|
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
/* has the silent status changed ? if so, send right signal
|
|
|
|
* and, if from silent -> not silent, flush pre_record buffer
|
2001-12-22 23:27:31 +00:00
|
|
|
*/
|
|
|
|
if (filter->silent != silent_prev)
|
|
|
|
{
|
|
|
|
if (filter->silent)
|
|
|
|
{
|
2002-03-19 04:10:05 +00:00
|
|
|
/* g_print ("DEBUG: cutter: cut to here, turning off out\n"); */
|
2002-03-30 17:06:26 +00:00
|
|
|
g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_STOP], 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-10 16:57:38 +00:00
|
|
|
gint count = 0;
|
2002-03-19 04:10:05 +00:00
|
|
|
/* g_print ("DEBUG: cutter: start from here, turning on out\n"); */
|
2001-12-22 23:27:31 +00:00
|
|
|
/* first of all, flush current buffer */
|
2002-03-30 17:06:26 +00:00
|
|
|
g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_START], 0);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG (
|
2003-05-10 16:57:38 +00:00
|
|
|
"flushing buffer of length %.3f",
|
|
|
|
filter->pre_run_length);
|
2001-12-22 23:27:31 +00:00
|
|
|
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, prebuf);
|
2003-05-10 16:57:38 +00:00
|
|
|
++count;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flushed %d buffers", count);
|
2003-05-10 16:57:38 +00:00
|
|
|
filter->pre_run_length = 0.0;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2003-05-10 16:57:38 +00:00
|
|
|
/* now check if we have to send the new buffer to the internal buffer cache
|
|
|
|
* or to the srcpad */
|
2001-12-22 23:27:31 +00:00
|
|
|
if (filter->silent)
|
|
|
|
{
|
2002-07-12 21:15:31 +00:00
|
|
|
/* we ref it before putting it in the pre_buffer */
|
2003-05-10 16:57:38 +00:00
|
|
|
/* 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 */
|
|
|
|
/*
|
2002-07-12 21:15:31 +00:00
|
|
|
gst_buffer_ref (buf);
|
2003-05-10 16:57:38 +00:00
|
|
|
*/
|
2001-12-22 23:27:31 +00:00
|
|
|
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;
|
2002-07-12 21:15:31 +00:00
|
|
|
g_assert (GST_IS_BUFFER (prebuf));
|
2001-12-22 23:27:31 +00:00
|
|
|
filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf);
|
|
|
|
filter->pre_run_length -= gst_audio_length (filter->srcpad, prebuf);
|
2003-05-10 16:57:38 +00:00
|
|
|
/* only pass buffers if we don't leak */
|
|
|
|
if (!filter->leaky)
|
|
|
|
gst_pad_push (filter->srcpad, prebuf);
|
2002-07-12 21:15:31 +00:00
|
|
|
/* we unref it after getting it out of the pre_buffer */
|
|
|
|
gst_buffer_unref (prebuf);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gst_pad_push (filter->srcpad, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static double inline
|
|
|
|
gst_cutter_16bit_ms (gint16* data, guint num_samples)
|
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static double inline
|
|
|
|
gst_cutter_8bit_ms (gint8* data, guint num_samples)
|
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static void
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_cutter_set_property (GObject *object, guint prop_id,
|
2002-09-09 08:47:32 +00:00
|
|
|
const GValue *value, GParamSpec *pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstCutter *filter;
|
|
|
|
|
2002-09-09 08:47:32 +00:00
|
|
|
g_return_if_fail (GST_IS_CUTTER (object));
|
2001-12-22 23:27:31 +00:00
|
|
|
filter = GST_CUTTER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case ARG_THRESHOLD:
|
|
|
|
/* set the level */
|
|
|
|
filter->threshold_level = g_value_get_double (value);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG (
|
2003-05-10 16:57:38 +00:00
|
|
|
"DEBUG: set threshold level to %f",
|
2002-07-15 12:30:17 +00:00
|
|
|
filter->threshold_level);
|
2001-12-22 23:27:31 +00:00
|
|
|
break;
|
|
|
|
case ARG_THRESHOLD_DB:
|
2003-05-10 16:57:38 +00:00
|
|
|
/* set the level given in dB
|
|
|
|
* value in dB = 20 * log (value)
|
2001-12-22 23:27:31 +00:00
|
|
|
* values in dB < 0 result in values between 0 and 1
|
|
|
|
*/
|
|
|
|
filter->threshold_level = pow (10, g_value_get_double (value) / 20);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG (
|
2003-05-10 16:57:38 +00:00
|
|
|
"DEBUG: set threshold level to %f",
|
2002-07-15 12:30:17 +00:00
|
|
|
filter->threshold_level);
|
2001-12-22 23:27:31 +00:00
|
|
|
break;
|
|
|
|
case ARG_RUN_LENGTH:
|
|
|
|
/* set the minimum length of the silent run required */
|
|
|
|
filter->threshold_length = g_value_get_double (value);
|
2003-05-10 16:57:38 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
case ARG_PRE_LENGTH:
|
|
|
|
/* set the length of the pre-record block */
|
|
|
|
filter->pre_length = g_value_get_double (value);
|
|
|
|
break;
|
2003-05-10 16:57:38 +00:00
|
|
|
case ARG_LEAKY:
|
|
|
|
/* set if the pre-record buffer is leaky or not */
|
|
|
|
filter->leaky = g_value_get_boolean (value);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-05-10 16:57:38 +00:00
|
|
|
gst_cutter_get_property (GObject *object, guint prop_id,
|
2002-09-09 08:47:32 +00:00
|
|
|
GValue *value, GParamSpec *pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstCutter *filter;
|
|
|
|
|
2002-09-09 08:47:32 +00:00
|
|
|
g_return_if_fail (GST_IS_CUTTER (object));
|
2001-12-22 23:27:31 +00:00
|
|
|
filter = GST_CUTTER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case ARG_RUN_LENGTH:
|
|
|
|
g_value_set_double (value, filter->threshold_length);
|
|
|
|
break;
|
|
|
|
case ARG_THRESHOLD:
|
|
|
|
g_value_set_double (value, filter->threshold_level);
|
|
|
|
break;
|
|
|
|
case ARG_THRESHOLD_DB:
|
|
|
|
g_value_set_double (value, 20 * log (filter->threshold_level));
|
|
|
|
break;
|
|
|
|
case ARG_PRE_LENGTH:
|
|
|
|
g_value_set_double (value, filter->pre_length);
|
|
|
|
break;
|
2003-05-10 16:57:38 +00:00
|
|
|
case ARG_LEAKY:
|
|
|
|
g_value_set_boolean (value, filter->leaky);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2002-09-09 08:47:32 +00:00
|
|
|
factory = gst_element_factory_new ("cutter", GST_TYPE_CUTTER,
|
|
|
|
&cutter_details);
|
2001-12-22 23:27:31 +00:00
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
2003-05-10 16:57:38 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (cutter_src_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (cutter_sink_factory));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
/* load audio support library */
|
|
|
|
if (!gst_library_load ("gstaudio"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-10 16:57:38 +00:00
|
|
|
GstPluginDesc plugin_desc =
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"cutter",
|
|
|
|
plugin_init
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_cutter_get_caps (GstPad *pad, GstCutter* filter)
|
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
2002-03-19 04:10:05 +00:00
|
|
|
/* FIXME : Please change this to a better warning method ! */
|
2002-07-12 21:15:31 +00:00
|
|
|
g_assert (caps != NULL);
|
2001-12-22 23:27:31 +00:00
|
|
|
if (caps == NULL)
|
2003-05-10 16:57:38 +00:00
|
|
|
printf ("WARNING: get_caps: Could not get caps of pad !\n");
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (caps, "width", &filter->width);
|
2001-12-22 23:27:31 +00:00
|
|
|
filter->max_sample = gst_audio_highest_sample_value (pad);
|
|
|
|
filter->have_caps = TRUE;
|
|
|
|
}
|