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 751105 - baseparse: drain on stream-start
baseparse: drain on stream-start
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other All
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-06-17 13:43 UTC by Thiago Sousa Santos
Modified: 2018-11-03 12:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
baseparse: drain and reset on stream-start (1.46 KB, patch)
2015-06-17 13:43 UTC, Thiago Sousa Santos
accepted-commit_now Details | Review
h264parse: reset parser state (800 bytes, patch)
2015-06-17 13:45 UTC, Thiago Sousa Santos
accepted-commit_now Details | Review
h264parse: handle stream-start event (1.03 KB, patch)
2015-06-17 13:46 UTC, Thiago Sousa Santos
reviewed Details | Review
baseparse: add reset virtual function (2.38 KB, patch)
2015-06-24 17:58 UTC, Thiago Sousa Santos
reviewed Details | Review
h264parse: implement reset() method (2.41 KB, patch)
2015-06-24 17:59 UTC, Thiago Sousa Santos
none Details | Review

Description Thiago Sousa Santos 2015-06-17 13:43:05 UTC
When handling stream-start events, baseparse should drain its current data and then reset itself as a new stream is about to start, no data from previous stream should be reused.
Comment 1 Thiago Sousa Santos 2015-06-17 13:43:31 UTC
Created attachment 305478 [details] [review]
baseparse: drain and reset on stream-start

When a stream-start event is received it indicates a new stream is
starting and elements should reset their status to start processing
new data.

This patch makes baseparse drain the current data and then reset
itself when handling this event.
Comment 2 Thiago Sousa Santos 2015-06-17 13:45:54 UTC
Created attachment 305479 [details] [review]
h264parse: reset parser state

After reset h264parse shouldn't rely on having received previous SPS
or PPS
Comment 3 Thiago Sousa Santos 2015-06-17 13:46:03 UTC
Created attachment 305480 [details] [review]
h264parse: handle stream-start event

Reset internal state when stream-start is received
Comment 4 Thiago Sousa Santos 2015-06-17 13:48:12 UTC
The bug is about baseparse but I decided to attach those 2 extra patches here for h264parse as it was the use case that had me modifying baseparse.

I've been trying to use h264parse to play 2 streams sequentially and I found that it was using data from a previous stream to parse the new one leading to broken decoding and bad frames on screen. Using the stream-start to signal the beginning of a completely new stream seems to make sense.
Comment 5 Tim-Philipp Müller 2015-06-17 14:57:11 UTC
Haven't looked at the patches yet, but I think it makes sense conceptually and seems like the right thing to do.
Comment 6 Olivier Crête 2015-06-17 17:20:22 UTC
Review of attachment 305478 [details] [review]:

Shouldn't it do it only if the stream-id changed? The same event could have been re-sent, or some other property than the stream-id could have changed.
Comment 7 Sebastian Dröge (slomo) 2015-06-18 07:30:32 UTC
If the group-id changes, it should also drain. So maybe check both, yes.
Comment 8 Tim-Philipp Müller 2015-06-18 07:43:50 UTC
I don't know if the fact that it's the same stream semantically has any meaning with regard to whether any of the technical parameters extracted from it are still valid. Imagine you have a long stream and are now going back to the start and feeding data again from the beginning.

Do we know cases where stream-start events are gratuitiously re-sent? Or some property changes?
Comment 9 Sebastian Dröge (slomo) 2015-06-18 08:00:08 UTC
Also note that videodecoder and others are also draining unconditionally on stream-start events already.
Comment 10 Olivier Crête 2015-06-18 16:48:02 UTC
Nicolas also told me I was an idiot, forget what I said about stream-start events being re-sent.
Comment 11 Sebastian Dröge (slomo) 2015-06-22 16:31:34 UTC
Comment on attachment 305480 [details] [review]
h264parse: handle stream-start event

Shouldn't the draining make this happen already? Or some GstBaseParse::reset()?
Comment 12 Thiago Sousa Santos 2015-06-22 20:18:23 UTC
(In reply to Sebastian Dröge (slomo) from comment #11)
> Comment on attachment 305480 [details] [review] [review]
> h264parse: handle stream-start event
> 
> Shouldn't the draining make this happen already? Or some
> GstBaseParse::reset()?

baseparse class doesn't have a reset(), we could add that and call it from the baseparse reset() function, then we wouldn't have to deal with the stream-start directly in h264parse. Both ways are ok with me, I went with this one to avoid adding extra API as it could be done from the event handler anyway.
Comment 13 Sebastian Dröge (slomo) 2015-06-23 08:17:10 UTC
A ::reset() has the problem to decide when to call it, like in the other base classes. And what makes it different from a ::flush() :)

