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 752791 - basesink: drops first few buffers with dts/pts b-frame shift
basesink: drops first few buffers with dts/pts b-frame shift
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal blocker
: git master
Assigned To: Nicolas Dufresne (ndufresne)
GStreamer Maintainers
Depends on:
Blocks: 760677
 
 
Reported: 2015-07-23 18:01 UTC by Tim-Philipp Müller
Modified: 2016-01-15 14:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
basesink: Don't drop buffers with DTS (1.75 KB, patch)
2015-07-29 20:49 UTC, Nicolas Dufresne (ndufresne)
none Details | Review
basesink: Don't drop buffers (1.76 KB, patch)
2015-08-03 17:49 UTC, Nicolas Dufresne (ndufresne)
rejected Details | Review
basesink: Restrict dropping out of segment buffer (2.73 KB, patch)
2015-08-03 21:59 UTC, Nicolas Dufresne (ndufresne)
rejected Details | Review
videotestsrc: Don't set DTS on buffer (1.65 KB, patch)
2015-08-04 19:41 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
basesink: Only drop buffer if their PTS is out of segment (1.95 KB, patch)
2015-08-05 19:54 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review

Description Tim-Philipp Müller 2015-07-23 18:01:32 UTC
gst-launch-1.0 videotestsrc ! x264enc ! identity dump=true ! fakesink dump=true | grep ^0000000 | head -n 5

Should show each line twice, but the first two lines are only shown once because basesink drops the first two buffers as out of segment.
Comment 1 Nicolas Dufresne (ndufresne) 2015-07-24 23:21:18 UTC
I can fix it next week. Checking and dropping a buffer as "out of segment" base on the DTS is obviously wrong (unless PTS is unset).
Comment 2 Nicolas Dufresne (ndufresne) 2015-07-29 20:41:43 UTC
Ok, I have given first take on this one. Basically, basesink is trying to clip buffers regardless of what they are. The code is from the root quite wrong, as clipping encoded data like an H264 stream can only render the stream unusable.

The solution I foresee will require changes in multiple elements. The side effect of not making these changes is that raw frame could endup not being clipped (quick "playback" of few frames). It's not a major issue, at least it's does not break anything that exist.

It consist of better defining the use of DTS. Basically, we would never clip if DTS is set. That means, we need not to set DTS on raw streams if we want them to be clipped (also for streams like JPEG streams, where you can clip safely).
Comment 3 Nicolas Dufresne (ndufresne) 2015-07-29 20:49:20 UTC
Created attachment 308417 [details] [review]
basesink: Don't drop buffers with DTS

Specially for H264, it's common that the DTS falls outside (before) the
segment. More generally, it's not a good idea to drop buffers that
are encoded. In order to fix this problem, this patch propose that
basesink rely on the presence of a DTS to avoid dropping. This means
element that rely on out of segment buffer to be removed, need not to
set a DTS. This applies to raw stream, but also to streams without
state, like MJPEG.
Comment 4 Nicolas Dufresne (ndufresne) 2015-08-03 17:49:53 UTC
Created attachment 308696 [details] [review]
basesink: Don't drop buffers

Basesink is suppose to be media agnostic, but only raw medias can
possibly be dropped safely. So simply don't drop any buffers, even if
out of segment, and leave this task to sub-classes.
Comment 5 Nicolas Dufresne (ndufresne) 2015-08-03 21:42:36 UTC
This second patch is being proposed after an IRC discussion with Sebastien. The idea being that it make not sense for basesink to systematically drop buffers, as this depends on the media (basesink is media agnostic).

This is not the only place basesink may drop, it could drop if a buffer if late. Though, this requires subclass approval. This approval is given if the sub-class implements get_times() and that it sets the start to something different from -1. I think a big issue here is that this dropping code does not obey to the permission to drop given by the subclass.
Comment 6 Nicolas Dufresne (ndufresne) 2015-08-03 21:59:54 UTC
Created attachment 308705 [details] [review]
basesink: Restrict dropping out of segment buffer

