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 476514 - [multiqueue] Doesn't forward EOS event in all cases
[multiqueue] Doesn't forward EOS event in all cases
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal major
: NONE
Assigned To: Wim Taymans
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2007-09-13 11:17 UTC by Tommi Myöhänen
Modified: 2016-11-12 11:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (664 bytes, patch)
2007-09-13 11:18 UTC, Tommi Myöhänen
none Details | Review
proposed patch (679 bytes, patch)
2007-09-13 11:22 UTC, Tommi Myöhänen
none Details | Review
wavparse-eos.diff (3.49 KB, patch)
2007-09-13 11:48 UTC, Sebastian Dröge (slomo)
rejected Details | Review

Description Tommi Myöhänen 2007-09-13 11:17:21 UTC
The following pipeline never finishes:

$ gst-launch gnomevfssrc location=http://replaygain.hydrogenaudio.org/ref_pink.wav ! queue ! wavparse ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock

The reason for this seems to be that wavparse never sends eos event downstream. gst_wavparse_chain returns GST_FLOW_UNEXPECTED when wavparse thinks it has reached eos. This causes queue src pad task to pause and eos event is never received from the queue. Wavparse doesn't generate eos event itself either.
Comment 1 Tommi Myöhänen 2007-09-13 11:18:24 UTC
Created attachment 95511 [details] [review]
proposed patch
Comment 2 Tommi Myöhänen 2007-09-13 11:22:49 UTC
Created attachment 95515 [details] [review]
proposed patch
Comment 3 Sebastian Dröge (slomo) 2007-09-13 11:48:32 UTC
Created attachment 95518 [details] [review]
wavparse-eos.diff

What about this patch instead? This prevents two EOS events when being in loop-mode.

Does this fix your bug?
Comment 4 Sebastian Dröge (slomo) 2007-09-13 12:37:38 UTC
Well, it does for me... committed :) Please reopen if you still have problems with this.

2007-09-13  Sebastian Dröge  <slomo@circular-chaos.org>

        * gst/wavparse/gstwavparse.c: (gst_wavparse_perform_eos),
        (gst_wavparse_loop), (gst_wavparse_chain):
        Add EOS logic for the push-based mode too. Fixes #476514.
Comment 5 Tim-Philipp Müller 2007-09-13 12:49:18 UTC
I'm not sure whether this fix is correct.  The EOS event should be generated by the element driving the pipeline (in this case: not wavparse), and should be passed on downstream until it reaches a sink.  If this doesn't happen, it needs to be fixed upstream IMHO.
Comment 6 Sebastian Dröge (slomo) 2007-09-13 13:16:55 UTC
Ok, then let's reopen this bug...
Comment 7 Tommi Myöhänen 2007-09-13 14:13:38 UTC
(In reply to comment #5)
> I'm not sure whether this fix is correct.  The EOS event should be generated by
> the element driving the pipeline (in this case: not wavparse), and should be
> passed on downstream until it reaches a sink.  If this doesn't happen, it needs
> to be fixed upstream IMHO.
> 

So in this case wavparse shouldn't be responsible for determining when stream ends. And therefore it shouldn't return GST_FLOW_UNEXPECTED in gst_wavparse_chain until it receives eos event from upstream.
Comment 8 Tim-Philipp Müller 2007-09-13 14:28:40 UTC
> So in this case wavparse shouldn't be responsible for determining when stream
> ends. And therefore it shouldn't return GST_FLOW_UNEXPECTED in
> gst_wavparse_chain until it receives eos event from upstream.

I _think_ returning GST_FLOW_UNEXPECTED to tell upstream that processing should stop is okay in this case (even if unusual).
Comment 9 Sebastian Dröge (slomo) 2007-09-13 14:44:26 UTC
So it's probably either queue or gnomevfssrc that don't forward the EOS event? From a short look at a GST_DEBUG=5 log both forward the event but wavparse doesn't forward it anymore.
Comment 10 Sebastian Dröge (slomo) 2007-09-13 14:59:56 UTC
Hm, no... queue receives the event but doesn't forward it.
Comment 11 Sebastian Dröge (slomo) 2007-09-13 17:08:02 UTC
Tim, do you have any idea what could be wrong in queue? :)
Comment 12 Sebastian Dröge (slomo) 2007-09-14 09:56:37 UTC
Yep, adding the hack below to gstqueue.c makes the above pipeline work. Would be nice if someone with deeper knowledge about queue could look into this.



