From 4a1ceda8df71835bd62c060ad9088735a8493182 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 18 Apr 2007 12:36:37 +0000 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ common | 2 +- gst/cutter/gstcutter.c | 19 +++++++++---------- gst/cutter/gstcutter.h | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b84c215c..8b4121421 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-04-18 Michael Smith + + * 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 * gst/wavenc/gstwavenc.c: (gst_wavenc_create_header_buf), diff --git a/common b/common index 9097e252e..dae6fa1f5 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 9097e252e477e18182f08a032d8860bdee9a0416 +Subproject commit dae6fa1f592c9231820c2135b8b1b3c2b0875ef6 diff --git a/gst/cutter/gstcutter.c b/gst/cutter/gstcutter.c index 9170b3313..03dc9dce5 100644 --- a/gst/cutter/gstcutter.c +++ b/gst/cutter/gstcutter.c @@ -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); } diff --git a/gst/cutter/gstcutter.h b/gst/cutter/gstcutter.h index cace2bcff..d64c30174 100644 --- a/gst/cutter/gstcutter.h +++ b/gst/cutter/gstcutter.h @@ -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 ? */ -- 2.34.1