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 786740 - appsink: should not keep a ref on the preroll buffer all the time
appsink: should not keep a ref on the preroll buffer all the time
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other All
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-08-24 09:34 UTC by Julien Isorce
Modified: 2017-09-19 08:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
appsink: do a deep copy of the preroll buffer if it belongs to a pool (1.25 KB, patch)
2017-08-24 09:34 UTC, Julien Isorce
none Details | Review
appsink: unref preroll buffer upon pull (2.63 KB, patch)
2017-08-29 08:58 UTC, Julien Isorce
none Details | Review
appsink: unref preroll buffer upon pull (5.65 KB, patch)
2017-08-29 10:57 UTC, Julien Isorce
committed Details | Review
appsink: also clear preroll buffer in _pull_sample (2.36 KB, patch)
2017-09-18 16:19 UTC, Julien Isorce
committed Details | Review

Description Julien Isorce 2017-08-24 09:34:54 UTC
Created attachment 358309 [details] [review]
appsink: do a deep copy of the preroll buffer if it belongs to a pool

Otherwise the buffer pool will never re-use this buffer. Which is a problem if it has a limited number of buffers.

According to appsink's doc the preroll buffer remains available to the application even after EOS.

Do a deep copy instead.
Comment 1 Tim-Philipp Müller 2017-08-24 09:42:19 UTC
Weird, why do we hang onto the preroll buffer even after EOS and/or after we start playing?

Patch looks fine to me (if we need/want to support this).
Comment 2 Julien Isorce 2017-08-24 09:53:03 UTC
It is not to address a hang issue here (though it could happen in some situation). It is just that the buffer does not return to its pull while the pipeline is playing. There could be no problem about it but it just looks wrong. And I suspect appsink->preroll_buffer was designed without buffer pool consideration in the first place.

For example: if a buffer pool is configured with min=max=N buffers then the pool will iterate over N-1 buffers since one is kept all the time by appsink->preroll_buffer.
Comment 3 Tim-Philipp Müller 2017-08-24 09:59:13 UTC
hang on to = keep around :)
Comment 4 Julien Isorce 2017-08-24 10:02:20 UTC
(In reply to Tim-Philipp Müller from comment #3)
> hang on to = keep around :)

