Fix faulty faulty lookup table logic (addresses #70)

This commit is contained in:
Vanilagy
2025-08-22 14:20:57 +02:00
parent bb9554df60
commit 2d62395fc0
4 changed files with 19 additions and 15 deletions
+7 -7
View File
@@ -2460,15 +2460,10 @@ abstract class IsobmffTrackBacking implements InputTrackBacking {
metadataReader.pos = startPos + boxInfo.totalSize;
}
let result: EncodedPacket | null = null;
const bestFragment = bestFragmentIndex !== -1 ? this.internalTrack.fragments[bestFragmentIndex]! : null;
if (bestFragment) {
// If we finished looping but didn't find a perfect match, still return the best match we found
result = await this.fetchPacketInFragment(bestFragment, bestSampleIndex, options);
}
// Catch faulty lookup table entries
if (!result && lookupEntry && (!bestFragment || bestFragment.moofOffset < lookupEntry.moofOffset)) {
if (lookupEntry && (!bestFragment || bestFragment.moofOffset < lookupEntry.moofOffset)) {
// The lookup table entry lied to us! We found a lookup entry but no fragment there that satisfied
// the match. In this case, let's search again but using the lookup entry before that.
const previousLookupEntry = this.internalTrack.fragmentLookupTable![lookupEntryIndex - 1];
@@ -2476,7 +2471,12 @@ abstract class IsobmffTrackBacking implements InputTrackBacking {
return this.performFragmentedLookup(getBestMatch, newSearchTimestamp, latestTimestamp, options);
}
return result;
if (bestFragment) {
// If we finished looping but didn't find a perfect match, still return the best match we found
return this.fetchPacketInFragment(bestFragment, bestSampleIndex, options);
}
return null;
} finally {
release();
}
+7 -7
View File
@@ -1731,15 +1731,10 @@ abstract class MatroskaTrackBacking implements InputTrackBacking {
metadataReader.pos = dataStartPos + size;
}
let result: EncodedPacket | null = null;
const bestCluster = bestClusterIndex !== -1 ? this.internalTrack.clusters[bestClusterIndex]! : null;
if (bestCluster) {
// If we finished looping but didn't find a perfect match, still return the best match we found
result = await this.fetchPacketInCluster(bestCluster, bestBlockIndex, options);
}
// Catch faulty cue points
if (!result && cuePoint && (!bestCluster || bestCluster.elementStartPos < cuePoint.clusterPosition)) {
if (cuePoint && (!bestCluster || bestCluster.elementStartPos < cuePoint.clusterPosition)) {
// The cue point lied to us! We found a cue point but no cluster there that satisfied the match. In this
// case, let's search again but using the cue point before that.
const previousCuePoint = this.internalTrack.cuePoints[cuePointIndex - 1];
@@ -1747,7 +1742,12 @@ abstract class MatroskaTrackBacking implements InputTrackBacking {
return this.performClusterLookup(getBestMatch, newSearchTimestamp, latestTimestamp, options);
}
return result;
if (bestCluster) {
// If we finished looping but didn't find a perfect match, still return the best match we found
return this.fetchPacketInCluster(bestCluster, bestBlockIndex, options);
}
return null;
} finally {
release();
}