Skip to content

Interface: IsoCustomBoxMap ​

Defined in: IsoCustomBoxMap.ts:26

Map of each custom box type to the type of that box. The map is empty.

To add a box type, declare the interface again in a declare module block:

ts
type CustomBox = { type: 'cstm'; value: number }

declare module '@svta/cml-iso-bmff' {
	interface IsoCustomBoxMap {
		cstm: CustomBox
	}
}

IsoBoxMap then has the box type. The result of readIsoBoxes, the readers map, the writers map, and the write functions have that box type too. The declaration applies to every file of the program. Two declarations of one box type need the same type. Do not declare uuid in this map. Declare the box types of uuid in IsoCustomUuidBoxMap.

Example ​

ts
const readCstm = (cursor: IsoBoxReadCursor): CustomBox => ({
	type: 'cstm',
	value: readUint32(cursor),
})

const writeCstm = (cursor: IsoBoxWriteCursor, box: CustomBox): void => {
	const start = beginIsoBox(cursor, box.type)
	writeUint32(cursor, box.value)
	endIsoBox(cursor, start)
}

function readValues(bytes: Uint8Array): number[] {
	const boxes = readIsoBoxes(bytes, { readers: { cstm: readCstm } })

	// The guard narrows each box to `CustomBox`.
	return filterIsoBoxes(boxes, box => isIsoBoxType('cstm', box)).map(box => box.value)
}

function writeValue(value: number): Uint8Array {
	return writeIsoBoxes([{ type: 'cstm', value }], { writers: { cstm: writeCstm } })
}

A Streaming Video Technology Alliance project.