After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763460 - vaapidecoder: events from frames might leak when shutting down
vaapidecoder: events from frames might leak when shutting down
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer-vaapi
git master
Other All
: Normal normal
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-03-10 14:09 UTC by Thiago Sousa Santos
Modified: 2016-04-01 13:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
videodecoder: fix events leak (2.68 KB, patch)
2016-03-10 14:10 UTC, Thiago Sousa Santos
rejected Details | Review
vaapidecode: add stop function (1.84 KB, patch)
2016-03-18 23:42 UTC, Thiago Sousa Santos
none Details | Review
vaapidecode: add stop function (2.26 KB, patch)
2016-03-31 13:57 UTC, Thiago Sousa Santos
committed Details | Review

Description Thiago Sousa Santos 2016-03-10 14:09:54 UTC
See associated patch commit message.

It was reproducible using a pipeline with dvb:// that would shutdown and restart every few seconds. This is not directly related to dvb/mpegts but it seems that hose formats output lots of tag events that makes it easy to reproduce the event leak.
Comment 1 Thiago Sousa Santos 2016-03-10 14:10:20 UTC
Created attachment 323631 [details] [review]
videodecoder: fix events leak

When a frame is released its associated events are transfered to the
'pending_events' list to be pushed with the next frame.

The leak happens because, when shutting down, videodecoder frees its
pending_events lis and then unrefs the pool. By unreffing the pool,
its associated frames are also unreffed and those frames might contain
events that would be added to the pending_events list that won't be
freed again.

We could re-free the pending_events list after unreffing the pool to
make sure those events are freed but, as the pool can have references
elsewhere, it won't guarantee that it is going to be freed at that moment.

Instead, this patch fixes it by adding a boolean to indicate whether the
videodecoder is started or not ( > READY state) and, depending on that,
the events from a released frame are directly freed or added to the
pending_events list.
Comment 2 Sebastian Dröge (slomo) 2016-03-10 18:12:40 UTC
Comment on attachment 323631 [details] [review]
videodecoder: fix events leak

I think I prefer to re-free the list :) Instead of the new boolean you can also check GST_STATE(dec) <= READY.
Comment 3 Thiago Sousa Santos 2016-03-17 18:34:37 UTC
(In reply to Sebastian Dröge (slomo) from comment #2)
> Comment on attachment 323631 [details] [review] [review]
> videodecoder: fix events leak
> 
> I think I prefer to re-free the list :) Instead of the new boolean you can
> also check GST_STATE(dec) <= READY.

Agreed on the new boolean but re-freeing the list might not always work if someone else has a reference on the bufferpool and unrefs it after videodecoder.
Comment 4 Sebastian Dröge (slomo) 2016-03-18 09:53:23 UTC
How is the events list related to a buffer pool?
Comment 5 Thiago Sousa Santos 2016-03-18 15:51:04 UTC
My mistake, it is actually gst_vaapidecode_destroy that is unreffing GstVideoCodecFrames. It is called in READY_TO_NULL. I guess we need to free all events from those frames when we reach ready state. They shouldn't make sense when a new stream is restarted.
Comment 6 Sebastian Dröge (slomo) 2016-03-18 17:44:14 UTC
In PAUSED->READY we should get rid of all frames and events and whatever else they contain
Comment 7 Thiago Sousa Santos 2016-03-18 23:42:03 UTC
Created attachment 324307 [details] [review]
vaapidecode: add stop function

In the end it seemed that it was only vaapidecode missing an implementation to videodecoder's stop function
Comment 8 Sebastian Dröge (slomo) 2016-03-19 09:17:00 UTC
Comment on attachment 323631 [details] [review]
videodecoder: fix events leak

So let's keep videodecoder as is then :)
Comment 9 Sebastian Dröge (slomo) 2016-03-19 09:17:39 UTC
Comment on attachment 324307 [details] [review]
vaapidecode: add stop function

Looks good to me
Comment 10 Thiago Sousa Santos 2016-03-28 16:36:42 UTC
Any further comments from gstreamer-vaapi maintainers?

Otherwise I'll just push it this week.
Comment 11 Víctor Manuel Jáquez Leal 2016-03-28 16:57:47 UTC
(In reply to Thiago Sousa Santos from comment #10)
> Any further comments from gstreamer-vaapi maintainers?
> 
> Otherwise I'll just push it this week.

Sorry, I lost track of this issue.

Looks good. Not a blocker, but I would try to merge, somehow, _stop()/close()/_destroy() in order to avoid code duplication.
Comment 12 Thiago Sousa Santos 2016-03-31 13:57:27 UTC
Created attachment 325087 [details] [review]
vaapidecode: add stop function

Updated moving some cleanup from finalize() to stop().

The only common call now is the _destroy() function that is called both from _close() and from _reset_full() but I'm not sure we can change much as the reset_full has to destroy the current decoder to create a new one.
Comment 13 Thiago Sousa Santos 2016-04-01 13:07:16 UTC
commit 506c9e2b5bbc50730b0083598b346b0fcc41ec78
Author: Thiago Santos <thiagoss@osg.samsung.com>
Date:   Fri Mar 18 20:00:52 2016 -0300

    vaapidecode: add stop function
    
    Clear any status on the current stream:
    
    stored frames, caps and decoder configuration
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763460