@blockcast/mmt-container 2.2.0-main.5da4e39e7fb8 → 2.2.0-main.5deae23da0f9
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 +125 -2
- package/dist/__tests__/ad-creative-signer.d.ts +11 -0
- package/dist/__tests__/ad-creative-signer.d.ts.map +1 -0
- package/dist/__tests__/test-utils.d.ts +1 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -1
- package/dist/ad-beacon.d.ts +39 -0
- package/dist/ad-beacon.d.ts.map +1 -0
- package/dist/ad-beacon.js +21 -0
- package/dist/ad-beacon.js.map +7 -0
- package/dist/ad-creative-record.d.ts +65 -0
- package/dist/ad-creative-record.d.ts.map +1 -0
- package/dist/ad-creative-record.js +2281 -0
- package/dist/ad-creative-record.js.map +7 -0
- package/dist/ad-creative-timeline.d.ts +103 -0
- package/dist/ad-creative-timeline.d.ts.map +1 -0
- package/dist/ad-creative-timeline.js +2548 -0
- package/dist/ad-creative-timeline.js.map +7 -0
- package/dist/block-policy.d.ts +128 -14
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +472 -27
- package/dist/block-policy.js.map +2 -2
- package/dist/browser-runtime.js +1024 -117
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +1 -0
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +34 -0
- package/dist/carp-catalog.js.map +4 -4
- package/dist/catalog-fec-params.js.map +1 -1
- package/dist/catalog-network-source.d.ts +1 -17
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +25 -19
- package/dist/catalog-network-source.js.map +3 -3
- package/dist/cmaf-block-assembler.d.ts +10 -2
- package/dist/cmaf-block-assembler.d.ts.map +1 -1
- package/dist/cmaf-block-assembler.js +30 -8
- package/dist/cmaf-block-assembler.js.map +3 -3
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +16 -3
- package/dist/codec-utils.js.map +2 -2
- package/dist/conceal-timeline.d.ts +24 -1
- package/dist/conceal-timeline.d.ts.map +1 -1
- package/dist/conceal-timeline.js +201 -4
- package/dist/conceal-timeline.js.map +3 -3
- package/dist/datagram-leg-deadline.d.ts +4 -0
- package/dist/datagram-leg-deadline.d.ts.map +1 -1
- package/dist/datagram-leg-deadline.js.map +2 -2
- package/dist/event-timeline-mmtp.d.ts +17 -0
- package/dist/event-timeline-mmtp.d.ts.map +1 -0
- package/dist/event-timeline-mmtp.js +3117 -0
- package/dist/event-timeline-mmtp.js.map +7 -0
- package/dist/fec-manager.d.ts +24 -3
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +531 -38
- package/dist/fec-manager.js.map +2 -2
- package/dist/feed-gate.d.ts +114 -0
- package/dist/feed-gate.d.ts.map +1 -0
- package/dist/feed-gate.js +175 -0
- package/dist/feed-gate.js.map +7 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +16 -0
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +28 -0
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/mfu-reassembler.d.ts +2 -0
- package/dist/mfu-reassembler.d.ts.map +1 -1
- package/dist/mfu-reassembler.js +4 -2
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts +12 -0
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +73 -3
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +103 -25
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +73 -3
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +20 -2
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +150 -23
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.js.map +1 -1
- package/dist/multicast-input.js.map +1 -1
- package/dist/multicast-manager.d.ts +23 -2
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +737 -86
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +44 -22
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +98 -22
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +10 -3
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +31 -5
- package/dist/repair-fetch.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +73 -3
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +17 -5
- package/schemas/catalog.schema.json +7 -2
- package/src/ad-beacon.ts +51 -0
- package/src/ad-creative-record.ts +276 -0
- package/src/ad-creative-timeline.ts +410 -0
- package/src/block-policy.ts +673 -42
- package/src/carp-catalog.ts +9 -0
- package/src/catalog-network-source.ts +3 -37
- package/src/cmaf-block-assembler.ts +17 -0
- package/src/codec-utils.ts +19 -3
- package/src/conceal-timeline.ts +60 -5
- package/src/datagram-leg-deadline.ts +4 -0
- package/src/event-timeline-mmtp.ts +55 -0
- package/src/fec-manager.ts +84 -12
- package/src/feed-gate.ts +295 -0
- package/src/index.ts +21 -0
- package/src/iso-bmff-timing.ts +33 -0
- package/src/mfu-reassembler.ts +4 -0
- package/src/mmtp-container-parser.ts +51 -5
- package/src/mmtp-router.ts +116 -4
- package/src/multicast-manager.ts +31 -0
- package/src/repair-fetch.ts +53 -8
- package/test-vectors/catalog/README.md +1 -0
- package/test-vectors/catalog/negative/event-timeline-empty-event-type.json +41 -0
- package/test-vectors/catalog/positive/event-timeline-ad-creative.json +41 -0
- package/test-vectors/catalog/positive/event-timeline-wallclock-no-depends.json +38 -0
- package/test-vectors/catalog/positive/multicast-event-timeline.json +81 -0
- package/test-vectors/catalog/section-codes.json +1 -0
- package/test-vectors/frame-needs-v1.json +295 -0
- package/test-vectors/repair-policy-v1.json +36 -3
package/dist/block-policy.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/block-policy.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Keyframe-protected FEC repair policy.\n *\n * Every FEC block still gets in-band FEC decode. What this module decides is\n * (1) which blocks may hold a keyframe (RAP), so a block short of K at its\n * repair deadline can be repaired over QUIC with the right priority, and\n * (2) what a sink must do with the first frame released after a gap: stall\n * until the next RAP, or conceal and keep playing.\n *\n * The two decisions are deliberately independent. Classification only sets\n * repair priority. The stall/conceal decision is made again per released gap\n * from the media that is actually missing, so a wrong classification can only\n * lower a block's repair priority; it can never make playback wrong.\n *\n * Everything here is derived from catalog-authored timing and in-band MMTP\n * evidence. There are no timers, no cadence heuristics, and no defaults: a\n * track whose geometry cannot be derived exactly runs in the defined\n * fail-closed mode `all-protected`, where every block is treated as possibly\n * keyframe-bearing.\n *\n * All three players (moqtail, hang, Shaka) consume this one implementation.\n */\n\nimport { deriveFecInterleaveDepth } from '@blockcast/mmt-fec'\n\n// \u2500\u2500\u2500 Classes and priorities \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Repair class of one FEC block.\n *\n * - `keyframe`: the block holds (or held) a RAP / MPU start.\n * - `delta`: the block provably holds only non-RAP video frames.\n * - `unknown`: neither could be proven; treated exactly like `keyframe`.\n * - `audio`: an audio block.\n */\nexport type BlockClass = 'keyframe' | 'delta' | 'unknown' | 'audio'\n\n/** Repair priority. Lower is more urgent. */\nexport type RepairPriority = 0 | 1 | 2\n\nexport type TrackKind = 'video' | 'audio'\n\n/** P0 = keyframe/unknown (stall-preventing), P1 = audio, P2 = delta. */\nexport function repairPriorityForClass(blockClass: BlockClass): RepairPriority {\n switch (blockClass) {\n case 'keyframe':\n case 'unknown':\n return 0\n case 'audio':\n return 1\n case 'delta':\n return 2\n }\n}\n\n// \u2500\u2500\u2500 Geometry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport type ClassifierMode = 'classifying' | 'all-protected'\n\n/** Why a track runs `all-protected`. */\nexport type ClassifierReason =\n // Geometry (catalog) reasons.\n | 'framerate-absent'\n | 'keyframe-cadence-absent'\n | 'keyframe-interval-not-integral'\n | 'block-spans-gop'\n /**\n * The catalog keyframe interval is not an exact integer number of ticks\n * in the media track's own timescale (ISO-BMFF `mdhd`), so released RAP\n * spacing cannot be verified and hold-last cannot predict the next RAP.\n * Nothing is wrong with the stream; the cadence is simply unprovable.\n */\n | 'keyframe-interval-not-media-integral'\n /**\n * Another stream on this packetId was configured with its own geometry\n * and this one was not, so no geometry provably belongs to it (ABR rungs\n * sharing a packetId).\n */\n | 'stream-geometry-absent'\n // In-band invariant violations (positive evidence only).\n | 'rap-not-mpu-start'\n | 'mpu-longer-than-gop'\n | 'block-not-contiguous'\n /**\n * MPU-start RAPs are not exactly one keyframe interval apart per MPU:\n * released RAPs in the media timescale, or, once each frame is its own\n * movie fragment, RAP fragments G fragments apart per MPU (P3).\n */\n | 'rap-spacing-mismatch'\n /**\n * An MPU of several movie fragments whose fragments hold several samples:\n * neither sample_number nor the fragment number states a frame's MPU\n * position (P3).\n */\n | 'mpu-multiple-fragments'\n | 'block-wider-than-interleave'\n\n/** Raw catalog timing for one track. Never a resolved cadence. */\nexport interface BlockClassifierGeometryInput {\n readonly trackKind: TrackKind\n /** Catalog `framerate` (frames per second). */\n readonly framerate?: number\n /** Catalog `fec.interleaveDepthMs`: the full FEC block span (\u00A75.1). */\n readonly interleaveDepthMs: number\n /** Catalog track `timescale` for `keyframeIntervalTicks`. */\n readonly timescale?: number\n /** Catalog `keyframeIntervalTicks` (preferred when the timescale is present). */\n readonly keyframeIntervalTicks?: number\n /** Catalog `keyframeIntervalMs`. */\n readonly keyframeIntervalMs?: number\n}\n\n/** Exact keyframe interval as a rational number of seconds: ticks / timescale. */\nexport interface KeyframeInterval {\n readonly ticks: number\n readonly timescale: number\n}\n\nexport type BlockClassifierGeometry =\n | { readonly trackKind: 'audio' }\n | {\n readonly trackKind: 'video'\n readonly mode: 'classifying'\n /** F: one frame's duration in milliseconds (1000 / framerate). */\n readonly frameDurationMs: number\n /** D: media units per FEC block (deriveFecInterleaveDepth). */\n readonly interleaveUnits: number\n /** G: frames per GOP. */\n readonly gopFrames: number\n readonly keyframeInterval: KeyframeInterval\n }\n | {\n readonly trackKind: 'video'\n readonly mode: 'all-protected'\n readonly reason: ClassifierReason\n /** The catalog interval when one is stated: gap decisions use it (keyframeInstantBetween). */\n readonly keyframeInterval?: KeyframeInterval\n }\n\n/**\n * Integer value of `numerator / denominator` when it is one, else null.\n *\n * Catalog framerates are JSON numbers, so an NTSC rate arrives as the double\n * nearest 30000/1001. One multiply and one divide each add at most half an\n * ulp of relative error (IEEE-754), so a quotient within two ulps of an\n * integer IS that integer; anything further is genuinely non-integral.\n */\nfunction exactInteger(numerator: number, denominator: number): number | null {\n if (!Number.isFinite(numerator) || !Number.isFinite(denominator) || denominator === 0) {\n return null\n }\n const quotient = numerator / denominator\n const rounded = Math.round(quotient)\n if (rounded < 1) return null\n const representationError = 2 * Number.EPSILON * Math.abs(quotient)\n return Math.abs(quotient - rounded) <= representationError ? rounded : null\n}\n\nfunction isPositiveFinite(value: number | undefined): value is number {\n return value !== undefined && Number.isFinite(value) && value > 0\n}\n\n/**\n * Derive the per-track classifier geometry from raw catalog fields.\n *\n * `all-protected` is the policy's defined fail-closed state, not a default:\n * it is returned with the exact reason. The only throw is for a value the\n * catalog validator already rejects (a non-positive block span).\n */\nexport function deriveBlockClassifierGeometry(\n input: BlockClassifierGeometryInput,\n): BlockClassifierGeometry {\n if (!isPositiveFinite(input.interleaveDepthMs)) {\n throw new Error(\n `[BlockPolicy] interleaveDepthMs=${input.interleaveDepthMs} is not a positive block span; ` +\n 'the catalog validator rejects this',\n )\n }\n if (input.trackKind === 'audio') return { trackKind: 'audio' }\n\n // Every video geometry keeps the catalog interval: gap decisions need it in\n // either mode (fec-multicast-00 Block Classification item 3).\n let keyframeInterval: KeyframeInterval | undefined\n if (isPositiveFinite(input.keyframeIntervalTicks) && isPositiveFinite(input.timescale)) {\n keyframeInterval = { ticks: input.keyframeIntervalTicks, timescale: input.timescale }\n } else if (isPositiveFinite(input.keyframeIntervalMs)) {\n keyframeInterval = { ticks: input.keyframeIntervalMs, timescale: 1000 }\n }\n const protect = (reason: ClassifierReason): BlockClassifierGeometry => ({\n trackKind: 'video',\n mode: 'all-protected',\n reason,\n ...(keyframeInterval === undefined ? {} : { keyframeInterval }),\n })\n\n if (!isPositiveFinite(input.framerate)) return protect('framerate-absent')\n const framerate = input.framerate\n if (keyframeInterval === undefined) return protect('keyframe-cadence-absent')\n\n const gopFrames = exactInteger(keyframeInterval.ticks * framerate, keyframeInterval.timescale)\n if (gopFrames === null) return protect('keyframe-interval-not-integral')\n\n const frameDurationMs = 1000 / framerate\n const interleaveUnits = deriveFecInterleaveDepth(input.interleaveDepthMs, frameDurationMs)\n if (interleaveUnits >= gopFrames) return protect('block-spans-gop')\n\n return {\n trackKind: 'video',\n mode: 'classifying',\n frameDurationMs,\n interleaveUnits,\n gopFrames,\n keyframeInterval,\n }\n}\n\n/**\n * The keyframe interval expressed in a media track's timescale, or null when\n * the geometry states none or the interval is not an exact integer number of\n * media ticks (fec-multicast-00 Block Classification item 3: an inexact one\n * gives no usable interval).\n */\nexport function keyframeIntervalMediaTicks(\n geometry: BlockClassifierGeometry,\n mediaTimescale: number,\n): bigint | null {\n if (geometry.trackKind !== 'video' || geometry.keyframeInterval === undefined) return null\n if (!Number.isSafeInteger(mediaTimescale) || mediaTimescale <= 0) return null\n const { ticks, timescale } = geometry.keyframeInterval\n if (!Number.isSafeInteger(ticks) || !Number.isSafeInteger(timescale)) return null\n const scaled = BigInt(ticks) * BigInt(mediaTimescale)\n const divisor = BigInt(timescale)\n if (scaled % divisor !== 0n) return null\n return scaled / divisor\n}\n\n/**\n * fec-multicast-00 Block Classification item 3 for two released frames:\n * whether `(from, to]` holds `start + k * interval` for some k >= 1, `start`\n * the decode time of an MPU's first RAP, all in one media timescale. `from`\n * is exclusive: the frame at `from` is held and complete, so an instant there\n * is that frame itself (an on-cadence RAP), not a lost one. The draft's closed\n * interval is for bounding packets, which may be part of a RAP.\n */\nexport function keyframeInstantBetween(start: bigint, interval: bigint, from: bigint, to: bigint): boolean {\n const k = from >= start ? (from - start) / interval + 1n : 1n\n return start + k * interval <= to\n}\n\n// \u2500\u2500\u2500 Evidence \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * In-band evidence from ONE first-arrival source symbol received from the\n * network. Recovered symbols and repair symbols never contribute, and the\n * MFU `priority > 0x80` hint is not evidence.\n */\nexport interface SourceSymbolEvidence {\n /** The MMTP header R (RAP) bit. */\n readonly rap: boolean\n /** MPU_sequence_number, when parsed from this packet. */\n readonly mpu?: number\n /**\n * 0-based sample position within its movie fragment: the MFU DU-header\n * `sample_number` minus one (ISO/IEC 23008-1 numbers samples from 1, and\n * the parser rejects `sample_number` 0). Present only when this packet\n * carried a DU header. It is the MPU position only while the MPU is one\n * movie fragment; BlockClassifier derives MPU positions (P3).\n */\n readonly idx?: number\n /**\n * movie_fragment_sequence_number from the DU header, when present. When\n * each frame is its own fragment, it positions the frame from its MPU's\n * RAP fragment (P3).\n */\n readonly movieFragment?: number\n /**\n * DU-header `offset`: the data unit's authored byte position within its\n * sample (0 for a whole-sample data unit, the partition boundary for a\n * subsample data unit). Present only with `idx`; absent reads as 0.\n */\n readonly offset?: number\n /**\n * The MMTP header packet_sequence_number (contiguous per packet_id). Not\n * classification evidence: FECManager uses it to bound how many blocks the\n * producer can have started between two source symbols, so an outage is\n * never mistaken for a source restart.\n */\n readonly packetSequenceNumber?: number\n}\n\nexport type ReclassificationEvidence = 'rap' | 'mpu-span' | 'window' | 'classifier-disabled'\n\nexport type ClassifierChange =\n | {\n readonly kind: 'reclassified'\n readonly sbn: number\n readonly from: BlockClass\n readonly to: BlockClass\n readonly evidence: ReclassificationEvidence\n }\n | {\n readonly kind: 'mode'\n readonly mode: 'all-protected'\n readonly reason: ClassifierReason\n }\n\ninterface BlockEvidence {\n rapSeen: boolean\n mpus: Set<number>\n /** The lowest and highest MPU positions its DU headers proved (P3). */\n positionMin?: number\n positionMax?: number\n cls: BlockClass\n}\n\n/** A data-unit start (a packet carrying a DU header) and the block it is in. */\ninterface DataUnitStart {\n readonly movieFragment: number\n readonly idx: number\n readonly offset: number\n readonly sbn: number\n}\n\n/**\n * Authored order of two data-unit starts of one MPU. Fragment numbers wrap\n * at 2^32, so they compare in RFC 1982 serial order.\n */\nfunction compareDataUnitStarts(\n a: Omit<DataUnitStart, 'sbn'>,\n b: Omit<DataUnitStart, 'sbn'>,\n): number {\n return ((a.movieFragment - b.movieFragment) | 0) || a.idx - b.idx || a.offset - b.offset\n}\n\n/**\n * How many MPUs behind the newest released RAP a stale release can be. The\n * release gate holds a frame for seconds at most, so a late copy is a few\n * MPUs back; anything further is another MPU sequence. With MPUs so short\n * that a late copy lies further back, it re-anchors there: the newest MPU's\n * gaps read rap-unknown until the next MPU's RAP, never a wrong measure.\n */\nconst LATE_RAP_MAX_MPUS_BACK = 64\n\n/** One MPU's movie fragments (P3). */\ninterface MpuLayout {\n /** Serial-earliest movie_fragment_sequence_number of its DU headers. */\n low: number\n /** The fragment of its first RAP-flagged DU header: position 0. */\n anchor?: number\n}\n\n/** What one DU header proves about its MPU (BlockClassifier `#place`). */\ninterface Placement {\n /** Its 0-based MPU position, when the wire proves it. */\n readonly position?: number\n /**\n * It shows a RAP inside an MPU, or an MPU longer than G: MPU boundaries\n * no longer bound the stream's RAPs (`rap-not-mpu-start`).\n */\n readonly rapNotMpuStart: boolean\n /** A refuted layout premise. */\n readonly violation?: ClassifierReason\n}\n\nconst UNPLACED: Placement = { rapNotMpuStart: false }\n\n/**\n * Per-stream block classifier.\n *\n * Classes only move toward more protection or narrower evidence:\n * `unknown\u2192delta` and `unknown\u2192keyframe` / `delta\u2192keyframe` on evidence, and\n * `delta\u2192unknown` when an invariant disables classification. `keyframe` is\n * terminal.\n *\n * The delta window rule rests on three premises, each guarded by an\n * invariant that fires on positive evidence only:\n *\n * - P1: the source packets of one block are one contiguous run of the\n * stream's authored order, and blocks follow each other in SBN order\n * (`block-not-contiguous`). The producer assigns SS_IDs in authored order\n * and a block is the SS_ID range [SBN*K, SBN*K + K), so this holds for a\n * block that closes at K symbols in the middle of a frame: that frame's\n * fragments then land in two ADJACENT blocks, which is still one run each.\n * A frame split across adjacent blocks is not a violation.\n * - P2: that run touches at most D media units, counting a frame continued\n * from the previous block (`block-wider-than-interleave`). The producer\n * counts a media-unit boundary only once the open block holds a symbol.\n * - P3: an MPU starts with its only RAP and holds at most G frames\n * (`rap-not-mpu-start`, `mpu-longer-than-gop`, `rap-spacing-mismatch`),\n * and its DU headers state each frame's MPU position in one of two layouts\n * (`mpu-multiple-fragments` when an MPU shows two fragments and a DU\n * header states sample_number above 1, which is neither):\n * - one movie fragment per MPU (ATSC 3.0): the position is\n * sample_number \u2212 1. This is the rule until some MPU of the sequence\n * shows two fragments.\n * - one fragment per frame, numbered one per frame (FFmpeg's MoQ MMT\n * muxer, every DU header stating sample_number 1): the position is the\n * fragment's distance from the fragment of the MPU's first RAP-flagged\n * DU header (its anchor). The RAP's own fragment is position 0. Each\n * anchor must lie exactly G fragments per MPU from the anchor received\n * before it, which is kept past the horizon, and from the anchor\n * received last (`rap-spacing-mismatch`, as after a dropped frame).\n * Once two anchors kept that spacing, fragment numbers count frames:\n * later fragments get positions, and an anchor arriving past the\n * spacing is a RAP inside its MPU or follows an MPU longer than G\n * (`rap-not-mpu-start`). An MPU whose anchor was not received has no\n * positions; its blocks stay unknown. A second RAP-flagged fragment, or\n * a DU header in a fragment before the anchor, refutes the MPU start\n * (`rap-not-mpu-start`).\n *\n * P1 and P2 are what make a block's frames contiguous and lie within\n * [positionMax \u2212 D + 1, positionMin + D \u2212 1] of its MPU. What refutes P1 is\n * a pair of source packets whose wire-stated authored order and SBN order\n * disagree: a later MPU in an earlier block, a later data unit of one MPU\n * (by movie_fragment_sequence_number, sample_number, then DU offset) in an\n * earlier block, or one data unit in two blocks. That is the signature of a\n * round-robin interleave, which scatters one run over several concurrent\n * blocks. Non-adjacency alone is not: a sample larger than K packets\n * legitimately spans blocks SBN..SBN+n.\n */\nexport class BlockClassifier {\n #geometry: BlockClassifierGeometry\n #mode: ClassifierMode\n #reason: ClassifierReason | null\n /**\n * False once the stream showed that an MPU boundary does not bound its\n * RAPs (a RAP inside an MPU, or an MPU longer than a GOP). Recorded in\n * every mode: the stall/conceal decision relies on it even when the\n * catalog geometry already runs the classifier `all-protected`.\n */\n #mpuBoundsRaps = true\n #blocks = new Map<number, BlockEvidence>()\n /**\n * P1 ledger, kept for the MPUs within the classification horizon (the\n * highest MPU seen and the one before it): the SBN span of every source\n * packet of each MPU, and each MPU's data-unit starts in authored order.\n * Valid only within one continuous SBN sequence; a source discontinuity\n * clears it (`noteSourceDiscontinuity`).\n */\n #mpuSbnSpans = new Map<number, { min: number; max: number }>()\n #dataUnitStarts = new Map<number, DataUnitStart[]>()\n #highestMpu: number | null = null\n /**\n * P3 layout, kept for the MPUs within the classification horizon and valid\n * within one continuous SBN sequence (`noteSourceDiscontinuity`).\n */\n #mpus = new Map<number, MpuLayout>()\n /** An MPU of this sequence showed two movie fragments: each frame is one. */\n #fragmentPerFrame = false\n /** A DU header of this sequence stated sample_number above 1. */\n #multiSampleFragment = false\n /**\n * The anchor received last, whether or not its MPU is still in the\n * horizon. Each new anchor, and the anchor of every DU header's MPU, is\n * checked against it.\n */\n #lastAnchor: { mpu: number; fragment: number } | null = null\n /** Two anchors were exactly G fragments per MPU apart. */\n #fragmentsProven = false\n /** The first RAP released of the latest MPU a RAP was released in, recorded in every mode. */\n #lastRap: { mpu: number; presentationTime: bigint; mediaTimescale: number; decodeTime?: bigint } | null = null\n\n constructor(geometry: BlockClassifierGeometry) {\n this.#geometry = geometry\n this.#mode = 'classifying'\n this.#reason = null\n this.reset(geometry)\n }\n\n get geometry(): BlockClassifierGeometry {\n return this.#geometry\n }\n\n get mode(): ClassifierMode {\n return this.#mode\n }\n\n get reason(): ClassifierReason | null {\n return this.#reason\n }\n\n /**\n * Whether \"same MPU on both sides of a gap\" still proves the gap held no\n * RAP. It stops holding for the rest of the epoch once a RAP was received\n * inside an MPU or an MPU ran longer than a GOP.\n */\n get mpuBoundsRaps(): boolean {\n return this.#mpuBoundsRaps\n }\n\n /** Begin a fresh epoch (catalog change or track reset). */\n reset(geometry: BlockClassifierGeometry = this.#geometry): void {\n this.#geometry = geometry\n this.#blocks.clear()\n this.#clearContiguityLedger()\n this.#clearMpuLayout()\n this.#lastRap = null\n this.#mpuBoundsRaps = true\n if (geometry.trackKind === 'video' && geometry.mode === 'all-protected') {\n this.#mode = 'all-protected'\n this.#reason = geometry.reason\n } else {\n this.#mode = 'classifying'\n this.#reason = null\n }\n }\n\n /**\n * Retire this classifier (its stream moves to a new catalog epoch). Every\n * block it had classified `delta` loses the evidence behind that class and\n * reads `unknown` from now on; the returned changes say so.\n */\n retire(): ClassifierChange[] {\n const changes: ClassifierChange[] = []\n for (const [sbn, block] of this.#blocks) {\n if (block.cls !== 'delta') continue\n block.cls = 'unknown'\n changes.push({\n kind: 'reclassified',\n sbn,\n from: 'delta',\n to: 'unknown',\n evidence: 'classifier-disabled',\n })\n }\n return changes\n }\n\n /**\n * The stream's SBN sequence restarted (FECManager source discontinuity:\n * a publisher restart, or the SS_ID space wrapped). Authored order and SBN\n * order are comparable only within one continuous sequence, and a\n * restarted publisher numbers MPUs and movie fragments again, so the P1\n * ledger and the P3 layout start again.\n */\n noteSourceDiscontinuity(): void {\n this.#clearContiguityLedger()\n this.#clearMpuLayout()\n // A restarted publisher numbers MPUs again: its first RAP is no second\n // RAP of the MPU the old sequence last released one in.\n this.#lastRap = null\n }\n\n /** Register a block that exists without evidence (a vanished block). */\n touch(sbn: number): void {\n this.#blockFor(sbn)\n }\n\n /** Forget a resolved block. */\n forget(sbn: number): void {\n this.#blocks.delete(sbn)\n }\n\n classOf(sbn: number): BlockClass {\n if (this.#geometry.trackKind === 'audio') return 'audio'\n return this.#blocks.get(sbn)?.cls ?? 'unknown'\n }\n\n /** Record one first-arrival source symbol's evidence for block `sbn`. */\n observe(sbn: number, evidence: SourceSymbolEvidence): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const changes: ClassifierChange[] = []\n const block = this.#blockFor(sbn)\n const placement = this.#place(evidence)\n\n if (evidence.rap) block.rapSeen = true\n if (evidence.mpu !== undefined) block.mpus.add(evidence.mpu)\n const { position } = placement\n if (position !== undefined) {\n block.positionMin =\n block.positionMin === undefined ? position : Math.min(block.positionMin, position)\n block.positionMax =\n block.positionMax === undefined ? position : Math.max(block.positionMax, position)\n }\n\n // A RAP inside an MPU refutes \"an MPU boundary bounds RAPs\" whatever the\n // classifier mode, because gap decisions rely on it in every mode.\n if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false\n\n const violation = this.#checkInvariants(sbn, block, evidence, placement)\n if (violation !== null) changes.push(...this.#disable(violation))\n\n const next = this.#classify(block)\n if (next !== block.cls && this.#allowed(block.cls, next)) {\n changes.push({\n kind: 'reclassified',\n sbn,\n from: block.cls,\n to: next,\n evidence: this.#evidenceFor(block, next),\n })\n block.cls = next\n }\n return changes\n }\n\n /**\n * Record a RAP frame released in order. Released MPU-start RAPs of MPUs m\n * and m+n must be exactly n keyframe intervals apart in the media\n * timescale, compared as integers.\n *\n * Comparing only consecutive MPUs would miss exactly the case the window\n * rule cannot survive: a short MPU whose successor's RAP was lost (that\n * RAP-bearing block is the one a wrong G calls delta), because the next\n * released RAP then belongs to m+2. Every MPU is one interval long, so the\n * span to any later released RAP proves or refutes all MPUs in between.\n *\n * In every mode it keeps each MPU's first released RAP, with its decode\n * time, as the start keyframeFreeBetween measures the catalog interval\n * from, and a second RAP released inside one MPU refutes `mpuBoundsRaps`\n * when it lies off the catalog lattice (not a whole number of intervals\n * after the first; draft-ramadan-moq-mmt-02 4.4.3 binds every keyframe to\n * it): with no repair, released RAPs are the only evidence of where they\n * lie. Without a usable interval, or a decode time on either, any second\n * RAP with another presentation time refutes.\n */\n noteReleasedRap(\n mpu: number,\n presentationTime: bigint,\n mediaTimescale: number,\n decodeTime?: bigint,\n ): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const previous = this.#lastRap\n // A further RAP inside an already-anchored MPU is not an MPU start; the\n // MPU keeps its first RAP as the spacing anchor (rap-not-mpu-start owns\n // mid-MPU RAPs). The same RAP released again is no further one.\n if (previous !== null && previous.mpu === mpu && previous.mediaTimescale === mediaTimescale) {\n if (presentationTime === previous.presentationTime) return []\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n if (\n interval === null ||\n decodeTime === undefined ||\n previous.decodeTime === undefined ||\n (decodeTime - previous.decodeTime) % interval !== 0n\n ) {\n this.#mpuBoundsRaps = false\n }\n return []\n }\n // A late copy of an earlier MPU's RAP (the gate reports stale releases\n // too) moves no anchor back: the newest MPU's gaps are measured from its\n // own. MPU sequence numbers wrap at 2^32, so \"earlier\" is serial; it is\n // bounded, and a late copy is older in presentation time than the anchor.\n // Any other RAP behind the anchor is a restarted MPU sequence nothing\n // signalled, which re-anchors, or no same-MPU gap could ever be measured\n // again. A restart inside the bound whose presentation time went back\n // too still reads as late, and fails closed: its same-MPU gaps stay\n // rap-unknown until its MPU numbers pass the old newest, and unless it\n // repeats the old timeline the spacing checks then end the epoch\n // all-protected.\n if (previous !== null && previous.mediaTimescale === mediaTimescale) {\n const back = (previous.mpu - mpu) >>> 0\n if (back !== 0 && back <= LATE_RAP_MAX_MPUS_BACK && presentationTime < previous.presentationTime) return []\n }\n this.#lastRap = { mpu, presentationTime, mediaTimescale, ...(decodeTime === undefined ? {} : { decodeTime }) }\n if (this.#mode === 'all-protected') return []\n // Verification compares integers in the media timescale. When the\n // catalog interval is not an exact tick count there, spacing is\n // unprovable: fail closed, naming the cause, rather than blaming the\n // encoder with rap-spacing-mismatch on a perfectly spaced RAP.\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n if (interval === null) return this.#disable('keyframe-interval-not-media-integral')\n if (\n previous === null ||\n mpu < previous.mpu ||\n previous.mediaTimescale !== mediaTimescale\n ) {\n return []\n }\n if (\n presentationTime - previous.presentationTime === interval * BigInt(mpu - previous.mpu)\n ) {\n return []\n }\n return this.#disable('rap-spacing-mismatch')\n }\n\n /**\n * Whether a gap inside MPU `mpu`, between the decode times `from` and `to`\n * of the frames on either side, holds no keyframe: MPU boundaries still\n * bound RAPs, the catalog states an interval exact in this timescale, and\n * none of its instants after the MPU's first released RAP lies in\n * `(from, to]` (fec-multicast-00 Block Classification item 3). Anything\n * unknown counts as a keyframe.\n */\n keyframeFreeBetween(mpu: number, from: bigint, to: bigint, mediaTimescale: number): boolean {\n const rap = this.#lastRap\n if (!this.#mpuBoundsRaps || rap?.mpu !== mpu || rap.mediaTimescale !== mediaTimescale || rap.decodeTime === undefined) {\n return false\n }\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n return interval !== null && !keyframeInstantBetween(rap.decodeTime, interval, from, to)\n }\n\n #blockFor(sbn: number): BlockEvidence {\n let block = this.#blocks.get(sbn)\n if (!block) {\n block = { rapSeen: false, mpus: new Set(), cls: 'unknown' }\n this.#blocks.set(sbn, block)\n }\n return block\n }\n\n #checkInvariants(\n sbn: number,\n block: BlockEvidence,\n evidence: SourceSymbolEvidence,\n placement: Placement,\n ): ClassifierReason | null {\n if (this.#mode === 'all-protected' || this.#geometry.trackKind !== 'video') return null\n const geometry = this.#geometry\n if (geometry.mode !== 'classifying') return null\n if (placement.rapNotMpuStart) return 'rap-not-mpu-start'\n if (placement.position !== undefined && placement.position >= geometry.gopFrames) {\n return 'mpu-longer-than-gop'\n }\n // A block closes at the latest after D media units, so the DU headers it\n // carries from one MPU lie within D consecutive positions. A wider span\n // means the producer closes blocks some other way (at K symbols, or\n // round-robin across concurrent blocks) and the window rule is void.\n if (\n block.mpus.size === 1 &&\n block.positionMin !== undefined &&\n block.positionMax !== undefined &&\n block.positionMax - block.positionMin >= geometry.interleaveUnits\n ) {\n return 'block-wider-than-interleave'\n }\n if (placement.violation !== undefined) return placement.violation\n if (evidence.mpu !== undefined && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {\n return 'block-not-contiguous'\n }\n return null\n }\n\n /**\n * The MPU position a source symbol's DU header proves (P3), and what it\n * refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.\n */\n #place(evidence: SourceSymbolEvidence): Placement {\n const { mpu, idx, movieFragment: fragment } = evidence\n if (idx === undefined) return UNPLACED\n const bySample: Placement = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 }\n // Every wire DU header states both; evidence without them keeps the\n // one-fragment rule unless the sequence is fragment-per-frame.\n if (mpu === undefined || fragment === undefined) {\n return this.#fragmentPerFrame && !this.#multiSampleFragment\n ? { rapNotMpuStart: bySample.rapNotMpuStart }\n : bySample\n }\n let layout = this.#mpus.get(mpu)\n if (layout === undefined) {\n layout = { low: fragment }\n this.#mpus.set(mpu, layout)\n // One entry per MPU still inside the classification horizon.\n for (const other of this.#mpus.keys()) {\n if (other + 1 < mpu) this.#mpus.delete(other)\n }\n } else if (fragment !== layout.low) {\n this.#fragmentPerFrame = true\n if (((fragment - layout.low) | 0) < 0) layout.low = fragment\n }\n if (idx !== 0) this.#multiSampleFragment = true\n let arrival: number | undefined\n if (evidence.rap && layout.anchor === undefined) {\n layout.anchor = fragment\n arrival = this.#anchorDrift(mpu, fragment)\n // Proof takes two MPUs: an MPU's RAP header seen again proves nothing.\n if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true\n this.#lastAnchor = { mpu, fragment }\n }\n // Until an MPU shows two fragments, sample_number \u2212 1 is the position.\n // Once one has, a sample_number above 1 leaves neither layout.\n if (!this.#fragmentPerFrame) return bySample\n if (this.#multiSampleFragment) return { ...bySample, violation: 'mpu-multiple-fragments' }\n const { anchor } = layout\n if (anchor === undefined) return UNPLACED\n // A new anchor against the anchor received before it; any other DU\n // header's anchor against the anchor received last, so an anchor that\n // arrived before the layout was known is held to the spacing too.\n const drift = arrival ?? this.#anchorDrift(mpu, anchor)\n // RFC 1982 distance from the anchor: positive for a later fragment.\n const offset = (fragment - anchor) | 0\n return {\n ...(offset === 0 || (offset > 0 && this.#fragmentsProven) ? { position: offset } : {}),\n rapNotMpuStart:\n (evidence.rap && offset !== 0) ||\n ((layout.low - anchor) | 0) < 0 ||\n // Fragments count frames: an anchor arriving past the spacing is a\n // RAP inside its MPU, or an earlier MPU outran G.\n (arrival !== undefined && arrival > 0 && this.#fragmentsProven),\n ...(drift === undefined || drift === 0 ? {} : { violation: 'rap-spacing-mismatch' }),\n }\n }\n\n /**\n * How many fragments MPU m's anchor `fragment` lies past the start that\n * the anchor received last predicts for MPU m: one frame per fragment and\n * G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')\n * fragments apart, modulo 2^32. Undefined without a last anchor, a\n * cadence, or this layout.\n */\n #anchorDrift(mpu: number, fragment: number): number | undefined {\n const geometry = this.#geometry\n const last = this.#lastAnchor\n if (\n last === null ||\n !this.#fragmentPerFrame ||\n this.#multiSampleFragment ||\n geometry.trackKind !== 'video' ||\n geometry.mode !== 'classifying'\n ) {\n return undefined\n }\n return (fragment - last.fragment - geometry.gopFrames * (mpu - last.mpu)) | 0\n }\n\n #clearMpuLayout(): void {\n this.#mpus.clear()\n this.#fragmentPerFrame = false\n this.#multiSampleFragment = false\n this.#lastAnchor = null\n this.#fragmentsProven = false\n }\n\n #clearContiguityLedger(): void {\n this.#mpuSbnSpans.clear()\n this.#dataUnitStarts.clear()\n this.#highestMpu = null\n }\n\n /**\n * P1 check for one source packet of MPU `mpu` in block `sbn`, then record\n * it. True when some recorded packet's authored order and SBN order\n * disagree with this one's (see the class comment). Only positions the\n * wire states are compared: MPU order for every packet, and data-unit\n * order for packets that carry a DU header. A packet of one data unit\n * that continues into the next block carries no DU header and so only\n * takes part through its MPU, which is exactly what makes an adjacent\n * straddle consistent.\n */\n #contradictsAuthoredOrder(sbn: number, mpu: number, evidence: SourceSymbolEvidence): boolean {\n // Every packet of MPU m precedes every packet of MPU m' > m.\n for (const [other, span] of this.#mpuSbnSpans) {\n if (other < mpu && span.max > sbn) return true\n if (other > mpu && span.min < sbn) return true\n }\n const inHorizon = this.#highestMpu === null || mpu + 1 >= this.#highestMpu\n let insertAt = -1\n let starts: DataUnitStart[] | undefined\n let start: DataUnitStart | undefined\n if (evidence.idx !== undefined) {\n start = {\n movieFragment: evidence.movieFragment ?? 0,\n idx: evidence.idx,\n offset: evidence.offset ?? 0,\n sbn,\n }\n starts = this.#dataUnitStarts.get(mpu)\n if (starts !== undefined) {\n let lo = 0\n let hi = starts.length\n while (lo < hi) {\n const mid = (lo + hi) >>> 1\n if (compareDataUnitStarts(starts[mid]!, start) < 0) lo = mid + 1\n else hi = mid\n }\n const at = starts[lo]\n if (at !== undefined && compareDataUnitStarts(at, start) === 0) {\n // One data unit has one first packet: seen in another block, the\n // SBN-to-authored-order map is not a function.\n if (at.sbn !== sbn) return true\n } else {\n const before = starts[lo - 1]\n if (before !== undefined && before.sbn > sbn) return true\n if (at !== undefined && at.sbn < sbn) return true\n insertAt = lo\n }\n }\n }\n if (!inHorizon) return false\n const span = this.#mpuSbnSpans.get(mpu)\n if (span === undefined) this.#mpuSbnSpans.set(mpu, { min: sbn, max: sbn })\n else {\n if (sbn < span.min) span.min = sbn\n if (sbn > span.max) span.max = sbn\n }\n if (start !== undefined) {\n if (starts === undefined) this.#dataUnitStarts.set(mpu, [start])\n else if (insertAt >= 0) starts.splice(insertAt, 0, start)\n }\n if (this.#highestMpu === null || mpu > this.#highestMpu) {\n this.#highestMpu = mpu\n for (const other of [...this.#mpuSbnSpans.keys()]) {\n if (other + 1 < mpu) {\n this.#mpuSbnSpans.delete(other)\n this.#dataUnitStarts.delete(other)\n }\n }\n }\n return false\n }\n\n #disable(reason: ClassifierReason): ClassifierChange[] {\n if (reason === 'rap-not-mpu-start' || reason === 'mpu-longer-than-gop') {\n this.#mpuBoundsRaps = false\n }\n if (this.#mode === 'all-protected') return []\n this.#mode = 'all-protected'\n this.#reason = reason\n const changes: ClassifierChange[] = [{ kind: 'mode', mode: 'all-protected', reason }]\n for (const [sbn, block] of this.#blocks) {\n if (block.cls !== 'delta') continue\n block.cls = 'unknown'\n changes.push({\n kind: 'reclassified',\n sbn,\n from: 'delta',\n to: 'unknown',\n evidence: 'classifier-disabled',\n })\n }\n return changes\n }\n\n #classify(block: BlockEvidence): BlockClass {\n if (block.rapSeen || block.mpus.size >= 2) return 'keyframe'\n if (this.#mode === 'all-protected') return 'unknown'\n const geometry = this.#geometry\n if (geometry.trackKind !== 'video' || geometry.mode !== 'classifying') return 'unknown'\n if (\n block.mpus.size === 1 &&\n block.positionMin !== undefined &&\n block.positionMax !== undefined\n ) {\n // A block closes every D media units, so its frames are contiguous and\n // lie in [positionMax \u2212 D + 1, positionMin + D \u2212 1] of MPU m. Position\n // 0 is the only RAP of an MPU and G bounds its length.\n const span = geometry.interleaveUnits - 1\n if (\n block.positionMax - span >= 1 &&\n block.positionMin + span <= geometry.gopFrames - 1\n ) {\n return 'delta'\n }\n }\n return 'unknown'\n }\n\n #allowed(from: BlockClass, to: BlockClass): boolean {\n if (from === 'keyframe') return false\n if (from === 'unknown') return to === 'delta' || to === 'keyframe'\n if (from === 'delta') return to === 'keyframe'\n return false\n }\n\n #evidenceFor(block: BlockEvidence, to: BlockClass): ReclassificationEvidence {\n if (to === 'delta') return 'window'\n return block.rapSeen ? 'rap' : 'mpu-span'\n }\n}\n\n// \u2500\u2500\u2500 Stall vs conceal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface GapStreamIdentity {\n readonly packetId: number\n /** Non-empty catalog identity, or null when the producer has no track name. */\n readonly catalogTrackName: string | null\n}\n\n/** What the sink knows about one side of a released gap. */\nexport interface GapFrameEvidence {\n /**\n * Codec-aware RAP check: `MmtpContainerParser.isKeyframe(data, rapFlag,\n * codec)`, bitstream-only for recovered frames. Never the priority hint.\n */\n readonly rap: boolean\n /**\n * MPU_sequence_number of the frame. Omit it once the stream showed that\n * an MPU boundary does not bound its RAPs (`BlockClassifier.mpuBoundsRaps`):\n * same-MPU then no longer proves a gap lost only deltas.\n */\n readonly mpu?: number\n /**\n * 0-based sample position within its movie fragment (sample_number \u2212 1).\n * State it on both sides only when both frames are in one movie fragment:\n * decideGap reads `after.idx \u2212 before.idx \u2212 1` as the samples missed\n * between them.\n */\n readonly idx?: number\n /** Authored presentation time in `timescale` ticks. */\n readonly pts?: bigint\n /** Authored sample duration in `timescale` ticks. */\n readonly durationTicks?: number\n /** The media timescale of `pts` and `durationTicks`. */\n readonly timescale?: number\n}\n\nexport type FrameGapAction = 'stall' | 'conceal'\n\nexport type FrameGapReason =\n | 'rap-lost'\n | 'rap-unknown'\n | 'discontinuity'\n | 'delta-lost'\n | 'rap-next'\n | 'audio-gap'\n | 'audio-discontinuity'\n\n/**\n * The decision attached to the first frame released after a gap\n * (`RoutedFrameMeta.gapBefore`). It is the same frozen object the manager\n * emits as its `gap` repair lifecycle event, so a sink that acts on the frame\n * and an observer that counts events see one fact.\n */\nexport interface FrameGapDecision {\n readonly version: 2\n readonly type: 'gap'\n readonly stream: GapStreamIdentity\n readonly trackKind: TrackKind\n readonly action: FrameGapAction\n readonly reason: FrameGapReason\n /** FEC blocks in the gap whose media was lost (failed or vanished). */\n readonly blocks: readonly number[]\n /** Missing video frames or audio access units, when exactly known. */\n readonly missingFrames: number | null\n /** Authored duration of the missing media in milliseconds, when known. */\n readonly missingMs: number | null\n /** Manager epoch of the stream when the decision was made. */\n readonly epoch: number\n}\n\nexport interface DecideGapInput {\n readonly stream: GapStreamIdentity\n readonly trackKind: TrackKind\n /** Last frame released before the gap. */\n readonly before: GapFrameEvidence\n /** First frame released after the gap. */\n readonly after: GapFrameEvidence\n /** The stream restarted (FEC SBN went backwards or the publisher reset). */\n readonly discontinuity: boolean\n readonly blocks: readonly number[]\n /**\n * The most media units the gap can hold: the FEC blocks spanned from the\n * frame before to the frame after, times D (media units per block,\n * ceil(interleaveDepthMs / unit duration), \u00A75.1). A block touches at most D\n * units whether it closes at D or at K symbols. Null when the span or D is\n * unknown. An audio PTS delta that implies more AUs than this is a clock\n * jump, not loss, and re-anchors instead of concealing every slot.\n */\n readonly maxMissingUnits: number | null\n readonly epoch: number\n}\n\nfunction durationMs(units: number, before: GapFrameEvidence): number | null {\n if (\n before.durationTicks === undefined ||\n before.timescale === undefined ||\n before.timescale <= 0\n ) {\n return null\n }\n return (units * before.durationTicks * 1000) / before.timescale\n}\n\n/**\n * Pure stall/conceal decision for the first frame released after a gap.\n *\n * Video stalls only when a RAP may be inside the gap: the frame after it is\n * not a RAP and either sits in another MPU (`rap-lost`) or the MPU cannot be\n * proven on both sides (`rap-unknown`), or the stream restarted\n * (`discontinuity`). A gap inside one MPU lost only deltas (`delta-lost`) and\n * a RAP after the gap resynchronises by itself (`rap-next`). Audio never\n * stalls: an exact gap is concealed per access unit (`audio-gap`), anything\n * else re-anchors at the next frame (`audio-discontinuity`).\n */\nexport function decideGap(input: DecideGapInput): FrameGapDecision {\n const { before, after } = input\n let action: FrameGapAction\n let reason: FrameGapReason\n let missingFrames: number | null = null\n\n if (input.trackKind === 'audio') {\n action = 'conceal'\n reason = 'audio-discontinuity'\n if (\n !input.discontinuity &&\n before.pts !== undefined &&\n after.pts !== undefined &&\n before.durationTicks !== undefined &&\n Number.isSafeInteger(before.durationTicks) &&\n before.durationTicks > 0\n ) {\n const auDuration = BigInt(before.durationTicks)\n const missingTicks = after.pts - before.pts - auDuration\n const bound = input.maxMissingUnits\n if (\n missingTicks > 0n &&\n missingTicks % auDuration === 0n &&\n bound !== null &&\n missingTicks / auDuration <= BigInt(bound)\n ) {\n reason = 'audio-gap'\n missingFrames = Number(missingTicks / auDuration)\n }\n }\n } else if (input.discontinuity) {\n action = 'stall'\n reason = 'discontinuity'\n } else if (after.rap) {\n action = 'conceal'\n reason = 'rap-next'\n } else if (before.mpu === undefined || after.mpu === undefined) {\n action = 'stall'\n reason = 'rap-unknown'\n } else if (before.mpu !== after.mpu) {\n action = 'stall'\n reason = 'rap-lost'\n } else {\n action = 'conceal'\n reason = 'delta-lost'\n if (before.idx !== undefined && after.idx !== undefined) {\n const missing = after.idx - before.idx - 1\n missingFrames = missing > 0 ? missing : null\n }\n }\n\n return Object.freeze({\n version: 2 as const,\n type: 'gap' as const,\n stream: Object.freeze({\n packetId: input.stream.packetId,\n catalogTrackName: input.stream.catalogTrackName,\n }),\n trackKind: input.trackKind,\n action,\n reason,\n blocks: Object.freeze([...input.blocks]),\n missingFrames,\n missingMs: missingFrames === null ? null : durationMs(missingFrames, before),\n epoch: input.epoch,\n })\n}\n"],
|
|
5
|
-
"mappings": ";AAuBA,SAAS,gCAAgC;AAoBlC,SAAS,uBAAuB,YAAwC;AAC7E,UAAQ,YAAY;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AA8FA,SAAS,aAAa,WAAmB,aAAoC;AAC3E,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,CAAC,OAAO,SAAS,WAAW,KAAK,gBAAgB,GAAG;AACrF,WAAO;AAAA,EACT;AACA,QAAM,WAAW,YAAY;AAC7B,QAAM,UAAU,KAAK,MAAM,QAAQ;AACnC,MAAI,UAAU,EAAG,QAAO;AACxB,QAAM,sBAAsB,IAAI,OAAO,UAAU,KAAK,IAAI,QAAQ;AAClE,SAAO,KAAK,IAAI,WAAW,OAAO,KAAK,sBAAsB,UAAU;AACzE;AAEA,SAAS,iBAAiB,OAA4C;AACpE,SAAO,UAAU,UAAa,OAAO,SAAS,KAAK,KAAK,QAAQ;AAClE;AASO,SAAS,8BACd,OACyB;AACzB,MAAI,CAAC,iBAAiB,MAAM,iBAAiB,GAAG;AAC9C,UAAM,IAAI;AAAA,MACR,mCAAmC,MAAM,iBAAiB;AAAA,IAE5D;AAAA,EACF;AACA,MAAI,MAAM,cAAc,QAAS,QAAO,EAAE,WAAW,QAAQ;AAI7D,MAAI;AACJ,MAAI,iBAAiB,MAAM,qBAAqB,KAAK,iBAAiB,MAAM,SAAS,GAAG;AACtF,uBAAmB,EAAE,OAAO,MAAM,uBAAuB,WAAW,MAAM,UAAU;AAAA,EACtF,WAAW,iBAAiB,MAAM,kBAAkB,GAAG;AACrD,uBAAmB,EAAE,OAAO,MAAM,oBAAoB,WAAW,IAAK;AAAA,E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AAe,MAC9B,UAAU,QACV,eAAe,cAAc,OAAO,KAAK,GACzC;AACA,iBAAS;AACT,wBAAgB,OAAO,eAAe,UAAU;AAAA,MAClD;AAAA,IACF;AAAA,EACF,WAAW,MAAM,eAAe;AAC9B,aAAS;AACT,aAAS;AAAA,EACX,WAAW,MAAM,KAAK;AACpB,aAAS;AACT,aAAS;AAAA,EACX,WAAW,OAAO,QAAQ,UAAa,MAAM,QAAQ,QAAW;AAC9D,aAAS;AACT,aAAS;AAAA,EACX,WAAW,OAAO,QAAQ,MAAM,KAAK;AACnC,aAAS;AACT,aAAS;AAAA,EACX,OAAO;AACL,aAAS;AACT,aAAS;AACT,QAAI,OAAO,QAAQ,UAAa,MAAM,QAAQ,QAAW;AACvD,YAAM,UAAU,MAAM,MAAM,OAAO,MAAM;AACzC,sBAAgB,UAAU,IAAI,UAAU;AAAA,IAC1C;AAAA,EACF;AAEA,SAAO,OAAO,OAAO;AAAA,IACnB,SAAS;AAAA,IACT,MAAM;AAAA,IACN,QAAQ,OAAO,OAAO;AAAA,MACpB,UAAU,MAAM,OAAO;AAAA,MACvB,kBAAkB,MAAM,OAAO;AAAA,IACjC,CAAC;AAAA,IACD,WAAW,MAAM;AAAA,IACjB;AAAA,IACA;AAAA,IACA,QAAQ,OAAO,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;AAAA,IACvC;AAAA,IACA,WAAW,kBAAkB,OAAO,OAAO,WAAW,eAAe,MAAM;AAAA,IAC3E,OAAO,MAAM;AAAA,EACf,CAAC;AACH;",
|
|
4
|
+
"sourcesContent": ["/**\n * Keyframe-protected FEC repair policy.\n *\n * Every FEC block still gets in-band FEC decode. What this module decides is\n * (1) which blocks may hold a keyframe (RAP), so a block short of K at its\n * repair deadline can be repaired over QUIC with the right priority, and\n * (2) what a sink must do with the first frame released after a gap: stall\n * until the next RAP, or conceal and keep playing.\n *\n * The two decisions are deliberately independent. Classification only sets\n * repair priority. The stall/conceal decision is made again per released gap\n * from the media that is actually missing, so a wrong classification can only\n * lower a block's repair priority; it can never make playback wrong.\n *\n * Everything here is derived from catalog-authored timing and in-band MMTP\n * evidence. There are no timers, no cadence heuristics, and no defaults: a\n * track whose geometry cannot be derived exactly runs in the defined\n * fail-closed mode `all-protected`, where the window rule is off: a block is\n * treated as possibly keyframe-bearing unless the MPU numbers of the DU\n * headers held around it show otherwise (the MPU rule). That rule needs no\n * block geometry, but it classes nothing on a track whose catalog does not\n * state a keyframe interval equal to its group duration.\n *\n * All three players (moqtail, hang, Shaka) consume this one implementation.\n */\n\nimport { deriveFecInterleaveDepth } from '@blockcast/mmt-fec'\n\n// \u2500\u2500\u2500 Classes and priorities \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Repair class of one FEC block.\n *\n * - `keyframe`: the block holds (or held) a RAP / MPU start.\n * - `delta`: the block provably holds only non-RAP video frames.\n * - `unknown`: neither could be proven; treated exactly like `keyframe`.\n * - `audio`: an audio block.\n */\nexport type BlockClass = 'keyframe' | 'delta' | 'unknown' | 'audio'\n\n/** Repair priority. Lower is more urgent. */\nexport type RepairPriority = 0 | 1 | 2\n\nexport type TrackKind = 'video' | 'audio'\n\n/** P0 = keyframe/unknown (stall-preventing), P1 = audio, P2 = delta. */\nexport function repairPriorityForClass(blockClass: BlockClass): RepairPriority {\n switch (blockClass) {\n case 'keyframe':\n case 'unknown':\n return 0\n case 'audio':\n return 1\n case 'delta':\n return 2\n }\n}\n\n// \u2500\u2500\u2500 Geometry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport type ClassifierMode = 'classifying' | 'all-protected'\n\n/** Why a track runs `all-protected`. */\nexport type ClassifierReason =\n // Geometry (catalog) reasons.\n | 'framerate-absent'\n | 'keyframe-cadence-absent'\n | 'keyframe-interval-not-integral'\n | 'block-spans-gop'\n /**\n * The catalog keyframe interval is not an exact integer number of ticks\n * in the media track's own timescale (ISO-BMFF `mdhd`), so released RAP\n * spacing cannot be verified and hold-last cannot predict the next RAP.\n * Nothing is wrong with the stream; the cadence is simply unprovable.\n */\n | 'keyframe-interval-not-media-integral'\n /**\n * Another stream on this packetId was configured with its own geometry\n * and this one was not, so no geometry provably belongs to it (ABR rungs\n * sharing a packetId).\n */\n | 'stream-geometry-absent'\n // In-band invariant violations (positive evidence only).\n | 'rap-not-mpu-start'\n | 'mpu-longer-than-gop'\n | 'block-not-contiguous'\n /**\n * MPU-start RAPs are not exactly one keyframe interval apart per MPU:\n * released RAPs in the media timescale, or, once each frame is its own\n * movie fragment, RAP fragments G fragments apart per MPU (P3).\n */\n | 'rap-spacing-mismatch'\n /**\n * An MPU of several movie fragments whose fragments hold several samples:\n * neither sample_number nor the fragment number states a frame's MPU\n * position (P3).\n */\n | 'mpu-multiple-fragments'\n | 'block-wider-than-interleave'\n\n/** Raw catalog timing for one track. Never a resolved cadence. */\nexport interface BlockClassifierGeometryInput {\n readonly trackKind: TrackKind\n /** Catalog `framerate` (frames per second). */\n readonly framerate?: number\n /** Catalog `fec.interleaveDepthMs`: the full FEC block span (\u00A75.1). */\n readonly interleaveDepthMs: number\n /** Catalog track `timescale` for `keyframeIntervalTicks`. */\n readonly timescale?: number\n /** Catalog `keyframeIntervalTicks` (preferred when the timescale is present). */\n readonly keyframeIntervalTicks?: number\n /** Catalog `keyframeIntervalMs`. */\n readonly keyframeIntervalMs?: number\n /**\n * The track's catalog group duration in ms (`catalogGroupDurationMs`: the\n * tick form over the timescale where the catalog states it, so it may be a\n * fraction). Never a cadence. It is only compared with the keyframe\n * interval: the MPU rule classes nothing unless the two are equal.\n */\n readonly groupDurationMs?: number\n}\n\n/** Exact keyframe interval as a rational number of seconds: ticks / timescale. */\nexport interface KeyframeInterval {\n readonly ticks: number\n readonly timescale: number\n}\n\nexport type BlockClassifierGeometry =\n | { readonly trackKind: 'audio' }\n | {\n readonly trackKind: 'video'\n readonly mode: 'classifying'\n /** F: one frame's duration in milliseconds (1000 / framerate). */\n readonly frameDurationMs: number\n /** D: media units per FEC block (deriveFecInterleaveDepth). */\n readonly interleaveUnits: number\n /** G: frames per GOP. */\n readonly gopFrames: number\n readonly keyframeInterval: KeyframeInterval\n /** The catalog group duration in ms, when stated (the MPU rule's catalog test). */\n readonly groupDurationMs?: number\n }\n | {\n readonly trackKind: 'video'\n readonly mode: 'all-protected'\n readonly reason: ClassifierReason\n /** The catalog interval when one is stated: gap decisions use it (keyframeInstantBetween). */\n readonly keyframeInterval?: KeyframeInterval\n /** The catalog group duration in ms, when stated (the MPU rule's catalog test). */\n readonly groupDurationMs?: number\n }\n\n/**\n * Integer value of `numerator / denominator` when it is one, else null.\n *\n * Catalog framerates are JSON numbers, so an NTSC rate arrives as the double\n * nearest 30000/1001. One multiply and one divide each add at most half an\n * ulp of relative error (IEEE-754), so a quotient within two ulps of an\n * integer IS that integer; anything further is genuinely non-integral.\n */\nfunction exactInteger(numerator: number, denominator: number): number | null {\n if (!Number.isFinite(numerator) || !Number.isFinite(denominator) || denominator === 0) {\n return null\n }\n const quotient = numerator / denominator\n const rounded = Math.round(quotient)\n if (rounded < 1) return null\n const representationError = 2 * Number.EPSILON * Math.abs(quotient)\n return Math.abs(quotient - rounded) <= representationError ? rounded : null\n}\n\nfunction isPositiveFinite(value: number | undefined): value is number {\n return value !== undefined && Number.isFinite(value) && value > 0\n}\n\n/**\n * Derive the per-track classifier geometry from raw catalog fields.\n *\n * `all-protected` is the policy's defined fail-closed state, not a default:\n * it is returned with the exact reason. It turns the window rule off; the\n * MPU rule can still class a block `delta` where the catalog states a\n * keyframe interval equal to the group duration (`mpuRuleCatalogReason`).\n * A `classifying` geometry whose catalog does not state that gets no `delta`\n * either: the window rule classes only on a track the MPU rule applies to.\n * The only throw is for a value the catalog validator already rejects (a\n * non-positive block span).\n */\nexport function deriveBlockClassifierGeometry(\n input: BlockClassifierGeometryInput,\n): BlockClassifierGeometry {\n if (!isPositiveFinite(input.interleaveDepthMs)) {\n throw new Error(\n `[BlockPolicy] interleaveDepthMs=${input.interleaveDepthMs} is not a positive block span; ` +\n 'the catalog validator rejects this',\n )\n }\n if (input.trackKind === 'audio') return { trackKind: 'audio' }\n\n // Every video geometry keeps the catalog interval: gap decisions need it in\n // either mode (fec-multicast-00 Block Classification item 3).\n let keyframeInterval: KeyframeInterval | undefined\n if (isPositiveFinite(input.keyframeIntervalTicks) && isPositiveFinite(input.timescale)) {\n keyframeInterval = { ticks: input.keyframeIntervalTicks, timescale: input.timescale }\n } else if (isPositiveFinite(input.keyframeIntervalMs)) {\n keyframeInterval = { ticks: input.keyframeIntervalMs, timescale: 1000 }\n }\n const groupDuration = isPositiveFinite(input.groupDurationMs) ? { groupDurationMs: input.groupDurationMs } : {}\n const protect = (reason: ClassifierReason): BlockClassifierGeometry => ({\n trackKind: 'video',\n mode: 'all-protected',\n reason,\n ...(keyframeInterval === undefined ? {} : { keyframeInterval }),\n ...groupDuration,\n })\n\n if (!isPositiveFinite(input.framerate)) return protect('framerate-absent')\n const framerate = input.framerate\n if (keyframeInterval === undefined) return protect('keyframe-cadence-absent')\n\n const gopFrames = exactInteger(keyframeInterval.ticks * framerate, keyframeInterval.timescale)\n if (gopFrames === null) return protect('keyframe-interval-not-integral')\n\n const frameDurationMs = 1000 / framerate\n const interleaveUnits = deriveFecInterleaveDepth(input.interleaveDepthMs, frameDurationMs)\n if (interleaveUnits >= gopFrames) return protect('block-spans-gop')\n\n return {\n trackKind: 'video',\n mode: 'classifying',\n frameDurationMs,\n interleaveUnits,\n gopFrames,\n keyframeInterval,\n ...groupDuration,\n }\n}\n\n/**\n * Why the MPU rule classes no block on a track (`BlockClassifier.mpuRuleOff`).\n * Under every reason but the last the window rule classes none either: the\n * track gets no `delta` (fec-multicast-01 Block Classification).\n *\n * The first three are the catalog's: it does not state that the publisher\n * keeps one RAP to an MPU. It carries no usable keyframe interval (none, or\n * one that is not a whole number of its unit), no group duration, or two that\n * differ. The rest are what the stream showed. Each lasts for the epoch but\n * the last, which ends at the next source discontinuity.\n */\nexport type MpuRuleOffReason =\n | 'keyframe-interval-absent'\n | 'group-duration-absent'\n | 'keyframe-interval-not-group-duration'\n /** A DU header carried RAP_flag and was not the first sample of its movie fragment, or was held and lay in another fragment than the first header held of its MPU. */\n | 'rap-inside-mpu'\n /** An MPU held a sample one keyframe interval or more after another, by decode time. */\n | 'mpu-longer-than-keyframe-interval'\n /** `mpuBoundsRaps` went false (see `BlockClassifier.mpuBoundsRaps`). */\n | 'mpu-bounds-raps-refuted'\n /** Two DU headers lay in blocks against their authored order. */\n | 'du-headers-out-of-order'\n\nfunction isPositiveSafeInteger(value: number): boolean {\n return Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * The catalog's side of the MPU rule (fec-multicast-01 Block Classification):\n * a keyframe interval equal to the group duration is the publisher's\n * statement that every MPU of the track holds one RAP, its first sample. A\n * packet does not say so, and a publisher of an earlier revision could put\n * more RAPs in an MPU. Null when the catalog states it, else what is missing.\n *\n * Integers compare exactly, as rationals: ticks / timescale against ms / 1000.\n * A group duration that the catalog states in ticks reaches here as the\n * double nearest ticks / timescale * 1000. Each side then carries at most two\n * roundings, so the two are equal when they differ by no more than\n * 2 * Number.EPSILON of the group duration (as exactInteger reads a quotient).\n */\nfunction mpuRuleCatalogReason(\n geometry: Extract<BlockClassifierGeometry, { trackKind: 'video' }>,\n): MpuRuleOffReason | null {\n const interval = geometry.keyframeInterval\n if (\n interval === undefined ||\n !isPositiveSafeInteger(interval.ticks) ||\n !isPositiveSafeInteger(interval.timescale)\n ) {\n return 'keyframe-interval-absent'\n }\n const groupMs = geometry.groupDurationMs\n if (!isPositiveFinite(groupMs)) return 'group-duration-absent'\n const { ticks, timescale } = interval\n const equal = Number.isSafeInteger(groupMs)\n ? BigInt(ticks) * 1000n === BigInt(groupMs) * BigInt(timescale)\n : Math.abs((ticks / timescale) * 1000 - groupMs) <= 2 * Number.EPSILON * groupMs\n return equal ? null : 'keyframe-interval-not-group-duration'\n}\n\n/**\n * The keyframe interval expressed in a media track's timescale, or null when\n * the geometry states none or the interval is not an exact integer number of\n * media ticks (fec-multicast-00 Block Classification item 3: an inexact one\n * gives no usable interval).\n */\nexport function keyframeIntervalMediaTicks(\n geometry: BlockClassifierGeometry,\n mediaTimescale: number,\n): bigint | null {\n if (geometry.trackKind !== 'video' || geometry.keyframeInterval === undefined) return null\n if (!Number.isSafeInteger(mediaTimescale) || mediaTimescale <= 0) return null\n const { ticks, timescale } = geometry.keyframeInterval\n if (!Number.isSafeInteger(ticks) || !Number.isSafeInteger(timescale)) return null\n const scaled = BigInt(ticks) * BigInt(mediaTimescale)\n const divisor = BigInt(timescale)\n if (scaled % divisor !== 0n) return null\n return scaled / divisor\n}\n\n/**\n * fec-multicast-00 Block Classification item 3 for two released frames:\n * whether `(from, to]` holds `start + k * interval` for some k >= 1, `start`\n * the decode time of an MPU's first RAP, all in one media timescale. `from`\n * is exclusive: the frame at `from` is held and complete, so an instant there\n * is that frame itself (an on-cadence RAP), not a lost one. The draft's closed\n * interval is for bounding packets, which may be part of a RAP.\n */\nexport function keyframeInstantBetween(start: bigint, interval: bigint, from: bigint, to: bigint): boolean {\n const k = from >= start ? (from - start) / interval + 1n : 1n\n return start + k * interval <= to\n}\n\n// \u2500\u2500\u2500 Evidence \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * In-band evidence from ONE first-arrival source symbol received from the\n * network. Repair symbols never contribute, and the MFU `priority > 0x80`\n * hint is not evidence. A recovered symbol is no evidence for its own block\n * and supports no class by the window rule; its DU header alone bounds the\n * blocks around it for the MPU rule (BlockClassifier.observeRecovered).\n */\nexport interface SourceSymbolEvidence {\n /** The MMTP header R (RAP) bit. */\n readonly rap: boolean\n /** MPU_sequence_number, when parsed from this packet. */\n readonly mpu?: number\n /**\n * 0-based sample position within its movie fragment: the MFU DU-header\n * `sample_number` minus one (ISO/IEC 23008-1 numbers samples from 1, and\n * the parser rejects `sample_number` 0). Present only when this packet\n * carried a DU header. It is the MPU position only while the MPU is one\n * movie fragment; BlockClassifier derives MPU positions (P3).\n */\n readonly idx?: number\n /**\n * movie_fragment_sequence_number from the DU header, when present. When\n * each frame is its own fragment, it positions the frame from its MPU's\n * RAP fragment (P3).\n */\n readonly movieFragment?: number\n /**\n * DU-header `offset`: the data unit's authored byte position within its\n * sample (0 for a whole-sample data unit, the partition boundary for a\n * subsample data unit). Present only with `idx`; absent reads as 0.\n */\n readonly offset?: number\n /**\n * The MMTP header packet_sequence_number (contiguous per packet_id). Not\n * classification evidence: FECManager uses it to bound how many blocks the\n * producer can have started between two source symbols, so an outage is\n * never mistaken for a source restart. A hop may write it anew on every\n * packet it forwards (cast's bridge does), so a gap in it, or none, says\n * nothing of what was lost before that hop.\n */\n readonly packetSequenceNumber?: number\n /**\n * DU-header `dep_counter` (ISO/IEC 23008-1 `dependency_counter`). Carried\n * for whoever wants to see it. Nothing here reads it: no class and no gap\n * decision changes with its value.\n */\n readonly depCounter?: number\n}\n\n/**\n * What moved a block's class. `mpu-rule`: the MPU numbers of the DU headers\n * held before and after the block show that it holds no part of a RAP.\n */\nexport type ReclassificationEvidence =\n | 'rap'\n | 'mpu-span'\n | 'window'\n | 'mpu-rule'\n /**\n * @deprecated Never emitted. It named the dependent run in `dep_counter`,\n * which no longer classes a block. The name stays so that a consumer that\n * spells it still compiles and an event recorded earlier still validates.\n */\n | 'dependent-run'\n | 'classifier-disabled'\n\nexport type ClassifierChange =\n | {\n readonly kind: 'reclassified'\n readonly sbn: number\n readonly from: BlockClass\n readonly to: BlockClass\n readonly evidence: ReclassificationEvidence\n }\n | {\n readonly kind: 'mode'\n readonly mode: 'all-protected'\n readonly reason: ClassifierReason\n }\n\ninterface BlockEvidence {\n rapSeen: boolean\n mpus: Set<number>\n /** The lowest and highest MPU positions its DU headers proved (P3). */\n positionMin?: number\n positionMax?: number\n cls: BlockClass\n}\n\n/** A data-unit start (a packet carrying a DU header) and the block it is in. */\ninterface DataUnitStart {\n readonly movieFragment: number\n readonly idx: number\n readonly offset: number\n readonly sbn: number\n}\n\n/** A held DU header as the MPU rule reads it. */\ninterface HeldHeader extends DataUnitStart {\n readonly rap: boolean\n /**\n * Its FEC source symbol id when it arrived from the network. A header that\n * FEC rebuilt has none here: it is not counted as a packet that arrived.\n */\n readonly ssId?: number\n /** Its MPU position, where the wire proved one when it arrived (P3). */\n readonly position?: number\n}\n\n/**\n * Authored order of two data-unit starts of one MPU. Fragment numbers wrap\n * at 2^32, so they compare in RFC 1982 serial order.\n */\nfunction compareDataUnitStarts(\n a: Omit<DataUnitStart, 'sbn'>,\n b: Omit<DataUnitStart, 'sbn'>,\n): number {\n return ((a.movieFragment - b.movieFragment) | 0) || a.idx - b.idx || a.offset - b.offset\n}\n\n/** The first index of an SBN-ordered list whose block is `sbn` or later. */\nfunction firstStartAtOrAfter(starts: readonly HeldHeader[], sbn: number): number {\n let lo = 0\n let hi = starts.length\n while (lo < hi) {\n const mid = (lo + hi) >>> 1\n if (starts[mid]!.sbn < sbn) lo = mid + 1\n else hi = mid\n }\n return lo\n}\n\n/**\n * What arrived of one MPU. The MPU rule asks only about an MPU's start and\n * about its last packet, so that is all that is kept however long the MPU.\n */\ninterface ArrivedPackets {\n /** Source symbol id to block, for the first ARRIVED_START_MAX packets that arrived. */\n readonly start: Map<number, number>\n /** The highest source symbol id among those that arrived. */\n last: number\n}\n\n/** More packets than an MPU's metadata and first sample take; a longer start proves nothing. */\nconst ARRIVED_START_MAX = 4096\n\n/** The first DU header after `headers[at]`, in authored order, of another sample. */\nfunction nextSampleHeader(headers: readonly HeldHeader[], at: number): HeldHeader | undefined {\n const of = headers[at]!\n for (let i = at + 1; i < headers.length; i++) {\n const header = headers[i]!\n if (header.movieFragment !== of.movieFragment || header.idx !== of.idx) return header\n }\n return undefined\n}\n\n/**\n * How many MPUs behind the newest released RAP a stale release can be. The\n * release gate holds a frame for seconds at most, so a late copy is a few\n * MPUs back; anything further is another MPU sequence. With MPUs so short\n * that a late copy lies further back, it re-anchors there: the newest MPU's\n * gaps read rap-unknown until the next MPU's RAP, never a wrong measure.\n */\nconst LATE_RAP_MAX_MPUS_BACK = 64\n\n/** One MPU's movie fragments (P3). */\ninterface MpuLayout {\n /** Serial-earliest movie_fragment_sequence_number of its DU headers. */\n low: number\n /** The fragment of its first RAP-flagged DU header: position 0. */\n anchor?: number\n}\n\n/** What one DU header proves about its MPU (BlockClassifier `#place`). */\ninterface Placement {\n /** Its 0-based MPU position, when the wire proves it. */\n readonly position?: number\n /**\n * It shows a RAP inside an MPU, or an MPU longer than G: MPU boundaries\n * no longer bound the stream's RAPs (`rap-not-mpu-start`).\n */\n readonly rapNotMpuStart: boolean\n /** A refuted layout premise. */\n readonly violation?: ClassifierReason\n}\n\nconst UNPLACED: Placement = { rapNotMpuStart: false }\n\n/**\n * Per-stream block classifier.\n *\n * Classes only move toward more protection or narrower evidence:\n * `unknown\u2192delta` and `unknown\u2192keyframe` / `delta\u2192keyframe` on evidence, and\n * `delta\u2192unknown` when an invariant disables classification. `keyframe` is\n * terminal.\n *\n * The delta window rule classes a block only on a track the MPU rule applies\n * to: one whose catalog passes that rule's test and that has shown neither a\n * RAP inside an MPU nor an MPU longer than the keyframe interval\n * (`mpuRuleOff`). It rests on three premises, each guarded by an invariant\n * that fires on positive evidence only:\n *\n * - P1: the source packets of one block are one contiguous run of the\n * stream's authored order, and blocks follow each other in SBN order\n * (`block-not-contiguous`). The producer assigns SS_IDs in authored order\n * and a block is the SS_ID range [SBN*K, SBN*K + K), so this holds for a\n * block that closes at K symbols in the middle of a frame: that frame's\n * fragments then land in two ADJACENT blocks, which is still one run each.\n * A frame split across adjacent blocks is not a violation.\n * - P2: that run touches at most D media units, counting a frame continued\n * from the previous block (`block-wider-than-interleave`). The producer\n * counts a media-unit boundary only once the open block holds a symbol.\n * - P3: an MPU starts with its only RAP and holds at most G frames\n * (`rap-not-mpu-start`, `mpu-longer-than-gop`, `rap-spacing-mismatch`),\n * and its DU headers state each frame's MPU position in one of two layouts\n * (`mpu-multiple-fragments` when an MPU shows two fragments and a DU\n * header states sample_number above 1, which is neither):\n * - one movie fragment per MPU (ATSC 3.0): the position is\n * sample_number \u2212 1. This is the rule until some MPU of the sequence\n * shows two fragments.\n * - one fragment per frame, numbered one per frame (FFmpeg's MoQ MMT\n * muxer, every DU header stating sample_number 1): the position is the\n * fragment's distance from the fragment of the MPU's first RAP-flagged\n * DU header (its anchor). The RAP's own fragment is position 0. Each\n * anchor must lie exactly G fragments per MPU from the anchor received\n * before it, which is kept past the horizon, and from the anchor\n * received last (`rap-spacing-mismatch`, as after a dropped frame).\n * Once two anchors kept that spacing, fragment numbers count frames:\n * later fragments get positions, and an anchor arriving past the\n * spacing is a RAP inside its MPU or follows an MPU longer than G\n * (`rap-not-mpu-start`). An MPU whose anchor was not received has no\n * positions; its blocks stay unknown. A second RAP-flagged fragment, or\n * a DU header in a fragment before the anchor, refutes the MPU start\n * (`rap-not-mpu-start`).\n *\n * P1 and P2 are what make a block's frames contiguous and lie within\n * [positionMax \u2212 D + 1, positionMin + D \u2212 1] of its MPU. What refutes P1 is\n * a pair of source packets whose wire-stated authored order and SBN order\n * disagree: a later MPU in an earlier block, a later data unit of one MPU\n * (by movie_fragment_sequence_number, sample_number, then DU offset) in an\n * earlier block, or one data unit in two blocks. That is the signature of a\n * round-robin interleave, which scatters one run over several concurrent\n * blocks. Non-adjacency alone is not: a sample larger than K packets\n * legitimately spans blocks SBN..SBN+n.\n */\nexport class BlockClassifier {\n #geometry: BlockClassifierGeometry\n #mode: ClassifierMode\n #reason: ClassifierReason | null\n /**\n * False once the stream showed that an MPU boundary does not bound its\n * RAPs (a RAP inside an MPU, or an MPU longer than a GOP). Recorded in\n * every mode: the stall/conceal decision relies on it even when the\n * catalog geometry already runs the classifier `all-protected`.\n */\n #mpuBoundsRaps = true\n #blocks = new Map<number, BlockEvidence>()\n /**\n * P1 ledger, kept for the MPUs within the classification horizon (the\n * highest MPU seen and the one before it): the SBN span of every source\n * packet of each MPU, and each MPU's data-unit starts in authored order.\n * Valid only within one continuous SBN sequence; a source discontinuity\n * clears it (`noteSourceDiscontinuity`).\n */\n #mpuSbnSpans = new Map<number, { min: number; max: number }>()\n #dataUnitStarts = new Map<number, DataUnitStart[]>()\n #highestMpu: number | null = null\n /**\n * The DU headers held, per MPU in authored order, for the MPU rule. Kept in\n * every mode (the rule needs no catalog cadence) for the same horizon and\n * the same continuous SBN sequence as the P1 ledger.\n */\n #headers = new Map<number, HeldHeader[]>()\n /**\n * The source packets that arrived, per MPU. The MPU rule asks it whether\n * every packet between two held DU headers arrived, and where. Same\n * horizon as the headers.\n */\n #arrived = new Map<number, ArrivedPackets>()\n #heldHighestMpu: number | null = null\n /** Two DU headers of this sequence lay in blocks against their authored order: the MPU rule proves nothing. */\n #headerOrderRefuted = false\n /**\n * A DU header held carried RAP_flag and was not of its MPU's first sample:\n * not the first sample of its movie fragment, or in another movie fragment\n * than the first DU header held of its MPU. This stream puts a RAP inside\n * an MPU, and neither rule proves anything for the rest of the epoch. It is\n * the MPU rule's own reading, in every DU-header layout and of rebuilt\n * headers too. The first case is read on a header of an MPU behind the two\n * kept as well. `mpuBoundsRaps`, which the stall or conceal decision reads,\n * is set as before and not from here.\n */\n #rapInsideMpu = false\n /** What the catalog lacks for the MPU rule, or null when it states a keyframe interval equal to the group duration. */\n #mpuRuleCatalog: MpuRuleOffReason | null = null\n /**\n * The lowest and highest decode time known in an MPU, for the two MPUs of\n * the highest numbers: those of the samples that held movie fragment\n * metadata times (noteDecodeTimes). Valid within one MPU sequence, as the\n * P1 ledger is; if MPU numbers go back with no source discontinuity, the\n * new ones are not read until then, as their DU headers are not.\n */\n #decodeSpans = new Map<number, { readonly min: bigint; readonly max: bigint; readonly mediaTimescale: number }>()\n /**\n * An MPU held a sample one keyframe interval or more after another by\n * decode time, so it lasts longer than the interval. A track of an earlier\n * revision whose interval equals its group duration can hold a further RAP\n * only in such an MPU: neither rule proves anything for the rest of the\n * epoch.\n */\n #mpuOutlastsInterval = false\n /**\n * P3 layout, kept for the MPUs within the classification horizon and valid\n * within one continuous SBN sequence (`noteSourceDiscontinuity`).\n */\n #mpus = new Map<number, MpuLayout>()\n /** An MPU of this sequence showed two movie fragments: each frame is one. */\n #fragmentPerFrame = false\n /** A DU header of this sequence stated sample_number above 1. */\n #multiSampleFragment = false\n /**\n * The anchor received last, whether or not its MPU is still in the\n * horizon. Each new anchor, and the anchor of every DU header's MPU, is\n * checked against it.\n */\n #lastAnchor: { mpu: number; fragment: number } | null = null\n /** Two anchors were exactly G fragments per MPU apart. */\n #fragmentsProven = false\n /** The first RAP released of the latest MPU a RAP was released in, recorded in every mode. */\n #lastRap: { mpu: number; presentationTime: bigint; mediaTimescale: number; decodeTime?: bigint } | null = null\n\n constructor(geometry: BlockClassifierGeometry) {\n this.#geometry = geometry\n this.#mode = 'classifying'\n this.#reason = null\n this.reset(geometry)\n }\n\n get geometry(): BlockClassifierGeometry {\n return this.#geometry\n }\n\n get mode(): ClassifierMode {\n return this.#mode\n }\n\n get reason(): ClassifierReason | null {\n return this.#reason\n }\n\n /**\n * Whether \"same MPU on both sides of a gap\" still proves the gap held no\n * RAP. It stops holding for the rest of the epoch once a RAP was received\n * inside an MPU or an MPU ran longer than a GOP.\n */\n get mpuBoundsRaps(): boolean {\n return this.#mpuBoundsRaps\n }\n\n /**\n * Why the MPU rule classes no block on this track now, or null while it\n * can. A catalog reason is known from the start of the epoch; the others\n * name what the stream showed. A block the rule would have classed reads\n * `unknown` under every one of them, and so does one the window rule would\n * have classed, under every one but `du-headers-out-of-order`.\n */\n get mpuRuleOff(): MpuRuleOffReason | null {\n if (this.#mpuRuleCatalog !== null) return this.#mpuRuleCatalog\n if (this.#rapInsideMpu) return 'rap-inside-mpu'\n if (this.#mpuOutlastsInterval) return 'mpu-longer-than-keyframe-interval'\n if (!this.#mpuBoundsRaps) return 'mpu-bounds-raps-refuted'\n return this.#headerOrderRefuted ? 'du-headers-out-of-order' : null\n }\n\n /** Begin a fresh epoch (catalog change or track reset). */\n reset(geometry: BlockClassifierGeometry = this.#geometry): void {\n this.#geometry = geometry\n this.#blocks.clear()\n this.#clearContiguityLedger()\n this.#clearMpuLayout()\n this.#lastRap = null\n this.#mpuBoundsRaps = true\n this.#rapInsideMpu = false\n this.#mpuOutlastsInterval = false\n this.#mpuRuleCatalog = geometry.trackKind === 'video' ? mpuRuleCatalogReason(geometry) : null\n if (geometry.trackKind === 'video' && geometry.mode === 'all-protected') {\n this.#mode = 'all-protected'\n this.#reason = geometry.reason\n } else {\n this.#mode = 'classifying'\n this.#reason = null\n }\n }\n\n /**\n * Retire this classifier (its stream moves to a new catalog epoch). Every\n * block it had classified `delta` loses the evidence behind that class and\n * reads `unknown` from now on; the returned changes say so.\n */\n retire(): ClassifierChange[] {\n const changes: ClassifierChange[] = []\n for (const [sbn, block] of this.#blocks) {\n if (block.cls !== 'delta') continue\n block.cls = 'unknown'\n changes.push({\n kind: 'reclassified',\n sbn,\n from: 'delta',\n to: 'unknown',\n evidence: 'classifier-disabled',\n })\n }\n return changes\n }\n\n /**\n * The stream's SBN sequence restarted (FECManager source discontinuity:\n * a publisher restart, or the SS_ID space wrapped). Authored order and SBN\n * order are comparable only within one continuous sequence, and a\n * restarted publisher numbers MPUs and movie fragments again, so the P1\n * ledger and the P3 layout start again.\n */\n noteSourceDiscontinuity(): void {\n this.#clearContiguityLedger()\n this.#clearMpuLayout()\n // A restarted publisher numbers MPUs again: its first RAP is no second\n // RAP of the MPU the old sequence last released one in.\n this.#lastRap = null\n }\n\n /**\n * Register a block that exists without evidence of its own: a vanished\n * block, or one only repair symbols state. The DU headers already held\n * around it class it now (the MPU rule); no later header need come between\n * them to ask again.\n */\n touch(sbn: number): ClassifierChange[] {\n const changes: ClassifierChange[] = []\n this.#reclassify(sbn, this.#blockFor(sbn), changes)\n return changes\n }\n\n /** Forget a resolved block. */\n forget(sbn: number): void {\n this.#blocks.delete(sbn)\n }\n\n classOf(sbn: number): BlockClass {\n if (this.#geometry.trackKind === 'audio') return 'audio'\n return this.#blocks.get(sbn)?.cls ?? 'unknown'\n }\n\n /**\n * Record one first-arrival source symbol's evidence for block `sbn`.\n * `ssId` is its FEC source symbol id (the block's SS_Start plus its ESI,\n * ISO/IEC 23008-1 C.5.2). The publisher numbers the packets of the FEC\n * flow with it, one each, so the MPU rule reads from it whether every\n * packet between two DU headers arrived. Without it the rule's two\n * exceptions prove nothing.\n */\n observe(sbn: number, evidence: SourceSymbolEvidence, ssId?: number): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const changes: ClassifierChange[] = []\n const block = this.#blockFor(sbn)\n const placement = this.#place(evidence)\n\n if (evidence.rap) block.rapSeen = true\n if (evidence.mpu !== undefined) block.mpus.add(evidence.mpu)\n const { position } = placement\n if (position !== undefined) {\n block.positionMin =\n block.positionMin === undefined ? position : Math.min(block.positionMin, position)\n block.positionMax =\n block.positionMax === undefined ? position : Math.max(block.positionMax, position)\n }\n\n // A RAP inside an MPU refutes \"an MPU boundary bounds RAPs\" whatever the\n // classifier mode, because gap decisions rely on it in every mode.\n if (placement.rapNotMpuStart) this.#refuteMpuBounds(changes)\n\n const violation = this.#checkInvariants(sbn, block, evidence, placement)\n if (violation !== null) changes.push(...this.#disable(violation))\n\n this.#noteArrived(sbn, evidence.mpu, ssId)\n const bounds = this.#noteHeader(sbn, evidence, position, ssId, changes)\n this.#reclassify(sbn, block, changes)\n // A new DU header can bound any block held: it may have had its last\n // symbol already.\n if (bounds) this.#reclassifyOthers(sbn, changes)\n return changes\n }\n\n /**\n * A first-arrival source symbol placed in a repair-less span (IsoBlockLocator:\n * the SS_IDs between two stated blocks whose every repair was lost). A span\n * is no block: it can hold several producer blocks, so nothing block-scoped\n * is read from it (no record, P1, P2 or MPU-rule bound) and its blocks stay\n * unknown. What its DU header says of its MPU (P3) still counts (BLO-57323).\n */\n observeInSpan(evidence: SourceSymbolEvidence): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const changes: ClassifierChange[] = []\n const placement = this.#place(evidence)\n if (placement.rapNotMpuStart) this.#refuteMpuBounds(changes)\n const geometry = this.#geometry\n if (this.#mode === 'all-protected' || geometry.mode !== 'classifying') return changes\n if (placement.rapNotMpuStart) changes.push(...this.#disable('rap-not-mpu-start'))\n else if (placement.position !== undefined && placement.position >= geometry.gopFrames) {\n changes.push(...this.#disable('mpu-longer-than-gop'))\n } else if (placement.violation !== undefined) changes.push(...this.#disable(placement.violation))\n return changes\n }\n\n /**\n * The DU header of a source packet that a decode rebuilt, in block `sbn`.\n * It bounds the blocks around that block for the MPU rule as a header that\n * arrived does: the rule reads the DU headers the receiver holds. The\n * rebuilt block is whole, so it gets no class and no record, and the\n * packet is no evidence for P1 or P3, which rest on what arrived: it\n * supports no class by the window rule, and can only end it. It is not\n * counted as a packet that arrived either (#arrivedBetween).\n */\n observeRecovered(sbn: number, evidence: SourceSymbolEvidence): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const { mpu, idx, movieFragment } = evidence\n if (mpu === undefined || idx === undefined || movieFragment === undefined) return []\n const changes: ClassifierChange[] = []\n // A second sample in a movie fragment is a fact of the stream whoever\n // shows it. Fragment numbers stop counting samples, and where an MPU has\n // shown two fragments the layout the window rule stands on is gone: say\n // so now, as #place does for a header that arrives.\n if (idx !== 0) {\n this.#multiSampleFragment = true\n const geometry = this.#geometry\n if (this.#fragmentPerFrame && geometry.trackKind === 'video' && geometry.mode === 'classifying') {\n changes.push(...this.#disable('mpu-multiple-fragments'))\n }\n }\n if (this.#noteHeader(sbn, evidence, this.#positionHeld(mpu, idx, movieFragment), undefined, changes)) {\n this.#reclassifyOthers(sbn, changes)\n }\n return changes\n }\n\n /**\n * Decode times the receiver can determine: `first` and `last` are those of\n * the first and the last sample that one held movie fragment's metadata\n * (FT=1) times, of MPU `mpu`, in ticks of `mediaTimescale`; a `trun` lists\n * samples in decode order, so `first` is not after `last`. They are read\n * for one thing, and only on a track the MPU rule applies to: an MPU with\n * two samples a keyframe interval or more apart lasts longer than the\n * interval, so its first sample need not be its only RAP. The rule then\n * stops for the rest of the epoch, the window rule with it, and every delta\n * class goes (fec-multicast-01 Block Classification). No class comes from\n * a decode time. The MPU's first sample is never later than the earliest\n * one known, so the known span is no longer than the real one.\n */\n noteDecodeTimes(mpu: number, first: bigint, last: bigint, mediaTimescale: number): ClassifierChange[] {\n const changes: ClassifierChange[] = []\n const geometry = this.#geometry\n if (geometry.trackKind !== 'video' || this.#mpuRuleCatalog !== null || !isPositiveSafeInteger(mediaTimescale)) {\n return changes\n }\n const held = this.#decodeSpans.get(mpu)\n // Ticks of another timescale are another clock: the MPU's span starts again.\n const known = held?.mediaTimescale === mediaTimescale ? held : undefined\n let late = false\n if (held === undefined && this.#decodeSpans.size >= 2) {\n // Kept by MPU number, as the DU headers are: the two highest. A report for an MPU behind both is late (a\n // slow repair) and must not push out the MPU the stream is in: it is not kept, and only its own span is read.\n const lowest = Math.min(...this.#decodeSpans.keys())\n late = mpu < lowest\n if (!late) this.#decodeSpans.delete(lowest)\n }\n const min = known !== undefined && known.min < first ? known.min : first\n const max = known !== undefined && known.max > last ? known.max : last\n if (!late) this.#decodeSpans.set(mpu, { min, max, mediaTimescale })\n // The catalog test passed, so the interval is stated in whole ticks.\n const { ticks, timescale } = geometry.keyframeInterval!\n if ((max - min) * BigInt(timescale) >= BigInt(ticks) * BigInt(mediaTimescale)) {\n this.#mpuOutlastsInterval = true\n this.#withdraw(changes)\n }\n return changes\n }\n\n /** Ask again for every block held but `own`: a new DU header can bound any of them. */\n #reclassifyOthers(own: number, changes: ClassifierChange[]): void {\n for (const [sbn, block] of this.#blocks) {\n if (sbn !== own) this.#reclassify(sbn, block, changes)\n }\n }\n\n /**\n * Move delta blocks back to unknown: a premise their class stood on is\n * gone. After DU headers out of block order, what the window rule still\n * holds for is classed again as its blocks are seen.\n */\n #withdraw(changes: ClassifierChange[]): void {\n for (const [sbn, block] of this.#blocks) {\n if (block.cls !== 'delta') continue\n block.cls = 'unknown'\n changes.push({ kind: 'reclassified', sbn, from: 'delta', to: 'unknown', evidence: 'classifier-disabled' })\n }\n }\n\n /**\n * An MPU boundary stopped bounding this stream's RAPs: neither rule proves\n * anything from now on, and every delta class goes.\n */\n #refuteMpuBounds(changes: ClassifierChange[]): void {\n if (!this.#mpuBoundsRaps) return\n this.#mpuBoundsRaps = false\n this.#withdraw(changes)\n }\n\n #reclassify(sbn: number, block: BlockEvidence, changes: ClassifierChange[]): void {\n const next = this.#classify(block, sbn)\n if (next === block.cls || !this.#allowed(block.cls, next)) return\n changes.push({\n kind: 'reclassified',\n sbn,\n from: block.cls,\n to: next,\n evidence: this.#evidenceFor(block, next),\n })\n block.cls = next\n }\n\n /**\n * Record a RAP frame released in order. Released MPU-start RAPs of MPUs m\n * and m+n must be exactly n keyframe intervals apart in the media\n * timescale, compared as integers.\n *\n * Comparing only consecutive MPUs would miss exactly the case the window\n * rule cannot survive: a short MPU whose successor's RAP was lost (that\n * RAP-bearing block is the one a wrong G calls delta), because the next\n * released RAP then belongs to m+2. Every MPU is one interval long, so the\n * span to any later released RAP proves or refutes all MPUs in between.\n *\n * In every mode it keeps each MPU's first released RAP, with its decode\n * time, as the start keyframeFreeBetween measures the catalog interval\n * from, and a second RAP released inside one MPU refutes `mpuBoundsRaps`\n * when it lies off the catalog lattice (not a whole number of intervals\n * after the first; draft-ramadan-moq-mmt-02 4.4.3 binds every keyframe to\n * it): with no repair, released RAPs are the only evidence of where they\n * lie. Without a usable interval, or a decode time on either, any second\n * RAP with another presentation time refutes.\n */\n noteReleasedRap(\n mpu: number,\n presentationTime: bigint,\n mediaTimescale: number,\n decodeTime?: bigint,\n ): ClassifierChange[] {\n if (this.#geometry.trackKind === 'audio') return []\n const previous = this.#lastRap\n // A further RAP inside an already-anchored MPU is not an MPU start; the\n // MPU keeps its first RAP as the spacing anchor (rap-not-mpu-start owns\n // mid-MPU RAPs). The same RAP released again is no further one.\n if (previous !== null && previous.mpu === mpu && previous.mediaTimescale === mediaTimescale) {\n if (presentationTime === previous.presentationTime) return []\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n if (\n interval === null ||\n decodeTime === undefined ||\n previous.decodeTime === undefined ||\n (decodeTime - previous.decodeTime) % interval !== 0n\n ) {\n const changes: ClassifierChange[] = []\n this.#refuteMpuBounds(changes)\n return changes\n }\n return []\n }\n // A late copy of an earlier MPU's RAP (the gate reports stale releases\n // too) moves no anchor back: the newest MPU's gaps are measured from its\n // own. MPU sequence numbers wrap at 2^32, so \"earlier\" is serial; it is\n // bounded, and a late copy is older in presentation time than the anchor.\n // Any other RAP behind the anchor is a restarted MPU sequence nothing\n // signalled, which re-anchors, or no same-MPU gap could ever be measured\n // again. A restart inside the bound whose presentation time went back\n // too still reads as late, and fails closed: its same-MPU gaps stay\n // rap-unknown until its MPU numbers pass the old newest, and unless it\n // repeats the old timeline the spacing checks then end the epoch\n // all-protected.\n if (previous !== null && previous.mediaTimescale === mediaTimescale) {\n const back = (previous.mpu - mpu) >>> 0\n if (back !== 0 && back <= LATE_RAP_MAX_MPUS_BACK && presentationTime < previous.presentationTime) return []\n }\n this.#lastRap = { mpu, presentationTime, mediaTimescale, ...(decodeTime === undefined ? {} : { decodeTime }) }\n if (this.#mode === 'all-protected') return []\n // Verification compares integers in the media timescale. When the\n // catalog interval is not an exact tick count there, spacing is\n // unprovable: fail closed, naming the cause, rather than blaming the\n // encoder with rap-spacing-mismatch on a perfectly spaced RAP.\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n if (interval === null) return this.#disable('keyframe-interval-not-media-integral')\n if (\n previous === null ||\n mpu < previous.mpu ||\n previous.mediaTimescale !== mediaTimescale\n ) {\n return []\n }\n if (\n presentationTime - previous.presentationTime === interval * BigInt(mpu - previous.mpu)\n ) {\n return []\n }\n return this.#disable('rap-spacing-mismatch')\n }\n\n /**\n * Whether a gap inside MPU `mpu`, between the decode times `from` and `to`\n * of the frames on either side, holds no keyframe: MPU boundaries still\n * bound RAPs, the catalog states an interval exact in this timescale, and\n * none of its instants after the MPU's first released RAP lies in\n * `(from, to]` (fec-multicast-00 Block Classification item 3). Anything\n * unknown counts as a keyframe.\n */\n keyframeFreeBetween(mpu: number, from: bigint, to: bigint, mediaTimescale: number): boolean {\n const rap = this.#lastRap\n if (!this.#mpuBoundsRaps || rap?.mpu !== mpu || rap.mediaTimescale !== mediaTimescale || rap.decodeTime === undefined) {\n return false\n }\n const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale)\n return interval !== null && !keyframeInstantBetween(rap.decodeTime, interval, from, to)\n }\n\n #blockFor(sbn: number): BlockEvidence {\n let block = this.#blocks.get(sbn)\n if (!block) {\n block = { rapSeen: false, mpus: new Set(), cls: 'unknown' }\n this.#blocks.set(sbn, block)\n }\n return block\n }\n\n #checkInvariants(\n sbn: number,\n block: BlockEvidence,\n evidence: SourceSymbolEvidence,\n placement: Placement,\n ): ClassifierReason | null {\n if (this.#mode === 'all-protected' || this.#geometry.trackKind !== 'video') return null\n const geometry = this.#geometry\n if (geometry.mode !== 'classifying') return null\n if (placement.rapNotMpuStart) return 'rap-not-mpu-start'\n if (placement.position !== undefined && placement.position >= geometry.gopFrames) {\n return 'mpu-longer-than-gop'\n }\n // A block closes at the latest after D media units, so the DU headers it\n // carries from one MPU lie within D consecutive positions. A wider span\n // means the producer closes blocks some other way (at K symbols, or\n // round-robin across concurrent blocks) and the window rule is void.\n if (\n block.mpus.size === 1 &&\n block.positionMin !== undefined &&\n block.positionMax !== undefined &&\n block.positionMax - block.positionMin >= geometry.interleaveUnits\n ) {\n return 'block-wider-than-interleave'\n }\n if (placement.violation !== undefined) return placement.violation\n if (evidence.mpu !== undefined && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {\n return 'block-not-contiguous'\n }\n return null\n }\n\n /**\n * The MPU position a source symbol's DU header proves (P3), and what it\n * refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.\n */\n #place(evidence: SourceSymbolEvidence): Placement {\n const { mpu, idx, movieFragment: fragment } = evidence\n if (idx === undefined) return UNPLACED\n const bySample: Placement = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 }\n // Every wire DU header states both; evidence without them keeps the\n // one-fragment rule unless the sequence is fragment-per-frame.\n if (mpu === undefined || fragment === undefined) {\n return this.#fragmentPerFrame && !this.#multiSampleFragment\n ? { rapNotMpuStart: bySample.rapNotMpuStart }\n : bySample\n }\n let layout = this.#mpus.get(mpu)\n if (layout === undefined) {\n layout = { low: fragment }\n this.#mpus.set(mpu, layout)\n // One entry per MPU still inside the classification horizon.\n for (const other of this.#mpus.keys()) {\n if (other + 1 < mpu) this.#mpus.delete(other)\n }\n } else if (fragment !== layout.low) {\n this.#fragmentPerFrame = true\n if (((fragment - layout.low) | 0) < 0) layout.low = fragment\n }\n if (idx !== 0) this.#multiSampleFragment = true\n let arrival: number | undefined\n if (evidence.rap && layout.anchor === undefined) {\n layout.anchor = fragment\n arrival = this.#anchorDrift(mpu, fragment)\n // Proof takes two MPUs: an MPU's RAP header seen again proves nothing.\n if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true\n this.#lastAnchor = { mpu, fragment }\n }\n // Until an MPU shows two fragments, sample_number \u2212 1 is the position.\n // Once one has, a sample_number above 1 leaves neither layout.\n if (!this.#fragmentPerFrame) return bySample\n if (this.#multiSampleFragment) return { ...bySample, violation: 'mpu-multiple-fragments' }\n const { anchor } = layout\n if (anchor === undefined) return UNPLACED\n // A new anchor against the anchor received before it; any other DU\n // header's anchor against the anchor received last, so an anchor that\n // arrived before the layout was known is held to the spacing too.\n const drift = arrival ?? this.#anchorDrift(mpu, anchor)\n // RFC 1982 distance from the anchor: positive for a later fragment.\n const offset = (fragment - anchor) | 0\n return {\n ...(offset === 0 || (offset > 0 && this.#fragmentsProven) ? { position: offset } : {}),\n rapNotMpuStart:\n (evidence.rap && offset !== 0) ||\n ((layout.low - anchor) | 0) < 0 ||\n // Fragments count frames: an anchor arriving past the spacing is a\n // RAP inside its MPU, or an earlier MPU outran G.\n (arrival !== undefined && arrival > 0 && this.#fragmentsProven),\n ...(drift === undefined || drift === 0 ? {} : { violation: 'rap-spacing-mismatch' }),\n }\n }\n\n /**\n * The MPU position #place gives a DU header, read from the layout the\n * arrived headers built and recording nothing: where a rebuilt header\n * stands for the catalog interval's check in the MPU rule.\n */\n #positionHeld(mpu: number, idx: number, fragment: number): number | undefined {\n if (!this.#fragmentPerFrame || this.#multiSampleFragment) return idx\n const anchor = this.#mpus.get(mpu)?.anchor\n if (anchor === undefined) return undefined\n const offset = (fragment - anchor) | 0\n return offset === 0 || (offset > 0 && this.#fragmentsProven) ? offset : undefined\n }\n\n /**\n * How many fragments MPU m's anchor `fragment` lies past the start that\n * the anchor received last predicts for MPU m: one frame per fragment and\n * G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')\n * fragments apart, modulo 2^32. Undefined without a last anchor, a\n * cadence, or this layout.\n */\n #anchorDrift(mpu: number, fragment: number): number | undefined {\n const geometry = this.#geometry\n const last = this.#lastAnchor\n if (\n last === null ||\n !this.#fragmentPerFrame ||\n this.#multiSampleFragment ||\n geometry.trackKind !== 'video' ||\n geometry.mode !== 'classifying'\n ) {\n return undefined\n }\n return (fragment - last.fragment - geometry.gopFrames * (mpu - last.mpu)) | 0\n }\n\n #clearMpuLayout(): void {\n this.#mpus.clear()\n this.#fragmentPerFrame = false\n this.#multiSampleFragment = false\n this.#lastAnchor = null\n this.#fragmentsProven = false\n }\n\n #clearContiguityLedger(): void {\n this.#mpuSbnSpans.clear()\n this.#dataUnitStarts.clear()\n this.#highestMpu = null\n this.#headers.clear()\n this.#arrived.clear()\n this.#heldHighestMpu = null\n this.#headerOrderRefuted = false\n this.#decodeSpans.clear()\n }\n\n /**\n * P1 check for one source packet of MPU `mpu` in block `sbn`, then record\n * it. True when some recorded packet's authored order and SBN order\n * disagree with this one's (see the class comment). Only positions the\n * wire states are compared: MPU order for every packet, and data-unit\n * order for packets that carry a DU header. A packet of one data unit\n * that continues into the next block carries no DU header and so only\n * takes part through its MPU, which is exactly what makes an adjacent\n * straddle consistent.\n */\n #contradictsAuthoredOrder(sbn: number, mpu: number, evidence: SourceSymbolEvidence): boolean {\n // Every packet of MPU m precedes every packet of MPU m' > m.\n for (const [other, span] of this.#mpuSbnSpans) {\n if (other < mpu && span.max > sbn) return true\n if (other > mpu && span.min < sbn) return true\n }\n const inHorizon = this.#highestMpu === null || mpu + 1 >= this.#highestMpu\n let insertAt = -1\n let starts: DataUnitStart[] | undefined\n let start: DataUnitStart | undefined\n if (evidence.idx !== undefined) {\n start = {\n movieFragment: evidence.movieFragment ?? 0,\n idx: evidence.idx,\n offset: evidence.offset ?? 0,\n sbn,\n }\n starts = this.#dataUnitStarts.get(mpu)\n if (starts !== undefined) {\n let lo = 0\n let hi = starts.length\n while (lo < hi) {\n const mid = (lo + hi) >>> 1\n if (compareDataUnitStarts(starts[mid]!, start) < 0) lo = mid + 1\n else hi = mid\n }\n const at = starts[lo]\n if (at !== undefined && compareDataUnitStarts(at, start) === 0) {\n // One data unit has one first packet: seen in another block, the\n // SBN-to-authored-order map is not a function.\n if (at.sbn !== sbn) return true\n } else {\n const before = starts[lo - 1]\n if (before !== undefined && before.sbn > sbn) return true\n if (at !== undefined && at.sbn < sbn) return true\n insertAt = lo\n }\n }\n }\n if (!inHorizon) return false\n const span = this.#mpuSbnSpans.get(mpu)\n if (span === undefined) this.#mpuSbnSpans.set(mpu, { min: sbn, max: sbn })\n else {\n if (sbn < span.min) span.min = sbn\n if (sbn > span.max) span.max = sbn\n }\n if (start !== undefined) {\n if (starts === undefined) this.#dataUnitStarts.set(mpu, [start])\n else if (insertAt >= 0) starts.splice(insertAt, 0, start)\n }\n if (this.#highestMpu === null || mpu > this.#highestMpu) {\n this.#highestMpu = mpu\n for (const other of [...this.#mpuSbnSpans.keys()]) {\n if (other + 1 < mpu) {\n this.#mpuSbnSpans.delete(other)\n this.#dataUnitStarts.delete(other)\n }\n }\n }\n return false\n }\n\n #disable(reason: ClassifierReason): ClassifierChange[] {\n if (reason === 'rap-not-mpu-start' || reason === 'mpu-longer-than-gop') {\n this.#mpuBoundsRaps = false\n }\n if (this.#mode === 'all-protected') return []\n this.#mode = 'all-protected'\n this.#reason = reason\n const changes: ClassifierChange[] = [{ kind: 'mode', mode: 'all-protected', reason }]\n for (const [sbn, block] of this.#blocks) {\n if (block.cls !== 'delta') continue\n block.cls = 'unknown'\n changes.push({\n kind: 'reclassified',\n sbn,\n from: 'delta',\n to: 'unknown',\n evidence: 'classifier-disabled',\n })\n }\n return changes\n }\n\n #classify(block: BlockEvidence, sbn: number): BlockClass {\n if (block.rapSeen || block.mpus.size >= 2) return 'keyframe'\n // Only a keyframe or a withdrawal moves a delta block: no symbol re-proves it.\n if (block.cls === 'delta') return 'delta'\n if (this.#windowHolds(block) || this.#mpuRuleHolds(block, sbn)) return 'delta'\n return 'unknown'\n }\n\n #windowHolds(block: BlockEvidence): boolean {\n // A track the MPU rule does not apply to gets no delta at all (fec-multicast-01 Block Classification): one whose\n // catalog fails the test, or that showed a RAP inside an MPU or an MPU longer than the keyframe interval. DU\n // headers out of block order stop the MPU rule alone: this rule has its own check of the order (P1).\n const off = this.mpuRuleOff\n if (this.#mode === 'all-protected' || (off !== null && off !== 'du-headers-out-of-order')) return false\n const geometry = this.#geometry\n if (geometry.trackKind !== 'video' || geometry.mode !== 'classifying') return false\n if (\n block.mpus.size !== 1 ||\n block.positionMin === undefined ||\n block.positionMax === undefined\n ) {\n return false\n }\n // A block closes every D media units, so its frames are contiguous and\n // lie in [positionMax \u2212 D + 1, positionMin + D \u2212 1] of MPU m. Position\n // 0 is the only RAP of an MPU and G bounds its length.\n const span = geometry.interleaveUnits - 1\n return block.positionMax - span >= 1 && block.positionMin + span <= geometry.gopFrames - 1\n }\n\n /**\n * Keep the header and arrival ledgers to the two newest MPUs. False for an\n * MPU behind them, which is not kept: no block still asked lies there, and\n * the ledgers stay bounded when MPU numbers go back with no source\n * discontinuity (a restart nothing signalled, or the 2^32 wrap). The rule\n * is then silent until the next one.\n */\n #noteHeldMpu(mpu: number): boolean {\n const highest = this.#heldHighestMpu\n if (highest !== null && mpu <= highest) return mpu + 1 >= highest\n this.#heldHighestMpu = mpu\n for (const held of [this.#headers, this.#arrived]) {\n for (const other of [...held.keys()]) {\n if (other + 1 < mpu) held.delete(other)\n }\n }\n return true\n }\n\n /** Record a source packet that arrived as source symbol `ssId`, for #arrivedBetween. */\n #noteArrived(sbn: number, mpu: number | undefined, ssId: number | undefined): void {\n if (mpu === undefined || ssId === undefined || !this.#noteHeldMpu(mpu)) return\n const arrived = this.#arrived.get(mpu)\n if (arrived === undefined) this.#arrived.set(mpu, { start: new Map([[ssId, sbn]]), last: ssId })\n else {\n if (arrived.start.size < ARRIVED_START_MAX) arrived.start.set(ssId, sbn)\n if (ssId > arrived.last) arrived.last = ssId\n }\n }\n\n /**\n * Record a held DU header for the MPU rule; `ssId` is its source symbol id\n * when it arrived, undefined for one that FEC rebuilt. True when it is new\n * and in order: the blocks held are then asked again. Blocks follow\n * authored order (P1), so the first header that lies against it withdraws\n * every class, and the rule proves nothing for the rest of the sequence.\n */\n #noteHeader(\n sbn: number,\n evidence: SourceSymbolEvidence,\n position: number | undefined,\n ssId: number | undefined,\n changes: ClassifierChange[],\n ): boolean {\n const { mpu, idx, movieFragment } = evidence\n if (this.#geometry.trackKind !== 'video' || mpu === undefined || idx === undefined || movieFragment === undefined) {\n return false\n }\n if (!this.#noteHeldMpu(mpu)) {\n // A header of an MPU behind the two newest is not kept. A RAP that is not the first sample of its movie\n // fragment needs nothing else held to show it, so that much is still read.\n if (evidence.rap && idx !== 0 && !this.#rapInsideMpu) {\n this.#rapInsideMpu = true\n this.#withdraw(changes)\n }\n return false\n }\n const header: HeldHeader = {\n movieFragment,\n idx,\n offset: evidence.offset ?? 0,\n sbn,\n rap: evidence.rap,\n ...(ssId === undefined ? {} : { ssId }),\n ...(position === undefined ? {} : { position }),\n }\n let headers = this.#headers.get(mpu)\n if (headers === undefined) {\n headers = []\n this.#headers.set(mpu, headers)\n }\n let at = 0\n let end = headers.length\n while (at < end) {\n const mid = (at + end) >>> 1\n if (compareDataUnitStarts(headers[mid]!, header) < 0) at = mid + 1\n else end = mid\n }\n if (at < headers.length && compareDataUnitStarts(headers[at]!, header) === 0) return false\n headers.splice(at, 0, header)\n // A RAP is an MPU's first sample. A RAP-flagged header is a RAP inside the MPU when it is not the first sample of\n // its movie fragment (whatever else is held: a header that FEC rebuilt may be the only one of its MPU), or when\n // its movie fragment is not that of the first header held.\n const first = headers[0]!\n if (\n !this.#rapInsideMpu &&\n ((header.rap && header.idx !== 0) ||\n (at === 0 ? headers : [header]).some((held) => held.rap && held.movieFragment !== first.movieFragment))\n ) {\n this.#rapInsideMpu = true\n this.#withdraw(changes)\n }\n const before = headers[at - 1]?.sbn\n const after = headers[at + 1]?.sbn\n if ((before !== undefined && before > sbn) || (after !== undefined && after < sbn)) {\n if (!this.#headerOrderRefuted) {\n this.#headerOrderRefuted = true\n this.#withdraw(changes)\n }\n return false\n }\n return true\n }\n\n /**\n * The MPU rule. L is the DU header held last before the block and U the\n * one held first after it. Every packet carries its MPU number, and an MPU\n * holds one RAP: its first sample.\n *\n * - R1, L and U in one MPU: the block holds no part of a RAP, provided the\n * MPU's first sample ended before the block (#firstSampleEndedBefore).\n * - R2, U in the next MPU: the block may hold the start of that MPU,\n * unless that start arrived whole (#startArrivedWhole). The block is\n * then the tail of L's MPU, and R1's proviso decides.\n * - R3, more than one MPU apart: a whole MPU is gone, its RAP with it.\n * - R4, no U held yet (or no L): not known. The next DU header asks again.\n *\n * It rests on the publisher keeping one RAP to an MPU, which no packet\n * says. So it classes nothing unless the catalog states a keyframe interval\n * equal to the group duration, and nothing once the stream showed\n * otherwise: a RAP inside an MPU (mpuBoundsRaps, or a RAP-flagged DU header\n * held that is not of its MPU's first sample: #noteHeader), an MPU longer than the\n * keyframe interval by the decode times known (noteDecodeTimes), or DU\n * headers against the block order. `mpuRuleOff` names which. `dep_counter`\n * is not read.\n */\n #mpuRuleHolds(block: BlockEvidence, sbn: number): boolean {\n // shortcut: reads the DU headers of the blocks around this one, not the nearest inside it, so it classes fewer blocks than the rule allows; upgrade when observe() is given symbol positions.\n if (this.mpuRuleOff !== null) return false\n let lower: HeldHeader | undefined\n let upper: HeldHeader | undefined\n let lowerMpu = 0\n let upperMpu = 0\n let lowerAt = 0\n let upperAt = 0\n for (const [mpu, headers] of this.#headers) {\n // While the order holds, sbn never decreases along a list: split it at this block.\n const before = firstStartAtOrAfter(headers, sbn) - 1\n const after = firstStartAtOrAfter(headers, sbn + 1)\n const below = headers[before]\n const above = headers[after]\n // The nearest block decides. Where two MPUs meet in one block, the later MPU is the nearer below and the earlier above.\n if (\n below !== undefined &&\n (lower === undefined || below.sbn > lower.sbn || (below.sbn === lower.sbn && mpu > lowerMpu))\n ) {\n lower = below\n lowerMpu = mpu\n lowerAt = before\n }\n if (\n above !== undefined &&\n (upper === undefined || above.sbn < upper.sbn || (above.sbn === upper.sbn && mpu < upperMpu))\n ) {\n upper = above\n upperMpu = mpu\n upperAt = after\n }\n }\n if (lower === undefined || upper === undefined) return false\n if (block.mpus.size === 1 && !block.mpus.has(lowerMpu)) return false\n if (upperMpu === lowerMpu) {\n // A RAP header after L in L's MPU is L's own sample again: the block lies inside the MPU's first sample.\n if (upper.rap) return false\n // The catalog interval wins where it places a keyframe between the two.\n const geometry = this.#geometry\n if (\n geometry.trackKind === 'video' &&\n geometry.mode === 'classifying' &&\n lower.position !== undefined &&\n upper.position !== undefined &&\n Math.floor(upper.position / geometry.gopFrames) > Math.floor(lower.position / geometry.gopFrames)\n ) {\n return false\n }\n } else if (upperMpu !== lowerMpu + 1 || !this.#startArrivedWhole(upperMpu, upperAt)) {\n // R3 is stated here, and kept by the ledgers too: a header two MPUs behind the newest is not held.\n return false\n }\n return this.#firstSampleEndedBefore(sbn, lowerMpu, lowerAt)\n }\n\n /**\n * R1's proviso for block `sbn`, where header `at` of MPU `mpu` is the one\n * held last before it: no part of the MPU's first sample lies in the\n * block. A sample start without RAP_flag is not the first sample. Any\n * other header may be of it (a later data unit of a sample need not repeat\n * the flag). That sample ended before the block only if every packet from\n * the header to the next sample's DU header arrived, in earlier blocks.\n */\n #firstSampleEndedBefore(sbn: number, mpu: number, at: number): boolean {\n const headers = this.#headers.get(mpu)!\n const lower = headers[at]!\n if (lower.offset === 0 && !lower.rap) return true\n // shortcut: a packet between the two headers that lies in the block itself counts as one of the first sample, though it may be the next fragment's metadata, so where every block opens with movie fragment metadata (FFmpeg's muxer) the block after a keyframe stays unknown; upgrade when the evidence says which packets are metadata.\n const next = nextSampleHeader(headers, at)\n return next !== undefined && this.#arrivedBetween(mpu, lower, next, sbn)\n }\n\n /**\n * R2's exception: the start of MPU `mpu` arrived whole. Its header `at`,\n * the DU header held first after the block, is of the MPU's RAP. Every\n * packet before it arrived, back to the last packet of the MPU before: so\n * did the MPU and movie fragment metadata sent before the sample. And\n * every packet after it arrived, up to the next sample's DU header.\n */\n #startArrivedWhole(mpu: number, at: number): boolean {\n const headers = this.#headers.get(mpu)!\n const first = headers[at]!\n const arrived = this.#arrived.get(mpu)\n const previous = this.#arrived.get(mpu - 1)\n if (!first.rap || first.ssId === undefined || arrived === undefined || previous === undefined) return false\n let ssId = first.ssId - 1\n while (arrived.start.has(ssId)) ssId--\n if (ssId !== previous.last) return false\n const next = nextSampleHeader(headers, at)\n return next !== undefined && this.#arrivedBetween(mpu, first, next)\n }\n\n /**\n * Whether every packet sent after DU header `from` and before DU header\n * `to`, both of MPU `mpu`, arrived as a packet of that MPU, each in a block\n * before `before` when one is given. The source symbol id counts every\n * packet of the FEC flow, so no id may be missing between the two. Ids are\n * read as plain numbers, as block starts are: past the 2^32 wrap of the id\n * nothing is proved.\n */\n #arrivedBetween(mpu: number, from: HeldHeader, to: HeldHeader, before?: number): boolean {\n // shortcut: a packet that FEC rebuilt does not count as arrived (only the DU headers of rebuilt packets are handed over), so a start that FEC completed proves nothing here; upgrade when the router hands every rebuilt packet over with its source symbol id.\n const arrived = this.#arrived.get(mpu)\n if (arrived === undefined || from.ssId === undefined || to.ssId === undefined) return false\n for (let ssId = from.ssId + 1; ssId !== to.ssId; ssId++) {\n const sbn = arrived.start.get(ssId)\n if (sbn === undefined || (before !== undefined && sbn >= before)) return false\n }\n return true\n }\n\n #allowed(from: BlockClass, to: BlockClass): boolean {\n if (from === 'keyframe') return false\n if (from === 'unknown') return to === 'delta' || to === 'keyframe'\n if (from === 'delta') return to === 'keyframe'\n return false\n }\n\n #evidenceFor(block: BlockEvidence, to: BlockClass): ReclassificationEvidence {\n if (to === 'delta') return this.#windowHolds(block) ? 'window' : 'mpu-rule'\n return block.rapSeen ? 'rap' : 'mpu-span'\n }\n}\n\n// \u2500\u2500\u2500 Stall vs conceal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface GapStreamIdentity {\n readonly packetId: number\n /** Non-empty catalog identity, or null when the producer has no track name. */\n readonly catalogTrackName: string | null\n}\n\n/** What the sink knows about one side of a released gap. */\nexport interface GapFrameEvidence {\n /**\n * Codec-aware RAP check: `MmtpContainerParser.isKeyframe(data, rapFlag,\n * codec)`, bitstream-only for recovered frames. Never the priority hint.\n */\n readonly rap: boolean\n /**\n * MPU_sequence_number of the frame. Omit it once the stream showed that\n * an MPU boundary does not bound its RAPs (`BlockClassifier.mpuBoundsRaps`):\n * same-MPU then no longer proves a gap lost only deltas.\n */\n readonly mpu?: number\n /**\n * 0-based sample position within its movie fragment (sample_number \u2212 1).\n * State it on both sides only when both frames are in one movie fragment:\n * decideGap reads `after.idx \u2212 before.idx \u2212 1` as the samples missed\n * between them.\n */\n readonly idx?: number\n /** Authored presentation time in `timescale` ticks. */\n readonly pts?: bigint\n /** Authored sample duration in `timescale` ticks. */\n readonly durationTicks?: number\n /** The media timescale of `pts` and `durationTicks`. */\n readonly timescale?: number\n}\n\nexport type FrameGapAction = 'stall' | 'conceal'\n\nexport type FrameGapReason =\n | 'rap-lost'\n | 'rap-unknown'\n | 'discontinuity'\n | 'delta-lost'\n | 'rap-next'\n | 'audio-gap'\n | 'audio-discontinuity'\n\n/**\n * The decision attached to the first frame released after a gap\n * (`RoutedFrameMeta.gapBefore`). It is the same frozen object the manager\n * emits as its `gap` repair lifecycle event, so a sink that acts on the frame\n * and an observer that counts events see one fact.\n */\nexport interface FrameGapDecision {\n readonly version: 2\n readonly type: 'gap'\n readonly stream: GapStreamIdentity\n readonly trackKind: TrackKind\n readonly action: FrameGapAction\n readonly reason: FrameGapReason\n /** FEC blocks in the gap whose media was lost (failed or vanished). */\n readonly blocks: readonly number[]\n /** Missing video frames or audio access units, when exactly known. */\n readonly missingFrames: number | null\n /** Authored duration of the missing media in milliseconds, when known. */\n readonly missingMs: number | null\n /** Manager epoch of the stream when the decision was made. */\n readonly epoch: number\n}\n\nexport interface DecideGapInput {\n readonly stream: GapStreamIdentity\n readonly trackKind: TrackKind\n /** Last frame released before the gap. */\n readonly before: GapFrameEvidence\n /** First frame released after the gap. */\n readonly after: GapFrameEvidence\n /** The stream restarted (FEC SBN went backwards or the publisher reset). */\n readonly discontinuity: boolean\n readonly blocks: readonly number[]\n /**\n * The most media units the gap can hold: the FEC blocks spanned from the\n * frame before to the frame after, times D (media units per block,\n * ceil(interleaveDepthMs / unit duration), \u00A75.1). A block touches at most D\n * units whether it closes at D or at K symbols. Null when the span or D is\n * unknown. An audio PTS delta that implies more AUs than this is a clock\n * jump, not loss, and re-anchors instead of concealing every slot.\n */\n readonly maxMissingUnits: number | null\n readonly epoch: number\n}\n\nfunction durationMs(units: number, before: GapFrameEvidence): number | null {\n if (\n before.durationTicks === undefined ||\n before.timescale === undefined ||\n before.timescale <= 0\n ) {\n return null\n }\n return (units * before.durationTicks * 1000) / before.timescale\n}\n\n/**\n * Pure stall/conceal decision for the first frame released after a gap.\n *\n * Video stalls only when a RAP may be inside the gap: the frame after it is\n * not a RAP and either sits in another MPU (`rap-lost`) or the MPU cannot be\n * proven on both sides (`rap-unknown`), or the stream restarted\n * (`discontinuity`). A gap inside one MPU lost only deltas (`delta-lost`) and\n * a RAP after the gap resynchronises by itself (`rap-next`). Audio never\n * stalls: an exact gap is concealed per access unit (`audio-gap`), anything\n * else re-anchors at the next frame (`audio-discontinuity`).\n */\nexport function decideGap(input: DecideGapInput): FrameGapDecision {\n const { before, after } = input\n let action: FrameGapAction\n let reason: FrameGapReason\n let missingFrames: number | null = null\n\n if (input.trackKind === 'audio') {\n action = 'conceal'\n reason = 'audio-discontinuity'\n if (\n !input.discontinuity &&\n before.pts !== undefined &&\n after.pts !== undefined &&\n before.durationTicks !== undefined &&\n Number.isSafeInteger(before.durationTicks) &&\n before.durationTicks > 0\n ) {\n const auDuration = BigInt(before.durationTicks)\n const missingTicks = after.pts - before.pts - auDuration\n const bound = input.maxMissingUnits\n if (\n missingTicks > 0n &&\n missingTicks % auDuration === 0n &&\n bound !== null &&\n missingTicks / auDuration <= BigInt(bound)\n ) {\n reason = 'audio-gap'\n missingFrames = Number(missingTicks / auDuration)\n }\n }\n } else if (input.discontinuity) {\n action = 'stall'\n reason = 'discontinuity'\n } else if (after.rap) {\n action = 'conceal'\n reason = 'rap-next'\n } else if (before.mpu === undefined || after.mpu === undefined) {\n action = 'stall'\n reason = 'rap-unknown'\n } else if (before.mpu !== after.mpu) {\n action = 'stall'\n reason = 'rap-lost'\n } else {\n action = 'conceal'\n reason = 'delta-lost'\n if (before.idx !== undefined && after.idx !== undefined) {\n const missing = after.idx - before.idx - 1\n missingFrames = missing > 0 ? missing : null\n }\n }\n\n return Object.freeze({\n version: 2 as const,\n type: 'gap' as const,\n stream: Object.freeze({\n packetId: input.stream.packetId,\n catalogTrackName: input.stream.catalogTrackName,\n }),\n trackKind: input.trackKind,\n action,\n reason,\n blocks: Object.freeze([...input.blocks]),\n missingFrames,\n missingMs: missingFrames === null ? null : durationMs(missingFrames, before),\n epoch: input.epoch,\n })\n}\n"],
|
|
5
|
+
"mappings": ";AA0BA,SAAS,gCAAgC;AAoBlC,SAAS,uBAAuB,YAAwC;AAC7E,UAAQ,YAAY;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAyGA,SAAS,aAAa,WAAmB,aAAoC;AAC3E,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,CAAC,OAAO,SAAS,WAAW,KAAK,gBAAgB,GAAG;AACrF,WAAO;AAAA,EACT;AACA,QAAM,WAAW,YAAY;AAC7B,QAAM,UAAU,KAAK,MAAM,QAAQ;AACnC,MAAI,UAAU,EAAG,QAAO;AACxB,QAAM,sBAAsB,IAAI,OAAO,UAAU,KAAK,IAAI,QAAQ;AAClE,SAAO,KAAK,IAAI,WAAW,OAAO,KAAK,sBAAsB,UAAU;AACzE;AAEA,SAAS,iBAAiB,OAA4C;AACpE,SA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