summaryrefslogtreecommitdiff
path: root/ext/xvid/gstxvidenc.c
diff options
context:
space:
mode:
authorEdgard Lima <edgard.lima@indt.org.br>2005-12-15 14:39:00 +0000
committerEdgard Lima <edgard.lima@indt.org.br>2005-12-15 14:39:00 +0000
commit9a85a17c4d5ad1aa5000264f56d7ea801c3b5ce7 (patch)
tree81e5662fabbe95dc55469d9e196533c045b11942 /ext/xvid/gstxvidenc.c
parente1eae4061d4a64a8b5f06e20ed8a3ce94d27dbac (diff)
downloadgstreamer-plugins-bad-9a85a17c4d5ad1aa5000264f56d7ea801c3b5ce7.tar.gz
Fixed some mem-leaks in xvid.
Original commit message from CVS: Fixed some mem-leaks in xvid.
Diffstat (limited to 'ext/xvid/gstxvidenc.c')
-rw-r--r--ext/xvid/gstxvidenc.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/ext/xvid/gstxvidenc.c b/ext/xvid/gstxvidenc.c
index 26f4d6c17..bc8c94249 100644
--- a/ext/xvid/gstxvidenc.c
+++ b/ext/xvid/gstxvidenc.c
@@ -297,7 +297,8 @@ gst_xvidenc_chain (GstPad * pad, GstBuffer * buf)
GstBuffer *outbuf;
xvid_enc_frame_t xframe;
xvid_enc_stats_t xstats;
- gint ret;
+ gint res;
+ GstFlowReturn ret = GST_FLOW_OK;
outbuf = gst_buffer_new_and_alloc (xvidenc->buffer_size << 10);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
@@ -328,39 +329,45 @@ gst_xvidenc_chain (GstPad * pad, GstBuffer * buf)
xframe.length = GST_BUFFER_SIZE (outbuf); /* GST_BUFFER_MAXSIZE */
gst_xvid_init_struct (xstats);
- if ((ret = xvid_encore (xvidenc->handle, XVID_ENC_ENCODE,
+ if ((res = xvid_encore (xvidenc->handle, XVID_ENC_ENCODE,
&xframe, &xstats)) < 0) {
GST_ELEMENT_ERROR (xvidenc, LIBRARY, ENCODE, (NULL),
- ("Error encoding xvid frame: %s (%d)", gst_xvid_error (ret), ret));
- gst_buffer_unref (buf);
+ ("Error encoding xvid frame: %s (%d)", gst_xvid_error (res), res));
gst_buffer_unref (outbuf);
- return GST_FLOW_ERROR;
+ ret = GST_FLOW_ERROR;
+ goto cleanup;
}
GST_BUFFER_SIZE (outbuf) = xstats.length;
/* go out, multiply! */
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (xvidenc->srcpad));
- gst_pad_push (xvidenc->srcpad, outbuf);
+ ret = gst_pad_push (xvidenc->srcpad, outbuf);
/* proclaim destiny */
g_signal_emit (G_OBJECT (xvidenc), gst_xvidenc_signals[FRAME_ENCODED], 0);
/* until the final judgement */
+
+cleanup:
+
gst_buffer_unref (buf);
- return GST_FLOW_OK;
+ gst_object_unref (xvidenc);
+ return ret;
}
static gboolean
gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps)
{
+ GstCaps *new_caps = NULL;
GstXvidEnc *xvidenc;
GstStructure *structure = gst_caps_get_structure (caps, 0);
const gchar *mime;
gint w, h;
const GValue *fps;
gint xvid_cs = -1, stride = -1;
+ gboolean ret = FALSE;
xvidenc = GST_XVIDENC (gst_pad_get_parent (pad));
@@ -374,7 +381,7 @@ gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps)
gst_structure_get_int (structure, "height", &h);
fps = gst_structure_get_value (structure, "framerate");
- if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
+ if (fps != NULL) {
xvidenc->fps_n = gst_value_get_fraction_numerator (fps);
xvidenc->fps_d = gst_value_get_fraction_denominator (fps);
} else {
@@ -389,24 +396,41 @@ gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps)
xvidenc->stride = stride;
if (gst_xvidenc_setup (xvidenc)) {
- GstCaps *new_caps = NULL;
new_caps = gst_caps_new_simple ("video/x-xvid",
"width", G_TYPE_INT, w,
"height", G_TYPE_INT, h,
"framerate", GST_TYPE_FRACTION, xvidenc->fps_n, xvidenc->fps_d, NULL);
- if (!gst_pad_set_caps (xvidenc->srcpad, new_caps)) {
- if (xvidenc->handle) {
- xvid_encore (xvidenc->handle, XVID_ENC_DESTROY, NULL, NULL);
- xvidenc->handle = NULL;
+
+ if (new_caps) {
+
+ if (!gst_pad_set_caps (xvidenc->srcpad, new_caps)) {
+ if (xvidenc->handle) {
+ xvid_encore (xvidenc->handle, XVID_ENC_DESTROY, NULL, NULL);
+ xvidenc->handle = NULL;
+ }
+ ret = FALSE;
+ goto cleanup;
}
- return FALSE;
+ ret = TRUE;
+ goto cleanup;
+
}
- return TRUE;
+
}
/* if we got here - it's not good */
- return FALSE;
+ ret = FALSE;
+
+cleanup:
+
+ if (new_caps) {
+ gst_caps_unref (new_caps);
+ }
+
+ gst_object_unref (xvidenc);
+ return ret;
+
}