From 758cd8fd1855f26d4e59ca1036e71d043aa9aaa1 Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Fri, 28 Oct 2005 19:19:40 +0000 Subject: [PATCH] Add checks for return values from gst_pad_push and gst_pad_alloc_buffer. Original commit message from CVS: Add checks for return values from gst_pad_push and gst_pad_alloc_buffer. --- ChangeLog | 7 +++++++ common | 2 +- ext/speex/gstspeexenc.c | 46 +++++++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2ad96dbf0..3740b960f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-10-28 Edgard Lima + + * ext/speex/gstspeexenc.c: (gst_speexenc_chain), + (gst_speexenc_push_buffer): + Add checks for return values from gst_pad_push and + gst_pad_alloc_buffer. + 2005-10-28 Michal Benes Reviewed by: Tim-Philipp Müller diff --git a/common b/common index 1cb5d7b76a..a0c6a14dbc 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 1cb5d7b76a01c711674c752015089e70c394fa99 +Subproject commit a0c6a14dbc3cb62bf513502eaef83d0600a7c1ca diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c index bd84ea7f5d..8dea5a0736 100644 --- a/ext/speex/gstspeexenc.c +++ b/ext/speex/gstspeexenc.c @@ -813,17 +813,15 @@ gst_speexenc_buffer_from_data (GstSpeexEnc * speexenc, guchar * data, return outbuf; } + /* push out the buffer and do internal bookkeeping */ -static void +static GstFlowReturn gst_speexenc_push_buffer (GstSpeexEnc * speexenc, GstBuffer * buffer) { speexenc->bytes_out += GST_BUFFER_SIZE (buffer); - if (GST_PAD_IS_USABLE (speexenc->srcpad)) { - gst_pad_push (speexenc->srcpad, buffer); - } else { - gst_buffer_unref (buffer); - } + return gst_pad_push (speexenc->srcpad, buffer); + } static GstCaps * @@ -890,18 +888,21 @@ gst_speexenc_sinkevent (GstPad * pad, GstEvent * event) return res; } + static GstFlowReturn gst_speexenc_chain (GstPad * pad, GstBuffer * buf) { GstSpeexEnc *speexenc; + GstFlowReturn ret = GST_FLOW_OK; - speexenc = GST_SPEEXENC (GST_PAD_PARENT (pad)); + speexenc = GST_SPEEXENC (gst_pad_get_parent (pad)); if (!speexenc->setup) { gst_buffer_unref (buf); GST_ELEMENT_ERROR (speexenc, CORE, NEGOTIATION, (NULL), ("encoder not initialized (input is not audio?)")); - return GST_FLOW_UNEXPECTED; + ret = GST_FLOW_UNEXPECTED; + goto error; } if (!speexenc->header_sent) { @@ -939,8 +940,15 @@ gst_speexenc_chain (GstPad * pad, GstBuffer * buf) gst_buffer_set_caps (buf2, caps); /* push out buffers */ - gst_speexenc_push_buffer (speexenc, buf1); - gst_speexenc_push_buffer (speexenc, buf2); + if (GST_FLOW_OK != (ret = gst_speexenc_push_buffer (speexenc, buf1))) { + gst_buffer_unref (buf1); + goto error; + } + + if (GST_FLOW_OK != (ret = gst_speexenc_push_buffer (speexenc, buf2))) { + gst_buffer_unref (buf2); + goto error; + } speex_bits_init (&speexenc->bits); speex_bits_reset (&speexenc->bits); @@ -983,10 +991,14 @@ gst_speexenc_chain (GstPad * pad, GstBuffer * buf) speex_bits_insert_terminator (&speexenc->bits); outsize = speex_bits_nbytes (&speexenc->bits); - gst_pad_alloc_buffer (speexenc->srcpad, + ret = gst_pad_alloc_buffer (speexenc->srcpad, GST_BUFFER_OFFSET_NONE, outsize, GST_PAD_CAPS (speexenc->srcpad), &outbuf); + if (GST_FLOW_OK != ret) { + goto error; + } + written = speex_bits_write (&speexenc->bits, (gchar *) GST_BUFFER_DATA (outbuf), outsize); g_assert (written == outsize); @@ -1000,13 +1012,21 @@ gst_speexenc_chain (GstPad * pad, GstBuffer * buf) GST_BUFFER_OFFSET_END (outbuf) = speexenc->frameno * frame_size - speexenc->lookahead; - gst_speexenc_push_buffer (speexenc, outbuf); + if (GST_FLOW_OK != (ret = gst_speexenc_push_buffer (speexenc, outbuf))) { + printf ("ret = %d\n", ret); + // gst_buffer_unref(outbuf); + // goto error; + } } } - return GST_FLOW_OK; +error: + + gst_object_unref (speexenc); + return ret; } + static void gst_speexenc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)