summaryrefslogtreecommitdiffstats
path: root/gst/cutter
diff options
context:
space:
mode:
authorMichael Smith <msmith@xiph.org>2007-04-18 12:36:37 +0000
committerMichael Smith <msmith@xiph.org>2007-04-18 12:36:37 +0000
commit4a1ceda8df71835bd62c060ad9088735a8493182 (patch)
tree99955a5fcda8858e8b811b6ea08a2ae8b2377c30 /gst/cutter
parent1723d916dd9dae9b3df8a32d155e1f3529b11f16 (diff)
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.
Diffstat (limited to 'gst/cutter')
-rw-r--r--gst/cutter/gstcutter.c19
-rw-r--r--gst/cutter/gstcutter.h1
2 files changed, 10 insertions, 10 deletions
diff --git a/gst/cutter/gstcutter.c b/gst/cutter/gstcutter.c
index 9170b331..03dc9dce 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 cace2bcf..d64c3017 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 ? */