Properly freeing resources

Tim-Philipp Müller t.i.m at zen.co.uk
Fri Feb 22 11:40:31 PST 2013


On Wed, 2013-02-20 at 07:41 -0700, Jim wrote:

Hi,

your code looks mostly ok.

>   streamData->videoDecoder = gst_element_factory_make("vpudec",
> "videoDecoder");
>   streamData->videoSink = gst_element_factory_make("mfw_v4lsink",
> "videoSink");
>   streamData->audioDecoder =
> gst_element_factory_make("mfw_mp3decoder", "audioDecoder");

I would check these elements first, if they free all resources correctly
when being shut down and/or being shut down during playback.


>   g_object_set(G_OBJECT(streamData->videoQueue), "max-size-time", 0, 
NULL);
>   g_object_set(G_OBJECT(streamData->audioQueue), "max-size-time", 0,
> NULL);

You want (guint64)0 here.

>   g_signal_connect(streamData->demux, "pad-added",
> G_CALLBACK(pad_added_handler), streamData);

What do you do in the pad_added_handler? Are you sure you are not
leaking any references there?

>   // Retrieve pipeline signal bus
>   streamData->bus =
> gst_pipeline_get_bus(GST_PIPELINE(streamData->pipeline));
>   streamData->busWatchId = gst_bus_add_watch(streamData->bus,
> (GstBusFunc)handle_message, streamData);

FWIW, you don't have to keep a ref to the bus around if you don't need
it, you can just unref it right here and there after adding the watch if
you want to.

> Before switching to a another video, the following cleanup is done:
> 
>   gst_object_unref(streamData->bus);
>   gst_element_set_state(streamData->pipeline, GST_STATE_NULL);
>   gst_object_unref(streamData->pipeline);

You will also need to

  to g_source_remove (streamData->busWatchId)

Cheers
 -Tim




More information about the gstreamer-devel mailing list