@blockcast/mmt-container 2.2.0-main.a88c3a0aa4f3 → 2.2.0-main.aee8d33d2cc8
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 +34 -19
- package/dist/block-policy.d.ts +55 -13
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +104 -32
- package/dist/block-policy.js.map +2 -2
- package/dist/browser-runtime.js +2094 -385
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.js.map +2 -2
- package/dist/catalog-fec-params.d.ts +18 -2
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +29 -1
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmcd-producer.d.ts +60 -47
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +138 -109
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js +5 -1
- package/dist/delta-fallback-config.js.map +3 -3
- package/dist/fec-manager.d.ts +114 -15
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +639 -95
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-state.js +5 -1
- package/dist/fec-state.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/held-layer-admission.js.map +2 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +48 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +97 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mfu-reassembler.js +12 -19
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts +106 -12
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +324 -46
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +466 -66
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +323 -46
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +41 -3
- package/dist/mmtp-fec-session.d.ts.map +1 -1
- package/dist/mmtp-fec-session.js +118 -13
- package/dist/mmtp-fec-session.js.map +3 -3
- package/dist/mmtp-router.d.ts +36 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +716 -100
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.js.map +2 -2
- package/dist/multicast-input.js.map +2 -2
- package/dist/multicast-manager.d.ts +28 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1451 -215
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +28 -18
- package/dist/multicast-transport.js.map +2 -2
- package/dist/multicast-unwrap.js +12 -19
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +1 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +463 -64
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.d.ts +82 -0
- package/dist/repair-layer-subscriptions.d.ts.map +1 -0
- package/dist/repair-layer-subscriptions.js +192 -0
- package/dist/repair-layer-subscriptions.js.map +7 -0
- package/dist/signaling.js.map +2 -2
- package/dist/timestamp-codec.js +12 -19
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +323 -46
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/schemas/catalog.schema.json +4 -0
- package/src/block-policy.ts +216 -52
- package/src/catalog-fec-params.ts +37 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +619 -37
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +22 -2
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +353 -32
- package/src/mmtp-fec-session.ts +115 -15
- package/src/mmtp-router.ts +618 -44
- package/src/multicast-manager.ts +139 -16
- package/src/no-modules.ts +3 -0
- package/src/repair-fetch.ts +366 -50
- package/src/repair-layer-subscriptions.ts +261 -0
- package/src/track-session.ts +4 -1
package/src/mmtp-router.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type MoqRepairFrame,
|
|
25
25
|
} from "@blockcast/mmt-base";
|
|
26
26
|
import { USER_AGENT_VERIFIED } from "@blockcast/mmt-transport";
|
|
27
|
-
import type { FECManager, IsoHeldSource, WasmFecDecoder } from "./fec-manager.js";
|
|
27
|
+
import type { FECManager, IsoHeldSource, IsoSpanFailure, RebuiltSourceFeed, WasmFecDecoder } from "./fec-manager.js";
|
|
28
28
|
import type { IsoPlacedSource, IsoRepairPlacement } from "./iso-block-locator.js";
|
|
29
29
|
import { isMfuReassemblyError } from "./mfu-reassembler.js";
|
|
30
30
|
import type {
|
|
@@ -48,10 +48,12 @@ import {
|
|
|
48
48
|
} from "./cmaf-block-assembler.js";
|
|
49
49
|
import {
|
|
50
50
|
MmtpContainerParser,
|
|
51
|
+
authoredAdjacent,
|
|
51
52
|
isMfuKeyframeMetadata,
|
|
52
53
|
type FecReleaseGate,
|
|
53
54
|
type FrameMeta as ParserFrameMeta,
|
|
54
55
|
type ParsedMmtpPacket,
|
|
56
|
+
type MmtpRecoveredHeadTimingStats,
|
|
55
57
|
} from "./mmtp-container-parser.js";
|
|
56
58
|
import { type TrackRole } from "./carp-catalog.js";
|
|
57
59
|
import {
|
|
@@ -212,6 +214,92 @@ export interface KeyframeOverlayStats {
|
|
|
212
214
|
restarts: number;
|
|
213
215
|
unsequencedDropped: number;
|
|
214
216
|
protectedDropped: number;
|
|
217
|
+
/** Rebuilt packets fed to their base block's decoder (joint decoding). */
|
|
218
|
+
baseFed: number;
|
|
219
|
+
/** Rebuilt packets the base never took: no base SS_ID could be determined,
|
|
220
|
+
* or only the overlay's own evidence did, which anchors the release gate
|
|
221
|
+
* alone (BLO-52085). */
|
|
222
|
+
baseUndetermined: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The newest received overlay member of one MPU. `psnOffset` (overlay SS_ID
|
|
227
|
+
* minus wire packet_sequence_number) restores a rebuilt packet's wire
|
|
228
|
+
* sequence; the member's own SS_IDs anchor a rebuilt packet's base SS_ID
|
|
229
|
+
* (overlayBaseSsId).
|
|
230
|
+
*/
|
|
231
|
+
interface OverlayMemberAnchor {
|
|
232
|
+
readonly psnOffset: number;
|
|
233
|
+
readonly overlaySsId: number;
|
|
234
|
+
/** The member's base SS_ID, from its Source FEC Payload ID. */
|
|
235
|
+
readonly baseSsId?: number;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The base SS_ID of a packet the overlay rebuilt at `overlaySsId`, which an
|
|
240
|
+
* overlay coordinate alone never yields (draft-ramadan-moq-mmt-02 7.1). Both
|
|
241
|
+
* SS_IDs advance by one per packet along a run of consecutive overlay
|
|
242
|
+
* members, so base minus overlay SS_ID is the anchor's along a run the wire
|
|
243
|
+
* proves to be all members: one over which the rebuilt packet's protected
|
|
244
|
+
* packet_sequence_number (`headerPsn`) advanced from the anchor's exactly as
|
|
245
|
+
* the overlay SS_ID did (`restoredPsn`), so no other packet lies inside it.
|
|
246
|
+
* A hop that re-stamped packet_sequence_number after protection fails the
|
|
247
|
+
* test. Undefined when it fails.
|
|
248
|
+
*/
|
|
249
|
+
function overlayBaseSsId(
|
|
250
|
+
anchor: OverlayMemberAnchor,
|
|
251
|
+
overlaySsId: number,
|
|
252
|
+
restoredPsn: number,
|
|
253
|
+
headerPsn: number,
|
|
254
|
+
): number | undefined {
|
|
255
|
+
if (anchor.baseSsId === undefined || headerPsn !== restoredPsn) return undefined;
|
|
256
|
+
return serial32Add(anchor.baseSsId, (overlaySsId - anchor.overlaySsId) | 0);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The base SS_ID of a rebuilt packet no received member of its MPU anchors,
|
|
261
|
+
* from its protected packet_sequence_number (`headerPsn`). SS_ID advances by
|
|
262
|
+
* one per FEC source packet (mmt-02 7.1) and psn by one per packet, so on a
|
|
263
|
+
* track whose every packet is an FEC source packet the sender keeps
|
|
264
|
+
* SS_ID - psn fixed. `offset` (SS_ID - psn of the stream's latest received
|
|
265
|
+
* source) is that sender value while evidence showed it (`unstampedOffset`):
|
|
266
|
+
* a base recovery's (#unstampedSsIdSeqOffsetByStream), or the overlay's
|
|
267
|
+
* alone (#overlayUnstampedSsIdSeqOffsetByStream). A hop that re-stamps psn
|
|
268
|
+
* moves the offset away from the one shown, which voids it, as does a packet
|
|
269
|
+
* with no SS_ID between the packet that showed it and the latest received
|
|
270
|
+
* source (the shown span). Undefined without both.
|
|
271
|
+
* ponytail: exact only if every packet from the rebuilt one to the latest
|
|
272
|
+
* received source is an FEC source packet, as FFmpeg's muxer sends a track
|
|
273
|
+
* it protects. fec-core 8.3 lets a publisher leave one unprotected
|
|
274
|
+
* (FEC Type 0): outside the shown span it goes unseen, and each one puts the
|
|
275
|
+
* rebuilt packet a base slot off. If such a publisher appears, have mmt-02
|
|
276
|
+
* require FEC Type 1 across a protected track, or refuse a headerPsn outside
|
|
277
|
+
* the shown span.
|
|
278
|
+
*/
|
|
279
|
+
function unstampedBaseSsId(
|
|
280
|
+
offset: number | undefined,
|
|
281
|
+
unstampedOffset: number | undefined,
|
|
282
|
+
headerPsn: number,
|
|
283
|
+
): number | undefined {
|
|
284
|
+
if (offset === undefined || offset !== unstampedOffset) return undefined;
|
|
285
|
+
return (headerPsn + offset) >>> 0;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Base SS_IDs of overlay-routed packets kept per stream (see OverlayToBase). */
|
|
289
|
+
const OVERLAY_ROUTED_LIMIT = 1024;
|
|
290
|
+
/** Rebuilt sources kept per stream for a base block no repair stated yet. */
|
|
291
|
+
const OVERLAY_PENDING_LIMIT = 256;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* One stream's keyframe-overlay recoveries on their way into its base
|
|
295
|
+
* decoder (joint decoding, BLO-52085).
|
|
296
|
+
*/
|
|
297
|
+
interface OverlayToBase {
|
|
298
|
+
/** Base SS_IDs of the packets an overlay recovery routed (as media, or held
|
|
299
|
+
* for their FT=1): a base recovery does not route them a second time. */
|
|
300
|
+
readonly routed: Set<number>;
|
|
301
|
+
/** Rebuilt sources, by base SS_ID, whose base block no repair stated yet. */
|
|
302
|
+
readonly pending: Map<number, Uint8Array>;
|
|
215
303
|
}
|
|
216
304
|
|
|
217
305
|
interface OverlayInstance {
|
|
@@ -223,14 +311,22 @@ interface OverlayInstance {
|
|
|
223
311
|
readonly k: number;
|
|
224
312
|
/** The newest overlay symbol seen: its overlay SS_ID and wire sequence. */
|
|
225
313
|
last?: { ssId: number; psn: number };
|
|
226
|
-
/** MPU sequence number →
|
|
227
|
-
readonly offsets: Map<number,
|
|
314
|
+
/** MPU sequence number → its newest received member. */
|
|
315
|
+
readonly offsets: Map<number, OverlayMemberAnchor>;
|
|
228
316
|
/** Overlay blocks a MoQ symbol fed (multicast-02 7.2.7). */
|
|
229
317
|
readonly moqBlocks: Set<number>;
|
|
318
|
+
/** Overlay SS_ID → protected packet_sequence_number of each packet rebuilt
|
|
319
|
+
* with no base SS_ID, until its base copy lands (#feedOverlaySource). */
|
|
320
|
+
readonly rebuilt: Map<number, number>;
|
|
230
321
|
}
|
|
231
322
|
|
|
232
323
|
/** Offsets kept per overlay, one per MPU: a keyframe's fragments share one. */
|
|
233
324
|
const OVERLAY_OFFSET_MPUS = 16;
|
|
325
|
+
/** Rebuilt packets kept per overlay whose base copy has not landed (OverlayInstance.rebuilt).
|
|
326
|
+
* ponytail: this cap is the only eviction for a base copy that never lands
|
|
327
|
+
* (oldest first; an overlay epoch reset clears all). Bound records by SS_ID
|
|
328
|
+
* age instead if stale ones ever crowd out live ones. */
|
|
329
|
+
const OVERLAY_REBUILT_LIMIT = 256;
|
|
234
330
|
/** A MoQ-fed overlay block is forgotten once it starts this many K_overlay
|
|
235
331
|
* behind the newest overlay SS_ID: the overlay locator, which keeps a fixed
|
|
236
332
|
* few blocks (no catalog timing), has retired it long before, so it can no
|
|
@@ -511,6 +607,9 @@ export type RoutedPacketMeta = {
|
|
|
511
607
|
mmtpTimestamp: bigint;
|
|
512
608
|
/**
|
|
513
609
|
* The MMTP header RAP flag: the packet starts a random access point. On a
|
|
610
|
+
* track under a keyframe overlay it is also set on the FT=0 and FT=1 data
|
|
611
|
+
* units that govern a covered keyframe (draft-ramadan-moq-mmt-02 7.4.2), so
|
|
612
|
+
* it can precede the keyframe's first MFU fragment. On a
|
|
514
613
|
* `recovered` packet it is read from the FEC-reconstructed header, which is
|
|
515
614
|
* byte-exact outside packet_sequence_number, so it is the flag the
|
|
516
615
|
* publisher sent. The router's own gap decisions deliberately ignore it for
|
|
@@ -574,6 +673,7 @@ interface StreamLedgers {
|
|
|
574
673
|
* the pair.
|
|
575
674
|
*/
|
|
576
675
|
readonly duplicates: StreamDuplicateLedgers;
|
|
676
|
+
readonly overlayToBase: OverlayToBase;
|
|
577
677
|
}
|
|
578
678
|
|
|
579
679
|
const NO_FEC_MANAGER_HORIZON: DuplicateHorizon = Object.freeze({
|
|
@@ -661,6 +761,17 @@ export interface FECManagerLike {
|
|
|
661
761
|
catalogTrackName?: string,
|
|
662
762
|
): Uint8Array | null;
|
|
663
763
|
|
|
764
|
+
/** Feed a source another FEC instance over the same packets rebuilt (a
|
|
765
|
+
* keyframe overlay) to its base block, which a repair must already have
|
|
766
|
+
* stated; not a network arrival (FECManager.feedRebuiltSourceSymbol).
|
|
767
|
+
* Optional: without it the overlay and the base decode apart. */
|
|
768
|
+
feedRebuiltSourceSymbol?(
|
|
769
|
+
packetId: number,
|
|
770
|
+
ssId: number,
|
|
771
|
+
symbolData: Uint8Array,
|
|
772
|
+
catalogTrackName?: string,
|
|
773
|
+
): RebuiltSourceFeed;
|
|
774
|
+
|
|
664
775
|
/** How long ago the stream's oldest open block with an FEC deadline took its first symbol (optional). */
|
|
665
776
|
oldestOpenBlockAgeMs?(packetId: number, catalogTrackName: string): number | undefined;
|
|
666
777
|
|
|
@@ -732,13 +843,14 @@ export interface FECManagerLike {
|
|
|
732
843
|
|
|
733
844
|
/** Track a first-arrival network source symbol for block completion and
|
|
734
845
|
* classification. Refreshes the inactivity deadline and marks clean when
|
|
735
|
-
* K arrive. */
|
|
846
|
+
* K arrive. `held`: a source held unplaced since it arrived, placed now. */
|
|
736
847
|
trackBlock(
|
|
737
848
|
sbn: number,
|
|
738
849
|
packetId: number,
|
|
739
850
|
catalogTrackName: string | undefined,
|
|
740
851
|
esi: number,
|
|
741
852
|
evidence: SourceSymbolEvidence,
|
|
853
|
+
held?: boolean,
|
|
742
854
|
): void;
|
|
743
855
|
|
|
744
856
|
/** True once the packetId has a per-track FEC configuration. */
|
|
@@ -854,6 +966,15 @@ export interface FECManagerLike {
|
|
|
854
966
|
fromSsId: number,
|
|
855
967
|
toSsId: number,
|
|
856
968
|
): readonly number[] | null;
|
|
969
|
+
/** iso-ssbg1-v1: how long a frame waits once only a late source can fill the SS_IDs before it, longer when they may hold a RAP an installed keyframe overlay can still rebuild (FECManager.isoRepairlessWaitMs). */
|
|
970
|
+
isoRepairlessWaitMs?(
|
|
971
|
+
packetId: number,
|
|
972
|
+
catalogTrackName: string | undefined,
|
|
973
|
+
fromSsId: number,
|
|
974
|
+
toSsId: number,
|
|
975
|
+
rapMayHide?: boolean,
|
|
976
|
+
rapNext?: boolean,
|
|
977
|
+
): number | undefined;
|
|
857
978
|
|
|
858
979
|
|
|
859
980
|
/**
|
|
@@ -908,6 +1029,7 @@ export interface FECManagerLike {
|
|
|
908
1029
|
packetId: number,
|
|
909
1030
|
catalogTrackName: string | undefined,
|
|
910
1031
|
blockClass: BlockClass,
|
|
1032
|
+
span?: IsoSpanFailure,
|
|
911
1033
|
) => void)
|
|
912
1034
|
| null;
|
|
913
1035
|
|
|
@@ -930,9 +1052,10 @@ export interface FECManagerLike {
|
|
|
930
1052
|
/**
|
|
931
1053
|
* Classification evidence carried by one first-arrival network source
|
|
932
1054
|
* packet: the MMTP header R bit and the MPU / data-unit identity it states
|
|
933
|
-
* (movie fragment, sample, DU offset). `idx` is the 0-based
|
|
934
|
-
* (`sample_number` is 1-based)
|
|
935
|
-
*
|
|
1055
|
+
* (movie fragment, sample, DU offset). `idx` is the sample's 0-based
|
|
1056
|
+
* position within its movie fragment (`sample_number` is 1-based);
|
|
1057
|
+
* BlockClassifier turns it and the fragment into an MPU position. The
|
|
1058
|
+
* packet_sequence_number rides along for FECManager's forward-jump bound.
|
|
936
1059
|
*/
|
|
937
1060
|
function sourceSymbolEvidence(
|
|
938
1061
|
packet: Uint8Array,
|
|
@@ -976,6 +1099,7 @@ export class MmtpRouter {
|
|
|
976
1099
|
readonly #provenance = new Map<string, ProvenanceEntry>();
|
|
977
1100
|
#onFlowProtected: ((flow: string) => void) | null = null;
|
|
978
1101
|
#unadmittedListedDrops = 0;
|
|
1102
|
+
#admittedSourceDatagrams = 0;
|
|
979
1103
|
#unlistedRepairSetAside = 0;
|
|
980
1104
|
readonly #assistBlocks = new Map<string, AssistBlock>();
|
|
981
1105
|
readonly #assistFailures = new Map<string, number>();
|
|
@@ -1044,6 +1168,26 @@ export class MmtpRouter {
|
|
|
1044
1168
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
1045
1169
|
*/
|
|
1046
1170
|
#ssIdSeqOffsetByStream = new Map<string, number>();
|
|
1171
|
+
/**
|
|
1172
|
+
* Per stream, the SS_ID offset at which a base recovery last showed the
|
|
1173
|
+
* sender's own packet_sequence_number: a recovered packet's header psn
|
|
1174
|
+
* equal to its SS_ID minus that offset. While it equals the stream's
|
|
1175
|
+
* current offset, no hop re-stamps the stream, and a packet's protected psn
|
|
1176
|
+
* names its base SS_ID within unstampedBaseSsId's limits (joint decoding of
|
|
1177
|
+
* an MPU no member of which arrived).
|
|
1178
|
+
*/
|
|
1179
|
+
#unstampedSsIdSeqOffsetByStream = new Map<string, number>();
|
|
1180
|
+
/**
|
|
1181
|
+
* The same, shown by the overlay alone, before any base recovery did: a
|
|
1182
|
+
* packet it rebuilt whose base copy carries its protected psn
|
|
1183
|
+
* (#feedOverlaySource), or whose protected psn passes overlayBaseSsId's
|
|
1184
|
+
* test at that offset (#routeOverlayRecovered). A base SS_ID placed by it
|
|
1185
|
+
* anchors the release gate only (BLO-52085 D3): fed to the base, it would
|
|
1186
|
+
* make the base drop a late base copy of a keyframe the overlay never
|
|
1187
|
+
* finished, and lift a block's late-source cut, which nothing before
|
|
1188
|
+
* this offset did.
|
|
1189
|
+
*/
|
|
1190
|
+
#overlayUnstampedSsIdSeqOffsetByStream = new Map<string, number>();
|
|
1047
1191
|
/**
|
|
1048
1192
|
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
1049
1193
|
* not parsed, typically because its overlap copy was parsed first
|
|
@@ -1092,6 +1236,7 @@ export class MmtpRouter {
|
|
|
1092
1236
|
packetId: number,
|
|
1093
1237
|
catalogTrackName: string | undefined,
|
|
1094
1238
|
blockClass: BlockClass,
|
|
1239
|
+
span?: IsoSpanFailure,
|
|
1095
1240
|
) => void)
|
|
1096
1241
|
| null = null;
|
|
1097
1242
|
/** Typed observer of every gap decision the release gate makes. */
|
|
@@ -1101,6 +1246,8 @@ export class MmtpRouter {
|
|
|
1101
1246
|
// end: a synchronous recovery completes its block BEFORE routing the
|
|
1102
1247
|
// recovered frames, and releasing a held gap in between would strand them.
|
|
1103
1248
|
#fecPokeDepth = 0;
|
|
1249
|
+
/** FecReleaseGate.wakeAt timers, by media stream key. */
|
|
1250
|
+
readonly #fecWakes = new Map<string, { atMs: number; timer: ReturnType<typeof setTimeout> }>();
|
|
1104
1251
|
#pendingFecPokes = new Map<string, { packetId: number; catalogTrackName?: string }>();
|
|
1105
1252
|
// ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
|
|
1106
1253
|
/** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
|
|
@@ -1121,7 +1268,7 @@ export class MmtpRouter {
|
|
|
1121
1268
|
#restampedStreams = new Set<string>();
|
|
1122
1269
|
#overlayStats: KeyframeOverlayStats = {
|
|
1123
1270
|
repairDropped: 0, ownerRefused: 0, recovered: 0, restarts: 0,
|
|
1124
|
-
unsequencedDropped: 0, protectedDropped: 0,
|
|
1271
|
+
unsequencedDropped: 0, protectedDropped: 0, baseFed: 0, baseUndetermined: 0,
|
|
1125
1272
|
};
|
|
1126
1273
|
/** Callback fired when a delta-track FEC block completes or fails. */
|
|
1127
1274
|
#onDeltaBlockCompleteCb:
|
|
@@ -1189,6 +1336,7 @@ export class MmtpRouter {
|
|
|
1189
1336
|
packetId: number,
|
|
1190
1337
|
catalogTrackName: string | undefined,
|
|
1191
1338
|
blockClass: BlockClass,
|
|
1339
|
+
span?: IsoSpanFailure,
|
|
1192
1340
|
) => void;
|
|
1193
1341
|
/** Internal gap-decision sink owned by the composing transport. */
|
|
1194
1342
|
onFrameGap?: (decision: FrameGapDecision) => void;
|
|
@@ -1400,7 +1548,7 @@ export class MmtpRouter {
|
|
|
1400
1548
|
const cb = this.#getFrameCallback(packetId);
|
|
1401
1549
|
if (isVideo && !assembler) {
|
|
1402
1550
|
if (frameMeta.recovered) {
|
|
1403
|
-
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb);
|
|
1551
|
+
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb, meta.fecSbn);
|
|
1404
1552
|
} else {
|
|
1405
1553
|
this.#routeDirectSourceVideo(packetId, data, frameMeta, cb);
|
|
1406
1554
|
}
|
|
@@ -1422,6 +1570,7 @@ export class MmtpRouter {
|
|
|
1422
1570
|
packetId: number,
|
|
1423
1571
|
catalogTrackName: string | undefined,
|
|
1424
1572
|
blockClass: BlockClass,
|
|
1573
|
+
span?: IsoSpanFailure,
|
|
1425
1574
|
) => void)
|
|
1426
1575
|
| undefined,
|
|
1427
1576
|
): void {
|
|
@@ -1474,6 +1623,7 @@ export class MmtpRouter {
|
|
|
1474
1623
|
packetId: number,
|
|
1475
1624
|
catalogTrackName: string | undefined,
|
|
1476
1625
|
blockClass: BlockClass,
|
|
1626
|
+
span?: IsoSpanFailure,
|
|
1477
1627
|
) => {
|
|
1478
1628
|
this.#mseAssemblerFor(packetId, catalogTrackName)?.failBlock(sbn);
|
|
1479
1629
|
if (
|
|
@@ -1482,8 +1632,13 @@ export class MmtpRouter {
|
|
|
1482
1632
|
) {
|
|
1483
1633
|
this.#onDeltaBlockCompleteCb?.(packetId, true); // failed=true
|
|
1484
1634
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1635
|
+
if (span === undefined) {
|
|
1636
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
1637
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
1638
|
+
} else {
|
|
1639
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
1640
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
1641
|
+
}
|
|
1487
1642
|
};
|
|
1488
1643
|
}
|
|
1489
1644
|
}
|
|
@@ -1536,8 +1691,9 @@ export class MmtpRouter {
|
|
|
1536
1691
|
|
|
1537
1692
|
/**
|
|
1538
1693
|
* FEC-recovered source symbols whose reconstructed header named a
|
|
1539
|
-
* packet_sequence_number other than the wire sequence their SS_ID maps to
|
|
1540
|
-
*
|
|
1694
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to,
|
|
1695
|
+
* or, rebuilt by the overlay, than their base copy carries: a hop
|
|
1696
|
+
* re-stamped the sequence after the sender protected the packet.
|
|
1541
1697
|
*/
|
|
1542
1698
|
get restampedRecoveredSequenceCount(): number {
|
|
1543
1699
|
return this.#restampedRecoveredSeqs;
|
|
@@ -1761,6 +1917,11 @@ export class MmtpRouter {
|
|
|
1761
1917
|
): CmafBlockAssembler {
|
|
1762
1918
|
const assemblerKey = this.#mseAssemblerKey(packetId, catalogTrackName);
|
|
1763
1919
|
const previous = this.#mseAssemblers.get(assemblerKey);
|
|
1920
|
+
// The new assembler has no source cursor: the release gate must not hold
|
|
1921
|
+
// an overlay keyframe for one either (FecReleaseSequencer.#cursorPassed).
|
|
1922
|
+
// What the gate holds that unanchored had already released to the
|
|
1923
|
+
// assembler being replaced goes to it first, and plays with its flush.
|
|
1924
|
+
this.#parser.unsourceFecRelease(packetId, catalogTrackName);
|
|
1764
1925
|
if (previous) {
|
|
1765
1926
|
previous.flush();
|
|
1766
1927
|
previous.dispose();
|
|
@@ -1832,6 +1993,7 @@ export class MmtpRouter {
|
|
|
1832
1993
|
packetId: number,
|
|
1833
1994
|
catalogTrackName: string | undefined,
|
|
1834
1995
|
blockClass: BlockClass,
|
|
1996
|
+
span?: IsoSpanFailure,
|
|
1835
1997
|
) => void,
|
|
1836
1998
|
): void {
|
|
1837
1999
|
this.#onBlockFailed = cb;
|
|
@@ -1915,6 +2077,11 @@ export class MmtpRouter {
|
|
|
1915
2077
|
return { ...this.#overlayStats };
|
|
1916
2078
|
}
|
|
1917
2079
|
|
|
2080
|
+
/** Recovered FT=2 heads held for their FT=1, and how each left the wait (BLO-53369). */
|
|
2081
|
+
get recoveredHeadsAwaitingTiming(): Readonly<MmtpRecoveredHeadTimingStats> {
|
|
2082
|
+
return this.#parser.recoveredHeadsAwaitingTiming;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
1918
2085
|
#isOverlayRepair(repairPacketId: number, repairTrackName?: string): boolean {
|
|
1919
2086
|
return this.#overlayLegs.has(repairPacketId) ||
|
|
1920
2087
|
(repairTrackName !== undefined && this.#overlayRepairNames.has(repairTrackName));
|
|
@@ -1931,7 +2098,7 @@ export class MmtpRouter {
|
|
|
1931
2098
|
const leg = this.#overlayLegs.get(repairPacketId);
|
|
1932
2099
|
if (!leg) throw new Error(`[MmtpRouter] packetId=${repairPacketId} is no known keyframe-overlay leg`);
|
|
1933
2100
|
const inst: OverlayInstance = {
|
|
1934
|
-
repairPacketId, streamName, leg: { ...leg }, fec, k, offsets: new Map(), moqBlocks: new Set(),
|
|
2101
|
+
repairPacketId, streamName, leg: { ...leg }, fec, k, offsets: new Map(), moqBlocks: new Set(), rebuilt: new Map(),
|
|
1935
2102
|
};
|
|
1936
2103
|
this.#overlays.set(repairPacketId, inst);
|
|
1937
2104
|
return () => {
|
|
@@ -1966,6 +2133,13 @@ export class MmtpRouter {
|
|
|
1966
2133
|
*/
|
|
1967
2134
|
resetKeyframeOverlays(sourcePacketId: number, catalogTrackName?: string): void {
|
|
1968
2135
|
for (const inst of this.#overlaysForSource(sourcePacketId, catalogTrackName)) this.#resetOverlay(inst);
|
|
2136
|
+
// The base restarted with it: base SS_IDs kept for joint decoding name
|
|
2137
|
+
// the old epoch's packets.
|
|
2138
|
+
for (const [name, stream] of this.#streams.get(sourcePacketId) ?? []) {
|
|
2139
|
+
if (catalogTrackName !== undefined && name !== catalogTrackName) continue;
|
|
2140
|
+
stream.overlayToBase.routed.clear();
|
|
2141
|
+
stream.overlayToBase.pending.clear();
|
|
2142
|
+
}
|
|
1969
2143
|
}
|
|
1970
2144
|
|
|
1971
2145
|
#resetOverlay(inst: OverlayInstance): void {
|
|
@@ -1973,6 +2147,7 @@ export class MmtpRouter {
|
|
|
1973
2147
|
inst.last = undefined;
|
|
1974
2148
|
inst.offsets.clear();
|
|
1975
2149
|
inst.moqBlocks.clear();
|
|
2150
|
+
inst.rebuilt.clear();
|
|
1976
2151
|
}
|
|
1977
2152
|
|
|
1978
2153
|
#overlaysForSource(sourcePacketId: number, catalogTrackName: string | undefined): OverlayInstance[] {
|
|
@@ -2043,7 +2218,15 @@ export class MmtpRouter {
|
|
|
2043
2218
|
* A source packet that carries a 0x8B01 overlay SS_ID is also a symbol of
|
|
2044
2219
|
* every overlay installed for its source, at that SS_ID, with the bytes the
|
|
2045
2220
|
* base protects: the packet minus its 4-byte SS_ID trailer, extension
|
|
2046
|
-
* included (7.1, 7.4.3).
|
|
2221
|
+
* included (7.1, 7.4.3). `baseSsId` is that trailer's SS_ID, when the base
|
|
2222
|
+
* FEC reads it.
|
|
2223
|
+
*
|
|
2224
|
+
* The base copy of a packet an overlay rebuilt with no base SS_ID shows
|
|
2225
|
+
* what a base recovery of it would (#routeProcessedFecSymbols, BLO-52085):
|
|
2226
|
+
* its wire packet_sequence_number equal to the protected one rebuilt shows
|
|
2227
|
+
* the stream unstamped at the SS_ID offset it states, for the release gate
|
|
2228
|
+
* (#overlayUnstampedSsIdSeqOffsetByStream); any other shows a hop that
|
|
2229
|
+
* re-stamps it, which is counted (restampedRecoveredSequenceCount).
|
|
2047
2230
|
*/
|
|
2048
2231
|
#feedOverlaySource(
|
|
2049
2232
|
packetId: number,
|
|
@@ -2053,16 +2236,35 @@ export class MmtpRouter {
|
|
|
2053
2236
|
sequenceNumber: number,
|
|
2054
2237
|
rapFlag: boolean,
|
|
2055
2238
|
source: MmtpSourcePath,
|
|
2239
|
+
baseSsId: number | undefined,
|
|
2056
2240
|
): void {
|
|
2057
2241
|
if (this.#overlays.size === 0) return;
|
|
2058
2242
|
const ssId = keyframeOverlaySsId(header);
|
|
2059
2243
|
if (ssId === undefined) return;
|
|
2244
|
+
let rebuiltPsn: number | undefined;
|
|
2060
2245
|
for (const inst of this.#overlaysForSource(packetId, catalogTrackName)) {
|
|
2061
2246
|
this.#noteOverlaySsId(inst, ssId, sequenceNumber);
|
|
2247
|
+
// After the restart check: a new epoch forgets the old one's packets.
|
|
2248
|
+
rebuiltPsn ??= inst.rebuilt.get(ssId);
|
|
2249
|
+
inst.rebuilt.delete(ssId);
|
|
2062
2250
|
const identity = MmtpContainerParser.sourcePacketIdentity(packet, header);
|
|
2063
2251
|
if (identity !== null) {
|
|
2252
|
+
// The newest member anchors its MPU; one with no base SS_ID leaves the
|
|
2253
|
+
// MPU no base anchor rather than keep an older member's. A member that
|
|
2254
|
+
// is no FEC source packet of the base takes an overlay SS_ID and a psn
|
|
2255
|
+
// but no base SS_ID, so past it an older anchor would put each rebuilt
|
|
2256
|
+
// packet one base slot high, and overlayBaseSsId's psn test would pass
|
|
2257
|
+
// it. That costs a conforming stream nothing: every member carries the
|
|
2258
|
+
// base trailer (7.4.3), unread only while the base track is
|
|
2259
|
+
// unconfigured (fecUnreadable), which joint decoding skips, and a base
|
|
2260
|
+
// release (MulticastManager) resets or removes the overlay, so no
|
|
2261
|
+
// readable member precedes an unread one in its MPU.
|
|
2064
2262
|
inst.offsets.delete(identity.mpuSequenceNumber);
|
|
2065
|
-
inst.offsets.set(identity.mpuSequenceNumber,
|
|
2263
|
+
inst.offsets.set(identity.mpuSequenceNumber, {
|
|
2264
|
+
psnOffset: (ssId - sequenceNumber) >>> 0,
|
|
2265
|
+
overlaySsId: ssId,
|
|
2266
|
+
...(baseSsId === undefined ? {} : { baseSsId }),
|
|
2267
|
+
});
|
|
2066
2268
|
if (inst.offsets.size > OVERLAY_OFFSET_MPUS) inst.offsets.delete(inst.offsets.keys().next().value!);
|
|
2067
2269
|
}
|
|
2068
2270
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -2082,6 +2284,18 @@ export class MmtpRouter {
|
|
|
2082
2284
|
const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
|
|
2083
2285
|
if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, coords.sbn, recovered);
|
|
2084
2286
|
}
|
|
2287
|
+
if (rebuiltPsn === undefined || this.#classifyPacketId(packetId) === null) return;
|
|
2288
|
+
const streamKey = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
2289
|
+
if (rebuiltPsn !== sequenceNumber) {
|
|
2290
|
+
// Counted only. Marked re-stamped (#restampedStreams), the stream would
|
|
2291
|
+
// drop every later rebuilt packet no member anchors, which the overlay
|
|
2292
|
+
// route delivers unanchored until a base recovery shows the re-stamp:
|
|
2293
|
+
// a keyframe whose base copy is lost too would never play.
|
|
2294
|
+
this.#restampedRecoveredSeqs++;
|
|
2295
|
+
} else if (baseSsId !== undefined) {
|
|
2296
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
2297
|
+
if (offset === ((baseSsId - sequenceNumber) >>> 0)) this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
2298
|
+
}
|
|
2085
2299
|
}
|
|
2086
2300
|
|
|
2087
2301
|
#noteOverlayMoqBlock(inst: OverlayInstance, blockStart: number): void {
|
|
@@ -2122,11 +2336,16 @@ export class MmtpRouter {
|
|
|
2122
2336
|
|
|
2123
2337
|
/**
|
|
2124
2338
|
* Route an overlay-recovered block's packets as source media of the
|
|
2125
|
-
* overlay's source (7.2: an overlay coordinate yields no base SS_ID).
|
|
2126
|
-
*
|
|
2127
|
-
*
|
|
2128
|
-
*
|
|
2129
|
-
*
|
|
2339
|
+
* overlay's source (7.2: an overlay coordinate yields no base SS_ID). A
|
|
2340
|
+
* packet whose base SS_ID is determined independently (overlayBaseSsId,
|
|
2341
|
+
* unstampedBaseSsId) enters the release gate at that SS_ID, as a packet
|
|
2342
|
+
* base FEC recovered does, so it waits behind base frames still in flight,
|
|
2343
|
+
* though not for its own MPU's packets (FrameMeta.fecSbnFirst) and no
|
|
2344
|
+
* longer than unanchored; one whose base SS_ID is undetermined has no
|
|
2345
|
+
* release-gate anchor. No parse ledger, no base re-stamp, no block
|
|
2346
|
+
* advance. Each packet's wire sequence is restored from its keyframe's own
|
|
2347
|
+
* offset; without one, a stream the base never re-stamped keeps the
|
|
2348
|
+
* header's sequence and any other drops the packet.
|
|
2130
2349
|
*/
|
|
2131
2350
|
#routeOverlayRecovered(inst: OverlayInstance, blockStart: number, recovered: Uint8Array): void {
|
|
2132
2351
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -2149,27 +2368,181 @@ export class MmtpRouter {
|
|
|
2149
2368
|
const streamKey = this.#mediaStreamKey(sourcePacketId, sourceName);
|
|
2150
2369
|
const restamped = this.#restampedStreams.has(streamKey);
|
|
2151
2370
|
const restored = new Set<number>();
|
|
2371
|
+
// The base SS_IDs determined independently, by overlay ESI; those the
|
|
2372
|
+
// overlay alone showed anchor the release gate, not the base decoder.
|
|
2373
|
+
const baseSsIds = new Map<number, number>();
|
|
2374
|
+
const gateOnly = new Set<number>();
|
|
2152
2375
|
const symbols = result.symbols.flatMap((sym) => {
|
|
2153
|
-
const
|
|
2154
|
-
|
|
2155
|
-
|
|
2376
|
+
const overlaySsId = serial32Add(blockStart, sym.index);
|
|
2377
|
+
const anchor = inst.offsets.get(sym.fragment.mpuSequenceNumber);
|
|
2378
|
+
if (anchor !== undefined) {
|
|
2379
|
+
const packetSequenceNumber = (overlaySsId - anchor.psnOffset) >>> 0;
|
|
2156
2380
|
restored.add(packetSequenceNumber);
|
|
2157
|
-
|
|
2381
|
+
const out = { ...sym, packetSequenceNumber };
|
|
2382
|
+
const baseSsId = overlayBaseSsId(anchor, overlaySsId, packetSequenceNumber, sym.packetSequenceNumber);
|
|
2383
|
+
if (baseSsId !== undefined) {
|
|
2384
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
2385
|
+
// Its protected psn is the wire sequence its member gives it, at
|
|
2386
|
+
// the base SS_ID that member gives it: at the stream's current
|
|
2387
|
+
// SS_ID offset, the stream unstamped, as a base recovery shows it
|
|
2388
|
+
// (#routeProcessedFecSymbols). A re-stamping hop fails the psn test.
|
|
2389
|
+
// Only for a packet the base did not receive: a received member's
|
|
2390
|
+
// slot holds the bytes it arrived with (the decoder keeps a
|
|
2391
|
+
// received source as given), whose psn is the wire one whatever a
|
|
2392
|
+
// hop did, so it passes the test against itself.
|
|
2393
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
2394
|
+
if (!this.#sourceSeqReceived(sourcePacketId, packetSequenceNumber, sourceName) &&
|
|
2395
|
+
offset === ((baseSsId - packetSequenceNumber) >>> 0)) {
|
|
2396
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
return [out];
|
|
2158
2400
|
}
|
|
2159
2401
|
// A stream re-stamped by a bridge that no base recovery has shown yet
|
|
2160
2402
|
// keeps the header's sequence too: from received packets alone the
|
|
2161
|
-
// router cannot tell (their psn is the wire one)
|
|
2162
|
-
//
|
|
2163
|
-
|
|
2403
|
+
// router cannot tell (their psn is the wire one), and the base copy of
|
|
2404
|
+
// a packet the overlay rebuilt only counts a re-stamp. Base recovery or
|
|
2405
|
+
// a FETCH still covers such a keyframe.
|
|
2406
|
+
if (!restamped) {
|
|
2407
|
+
// No member of this MPU arrived to anchor a base SS_ID. Evidence that
|
|
2408
|
+
// the stream is unstamped at its current offset determines one from
|
|
2409
|
+
// the packet's protected psn instead (unstampedBaseSsId): a base
|
|
2410
|
+
// recovery's, or else the overlay's own, which anchors the release
|
|
2411
|
+
// gate only (#overlayUnstampedSsIdSeqOffsetByStream). Without it, the
|
|
2412
|
+
// packet's base copy, if it lands, shows whether it is
|
|
2413
|
+
// (#feedOverlaySource).
|
|
2414
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
2415
|
+
const fedSsId = unstampedBaseSsId(offset, this.#unstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
2416
|
+
const baseSsId = fedSsId ??
|
|
2417
|
+
unstampedBaseSsId(offset, this.#overlayUnstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
2418
|
+
if (baseSsId !== undefined) {
|
|
2419
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
2420
|
+
if (fedSsId === undefined) gateOnly.add(sym.index);
|
|
2421
|
+
} else {
|
|
2422
|
+
inst.rebuilt.set(overlaySsId, sym.packetSequenceNumber);
|
|
2423
|
+
if (inst.rebuilt.size > OVERLAY_REBUILT_LIMIT) inst.rebuilt.delete(inst.rebuilt.keys().next().value!);
|
|
2424
|
+
}
|
|
2425
|
+
return [sym];
|
|
2426
|
+
}
|
|
2164
2427
|
this.#overlayStats.unsequencedDropped++;
|
|
2165
2428
|
return [];
|
|
2166
2429
|
});
|
|
2167
2430
|
this.#overlayStats.recovered++;
|
|
2431
|
+
// Each packet's MPU starts, in this decode, at the lowest base SS_ID
|
|
2432
|
+
// determined for it: the release gate's span ends there.
|
|
2433
|
+
const mpuFirst = new Map<number, number>();
|
|
2434
|
+
for (const sym of symbols) {
|
|
2435
|
+
const ssId = baseSsIds.get(sym.index);
|
|
2436
|
+
const mpu = sym.fragment.mpuSequenceNumber;
|
|
2437
|
+
const first = mpuFirst.get(mpu);
|
|
2438
|
+
if (ssId !== undefined && (first === undefined || serial32Precedes(ssId, first))) mpuFirst.set(mpu, ssId);
|
|
2439
|
+
}
|
|
2440
|
+
const firstSsIds = new Map<number, number>();
|
|
2441
|
+
for (const sym of symbols) {
|
|
2442
|
+
if (baseSsIds.has(sym.index)) firstSsIds.set(sym.index, mpuFirst.get(sym.fragment.mpuSequenceNumber)!);
|
|
2443
|
+
}
|
|
2168
2444
|
this.#routeProcessedFecSymbols(blockStart, { ...result, symbols }, sourcePacketId, sourceName, {
|
|
2169
2445
|
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast",
|
|
2446
|
+
baseSsIds,
|
|
2447
|
+
firstSsIds,
|
|
2170
2448
|
});
|
|
2171
2449
|
this.#noteOverlayRecoveredRaps(sourcePacketId, sourceName, streamKey, symbols.filter((sym) =>
|
|
2172
2450
|
restored.has(sym.packetSequenceNumber)));
|
|
2451
|
+
this.#feedOverlayRecoveredToBase(inst, blockStart, symbols, gateOnly.size === 0
|
|
2452
|
+
? baseSsIds
|
|
2453
|
+
: new Map([...baseSsIds].filter(([index]) => !gateOnly.has(index))));
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
/**
|
|
2457
|
+
* Joint decoding (BLO-52085). A packet the overlay rebuilt is a source of
|
|
2458
|
+
* its base block too, once its base SS_ID is determined (overlayBaseSsId,
|
|
2459
|
+
* from a received member of its MPU, else unstampedBaseSsId at an offset a
|
|
2460
|
+
* base recovery showed; `baseSsIds` holds no other),
|
|
2461
|
+
* so it is fed to the base decoder as a rebuilt source
|
|
2462
|
+
* (FECManager.feedRebuiltSourceSymbol): the base block has one erasure
|
|
2463
|
+
* fewer to solve, and its repair can recover the block's other packets.
|
|
2464
|
+
* A base block no repair has stated yet takes it when one does
|
|
2465
|
+
* (#feedPendingRebuilt).
|
|
2466
|
+
*
|
|
2467
|
+
* The overlay route already handled each packet fed (delivered it, or
|
|
2468
|
+
* held an untimed head for its FT=1), so a base recovery routes none of
|
|
2469
|
+
* them again (#routeVerifiedFecSymbols): a second recovered copy of a
|
|
2470
|
+
* held head would wait in the parser for timing its first copy consumed.
|
|
2471
|
+
* Only an overlay block decoded from multicast symbols alone is fed: with
|
|
2472
|
+
* a MoQ symbol in it, the base block's recovery would depend on bytes
|
|
2473
|
+
* that crossed no multicast socket, which the provenance counted from the
|
|
2474
|
+
* block's own arrivals cannot show.
|
|
2475
|
+
*/
|
|
2476
|
+
#feedOverlayRecoveredToBase(
|
|
2477
|
+
inst: OverlayInstance,
|
|
2478
|
+
blockStart: number,
|
|
2479
|
+
symbols: ProcessFecBlockResult["symbols"],
|
|
2480
|
+
baseSsIds: ReadonlyMap<number, number>,
|
|
2481
|
+
): void {
|
|
2482
|
+
const fec = this.#fecManager;
|
|
2483
|
+
const owner = inst.leg.sourcePacketId;
|
|
2484
|
+
const name = inst.leg.sourceCatalogTrackName;
|
|
2485
|
+
if (!fec?.feedRebuiltSourceSymbol || inst.moqBlocks.has(blockStart)) return;
|
|
2486
|
+
if (this.#classifyPacketId(owner) === null || fec.isTrackConfigured?.(owner) === false) return;
|
|
2487
|
+
const { duplicates, overlayToBase: { routed } } = this.#stream(owner, name);
|
|
2488
|
+
const feeds: Array<readonly [number, Uint8Array]> = [];
|
|
2489
|
+
for (const sym of symbols) {
|
|
2490
|
+
// A packet the base received already sits in its block.
|
|
2491
|
+
if (duplicates.sourceSeqs.has(sym.packetSequenceNumber)) continue;
|
|
2492
|
+
const ssId = baseSsIds.get(sym.index);
|
|
2493
|
+
if (ssId === undefined) {
|
|
2494
|
+
this.#overlayStats.baseUndetermined++;
|
|
2495
|
+
continue;
|
|
2496
|
+
}
|
|
2497
|
+
routed.delete(ssId);
|
|
2498
|
+
routed.add(ssId);
|
|
2499
|
+
if (routed.size > OVERLAY_ROUTED_LIMIT) routed.delete(routed.values().next().value!);
|
|
2500
|
+
feeds.push([ssId, sym.rawSymbol]);
|
|
2501
|
+
}
|
|
2502
|
+
// Any feed can recover the base block, whose routing must already skip
|
|
2503
|
+
// every packet this recovery routed: all are registered before the first.
|
|
2504
|
+
for (const [ssId, symbolData] of feeds) {
|
|
2505
|
+
// A recovery routed above can retire the owner (an in-place switch).
|
|
2506
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
2507
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
/** Feed one rebuilt source to its base block, or keep it until a repair states that block. */
|
|
2512
|
+
#feedRebuiltToBase(owner: number, name: string | undefined, ssId: number, symbolData: Uint8Array): void {
|
|
2513
|
+
const fec = this.#fecManager;
|
|
2514
|
+
if (!fec?.feedRebuiltSourceSymbol) return;
|
|
2515
|
+
const coords = fec.locateIsoSource?.(owner, name, ssId);
|
|
2516
|
+
if (coords == null) {
|
|
2517
|
+
const pending = this.#stream(owner, name).overlayToBase.pending;
|
|
2518
|
+
pending.delete(ssId);
|
|
2519
|
+
// Its own copy: the symbol is a view of the whole recovered block.
|
|
2520
|
+
pending.set(ssId, symbolData.slice());
|
|
2521
|
+
if (pending.size > OVERLAY_PENDING_LIMIT) pending.delete(pending.keys().next().value!);
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
const fed = fec.feedRebuiltSourceSymbol(owner, ssId, symbolData, name);
|
|
2525
|
+
if (!fed.taken) return;
|
|
2526
|
+
this.#overlayStats.baseFed++;
|
|
2527
|
+
if (fed.recovered === null) return;
|
|
2528
|
+
const sbn = coords.sbn;
|
|
2529
|
+
this.#routeRecoveredBlock(sbn, fed.recovered, owner, name, () => {
|
|
2530
|
+
fec.cancelBlockTimeout(sbn, owner, name);
|
|
2531
|
+
fec.countRecovery(owner, sbn, name);
|
|
2532
|
+
fec.markBlockCompleted(sbn, owner, name);
|
|
2533
|
+
});
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
/** A repair stated `block`: the rebuilt sources that waited for it join it now. */
|
|
2537
|
+
#feedPendingRebuilt(owner: number, name: string | undefined, block: { start: number; length: number }): void {
|
|
2538
|
+
const pending = this.#streams.get(owner)?.get(name)?.overlayToBase.pending;
|
|
2539
|
+
if (pending === undefined || pending.size === 0) return;
|
|
2540
|
+
for (const [ssId, symbolData] of [...pending]) {
|
|
2541
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
2542
|
+
if (serial32Distance(block.start, ssId) >= block.length) continue;
|
|
2543
|
+
pending.delete(ssId);
|
|
2544
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
2545
|
+
}
|
|
2173
2546
|
}
|
|
2174
2547
|
|
|
2175
2548
|
/** fec-multicast-00 §6.6: report each base block whose RAP MFU fragments
|
|
@@ -2205,6 +2578,9 @@ export class MmtpRouter {
|
|
|
2205
2578
|
const mpu = sym.fragment.mpuSequenceNumber;
|
|
2206
2579
|
if (sym.fragmentType !== 2 || !sym.fragment.rapFlag || !ft0.has(mpu) || !ft1.has(mpu)) continue;
|
|
2207
2580
|
if (!single.has(mpu) && !(first.has(mpu) && last.has(mpu))) continue;
|
|
2581
|
+
// Not overlayBaseSsId: a wrong sbn only keeps or wrongly stops a keyframe
|
|
2582
|
+
// FETCH (§6.6, a SHOULD; no symbol moves), and wire psn plus offset holds
|
|
2583
|
+
// under a constant re-stamp shift, which overlayBaseSsId's psn test refuses.
|
|
2208
2584
|
const ssId = (sym.packetSequenceNumber + ssIdSeqOffset) >>> 0;
|
|
2209
2585
|
// ponytail: a base block no repair has stated yet (an undelimited hole) is not reported.
|
|
2210
2586
|
const sbn = this.#fecManager?.locateIsoSource?.(packetId, catalogTrackName, ssId)?.sbn;
|
|
@@ -2355,6 +2731,11 @@ export class MmtpRouter {
|
|
|
2355
2731
|
return this.#unadmittedListedDrops;
|
|
2356
2732
|
}
|
|
2357
2733
|
|
|
2734
|
+
/** Source datagrams (multicast or MoQ) a protected flow's bc-provenance v2 receiver released: admitted at once or held, then admitted by a record. Repair symbols and user-agent-admitted datagrams are not counted. Counted at release, before this router's own track checks: a released datagram those drop, which only a track change between hold and release can cause, still counts, so this is not a count of routed media. */
|
|
2735
|
+
get admittedSourceDatagramCount(): number {
|
|
2736
|
+
return this.#admittedSourceDatagrams;
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2358
2739
|
/** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
|
|
2359
2740
|
get unlistedRepairSetAsideCount(): number {
|
|
2360
2741
|
return this.#unlistedRepairSetAside;
|
|
@@ -2989,6 +3370,11 @@ export class MmtpRouter {
|
|
|
2989
3370
|
)) return;
|
|
2990
3371
|
fec.noteBlockActivity?.(blockStart, ownerPacketId, catalogTrackName);
|
|
2991
3372
|
fec.noteRepairGroupLength?.(blockStart, ownerPacketId, repair.rsbLength, catalogTrackName);
|
|
3373
|
+
// Rebuilt sources that waited for this block join it once the block took
|
|
3374
|
+
// a repair, so it has a deadline; still ahead of the repair, as the held
|
|
3375
|
+
// sources above are.
|
|
3376
|
+
this.#feedPendingRebuilt(ownerPacketId, catalogTrackName, placement.block);
|
|
3377
|
+
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
2992
3378
|
const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
|
|
2993
3379
|
const recovered = fec.feedRepairSymbol(
|
|
2994
3380
|
ownerPacketId,
|
|
@@ -3051,7 +3437,7 @@ export class MmtpRouter {
|
|
|
3051
3437
|
catalogTrackName,
|
|
3052
3438
|
)) continue;
|
|
3053
3439
|
if (fec.isTrackConfigured?.(ownerPacketId) !== false) {
|
|
3054
|
-
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence);
|
|
3440
|
+
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence, true);
|
|
3055
3441
|
this.#requestFecPoke(ownerPacketId, catalogTrackName);
|
|
3056
3442
|
}
|
|
3057
3443
|
if (payload.oversized) continue;
|
|
@@ -3169,6 +3555,8 @@ export class MmtpRouter {
|
|
|
3169
3555
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
3170
3556
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
3171
3557
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
3558
|
+
this.#unstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
3559
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
3172
3560
|
this.#multicastRapTwinByStream.delete(streamKey);
|
|
3173
3561
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
3174
3562
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
@@ -3300,6 +3688,12 @@ export class MmtpRouter {
|
|
|
3300
3688
|
* the outgoing stream stops. The hold is bounded by the incoming stream's
|
|
3301
3689
|
* own RAP cadence, so no timer is involved.
|
|
3302
3690
|
*
|
|
3691
|
+
* While the switch is staged, the FEC release gate lets a keyframe the
|
|
3692
|
+
* overlay rebuilt reach it, on either side, when the keyframe did before
|
|
3693
|
+
* the gate anchored it (FecReleaseGate.releaseUnanchored): the switch
|
|
3694
|
+
* decides on what each side delivered, and the commit discards the gate's
|
|
3695
|
+
* frames of the outgoing stream.
|
|
3696
|
+
*
|
|
3303
3697
|
* The commit is one synchronous transition inside the frame path: the
|
|
3304
3698
|
* outgoing stream's already-admitted frames are released (its queued FEC
|
|
3305
3699
|
* gap fills only up to the RAP, since recovery can queue a frame ahead of
|
|
@@ -3352,6 +3746,16 @@ export class MmtpRouter {
|
|
|
3352
3746
|
droppedIncomingFrames: 0,
|
|
3353
3747
|
};
|
|
3354
3748
|
this.#staged = state;
|
|
3749
|
+
// Release what the outgoing stream's gate held only because it was
|
|
3750
|
+
// anchored (FecReleaseGate.releaseUnanchored): unanchored, it had already
|
|
3751
|
+
// reached the switch. Only a gate that holds a frame the overlay rebuilt
|
|
3752
|
+
// is poked: any other holds nothing for that reason, and a poke would
|
|
3753
|
+
// still force out a frame held past the hold limit, which before the
|
|
3754
|
+
// anchor waited for the next push. The incoming stream's gate is not
|
|
3755
|
+
// drained here: a RAP it released would commit before this call returns.
|
|
3756
|
+
if (this.#parser.fecReleaseHoldsRebuilt(from.packetId, from.catalogTrackName)) {
|
|
3757
|
+
this.#requestFecPoke(from.packetId, from.catalogTrackName);
|
|
3758
|
+
}
|
|
3355
3759
|
return {
|
|
3356
3760
|
cancel: () => {
|
|
3357
3761
|
if (this.#staged !== state) return false;
|
|
@@ -3446,7 +3850,24 @@ export class MmtpRouter {
|
|
|
3446
3850
|
// same call. Nothing registers a packet ID mid-frame, so this drops
|
|
3447
3851
|
// only frames that lost their registration.
|
|
3448
3852
|
if (this.#classifyPacketId(meta.packetId) === null) return;
|
|
3449
|
-
if (this.#staged !== null
|
|
3853
|
+
if (this.#staged !== null) {
|
|
3854
|
+
// A switch staged from this frame's commit (onCommit: the ladder walk)
|
|
3855
|
+
// pokes its outgoing stream's gate, the stream just committed to, whose
|
|
3856
|
+
// drain may be what released this frame. The poke waits until the
|
|
3857
|
+
// commit has delivered that stream's init, held GOP and RAP. Run now,
|
|
3858
|
+
// it would release the frames behind them ahead of them: a delta is
|
|
3859
|
+
// dropped there (its stream is not synced yet), and a keyframe plays
|
|
3860
|
+
// ahead of the init and leaves the commit's frames behind it.
|
|
3861
|
+
let consumed = false;
|
|
3862
|
+
this.#fecPokeDepth++;
|
|
3863
|
+
try {
|
|
3864
|
+
consumed = this.#interceptSwitchFrame(data, meta);
|
|
3865
|
+
} finally {
|
|
3866
|
+
this.#fecPokeDepth--;
|
|
3867
|
+
this.#flushPendingFecPokes();
|
|
3868
|
+
}
|
|
3869
|
+
if (consumed) return;
|
|
3870
|
+
}
|
|
3450
3871
|
this.#deliverParsedFrame(data, meta);
|
|
3451
3872
|
}
|
|
3452
3873
|
|
|
@@ -3513,6 +3934,8 @@ export class MmtpRouter {
|
|
|
3513
3934
|
this.#disposed = true;
|
|
3514
3935
|
this.#staged = null;
|
|
3515
3936
|
this.cancelKeyframeLostTimer();
|
|
3937
|
+
for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
|
|
3938
|
+
this.#fecWakes.clear();
|
|
3516
3939
|
this.#parser.dispose();
|
|
3517
3940
|
this.#streams.clear();
|
|
3518
3941
|
this.#trackPacketCallbacks.clear();
|
|
@@ -3639,12 +4062,17 @@ export class MmtpRouter {
|
|
|
3639
4062
|
this.#parser.deferFecRelease(work);
|
|
3640
4063
|
} finally {
|
|
3641
4064
|
this.#fecPokeDepth--;
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
4065
|
+
this.#flushPendingFecPokes();
|
|
4066
|
+
}
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
/** Run the pokes requested while #fecPokeDepth was raised, once it is 0. */
|
|
4070
|
+
#flushPendingFecPokes(): void {
|
|
4071
|
+
if (this.#fecPokeDepth === 0 && this.#pendingFecPokes.size > 0 && !this.#disposed) {
|
|
4072
|
+
const pokes = [...this.#pendingFecPokes.values()];
|
|
4073
|
+
this.#pendingFecPokes.clear();
|
|
4074
|
+
for (const poke of pokes) {
|
|
4075
|
+
this.#parser.pokeFecRelease(poke.packetId, poke.catalogTrackName);
|
|
3648
4076
|
}
|
|
3649
4077
|
}
|
|
3650
4078
|
}
|
|
@@ -3724,6 +4152,35 @@ export class MmtpRouter {
|
|
|
3724
4152
|
if (!fec?.terminalRetentionMsForPacket) return Infinity;
|
|
3725
4153
|
return fec.terminalRetentionMsForPacket(packetId) ?? 0;
|
|
3726
4154
|
},
|
|
4155
|
+
// Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
|
|
4156
|
+
// late source can), its frame waits the late-symbol allowance when the
|
|
4157
|
+
// gap holds no RAP an installed keyframe overlay could still rebuild:
|
|
4158
|
+
// lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
|
|
4159
|
+
// that opens the next one while MPU boundaries bound RAPs (rap-next,
|
|
4160
|
+
// unless the gap holds a stated block's loss: the overlay may rebuild
|
|
4161
|
+
// that MPU's FT=0, and the block's group then complete it), or
|
|
4162
|
+
// an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
|
|
4163
|
+
// other rap-next, whose gap may hold a whole MPU and the keyframe the
|
|
4164
|
+
// overlay protects) waits for that overlay's repair too (BLO-52085
|
|
4165
|
+
// D4). The FEC check comes first: most held gaps are not behind such a
|
|
4166
|
+
// span, and deciding one scans both frames' bitstreams.
|
|
4167
|
+
unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
|
|
4168
|
+
const fec = this.#fecManager;
|
|
4169
|
+
const { packetId, catalogTrackName } = after.meta;
|
|
4170
|
+
const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
|
|
4171
|
+
if (!fec || allowanceMs === undefined) return undefined;
|
|
4172
|
+
const decision = this.#decideGap(before, after, [], false);
|
|
4173
|
+
const mpu = before.meta.mpuSequenceNumber;
|
|
4174
|
+
const intoNextMpu = decision.reason === "rap-next" && mpu !== undefined &&
|
|
4175
|
+
after.meta.mpuSequenceNumber === ((mpu + 1) >>> 0) &&
|
|
4176
|
+
fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
|
|
4177
|
+
if (decision.action === "stall" || (decision.reason === "rap-next" && !intoNextMpu)) {
|
|
4178
|
+
return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
|
|
4179
|
+
}
|
|
4180
|
+
return decision.reason === "rap-next"
|
|
4181
|
+
? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true)
|
|
4182
|
+
: allowanceMs;
|
|
4183
|
+
},
|
|
3727
4184
|
decide: (before, after, lostBlocks, discontinuity) => {
|
|
3728
4185
|
const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
|
|
3729
4186
|
this.#onFrameGap?.(decision);
|
|
@@ -3733,6 +4190,28 @@ export class MmtpRouter {
|
|
|
3733
4190
|
onRap: (packetId, catalogTrackName, ssId) => {
|
|
3734
4191
|
for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
|
|
3735
4192
|
},
|
|
4193
|
+
// One timer per stream, at the earliest wake asked: its drain re-arms
|
|
4194
|
+
// for the next frame still waiting.
|
|
4195
|
+
wakeAt: (packetId, catalogTrackName, atMs) => {
|
|
4196
|
+
if (this.#disposed) return;
|
|
4197
|
+
const key = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
4198
|
+
const armed = this.#fecWakes.get(key);
|
|
4199
|
+
if (armed !== undefined && armed.atMs <= atMs) return;
|
|
4200
|
+
if (armed !== undefined) clearTimeout(armed.timer);
|
|
4201
|
+
const timer = setTimeout(() => {
|
|
4202
|
+
this.#fecWakes.delete(key);
|
|
4203
|
+
this.#requestFecPoke(packetId, catalogTrackName);
|
|
4204
|
+
}, Math.max(0, Math.ceil(atMs - performance.now())));
|
|
4205
|
+
this.#fecWakes.set(key, { atMs, timer });
|
|
4206
|
+
},
|
|
4207
|
+
// A staged switch commits on when each side's frames reach it
|
|
4208
|
+
// (#interceptSwitchFrame): both sides' overlay keyframes reach it when
|
|
4209
|
+
// they did unanchored.
|
|
4210
|
+
releaseUnanchored: (packetId, catalogTrackName) => {
|
|
4211
|
+
const staged = this.#staged;
|
|
4212
|
+
const stream = { packetId, ...(catalogTrackName === undefined ? {} : { catalogTrackName }) };
|
|
4213
|
+
return staged !== null && (isStream(stream, staged.from) || isStream(stream, staged.to));
|
|
4214
|
+
},
|
|
3736
4215
|
onReleased: (data, meta) => {
|
|
3737
4216
|
if (meta.trackType !== "video" || meta.mpuSequenceNumber === undefined) return;
|
|
3738
4217
|
const timing = meta.authoredTiming;
|
|
@@ -3768,10 +4247,17 @@ export class MmtpRouter {
|
|
|
3768
4247
|
): FrameGapDecision {
|
|
3769
4248
|
const { packetId, catalogTrackName } = after.meta;
|
|
3770
4249
|
const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
|
|
3771
|
-
//
|
|
3772
|
-
// the
|
|
4250
|
+
// decideGap counts the frames a delta-lost gap missed as the difference
|
|
4251
|
+
// of the two sides' sample_number. That is exact only within one movie
|
|
4252
|
+
// fragment, which numbers its samples consecutively, and is stated only
|
|
4253
|
+
// while the classifier verifies the geometry. Two fragments state no
|
|
4254
|
+
// count: an MPU of several multi-sample fragments still classifies while
|
|
4255
|
+
// the classifier received only one of them first-hand (BLO-55339).
|
|
4256
|
+
// ponytail: cross-fragment gaps report missingFrames null; count them from
|
|
4257
|
+
// BlockClassifier MPU positions when concealedFrames must cover them.
|
|
3773
4258
|
const positionsTrusted =
|
|
3774
|
-
this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying"
|
|
4259
|
+
this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" &&
|
|
4260
|
+
before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
|
|
3775
4261
|
// "Same MPU on both sides" proves a delta-only gap only while an MPU
|
|
3776
4262
|
// boundary bounds the stream's RAPs. Once a RAP was seen inside an MPU
|
|
3777
4263
|
// (or an MPU outran its GOP), a lost RAP can hide inside one MPU, so the
|
|
@@ -3928,6 +4414,8 @@ export class MmtpRouter {
|
|
|
3928
4414
|
const parsed = this.#parser.parsePacket(packet);
|
|
3929
4415
|
if (!parsed) return;
|
|
3930
4416
|
const info = parsed.info;
|
|
4417
|
+
// manifestAdmitted is set only by a receiver release or the user agent's own verification.
|
|
4418
|
+
if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
|
|
3931
4419
|
// Every multicast packet is a delivery-gap sample, including one dropped
|
|
3932
4420
|
// below: the gap is a property of the link the FEC deadlines run on, not
|
|
3933
4421
|
// of which packets this router routes. The re-entry after a manifest
|
|
@@ -4391,6 +4879,7 @@ export class MmtpRouter {
|
|
|
4391
4879
|
if (!overlapCopy && this.#classifyPacketId(info.packetId) !== null) {
|
|
4392
4880
|
this.#feedOverlaySource(
|
|
4393
4881
|
info.packetId, catalogTrackName, packet, parsed.header, info.sequenceNumber, info.rapFlag, source,
|
|
4882
|
+
fecPayloadId?.ssId,
|
|
4394
4883
|
);
|
|
4395
4884
|
}
|
|
4396
4885
|
}
|
|
@@ -4415,6 +4904,7 @@ export class MmtpRouter {
|
|
|
4415
4904
|
deliveryProvenance?: MmtpDeliveryProvenance;
|
|
4416
4905
|
catalogTrackName?: string;
|
|
4417
4906
|
fecSbn?: number;
|
|
4907
|
+
fecSbnFirst?: number;
|
|
4418
4908
|
},
|
|
4419
4909
|
parsed?: ParsedMmtpPacket,
|
|
4420
4910
|
): void {
|
|
@@ -4438,6 +4928,7 @@ export class MmtpRouter {
|
|
|
4438
4928
|
deliveryProvenance: parserOptions?.deliveryProvenance,
|
|
4439
4929
|
catalogTrackName: parserOptions?.catalogTrackName,
|
|
4440
4930
|
...(parserOptions?.fecSbn === undefined ? {} : { fecSbn: parserOptions.fecSbn }),
|
|
4931
|
+
...(parserOptions?.fecSbnFirst === undefined ? {} : { fecSbnFirst: parserOptions.fecSbnFirst }),
|
|
4441
4932
|
};
|
|
4442
4933
|
if (parsed) this.#parser.feedParsed(packet, parsed, feedOptions);
|
|
4443
4934
|
else this.#parser.feed(packet, feedOptions);
|
|
@@ -4619,6 +5110,7 @@ export class MmtpRouter {
|
|
|
4619
5110
|
stream = {
|
|
4620
5111
|
key: JSON.stringify([packetId, catalogTrackName ?? null]),
|
|
4621
5112
|
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId)),
|
|
5113
|
+
overlayToBase: { routed: new Set(), pending: new Map() },
|
|
4622
5114
|
};
|
|
4623
5115
|
byName.set(catalogTrackName, stream);
|
|
4624
5116
|
}
|
|
@@ -4817,8 +5309,29 @@ export class MmtpRouter {
|
|
|
4817
5309
|
data: Uint8Array,
|
|
4818
5310
|
meta: RoutedFrameMeta,
|
|
4819
5311
|
cb: FrameCallback | null,
|
|
5312
|
+
/** The base SS_ID the FEC release gate ordered the frame by, if any. */
|
|
5313
|
+
fecSbn: number | undefined,
|
|
4820
5314
|
): void {
|
|
4821
5315
|
const streamKey = this.#mediaStreamKey(packetId, meta.catalogTrackName);
|
|
5316
|
+
// The FEC release gate let this frame out in order: only once every
|
|
5317
|
+
// block between it and the frame before it resolved, because it starts
|
|
5318
|
+
// where that frame ended, or (one the overlay rebuilt) once the base
|
|
5319
|
+
// path passed it. Nothing still in flight can precede it then, so it
|
|
5320
|
+
// plays now, as a source frame does; holding it for the next
|
|
5321
|
+
// intact frame cost every repaired burst its length in decoder input
|
|
5322
|
+
// (BLO-52085). An overlay recovery whose base SS_ID is undetermined names
|
|
5323
|
+
// no base block for the gate to wait on, so past a gap it may be ahead of
|
|
5324
|
+
// frames still in flight (an overlay that outran the wire, BLO-53342): it
|
|
5325
|
+
// keeps waiting for the source cursor below, unless it starts where the
|
|
5326
|
+
// last emitted frame ended (on this direct path, the delivered high water).
|
|
5327
|
+
if (this.#isFecTrack(packetId)) {
|
|
5328
|
+
const high = this.#deliveredVideoHighWaterByStream.get(streamKey);
|
|
5329
|
+
if (fecSbn !== undefined || (high !== undefined && authoredAdjacent(high, meta))) {
|
|
5330
|
+
this.#drainDirectRecoveredVideo(streamKey, packetId, frame => frame.timestamp <= meta.timestamp, cb);
|
|
5331
|
+
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
5332
|
+
return;
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
4822
5335
|
this.#enqueueDirectRecoveredVideo(packetId, data, meta);
|
|
4823
5336
|
const lastSourceTs = this.#lastDirectSourceVideoTsByStream.get(streamKey);
|
|
4824
5337
|
this.#drainDirectRecoveredVideo(
|
|
@@ -5056,6 +5569,17 @@ export class MmtpRouter {
|
|
|
5056
5569
|
complete?: () => void,
|
|
5057
5570
|
assisted = false,
|
|
5058
5571
|
): boolean {
|
|
5572
|
+
// A packet a keyframe overlay recovery routed before it fed the packet to
|
|
5573
|
+
// this block (#feedOverlayRecoveredToBase) is not routed again.
|
|
5574
|
+
const overlayRouted = ownerPacketId == null
|
|
5575
|
+
? undefined
|
|
5576
|
+
: this.#streams.get(ownerPacketId)?.get(catalogTrackName)?.overlayToBase.routed;
|
|
5577
|
+
if (overlayRouted !== undefined && overlayRouted.size > 0) {
|
|
5578
|
+
result = {
|
|
5579
|
+
...result,
|
|
5580
|
+
symbols: result.symbols.filter((sym) => !overlayRouted.has(this.#fecAnchorForRecovered(blockId, sym.index))),
|
|
5581
|
+
};
|
|
5582
|
+
}
|
|
5059
5583
|
const entry = ownerPacketId == null ? undefined : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
5060
5584
|
const receiver = entry === undefined || entry === "ambiguous" ? entry : entry.receiver;
|
|
5061
5585
|
const userAgent = !assisted && entry !== undefined && entry !== "ambiguous" && entry.protected === true && entry.userAgent === true;
|
|
@@ -5125,15 +5649,25 @@ export class MmtpRouter {
|
|
|
5125
5649
|
catalogTrackName?: string,
|
|
5126
5650
|
/** Set for a keyframe-overlay recovery: `blockId` is an overlay
|
|
5127
5651
|
* coordinate, which yields no base SS_ID (mmt-02 7.2), and the packets'
|
|
5128
|
-
* wire sequences are already restored.
|
|
5129
|
-
|
|
5652
|
+
* wire sequences are already restored. `baseSsIds` holds, by ESI, the
|
|
5653
|
+
* base SS_IDs determined independently: a packet's release-gate anchor;
|
|
5654
|
+
* `firstSsIds` the lowest of them in its MPU (FrameMeta.fecSbnFirst). */
|
|
5655
|
+
overlay?: {
|
|
5656
|
+
deliveryProvenance: MmtpDeliveryProvenance;
|
|
5657
|
+
baseSsIds: ReadonlyMap<number, number>;
|
|
5658
|
+
firstSsIds: ReadonlyMap<number, number>;
|
|
5659
|
+
},
|
|
5130
5660
|
): void {
|
|
5131
5661
|
// Route recovered symbols to the track's callback. The ownerPacketId tells us
|
|
5132
5662
|
// which track this block belongs to — resolves per-track, then legacy fallback.
|
|
5133
5663
|
if (ownerPacketId == null) return; // no track association
|
|
5134
5664
|
if (this.#classifyPacketId(ownerPacketId) === null) return; // unknown track
|
|
5135
|
-
const fecSbnOf = (index: number): { fecSbn?: number } =>
|
|
5136
|
-
overlay
|
|
5665
|
+
const fecSbnOf = (index: number): { fecSbn?: number; fecSbnFirst?: number } => {
|
|
5666
|
+
if (!overlay) return { fecSbn: this.#fecAnchorForRecovered(blockId, index) };
|
|
5667
|
+
const fecSbn = overlay.baseSsIds.get(index);
|
|
5668
|
+
const fecSbnFirst = overlay.firstSsIds.get(index);
|
|
5669
|
+
return fecSbn === undefined || fecSbnFirst === undefined ? {} : { fecSbn, fecSbnFirst };
|
|
5670
|
+
};
|
|
5137
5671
|
// A recovered symbol's header names the sequence the sender protected. A
|
|
5138
5672
|
// hop that re-stamps packet_sequence_number after protection (cast's
|
|
5139
5673
|
// publisher-rotation bridge) leaves the decode mixing every received
|
|
@@ -5149,7 +5683,10 @@ export class MmtpRouter {
|
|
|
5149
5683
|
...result,
|
|
5150
5684
|
symbols: result.symbols.map((sym) => {
|
|
5151
5685
|
const wire = (this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset) >>> 0;
|
|
5152
|
-
if (wire === sym.packetSequenceNumber)
|
|
5686
|
+
if (wire === sym.packetSequenceNumber) {
|
|
5687
|
+
this.#unstampedSsIdSeqOffsetByStream.set(streamKey, ssIdSeqOffset);
|
|
5688
|
+
return sym;
|
|
5689
|
+
}
|
|
5153
5690
|
this.#restampedRecoveredSeqs++;
|
|
5154
5691
|
this.#restampedStreams.add(streamKey);
|
|
5155
5692
|
return { ...sym, packetSequenceNumber: wire };
|
|
@@ -5206,6 +5743,43 @@ export class MmtpRouter {
|
|
|
5206
5743
|
);
|
|
5207
5744
|
}
|
|
5208
5745
|
|
|
5746
|
+
// A recovered head whose sample FT=1 has not named yet (an overlay that
|
|
5747
|
+
// outran the source path) would complete its data unit untimed: the unit
|
|
5748
|
+
// is dropped, marked completed, and the timed source copy is then refused
|
|
5749
|
+
// (BLO-53342). Hand it to the parser instead, which holds it in its
|
|
5750
|
+
// awaiting-timing queue and feeds it again when FT=1 lands; its recovered
|
|
5751
|
+
// continuations park in the reassembler meanwhile. If the source path
|
|
5752
|
+
// lost the head, this held copy is the keyframe (BLO-53369).
|
|
5753
|
+
const untimedHead = (sym: (typeof result.symbols)[number]): boolean =>
|
|
5754
|
+
sym.fragmentType === 2 &&
|
|
5755
|
+
sym.fragment.fragmentationIndicator === 1 &&
|
|
5756
|
+
sym.fragment.movieFragmentSequenceNumber !== undefined &&
|
|
5757
|
+
sym.fragment.sampleNumber !== undefined &&
|
|
5758
|
+
!this.#parser.hasAuthoredTimingFor(
|
|
5759
|
+
ownerPacketId,
|
|
5760
|
+
sym.fragment.mpuSequenceNumber,
|
|
5761
|
+
sym.fragment.movieFragmentSequenceNumber,
|
|
5762
|
+
sym.fragment.sampleNumber,
|
|
5763
|
+
catalogTrackName,
|
|
5764
|
+
);
|
|
5765
|
+
for (const sym of result.symbols) {
|
|
5766
|
+
if (!untimedHead(sym) ||
|
|
5767
|
+
this.#sourceSeqReceived(ownerPacketId, sym.packetSequenceNumber, catalogTrackName)) continue;
|
|
5768
|
+
this.#feedViaParser(
|
|
5769
|
+
sym.rawSymbol,
|
|
5770
|
+
{ packetId: ownerPacketId, sequenceNumber: sym.packetSequenceNumber },
|
|
5771
|
+
undefined,
|
|
5772
|
+
{
|
|
5773
|
+
skipFecPayloadId: true,
|
|
5774
|
+
recovered: true,
|
|
5775
|
+
deliveryProvenance,
|
|
5776
|
+
...fecSbnOf(sym.index),
|
|
5777
|
+
...(catalogTrackName === undefined ? {} : { catalogTrackName }),
|
|
5778
|
+
},
|
|
5779
|
+
);
|
|
5780
|
+
}
|
|
5781
|
+
result = { ...result, symbols: result.symbols.filter((sym) => !untimedHead(sym)) };
|
|
5782
|
+
|
|
5209
5783
|
// MSE assembler path: route recovered block as pre-assembled frames (skip FT=0)
|
|
5210
5784
|
// BLO-3035 layer 3: recovered symbols are RAW MFU fragments, not complete
|
|
5211
5785
|
// frames. A keyframe can span multiple packets (FI=1/2/3); pushing each
|