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 786739 - appsink: handle drain query
appsink: handle drain query
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other All
: Normal enhancement
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-08-24 09:31 UTC by Julien Isorce
Modified: 2017-09-19 13:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
appsink: clear queue and preroll buffer on a drain query (1.32 KB, patch)
2017-08-24 09:31 UTC, Julien Isorce
none Details | Review
appsink: on drain wait for buffers to be consumed (4.11 KB, patch)
2017-08-29 16:30 UTC, Julien Isorce
none Details | Review
appsink: on drain wait for buffers to be consumed (5.11 KB, patch)
2017-09-18 16:19 UTC, Julien Isorce
committed Details | Review

Description Julien Isorce 2017-08-24 09:31:22 UTC
Created attachment 358308 [details] [review]
appsink: clear queue and preroll buffer on a drain query

So that an upstream element can claim all buffers to return to its buffer pool.
Comment 1 Tim-Philipp Müller 2017-08-24 09:45:17 UTC
The real problem is that we don't have a proper mechanism for making elements return buffers to a pool (and make deep copies where possible).

Why are we not doing a deep copies here as well, like in the other patch?

It's not clear to me that just throwing away queued buffers is the right thing to do here for a DRAIN query? shouldn't it rather block until all these buffers have been consumed / pulled by the app?
Comment 2 Julien Isorce 2017-08-24 10:24:25 UTC
>> shouldn't it rather block until all these buffers have been consumed
>> / pulled by the app?

Looks correct indeed and the app can deal with the following to clear any local ref it keeps:

pad = gst_element_get_static_pad (appsink, "sink");
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM, query_cb, user_data, NULL);

static GstPadProbeReturn 
query_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) {

  GstQuery *query = GST_PAD_PROBE_INFO_QUERY (info);
    switch (GST_QUERY_TYPE (query)) {
      case GST_QUERY_DRAIN:
      {
        // TODO clear all local/old gst buffers that came out from appsink.
        break;
      }
      default:
        break;
    }
    return GST_PAD_PROBE_OK;
  }

}

Thx!
Comment 3 Nicolas Dufresne (ndufresne) 2017-08-26 01:10:04 UTC
Review of attachment 358308 [details] [review]:

This will lead do data lost. Only a flush can destroy queued buffers. You can could wait for the queue to be consumed, but with appsink, you'll rely on the application.
Comment 4 Julien Isorce 2017-08-29 16:30:14 UTC
Created attachment 358707 [details] [review]
appsink: on drain wait for buffers to be consumed

Wait for buffers to be consumed instead of clearing the queue. Also added unit test that would fail without this patch.
Comment 5 Nicolas Dufresne (ndufresne) 2017-09-12 13:22:50 UTC
Review of attachment 358707 [details] [review]:

Looks good, but I would like not to see yet another racy test using g_usleep(). There is so many tests to fix, let's not add more.

::: tests/check/elements/appsink.c
@@ +535,3 @@
+  GstSample *pulled_sample = NULL;
+
+  g_usleep (1 * G_USEC_PER_SEC);

Would be nice to avoid g_usleep(), it makes the tests slow and racy.
Comment 6 Julien Isorce 2017-09-18 16:19:58 UTC
Created attachment 359997 [details] [review]
appsink: on drain wait for buffers to be consumed

Addressed remarks.
Comment 7 Nicolas Dufresne (ndufresne) 2017-09-19 13:03:26 UTC
Review of attachment 359997 [details] [review]:

looks good now.
Comment 8 Julien Isorce 2017-09-19 13:43:37 UTC
Comment on attachment 359997 [details] [review]
appsink: on drain wait for buffers to be consumed

commit fc86194595955886df248452b3aee6bbdd9851cc
Author: Julien Isorce <jisorce@oblong.com>
Date:   Thu Aug 24 10:02:31 2017 +0100

    appsink: on drain wait for buffers to be consumed
    
    So that an upstream element can claim all buffers to return to its buffer pool.
    
    Added unit test 'test_query_drain'
      make elements/appsink.check
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786739