fix: handle NaN in zero-scan fallback and symmetric divergence check
- validateDuration returns 0 instead of NaN when both container is NaN and scanned is zero - Use Math.abs for divergence check so container under-reporting is also corrected (not just over-reporting)
This commit is contained in:
@@ -27,9 +27,17 @@ describe("validateDuration", () => {
|
||||
expect(validateDuration(15.0, 15.3)).toBe(15.0);
|
||||
});
|
||||
|
||||
it("returns scanned duration when container under-reports beyond threshold", () => {
|
||||
expect(validateDuration(10, 15.3)).toBe(15.3);
|
||||
});
|
||||
|
||||
it("returns container duration when scanned is zero (corrupted/empty file)", () => {
|
||||
expect(validateDuration(10, 0)).toBe(10);
|
||||
});
|
||||
|
||||
it("returns 0 when both container is NaN and scanned is zero", () => {
|
||||
expect(validateDuration(NaN, 0)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldFailDecodeEndedEarly", () => {
|
||||
|
||||
@@ -86,12 +86,12 @@ export function validateDuration(containerDuration: number, scannedDuration: num
|
||||
if (scannedDuration <= 0) {
|
||||
// Zero scanned duration means corrupted/empty file — fall back to container
|
||||
// (downstream shouldFailDecodeEndedEarly will catch truly empty files)
|
||||
return Math.max(containerDuration, 0);
|
||||
return Number.isFinite(containerDuration) ? Math.max(containerDuration, 0) : 0;
|
||||
}
|
||||
if (!Number.isFinite(containerDuration) || containerDuration <= 0) {
|
||||
return scannedDuration;
|
||||
}
|
||||
if (containerDuration - scannedDuration > DURATION_DIVERGENCE_THRESHOLD_SEC) {
|
||||
if (Math.abs(containerDuration - scannedDuration) > DURATION_DIVERGENCE_THRESHOLD_SEC) {
|
||||
return scannedDuration;
|
||||
}
|
||||
return containerDuration;
|
||||
|
||||
Reference in New Issue
Block a user