From 29bb8a51df4145e1fa9d6dda143f635d9062f440 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sun, 8 Mar 2020 21:36:58 +0000 Subject: [PATCH] When seeking forward isn't possible, try skipping. When SourceVideo::getVideoField is reading video from an unseekable source, like a pipe, trying to seek forward to a field later in the file would fail -- which, for example, means you couldn't use "ld-chroma-decoder -s" when input was from a pipe. Make it try to read and discard data instead when seeking forward fails. If reading fails or hits the end of the input stream, it'll report an error as before. --- tools/library/tbc/sourcevideo.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/library/tbc/sourcevideo.cpp b/tools/library/tbc/sourcevideo.cpp index ad5ddc53d..9a8d83cb8 100644 --- a/tools/library/tbc/sourcevideo.cpp +++ b/tools/library/tbc/sourcevideo.cpp @@ -185,7 +185,24 @@ SourceVideo::Data SourceVideo::getVideoField(qint32 fieldNumber, qint32 startFie // Seek to the correct file position (if not already there) if (inputFilePos != requiredStartPosition) { - if (!inputFile.seek(requiredStartPosition)) qFatal("Could not seek to required field position in input TBC file"); + if (!inputFile.seek(requiredStartPosition)) { + // Seek failed + + if (inputFilePos > requiredStartPosition) { + qFatal("Could not seek backwards to required field position in input TBC file"); + } else { + // Seeking forwards -- try reading and discarding data instead + qint64 discardBytes = requiredStartPosition - inputFilePos; + while (discardBytes > 0) { + qint64 readBytes = inputFile.read(reinterpret_cast(outputFieldData.data()), + qMin(discardBytes, static_cast(outputFieldData.size() * 2))); + if (readBytes <= 0) { + qFatal("Could not seek or read forwards to required field position in input TBC file"); + } + discardBytes -= readBytes; + } + } + } inputFilePos = requiredStartPosition; }