gst/cutter/gstcutter.*: Fix some of the most obvious bugs in cutter. Now doesn't leak everything if input is silent.

Original commit message from CVS:
* gst/cutter/gstcutter.c: (gst_cutter_init), (gst_cutter_chain),
(gst_cutter_get_caps):
* gst/cutter/gstcutter.h:
Fix some of the most obvious bugs in cutter. Now doesn't leak
everything if input is silent.
This commit is contained in:
Michael Smith 2007-04-18 12:36:37 +00:00
parent 1723d916dd
commit 4a1ceda8df
4 changed files with 19 additions and 11 deletions

View file

@ -1,3 +1,11 @@
2007-04-18 Michael Smith <msmith@fluendo.com>
* gst/cutter/gstcutter.c: (gst_cutter_init), (gst_cutter_chain),
(gst_cutter_get_caps):
* gst/cutter/gstcutter.h:
Fix some of the most obvious bugs in cutter. Now doesn't leak
everything if input is silent.
2007-04-18 Sebastian Dröge <slomo@circular-chaos.org>
* gst/wavenc/gstwavenc.c: (gst_wavenc_create_header_buf),

2
common

@ -1 +1 @@
Subproject commit 9097e252e477e18182f08a032d8860bdee9a0416
Subproject commit dae6fa1f592c9231820c2135b8b1b3c2b0875ef6

View file

@ -144,6 +144,7 @@ gst_cutter_init (GstCutter * filter, GstCutterClass * g_class)
filter->threshold_length = CUTTER_DEFAULT_THRESHOLD_LENGTH;
filter->silent_run_length = 0 * GST_SECOND;
filter->silent = TRUE;
filter->silent_prev = FALSE; /* previous value of silent */
filter->pre_length = CUTTER_DEFAULT_PRE_LENGTH;
filter->pre_run_length = 0 * GST_SECOND;
@ -213,7 +214,6 @@ gst_cutter_chain (GstPad * pad, GstBuffer * buf)
gdouble NCS = 0.0; /* Normalized Cumulative Square of buffer */
gdouble RMS = 0.0; /* RMS of signal in buffer */
gdouble NMS = 0.0; /* Normalized Mean Square of buffer */
static gboolean silent_prev = FALSE; /* previous value of silent */
GstBuffer *prebuf; /* pointer to a prebuffer element */
g_return_val_if_fail (pad != NULL, GST_FLOW_ERROR);
@ -224,11 +224,6 @@ gst_cutter_chain (GstPad * pad, GstBuffer * buf)
g_return_val_if_fail (filter != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_CUTTER (filter), GST_FLOW_ERROR);
if (gst_audio_is_buffer_framed (pad, buf) == FALSE) {
g_warning ("audio buffer is not framed !\n");
return GST_FLOW_ERROR;
}
if (!filter->have_caps)
gst_cutter_get_caps (pad, filter);
@ -254,7 +249,7 @@ gst_cutter_chain (GstPad * pad, GstBuffer * buf)
break;
}
silent_prev = filter->silent;
filter->silent_prev = filter->silent;
RMS = sqrt (NMS);
/* if RMS below threshold, add buffer length to silent run length count
@ -280,7 +275,7 @@ gst_cutter_chain (GstPad * pad, GstBuffer * buf)
/* 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 != filter->silent_prev) {
if (filter->silent) {
GstMessage *m =
gst_cutter_message_new (filter, FALSE, GST_BUFFER_TIMESTAMP (buf));
@ -323,6 +318,8 @@ gst_cutter_chain (GstPad * pad, GstBuffer * buf)
/* only pass buffers if we don't leak */
if (!filter->leaky)
gst_pad_push (filter->srcpad, prebuf);
else
gst_buffer_unref (prebuf);
}
} else
gst_pad_push (filter->srcpad, buf);
@ -422,14 +419,16 @@ GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
void
gst_cutter_get_caps (GstPad * pad, GstCutter * filter)
{
const GstCaps *caps = NULL;
GstCaps *caps;
GstStructure *structure;
caps = GST_PAD_CAPS (pad);
caps = gst_pad_get_caps (pad);
/* FIXME : Please change this to a better warning method ! */
g_assert (caps != NULL);
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "width", &filter->width);
filter->max_sample = 1 << (filter->width - 1); /* signed */
filter->have_caps = TRUE;
gst_caps_unref (caps);
}

View file

@ -57,6 +57,7 @@ struct _GstCutter
double silent_run_length; /* how long has it been below threshold ? */
gboolean silent;
gboolean silent_prev;
double pre_length; /* how long can the pre-record buffer be ? */
double pre_run_length; /* how long is it currently ? */