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 751147 - appsink: pull_preroll returns wrong segment in the sample
appsink: pull_preroll returns wrong segment in the sample
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal normal
: 1.5.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-06-18 10:42 UTC by George Kiagiadakis
Modified: 2015-08-16 13:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch that solves the issue (2.00 KB, patch)
2015-06-18 10:42 UTC, George Kiagiadakis
none Details | Review
appsink: put the correct segment in the preroll sample (2.08 KB, patch)
2015-08-14 16:52 UTC, George Kiagiadakis
committed Details | Review
tests/appsink: add test to ensure that the segment returned by pull-preroll/sample is correct (2.06 KB, patch)
2015-08-14 16:52 UTC, George Kiagiadakis
committed Details | Review
appsink: do not update preroll_caps unless the sink is prerolling (981 bytes, patch)
2015-08-14 16:53 UTC, George Kiagiadakis
committed Details | Review
appsink: unref the preroll buffer and cleanup the segments on stop() (1.03 KB, patch)
2015-08-14 16:53 UTC, George Kiagiadakis
committed Details | Review

Description George Kiagiadakis 2015-06-18 10:42:05 UTC
Created attachment 305540 [details] [review]
Patch that solves the issue

When appsink prerolls, the sample returned by pull_preroll() has a wrong segment in it. The actual segment sits and waits in appsink's internal queue until one calls pull_buffer() instead.
Comment 1 Thiago Sousa Santos 2015-06-18 15:15:44 UTC
Review of attachment 305540 [details] [review]:

::: gst-libs/gst/app/gstappsink.c
@@ +572,3 @@
       GST_DEBUG_OBJECT (appsink, "receiving SEGMENT");
       g_queue_push_tail (priv->queue, gst_event_ref (event));
+      gst_event_copy_segment (event, &priv->preroll_segment);

Doesn't this mean that it will always have the latest segment received? I think it should only consider the segment received before the preroll buffer, so it should only do this while preroll == NULL.

For consistency it might also be a good idea to init it to UNDEFINED/TIME again when ins _stop
Comment 2 George Kiagiadakis 2015-06-24 09:54:49 UTC
Indeed, it does mean that the latest segment will be received in preroll_segment. However, the same is done with preroll_caps and the preroll buffer never becomes NULL until dispose(), so checking for preroll==NULL would be problematic at this point. I guess the whole logic could be improved for optimization, but it works.

Initializing it in stop() doesn't sound like it has any advantage to me. A preroll can only happen in PAUSED state, so if stop() gets called (going to NULL), then start() will be called after that before a new preroll. The only potential problem is what happens if somebody calls "pull-preroll" when appsink is in the NULL state, but that is broken anyway with the current code regarding the preroll variables (buffer & caps). I would not consider fixing this as part of this patch.
Comment 3 Thiago Sousa Santos 2015-06-25 16:00:32 UTC
(In reply to George Kiagiadakis from comment #2)
> Indeed, it does mean that the latest segment will be received in
> preroll_segment. However, the same is done with preroll_caps and the preroll
> buffer never becomes NULL until dispose(), so checking for preroll==NULL
> would be problematic at this point. I guess the whole logic could be
> improved for optimization, but it works.

I'd more think of it as 'works' as you can get the wrong segment. But I agree this is an improvement anyway.

> 
> Initializing it in stop() doesn't sound like it has any advantage to me. A
> preroll can only happen in PAUSED state, so if stop() gets called (going to
> NULL), then start() will be called after that before a new preroll. The only
> potential problem is what happens if somebody calls "pull-preroll" when
> appsink is in the NULL state, but that is broken anyway with the current
> code regarding the preroll variables (buffer & caps). I would not consider
> fixing this as part of this patch.

The caps issue can be done as a separate patch/bug.
Comment 4 Tim-Philipp Müller 2015-06-25 20:24:32 UTC
A unit test would be great too :)
Comment 5 George Kiagiadakis 2015-08-14 16:52:04 UTC
Created attachment 309291 [details] [review]
appsink: put the correct segment in the preroll sample
Comment 6 George Kiagiadakis 2015-08-14 16:52:36 UTC
Created attachment 309292 [details] [review]
tests/appsink: add test to ensure that the segment returned by pull-preroll/sample is correct
Comment 7 George Kiagiadakis 2015-08-14 16:53:05 UTC
Created attachment 309293 [details] [review]
appsink: do not update preroll_caps unless the sink is prerolling
Comment 8 George Kiagiadakis 2015-08-14 16:53:33 UTC
Created attachment 309294 [details] [review]
appsink: unref the preroll buffer and cleanup the segments on stop()
Comment 9 George Kiagiadakis 2015-08-14 17:29:07 UTC
commit 897371ac4fb75e5d334702341dc641a0e96f26a2
Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date:   Fri Aug 14 18:43:03 2015 +0200

    appsink: unref the preroll buffer and cleanup the segments on stop()

    Just for consistency. No need to keep data around.

commit c3e4d8ca6fe118869506065e46fee5fe6d5bcacc
Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date:   Fri Aug 14 18:35:22 2015 +0200

    appsink: do not update preroll_caps unless the sink is prerolling

    Just for consistency with the preroll_segment

commit 41cb26b0e9969d2b49c26a259bb3bb8a6e9217d6
Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date:   Fri Aug 14 18:06:03 2015 +0200

    tests/appsink: add test to ensure that the segment returned by pull-preroll/sample is correct

    https://bugzilla.gnome.org/show_bug.cgi?id=751147
    
commit c411819452524c281b58b531829aa3914de53ef2
Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date:   Thu Jun 18 12:30:24 2015 +0200
    
    appsink: put the correct segment in the preroll sample

    last_segment is only being updated in dequeue_buffer(),
    which is only called from _pull_sample(). _pull_preroll()
    simply re-uses an old or dummy segment while the actual
    one sits and waits in the queue.

    https://bugzilla.gnome.org/show_bug.cgi?id=751147