qtdemux: Fix premature EOS when some files are played in push mode
authorAlicia Boya García <aboya@igalia.com>
Wed, 12 Jul 2023 10:37:34 +0000 (12:37 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 3 Aug 2023 20:22:51 +0000 (20:22 +0000)
commit654ca283a71849ad5c63425083a9a0c2646b2219
tree0d72c603f054f10e0eb35238a289844b896ce7ee
parent1ea67bdfc58c33812019d70c5afe801077f8b0d9
qtdemux: Fix premature EOS when some files are played in push mode

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2771

This EOS branch exists so that if a seek with a stop is made, qtdemux
stops accepting bytes from the sink after the entire requested playback
range is demuxed, as otherwise we could keep download content that is
not being used.

This patch fixes two flaws that were present in that EOS check:

1) A comparison was made between track time and movie time without conversion.
This made the check trigger early in files with edit lists. This patch fixes
this by converting the track PTS to movie PTS (stream time) for the check.

2) To avoid sending a EOS prematurely when the segment stop is within a GOP and
B-frames are present, the check for EOS should only be done for keyframes. I
gather this was already the intention with the existing code, but because it
used `stream->on_keyframe` instead of the local variable `keyframe` the old
code was checking if the *previous* frame was a keyframe.

It's interesting to note that these two flaws in the old code mask each other
in most cases: the track PTS will have reached the movie end PTS, but EOS would
only be sent if the previous frame was a keyframe. A simple case where they
wouldn't mask each other, reproducing the bug, is a sequence of 3 frame GOPs
with structure I-B-P.

The following validateflow tests have been added to future-proof the
fix:

 * validate.test.mp4.qtdemux_ibpibp_non_frag_pull.default
 * validate.test.mp4.qtdemux_ibpibp_non_frag_push.default

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5114>
subprojects/gst-integration-testsuites/medias
subprojects/gst-integration-testsuites/testsuites/validate.testslist
subprojects/gst-integration-testsuites/testsuites/validate/mp4/qtdemux_ibpibp_non_frag_pull.default.validatetest [new file with mode: 0644]
subprojects/gst-integration-testsuites/testsuites/validate/mp4/qtdemux_ibpibp_non_frag_pull.default/flow-expectations/log-fakesink0-sink-expected [new file with mode: 0644]
subprojects/gst-integration-testsuites/testsuites/validate/mp4/qtdemux_ibpibp_non_frag_push.default.validatetest [new file with mode: 0644]
subprojects/gst-integration-testsuites/testsuites/validate/mp4/qtdemux_ibpibp_non_frag_push.default/flow-expectations/log-fakesink0-sink-expected [new file with mode: 0644]
subprojects/gst-plugins-good/gst/isomp4/qtdemux.c