matroskademux: try to ensure keyframe when seeking without index
authorTim-Philipp Müller <tim@centricular.com>
Wed, 8 Aug 2018 11:37:54 +0000 (12:37 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 27 Aug 2018 21:01:21 +0000 (23:01 +0200)
commit43ce85f794f7599e81483c75c0e31147189755e3
treed18a33fa3421a0efa2647ea88f2ad81e36d62e73
parent93ddea2a70991f24f2b4de81d2d9beb0136c9a5e
matroskademux: try to ensure keyframe when seeking without index

When seeking in pull mode without an index (because there is no index
or the file is still being written to) we bisect to find the right
cluster to jump to. However, it's possible the cluster we found doesn't
start with a keyframe, which leads to decoding errors, so if we know
that the found cluster starts with a delta frame try to scan back to
previous clusters until we find one that starts with a keyframe or
we are back at the beginning. Theoretically it's possible that all
clusters but the first one do not start with a keyframe and the
keyframes are in the middle of clusters, but this is extremely
unusual, so we will cover this case with a basic sanity check.

This problem is especially problematic with content recorded with
dynamic GOP and FPS, where long GOP lengths and low FPS may cause a
large set of clusters to lack key frames. Playback would then be
started on a non-keyframe cluster, and the large number of such frames
would make the content impossible to decode fo a long stretch of time.

Based on patch by: Mats Lindestam <matslm@axis.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790696
gst/matroska/matroska-demux.c