@blockcast/mmt-container 0.4.0 → 0.4.1-main.22841c1f0a2d
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 +37 -21
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +2037 -881
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +13 -1
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +108 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +452 -66
- package/dist/fec-manager.js.map +4 -4
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/held-layer-admission.d.ts +58 -0
- package/dist/held-layer-admission.d.ts.map +1 -0
- package/dist/held-layer-admission.js +105 -0
- package/dist/held-layer-admission.js.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/mfu-reassembler.js +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +3677 -1213
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +192 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +640 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +69 -32
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +296 -192
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +313 -124
- package/dist/multicast-auth-catalog.js.map +3 -3
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +97 -11
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1022 -527
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +5 -3
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +3625 -1194
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -18
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +23 -1
- package/src/fec-manager.ts +366 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/held-layer-admission.ts +161 -0
- package/src/index.ts +32 -19
- package/src/iso-block-locator.ts +110 -7
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +606 -0
- package/src/mmtp-router.ts +301 -240
- package/src/multicast-auth-catalog.ts +134 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +271 -40
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +8 -7
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/sample-combiner.ts +15 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/dist/manifest-auth-plan.d.ts +0 -30
- package/dist/manifest-auth-plan.d.ts.map +0 -1
- package/dist/manifest-auth-plan.js +0 -1266
- package/dist/manifest-auth-plan.js.map +0 -7
- package/dist/source-auth.d.ts +0 -2
- package/dist/source-auth.d.ts.map +0 -1
- package/dist/source-auth.js +0 -1209
- package/dist/source-auth.js.map +0 -7
- package/src/fec-codec.ts +0 -61
- package/src/manifest-auth-plan.ts +0 -107
- package/src/source-auth.ts +0 -1
- package/test-vectors/generate-source-auth-fixture.mjs +0 -114
- package/test-vectors/source-auth-v1.json +0 -61
package/src/mmtp-router.ts
CHANGED
|
@@ -67,10 +67,8 @@ import {
|
|
|
67
67
|
type DuplicateHorizon,
|
|
68
68
|
} from "./duplicate-ledger.js";
|
|
69
69
|
import type {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
ManifestTrackContext,
|
|
73
|
-
ManifestVerifier,
|
|
70
|
+
BcProvenanceV2Receiver,
|
|
71
|
+
BcpV2RecordPath,
|
|
74
72
|
} from "@blockcast/mmt-manifest-verify";
|
|
75
73
|
|
|
76
74
|
// ─── Constants ─────────────────────────────────────────────────────
|
|
@@ -177,6 +175,12 @@ export type RoutedFrameMeta = {
|
|
|
177
175
|
|
|
178
176
|
export interface MmtpIngressContext {
|
|
179
177
|
tracks: readonly Readonly<{ name: string; packetId: number }>[];
|
|
178
|
+
/**
|
|
179
|
+
* The bc-provenance v2 flow (draft-ramadan-moq-multicast-01 7.2.7) that
|
|
180
|
+
* delivered the packet, when its endpoint is protected: the key a receiver
|
|
181
|
+
* was registered under with `registerProvenanceFlow`.
|
|
182
|
+
*/
|
|
183
|
+
flow?: string;
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
/** One physical stream: an MMTP packet ID and the catalog track it carries. */
|
|
@@ -435,10 +439,11 @@ export type RoutedPacketMeta = {
|
|
|
435
439
|
/**
|
|
436
440
|
* The MMTP header RAP flag: the packet starts a random access point. On a
|
|
437
441
|
* `recovered` packet it is read from the FEC-reconstructed header, which is
|
|
438
|
-
* byte-exact, so it is the flag the
|
|
439
|
-
* decisions deliberately ignore it for
|
|
440
|
-
* judges those by bitstream only); a host
|
|
441
|
-
* point should decide explicitly whether a
|
|
442
|
+
* byte-exact outside packet_sequence_number, so it is the flag the
|
|
443
|
+
* publisher sent. The router's own gap decisions deliberately ignore it for
|
|
444
|
+
* recovered frames (`#isRapForGap` judges those by bitstream only); a host
|
|
445
|
+
* using it as a tier-switch commit point should decide explicitly whether a
|
|
446
|
+
* recovered RAP qualifies.
|
|
442
447
|
*/
|
|
443
448
|
rap: boolean;
|
|
444
449
|
/** True when FEC reconstructed this source packet. */
|
|
@@ -560,6 +565,27 @@ export interface FECManagerLike {
|
|
|
560
565
|
/** A block's RSB_length, from one of its repair symbols (optional). */
|
|
561
566
|
noteRepairGroupLength?(sbn: number, packetId: number, rsbLength: number, catalogTrackName?: string): void;
|
|
562
567
|
|
|
568
|
+
/** fec-01 4.5: refuse a repair header whose block length the track's scheme
|
|
569
|
+
* forbids, before it touches block state (optional). */
|
|
570
|
+
admitRepairBlockLength?(packetId: number, ssbLength: number, rsbLength: number, rsId: number): boolean;
|
|
571
|
+
admitRepairLayerTotal?(
|
|
572
|
+
packetId: number,
|
|
573
|
+
catalogTrackName: string | undefined,
|
|
574
|
+
repairTrackName: string | undefined,
|
|
575
|
+
ssStart: number,
|
|
576
|
+
rsbLength: number,
|
|
577
|
+
): boolean;
|
|
578
|
+
|
|
579
|
+
/** Validate a repair symbol's size before it touches block state; counts a
|
|
580
|
+
* mismatch on `repairSymbolSizeMismatches` (optional). */
|
|
581
|
+
admitRepairSymbolSize?(
|
|
582
|
+
packetId: number,
|
|
583
|
+
ssStart: number,
|
|
584
|
+
ssbLength: number,
|
|
585
|
+
rsId: number,
|
|
586
|
+
byteLength: number,
|
|
587
|
+
): boolean;
|
|
588
|
+
|
|
563
589
|
/** Feed a repair symbol to the FEC decoder for a given track.
|
|
564
590
|
* Returns recovered block bytes if recovery completes, else null. */
|
|
565
591
|
feedRepairSymbol(
|
|
@@ -695,6 +721,13 @@ export interface FECManagerLike {
|
|
|
695
721
|
ssStart: number,
|
|
696
722
|
ssbLength: number,
|
|
697
723
|
): IsoRepairPlacement<IsoHeldSource>;
|
|
724
|
+
/** iso-ssbg1-v1: turn the pending holes in a range into spans, with the sources they place. */
|
|
725
|
+
closeIsoHoles?(
|
|
726
|
+
packetId: number,
|
|
727
|
+
catalogTrackName: string | undefined,
|
|
728
|
+
start: number,
|
|
729
|
+
length: number,
|
|
730
|
+
): readonly { readonly block: { readonly start: number }; readonly placed: readonly IsoPlacedSource<IsoHeldSource>[] }[];
|
|
698
731
|
/** iso-ssbg1-v1: resolution of the SS_IDs strictly between two released frames. */
|
|
699
732
|
isoSpanResolution?(
|
|
700
733
|
packetId: number,
|
|
@@ -775,26 +808,6 @@ export interface FECManagerLike {
|
|
|
775
808
|
|
|
776
809
|
// ─── MmtpRouter ─────────────────────────────────────────────────────
|
|
777
810
|
|
|
778
|
-
export interface ManifestIdentityResolutionInput {
|
|
779
|
-
packetId: number;
|
|
780
|
-
sbn: number;
|
|
781
|
-
esi: number;
|
|
782
|
-
/**
|
|
783
|
-
* The packet's SS_ID and its MPU's mpu_sequence_number. Under
|
|
784
|
-
* iso-ssbg1-v1 blocks vary in length, so a packet's media group comes from
|
|
785
|
-
* its own MPU header, never from SBN arithmetic (BLO-35597 D2a).
|
|
786
|
-
*/
|
|
787
|
-
ssId?: number;
|
|
788
|
-
mpuSequenceNumber?: number;
|
|
789
|
-
catalogTrackName?: string;
|
|
790
|
-
recovered: boolean;
|
|
791
|
-
sourceSymbolFormat: "full-mmtp-packet" | "fec-padded-recovery";
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
export type ManifestIdentityResolver = (
|
|
795
|
-
input: ManifestIdentityResolutionInput,
|
|
796
|
-
) => ManifestObjectIdentity | null;
|
|
797
|
-
|
|
798
811
|
/**
|
|
799
812
|
* Classification evidence carried by one first-arrival network source
|
|
800
813
|
* packet: the MMTP header R bit and the MPU / data-unit identity it states
|
|
@@ -831,26 +844,17 @@ export class MmtpRouter {
|
|
|
831
844
|
readonly #fecManager: FECManagerLike | null;
|
|
832
845
|
#defaultFecMapper: FecBlockMapper | null;
|
|
833
846
|
#fecMappersByPacketId = new Map<number, FecBlockMapper>();
|
|
834
|
-
|
|
835
|
-
readonly #
|
|
836
|
-
readonly #resolveManifestIdentity:
|
|
837
|
-
| ((
|
|
838
|
-
packetId: number,
|
|
839
|
-
sbn: number,
|
|
840
|
-
esi: number,
|
|
841
|
-
catalogTrackName?: string,
|
|
842
|
-
) => ManifestObjectIdentity | null)
|
|
843
|
-
| null;
|
|
844
|
-
readonly #resolveManifestIdentityForRoute: ManifestIdentityResolver | null;
|
|
845
|
-
#manifestRecoveryQueues = new Map<
|
|
847
|
+
/** Protected flows: one 7.2.7 receiver each, and the ingress its datagrams arrive with. */
|
|
848
|
+
readonly #provenance = new Map<
|
|
846
849
|
string,
|
|
847
|
-
|
|
848
|
-
blockId: number;
|
|
849
|
-
result: ProcessFecBlockResult;
|
|
850
|
-
ownerPacketId: number;
|
|
851
|
-
catalogTrackName?: string;
|
|
852
|
-
}>
|
|
850
|
+
{ receiver: BcProvenanceV2Receiver; ingress: MmtpIngressContext }
|
|
853
851
|
>();
|
|
852
|
+
/** The ingress a held datagram arrived with; the receiver returns the same bytes on release. */
|
|
853
|
+
readonly #heldIngress = new WeakMap<Uint8Array, MmtpIngressContext>();
|
|
854
|
+
/** The flow whose receiver admitted a stream's source datagrams, by packetId then catalog track name: recovered packets answer to it. */
|
|
855
|
+
readonly #provenanceStreamFlow = new Map<number, Map<string | undefined, string>>();
|
|
856
|
+
#unregisteredFlowDrops = 0;
|
|
857
|
+
#ambiguousRecoveredDrops = 0;
|
|
854
858
|
|
|
855
859
|
// Temp state set by #processMMTP before calling parser.feed(),
|
|
856
860
|
// read by the parser's onFrame callback for CMAF assembly + dedup.
|
|
@@ -896,6 +900,18 @@ export class MmtpRouter {
|
|
|
896
900
|
// MSE recovery routes through CmafBlockAssembler and can reorder by block; the
|
|
897
901
|
// direct callback path has to preserve decode order before frames leave libmmt.
|
|
898
902
|
#latestVideoSeqByStream = new Map<string, number>();
|
|
903
|
+
/**
|
|
904
|
+
* Per stream, SS_ID - packet_sequence_number (mod 2^32) of its latest
|
|
905
|
+
* first-arrival FEC source packet. A recovered source symbol's wire
|
|
906
|
+
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
907
|
+
*/
|
|
908
|
+
#ssIdSeqOffsetByStream = new Map<string, number>();
|
|
909
|
+
/**
|
|
910
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
911
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
912
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
913
|
+
*/
|
|
914
|
+
#multicastRapTwinByStream = new Set<string>();
|
|
899
915
|
#lastDirectSourceVideoTsByStream = new Map<string, number>();
|
|
900
916
|
#lastDirectEmittedVideoTsByStream = new Map<string, number>();
|
|
901
917
|
#pendingDirectRecoveredVideoByStream = new Map<string, Map<string, PendingRecoveredVideoFrame>>();
|
|
@@ -988,11 +1004,14 @@ export class MmtpRouter {
|
|
|
988
1004
|
*/
|
|
989
1005
|
#onPublisherRestart: ((packetId: number, catalogTrackName: string) => void) | null;
|
|
990
1006
|
#publisherRestarts = 0;
|
|
1007
|
+
#restampedRecoveredSeqs = 0;
|
|
991
1008
|
/** Inits delivered with no onTrackInit handler for their packetId (MOQT-01). */
|
|
992
1009
|
#unmappedInitDeliveries = 0;
|
|
993
1010
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
994
1011
|
// configured fec.blockProfile (see #noteUnreadableFecPayloadId).
|
|
995
1012
|
#fecPayloadIdsWithoutProfile = 0;
|
|
1013
|
+
// Repair packets discarded by the fec-01 4.5 block-length rule.
|
|
1014
|
+
#repairBlockLengthDiscards = 0;
|
|
996
1015
|
|
|
997
1016
|
/** The staged in-place stream switch, if any (stageStreamSwitch). */
|
|
998
1017
|
#staged: StreamSwitchState | null = null;
|
|
@@ -1012,16 +1031,6 @@ export class MmtpRouter {
|
|
|
1012
1031
|
* Pass a reader when its inputs are measured later; see
|
|
1013
1032
|
* setKeyframeLostTimeoutMs. */
|
|
1014
1033
|
keyframeLostTimeoutMs?: number | (() => number);
|
|
1015
|
-
manifestVerifier?: ManifestVerifier;
|
|
1016
|
-
/** Existing behavior is router ownership; shared browser plans opt into caller ownership. */
|
|
1017
|
-
manifestVerifierOwnership?: "caller" | "router";
|
|
1018
|
-
resolveManifestIdentity?: (
|
|
1019
|
-
packetId: number,
|
|
1020
|
-
sbn: number,
|
|
1021
|
-
esi: number,
|
|
1022
|
-
catalogTrackName?: string,
|
|
1023
|
-
) => ManifestObjectIdentity | null;
|
|
1024
|
-
resolveManifestIdentityForRoute?: ManifestIdentityResolver;
|
|
1025
1034
|
/** Internal terminal-failure sink owned by the composing transport. */
|
|
1026
1035
|
onBlockFailed?: (
|
|
1027
1036
|
sbn: number,
|
|
@@ -1044,10 +1053,6 @@ export class MmtpRouter {
|
|
|
1044
1053
|
this.#fecManager = config?.fecManager ?? null;
|
|
1045
1054
|
this.#onFrameGap = config?.onFrameGap ?? null;
|
|
1046
1055
|
this.#defaultFecMapper = config?.fecMapper ?? null;
|
|
1047
|
-
this.#manifestVerifier = config?.manifestVerifier ?? null;
|
|
1048
|
-
this.#ownsManifestVerifier = config?.manifestVerifierOwnership !== "caller";
|
|
1049
|
-
this.#resolveManifestIdentity = config?.resolveManifestIdentity ?? null;
|
|
1050
|
-
this.#resolveManifestIdentityForRoute = config?.resolveManifestIdentityForRoute ?? null;
|
|
1051
1056
|
|
|
1052
1057
|
// Create MMTP parser — handles MFU extraction, reassembly, keyframe detection.
|
|
1053
1058
|
// Its MFUReassembler is the single reassembler for BOTH the source path
|
|
@@ -1119,6 +1124,19 @@ export class MmtpRouter {
|
|
|
1119
1124
|
: { catalogTrackName: meta.catalogTrackName }),
|
|
1120
1125
|
};
|
|
1121
1126
|
if (meta.source) frameMeta.source = meta.source;
|
|
1127
|
+
// During make-before-break the overlap copy usually wins the parse ledger,
|
|
1128
|
+
// so almost every frame is head-attributed to "moq" and multicast takeover
|
|
1129
|
+
// waited on a rare multicast-won keyframe (BLO-49179: 34 s, 38 s, or past
|
|
1130
|
+
// the 30 s window). A RAP whose multicast twin the ledger dropped is
|
|
1131
|
+
// multicast delivering keyframes, so the next keyframe routes as multicast:
|
|
1132
|
+
// this one if the twin beat its tail, else at most one GOP later.
|
|
1133
|
+
// deliveryProvenance is unchanged and stays 'mixed'.
|
|
1134
|
+
if (isVideo && frameMeta.keyframe) {
|
|
1135
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
1136
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName),
|
|
1137
|
+
);
|
|
1138
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
1139
|
+
}
|
|
1122
1140
|
// Forward whenever present, not when truthy: 'unknown' is a verdict the
|
|
1123
1141
|
// parser reached, not a value to drop.
|
|
1124
1142
|
if (meta.deliveryProvenance !== undefined)
|
|
@@ -1364,6 +1382,15 @@ export class MmtpRouter {
|
|
|
1364
1382
|
return this.#publisherRestarts;
|
|
1365
1383
|
}
|
|
1366
1384
|
|
|
1385
|
+
/**
|
|
1386
|
+
* FEC-recovered source symbols whose reconstructed header named a
|
|
1387
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to:
|
|
1388
|
+
* a hop re-stamped the sequence after the sender protected the packet.
|
|
1389
|
+
*/
|
|
1390
|
+
get restampedRecoveredSequenceCount(): number {
|
|
1391
|
+
return this.#restampedRecoveredSeqs;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1367
1394
|
/**
|
|
1368
1395
|
* Packets whose Source or Repair FEC Payload ID was left unread because
|
|
1369
1396
|
* their (owner) packetId had no configured `fec.blockProfile`: FEC not
|
|
@@ -1376,6 +1403,15 @@ export class MmtpRouter {
|
|
|
1376
1403
|
return this.#fecPayloadIdsWithoutProfile;
|
|
1377
1404
|
}
|
|
1378
1405
|
|
|
1406
|
+
/**
|
|
1407
|
+
* Repair packets discarded at admission by the fec-01 4.5 rule (RS_ID not
|
|
1408
|
+
* below RSB_length, or a reed-solomon SSB_length + RSB_length above 255),
|
|
1409
|
+
* before they touched any block state.
|
|
1410
|
+
*/
|
|
1411
|
+
get repairBlockLengthDiscards(): number {
|
|
1412
|
+
return this.#repairBlockLengthDiscards;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1379
1415
|
get reassembler(): MfuReassemblerBackend {
|
|
1380
1416
|
return this.#parser.reassembler;
|
|
1381
1417
|
}
|
|
@@ -1747,32 +1783,59 @@ export class MmtpRouter {
|
|
|
1747
1783
|
});
|
|
1748
1784
|
}
|
|
1749
1785
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1786
|
+
/**
|
|
1787
|
+
* Protect a flow (draft-ramadan-moq-multicast-01 7.2.7): every multicast
|
|
1788
|
+
* datagram whose ingress names `ingress.flow`, source and repair alike, is
|
|
1789
|
+
* admitted by `receiver` before anything reads it, and an unadmitted one is
|
|
1790
|
+
* held or dropped. The caller owns the receiver's configuration; the router
|
|
1791
|
+
* releases it on `releaseProvenanceFlow` and on dispose.
|
|
1792
|
+
*/
|
|
1793
|
+
registerProvenanceFlow(
|
|
1794
|
+
ingress: MmtpIngressContext & { flow: string },
|
|
1795
|
+
receiver: BcProvenanceV2Receiver,
|
|
1796
|
+
): void {
|
|
1797
|
+
this.#provenance.get(ingress.flow)?.receiver.release();
|
|
1798
|
+
this.#provenance.set(ingress.flow, { receiver, ingress });
|
|
1753
1799
|
}
|
|
1754
1800
|
|
|
1755
|
-
|
|
1756
|
-
|
|
1801
|
+
/**
|
|
1802
|
+
* Feed one bc-provenance record of `flow`: a datagram from `manifestPort`
|
|
1803
|
+
* (`multicast`) or an object of the manifest track (`mirror`). Held
|
|
1804
|
+
* datagrams the record admits are routed before this returns.
|
|
1805
|
+
*/
|
|
1806
|
+
feedProvenanceRecord(flow: string, record: Uint8Array, path: BcpV2RecordPath): string {
|
|
1807
|
+
const entry = this.#provenance.get(flow);
|
|
1808
|
+
if (!entry || this.#disposed) return "unregistered";
|
|
1809
|
+
const result = entry.receiver.onRecord(record, path);
|
|
1810
|
+
if (result.admitted.length > 0) {
|
|
1811
|
+
this.#withDeferredFecPokes(() => {
|
|
1812
|
+
for (const datagram of result.admitted) {
|
|
1813
|
+
this.#processMMTP(datagram, "multicast", true, this.#heldIngress.get(datagram) ?? entry.ingress, false, true);
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
return result.verdict;
|
|
1757
1818
|
}
|
|
1758
1819
|
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
item.blockId,
|
|
1766
|
-
item.result,
|
|
1767
|
-
item.ownerPacketId,
|
|
1768
|
-
item.catalogTrackName,
|
|
1769
|
-
);
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
this.#manifestRecoveryQueues.clear();
|
|
1820
|
+
/** The receiver ceased to hold the flow: its hold queues are dropped, not expired. */
|
|
1821
|
+
releaseProvenanceFlow(flow: string): void {
|
|
1822
|
+
this.#provenance.get(flow)?.receiver.release();
|
|
1823
|
+
this.#provenance.delete(flow);
|
|
1824
|
+
for (const byName of this.#provenanceStreamFlow.values()) {
|
|
1825
|
+
for (const [name, bound] of byName) if (bound === flow) byName.delete(name);
|
|
1773
1826
|
}
|
|
1774
1827
|
}
|
|
1775
1828
|
|
|
1829
|
+
/** Multicast datagrams dropped because their ingress names a flow with no registered receiver. */
|
|
1830
|
+
get unregisteredFlowDropCount(): number {
|
|
1831
|
+
return this.#unregisteredFlowDrops;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
/** Recovered packets dropped because more than one protected flow could own their stream. */
|
|
1835
|
+
get ambiguousRecoveredDropCount(): number {
|
|
1836
|
+
return this.#ambiguousRecoveredDrops;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1776
1839
|
/**
|
|
1777
1840
|
* Main entry point: feed a raw MMTP packet for processing.
|
|
1778
1841
|
*
|
|
@@ -1790,12 +1853,11 @@ export class MmtpRouter {
|
|
|
1790
1853
|
feedPacket(
|
|
1791
1854
|
packet: Uint8Array,
|
|
1792
1855
|
source: "multicast" | "moq",
|
|
1793
|
-
manifestIdentity?: ManifestObjectIdentity,
|
|
1794
1856
|
ingress?: MmtpIngressContext,
|
|
1795
1857
|
): void {
|
|
1796
1858
|
if (this.#disposed) return;
|
|
1797
1859
|
this.#withDeferredFecPokes(() => {
|
|
1798
|
-
this.#processMMTP(packet, source,
|
|
1860
|
+
this.#processMMTP(packet, source, false, ingress);
|
|
1799
1861
|
});
|
|
1800
1862
|
}
|
|
1801
1863
|
|
|
@@ -1831,7 +1893,7 @@ export class MmtpRouter {
|
|
|
1831
1893
|
feedOverlapCopy(packet: Uint8Array, ingress?: MmtpIngressContext): void {
|
|
1832
1894
|
if (this.#disposed) return;
|
|
1833
1895
|
this.#withDeferredFecPokes(() => {
|
|
1834
|
-
this.#processMMTP(packet, "moq",
|
|
1896
|
+
this.#processMMTP(packet, "moq", false, ingress, true);
|
|
1835
1897
|
});
|
|
1836
1898
|
}
|
|
1837
1899
|
|
|
@@ -1843,10 +1905,11 @@ export class MmtpRouter {
|
|
|
1843
1905
|
packet: Uint8Array,
|
|
1844
1906
|
ownerPacketIdHint?: number,
|
|
1845
1907
|
catalogTrackName?: string,
|
|
1908
|
+
repairTrackName?: string,
|
|
1846
1909
|
): void {
|
|
1847
1910
|
if (this.#disposed) return;
|
|
1848
1911
|
this.#withDeferredFecPokes(() => {
|
|
1849
|
-
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName);
|
|
1912
|
+
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
|
|
1850
1913
|
});
|
|
1851
1914
|
}
|
|
1852
1915
|
|
|
@@ -1854,6 +1917,7 @@ export class MmtpRouter {
|
|
|
1854
1917
|
packet: Uint8Array,
|
|
1855
1918
|
ownerPacketIdHint: number | undefined,
|
|
1856
1919
|
catalogTrackName: string | undefined,
|
|
1920
|
+
repairTrackName: string | undefined,
|
|
1857
1921
|
): void {
|
|
1858
1922
|
// One header parse per packet, as on the multicast repair branch: mmt-fec's
|
|
1859
1923
|
// parseRepairPacket() parsed it once more before this parse (BLO-36599).
|
|
@@ -1901,7 +1965,7 @@ export class MmtpRouter {
|
|
|
1901
1965
|
this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
|
|
1902
1966
|
return;
|
|
1903
1967
|
}
|
|
1904
|
-
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq");
|
|
1968
|
+
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
|
|
1905
1969
|
}
|
|
1906
1970
|
}
|
|
1907
1971
|
|
|
@@ -2007,6 +2071,7 @@ export class MmtpRouter {
|
|
|
2007
2071
|
catalogTrackName: string | undefined,
|
|
2008
2072
|
repair: { ssStart: number; ssbLength: number; rsbLength: number; rsId: number; symbolData: Uint8Array },
|
|
2009
2073
|
source: "multicast" | "moq",
|
|
2074
|
+
repairTrackName?: string,
|
|
2010
2075
|
): void {
|
|
2011
2076
|
const fec = this.#fecManager;
|
|
2012
2077
|
if (!fec?.placeIsoRepair) {
|
|
@@ -2014,6 +2079,33 @@ export class MmtpRouter {
|
|
|
2014
2079
|
`[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`,
|
|
2015
2080
|
);
|
|
2016
2081
|
}
|
|
2082
|
+
// fec-01 4.5: a reed-solomon block-length violation is discarded with the
|
|
2083
|
+
// block state unchanged, so it runs before any other admission.
|
|
2084
|
+
if (
|
|
2085
|
+
fec.admitRepairBlockLength &&
|
|
2086
|
+
!fec.admitRepairBlockLength(ownerPacketId, repair.ssbLength, repair.rsbLength, repair.rsId)
|
|
2087
|
+
) {
|
|
2088
|
+
this.#repairBlockLengthDiscards++;
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
// A repair symbol that is not exactly T bytes is invalid: refuse it before
|
|
2092
|
+
// it can place a block or be swallowed by dedup, so it is always counted
|
|
2093
|
+
// and never reaches the decoder (BLO-48306).
|
|
2094
|
+
if (
|
|
2095
|
+
fec.admitRepairSymbolSize &&
|
|
2096
|
+
!fec.admitRepairSymbolSize(
|
|
2097
|
+
ownerPacketId,
|
|
2098
|
+
repair.ssStart,
|
|
2099
|
+
repair.ssbLength,
|
|
2100
|
+
repair.rsId,
|
|
2101
|
+
repair.symbolData.byteLength,
|
|
2102
|
+
)
|
|
2103
|
+
) return;
|
|
2104
|
+
// fec-01 6.3.9: a held layer's total below its anchor fails the track's FEC closed.
|
|
2105
|
+
if (
|
|
2106
|
+
fec.admitRepairLayerTotal &&
|
|
2107
|
+
!fec.admitRepairLayerTotal(ownerPacketId, catalogTrackName, repairTrackName, repair.ssStart, repair.rsbLength)
|
|
2108
|
+
) return;
|
|
2017
2109
|
const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
|
|
2018
2110
|
if (placement.status !== "placed") return;
|
|
2019
2111
|
const blockStart = placement.block.start;
|
|
@@ -2049,6 +2141,23 @@ export class MmtpRouter {
|
|
|
2049
2141
|
}
|
|
2050
2142
|
}
|
|
2051
2143
|
|
|
2144
|
+
/**
|
|
2145
|
+
* The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
|
|
2146
|
+
* §7.5): what no repair stated becomes repair-less spans, whose held sources
|
|
2147
|
+
* are fed exactly as a span a repair closed.
|
|
2148
|
+
*/
|
|
2149
|
+
closeIsoHoles(
|
|
2150
|
+
ownerPacketId: number,
|
|
2151
|
+
catalogTrackName: string | undefined,
|
|
2152
|
+
start: number,
|
|
2153
|
+
length: number,
|
|
2154
|
+
): void {
|
|
2155
|
+
const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
|
|
2156
|
+
for (const span of spans) {
|
|
2157
|
+
this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2052
2161
|
/**
|
|
2053
2162
|
* Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
|
|
2054
2163
|
* a first-arrival source is fed once its block is known: transport
|
|
@@ -2180,13 +2289,14 @@ export class MmtpRouter {
|
|
|
2180
2289
|
this.#trackSynced.delete(streamKey);
|
|
2181
2290
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
2182
2291
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
2292
|
+
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
2293
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
2183
2294
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
2184
2295
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
2185
2296
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
2186
2297
|
this.#lastDirectSourceAudioCursorByStream.delete(streamKey);
|
|
2187
2298
|
this.#lastDirectEmittedAudioCursorByStream.delete(streamKey);
|
|
2188
2299
|
this.#pendingDirectRecoveredAudioByStream.delete(streamKey);
|
|
2189
|
-
this.#manifestRecoveryQueues.delete(streamKey);
|
|
2190
2300
|
this.#deliveredVideoHighWaterByStream.delete(streamKey);
|
|
2191
2301
|
this.#stream(packetId, catalogTrackName).duplicates.clear();
|
|
2192
2302
|
const assemblersToReset = new Set<CmafBlockAssembler>();
|
|
@@ -2238,7 +2348,6 @@ export class MmtpRouter {
|
|
|
2238
2348
|
this.#lastDirectSourceAudioCursorByStream.delete(key);
|
|
2239
2349
|
this.#lastDirectEmittedAudioCursorByStream.delete(key);
|
|
2240
2350
|
this.#pendingDirectRecoveredAudioByStream.delete(key);
|
|
2241
|
-
this.#manifestRecoveryQueues.delete(key);
|
|
2242
2351
|
this.#trackInitDelivered.delete(key);
|
|
2243
2352
|
this.#parserDiagnostics.delete(key);
|
|
2244
2353
|
this.#pendingFecPokes.delete(key);
|
|
@@ -2534,8 +2643,9 @@ export class MmtpRouter {
|
|
|
2534
2643
|
this.#parserDiagnostics.clear();
|
|
2535
2644
|
this.#catalogTrackNamesByPacketId.clear();
|
|
2536
2645
|
this.#repairOwnersByPacketId.clear();
|
|
2537
|
-
|
|
2538
|
-
this.#
|
|
2646
|
+
for (const { receiver } of this.#provenance.values()) receiver.release();
|
|
2647
|
+
this.#provenance.clear();
|
|
2648
|
+
this.#provenanceStreamFlow.clear();
|
|
2539
2649
|
for (const assembler of this.#mseAssemblers.values()) assembler.dispose();
|
|
2540
2650
|
this.#mseAssemblers.clear();
|
|
2541
2651
|
}
|
|
@@ -2889,7 +2999,6 @@ export class MmtpRouter {
|
|
|
2889
2999
|
#processMMTP(
|
|
2890
3000
|
packet: Uint8Array,
|
|
2891
3001
|
source: "multicast" | "moq",
|
|
2892
|
-
manifestIdentity?: ManifestObjectIdentity,
|
|
2893
3002
|
manifestAdmitted = false,
|
|
2894
3003
|
ingress?: MmtpIngressContext,
|
|
2895
3004
|
overlapCopy = false,
|
|
@@ -2938,59 +3047,28 @@ export class MmtpRouter {
|
|
|
2938
3047
|
this.#classifyPacketId(info.packetId) !== null &&
|
|
2939
3048
|
this.#configuredBlockProfile(info.packetId) === undefined;
|
|
2940
3049
|
if (fecUnreadable && !manifestAdmitted) this.#noteUnreadableFecPayloadId(info.packetId, "source");
|
|
3050
|
+
if (source === "multicast" && manifestAdmitted && !info.isRepair && ingress?.flow !== undefined) {
|
|
3051
|
+
let byName = this.#provenanceStreamFlow.get(info.packetId);
|
|
3052
|
+
if (!byName) this.#provenanceStreamFlow.set(info.packetId, (byName = new Map()));
|
|
3053
|
+
byName.set(catalogTrackNameForPacket(ingress, info.packetId), ingress.flow);
|
|
3054
|
+
}
|
|
2941
3055
|
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
const coordinates = this.#locateFecSource(info.packetId, catalogTrackName, info.fecPayloadId.ssId);
|
|
2952
|
-
identity = coordinates === null ? undefined : (this.#resolveManifestIdentityForRoute
|
|
2953
|
-
? this.#resolveManifestIdentityForRoute({
|
|
2954
|
-
packetId: info.packetId,
|
|
2955
|
-
sbn: coordinates.sbn,
|
|
2956
|
-
esi: coordinates.esi,
|
|
2957
|
-
...(catalogTrackName === undefined ? {} : { catalogTrackName }),
|
|
2958
|
-
recovered: false,
|
|
2959
|
-
sourceSymbolFormat: "full-mmtp-packet",
|
|
2960
|
-
})
|
|
2961
|
-
: this.#resolveManifestIdentity!(
|
|
2962
|
-
info.packetId,
|
|
2963
|
-
coordinates.sbn,
|
|
2964
|
-
coordinates.esi,
|
|
2965
|
-
catalogTrackName,
|
|
2966
|
-
)) ?? undefined;
|
|
2967
|
-
}
|
|
2968
|
-
if (identity) {
|
|
2969
|
-
identity = {
|
|
2970
|
-
...identity,
|
|
2971
|
-
packetId: info.packetId,
|
|
2972
|
-
...(info.fecPayloadId ? { ssId: info.fecPayloadId.ssId } : {}),
|
|
2973
|
-
};
|
|
2974
|
-
const authenticated = info.fecPayloadId ? packet.subarray(0, packet.length - 4) : packet;
|
|
2975
|
-
// A `stall` admission quarantines the packet and releases it later,
|
|
2976
|
-
// after the stream has moved on; a synchronous release happens inside
|
|
2977
|
-
// admitObject, before this flag is set.
|
|
2978
|
-
let quarantined = false;
|
|
2979
|
-
const admission = this.#manifestVerifier.admitObject(identity, authenticated, () => {
|
|
2980
|
-
if (!this.#disposed) {
|
|
2981
|
-
this.#processMMTP(packet, source, identity, true, ingress, overlapCopy, quarantined);
|
|
2982
|
-
}
|
|
2983
|
-
});
|
|
2984
|
-
quarantined = admission.action === "stall";
|
|
2985
|
-
return;
|
|
2986
|
-
}
|
|
2987
|
-
if (
|
|
2988
|
-
this.#manifestVerifier.config.mode === "enforce" &&
|
|
2989
|
-
this.#manifestVerifier.config.onMissingManifest === "stall"
|
|
2990
|
-
) {
|
|
2991
|
-
console.warn(`[MmtpRouter] manifest identity absent; stalling packetId=${info.packetId}`);
|
|
3056
|
+
// A protected flow admits every datagram, repair included, before it is
|
|
3057
|
+
// read (7.2.7): an unadmitted repair symbol never reaches the decoder.
|
|
3058
|
+
if (source === "multicast" && !manifestAdmitted && ingress?.flow !== undefined) {
|
|
3059
|
+
const protectedFlow = this.#provenance.get(ingress.flow);
|
|
3060
|
+
// Named but not registered (before registration, after release): the
|
|
3061
|
+
// flow is protected, so nothing admits this datagram. Fail closed.
|
|
3062
|
+
if (!protectedFlow) {
|
|
3063
|
+
this.#unregisteredFlowDrops++;
|
|
3064
|
+
debugRouter(`[MmtpRouter] Dropping multicast packet pid=${info.packetId}: flow ${ingress.flow} has no receiver`);
|
|
2992
3065
|
return;
|
|
2993
3066
|
}
|
|
3067
|
+
// Held: released by a record (feedProvenanceRecord) or expired. Duplicate / overflow: dropped.
|
|
3068
|
+
const { verdict } = protectedFlow.receiver.onDatagram(packet, "multicast");
|
|
3069
|
+
if (verdict === "admitted") this.#processMMTP(packet, source, true, ingress, overlapCopy);
|
|
3070
|
+
else if (verdict === "held") this.#heldIngress.set(packet, ingress!);
|
|
3071
|
+
return;
|
|
2994
3072
|
}
|
|
2995
3073
|
|
|
2996
3074
|
if (info.isRepair) {
|
|
@@ -3079,8 +3157,8 @@ export class MmtpRouter {
|
|
|
3079
3157
|
// Start a fresh epoch for the stream before this packet is looked up.
|
|
3080
3158
|
// The reset needs the catalog identity, so a stream without one is not
|
|
3081
3159
|
// checked; an overlap copy is MoQ bytes and says nothing about the
|
|
3082
|
-
// multicast publisher, and neither does a packet
|
|
3083
|
-
//
|
|
3160
|
+
// multicast publisher, and neither does a packet a provenance hold queue
|
|
3161
|
+
// released: it predates the horizon because it waited, not because the
|
|
3084
3162
|
// publisher restarted.
|
|
3085
3163
|
if (
|
|
3086
3164
|
source === "multicast" &&
|
|
@@ -3205,6 +3283,13 @@ export class MmtpRouter {
|
|
|
3205
3283
|
parseSourceSymbol = !duplicates.parsedSymbols.has(info.fecPayloadId.ssId);
|
|
3206
3284
|
}
|
|
3207
3285
|
|
|
3286
|
+
if (fecPayloadId && !overlapCopy) {
|
|
3287
|
+
this.#ssIdSeqOffsetByStream.set(
|
|
3288
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
3289
|
+
(fecPayloadId.ssId - info.sequenceNumber) >>> 0,
|
|
3290
|
+
);
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3208
3293
|
// Parse only the first copy of an FEC source symbol. A late direct copy
|
|
3209
3294
|
// of a worker-recovered fragment has the same SBN/ESI and fragment
|
|
3210
3295
|
// counter; feeding it again can make the MFU buffer non-contiguous even
|
|
@@ -3231,6 +3316,11 @@ export class MmtpRouter {
|
|
|
3231
3316
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
3232
3317
|
...(fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}),
|
|
3233
3318
|
}, parsed);
|
|
3319
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
3320
|
+
// Usually the twin of a RAP its overlap copy already parsed.
|
|
3321
|
+
this.#multicastRapTwinByStream.add(
|
|
3322
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
3323
|
+
);
|
|
3234
3324
|
}
|
|
3235
3325
|
// The frame this packet completed can commit an in-place switch that
|
|
3236
3326
|
// retires this very packet ID. Its FEC state is gone then, and feeding
|
|
@@ -3959,115 +4049,63 @@ export class MmtpRouter {
|
|
|
3959
4049
|
this.#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
|
|
3960
4050
|
}
|
|
3961
4051
|
|
|
4052
|
+
/**
|
|
4053
|
+
* A recovered source packet of a protected flow is admitted on its own
|
|
4054
|
+
* digest: its bytes with the SS_ID it was sent with (SS_Start + ESI)
|
|
4055
|
+
* appended are the datagram the record listed (7.2.7). One that no record
|
|
4056
|
+
* lists is dropped; holding it would let it out later as a multicast arrival.
|
|
4057
|
+
*/
|
|
3962
4058
|
#routeVerifiedFecSymbols(
|
|
3963
4059
|
blockId: number,
|
|
3964
4060
|
result: ProcessFecBlockResult,
|
|
3965
4061
|
ownerPacketId?: number,
|
|
3966
4062
|
catalogTrackName?: string,
|
|
3967
4063
|
): void {
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
if (
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
4064
|
+
const receiver = ownerPacketId == null ? undefined : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
4065
|
+
if (receiver === "ambiguous") {
|
|
4066
|
+
this.#ambiguousRecoveredDrops += result.symbols.length;
|
|
4067
|
+
result = { ...result, symbols: [] };
|
|
4068
|
+
} else if (receiver) {
|
|
4069
|
+
result = {
|
|
4070
|
+
...result,
|
|
4071
|
+
symbols: result.symbols.filter((sym) => {
|
|
4072
|
+
const wire = new Uint8Array(sym.rawSymbol.byteLength + 4);
|
|
4073
|
+
wire.set(sym.rawSymbol);
|
|
4074
|
+
new DataView(wire.buffer).setUint32(sym.rawSymbol.byteLength, this.#fecAnchorForRecovered(blockId, sym.index));
|
|
4075
|
+
return receiver.admitRecovered(wire);
|
|
4076
|
+
}),
|
|
4077
|
+
};
|
|
3976
4078
|
}
|
|
3977
|
-
|
|
3978
|
-
const queue = this.#manifestRecoveryQueues.get(queueKey) ?? [];
|
|
3979
|
-
queue.push({ blockId, result, ownerPacketId, catalogTrackName });
|
|
3980
|
-
this.#manifestRecoveryQueues.set(queueKey, queue);
|
|
3981
|
-
if (queue.length > 1) return;
|
|
3982
|
-
const drain = (): void => {
|
|
3983
|
-
const next = queue[0];
|
|
3984
|
-
if (!next) {
|
|
3985
|
-
this.#manifestRecoveryQueues.delete(queueKey);
|
|
3986
|
-
return;
|
|
3987
|
-
}
|
|
3988
|
-
this.#admitRecoveredResult(
|
|
3989
|
-
next.blockId,
|
|
3990
|
-
next.result,
|
|
3991
|
-
next.ownerPacketId,
|
|
3992
|
-
next.catalogTrackName,
|
|
3993
|
-
() => {
|
|
3994
|
-
queue.shift();
|
|
3995
|
-
drain();
|
|
3996
|
-
},
|
|
3997
|
-
);
|
|
3998
|
-
};
|
|
3999
|
-
drain();
|
|
4079
|
+
this.#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
|
|
4000
4080
|
}
|
|
4001
4081
|
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4082
|
+
/**
|
|
4083
|
+
* The receiver a recovered packet of `packetId` answers to: the flow that
|
|
4084
|
+
* admitted the stream's source datagrams. Before any was admitted, the one
|
|
4085
|
+
* flow whose registration lists the stream; more than one (a repair flow
|
|
4086
|
+
* also lists its owners' source tracks) cannot be told apart, so none.
|
|
4087
|
+
*/
|
|
4088
|
+
#provenanceFor(
|
|
4089
|
+
packetId: number,
|
|
4006
4090
|
catalogTrackName: string | undefined,
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
const
|
|
4010
|
-
const
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
const
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
done();
|
|
4023
|
-
return;
|
|
4024
|
-
}
|
|
4025
|
-
const identity = resolveIdentityForRoute
|
|
4026
|
-
? resolveIdentityForRoute({
|
|
4027
|
-
packetId: ownerPacketId,
|
|
4028
|
-
sbn: blockId,
|
|
4029
|
-
esi: symbol.index,
|
|
4030
|
-
...(catalogTrackName === undefined ? {} : { catalogTrackName }),
|
|
4031
|
-
recovered: true,
|
|
4032
|
-
sourceSymbolFormat: "fec-padded-recovery",
|
|
4033
|
-
})
|
|
4034
|
-
: resolveIdentity!(ownerPacketId, blockId, symbol.index, catalogTrackName);
|
|
4035
|
-
if (!identity) {
|
|
4036
|
-
console.warn(`[MmtpRouter] manifest identity unresolved; recovered symbol is fail-open for packetId=${ownerPacketId} block=${blockId} esi=${symbol.index}`);
|
|
4037
|
-
this.#routeProcessedFecSymbols(
|
|
4038
|
-
blockId,
|
|
4039
|
-
{ ...result, symbols: [symbol] },
|
|
4040
|
-
ownerPacketId,
|
|
4041
|
-
catalogTrackName,
|
|
4042
|
-
);
|
|
4043
|
-
admitNext(index + 1);
|
|
4044
|
-
return;
|
|
4091
|
+
): BcProvenanceV2Receiver | "ambiguous" | undefined {
|
|
4092
|
+
// A caller that names no track matches every name the packet id was admitted under.
|
|
4093
|
+
const byName = this.#provenanceStreamFlow.get(packetId);
|
|
4094
|
+
const flows = new Set(
|
|
4095
|
+
catalogTrackName === undefined || !byName
|
|
4096
|
+
? byName?.values()
|
|
4097
|
+
: byName.has(catalogTrackName) ? [byName.get(catalogTrackName)!] : [],
|
|
4098
|
+
);
|
|
4099
|
+
if (flows.size > 1) return "ambiguous";
|
|
4100
|
+
for (const bound of flows) return this.#provenance.get(bound)?.receiver ?? "ambiguous";
|
|
4101
|
+
let match: BcProvenanceV2Receiver | undefined;
|
|
4102
|
+
for (const { receiver, ingress } of this.#provenance.values()) {
|
|
4103
|
+
if (ingress.tracks.some((t) => t.packetId === packetId && (catalogTrackName === undefined || t.name === catalogTrackName))) {
|
|
4104
|
+
if (match) return "ambiguous";
|
|
4105
|
+
match = receiver;
|
|
4045
4106
|
}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
...identity,
|
|
4049
|
-
packetId: ownerPacketId,
|
|
4050
|
-
},
|
|
4051
|
-
symbol.rawSymbol,
|
|
4052
|
-
() => {
|
|
4053
|
-
if (!this.#disposed) {
|
|
4054
|
-
this.#routeProcessedFecSymbols(
|
|
4055
|
-
blockId,
|
|
4056
|
-
{ ...result, symbols: [symbol] },
|
|
4057
|
-
ownerPacketId,
|
|
4058
|
-
catalogTrackName,
|
|
4059
|
-
);
|
|
4060
|
-
}
|
|
4061
|
-
admitNext(index + 1);
|
|
4062
|
-
},
|
|
4063
|
-
// A stalled symbol that is later discarded instead of played must still
|
|
4064
|
-
// advance this loop; enforce mode never calls the release callback for
|
|
4065
|
-
// it (BLO-30095).
|
|
4066
|
-
() => admitNext(index + 1),
|
|
4067
|
-
);
|
|
4068
|
-
if (admission.action === "drop") admitNext(index + 1);
|
|
4069
|
-
};
|
|
4070
|
-
admitNext(0);
|
|
4107
|
+
}
|
|
4108
|
+
return match;
|
|
4071
4109
|
}
|
|
4072
4110
|
|
|
4073
4111
|
#routeProcessedFecSymbols(
|
|
@@ -4080,6 +4118,28 @@ export class MmtpRouter {
|
|
|
4080
4118
|
// which track this block belongs to — resolves per-track, then legacy fallback.
|
|
4081
4119
|
if (ownerPacketId == null) return; // no track association
|
|
4082
4120
|
if (this.#classifyPacketId(ownerPacketId) === null) return; // unknown track
|
|
4121
|
+
// A recovered symbol's header names the sequence the sender protected. A
|
|
4122
|
+
// hop that re-stamps packet_sequence_number after protection (cast's
|
|
4123
|
+
// publisher-rotation bridge) leaves the decode mixing every received
|
|
4124
|
+
// source's re-stamped bytes into it. The reassembler addresses a
|
|
4125
|
+
// fragmented data unit by sequence + fragment counter, and the source
|
|
4126
|
+
// dedup reads the same number, so that fragment would park under a
|
|
4127
|
+
// foreign address until its data unit times out. Its SS_ID still names
|
|
4128
|
+
// its wire sequence, through the offset every received source states.
|
|
4129
|
+
const ssIdSeqOffset = this.#ssIdSeqOffsetByStream.get(
|
|
4130
|
+
this.#mediaStreamKey(ownerPacketId, catalogTrackName),
|
|
4131
|
+
);
|
|
4132
|
+
if (ssIdSeqOffset !== undefined) {
|
|
4133
|
+
result = {
|
|
4134
|
+
...result,
|
|
4135
|
+
symbols: result.symbols.map((sym) => {
|
|
4136
|
+
const wire = (this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset) >>> 0;
|
|
4137
|
+
if (wire === sym.packetSequenceNumber) return sym;
|
|
4138
|
+
this.#restampedRecoveredSeqs++;
|
|
4139
|
+
return { ...sym, packetSequenceNumber: wire };
|
|
4140
|
+
}),
|
|
4141
|
+
};
|
|
4142
|
+
}
|
|
4083
4143
|
this.#stream(ownerPacketId, catalogTrackName).duplicates.advance(blockId);
|
|
4084
4144
|
|
|
4085
4145
|
// A recovered symbol is a function of EVERY symbol that entered its block,
|
|
@@ -4100,7 +4160,8 @@ export class MmtpRouter {
|
|
|
4100
4160
|
) ?? 'unknown';
|
|
4101
4161
|
|
|
4102
4162
|
for (const sym of result.symbols) {
|
|
4103
|
-
// The block processor read these from the recovered packet's own
|
|
4163
|
+
// The block processor read these from the recovered packet's own
|
|
4164
|
+
// header; the sequence is the wire one derived above.
|
|
4104
4165
|
this.#routeTrackPacket(sym.rawSymbol, ownerPacketId, sym.packetSequenceNumber, {
|
|
4105
4166
|
mmtpTimestamp: sym.fragment.timestamp,
|
|
4106
4167
|
rap: sym.fragment.rapFlag,
|