Fixed some mem-leaks in xvid.

Original commit message from CVS:
Fixed some mem-leaks in xvid.
This commit is contained in:
Edgard Lima 2005-12-15 14:39:00 +00:00
parent e1eae4061d
commit 9a85a17c4d
4 changed files with 88 additions and 37 deletions

View File

@ -1,3 +1,10 @@
2005-12-15 Edgard Lima <edgard.lima@indt.org.br>
* ext/xvid/Makefile.am:
* ext/xvid/gstxviddec.c:
* ext/xvid/gstxvidenc.c:
Fixed some mem-leaks in xvid.
2005-12-14 Edgard Lima <edgard.lima@indt.org.br> 2005-12-14 Edgard Lima <edgard.lima@indt.org.br>
* configure.ac: * configure.ac:

View File

@ -2,8 +2,8 @@
plugin_LTLIBRARIES = libgstxvid.la plugin_LTLIBRARIES = libgstxvid.la
libgstxvid_la_SOURCES = gstxvidenc.c gstxviddec.c gstxvid.c libgstxvid_la_SOURCES = gstxvidenc.c gstxviddec.c gstxvid.c
libgstxvid_la_CFLAGS = $(GST_CFLAGS) $(XVID_CFLAGS) libgstxvid_la_CFLAGS = $(GST_CFLAGS) $(XVID_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstxvid_la_LIBADD = $(XVID_LIBS) libgstxvid_la_LIBADD = $(XVID_LIBS) $(GST_PLUGINS_BASE_LIBS)
libgstxvid_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstxvid_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstxvidenc.h gstxviddec.h gstxvid.h noinst_HEADERS = gstxvidenc.h gstxviddec.h gstxvid.h

View File

@ -238,16 +238,16 @@ gst_xviddec_chain (GstPad * pad, GstBuffer * buf)
} }
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (xviddec->srcpad)); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (xviddec->srcpad));
gst_pad_push (xviddec->srcpad, outbuf); ret = gst_pad_push (xviddec->srcpad, outbuf);
gst_buffer_unref (buf);
return ret; goto cleanup;
not_negotiated: not_negotiated:
{ {
GST_ELEMENT_ERROR (xviddec, CORE, NEGOTIATION, (NULL), GST_ELEMENT_ERROR (xviddec, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before chain function")); ("format wasn't negotiated before chain function"));
gst_buffer_unref (buf); ret = GST_FLOW_NOT_NEGOTIATED;
return GST_FLOW_NOT_NEGOTIATED; goto cleanup;
} }
not_decoding: not_decoding:
@ -255,16 +255,22 @@ not_decoding:
GST_ELEMENT_ERROR (xviddec, STREAM, DECODE, (NULL), GST_ELEMENT_ERROR (xviddec, STREAM, DECODE, (NULL),
("Error decoding xvid frame: %s (%d)\n", gst_xvid_error (error), ("Error decoding xvid frame: %s (%d)\n", gst_xvid_error (error),
error)); error));
gst_buffer_unref (buf);
gst_buffer_unref (outbuf); 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 static gboolean
gst_xviddec_negotiate (GstXvidDec * xviddec) gst_xviddec_negotiate (GstXvidDec * xviddec)
{ {
GstCaps *caps = NULL;
gint csp[] = { gint csp[] = {
XVID_CSP_I420, XVID_CSP_I420,
XVID_CSP_YV12, XVID_CSP_YV12,
@ -283,23 +289,29 @@ gst_xviddec_negotiate (GstXvidDec * xviddec)
0 0
}, i; }, i;
caps = gst_caps_new_empty ();
for (i = 0; csp[i] != 0; i++) { for (i = 0; csp[i] != 0; i++) {
GstCaps *one = gst_xvid_csp_to_caps (csp[i], xviddec->width, GstCaps *one = gst_xvid_csp_to_caps (csp[i], xviddec->width,
xviddec->height, xviddec->fps_n, xviddec->fps_d); xviddec->height, xviddec->fps_n, xviddec->fps_d);
if (gst_pad_set_caps (xviddec->srcpad, one)) { if (one) {
GstStructure *structure = gst_caps_get_structure (one, 0);
xviddec->csp = gst_xvid_structure_to_csp (structure, xviddec->width, if (gst_pad_set_caps (xviddec->srcpad, one)) {
&xviddec->stride, &xviddec->bpp); GstStructure *structure = gst_caps_get_structure (one, 0);
if (xviddec->csp < 0) { xviddec->csp = gst_xvid_structure_to_csp (structure, xviddec->width,
return FALSE; &xviddec->stride, &xviddec->bpp);
if (xviddec->csp < 0) {
return FALSE;
}
break;
} }
break; gst_caps_unref (one);
} }
} }
gst_xviddec_setup (xviddec); gst_xviddec_setup (xviddec);
@ -312,6 +324,7 @@ gst_xviddec_setcaps (GstPad * pad, GstCaps * caps)
GstXvidDec *xviddec = GST_XVIDDEC (gst_pad_get_parent (pad)); GstXvidDec *xviddec = GST_XVIDDEC (gst_pad_get_parent (pad));
GstStructure *structure; GstStructure *structure;
const GValue *fps; const GValue *fps;
gboolean ret = FALSE;
/* if there's something old around, remove it */ /* if there's something old around, remove it */
if (xviddec->handle) { if (xviddec->handle) {
@ -319,7 +332,8 @@ gst_xviddec_setcaps (GstPad * pad, GstCaps * caps)
} }
if (!gst_pad_set_caps (xviddec->srcpad, 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 /* 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); gst_structure_get_int (structure, "height", &xviddec->height);
fps = gst_structure_get_value (structure, "framerate"); 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_n = gst_value_get_fraction_numerator (fps);
xviddec->fps_d = gst_value_get_fraction_denominator (fps); xviddec->fps_d = gst_value_get_fraction_denominator (fps);
} else { } else {
xviddec->fps_n = -1; xviddec->fps_n = -1;
} }
return gst_xviddec_negotiate (xviddec); ret = gst_xviddec_negotiate (xviddec);
done:
gst_object_unref (xviddec);
return ret;
} }
static GstStateChangeReturn static GstStateChangeReturn

View File

@ -297,7 +297,8 @@ gst_xvidenc_chain (GstPad * pad, GstBuffer * buf)
GstBuffer *outbuf; GstBuffer *outbuf;
xvid_enc_frame_t xframe; xvid_enc_frame_t xframe;
xvid_enc_stats_t xstats; xvid_enc_stats_t xstats;
gint ret; gint res;
GstFlowReturn ret = GST_FLOW_OK;
outbuf = gst_buffer_new_and_alloc (xvidenc->buffer_size << 10); outbuf = gst_buffer_new_and_alloc (xvidenc->buffer_size << 10);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); 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 */ xframe.length = GST_BUFFER_SIZE (outbuf); /* GST_BUFFER_MAXSIZE */
gst_xvid_init_struct (xstats); 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) { &xframe, &xstats)) < 0) {
GST_ELEMENT_ERROR (xvidenc, LIBRARY, ENCODE, (NULL), GST_ELEMENT_ERROR (xvidenc, LIBRARY, ENCODE, (NULL),
("Error encoding xvid frame: %s (%d)", gst_xvid_error (ret), ret)); ("Error encoding xvid frame: %s (%d)", gst_xvid_error (res), res));
gst_buffer_unref (buf);
gst_buffer_unref (outbuf); gst_buffer_unref (outbuf);
return GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
goto cleanup;
} }
GST_BUFFER_SIZE (outbuf) = xstats.length; GST_BUFFER_SIZE (outbuf) = xstats.length;
/* go out, multiply! */ /* go out, multiply! */
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (xvidenc->srcpad)); 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 */ /* proclaim destiny */
g_signal_emit (G_OBJECT (xvidenc), gst_xvidenc_signals[FRAME_ENCODED], 0); g_signal_emit (G_OBJECT (xvidenc), gst_xvidenc_signals[FRAME_ENCODED], 0);
/* until the final judgement */ /* until the final judgement */
cleanup:
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_OK; gst_object_unref (xvidenc);
return ret;
} }
static gboolean static gboolean
gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps) gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstCaps *new_caps = NULL;
GstXvidEnc *xvidenc; GstXvidEnc *xvidenc;
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
const gchar *mime; const gchar *mime;
gint w, h; gint w, h;
const GValue *fps; const GValue *fps;
gint xvid_cs = -1, stride = -1; gint xvid_cs = -1, stride = -1;
gboolean ret = FALSE;
xvidenc = GST_XVIDENC (gst_pad_get_parent (pad)); 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); gst_structure_get_int (structure, "height", &h);
fps = gst_structure_get_value (structure, "framerate"); 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_n = gst_value_get_fraction_numerator (fps);
xvidenc->fps_d = gst_value_get_fraction_denominator (fps); xvidenc->fps_d = gst_value_get_fraction_denominator (fps);
} else { } else {
@ -389,24 +396,41 @@ gst_xvidenc_setcaps (GstPad * pad, GstCaps * caps)
xvidenc->stride = stride; xvidenc->stride = stride;
if (gst_xvidenc_setup (xvidenc)) { if (gst_xvidenc_setup (xvidenc)) {
GstCaps *new_caps = NULL;
new_caps = gst_caps_new_simple ("video/x-xvid", new_caps = gst_caps_new_simple ("video/x-xvid",
"width", G_TYPE_INT, w, "width", G_TYPE_INT, w,
"height", G_TYPE_INT, h, "height", G_TYPE_INT, h,
"framerate", GST_TYPE_FRACTION, xvidenc->fps_n, xvidenc->fps_d, NULL); "framerate", GST_TYPE_FRACTION, xvidenc->fps_n, xvidenc->fps_d, NULL);
if (!gst_pad_set_caps (xvidenc->srcpad, new_caps)) {
if (xvidenc->handle) { if (new_caps) {
xvid_encore (xvidenc->handle, XVID_ENC_DESTROY, NULL, NULL);
xvidenc->handle = 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;
}
ret = FALSE;
goto cleanup;
} }
return FALSE; ret = TRUE;
goto cleanup;
} }
return TRUE;
} }
/* if we got here - it's not good */ /* 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;
} }