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 781673 - aggregator: always handle synchronized events on output thread
aggregator: always handle synchronized events on output thread
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 779945 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-04-24 18:36 UTC by Olivier Crête
Modified: 2017-05-20 14:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
aggregator: Only declare first buffer on actual buffer (999 bytes, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Simplify clip function (5.83 KB, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
tests: Test caps using query (1.50 KB, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Only count buffers when declaring queue full (954 bytes, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Make pad eos as soon as all buffers are processed, dont way for events (1.71 KB, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Delay clipping to output thread (10.13 KB, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Always handle sync'ed events on output thread (1.14 KB, patch)
2017-04-24 18:37 UTC, Olivier Crête
none Details | Review
aggregator: Fix indentation (1.04 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Reset pad on init (1.88 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Reset the pad's first buffer flag with the rest (1.09 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Set initial position on first buffer (1.13 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Only declare first buffer on actual buffer (2.06 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Simplify clip function (5.83 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
tests: Test caps using query (1.50 KB, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Only count buffers when declaring queue full (954 bytes, patch)
2017-05-10 00:40 UTC, Olivier Crête
none Details | Review
aggregator: Make pad eos as soon as all buffers are processed, dont way for events (1.71 KB, patch)
2017-05-10 00:41 UTC, Olivier Crête
none Details | Review
aggregator: Delay clipping to output thread (10.06 KB, patch)
2017-05-10 00:41 UTC, Olivier Crête
none Details | Review
aggregator: Always handle sync'ed events on output thread (1.14 KB, patch)
2017-05-10 00:41 UTC, Olivier Crête
none Details | Review
aggregator: Fix indentation (1.04 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Reset pad on init (1.84 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Reset the pad's first buffer flag with the rest (1.38 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Set initial position on first buffer (1.13 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Only declare first buffer on actual buffer (2.29 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Simplify clip function (5.83 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
tests: Test caps using query (2.31 KB, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Only count buffers when declaring queue full (954 bytes, patch)
2017-05-20 10:44 UTC, Olivier Crête
committed Details | Review
aggregator: Make pad eos as soon as all buffers are processed, dont way for events (1.71 KB, patch)
2017-05-20 10:45 UTC, Olivier Crête
committed Details | Review
aggregator: Delay clipping to output thread (10.19 KB, patch)
2017-05-20 10:45 UTC, Olivier Crête
committed Details | Review
aggregator: Always handle sync'ed events on output thread (1.14 KB, patch)
2017-05-20 10:45 UTC, Olivier Crête
committed Details | Review

Description Olivier Crête 2017-04-24 18:36:54 UTC
Instead of handling synchronized events sometimes on the input threads and sometimes on the output thread, always handle them on the output thread. This required fixing a couple things that were broken by this, but it should make the code more simple and help with #776931 and #780682
Comment 1 Olivier Crête 2017-04-24 18:37:13 UTC
Created attachment 350329 [details] [review]
aggregator: Only declare first buffer on actual buffer

The function needs to be unlocked if any data is received, but only
end the first buffer processing on an actual buffer. Not on synchronized events.
Comment 2 Olivier Crête 2017-04-24 18:37:17 UTC
Created attachment 350330 [details] [review]
aggregator: Simplify clip function

The return value was ignored anyway
Comment 3 Olivier Crête 2017-04-24 18:37:22 UTC
Created attachment 350331 [details] [review]
tests: Test caps using query

Sending an event can accepted event if the caps were rejected
because the event could be queued and processed later.
Comment 4 Olivier Crête 2017-04-24 18:37:26 UTC
Created attachment 350332 [details] [review]
aggregator: Only count buffers when declaring queue full
Comment 5 Olivier Crête 2017-04-24 18:37:30 UTC
Created attachment 350333 [details] [review]
aggregator: Make pad eos as soon as all buffers are processed, dont way for events
Comment 6 Olivier Crête 2017-04-24 18:37:34 UTC
Created attachment 350334 [details] [review]
aggregator: Delay clipping to output thread

This is required because the synchronized events like caps or segments
may only be processed on the output thread.
Comment 7 Olivier Crête 2017-04-24 18:37:38 UTC
Created attachment 350335 [details] [review]
aggregator: Always handle sync'ed events on output thread

Having all synchronized events always be handled on the output
thread should make synchronization easier.
Comment 8 Sebastian Dröge (slomo) 2017-05-09 12:49:12 UTC
*** Bug 779945 has been marked as a duplicate of this bug. ***
Comment 9 Sebastian Dröge (slomo) 2017-05-09 12:50:56 UTC
Go ahead, would be good to get this in as early as possible in the 1.14 release cycle now.
Comment 10 Olivier Crête 2017-05-10 00:40:28 UTC
Created attachment 351489 [details] [review]
aggregator: Fix indentation
Comment 11 Olivier Crête 2017-05-10 00:40:32 UTC
Created attachment 351490 [details] [review]
aggregator: Reset pad on init

Factor out the pad reset code from the flushing and use it on init as well
Comment 12 Olivier Crête 2017-05-10 00:40:36 UTC
Created attachment 351491 [details] [review]
aggregator: Reset the pad's first buffer flag with the rest

There is not reason to have separate code to reset this one.
Comment 13 Olivier Crête 2017-05-10 00:40:41 UTC
Created attachment 351492 [details] [review]
aggregator: Set initial position on first buffer

Set the initial position on the first buffer, otherwise the queue
will grow without limits before the output thread is started.
Comment 14 Olivier Crête 2017-05-10 00:40:44 UTC
Created attachment 351493 [details] [review]
aggregator: Only declare first buffer on actual buffer

The function needs to be unlocked if any data is received, but only
end the first buffer processing on an actual buffer, synchronized events
don't matter on the first buffer processing.
Comment 15 Olivier Crête 2017-05-10 00:40:48 UTC
Created attachment 351494 [details] [review]
aggregator: Simplify clip function

The return value was ignored anyway
Comment 16 Olivier Crête 2017-05-10 00:40:53 UTC
Created attachment 351495 [details] [review]
tests: Test caps using query

Sending an event can accepted event if the caps were rejected
because the event could be queued and processed later.
Comment 17 Olivier Crête 2017-05-10 00:40:57 UTC
Created attachment 351496 [details] [review]
aggregator: Only count buffers when declaring queue full
Comment 18 Olivier Crête 2017-05-10 00:41:02 UTC
Created attachment 351497 [details] [review]
aggregator: Make pad eos as soon as all buffers are processed, dont way for events
Comment 19 Olivier Crête 2017-05-10 00:41:06 UTC
Created attachment 351498 [details] [review]
aggregator: Delay clipping to output thread

This is required because the synchronized events like caps or segments
may only be processed on the output thread.
Comment 20 Olivier Crête 2017-05-10 00:41:11 UTC
Created attachment 351499 [details] [review]
aggregator: Always handle sync'ed events on output thread

Having all synchronized events always be handled on the output
thread should make synchronization easier.
Comment 21 Olivier Crête 2017-05-10 00:42:33 UTC
While re-testing this, I found some bugs I had introduced, any kind of review would be welcome otherwise I'll push this as-is
Comment 22 Matthew Waters (ystreet00) 2017-05-12 08:47:35 UTC
Review of attachment 351490 [details] [review]:

.

::: gst-libs/gst/base/gstaggregator.c
@@ +246,3 @@
   aggpad->priv->tail_time = GST_CLOCK_TIME_NONE;
   aggpad->priv->time_level = 0;
+  aggpad->priv->first_buffer = TRUE;

This line is different in the refactor. Is that intentional?
Comment 23 Matthew Waters (ystreet00) 2017-05-12 08:48:34 UTC
Review of attachment 351491 [details] [review]:

This makes sense with the previous comment and the changed line should be moved to this patch.
Comment 24 Matthew Waters (ystreet00) 2017-05-12 08:49:22 UTC
Review of attachment 351492 [details] [review]:

Makes sense.
Comment 25 Matthew Waters (ystreet00) 2017-05-12 08:58:51 UTC
Review of attachment 351493 [details] [review]:

This seems to make sense.

::: gst-libs/gst/base/gstaggregator.c
@@ +444,3 @@
 
+    if (pad->priv->num_buffers == 0) {
+      if (g_queue_get_length (&pad->priv->buffers) != 0)

Maybe a premature optimization but could be replaced with gst_aggregator_pad_queue_is_empty (pad) like in the original code.

@@ +486,3 @@
     GST_LOG_OBJECT (pad, "pad not ready to be aggregated yet");
     GST_OBJECT_UNLOCK (self);
+    return have_event;

The log message is not quite right here anymore
Comment 26 Matthew Waters (ystreet00) 2017-05-12 10:52:00 UTC
Review of attachment 351494 [details] [review]:

Looks sane.

::: gst-libs/gst/base/gstaggregator.h
@@ +159,3 @@
+ *                  clipping it and translating it to the current segment falls
+ *                  on the subclass. The function should use the segment of data
+ *                  and the  negotiated media type on the pad to perform

double space! :)
Comment 27 Matthew Waters (ystreet00) 2017-05-12 10:54:17 UTC
Review of attachment 351495 [details] [review]:

Ok.
Comment 28 Matthew Waters (ystreet00) 2017-05-12 10:54:48 UTC
Review of attachment 351496 [details] [review]:

Ok.
Comment 29 Matthew Waters (ystreet00) 2017-05-12 10:56:03 UTC
Review of attachment 351497 [details] [review]:

Ok.
Comment 30 Matthew Waters (ystreet00) 2017-05-12 11:16:42 UTC
Review of attachment 351498 [details] [review]:

This seems mostly sane.

I'm not exactly sure about the rationale for storing in the clipped_buffer unless ->clip() is not idempotent and/or not deterministic.

::: gst-libs/gst/base/gstaggregator.c
@@ +2494,3 @@
+
+    if (self == NULL) {
+      self = GST_AGGREGATOR (gst_pad_get_parent_element (GST_PAD (pad)));

Why is this inside the loop?

Will the pad get a different parent while the PAD_LOCK is held?
Comment 31 Matthew Waters (ystreet00) 2017-05-12 11:17:38 UTC
Review of attachment 351499 [details] [review]:

Ok.
Comment 32 Olivier Crête 2017-05-20 10:44:07 UTC
Created attachment 352207 [details] [review]
aggregator: Fix indentation
Comment 33 Olivier Crête 2017-05-20 10:44:14 UTC
Created attachment 352208 [details] [review]
aggregator: Reset pad on init

Factor out the pad reset code from the flushing and use it on init as well
Comment 34 Olivier Crête 2017-05-20 10:44:20 UTC
Created attachment 352209 [details] [review]
aggregator: Reset the pad's first buffer flag with the rest

There is not reason to have separate code to reset this one.
Comment 35 Olivier Crête 2017-05-20 10:44:26 UTC
Created attachment 352210 [details] [review]
aggregator: Set initial position on first buffer

Set the initial position on the first buffer, otherwise the queue
will grow without limits before the output thread is started.
Comment 36 Olivier Crête 2017-05-20 10:44:33 UTC
Created attachment 352211 [details] [review]
aggregator: Only declare first buffer on actual buffer

The function needs to be unlocked if any data is received, but only
end the first buffer processing on an actual buffer, synchronized events
don't matter on the first buffer processing.
Comment 37 Olivier Crête 2017-05-20 10:44:40 UTC
Created attachment 352212 [details] [review]
aggregator: Simplify clip function

The return value was ignored anyway
Comment 38 Olivier Crête 2017-05-20 10:44:46 UTC
Created attachment 352213 [details] [review]
tests: Test caps using query

Sending an event can accepted event if the caps were rejected
because the event could be queued and processed later.

Also send a drain query in the caps test to make sure that the
event has been processed.
Comment 39 Olivier Crête 2017-05-20 10:44:53 UTC
Created attachment 352214 [details] [review]
aggregator: Only count buffers when declaring queue full
Comment 40 Olivier Crête 2017-05-20 10:45:05 UTC
Created attachment 352215 [details] [review]
aggregator: Make pad eos as soon as all buffers are processed, dont way for events
Comment 41 Olivier Crête 2017-05-20 10:45:12 UTC
Created attachment 352216 [details] [review]
aggregator: Delay clipping to output thread

This is required because the synchronized events like caps or segments
may only be processed on the output thread.
Comment 42 Olivier Crête 2017-05-20 10:45:21 UTC
Created attachment 352217 [details] [review]
aggregator: Always handle sync'ed events on output thread

Having all synchronized events always be handled on the output
thread should make synchronization easier.
Comment 43 Matthew Waters (ystreet00) 2017-05-20 12:29:27 UTC
Review of attachment 352212 [details] [review]:

Feel free to push after the doc modifications.

::: gst-libs/gst/base/gstaggregator.h
@@ +158,3 @@
+ *                  Called when a buffer is received on a sink pad, the task of
+ *                  clipping it and translating it to the current segment falls
+ *                  on the subclass. The function should use the segment of data

s/ of// ?

@@ +162,3 @@
+ *                  clipping of inbuffer. This function takes ownership of
+ *                  buf and should output a buffer or return NULL in
+ *                  if the buffer should be dropped.

s/ in//
Comment 44 Matthew Waters (ystreet00) 2017-05-20 12:31:30 UTC
Review of attachment 352215 [details] [review]:

Typo in commit message: s/way/wait/

Can push once fixed.
Comment 45 Olivier Crête 2017-05-20 14:26:47 UTC
Merged:

commit d2335bce9b96c95edeb4bafdabcf4ba39def8ade
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Sat May 14 15:52:37 2016 +0200

    aggregator: Always handle sync'ed events on output thread
    
    Having all synchronized events always be handled on the output
    thread should make synchronization easier.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 4cec1925e3768227150f82541b12ff61d4537e50
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Wed Jul 6 16:39:17 2016 -0400

    aggregator: Delay clipping to output thread
    
    This is required because the synchronized events like caps or segments
    may only be processed on the output thread.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit a6710944e81016fdee3a2000c5d98ca06d5d3f24
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Thu Jul 7 16:13:57 2016 -0400

    aggregator: Make pad eos as soon as all buffers are processed, dont way for events
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 6e96bebd5bd20ceb8d426958715d539dde67770e
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Thu Jul 7 11:47:40 2016 -0400

    aggregator: Only count buffers when declaring queue full
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit c0849df4aca6b51cc8c79f502bfcdb2171a377f2
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Wed Jul 6 17:28:11 2016 -0400

    tests: Test caps using query
    
    Sending an event can accepted event if the caps were rejected
    because the event could be queued and processed later.
    
    Also send a drain query in the caps test to make sure that the
    event has been processed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 4d408ea9205aedea1b51f571b89ee0cca339315a
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Wed Jul 6 16:41:44 2016 -0400

    aggregator: Simplify clip function
    
    The return value was ignored anyway
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 20aee5f5757e2b000d8e55bd1fb5386548526749
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Sun May 15 16:04:58 2016 +0300

    aggregator: Only declare first buffer on actual buffer
    
    The function needs to be unlocked if any data is received, but only
    end the first buffer processing on an actual buffer, synchronized events
    don't matter on the first buffer processing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 1ab33d78feb5d27adf229688ea56b92ce4c40222
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Tue May 9 20:20:07 2017 -0400

    aggregator: Set initial position on first buffer
    
    Set the initial position on the first buffer, otherwise the queue
    will grow without limits before the output thread is started.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 82f7b00ea38a6f83d3eb5d9405d25460dacf51e3
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Tue May 9 20:06:29 2017 -0400

    aggregator: Reset the pad's first buffer flag with the rest
    
    There is not reason to have separate code to reset this one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit 05374aa22cf730cd876cfb3f127be71ea9271b48
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Tue May 9 20:05:55 2017 -0400

    aggregator: Reset pad on init
    
    Factor out the pad reset code from the flushing and use it on init as well
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673

commit d722e064fd1c3222eb34595ad535a8f9cee10792
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Tue May 9 20:13:58 2017 -0400

    aggregator: Fix indentation
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781673
Comment 46 Olivier Crête 2017-05-20 14:28:10 UTC
Comment on attachment 352215 [details] [review]
aggregator: Make pad eos as soon as all buffers are processed, dont way for events

Fixed and merged
Comment 47 Olivier Crête 2017-05-20 14:28:34 UTC
Comment on attachment 352212 [details] [review]
aggregator: Simplify clip function

Fixed and merged