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

TS Extractor: Fix problem with corrupt last PCR in recordings #9100

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,29 @@ private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHo
private long readLastPcrValueFromBuffer(ParsableByteArray packetBuffer, int pcrPid) {
int searchStartPosition = packetBuffer.getPosition();
int searchEndPosition = packetBuffer.limit();
long pcrLast = C.TIME_UNSET;
for (int searchPosition = searchEndPosition - 1;
searchPosition >= searchStartPosition;
searchPosition--) {
if (packetBuffer.getData()[searchPosition] != TsExtractor.TS_SYNC_BYTE) {
continue;
}
long pcrValue = TsUtil.readPcrFromPacket(packetBuffer, searchPosition, pcrPid);
// Fix for getting a bad last pcr value by misinterpreting data.
if (pcrValue != C.TIME_UNSET) {
return pcrValue;
if (pcrLast == C.TIME_UNSET)
pcrLast = pcrValue;
else {
// Sanity Check
// Look at the second-last pcr value and make sure interval is between 0 and 60 seconds
// 60 * 90_000 = 5_400_000
// otherwise discard the last value found and check again.
long interval = pcrLast - pcrValue;
if (interval > 0 && interval < 5_400_000)
return pcrLast;
else
pcrLast = pcrValue;
}
}
}
return C.TIME_UNSET;
Expand Down