Skip to content

Commit

Permalink
Merge pull request #473 from atsampson/skipseek
Browse files Browse the repository at this point in the history
getVideoField: when seeking forward isn't possible, try reading and discarding
  • Loading branch information
Simon Inns committed Mar 23, 2020
2 parents 0c641fc + 29bb8a5 commit 2ee735a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/library/tbc/sourcevideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(outputFieldData.data()),
qMin(discardBytes, static_cast<qint64>(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;
}

Expand Down

0 comments on commit 2ee735a

Please sign in to comment.