summaryrefslogtreecommitdiffstats
path: root/ext
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
parente1eae4061d4a64a8b5f06e20ed8a3ce94d27dbac (diff)
downloadgst-plugins-bad-9a85a17c4d5ad1aa5000264f56d7ea801c3b5ce7.tar.gz
gst-plugins-bad-9a85a17c4d5ad1aa5000264f56d7ea801c3b5ce7.tar.bz2
gst-plugins-bad-9a85a17c4d5ad1aa5000264f56d7ea801c3b5ce7.zip
Fixed some mem-leaks in xvid.
Original commit message from CVS: Fixed some mem-leaks in xvid.
Diffstat (limited to 'ext')
-rw-r--r--ext/xvid/Makefile.am4
-rw-r--r--ext/xvid/gstxviddec.c58
-rw-r--r--ext/xvid/gstxvidenc.c56
3 files changed, 81 insertions, 37 deletions
diff --git a/ext/xvid/Makefile.am b/ext/xvid/Makefile.am
index b0204474..411f330f 100644
--- a/ext/xvid/Makefile.am
+++ b/ext/xvid/Makefile.am
@@ -2,8 +2,8 @@
plugin_LTLIBRARIES = libgstxvid.la
libgstxvid_la_SOURCES = gstxvidenc.c gstxviddec.c gstxvid.c
-libgstxvid_la_CFLAGS = $(GST_CFLAGS) $(XVID_CFLAGS)
-libgstxvid_la_LIBADD = $(XVID_LIBS)
+libgstxvid_la_CFLAGS = $(GST_CFLAGS) $(XVID_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
+libgstxvid_la_LIBADD = $(XVID_LIBS) $(GST_PLUGINS_BASE_LIBS)
libgstxvid_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstxvidenc.h gstxviddec.h gstxvid.h
diff --git a/ext/xvid/gstxviddec.c b/ext/xvid/gstxviddec.c
index 73601ef2..e108afc6 100644
--- a/ext/xvid/gstxviddec.c
+++ b/ext/xvid/gstxviddec.c
@@ -238,16 +238,16 @@ gst_xviddec_chain (GstPad * pad, GstBuffer * buf)
}
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (xviddec->srcpad));
- gst_pad_push (xviddec->srcpad, outbuf);
- gst_buffer_unref (buf);
- return ret;
+ ret = gst_pad_push (xviddec->srcpad, outbuf);
+
+ goto cleanup;
not_negotiated:
{
GST_ELEMENT_ERROR (xviddec, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before chain function"));
- gst_buffer_unref (buf);
- return GST_FLOW_NOT_NEGOTIATED;
+ ret = GST_FLOW_NOT_NEGOTIATED;
+ goto cleanup;
}
not_decoding:
@@ -255,16 +255,22 @@ not_decoding:
GST_ELEMENT_ERROR (xviddec, STREAM, DECODE, (NULL),
("Error decoding xvid frame: %s (%d)\n", gst_xvid_error (error),
error));
- gst_buffer_unref (buf);
gst_buffer_unref (outbuf);
- return GST_FLOW_ERROR;
+ ret = GST_FLOW_ERROR;
+ goto cleanup;
}
+
+cleanup:
+
+ gst_buffer_unref (buf);
+ gst_object_unref (xviddec);
+ return ret;
+
}
static gboolean
gst_xviddec_negotiate (GstXvidDec * xviddec)
{
- GstCaps *caps = NULL;
gint csp[] = {
XVID_CSP_I420,
XVID_CSP_YV12,
@@ -283,23 +289,29 @@ gst_xviddec_negotiate (GstXvidDec * xviddec)
0
}, i;
- caps = gst_caps_new_empty ();
for (i = 0; csp[i] != 0; i++) {
GstCaps *one = gst_xvid_csp_to_caps (csp[i], xviddec->width,
xviddec->height, xviddec->fps_n, xviddec->fps_d);
- if (gst_pad_set_caps (xviddec->srcpad, one)) {
- GstStructure *structure = gst_caps_get_structure (one, 0);
+ if (one) {
+
+ if (gst_pad_set_caps (xviddec->srcpad, one)) {
+ GstStructure *structure = gst_caps_get_structure (one, 0);
- xviddec->csp = gst_xvid_structure_to_csp (structure, xviddec->width,
- &xviddec->stride, &xviddec->bpp);
+ xviddec->csp = gst_xvid_structure_to_csp (structure, xviddec->width,
+ &xviddec->stride, &xviddec->bpp);
- if (xviddec->csp < 0) {
- return FALSE;
+ if (xviddec->csp < 0) {
+ return FALSE;
+ }
+
+ break;
}
- break;
+ gst_caps_unref (one);
+
}
+
}
gst_xviddec_setup (xviddec);
@@ -312,6 +324,7 @@ gst_xviddec_setcaps (GstPad * pad, GstCaps * caps)
GstXvidDec *xviddec = GST_XVIDDEC (gst_pad_get_parent (pad));
GstStructure *structure;
const GValue *fps;
+ gboolean ret = FALSE;
/* if there's something old around, remove it */
if (xviddec->handle) {
@@ -319,7 +332,8 @@ gst_xviddec_setcaps (GstPad * pad, GstCaps * caps)
}
if (!gst_pad_set_caps (xviddec->srcpad, caps)) {
- return FALSE;
+ ret = FALSE;
+ goto done;
}
/* if we get here, we know the input is xvid. we
@@ -330,14 +344,20 @@ gst_xviddec_setcaps (GstPad * pad, GstCaps * caps)
gst_structure_get_int (structure, "height", &xviddec->height);
fps = gst_structure_get_value (structure, "framerate");
- if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
+ if (fps != NULL) {
xviddec->fps_n = gst_value_get_fraction_numerator (fps);
xviddec->fps_d = gst_value_get_fraction_denominator (fps);
} else {
xviddec->fps_n = -1;
}
- return gst_xviddec_negotiate (xviddec);
+ ret = gst_xviddec_negotiate (xviddec);
+
+done:
+ gst_object_unref (xviddec);
+
+ return ret;
+
}
static GstStateChangeReturn
diff --git a/ext/xvid/gstxvidenc.c b/ext/xvid/gstxvidenc.c
index 26f4d6c1..bc8c9424 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;
+
}