Basesink shall not drop buffers unless it is doing synchronization.
Subclasses that do require synchronization implements get_times() and
indicate that they want a buffer to be synchronized by returning a valid
start time. This aligns the code dropping out of segment with the code
dealing with late buffers.
Comment 7 Nicolas Dufresne (ndufresne) 2015-08-03 22:24:04 UTC
Might just confuse thing, but in this 3rd iteration, I simply don't clip unless the subclass implements get_times() and start != -1. I think this last patch is what makes most sense.
Comment 8 Nicolas Dufresne (ndufresne) 2015-08-04 00:00:18 UTC
Comment on attachment 308705 [details] [review]
basesink: Restrict dropping out of segment buffer

Ok, after a long discussion with Olivier, we ruled out this one (so no short cut). The thing I missed is that get_time() is always implemented, so by default start won't be -1. It simply does not solve the initial problem.
Comment 9 Nicolas Dufresne (ndufresne) 2015-08-04 18:57:23 UTC
Comment on attachment 308696 [details] [review]
basesink: Don't drop buffers

So as brought up by Tim, a completly valid scenario would be existing code the do:

Take a snapshot:
  uridecodebin ! video/x-raw ! appsink

If it picks a file containing raw video directly, and a demuxer that don't try to clip on accurate seek (take TS), the resulting snapshot would be wrong if we don't do any clipping.
Comment 10 Nicolas Dufresne (ndufresne) 2015-08-04 19:41:20 UTC
Created attachment 308752 [details] [review]
videotestsrc: Don't set DTS on buffer

DTS is for encoded data. Setting it prevent basesink from being able
to clip out of segment buffers.
Comment 11 Tim-Philipp Müller 2015-08-04 19:54:44 UTC
Comment on attachment 308752 [details] [review]
videotestsrc: Don't set DTS on buffer

Seems right to me, we shouldn't set DTS on raw video buffers IMHO
Comment 12 Nicolas Dufresne (ndufresne) 2015-08-04 20:21:57 UTC
So with the remaining approach, similar simple patches would be added to make PTS/DTS coherent to their media type. I can't see any ambiguity with this to be fair.
Comment 13 Nicolas Dufresne (ndufresne) 2015-08-04 22:01:52 UTC
Attachment 308752 [details] pushed as 7db376d - videotestsrc: Don't set DTS on buffer
Comment 14 Nicolas Dufresne (ndufresne) 2015-08-05 19:54:24 UTC
Created attachment 308813 [details] [review]
basesink: Only drop buffer if their PTS is out of segment

As of now, even for stream completly inside segment, there is no
guarantied that the DTS will be inside the segment. Specifically
for H.264 with B-Frames, the first few frames often have DTS that
are before the segment.

Instead of using the sync timestamp to clip out of segment buffer,
take the duration from the start/stop provided by the sub-class, and
check if the pts and pts_end is out of segment.
Comment 15 Nicolas Dufresne (ndufresne) 2015-08-05 19:58:07 UTC
So I think there is two bugs, the patch in comment 14 fixes the regression. Basically an out of segment buffer is a buffer that has a PTS and PTS + duration that falls out of segment.

The second bug, which was present before the integration of proper DTS support for H.264 is that basesink will clip and break certain stream (if segment is in TIME format). This problem already existed, and should be handled differently. A simple option would be to add a clip-to-segment property to basesink, this way application (or sub-class) can choose. But let's file a seperate bug for that.
Comment 16 Nicolas Dufresne (ndufresne) 2015-08-05 21:34:18 UTC
Attachment 308813 [details] pushed as e24e902 - basesink: Only drop buffer if their PTS is out of segment

With suggested rename.
Comment 17 Nicolas Dufresne (ndufresne) 2015-08-05 21:35:46 UTC
Oops, I have pushed this accidentally, leaving open for comment, will revert if any comment, sorry about this.
Comment 18 Nicolas Dufresne (ndufresne) 2015-08-10 21:47:23 UTC
Looks like there is no or at least little objections.