@blockcast/mmt-container 2.2.0-main.c4fa878f4ff4 → 2.2.0-main.cb533d6dfc95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -17
- package/dist/browser-runtime.js +1540 -317
- package/dist/browser-runtime.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +17 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +15 -0
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmcd-producer.d.ts +60 -47
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +138 -109
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js.map +1 -1
- package/dist/fec-manager.d.ts +83 -15
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +446 -61
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +48 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +97 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mmtp-container-parser.d.ts +79 -10
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +299 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +301 -30
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +298 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +34 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +647 -80
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-manager.d.ts +26 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1183 -160
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +28 -18
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +298 -27
- package/dist/no-modules.js.map +3 -3
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.d.ts +6 -2
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +6 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +298 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/schemas/catalog.schema.json +4 -0
- package/src/catalog-fec-params.ts +36 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +487 -35
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +9 -2
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +306 -29
- package/src/mmtp-router.ts +548 -38
- package/src/multicast-manager.ts +134 -16
- package/src/repair-fetch.ts +366 -50
- package/src/repair-layer-subscriptions.ts +13 -5
- package/src/track-session.ts +4 -1
package/src/codec-utils.ts
CHANGED
|
@@ -1276,9 +1276,21 @@ function isH264IntraSlice(nal: Uint8Array): boolean {
|
|
|
1276
1276
|
return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9
|
|
1277
1277
|
}
|
|
1278
1278
|
|
|
1279
|
+
/**
|
|
1280
|
+
* Escaped bytes after the NAL header that always hold first_mb_in_slice and
|
|
1281
|
+
* slice_type. {@link readUnsignedExpGolomb} reads at most 61 bits per ue(v)
|
|
1282
|
+
* and gives up at the 31st leading zero, so both fields end within 122 bits
|
|
1283
|
+
* (16 bytes) of RBSP. {@link removeEmulationPrevention} drops a 0x03 only
|
|
1284
|
+
* after two kept zero bytes since the last one it dropped, so 32 escaped
|
|
1285
|
+
* bytes unescape to at least 22.
|
|
1286
|
+
*/
|
|
1287
|
+
const H264_SLICE_TYPE_ESCAPED_BYTES = 32
|
|
1288
|
+
|
|
1279
1289
|
function readH264SliceType(nal: Uint8Array): number | null {
|
|
1280
1290
|
if (nal.length < 2 || (nal[0]! & 0x1f) !== 1) return null
|
|
1281
|
-
|
|
1291
|
+
// Unescape the start of the slice header only, not the whole slice: this
|
|
1292
|
+
// runs on every non-IDR frame.
|
|
1293
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES))
|
|
1282
1294
|
const state = { bitOffset: 0 }
|
|
1283
1295
|
if (readUnsignedExpGolomb(rbsp, state) === null) return null
|
|
1284
1296
|
return readUnsignedExpGolomb(rbsp, state)
|
|
@@ -1705,6 +1717,114 @@ if (import.meta.vitest) {
|
|
|
1705
1717
|
})
|
|
1706
1718
|
})
|
|
1707
1719
|
|
|
1720
|
+
describe('readH264SliceType', () => {
|
|
1721
|
+
/** The read as it was before the prefix bound: unescape the whole NAL unit. */
|
|
1722
|
+
const wholeNalSliceType = (nal: Uint8Array): number | null => {
|
|
1723
|
+
if (nal.length < 2 || (nal[0]! & 0x1f) !== 1) return null
|
|
1724
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1))
|
|
1725
|
+
const state = { bitOffset: 0 }
|
|
1726
|
+
if (readUnsignedExpGolomb(rbsp, state) === null) return null
|
|
1727
|
+
return readUnsignedExpGolomb(rbsp, state)
|
|
1728
|
+
}
|
|
1729
|
+
const hex = (text: string) => Uint8Array.from(text.match(/../g)!, (byte) => parseInt(byte, 16))
|
|
1730
|
+
const ue = (value: number) => {
|
|
1731
|
+
const code = (value + 1).toString(2)
|
|
1732
|
+
return '0'.repeat(code.length - 1) + code
|
|
1733
|
+
}
|
|
1734
|
+
/** A nal_unit_type 1 NAL unit from RBSP bits, escaped as an encoder escapes it (H.264 §7.4.1). */
|
|
1735
|
+
const sliceNal = (bits: string): Uint8Array => {
|
|
1736
|
+
const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, '0').match(/.{8}/g)!
|
|
1737
|
+
const nal = [0x01]
|
|
1738
|
+
let zeros = 0
|
|
1739
|
+
for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
|
|
1740
|
+
if (zeros >= 2 && byte <= 0x03) {
|
|
1741
|
+
nal.push(0x03)
|
|
1742
|
+
zeros = 0
|
|
1743
|
+
}
|
|
1744
|
+
nal.push(byte)
|
|
1745
|
+
zeros = byte === 0 ? zeros + 1 : 0
|
|
1746
|
+
}
|
|
1747
|
+
return Uint8Array.from(nal)
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// x264 core 164 (FFmpeg 6.1.1) slices of testsrc2: 64x48 with open-gop=1:bframes=2:slices=3;
|
|
1751
|
+
// 1280x720 main with bframes=2:slices=4, each carrying an emulation_prevention_three_byte
|
|
1752
|
+
// in its first 32 bytes; and the first 40 bytes of 7680x4320 slices=4 slices, whose
|
|
1753
|
+
// first_mb_in_slice takes up to 33 bits. [name, NAL unit, slice_type, keyframe]
|
|
1754
|
+
const x264Slices: Array<[string, Uint8Array, number | null, boolean]> = [
|
|
1755
|
+
['64x48 P', hex('419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176'), 5, false],
|
|
1756
|
+
['64x48 B', hex('419e414212fffeeade283707cb70f7'), 6, false],
|
|
1757
|
+
['64x48 non-IDR I', hex(
|
|
1758
|
+
'4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66' +
|
|
1759
|
+
'247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39' +
|
|
1760
|
+
'a527e23eb34c8167fd',
|
|
1761
|
+
), 7, true],
|
|
1762
|
+
['1280x720 B, escape at byte 10', hex(
|
|
1763
|
+
'01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e' +
|
|
1764
|
+
'19b75d92170917306190f262fd58268702db2eff86a9651e48',
|
|
1765
|
+
), 6, false],
|
|
1766
|
+
['1280x720 P, escape at byte 15', hex(
|
|
1767
|
+
'41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f0' +
|
|
1768
|
+
'2c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e8530' +
|
|
1769
|
+
'2da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3',
|
|
1770
|
+
), 5, false],
|
|
1771
|
+
['1280x720 B, escape at byte 22', hex('01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352'), 6, false],
|
|
1772
|
+
['7680x4320 IDR, first_mb_in_slice 97440', hex(
|
|
1773
|
+
'650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9',
|
|
1774
|
+
), null, true],
|
|
1775
|
+
['7680x4320 P, first_mb_in_slice 32640', hex(
|
|
1776
|
+
'410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020',
|
|
1777
|
+
), 5, false],
|
|
1778
|
+
['7680x4320 P, first_mb_in_slice 97440', hex(
|
|
1779
|
+
'410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806',
|
|
1780
|
+
), 5, false],
|
|
1781
|
+
]
|
|
1782
|
+
// Field values far past what a picture needs, so that escapes fall inside the two fields.
|
|
1783
|
+
const syntheticSlices: Array<[string, Uint8Array, number | null]> = [
|
|
1784
|
+
['an escape inside first_mb_in_slice', sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
|
|
1785
|
+
['an escape between the fields', sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
|
|
1786
|
+
['an escape inside slice_type', sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
|
|
1787
|
+
['the longest fields, five escapes', sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
|
|
1788
|
+
['the largest values', sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
|
|
1789
|
+
['31 leading zeros in first_mb_in_slice', sliceNal(`${'0'.repeat(31)}1`), null],
|
|
1790
|
+
['31 leading zeros in slice_type', sliceNal(`1${'0'.repeat(31)}1`), null],
|
|
1791
|
+
['escapes running past the slice header', sliceNal(ue(0) + ue(5) + '0'.repeat(400)), 5],
|
|
1792
|
+
]
|
|
1793
|
+
|
|
1794
|
+
test('reads the slice_type of real and synthetic slices', () => {
|
|
1795
|
+
for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
|
|
1796
|
+
expect(readH264SliceType(nal), name).toBe(sliceType)
|
|
1797
|
+
}
|
|
1798
|
+
})
|
|
1799
|
+
|
|
1800
|
+
test('matches the whole-NAL unescape at every truncation', () => {
|
|
1801
|
+
for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
|
|
1802
|
+
for (let end = 0; end <= nal.length; end++) {
|
|
1803
|
+
const cut = nal.subarray(0, end)
|
|
1804
|
+
expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut))
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
})
|
|
1808
|
+
|
|
1809
|
+
test('matches the whole-NAL unescape on zero-heavy NAL units', () => {
|
|
1810
|
+
const bytes = [0x00, 0x00, 0x00, 0x03, 0x01, 0x02, 0x80, 0xff]
|
|
1811
|
+
let seed = 1
|
|
1812
|
+
const next = () => (seed = (Math.imul(seed, 1103515245) + 12345) >>> 0) >>> 16
|
|
1813
|
+
for (let i = 0; i < 5000; i++) {
|
|
1814
|
+
const nal = new Uint8Array(2 + (next() % 63))
|
|
1815
|
+
nal[0] = 0x41
|
|
1816
|
+
for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length]!
|
|
1817
|
+
expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal))
|
|
1818
|
+
}
|
|
1819
|
+
})
|
|
1820
|
+
|
|
1821
|
+
test('classifies the x264 slices as keyframes or not', () => {
|
|
1822
|
+
for (const [name, nal, , keyframe] of x264Slices) {
|
|
1823
|
+
expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe)
|
|
1824
|
+
}
|
|
1825
|
+
})
|
|
1826
|
+
})
|
|
1827
|
+
|
|
1708
1828
|
describe('avccToAnnexB', () => {
|
|
1709
1829
|
test('converts with SPS/PPS on keyframe', () => {
|
|
1710
1830
|
const avcc = new Uint8Array([0, 0, 0, 3, 0x65, 0xAA, 0xBB])
|