But I think your patch shows that something there is needed, it's probably not the only parser (definitely not: h265parse).
Comment 14 Thiago Sousa Santos 2015-06-24 15:41:35 UTC
So, should we go with reset or flush? I think reset is more appropriate as it is usually what we call when we do a READY-PAUSED transition, meaning *all* data is cleared.

But then what is different in a flush? Is some data preserved? Flush events, for example, don't remove the caps from pads, so we assume the caps are to remain the same.
Comment 15 Sebastian Dröge (slomo) 2015-06-24 15:49:05 UTC
Well, flush() would be something that we call on flush-stop. You probably don't want to drop the SPS/PPS on flush-stop, e.g. after a seek you might not get a new one :)
Comment 16 Thiago Sousa Santos 2015-06-24 17:58:25 UTC
Created attachment 306031 [details] [review]
baseparse: add reset virtual function

Used to instruct subclasses to reset their state and be ready
to start processing a new stream.

It is optional and was added to handle when a new STREAM_START event is
received before a new stream starts, making sure the subclass is ready
to start processing again without residues from a previous stream.
Comment 17 Thiago Sousa Santos 2015-06-24 17:59:03 UTC
Created attachment 306032 [details] [review]
h264parse: implement reset() method

Allow h264parse to reset internal state when a new stream is about
to start.
Comment 18 Thiago Sousa Santos 2015-06-24 18:00:01 UTC
will do the same to h265parse once those patches are accepted.

And also check some other parsers to see if they should also need this reset() handling.
Comment 19 Sebastian Dröge (slomo) 2015-06-25 09:03:46 UTC
Comment on attachment 306031 [details] [review]
baseparse: add reset virtual function

Should it also be called after drain? Or after start() or before stop() or something like that? Or when completely new caps arrive? Or ...? :)
Comment 20 Thiago Sousa Santos 2015-06-25 14:23:06 UTC
Reset is called from the reset() function that already was present at base parse. So it is now being called at:

init
stream-start
after stop

Lots of elements call a reset() to initialize their variables but it feels weird to have it at a constructor.

Drain() serves a different purpose and not necessarily means it needs to reset, might just be a discont handling.

new caps also might not necessarily mean a reset, at least not a hard one as this is supposed to mean.

For start() and stop() it might make sense, but the subclass can also call directly their implementation if needed.
Comment 21 Sebastian Dröge (slomo) 2015-06-25 14:35:04 UTC
Ok, maybe make that more clear in the docs but apart from that just go ahead :)
Comment 22 Sebastian Dröge (slomo) 2015-08-27 08:25:26 UTC
What's the status here?
Comment 23 Sebastian Dröge (slomo) 2015-10-02 14:48:33 UTC
Thiago?
Comment 24 Sebastian Dröge (slomo) 2016-11-01 18:54:13 UTC
Ping?
Comment 25 Thiago Sousa Santos 2016-11-12 18:43:39 UTC
Hi, this was part of a bigger change to allow playing media sequentially without having to put the pipeline to NULL and back. Specially on small devices, resetting hardware elements was costly. This was done to mitigate this delay when we knew the streams shared the same formats over time.

This use case is not a direct need for me anymore but it might still be interesting for more people. If you agree, let me know and I'll test those patches again and get them merged.
Comment 26 Tim-Philipp Müller 2016-11-12 19:38:11 UTC
Didn't review the patches, but it makes sense to me to drain on stream-start. gst_base_parse_drain() also has just been made public if it helps with anything.
Comment 27 Sebastian Dröge (slomo) 2016-11-14 09:15:49 UTC
Yes, we should get this change in. The STREAM_START part makes sense in general and is the same that is done elsewhere.
Comment 28 Edward Hervey 2018-05-22 10:05:32 UTC
We should definitely try to get these patches in.
Comment 29 GStreamer system administrator 2018-11-03 12:28:05 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/116.