Index: plugins/elements/gstqueue.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/plugins/elements/gstqueue.c,v
retrieving revision 1.199
diff -u -p -a -u -p -r1.199 gstqueue.c
--- plugins/elements/gstqueue.c 13 Sep 2007 17:15:38 -0000      1.199
+++ plugins/elements/gstqueue.c 14 Sep 2007 09:55:56 -0000
@@ -758,6 +758,9 @@ gst_queue_handle_sink_event (GstPad * pa
       STATUS (queue, pad, "after flush");
       goto done;
     }
+    case GST_EVENT_EOS:
+       gst_pad_push_event (queue->srcpad, event);
+       goto done;
     default:
       if (GST_EVENT_IS_SERIALIZED (event)) {
         /* serialized events go in the queue */
Comment 13 Sebastian Dröge (slomo) 2007-09-14 10:00:42 UTC
queue2 suffers from the same bug btw...
Comment 14 Jan Schmidt 2007-09-14 10:18:53 UTC
(In reply to comment #12)
> Yep, adding the hack below to gstqueue.c makes the above pipeline work. Would
> be nice if someone with deeper knowledge about queue could look into this.
> 

EOS is a serialized event - in queue it is handled by the default: case, and should be placed in the queue and output in correct serial order.

The problem from my perspective is wavparse returning UNEXPECTED when it hasn't yet received EOS - the consequence as you've noted is that queue won't send anything more.

Instead, I think wavparse should feel free to ignore any further data it receives once it has seen what it thinks is the end of the file, but it should definitely not take it upon itself to return UNEXPECTED - it should just pass the EOS downstream, and let that shut the pipeline down.

Comment 15 Tim-Philipp Müller 2007-09-14 11:32:44 UTC
> Instead, I think wavparse should feel free to ignore any further data it
> receives once it has seen what it thinks is the end of the file, but it should
> definitely not take it upon itself to return UNEXPECTED - it should just pass
> the EOS downstream, and let that shut the pipeline down.

Definitely?  While your suggestion would work of course, I think it would be unnecessarily limiting in terms of what can be done in future.

I wonder if it might not even be bad from a design point of view, making it impossible for elements in the pipeline to decide when streaming should stop, putting this burden onto the application, with all that entails (like shutting down source first to make it send EOS, then wait for the EOS message before shutting down the rest of the pipeline etc.).

And what if you have a source that provides data forever? (Not so much an issue for wavparse, but in general).

I think we should allow for elements in the pipeline to return FLOW_UNEXPECTED (or a new flow return, don't really care) to signal upstream that processing should stop now.
Comment 16 Wim Taymans 2007-09-14 15:36:45 UTC
it should be allowed for a chain based element to return FLOW_UNEXPECTED, which makes upstream perform its EOS logic (push EOS or post SEGMENT_DONE). It looks like queue is not handling this correctly yet.
Comment 17 Jan Schmidt 2007-09-14 15:49:33 UTC
(In reply to comment #16)
> it should be allowed for a chain based element to return FLOW_UNEXPECTED, which
> makes upstream perform its EOS logic (push EOS or post SEGMENT_DONE). It looks
> like queue is not handling this correctly yet.
> 

So that implies that queue should not shut down the source pad on UNEXPECTED, but should simply ensure that it is returned upstream and then await the EOS?
Comment 18 Wim Taymans 2007-09-14 17:20:18 UTC
UNEXPECTED means that it does not want anymore buffers. It's fine to push an EOS, FLUSH or NEWSEGMENT. Queue should probably get rid of all buffers up to a queued NEWSEGMENT or EOS, and not shut down the push thread.

I'm thinking about the case where you have httpsrc -> queue -> mad and you requested a SEGMENT seek in time from 0 to 3 seconds, mad does not know the byte end position so asks to seek from byte 0 to the end. When it has pushed up to 3 seconds it can return UNEXPECTED, which should make httpsrc perform the EOS logic (post SEGMENT_DONE), at which point the app can do another SEGMENT seek.
Comment 19 Wim Taymans 2007-09-14 20:24:36 UTC
        * plugins/elements/gstqueue.c: (gst_queue_locked_enqueue),
        (gst_queue_handle_sink_event), (gst_queue_chain),
        (gst_queue_push_one), (gst_queue_handle_src_query),
        (gst_queue_sink_activate_push), (gst_queue_src_activate_push):
        * plugins/elements/gstqueue.h:
        When downstream returns UNEXPECTED from pushing a buffer, don't try to
        push more buffers but allow pushing of EOS and NEWSEGMENT.
        Add some more debug info here and there. Fixes #476514.
Comment 20 Tommi Myöhänen 2007-09-17 08:05:31 UTC
This problem applies to queue2 too, so reopening.

$ gst-launch gnomevfssrc location=http://replaygain.hydrogenaudio.org/ref_pink.wav ! queue2 ! wavparse ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Comment 21 Sebastian Dröge (slomo) 2007-09-17 08:11:07 UTC
Hm, Works fine for me with queue2 now...
Comment 22 Tommi Myöhänen 2007-09-17 11:08:08 UTC
I'm using latest stable gst packages from debian + patched queue, it hangs as follows for me:

0:00:02.083651000  2792 0x8112578 LOG               wavparse gstwavparse.c:1604:gst_wavparse_stream_data:<wavparse0> Got buffer. timestamp:0:00:04.969070295 , duration:0:00:00.030929705, size:2728
0:00:02.083677000  2792 0x8112578 LOG               wavparse gstwavparse.c:1620:gst_wavparse_stream_data:<wavparse0> offset: 441028 , end: 441028
0:00:02.083688000  2792 0x8112578 LOG               wavparse gstwavparse.c:1504:gst_wavparse_stream_data:<wavparse0> offset: 441028 , end: 441028 , dataleft: 0
0:00:02.083697000  2792 0x8112578 DEBUG             wavparse gstwavparse.c:1628:gst_wavparse_stream_data:<wavparse0> found EOS
0:00:02.083708000  2792 0x8112578 LOG        queue2_dataflow gstqueue2.c:1390:gst_queue_loop:<queue20> pause task, reason:  unexpected

Do you have earlier workarounds to wavparse reverted?
Comment 23 Sebastian Dröge (slomo) 2007-09-17 11:14:02 UTC
Hum, right... I still had the old wavparse on that machine. You're right, with queue2 it still doesn't EOS correctly :/
Comment 24 Stefan Sauer (gstreamer, gtkdoc dev) 2007-09-17 11:52:42 UTC
Slomo, maybe because you applied that wavparse patch also. Should that be reverted now?
Comment 25 Sebastian Dröge (slomo) 2007-09-17 11:56:21 UTC
The wavparse patch _was_ applied, I reverted it in CVS as it's wrong behaviour (although it doesn't hurt for this bug).
With queue2 it definitely still has the broken EOS behaviour in current, clean CVS, queue(1) is fixed.
Comment 26 Stefan Sauer (gstreamer, gtkdoc dev) 2007-09-17 14:25:44 UTC
Wim, can you do the same change in queue2. Is it also needed in multiqueue?
Comment 27 Wim Taymans 2007-09-17 16:22:20 UTC
        * gst/playback/gstqueue2.c: (update_buffering),
        (gst_queue_locked_flush), (gst_queue_locked_enqueue),
        (gst_queue_handle_sink_event), (gst_queue_chain),
        (gst_queue_push_one), (gst_queue_sink_activate_push),
        (gst_queue_src_activate_push), (gst_queue_src_activate_pull):
        Also fix #476514 for queue2.
Comment 28 Wim Taymans 2007-09-17 16:24:22 UTC
It seems to be needed in multiqueue as well.
Comment 29 Stefan Sauer (gstreamer, gtkdoc dev) 2007-11-07 06:15:29 UTC
Wim, should this be fixed before releasing new core & base?
Comment 30 Jan Schmidt 2007-11-13 10:46:50 UTC
no, I don't think this is going to be done for the release. It's not a regression, and I think it can wait.
Comment 31 Stefan Sauer (gstreamer, gtkdoc dev) 2008-04-25 07:37:55 UTC
It applies to multiqueue too, but is not that easy to be fixed there.
Comment 32 Wim Taymans 2008-04-25 07:38:39 UTC
It's more complicated in multiqueue, mostly because the queue locking is done in the lower level object and we need to grab it to handle the EOS case.
Comment 33 Tim-Philipp Müller 2009-04-15 23:05:33 UTC
Maybe a test case would be a good first step towards getting this fixed?
Comment 34 Tim-Philipp Müller 2010-01-29 00:37:47 UTC
This seems relevant:

commit fbdf4dcedad8692f1e3d8838551188987e462e74
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Tue Jan 26 12:43:09 2010 +0100

    multiqueue: handle UNEXPECTED flowreturn better
    
    When we receive an UNEXPECTED flowreturn from downstream, we must not shutdown
    the pushing thread because upstream will at some point push an EOS that we still
    need to push further downstream.
    
    To achieve this, convert the UNEXPECTED return value to OK. Add a fixme so that
    we implement the right logic to propagate the flowreturn upstream at some point.
    
    Also clean up the unit test a little.
    
    Fixes #608136
Comment 35 Edward Hervey 2013-07-09 12:57:56 UTC
Does this still apply to 1.x ?
Comment 36 Tim-Philipp Müller 2016-11-12 11:27:16 UTC
This thing is almost 9 years old. A lot has changed in multiqueue since then. If it's still a problem someone will run into it sooner or later and open a new bug about it. Let's close this.