Function: createInt64OverflowReader()
function createInt64OverflowReader(onOverflow): IsoInt64Reader;Defined in: createInt64OverflowReader.ts:26
Creates a function for the int64 option of IsoBoxReadConfig that reports a rounded value.
The function reads every 64-bit integer field as a number, so the types of the result do not change. A number holds integers up to 2^53 - 1 exactly. When a value is outside the safe integer range, the function calls onOverflow with a RangeError. When onOverflow returns, the read continues with the rounded value. When onOverflow throws, the read stops with that error.
A version 1 mvhd, tkhd, or mdhd box can have a duration with all bits set. ISO/IEC 14496-12 uses that value for a duration that cannot be determined, and the function reports it too.
The function does not need BigInt. To read the exact value, use readInt64AsBigInt.
Parameters
onOverflow
(error) => void
The callback for a value outside the safe integer range.
Returns
A function for the int64 option.
Example
// A moof box that holds a traf box with a version 1 tfdt box.
// baseMediaDecodeTime is 2^53 + 1, which a number cannot hold.
const bytes = new Uint8Array([
0,
0,
0,
36,
0x6d,
0x6f,
0x6f,
0x66, // moof
0,
0,
0,
28,
0x74,
0x72,
0x61,
0x66, // traf
0,
0,
0,
20,
0x74,
0x66,
0x64,
0x74,
1,
0,
0,
0, // tfdt, version 1
0,
0x20,
0,
0,
0,
0,
0,
1, // baseMediaDecodeTime
])
const errors: RangeError[] = []
const boxes = readIsoBoxes(bytes, {
int64: createInt64OverflowReader(error => {
errors.push(error)
}),
readers: { tfdt: readTfdt },
})
// The field is a number, rounded to 2^53, and errors holds one RangeError.
const tfdt = findIsoBox(boxes, box => isIsoBoxType('tfdt', box))