ah got it thx! :)
Comment 5 Julien Isorce 2017-08-24 10:40:45 UTC
(In reply to Tim-Philipp Müller from comment #1)
> Weird, why do we hang onto the preroll buffer even after EOS and/or after we
> start playing?

Yes strange. It behaves like this since its initial implementation dd72f88a8c56126a0b74e98b35151c6d124b9ade. At least appsink should clear its local ref once the app has pulled it out, like for other samples. But pb remains if the app does not care about the preroll buffer since it can get it from the pull-sample callback anyway.

> 
> Patch looks fine to me (if we need/want to support this).

Oki thx. I think it improves the situation at minimum while not breaking any existing app that would need to pull the preroll buffer again. Let me know if I can push it.
Comment 6 Nicolas Dufresne (ndufresne) 2017-08-26 01:13:42 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 7 Nicolas Dufresne (ndufresne) 2017-08-26 01:15:35 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 8 Nicolas Dufresne (ndufresne) 2017-08-26 01:15:37 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 9 Nicolas Dufresne (ndufresne) 2017-08-26 01:16:03 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 10 Nicolas Dufresne (ndufresne) 2017-08-26 01:16:03 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 11 Nicolas Dufresne (ndufresne) 2017-08-26 01:16:03 UTC
Review of attachment 358309 [details] [review]:

I'm effraid this will be disastrous for scrubs in pause. You could maybe do the copy on drains query, allocation query and when receiving the eos.
Comment 12 Julien Isorce 2017-08-29 08:58:03 UTC
Created attachment 358658 [details] [review]
appsink: unref preroll buffer upon pull

There is no reason for appsink to hang onto the preroll buffer.
If needed, the application can just keep a ref on this buffer
after calling gst_app_sink_try_pull_preroll.
Comment 13 Julien Isorce 2017-08-29 10:57:01 UTC
Created attachment 358668 [details] [review]
appsink: unref preroll buffer upon pull

Added unit test
Comment 14 Sebastian Dröge (slomo) 2017-09-07 10:41:15 UTC
Sounds good to me, it's just a small behaviour change that might break applications Should be fine for 1.14 (put into release notes!), don't backport to 1.12
Comment 15 Nicolas Dufresne (ndufresne) 2017-09-12 13:21:09 UTC
Review of attachment 358668 [details] [review]:

I think it's better this way, the old behaviour seems unexpected. Can we also rename ->preroll into ->preroll_buffer ? Looks like a boolean otherwise.
Comment 16 Julien Isorce 2017-09-13 13:18:05 UTC
(In reply to Nicolas Dufresne (stormer) from comment #15)
> rename ->preroll into ->preroll_buffer ? Looks like a boolean otherwise.

Sure, done:

commit c134a3c21bf5c360a607d21f805f4cde44efe1a0
Author: Julien Isorce <jisorce@oblong.com>
Date:   Wed Sep 13 14:06:43 2017 +0100

    appsink: rename GstBuffer *preroll to preroll_buffer
    
    priv->preroll can be confused with basesink_class->preroll
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786740
Comment 17 Julien Isorce 2017-09-13 13:18:24 UTC
Comment on attachment 358668 [details] [review]
appsink: unref preroll buffer upon pull

commit 68518acb53d4808cf8352ed4fd1cb8b331553559
Author: Julien Isorce <jisorce@oblong.com>
Date:   Tue Aug 29 09:47:51 2017 +0100

    appsink: unref preroll buffer upon pull
    
    There is no reason for appsink to hang onto the preroll buffer.
    If needed, the application can just keep a ref on this buffer
    after calling gst_app_sink_try_pull_preroll.
    
    Also added unit test 'test_pull_preroll'
      make elements/appsink.check
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786740
Comment 18 Tim-Philipp Müller 2017-09-13 17:02:00 UTC
Looking at the commit, why do we clear the preroll buffer only on try_pull_preroll() ?

Shouldn't we also clear it when going to playing and/or pulling a normal buffer i.e. if no one actually cares about the preroll buffer?
Comment 19 Julien Isorce 2017-09-14 10:57:53 UTC
(In reply to Tim-Philipp Müller from comment #18)
> Looking at the commit, why do we clear the preroll buffer only on
> try_pull_preroll() ?

Looking at the code in gstappsink.c we do clear it in the following places:
- GST_EVENT_FLUSH_STOP
- basesink_class->stop
- gobject_class->dispose
- try_pull_preroll

> Shouldn't we also clear it if no one actually cares about the preroll buffer?

I like this idea. But it does not look trivial to me to implement the condition "no one cares" because the user can still call gst_app_sink_pull_preroll even if he has not set any appsink callbacks or signals.
I tried a little bit but this does not look good at all.

Feel free to suggest a patch, otherwise let's say there is nothing to do more here. Thx!
Comment 20 Tim-Philipp Müller 2017-09-14 11:07:51 UTC
I was thinking that if someone calls _pull_sample() they're probably no longer interested in any preroll samples.
Comment 21 Julien Isorce 2017-09-14 12:21:16 UTC
Make sense, so something like:

--- a/gst-libs/gst/app/gstappsink.c
+++ b/gst-libs/gst/app/gstappsink.c
@@ -1568,6 +1568,7 @@ gst_app_sink_try_pull_sample (GstAppSink * appsink, GstClockTime timeout)
   priv = appsink->priv;
 
   g_mutex_lock (&priv->mutex);
+  gst_buffer_replace (&priv->preroll_buffer, NULL);
 
?
Comment 22 Sebastian Dröge (slomo) 2017-09-18 10:37:26 UTC
Yes that
Comment 23 Julien Isorce 2017-09-18 16:19:11 UTC
Created attachment 359996 [details] [review]
appsink: also clear preroll buffer in _pull_sample
Comment 24 Julien Isorce 2017-09-19 08:20:06 UTC
Comment on attachment 359996 [details] [review]
appsink: also clear preroll buffer in _pull_sample

commit 7b1056b9467673d004ea7dd63ad91461b8f616fa
Author: Julien Isorce <jisorce@oblong.com>
Date:   Mon Sep 18 17:06:32 2017 +0100

    appsink: also clear preroll buffer in _pull_sample
    
    If someone calls gst_app_sink_try_pull_sample they are
    probably no longer interested in any preroll samples.
    
    Useful if the user has not registered a preroll appsink callback.
    
    Also added unit test 'test_do_not_care_preroll'
      make elements/appsink.check
    that fails without this patch.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786740