Unref Elements?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unref Elements?

killerrats
Administrator
*for example:*


*typedef struct* _CustomData {
GstElement* pipeline;
GstElement* rtspsrc;
GstElement* h264parse;
GstElement* decodebin;
} CustomData;

gboolean *bus_cb* (GstBus * bus, GstMessage * msg, CustomData* user_data)
{
    GstElement* src = gst_bin_get_by_name(GST_BIN(data.pipeline),"source");
    ....

    gst_object_unref(src);
}

int *main*()
{
   CustomData data;

   gst_init(NULL,NULL);

   .....

   gst_object_unref(data.pipeline);
   // never seen this in tutorials
   gst_object_unref(data.rtspsrc);
}

when you use the *gst_bin_get_by_name ()* you unref them in a method just
like in *bus_cb()*. I noticed in the tutorials you just unref the pipeline
not any of the elements that are add to the pipeline. they don't go
gst_object_unref(data.rtspsrc); or gst_object_unref(h264parse); or
gst_object_unref(decodebin);. is that something you don't have to do or
something I should be doing before I close?



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
------------------------------
Gstreamer 1.16.2
------------------------------
Windows
Reply | Threaded
Open this post in threaded view
|

Re: Unref Elements?

Nicolas Dufresne-5
Le mercredi 20 septembre 2017 à 16:45 -0700, killerrats a écrit :
> when you use the *gst_bin_get_by_name ()* you unref them in a method just
> like in *bus_cb()*. I noticed in the tutorials you just unref the pipeline
> not any of the elements that are add to the pipeline. they don't go
> gst_object_unref(data.rtspsrc); or gst_object_unref(h264parse); or
> gst_object_unref(decodebin);. is that something you don't have to do or
> something I should be doing before I close?

The GObject comes with a model of floating references. When an object
is initially created, it has a ref counting of 1 but flagged as
floating. This is the case for all objects that subclass
GInitiallyUnowned instead of GObject.

When these objects are added to a container, the container will become
the new owner of the object. This ownership is taker through calling
g_object_ref_sink(). This method will transparently take a reference on
own object, and will take over an unowned object.

That is the reason why you don't need to unref the freshly created
GstElement that you pass to a GstBin/GstPipeline. You'll find the same
in GTK with GtkWidget added to any GtkContainer.

regards,
Nicolas
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel