Problem with GstQueryAllocation pool refcount
Nicolas Dufresne
nicolas at ndufresne.ca
Tue Dec 6 20:26:52 UTC 2022
Le mardi 06 décembre 2022 à 09:31 +0000, Edgar Thier via gstreamer-devel a
écrit :
> Hi,
>
> I am encountering a problem with the reference count for my custom
> GstBufferPool.
> What I am observing is that GstQuery increases the reference count but never
> seems to unref it.
>
> My allocation function looks like this (simplified):
>
> gboolean _device_allocation(GstBaseSrc* base_src, GstQuery* query)
s/_device_allocation/_decide_allocation/
> {
> // my_buffer_pool_new does:
> // GstTcamBufferPool* pool =
> // (GstTcamBufferPool*)g_object_new(GST_TYPE_MY_BUFFER_POOL, "name",
> name, NULL);
> // g_object_ref_sink(pool);
> GstBufferPool* pool = my_buffer_pool_new(GST_ELEMENT(self), caps);
> GST_ERROR("Refcount: %d", pool->object.object.ref_count);
> // Refcount: 1
> GstStructure* config = gst_buffer_pool_get_config(pool);
>
> gst_buffer_pool_config_set_params(config, caps, buffer_size, 10, 10);
> gst_buffer_pool_set_config(pool, config);
> gst_query_add_allocation_pool(query, pool, size, 10, 0);
gst_object_unref (pool);
This is because the method to store a pool in the query is not a
"transfer:floating" method. From the doc, you can see "transfer: none"
annotation.
> pool ( [transfer: none][allow-none]) – the GstBufferPool
>
> GST_ERROR("Refcount: %d", pool->object.object.ref_count);
> // Refcount: 2
>
> // store pool pointer for later cleanup
> ...
>
> return GST_BASE_SRC_CLASS(gst_tcam_mainsrc_parent_class)-
> >decide_allocation(base_src, query);
> }
>
> It remains at two even when I reach state change paused->ready where I want to
> reset the pool:
>
> _change_state(GstElement* element,
> GstStateChange change)
> {
> ....
> case GST_STATE_CHANGE_PAUSED_TO_READY:
> {
> GstBufferPool* pool = ...;
> if (pool)
> {
> gst_buffer_pool_set_active(pool, FALSE);
> GST_ERROR("Freeing pool %d", pool->object.object.ref_count);
> // Refcount: 2
> gst_object_unref(pool);
>
> pool = NULL;
> // BufferPool not freed
> }
> ...
>
>
> Am I doing something wrong?
> Do I need to execute additional steps or is this a bug with GstQuery?
>
> Thanks,
>
> Edgar
>
More information about the gstreamer-devel
mailing list