Gstreamer: How do Gstreamer deletes its object

539 views Asked by At

I am quite confused about the above topic and its question. I understand from the tutorial and webpage API that to delete an object,

  • you should use gst_object_unref(obj) which would decrement the reference value count by one.
  • When the reference count of object reaches zero, the object will be automatically deleted

However there seem to be functions that will increase the internal reference count of object, correct me if i am wrong

For example, I write a snippet of the function to sync a newly joined element with a pipeline. The reference count increase to 4 from 1

//// record -> mfsink is the splitmux
g_print("ref count (1) splitmuxsink is %d \n", GST_OBJECT_REFCOUNT(record->mfsink));

    /// set to playing
    if (!gst_element_sync_state_with_parent  (GST_ELEMENT (record->mfsink)))
    {
        g_error ("Failed to go into PLAYING state");
        return -4;
    }
    else
    {
        g_print("Splitmux set to playing \n);
    }

    g_print("thread Live: ref count (2) of splitmuxsink is %d \n", GST_OBJECT_REFCOUNT(record->mfsink));

The result:

ref count of (1) splitmuxsink is 1 
Splitmux set to playing.
ref count of (2) splitmuxsink is 4 

Where else, if we call gst_object_unref() function, it will only unreference the oreference counter by 1.

Similar with some other functions gst_element_set_state and gst_element_request_pad will increase reference count by 3 and 2 respectively.

I am trying to "recreate/refresh" an object in dynamic pipeline, so that each iteration of start/stop will create/renew an object (ok that would create overhead) but it seems that to delete an object is impossible.

Or it is possible? Thanks for your help

Regards

1

There are 1 answers

1
Uğur On

I think it will not be appropriate approach to that problem.

You can use GST_OBJECT_REFCOUNT_VALUE macro for iteration over "while loop".

while(GST_OBJECT_REFCOUNT_VALUE(obj))
{
    gst_object_unref (obj);
}