gst/qtdemux/qtdemux.c: Series of memleak fixes:

Original commit message from CVS:
* gst/qtdemux/qtdemux.c: (gst_qtdemux_class_init),
(gst_qtdemux_init), (gst_qtdemux_dispose),
(gst_qtdemux_add_stream), (qtdemux_parse_trak):
Series of memleak fixes:
- Unref the GstAdapter in finalize.
- Use gst_pad_new_from_static_template(), shorter and safer.
- Free unused QtDemuxStream when not used.
This commit is contained in:
Edward Hervey 2006-03-15 14:39:25 +00:00
parent 6fe8d34129
commit 3424048158

View file

@ -231,6 +231,7 @@ static const guint32 ff_qt_grayscale_palette_256[256] = {
static void gst_qtdemux_class_init (GstQTDemuxClass * klass); static void gst_qtdemux_class_init (GstQTDemuxClass * klass);
static void gst_qtdemux_base_init (GstQTDemuxClass * klass); static void gst_qtdemux_base_init (GstQTDemuxClass * klass);
static void gst_qtdemux_init (GstQTDemux * quicktime_demux); static void gst_qtdemux_init (GstQTDemux * quicktime_demux);
static void gst_qtdemux_dispose (GObject * object);
static GstStateChangeReturn gst_qtdemux_change_state (GstElement * element, static GstStateChangeReturn gst_qtdemux_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static void gst_qtdemux_loop (GstPad * pad); static void gst_qtdemux_loop (GstPad * pad);
@ -309,6 +310,8 @@ gst_qtdemux_class_init (GstQTDemuxClass * klass)
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
gobject_class->dispose = gst_qtdemux_dispose;
gstelement_class->change_state = gst_qtdemux_change_state; gstelement_class->change_state = gst_qtdemux_change_state;
} }
@ -316,8 +319,7 @@ static void
gst_qtdemux_init (GstQTDemux * qtdemux) gst_qtdemux_init (GstQTDemux * qtdemux)
{ {
qtdemux->sinkpad = qtdemux->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_static_template (&gst_qtdemux_sink_template, "sink");
(&gst_qtdemux_sink_template), "sink");
gst_pad_set_activate_function (qtdemux->sinkpad, qtdemux_sink_activate); gst_pad_set_activate_function (qtdemux->sinkpad, qtdemux_sink_activate);
gst_pad_set_activatepull_function (qtdemux->sinkpad, gst_pad_set_activatepull_function (qtdemux->sinkpad,
qtdemux_sink_activate_pull); qtdemux_sink_activate_pull);
@ -338,6 +340,17 @@ gst_qtdemux_init (GstQTDemux * qtdemux)
qtdemux->mdatbuffer = NULL; qtdemux->mdatbuffer = NULL;
} }
static void
gst_qtdemux_dispose (GObject * object)
{
GstQTDemux *qtdemux = GST_QTDEMUX (object);
if (qtdemux->adapter) {
g_object_unref (G_OBJECT (qtdemux->adapter));
qtdemux->adapter = NULL;
}
}
#if 0 #if 0
static gboolean static gboolean
gst_qtdemux_src_convert (GstPad * pad, GstFormat src_format, gint64 src_value, gst_qtdemux_src_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
@ -1173,12 +1186,10 @@ gst_qtdemux_add_stream (GstQTDemux * qtdemux,
QtDemuxStream * stream, GstTagList * list) QtDemuxStream * stream, GstTagList * list)
{ {
if (stream->subtype == GST_MAKE_FOURCC ('v', 'i', 'd', 'e')) { if (stream->subtype == GST_MAKE_FOURCC ('v', 'i', 'd', 'e')) {
GstPadTemplate *templ;
gchar *name = g_strdup_printf ("video_%02d", qtdemux->n_video_streams); gchar *name = g_strdup_printf ("video_%02d", qtdemux->n_video_streams);
templ = gst_static_pad_template_get (&gst_qtdemux_videosrc_template); stream->pad =
stream->pad = gst_pad_new_from_template (templ, name); gst_pad_new_from_static_template (&gst_qtdemux_videosrc_template, name);
gst_object_unref (templ);
g_free (name); g_free (name);
if ((stream->n_samples == 1) && (stream->samples[0].duration == 0)) { if ((stream->n_samples == 1) && (stream->samples[0].duration == 0)) {
stream->fps_n = 0; stream->fps_n = 0;
@ -1220,8 +1231,7 @@ gst_qtdemux_add_stream (GstQTDemux * qtdemux,
gchar *name = g_strdup_printf ("audio_%02d", qtdemux->n_audio_streams); gchar *name = g_strdup_printf ("audio_%02d", qtdemux->n_audio_streams);
stream->pad = stream->pad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_static_template (&gst_qtdemux_audiosrc_template, name);
(&gst_qtdemux_audiosrc_template), name);
g_free (name); g_free (name);
if (stream->caps) { if (stream->caps) {
gst_caps_set_simple (stream->caps, gst_caps_set_simple (stream->caps,
@ -2374,8 +2384,6 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak)
GstTagList *list = NULL; GstTagList *list = NULL;
const gchar *codec = NULL; const gchar *codec = NULL;
stream = g_new0 (QtDemuxStream, 1);
tkhd = qtdemux_tree_get_child_by_type (trak, FOURCC_tkhd); tkhd = qtdemux_tree_get_child_by_type (trak, FOURCC_tkhd);
g_return_if_fail (tkhd); g_return_if_fail (tkhd);
@ -2390,6 +2398,8 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak)
mdhd = qtdemux_tree_get_child_by_type (mdia, FOURCC_mdhd); mdhd = qtdemux_tree_get_child_by_type (mdia, FOURCC_mdhd);
g_assert (mdhd); g_assert (mdhd);
stream = g_new0 (QtDemuxStream, 1);
stream->timescale = QTDEMUX_GUINT32_GET (mdhd->data + 20); stream->timescale = QTDEMUX_GUINT32_GET (mdhd->data + 20);
GST_LOG ("track timescale: %d", stream->timescale); GST_LOG ("track timescale: %d", stream->timescale);
GST_LOG ("track duration: %d", QTDEMUX_GUINT32_GET (mdhd->data + 24)); GST_LOG ("track duration: %d", QTDEMUX_GUINT32_GET (mdhd->data + 24));
@ -2405,6 +2415,7 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak)
"found, assuming preview image or something; skipping track", "found, assuming preview image or something; skipping track",
QTDEMUX_GUINT32_GET (mdhd->data + 24), stream->timescale, QTDEMUX_GUINT32_GET (mdhd->data + 24), stream->timescale,
qtdemux->duration, qtdemux->timescale); qtdemux->duration, qtdemux->timescale);
g_free (stream);
return; return;
} }
@ -2666,6 +2677,7 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak)
} else { } else {
GST_INFO ("unknown subtype %" GST_FOURCC_FORMAT, GST_INFO ("unknown subtype %" GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (stream->subtype)); GST_FOURCC_ARGS (stream->subtype));
g_free (stream);
return; return;
} }