Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getVideoField: when seeking forward isn't possible, try reading and discarding #473

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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