@blockcast/mmt-container 2.2.0-main.c4fa878f4ff4 → 2.2.0-main.e75bbd7576a6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -17
- package/dist/browser-runtime.js +703 -175
- package/dist/browser-runtime.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +17 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +15 -0
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/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/delivery-catalog.js +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js.map +1 -1
- package/dist/fec-manager.d.ts +33 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +222 -6
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +9 -0
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +17 -0
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mmtp-container-parser.d.ts +37 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +86 -9
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +89 -11
- package/dist/mmtp-container-parser.no-modules.js.map +2 -2
- package/dist/mmtp-decode-pipeline.js +85 -9
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +18 -1
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +304 -39
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-manager.js +526 -45
- package/dist/multicast-manager.js.map +2 -2
- package/dist/multicast-transport.js +26 -16
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +85 -9
- package/dist/no-modules.js.map +2 -2
- package/dist/repair-layer-subscriptions.d.ts +6 -2
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +6 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- package/dist/track-session.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +85 -9
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/schemas/catalog.schema.json +4 -0
- package/src/catalog-fec-params.ts +36 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/fec-manager.ts +277 -6
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +7 -2
- package/src/iso-block-locator.ts +19 -0
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +96 -8
- package/src/mmtp-router.ts +350 -13
- package/src/repair-layer-subscriptions.ts +13 -5
- package/src/track-session.ts +1 -1
package/dist/browser-runtime.js
CHANGED
|
@@ -7988,8 +7988,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7988
7988
|
record.claims--;
|
|
7989
7989
|
return this.acquire(gateway, config, consumer);
|
|
7990
7990
|
}
|
|
7991
|
-
const
|
|
7992
|
-
entry.consumers.set(
|
|
7991
|
+
const token2 = Symbol(key);
|
|
7992
|
+
entry.consumers.set(token2, consumer);
|
|
7993
7993
|
let released = false;
|
|
7994
7994
|
return {
|
|
7995
7995
|
key,
|
|
@@ -7997,7 +7997,7 @@ var MulticastSubscriptionPool = class {
|
|
|
7997
7997
|
if (released)
|
|
7998
7998
|
return;
|
|
7999
7999
|
released = true;
|
|
8000
|
-
entry.consumers.delete(
|
|
8000
|
+
entry.consumers.delete(token2);
|
|
8001
8001
|
record.claims--;
|
|
8002
8002
|
if (record.claims > 0)
|
|
8003
8003
|
return;
|
|
@@ -8746,14 +8746,15 @@ var MOQT_PUBLISHER_PRIORITY = Object.freeze({
|
|
|
8746
8746
|
});
|
|
8747
8747
|
|
|
8748
8748
|
// node_modules/@blockcast/mmt-transport/dist/amt-gateway.js
|
|
8749
|
+
var MAX_PENDING_PACKETS = 256;
|
|
8749
8750
|
var AMTGatewayManager = class {
|
|
8750
8751
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8751
8752
|
messageHandler;
|
|
8753
|
+
messageListenerRegistered = false;
|
|
8752
8754
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
8753
8755
|
constructor() {
|
|
8754
8756
|
this.messageHandler = (event) => {
|
|
8755
8757
|
const data = event.data;
|
|
8756
|
-
console.log(`[AMT] SW message received:`, data.type);
|
|
8757
8758
|
if (data.type === "UDP_PACKET") {
|
|
8758
8759
|
this.handlePacket(data);
|
|
8759
8760
|
} else if (data.type === "SOCKET_ERROR") {
|
|
@@ -8762,12 +8763,22 @@ var AMTGatewayManager = class {
|
|
|
8762
8763
|
console.log(`[AMT SW Debug] ${data.message}`);
|
|
8763
8764
|
}
|
|
8764
8765
|
};
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8766
|
+
}
|
|
8767
|
+
ensureMessageListener() {
|
|
8768
|
+
if (this.messageListenerRegistered || typeof navigator === "undefined" || !navigator.serviceWorker || !this.messageHandler) {
|
|
8769
|
+
return;
|
|
8770
|
+
}
|
|
8771
|
+
navigator.serviceWorker.addEventListener("message", this.messageHandler);
|
|
8772
|
+
this.messageListenerRegistered = true;
|
|
8773
|
+
console.log("[AMT] Registered service worker message handler");
|
|
8774
|
+
}
|
|
8775
|
+
removeMessageListener() {
|
|
8776
|
+
if (!this.messageListenerRegistered)
|
|
8777
|
+
return;
|
|
8778
|
+
if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
|
|
8779
|
+
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
8770
8780
|
}
|
|
8781
|
+
this.messageListenerRegistered = false;
|
|
8771
8782
|
}
|
|
8772
8783
|
/**
|
|
8773
8784
|
* Subscribe via AMT tunnel
|
|
@@ -8777,6 +8788,7 @@ var AMTGatewayManager = class {
|
|
|
8777
8788
|
if (config.protected) {
|
|
8778
8789
|
throw new Error("AMTGatewayManager refuses a protected join: it reports no per-datagram sender (multicast-02 7.2.7)");
|
|
8779
8790
|
}
|
|
8791
|
+
this.ensureMessageListener();
|
|
8780
8792
|
const keyStr = this.getKeyString(key);
|
|
8781
8793
|
if (this.subscriptions.has(keyStr)) {
|
|
8782
8794
|
console.log(`[AMT] Reusing existing subscription to ${keyStr}`);
|
|
@@ -8812,6 +8824,8 @@ var AMTGatewayManager = class {
|
|
|
8812
8824
|
this.subscriptions.delete(keyStr);
|
|
8813
8825
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
8814
8826
|
}
|
|
8827
|
+
if (this.subscriptions.size === 0)
|
|
8828
|
+
this.removeMessageListener();
|
|
8815
8829
|
throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
|
|
8816
8830
|
}
|
|
8817
8831
|
}
|
|
@@ -8833,6 +8847,8 @@ var AMTGatewayManager = class {
|
|
|
8833
8847
|
} finally {
|
|
8834
8848
|
this.subscriptions.delete(handle);
|
|
8835
8849
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
8850
|
+
if (this.subscriptions.size === 0)
|
|
8851
|
+
this.removeMessageListener();
|
|
8836
8852
|
}
|
|
8837
8853
|
}
|
|
8838
8854
|
/**
|
|
@@ -8849,14 +8865,12 @@ var AMTGatewayManager = class {
|
|
|
8849
8865
|
if (!subscriptionId)
|
|
8850
8866
|
return;
|
|
8851
8867
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
8852
|
-
if (!subscription)
|
|
8853
|
-
console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
|
|
8868
|
+
if (!subscription)
|
|
8854
8869
|
return;
|
|
8855
|
-
}
|
|
8856
8870
|
if (!subscription.handshakeComplete) {
|
|
8857
8871
|
const queue = this.pendingPackets.get(subscriptionId);
|
|
8858
8872
|
const packetData2 = data;
|
|
8859
|
-
if (queue) {
|
|
8873
|
+
if (queue && queue.length < MAX_PENDING_PACKETS) {
|
|
8860
8874
|
queue.push({
|
|
8861
8875
|
data: packetData2.data,
|
|
8862
8876
|
remoteAddress: packetData2.remoteAddress,
|
|
@@ -8882,19 +8896,15 @@ var AMTGatewayManager = class {
|
|
|
8882
8896
|
if (!subscriptionId)
|
|
8883
8897
|
return;
|
|
8884
8898
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
8885
|
-
if (!subscription)
|
|
8886
|
-
console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
|
|
8899
|
+
if (!subscription)
|
|
8887
8900
|
return;
|
|
8888
|
-
}
|
|
8889
8901
|
subscription.config.onError(new Error(error || "Unknown error"));
|
|
8890
8902
|
}
|
|
8891
8903
|
/**
|
|
8892
8904
|
* Cleanup on destroy
|
|
8893
8905
|
*/
|
|
8894
8906
|
destroy() {
|
|
8895
|
-
|
|
8896
|
-
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
8897
|
-
}
|
|
8907
|
+
this.removeMessageListener();
|
|
8898
8908
|
const handles = Array.from(this.subscriptions.keys());
|
|
8899
8909
|
for (const handle of handles) {
|
|
8900
8910
|
this.unsubscribe(handle).catch((err) => {
|
|
@@ -12939,6 +12949,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12939
12949
|
#retentionBlocks;
|
|
12940
12950
|
#heldEvicted;
|
|
12941
12951
|
#newest;
|
|
12952
|
+
#newestSource;
|
|
12942
12953
|
#holes;
|
|
12943
12954
|
static #checkedRetention(retentionBlocks) {
|
|
12944
12955
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
@@ -12976,6 +12987,21 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12976
12987
|
observe(position) {
|
|
12977
12988
|
if (this.#newest === void 0 || serial32Precedes(this.#newest, position)) this.#newest = position;
|
|
12978
12989
|
}
|
|
12990
|
+
/**
|
|
12991
|
+
* The newest source SS_ID noted with `noteSource` (RFC 1982 order). Unlike
|
|
12992
|
+
* `newest`, a repair never moves it: a repair can run ahead of its sources,
|
|
12993
|
+
* a source cannot run ahead of the sources sent before it except by
|
|
12994
|
+
* reordering.
|
|
12995
|
+
*/
|
|
12996
|
+
get newestSource() {
|
|
12997
|
+
return this.#newestSource;
|
|
12998
|
+
}
|
|
12999
|
+
/** Note a received source's SS_ID; true when it is the newest one yet. */
|
|
13000
|
+
noteSource(ssId) {
|
|
13001
|
+
if (this.#newestSource !== void 0 && !serial32Precedes(this.#newestSource, ssId)) return false;
|
|
13002
|
+
this.#newestSource = ssId;
|
|
13003
|
+
return true;
|
|
13004
|
+
}
|
|
12979
13005
|
/** Held sources evicted by `heldCapacity` (never by the horizon itself). */
|
|
12980
13006
|
get heldEvicted() {
|
|
12981
13007
|
return this.#heldEvicted;
|
|
@@ -13208,6 +13234,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13208
13234
|
this.#held.clear();
|
|
13209
13235
|
this.#coverageEnd = void 0;
|
|
13210
13236
|
this.#newest = void 0;
|
|
13237
|
+
this.#newestSource = void 0;
|
|
13211
13238
|
}
|
|
13212
13239
|
#claim(block) {
|
|
13213
13240
|
const placed = [];
|
|
@@ -13827,6 +13854,7 @@ var WORKER_ERROR_LOG_CAP = 5;
|
|
|
13827
13854
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13828
13855
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
13829
13856
|
var STARTUP_REPAIR_WAIT_SOURCE_BOUNDARIES = 2;
|
|
13857
|
+
var NOT_TAKEN = Object.freeze({ taken: false, recovered: null });
|
|
13830
13858
|
function isMulticastSymbolDelivery(value) {
|
|
13831
13859
|
return value === "datagram" || value === "ordered-relay";
|
|
13832
13860
|
}
|
|
@@ -13924,6 +13952,10 @@ var FECManager = class _FECManager {
|
|
|
13924
13952
|
// Source symbol count per track-scoped block — marks complete when K symbols arrive.
|
|
13925
13953
|
this.#blockSourceCounts = /* @__PURE__ */ new Map();
|
|
13926
13954
|
this.#blockSourceEsis = /* @__PURE__ */ new Map();
|
|
13955
|
+
// Source ESIs per block that another FEC instance rebuilt and fed in
|
|
13956
|
+
// (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
|
|
13957
|
+
// not network arrivals and never make a block clean.
|
|
13958
|
+
this.#blockRebuiltEsis = /* @__PURE__ */ new Map();
|
|
13927
13959
|
// Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
|
|
13928
13960
|
// first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
|
|
13929
13961
|
// media units, usually before it holds K symbols; under iso-ssbg1-v1
|
|
@@ -14052,6 +14084,10 @@ var FECManager = class _FECManager {
|
|
|
14052
14084
|
// ── Keyframe-protected repair policy (block-policy.ts) ──
|
|
14053
14085
|
// One classifier per physical stream, built from that stream's geometry.
|
|
14054
14086
|
this.#classifiers = /* @__PURE__ */ new Map();
|
|
14087
|
+
// A stream without catalog timing has no classifier, so the last RAP it
|
|
14088
|
+
// released stands in for one: "an MPU boundary bounds its RAPs" holds until
|
|
14089
|
+
// a second RAP is released inside one MPU (BLO-52085).
|
|
14090
|
+
this.#noSpanRaps = /* @__PURE__ */ new Map();
|
|
14055
14091
|
// Geometry a stream-scoped configuration gave one stream (streamKey). ABR
|
|
14056
14092
|
// rungs can share a packetId with a different framerate or GOP, so the
|
|
14057
14093
|
// packet-level geometry is only the geometry of a packet whose streams
|
|
@@ -14209,6 +14245,7 @@ var FECManager = class _FECManager {
|
|
|
14209
14245
|
#pendingWorkerCleanupBounds;
|
|
14210
14246
|
#blockSourceCounts;
|
|
14211
14247
|
#blockSourceEsis;
|
|
14248
|
+
#blockRebuiltEsis;
|
|
14212
14249
|
#blockAuthoredLengths;
|
|
14213
14250
|
#ssbLengthConflictCount;
|
|
14214
14251
|
#blockRepairRsIds;
|
|
@@ -14251,6 +14288,7 @@ var FECManager = class _FECManager {
|
|
|
14251
14288
|
#orderedFrontiers;
|
|
14252
14289
|
#orderedPendingBlocks;
|
|
14253
14290
|
#classifiers;
|
|
14291
|
+
#noSpanRaps;
|
|
14254
14292
|
#streamGeometries;
|
|
14255
14293
|
#failedBlocks;
|
|
14256
14294
|
#resolvedBlockClasses;
|
|
@@ -14912,6 +14950,7 @@ var FECManager = class _FECManager {
|
|
|
14912
14950
|
};
|
|
14913
14951
|
const discontinuity = () => {
|
|
14914
14952
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
14953
|
+
this.#noSpanRaps.delete(streamKey);
|
|
14915
14954
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14916
14955
|
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14917
14956
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
@@ -15324,6 +15363,9 @@ var FECManager = class _FECManager {
|
|
|
15324
15363
|
}
|
|
15325
15364
|
if (policyChanged) {
|
|
15326
15365
|
this.#bumpEpoch(packetId);
|
|
15366
|
+
for (const key of [...this.#noSpanRaps.keys()]) {
|
|
15367
|
+
if (this.#belongsToPacket(key, packetId)) this.#noSpanRaps.delete(key);
|
|
15368
|
+
}
|
|
15327
15369
|
for (const [key, classifier] of [...this.#classifiers]) {
|
|
15328
15370
|
if (!this.#belongsToPacket(key, packetId)) continue;
|
|
15329
15371
|
const stream = this.#parseStreamKey(key);
|
|
@@ -15526,6 +15568,7 @@ var FECManager = class _FECManager {
|
|
|
15526
15568
|
}
|
|
15527
15569
|
resetMap(this.#blockSourceCounts);
|
|
15528
15570
|
resetMap(this.#blockSourceEsis);
|
|
15571
|
+
resetMap(this.#blockRebuiltEsis);
|
|
15529
15572
|
resetMap(this.#blockAuthoredLengths);
|
|
15530
15573
|
resetMap(this.#blockRepairRsIds);
|
|
15531
15574
|
resetMap(this.#blockRsbLengths);
|
|
@@ -15559,6 +15602,7 @@ var FECManager = class _FECManager {
|
|
|
15559
15602
|
resetMap(this.#isoLocators);
|
|
15560
15603
|
resetMap(this.#sourceAnchors);
|
|
15561
15604
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
15605
|
+
this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName));
|
|
15562
15606
|
this.#bumpEpoch(packetId);
|
|
15563
15607
|
for (const [sbn, keys] of this.#blockKeysBySbn) {
|
|
15564
15608
|
for (const key of keys.keys()) {
|
|
@@ -15649,6 +15693,7 @@ var FECManager = class _FECManager {
|
|
|
15649
15693
|
dropMap(this.#pendingWorkerCleanupClients);
|
|
15650
15694
|
dropMap(this.#blockSourceCounts);
|
|
15651
15695
|
dropMap(this.#blockSourceEsis);
|
|
15696
|
+
dropMap(this.#blockRebuiltEsis);
|
|
15652
15697
|
dropMap(this.#blockAuthoredLengths);
|
|
15653
15698
|
dropMap(this.#blockRepairRsIds);
|
|
15654
15699
|
dropMap(this.#blockRsbLengths);
|
|
@@ -15665,6 +15710,7 @@ var FECManager = class _FECManager {
|
|
|
15665
15710
|
dropMap(this.#isoLocators);
|
|
15666
15711
|
dropMap(this.#sourceAnchors);
|
|
15667
15712
|
dropMap(this.#classifiers);
|
|
15713
|
+
dropMap(this.#noSpanRaps);
|
|
15668
15714
|
dropMap(this.#streamGeometries);
|
|
15669
15715
|
dropSet(this.#pendingWorkerCleanups);
|
|
15670
15716
|
dropSet(this.#completedBlocks);
|
|
@@ -15810,6 +15856,9 @@ var FECManager = class _FECManager {
|
|
|
15810
15856
|
this.#unindexBlockKey(key);
|
|
15811
15857
|
}
|
|
15812
15858
|
}
|
|
15859
|
+
if (isSourceSymbol && source === "multicast") {
|
|
15860
|
+
this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), sbn + esi >>> 0, packetId, catalogTrackName);
|
|
15861
|
+
}
|
|
15813
15862
|
return true;
|
|
15814
15863
|
}
|
|
15815
15864
|
#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName) {
|
|
@@ -16127,6 +16176,7 @@ var FECManager = class _FECManager {
|
|
|
16127
16176
|
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
16128
16177
|
const evictedBefore = locator.heldEvicted;
|
|
16129
16178
|
const held = locator.hold(ssId, source);
|
|
16179
|
+
if (held && source.source === "multicast") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
|
|
16130
16180
|
const evicted = locator.heldEvicted - evictedBefore;
|
|
16131
16181
|
if (evicted > 0) {
|
|
16132
16182
|
const before = this.#isoHeldEvictedCount;
|
|
@@ -16295,11 +16345,14 @@ var FECManager = class _FECManager {
|
|
|
16295
16345
|
/**
|
|
16296
16346
|
* Whether an MPU boundary still bounds this stream's RAPs (see
|
|
16297
16347
|
* `BlockClassifier.mpuBoundsRaps`). Gap decisions drop MPU evidence once
|
|
16298
|
-
* it does not. A stream with no classifier yet has shown nothing against it
|
|
16348
|
+
* it does not. A stream with no classifier yet has shown nothing against it,
|
|
16349
|
+
* and neither has a stream without catalog timing until it releases two
|
|
16350
|
+
* RAPs inside one MPU.
|
|
16299
16351
|
*/
|
|
16300
16352
|
mpuBoundsRapsFor(packetId, catalogTrackName) {
|
|
16301
|
-
|
|
16302
|
-
return this.#
|
|
16353
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16354
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true;
|
|
16355
|
+
return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true;
|
|
16303
16356
|
}
|
|
16304
16357
|
/** A block's class now, or frozen at its resolution. */
|
|
16305
16358
|
blockClassFor(sbn, packetId, catalogTrackName) {
|
|
@@ -16325,7 +16378,14 @@ var FECManager = class _FECManager {
|
|
|
16325
16378
|
* invariant (consecutive MPUs exactly one keyframe interval apart).
|
|
16326
16379
|
*/
|
|
16327
16380
|
noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale) {
|
|
16328
|
-
if (!this.#trackConfigs.has(packetId)
|
|
16381
|
+
if (!this.#trackConfigs.has(packetId)) return;
|
|
16382
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) {
|
|
16383
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16384
|
+
const last = this.#noSpanRaps.get(streamKey);
|
|
16385
|
+
const inside = last?.inside === true || last?.mpu === mpu && last.presentationTime !== presentationTime;
|
|
16386
|
+
this.#noSpanRaps.set(streamKey, { mpu, presentationTime, inside });
|
|
16387
|
+
return;
|
|
16388
|
+
}
|
|
16329
16389
|
this.#applyClassifierChanges(
|
|
16330
16390
|
packetId,
|
|
16331
16391
|
catalogTrackName,
|
|
@@ -16712,7 +16772,15 @@ var FECManager = class _FECManager {
|
|
|
16712
16772
|
this.#isoSourceOversizeCount++;
|
|
16713
16773
|
return null;
|
|
16714
16774
|
}
|
|
16715
|
-
|
|
16775
|
+
return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start);
|
|
16776
|
+
}
|
|
16777
|
+
/**
|
|
16778
|
+
* Hand one placed source symbol to the stream's decoder: its Worker, which
|
|
16779
|
+
* answers through onFrame (null here), or its synchronous decoder, whose
|
|
16780
|
+
* recovered block is returned. `sbn` is the SS_Start of the block a repair
|
|
16781
|
+
* stated for `ssId`.
|
|
16782
|
+
*/
|
|
16783
|
+
#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn) {
|
|
16716
16784
|
const blockKey = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
16717
16785
|
const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey);
|
|
16718
16786
|
const workerClient = this.#routableWorkerForPacket(packetId, catalogTrackName);
|
|
@@ -16741,6 +16809,74 @@ var FECManager = class _FECManager {
|
|
|
16741
16809
|
}
|
|
16742
16810
|
return recovered;
|
|
16743
16811
|
}
|
|
16812
|
+
/**
|
|
16813
|
+
* Feed a source symbol of this stream that another FEC instance over the
|
|
16814
|
+
* same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
|
|
16815
|
+
* caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
|
|
16816
|
+
* BLO-52085). It joins its block's decoder as a received source would, so
|
|
16817
|
+
* it reduces the erasures the block still has to solve, but it is not a
|
|
16818
|
+
* network arrival: no transport accounting, no classification evidence,
|
|
16819
|
+
* no deadline refresh, and it never makes a block clean.
|
|
16820
|
+
*
|
|
16821
|
+
* Only a block a repair stated takes one (a repair-less span has no
|
|
16822
|
+
* decoder block). A block that is terminal, or already holds that source,
|
|
16823
|
+
* does not. The symbol is the exact protected packet, unpadded, as
|
|
16824
|
+
* feedSourceSymbol takes it.
|
|
16825
|
+
*
|
|
16826
|
+
* `recovered` is the block the synchronous decoder completed with it; the
|
|
16827
|
+
* caller routes it and completes the block, as for any recovery. When
|
|
16828
|
+
* every source of the block is then present, received or rebuilt, and no
|
|
16829
|
+
* decoder returned it (a Worker answers asynchronously, and reports such a
|
|
16830
|
+
* block as clean on its own side), the block is completed here as
|
|
16831
|
+
* recovered, with nothing left to route.
|
|
16832
|
+
*/
|
|
16833
|
+
feedRebuiltSourceSymbol(packetId, ssId, symbolData, catalogTrackName) {
|
|
16834
|
+
if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN;
|
|
16835
|
+
const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId);
|
|
16836
|
+
if (located === null || located.block.span) return NOT_TAKEN;
|
|
16837
|
+
if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN;
|
|
16838
|
+
const sbn = located.block.start;
|
|
16839
|
+
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
16840
|
+
if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN;
|
|
16841
|
+
let rebuilt = this.#blockRebuiltEsis.get(key);
|
|
16842
|
+
if (rebuilt?.has(located.esi)) return NOT_TAKEN;
|
|
16843
|
+
if (rebuilt === void 0) {
|
|
16844
|
+
rebuilt = /* @__PURE__ */ new Set();
|
|
16845
|
+
this.#blockRebuiltEsis.set(key, rebuilt);
|
|
16846
|
+
}
|
|
16847
|
+
const config = this.#trackConfigs.get(packetId);
|
|
16848
|
+
const wasShort = config !== void 0 && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== void 0;
|
|
16849
|
+
rebuilt.add(located.esi);
|
|
16850
|
+
const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn);
|
|
16851
|
+
if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
|
|
16852
|
+
if (wasShort && this.#activeBlocks.has(key) && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) === void 0) {
|
|
16853
|
+
this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config));
|
|
16854
|
+
}
|
|
16855
|
+
}
|
|
16856
|
+
return { taken: true, recovered };
|
|
16857
|
+
}
|
|
16858
|
+
/**
|
|
16859
|
+
* A block that holds every one of its `length` sources, received or
|
|
16860
|
+
* rebuilt by another instance, with at least one rebuilt, is recovered:
|
|
16861
|
+
* every packet of it was delivered, by its own arrival or by the instance
|
|
16862
|
+
* that rebuilt it, so nothing is routed. Returns whether it completed it.
|
|
16863
|
+
*/
|
|
16864
|
+
#completeWhenSourcesPresent(key, sbn, length, packetId, catalogTrackName) {
|
|
16865
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
16866
|
+
if (rebuilt === void 0 || this.#completedBlocks.has(key)) return false;
|
|
16867
|
+
let present = rebuilt.size;
|
|
16868
|
+
for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++;
|
|
16869
|
+
if (present < length) return false;
|
|
16870
|
+
this.#traceLifecycle("recovered", sbn, packetId, catalogTrackName);
|
|
16871
|
+
this.countRecovery(packetId, sbn, catalogTrackName);
|
|
16872
|
+
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
16873
|
+
if (catalogTrackName === void 0) {
|
|
16874
|
+
this.onBlockComplete?.(sbn, packetId);
|
|
16875
|
+
} else {
|
|
16876
|
+
this.onBlockComplete?.(sbn, packetId, catalogTrackName);
|
|
16877
|
+
}
|
|
16878
|
+
return true;
|
|
16879
|
+
}
|
|
16744
16880
|
/**
|
|
16745
16881
|
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16746
16882
|
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
@@ -16943,8 +17079,75 @@ var FECManager = class _FECManager {
|
|
|
16943
17079
|
this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName);
|
|
16944
17080
|
return null;
|
|
16945
17081
|
}
|
|
17082
|
+
if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName);
|
|
16946
17083
|
return recovered;
|
|
16947
17084
|
}
|
|
17085
|
+
/**
|
|
17086
|
+
* A first-arrival multicast source, held or placed. A datagram flow keeps
|
|
17087
|
+
* its sources in send order, so one that moves the stream's newest source
|
|
17088
|
+
* position past a block leaves the sources that block still misses
|
|
17089
|
+
* reordered behind it at best: it shortens the wait of every block it
|
|
17090
|
+
* passed that only a late source can complete. MoQ is left out: its streams
|
|
17091
|
+
* can overtake one another, so a MoQ source shows nothing about the sources
|
|
17092
|
+
* sent before it.
|
|
17093
|
+
*/
|
|
17094
|
+
#noteMulticastSource(locator, ssId, packetId, catalogTrackName) {
|
|
17095
|
+
const previous = locator.newestSource;
|
|
17096
|
+
if (!locator.noteSource(ssId) || previous === void 0) return;
|
|
17097
|
+
for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
|
|
17098
|
+
if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
|
|
17099
|
+
this.#shortenUnrecoverableWait(
|
|
17100
|
+
this.#blockKey(block.start, packetId, catalogTrackName),
|
|
17101
|
+
block.start,
|
|
17102
|
+
packetId,
|
|
17103
|
+
catalogTrackName
|
|
17104
|
+
);
|
|
17105
|
+
}
|
|
17106
|
+
}
|
|
17107
|
+
/**
|
|
17108
|
+
* The wait of a block that only a late source can complete (BLO-52085): a
|
|
17109
|
+
* repair stated it, its received sources plus every symbol its repair group
|
|
17110
|
+
* carries (RSB_length) are short of K' (the repair scheduler's
|
|
17111
|
+
* group-cannot-complete), and a later source of the stream has arrived, so
|
|
17112
|
+
* a source it misses is lost or reordered behind that one. The span, which
|
|
17113
|
+
* covers repair symbols paced after its sources, buys it nothing: it waits
|
|
17114
|
+
* the late-symbol allowance alone, the multicast wait less the span (the
|
|
17115
|
+
* catalog tolerance or the measured delivery gap). Undefined for any other
|
|
17116
|
+
* block.
|
|
17117
|
+
*/
|
|
17118
|
+
#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
|
|
17119
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
17120
|
+
const rsbLength = this.#blockRsbLengths.get(key);
|
|
17121
|
+
if (authoredLength === void 0 || rsbLength === void 0) return void 0;
|
|
17122
|
+
let present = this.#blockSourceCounts.get(key) ?? 0;
|
|
17123
|
+
const received = this.#blockSourceEsis.get(key);
|
|
17124
|
+
for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
|
|
17125
|
+
if (present + rsbLength >= authoredLength) return void 0;
|
|
17126
|
+
const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
|
|
17127
|
+
if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
|
|
17128
|
+
return void 0;
|
|
17129
|
+
}
|
|
17130
|
+
return this.#multicastWaitMs(config) - config.interleaveDepthMs;
|
|
17131
|
+
}
|
|
17132
|
+
/**
|
|
17133
|
+
* Bring an open block's wait in to its late-source wait, when it has one.
|
|
17134
|
+
* Never later than it is armed: only a source can complete such a block,
|
|
17135
|
+
* so a repair of its group (paced across the span) must not keep it open.
|
|
17136
|
+
*/
|
|
17137
|
+
#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName) {
|
|
17138
|
+
if (!this.#activeBlocks.has(key)) return;
|
|
17139
|
+
const config = this.#trackConfigs.get(packetId);
|
|
17140
|
+
if (config === void 0) return;
|
|
17141
|
+
const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config);
|
|
17142
|
+
if (waitMs === void 0) return;
|
|
17143
|
+
const armedAtMs = this.#blockWaitDeadlinesMs.get(key);
|
|
17144
|
+
this.#armBlockTimeout(
|
|
17145
|
+
sbn,
|
|
17146
|
+
packetId,
|
|
17147
|
+
catalogTrackName,
|
|
17148
|
+
armedAtMs === void 0 ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow())
|
|
17149
|
+
);
|
|
17150
|
+
}
|
|
16948
17151
|
/**
|
|
16949
17152
|
* Record a block's authored SSB_length from a repair symbol. Returns false,
|
|
16950
17153
|
* leaving the block unchanged, when the symbol contradicts the block: a
|
|
@@ -17099,6 +17302,15 @@ var FECManager = class _FECManager {
|
|
|
17099
17302
|
this.#completeCleanBlock(key, sbn, packetId, catalogTrackName);
|
|
17100
17303
|
return;
|
|
17101
17304
|
}
|
|
17305
|
+
if (this.#blockRebuiltEsis.has(key) && this.#completeWhenSourcesPresent(
|
|
17306
|
+
key,
|
|
17307
|
+
sbn,
|
|
17308
|
+
this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
|
|
17309
|
+
packetId,
|
|
17310
|
+
catalogTrackName
|
|
17311
|
+
)) {
|
|
17312
|
+
return;
|
|
17313
|
+
}
|
|
17102
17314
|
this.noteBlockActivity(sbn, packetId, catalogTrackName, true);
|
|
17103
17315
|
}
|
|
17104
17316
|
#completeCleanBlock(key, sbn, packetId, catalogTrackName) {
|
|
@@ -17107,6 +17319,7 @@ var FECManager = class _FECManager {
|
|
|
17107
17319
|
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
17108
17320
|
this.#blockSourceCounts.delete(key);
|
|
17109
17321
|
this.#blockSourceEsis.delete(key);
|
|
17322
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17110
17323
|
this.#blockAuthoredLengths.delete(key);
|
|
17111
17324
|
this.#blockRepairRsIds.delete(key);
|
|
17112
17325
|
this.#blockRsbLengths.delete(key);
|
|
@@ -17173,7 +17386,16 @@ var FECManager = class _FECManager {
|
|
|
17173
17386
|
this.#repairDeadlineMs(trackConfig)
|
|
17174
17387
|
);
|
|
17175
17388
|
}
|
|
17176
|
-
this.#
|
|
17389
|
+
if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== void 0) {
|
|
17390
|
+
this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName);
|
|
17391
|
+
return;
|
|
17392
|
+
}
|
|
17393
|
+
this.#armBlockTimeout(
|
|
17394
|
+
sbn,
|
|
17395
|
+
packetId,
|
|
17396
|
+
catalogTrackName,
|
|
17397
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs
|
|
17398
|
+
);
|
|
17177
17399
|
}
|
|
17178
17400
|
#failBlock(sbn, packetId, catalogTrackName) {
|
|
17179
17401
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -17186,6 +17408,7 @@ var FECManager = class _FECManager {
|
|
|
17186
17408
|
}
|
|
17187
17409
|
this.#blockSourceCounts.delete(key);
|
|
17188
17410
|
this.#blockSourceEsis.delete(key);
|
|
17411
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17189
17412
|
this.#blockAuthoredLengths.delete(key);
|
|
17190
17413
|
this.#blockRepairRsIds.delete(key);
|
|
17191
17414
|
this.#blockRsbLengths.delete(key);
|
|
@@ -17224,6 +17447,7 @@ var FECManager = class _FECManager {
|
|
|
17224
17447
|
this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName);
|
|
17225
17448
|
this.#blockSourceCounts.delete(key);
|
|
17226
17449
|
this.#blockSourceEsis.delete(key);
|
|
17450
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17227
17451
|
this.#blockAuthoredLengths.delete(key);
|
|
17228
17452
|
this.#blockRepairRsIds.delete(key);
|
|
17229
17453
|
this.#blockRsbLengths.delete(key);
|
|
@@ -17315,6 +17539,7 @@ var FECManager = class _FECManager {
|
|
|
17315
17539
|
this.#blockKeysBySbn.clear();
|
|
17316
17540
|
this.#blockSourceCounts.clear();
|
|
17317
17541
|
this.#blockSourceEsis.clear();
|
|
17542
|
+
this.#blockRebuiltEsis.clear();
|
|
17318
17543
|
this.#blockAuthoredLengths.clear();
|
|
17319
17544
|
this.#blockRepairRsIds.clear();
|
|
17320
17545
|
this.#blockRsbLengths.clear();
|
|
@@ -17340,6 +17565,7 @@ var FECManager = class _FECManager {
|
|
|
17340
17565
|
this.#blockAnchorsMs.clear();
|
|
17341
17566
|
this.#blockCatalogTrackNames.clear();
|
|
17342
17567
|
this.#classifiers.clear();
|
|
17568
|
+
this.#noSpanRaps.clear();
|
|
17343
17569
|
this.#streamGeometries.clear();
|
|
17344
17570
|
this.#failedBlocks.clear();
|
|
17345
17571
|
this.#resolvedBlockClasses.clear();
|
|
@@ -17870,9 +18096,21 @@ var IsoBmffTimingResolver = class {
|
|
|
17870
18096
|
}
|
|
17871
18097
|
#track = null;
|
|
17872
18098
|
#fragments = /* @__PURE__ */ new Map();
|
|
18099
|
+
/** First sample of each pending fragment, kept in `#delivered` with its sample count. */
|
|
18100
|
+
#firstSamples = /* @__PURE__ */ new Map();
|
|
18101
|
+
/**
|
|
18102
|
+
* First sample and sample count of the newest fragments whose every slot was
|
|
18103
|
+
* cleared. Abandonment counts: `releaseSample` clears a slot too, which
|
|
18104
|
+
* matches the combiner, since it retires an abandoned sample as well.
|
|
18105
|
+
*/
|
|
18106
|
+
#delivered = /* @__PURE__ */ new Map();
|
|
17873
18107
|
#pendingSamples = 0;
|
|
17874
18108
|
#evictedSamples = 0;
|
|
17875
18109
|
#lastMovieFragmentRejection = null;
|
|
18110
|
+
/** True once an FT=0 has bound the track that FT=1 timing is read against. */
|
|
18111
|
+
get initialized() {
|
|
18112
|
+
return this.#track !== null;
|
|
18113
|
+
}
|
|
17876
18114
|
get pendingSampleCount() {
|
|
17877
18115
|
return this.#pendingSamples;
|
|
17878
18116
|
}
|
|
@@ -17896,7 +18134,14 @@ var IsoBmffTimingResolver = class {
|
|
|
17896
18134
|
this.#track = timing;
|
|
17897
18135
|
return true;
|
|
17898
18136
|
}
|
|
17899
|
-
|
|
18137
|
+
/**
|
|
18138
|
+
* `recovered` marks an FEC-recovered copy. A recovered block hands back
|
|
18139
|
+
* every FT=1 it holds, the received ones included, so a recovered copy of a
|
|
18140
|
+
* fragment whose samples are all done is a duplicate: admitting it again
|
|
18141
|
+
* would charge stale timing and could displace the live MPU's. A source
|
|
18142
|
+
* copy is still admitted again (a rendition switch re-arms timing that way).
|
|
18143
|
+
*/
|
|
18144
|
+
addMovieFragment(mpuSequenceNumber2, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
|
|
17900
18145
|
this.#lastMovieFragmentRejection = null;
|
|
17901
18146
|
if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
|
|
17902
18147
|
this.#lastMovieFragmentRejection = "invalid";
|
|
@@ -17922,6 +18167,8 @@ var IsoBmffTimingResolver = class {
|
|
|
17922
18167
|
(sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
|
|
17923
18168
|
);
|
|
17924
18169
|
}
|
|
18170
|
+
const delivered = recovered ? this.#delivered.get(key) : void 0;
|
|
18171
|
+
if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
|
|
17925
18172
|
let freed = 0;
|
|
17926
18173
|
while (this.#fragments.size > 0 && (this.#pendingSamples + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
|
|
17927
18174
|
freed += this.#evictOldestFragment();
|
|
@@ -17935,6 +18182,7 @@ var IsoBmffTimingResolver = class {
|
|
|
17935
18182
|
return false;
|
|
17936
18183
|
}
|
|
17937
18184
|
this.#fragments.set(key, [...parsed.samples]);
|
|
18185
|
+
this.#firstSamples.set(key, parsed.samples[0]);
|
|
17938
18186
|
this.#pendingSamples += parsed.samples.length;
|
|
17939
18187
|
return true;
|
|
17940
18188
|
}
|
|
@@ -17992,6 +18240,7 @@ var IsoBmffTimingResolver = class {
|
|
|
17992
18240
|
let live = 0;
|
|
17993
18241
|
for (const sample of samples) if (sample !== null) live++;
|
|
17994
18242
|
this.#fragments.delete(oldest);
|
|
18243
|
+
this.#firstSamples.delete(oldest);
|
|
17995
18244
|
this.#pendingSamples -= live;
|
|
17996
18245
|
this.#evictedSamples += live;
|
|
17997
18246
|
return live;
|
|
@@ -18007,12 +18256,23 @@ var IsoBmffTimingResolver = class {
|
|
|
18007
18256
|
if (!samples || !samples[index]) return false;
|
|
18008
18257
|
samples[index] = null;
|
|
18009
18258
|
this.#pendingSamples--;
|
|
18010
|
-
if (samples.every((value) => value === null))
|
|
18259
|
+
if (samples.every((value) => value === null)) {
|
|
18260
|
+
this.#fragments.delete(key);
|
|
18261
|
+
const first = this.#firstSamples.get(key);
|
|
18262
|
+
this.#firstSamples.delete(key);
|
|
18263
|
+
this.#delivered.delete(key);
|
|
18264
|
+
this.#delivered.set(key, { first, sampleCount: samples.length });
|
|
18265
|
+
if (this.#delivered.size > this.maxPendingSamples) {
|
|
18266
|
+
this.#delivered.delete(this.#delivered.keys().next().value);
|
|
18267
|
+
}
|
|
18268
|
+
}
|
|
18011
18269
|
return true;
|
|
18012
18270
|
}
|
|
18013
18271
|
reset() {
|
|
18014
18272
|
this.#track = null;
|
|
18015
18273
|
this.#fragments.clear();
|
|
18274
|
+
this.#firstSamples.clear();
|
|
18275
|
+
this.#delivered.clear();
|
|
18016
18276
|
this.#pendingSamples = 0;
|
|
18017
18277
|
}
|
|
18018
18278
|
};
|
|
@@ -18494,6 +18754,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18494
18754
|
this.#reclaimedTimingSamples = 0;
|
|
18495
18755
|
this.#evictedTimingSamples = 0;
|
|
18496
18756
|
this.#rejectedMovieFragments = 0;
|
|
18757
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
18758
|
+
held: 0,
|
|
18759
|
+
expired: 0,
|
|
18760
|
+
discarded: 0,
|
|
18761
|
+
superseded: 0
|
|
18762
|
+
};
|
|
18497
18763
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
18498
18764
|
this.#fecGate = null;
|
|
18499
18765
|
this.#fecSequencer = null;
|
|
@@ -18602,6 +18868,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18602
18868
|
#reclaimedTimingSamples;
|
|
18603
18869
|
#evictedTimingSamples;
|
|
18604
18870
|
#rejectedMovieFragments;
|
|
18871
|
+
#recoveredHeadsAwaitingTiming;
|
|
18605
18872
|
#sequencers;
|
|
18606
18873
|
#fecGate;
|
|
18607
18874
|
#fecSequencer;
|
|
@@ -18722,6 +18989,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18722
18989
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
18723
18990
|
};
|
|
18724
18991
|
}
|
|
18992
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
18993
|
+
get recoveredHeadsAwaitingTiming() {
|
|
18994
|
+
let pending = 0;
|
|
18995
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18996
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
18997
|
+
}
|
|
18998
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
18999
|
+
}
|
|
18725
19000
|
get reorderStats() {
|
|
18726
19001
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
18727
19002
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -18850,10 +19125,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18850
19125
|
get reassemblerDataUnitsReturned() {
|
|
18851
19126
|
return this.#reassemblerDataUnitsReturned;
|
|
18852
19127
|
}
|
|
18853
|
-
#countOutcome(
|
|
18854
|
-
const count = (this.#feedOutcomes.get(
|
|
18855
|
-
this.#feedOutcomes.set(
|
|
18856
|
-
this.#lastOutcome =
|
|
19128
|
+
#countOutcome(token2) {
|
|
19129
|
+
const count = (this.#feedOutcomes.get(token2) ?? 0) + 1;
|
|
19130
|
+
this.#feedOutcomes.set(token2, count);
|
|
19131
|
+
this.#lastOutcome = token2;
|
|
18857
19132
|
this.#lastOutcomeCount = count;
|
|
18858
19133
|
}
|
|
18859
19134
|
#countDeferredOutcome(reason) {
|
|
@@ -18895,7 +19170,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18895
19170
|
const now = Date.now();
|
|
18896
19171
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18897
19172
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
18898
|
-
awaitingTiming.shift();
|
|
19173
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
18899
19174
|
}
|
|
18900
19175
|
}
|
|
18901
19176
|
}
|
|
@@ -19013,11 +19288,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19013
19288
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
19014
19289
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
19015
19290
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
19016
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
19291
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
19017
19292
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
19018
19293
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
19019
19294
|
const remaining = this.#maxPendingTimingSamples - this.#pendingTimingSamples;
|
|
19020
|
-
const admitted = resolver2.addMovieFragment(
|
|
19295
|
+
const admitted = resolver2.addMovieFragment(
|
|
19296
|
+
mpu.mpuSequenceNumber,
|
|
19297
|
+
data,
|
|
19298
|
+
remaining,
|
|
19299
|
+
options?.recovered === true
|
|
19300
|
+
);
|
|
19021
19301
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
19022
19302
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
19023
19303
|
if (!admitted) {
|
|
@@ -19037,7 +19317,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19037
19317
|
};
|
|
19038
19318
|
}
|
|
19039
19319
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
19040
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
19320
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
19041
19321
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
19042
19322
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
19043
19323
|
return this.#drop("mfu-empty-payload");
|
|
@@ -19058,6 +19338,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19058
19338
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
19059
19339
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
19060
19340
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
19341
|
+
sequenceNumber: info.sequenceNumber,
|
|
19061
19342
|
arrivedAt: Date.now()
|
|
19062
19343
|
});
|
|
19063
19344
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -19381,6 +19662,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19381
19662
|
}
|
|
19382
19663
|
this.#emitFrame(data, meta);
|
|
19383
19664
|
}
|
|
19665
|
+
/** Whether FT=1 metadata already names this sample, without claiming it. */
|
|
19666
|
+
hasAuthoredTimingFor(packetId, mpuSequenceNumber2, movieFragmentSequenceNumber, sampleNumber, catalogTrackName) {
|
|
19667
|
+
return this.#timingResolver(this.#streamKey(packetId, catalogTrackName), packetId, false)?.sampleTiming(mpuSequenceNumber2, movieFragmentSequenceNumber, sampleNumber) != null;
|
|
19668
|
+
}
|
|
19384
19669
|
/**
|
|
19385
19670
|
* Claim and return the authored timing for a recovered sample. Recovery does
|
|
19386
19671
|
* not pass through the ordinary `feed()` completion path, so it must retire
|
|
@@ -19442,6 +19727,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19442
19727
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
19443
19728
|
this.#sequencers.clear();
|
|
19444
19729
|
this.#fecSequencer?.discard();
|
|
19730
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
19731
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
19732
|
+
}
|
|
19445
19733
|
this.#timingStreams.clear();
|
|
19446
19734
|
this.#pendingTimingSamples = 0;
|
|
19447
19735
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -19460,10 +19748,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19460
19748
|
return resolver;
|
|
19461
19749
|
}
|
|
19462
19750
|
#awaitTiming(streamKey, head) {
|
|
19463
|
-
const
|
|
19464
|
-
if (!
|
|
19751
|
+
const state = this.#timingStreams.get(streamKey);
|
|
19752
|
+
if (!state) return;
|
|
19753
|
+
if (!head.options?.recovered) {
|
|
19754
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
19755
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
19756
|
+
state.awaitingTiming = kept;
|
|
19757
|
+
}
|
|
19758
|
+
const awaitingTiming = state.awaitingTiming;
|
|
19465
19759
|
awaitingTiming.push(head);
|
|
19466
|
-
if (
|
|
19760
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
19761
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
19762
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
19763
|
+
}
|
|
19764
|
+
}
|
|
19765
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
19766
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
19767
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
19467
19768
|
}
|
|
19468
19769
|
/**
|
|
19469
19770
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -19491,6 +19792,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19491
19792
|
const state = this.#timingStreams.get(streamKey);
|
|
19492
19793
|
if (!state) return;
|
|
19493
19794
|
this.#timingStreams.delete(streamKey);
|
|
19795
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
19494
19796
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
19495
19797
|
if (this.#pendingTimingSamples < 0) {
|
|
19496
19798
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|
|
@@ -22697,6 +22999,16 @@ function keyframeOverlaySsId(header) {
|
|
|
22697
22999
|
if (ext?.type !== KEYFRAME_OVERLAY_EXTENSION_TYPE || ext.data.length !== 4) return void 0;
|
|
22698
23000
|
return new DataView(ext.data.buffer, ext.data.byteOffset, 4).getUint32(0);
|
|
22699
23001
|
}
|
|
23002
|
+
function overlayBaseSsId(anchor, overlaySsId, restoredPsn, headerPsn) {
|
|
23003
|
+
if (anchor.baseSsId === void 0 || headerPsn !== restoredPsn) return void 0;
|
|
23004
|
+
return serial32Add(anchor.baseSsId, overlaySsId - anchor.overlaySsId | 0);
|
|
23005
|
+
}
|
|
23006
|
+
function unstampedBaseSsId(offset, unstampedOffset, headerPsn) {
|
|
23007
|
+
if (offset === void 0 || offset !== unstampedOffset) return void 0;
|
|
23008
|
+
return headerPsn + offset >>> 0;
|
|
23009
|
+
}
|
|
23010
|
+
var OVERLAY_ROUTED_LIMIT = 1024;
|
|
23011
|
+
var OVERLAY_PENDING_LIMIT = 256;
|
|
22700
23012
|
var OVERLAY_OFFSET_MPUS = 16;
|
|
22701
23013
|
var OVERLAY_MOQ_HORIZON_BLOCKS = 64;
|
|
22702
23014
|
function assertStreamIdentity(role, stream) {
|
|
@@ -22808,6 +23120,7 @@ var MmtpRouter = class {
|
|
|
22808
23120
|
#provenance = /* @__PURE__ */ new Map();
|
|
22809
23121
|
#onFlowProtected = null;
|
|
22810
23122
|
#unadmittedListedDrops = 0;
|
|
23123
|
+
#admittedSourceDatagrams = 0;
|
|
22811
23124
|
#unlistedRepairSetAside = 0;
|
|
22812
23125
|
#assistBlocks = /* @__PURE__ */ new Map();
|
|
22813
23126
|
#assistFailures = /* @__PURE__ */ new Map();
|
|
@@ -22864,6 +23177,15 @@ var MmtpRouter = class {
|
|
|
22864
23177
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
22865
23178
|
*/
|
|
22866
23179
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
23180
|
+
/**
|
|
23181
|
+
* Per stream, the SS_ID offset at which a base recovery last showed the
|
|
23182
|
+
* sender's own packet_sequence_number: a recovered packet's header psn
|
|
23183
|
+
* equal to its SS_ID minus that offset. While it equals the stream's
|
|
23184
|
+
* current offset, no hop re-stamps the stream, and a packet's protected psn
|
|
23185
|
+
* names its base SS_ID within unstampedBaseSsId's limits (joint decoding of
|
|
23186
|
+
* an MPU no member of which arrived).
|
|
23187
|
+
*/
|
|
23188
|
+
#unstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
22867
23189
|
/**
|
|
22868
23190
|
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
22869
23191
|
* not parsed, typically because its overlap copy was parsed first
|
|
@@ -22933,7 +23255,9 @@ var MmtpRouter = class {
|
|
|
22933
23255
|
recovered: 0,
|
|
22934
23256
|
restarts: 0,
|
|
22935
23257
|
unsequencedDropped: 0,
|
|
22936
|
-
protectedDropped: 0
|
|
23258
|
+
protectedDropped: 0,
|
|
23259
|
+
baseFed: 0,
|
|
23260
|
+
baseUndetermined: 0
|
|
22937
23261
|
};
|
|
22938
23262
|
/** Callback fired when a delta-track FEC block completes or fails. */
|
|
22939
23263
|
#onDeltaBlockCompleteCb = null;
|
|
@@ -23106,7 +23430,7 @@ var MmtpRouter = class {
|
|
|
23106
23430
|
const cb = this.#getFrameCallback(packetId);
|
|
23107
23431
|
if (isVideo && !assembler) {
|
|
23108
23432
|
if (frameMeta.recovered) {
|
|
23109
|
-
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb);
|
|
23433
|
+
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb, meta.fecSbn);
|
|
23110
23434
|
} else {
|
|
23111
23435
|
this.#routeDirectSourceVideo(packetId, data, frameMeta, cb);
|
|
23112
23436
|
}
|
|
@@ -23496,6 +23820,10 @@ var MmtpRouter = class {
|
|
|
23496
23820
|
get keyframeOverlayStats() {
|
|
23497
23821
|
return { ...this.#overlayStats };
|
|
23498
23822
|
}
|
|
23823
|
+
/** Recovered FT=2 heads held for their FT=1, and how each left the wait (BLO-53369). */
|
|
23824
|
+
get recoveredHeadsAwaitingTiming() {
|
|
23825
|
+
return this.#parser.recoveredHeadsAwaitingTiming;
|
|
23826
|
+
}
|
|
23499
23827
|
#isOverlayRepair(repairPacketId, repairTrackName) {
|
|
23500
23828
|
return this.#overlayLegs.has(repairPacketId) || repairTrackName !== void 0 && this.#overlayRepairNames.has(repairTrackName);
|
|
23501
23829
|
}
|
|
@@ -23546,6 +23874,11 @@ var MmtpRouter = class {
|
|
|
23546
23874
|
*/
|
|
23547
23875
|
resetKeyframeOverlays(sourcePacketId, catalogTrackName) {
|
|
23548
23876
|
for (const inst of this.#overlaysForSource(sourcePacketId, catalogTrackName)) this.#resetOverlay(inst);
|
|
23877
|
+
for (const [name, stream] of this.#streams.get(sourcePacketId) ?? []) {
|
|
23878
|
+
if (catalogTrackName !== void 0 && name !== catalogTrackName) continue;
|
|
23879
|
+
stream.overlayToBase.routed.clear();
|
|
23880
|
+
stream.overlayToBase.pending.clear();
|
|
23881
|
+
}
|
|
23549
23882
|
}
|
|
23550
23883
|
#resetOverlay(inst) {
|
|
23551
23884
|
inst.fec.resetTrack(inst.repairPacketId, inst.streamName);
|
|
@@ -23602,9 +23935,10 @@ var MmtpRouter = class {
|
|
|
23602
23935
|
* A source packet that carries a 0x8B01 overlay SS_ID is also a symbol of
|
|
23603
23936
|
* every overlay installed for its source, at that SS_ID, with the bytes the
|
|
23604
23937
|
* base protects: the packet minus its 4-byte SS_ID trailer, extension
|
|
23605
|
-
* included (7.1, 7.4.3).
|
|
23938
|
+
* included (7.1, 7.4.3). `baseSsId` is that trailer's SS_ID, when the base
|
|
23939
|
+
* FEC reads it.
|
|
23606
23940
|
*/
|
|
23607
|
-
#feedOverlaySource(packetId, catalogTrackName, packet, header, sequenceNumber, rapFlag, source) {
|
|
23941
|
+
#feedOverlaySource(packetId, catalogTrackName, packet, header, sequenceNumber, rapFlag, source, baseSsId) {
|
|
23608
23942
|
if (this.#overlays.size === 0) return;
|
|
23609
23943
|
const ssId = keyframeOverlaySsId(header);
|
|
23610
23944
|
if (ssId === void 0) return;
|
|
@@ -23613,7 +23947,11 @@ var MmtpRouter = class {
|
|
|
23613
23947
|
const identity = MmtpContainerParser.sourcePacketIdentity(packet, header);
|
|
23614
23948
|
if (identity !== null) {
|
|
23615
23949
|
inst.offsets.delete(identity.mpuSequenceNumber);
|
|
23616
|
-
inst.offsets.set(identity.mpuSequenceNumber,
|
|
23950
|
+
inst.offsets.set(identity.mpuSequenceNumber, {
|
|
23951
|
+
psnOffset: ssId - sequenceNumber >>> 0,
|
|
23952
|
+
overlaySsId: ssId,
|
|
23953
|
+
...baseSsId === void 0 ? {} : { baseSsId }
|
|
23954
|
+
});
|
|
23617
23955
|
if (inst.offsets.size > OVERLAY_OFFSET_MPUS) inst.offsets.delete(inst.offsets.keys().next().value);
|
|
23618
23956
|
}
|
|
23619
23957
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -23692,14 +24030,27 @@ var MmtpRouter = class {
|
|
|
23692
24030
|
const streamKey = this.#mediaStreamKey(sourcePacketId, sourceName);
|
|
23693
24031
|
const restamped = this.#restampedStreams.has(streamKey);
|
|
23694
24032
|
const restored = /* @__PURE__ */ new Set();
|
|
24033
|
+
const baseSsIds = /* @__PURE__ */ new Map();
|
|
23695
24034
|
const symbols = result.symbols.flatMap((sym) => {
|
|
23696
|
-
const
|
|
23697
|
-
if (
|
|
23698
|
-
const
|
|
24035
|
+
const anchor = inst.offsets.get(sym.fragment.mpuSequenceNumber);
|
|
24036
|
+
if (anchor !== void 0) {
|
|
24037
|
+
const overlaySsId = serial32Add(blockStart, sym.index);
|
|
24038
|
+
const packetSequenceNumber = overlaySsId - anchor.psnOffset >>> 0;
|
|
23699
24039
|
restored.add(packetSequenceNumber);
|
|
23700
|
-
|
|
24040
|
+
const out = { ...sym, packetSequenceNumber };
|
|
24041
|
+
const baseSsId = overlayBaseSsId(anchor, overlaySsId, packetSequenceNumber, sym.packetSequenceNumber);
|
|
24042
|
+
if (baseSsId !== void 0) baseSsIds.set(out, baseSsId);
|
|
24043
|
+
return [out];
|
|
24044
|
+
}
|
|
24045
|
+
if (!restamped) {
|
|
24046
|
+
const baseSsId = unstampedBaseSsId(
|
|
24047
|
+
this.#ssIdSeqOffsetByStream.get(streamKey),
|
|
24048
|
+
this.#unstampedSsIdSeqOffsetByStream.get(streamKey),
|
|
24049
|
+
sym.packetSequenceNumber
|
|
24050
|
+
);
|
|
24051
|
+
if (baseSsId !== void 0) baseSsIds.set(sym, baseSsId);
|
|
24052
|
+
return [sym];
|
|
23701
24053
|
}
|
|
23702
|
-
if (!restamped) return [sym];
|
|
23703
24054
|
this.#overlayStats.unsequencedDropped++;
|
|
23704
24055
|
return [];
|
|
23705
24056
|
});
|
|
@@ -23708,6 +24059,85 @@ var MmtpRouter = class {
|
|
|
23708
24059
|
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast"
|
|
23709
24060
|
});
|
|
23710
24061
|
this.#noteOverlayRecoveredRaps(sourcePacketId, sourceName, streamKey, symbols.filter((sym) => restored.has(sym.packetSequenceNumber)));
|
|
24062
|
+
this.#feedOverlayRecoveredToBase(inst, blockStart, symbols, baseSsIds);
|
|
24063
|
+
}
|
|
24064
|
+
/**
|
|
24065
|
+
* Joint decoding (BLO-52085). A packet the overlay rebuilt is a source of
|
|
24066
|
+
* its base block too, once its base SS_ID is determined (overlayBaseSsId,
|
|
24067
|
+
* from a received member of its MPU, else unstampedBaseSsId),
|
|
24068
|
+
* so it is fed to the base decoder as a rebuilt source
|
|
24069
|
+
* (FECManager.feedRebuiltSourceSymbol): the base block has one erasure
|
|
24070
|
+
* fewer to solve, and its repair can recover the block's other packets.
|
|
24071
|
+
* A base block no repair has stated yet takes it when one does
|
|
24072
|
+
* (#feedPendingRebuilt).
|
|
24073
|
+
*
|
|
24074
|
+
* The overlay route already handled each packet fed (delivered it, or
|
|
24075
|
+
* held an untimed head for its FT=1), so a base recovery routes none of
|
|
24076
|
+
* them again (#routeVerifiedFecSymbols): a second recovered copy of a
|
|
24077
|
+
* held head would wait in the parser for timing its first copy consumed.
|
|
24078
|
+
* Only an overlay block decoded from multicast symbols alone is fed: with
|
|
24079
|
+
* a MoQ symbol in it, the base block's recovery would depend on bytes
|
|
24080
|
+
* that crossed no multicast socket, which the provenance counted from the
|
|
24081
|
+
* block's own arrivals cannot show.
|
|
24082
|
+
*/
|
|
24083
|
+
#feedOverlayRecoveredToBase(inst, blockStart, symbols, baseSsIds) {
|
|
24084
|
+
const fec = this.#fecManager;
|
|
24085
|
+
const owner = inst.leg.sourcePacketId;
|
|
24086
|
+
const name = inst.leg.sourceCatalogTrackName;
|
|
24087
|
+
if (!fec?.feedRebuiltSourceSymbol || inst.moqBlocks.has(blockStart)) return;
|
|
24088
|
+
if (this.#classifyPacketId(owner) === null || fec.isTrackConfigured?.(owner) === false) return;
|
|
24089
|
+
const { duplicates, overlayToBase: { routed } } = this.#stream(owner, name);
|
|
24090
|
+
const feeds = [];
|
|
24091
|
+
for (const sym of symbols) {
|
|
24092
|
+
if (duplicates.sourceSeqs.has(sym.packetSequenceNumber)) continue;
|
|
24093
|
+
const ssId = baseSsIds.get(sym);
|
|
24094
|
+
if (ssId === void 0) {
|
|
24095
|
+
this.#overlayStats.baseUndetermined++;
|
|
24096
|
+
continue;
|
|
24097
|
+
}
|
|
24098
|
+
routed.delete(ssId);
|
|
24099
|
+
routed.add(ssId);
|
|
24100
|
+
if (routed.size > OVERLAY_ROUTED_LIMIT) routed.delete(routed.values().next().value);
|
|
24101
|
+
feeds.push([ssId, sym.rawSymbol]);
|
|
24102
|
+
}
|
|
24103
|
+
for (const [ssId, symbolData] of feeds) {
|
|
24104
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24105
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24106
|
+
}
|
|
24107
|
+
}
|
|
24108
|
+
/** Feed one rebuilt source to its base block, or keep it until a repair states that block. */
|
|
24109
|
+
#feedRebuiltToBase(owner, name, ssId, symbolData) {
|
|
24110
|
+
const fec = this.#fecManager;
|
|
24111
|
+
if (!fec?.feedRebuiltSourceSymbol) return;
|
|
24112
|
+
const coords = fec.locateIsoSource?.(owner, name, ssId);
|
|
24113
|
+
if (coords == null) {
|
|
24114
|
+
const pending = this.#stream(owner, name).overlayToBase.pending;
|
|
24115
|
+
pending.delete(ssId);
|
|
24116
|
+
pending.set(ssId, symbolData.slice());
|
|
24117
|
+
if (pending.size > OVERLAY_PENDING_LIMIT) pending.delete(pending.keys().next().value);
|
|
24118
|
+
return;
|
|
24119
|
+
}
|
|
24120
|
+
const fed = fec.feedRebuiltSourceSymbol(owner, ssId, symbolData, name);
|
|
24121
|
+
if (!fed.taken) return;
|
|
24122
|
+
this.#overlayStats.baseFed++;
|
|
24123
|
+
if (fed.recovered === null) return;
|
|
24124
|
+
const sbn = coords.sbn;
|
|
24125
|
+
this.#routeRecoveredBlock(sbn, fed.recovered, owner, name, () => {
|
|
24126
|
+
fec.cancelBlockTimeout(sbn, owner, name);
|
|
24127
|
+
fec.countRecovery(owner, sbn, name);
|
|
24128
|
+
fec.markBlockCompleted(sbn, owner, name);
|
|
24129
|
+
});
|
|
24130
|
+
}
|
|
24131
|
+
/** A repair stated `block`: the rebuilt sources that waited for it join it now. */
|
|
24132
|
+
#feedPendingRebuilt(owner, name, block) {
|
|
24133
|
+
const pending = this.#streams.get(owner)?.get(name)?.overlayToBase.pending;
|
|
24134
|
+
if (pending === void 0 || pending.size === 0) return;
|
|
24135
|
+
for (const [ssId, symbolData] of [...pending]) {
|
|
24136
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24137
|
+
if (serial32Distance(block.start, ssId) >= block.length) continue;
|
|
24138
|
+
pending.delete(ssId);
|
|
24139
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24140
|
+
}
|
|
23711
24141
|
}
|
|
23712
24142
|
/** fec-multicast-00 §6.6: report each base block whose RAP MFU fragments
|
|
23713
24143
|
* the overlay restored, when the keyframe's FT=0 and FT=1 are held too. A
|
|
@@ -23847,6 +24277,10 @@ var MmtpRouter = class {
|
|
|
23847
24277
|
get unadmittedListedDropCount() {
|
|
23848
24278
|
return this.#unadmittedListedDrops;
|
|
23849
24279
|
}
|
|
24280
|
+
/** 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. */
|
|
24281
|
+
get admittedSourceDatagramCount() {
|
|
24282
|
+
return this.#admittedSourceDatagrams;
|
|
24283
|
+
}
|
|
23850
24284
|
/** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
|
|
23851
24285
|
get unlistedRepairSetAsideCount() {
|
|
23852
24286
|
return this.#unlistedRepairSetAside;
|
|
@@ -24333,6 +24767,8 @@ var MmtpRouter = class {
|
|
|
24333
24767
|
)) return;
|
|
24334
24768
|
fec.noteBlockActivity?.(blockStart, ownerPacketId, catalogTrackName);
|
|
24335
24769
|
fec.noteRepairGroupLength?.(blockStart, ownerPacketId, repair.rsbLength, catalogTrackName);
|
|
24770
|
+
this.#feedPendingRebuilt(ownerPacketId, catalogTrackName, placement.block);
|
|
24771
|
+
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
24336
24772
|
const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
|
|
24337
24773
|
const recovered = fec.feedRepairSymbol(
|
|
24338
24774
|
ownerPacketId,
|
|
@@ -24470,6 +24906,7 @@ var MmtpRouter = class {
|
|
|
24470
24906
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
24471
24907
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
24472
24908
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
24909
|
+
this.#unstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
24473
24910
|
this.#multicastRapTwinByStream.delete(streamKey);
|
|
24474
24911
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
24475
24912
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
@@ -25104,6 +25541,7 @@ var MmtpRouter = class {
|
|
|
25104
25541
|
const parsed = this.#parser.parsePacket(packet);
|
|
25105
25542
|
if (!parsed) return;
|
|
25106
25543
|
const info = parsed.info;
|
|
25544
|
+
if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
|
|
25107
25545
|
if (source === "multicast" && !manifestAdmitted) {
|
|
25108
25546
|
this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
|
|
25109
25547
|
}
|
|
@@ -25385,7 +25823,8 @@ var MmtpRouter = class {
|
|
|
25385
25823
|
parsed.header,
|
|
25386
25824
|
info.sequenceNumber,
|
|
25387
25825
|
info.rapFlag,
|
|
25388
|
-
source
|
|
25826
|
+
source,
|
|
25827
|
+
fecPayloadId?.ssId
|
|
25389
25828
|
);
|
|
25390
25829
|
}
|
|
25391
25830
|
}
|
|
@@ -25535,7 +25974,8 @@ var MmtpRouter = class {
|
|
|
25535
25974
|
if (stream === void 0) {
|
|
25536
25975
|
stream = {
|
|
25537
25976
|
key: JSON.stringify([packetId, catalogTrackName ?? null]),
|
|
25538
|
-
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId))
|
|
25977
|
+
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId)),
|
|
25978
|
+
overlayToBase: { routed: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Map() }
|
|
25539
25979
|
};
|
|
25540
25980
|
byName.set(catalogTrackName, stream);
|
|
25541
25981
|
}
|
|
@@ -25650,8 +26090,16 @@ var MmtpRouter = class {
|
|
|
25650
26090
|
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
25651
26091
|
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
25652
26092
|
}
|
|
25653
|
-
#routeDirectRecoveredVideo(packetId, data, meta, cb) {
|
|
26093
|
+
#routeDirectRecoveredVideo(packetId, data, meta, cb, fecSbn) {
|
|
25654
26094
|
const streamKey = this.#mediaStreamKey(packetId, meta.catalogTrackName);
|
|
26095
|
+
if (this.#isFecTrack(packetId)) {
|
|
26096
|
+
const high = this.#deliveredVideoHighWaterByStream.get(streamKey);
|
|
26097
|
+
if (fecSbn !== void 0 || high !== void 0 && authoredAdjacent(high, meta)) {
|
|
26098
|
+
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
26099
|
+
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
26100
|
+
return;
|
|
26101
|
+
}
|
|
26102
|
+
}
|
|
25655
26103
|
this.#enqueueDirectRecoveredVideo(packetId, data, meta);
|
|
25656
26104
|
const lastSourceTs = this.#lastDirectSourceVideoTsByStream.get(streamKey);
|
|
25657
26105
|
this.#drainDirectRecoveredVideo(
|
|
@@ -25805,6 +26253,13 @@ var MmtpRouter = class {
|
|
|
25805
26253
|
* frames by epoch only if pre-protection input ever matters.
|
|
25806
26254
|
*/
|
|
25807
26255
|
#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete, assisted = false) {
|
|
26256
|
+
const overlayRouted = ownerPacketId == null ? void 0 : this.#streams.get(ownerPacketId)?.get(catalogTrackName)?.overlayToBase.routed;
|
|
26257
|
+
if (overlayRouted !== void 0 && overlayRouted.size > 0) {
|
|
26258
|
+
result = {
|
|
26259
|
+
...result,
|
|
26260
|
+
symbols: result.symbols.filter((sym) => !overlayRouted.has(this.#fecAnchorForRecovered(blockId, sym.index)))
|
|
26261
|
+
};
|
|
26262
|
+
}
|
|
25808
26263
|
const entry = ownerPacketId == null ? void 0 : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
25809
26264
|
const receiver = entry === void 0 || entry === "ambiguous" ? entry : entry.receiver;
|
|
25810
26265
|
const userAgent = !assisted && entry !== void 0 && entry !== "ambiguous" && entry.protected === true && entry.userAgent === true;
|
|
@@ -25869,7 +26324,10 @@ var MmtpRouter = class {
|
|
|
25869
26324
|
...result,
|
|
25870
26325
|
symbols: result.symbols.map((sym) => {
|
|
25871
26326
|
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
25872
|
-
if (wire === sym.packetSequenceNumber)
|
|
26327
|
+
if (wire === sym.packetSequenceNumber) {
|
|
26328
|
+
this.#unstampedSsIdSeqOffsetByStream.set(streamKey, ssIdSeqOffset);
|
|
26329
|
+
return sym;
|
|
26330
|
+
}
|
|
25873
26331
|
this.#restampedRecoveredSeqs++;
|
|
25874
26332
|
this.#restampedStreams.add(streamKey);
|
|
25875
26333
|
return { ...sym, packetSequenceNumber: wire };
|
|
@@ -25905,6 +26363,29 @@ var MmtpRouter = class {
|
|
|
25905
26363
|
}
|
|
25906
26364
|
);
|
|
25907
26365
|
}
|
|
26366
|
+
const untimedHead = (sym) => sym.fragmentType === 2 && sym.fragment.fragmentationIndicator === 1 && sym.fragment.movieFragmentSequenceNumber !== void 0 && sym.fragment.sampleNumber !== void 0 && !this.#parser.hasAuthoredTimingFor(
|
|
26367
|
+
ownerPacketId,
|
|
26368
|
+
sym.fragment.mpuSequenceNumber,
|
|
26369
|
+
sym.fragment.movieFragmentSequenceNumber,
|
|
26370
|
+
sym.fragment.sampleNumber,
|
|
26371
|
+
catalogTrackName
|
|
26372
|
+
);
|
|
26373
|
+
for (const sym of result.symbols) {
|
|
26374
|
+
if (!untimedHead(sym) || this.#sourceSeqReceived(ownerPacketId, sym.packetSequenceNumber, catalogTrackName)) continue;
|
|
26375
|
+
this.#feedViaParser(
|
|
26376
|
+
sym.rawSymbol,
|
|
26377
|
+
{ packetId: ownerPacketId, sequenceNumber: sym.packetSequenceNumber },
|
|
26378
|
+
void 0,
|
|
26379
|
+
{
|
|
26380
|
+
skipFecPayloadId: true,
|
|
26381
|
+
recovered: true,
|
|
26382
|
+
deliveryProvenance,
|
|
26383
|
+
...fecSbnOf(sym.index),
|
|
26384
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
26385
|
+
}
|
|
26386
|
+
);
|
|
26387
|
+
}
|
|
26388
|
+
result = { ...result, symbols: result.symbols.filter((sym) => !untimedHead(sym)) };
|
|
25908
26389
|
const gated = this.#isFecTrack(ownerPacketId);
|
|
25909
26390
|
const assembler = this.#mseAssemblerFor(ownerPacketId, catalogTrackName);
|
|
25910
26391
|
if (assembler) {
|
|
@@ -29666,7 +30147,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
29666
30147
|
blockProfile,
|
|
29667
30148
|
k: opts.fecK,
|
|
29668
30149
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
29669
|
-
// and CMCD `
|
|
30150
|
+
// and CMCD `com.blockcast-fp` are read from this. Identity on a single layer.
|
|
29670
30151
|
repairCount: opts.joinedRepairCount ?? opts.fecRepairCount,
|
|
29671
30152
|
symbolSize: opts.fecSymbolSize,
|
|
29672
30153
|
interleaveDepth: interleaveDepthBlocks,
|
|
@@ -30208,24 +30689,24 @@ var MediaRouter = class {
|
|
|
30208
30689
|
if (!this.#multicastVideoKeyed) return;
|
|
30209
30690
|
if (this.#requireAudio && !this.#multicastAudioReceived) return;
|
|
30210
30691
|
if (this.#requireAudio && !this.#moqAudioWarmed) return;
|
|
30211
|
-
const
|
|
30692
|
+
const token2 = ++this.#sourceSwitchToken;
|
|
30212
30693
|
const maybeReady = this.#onSourceSwitch?.("multicast");
|
|
30213
30694
|
if (!maybeReady || typeof maybeReady.then !== "function") {
|
|
30214
|
-
this.#commitMulticastActivation(
|
|
30695
|
+
this.#commitMulticastActivation(token2);
|
|
30215
30696
|
return;
|
|
30216
30697
|
}
|
|
30217
30698
|
const ready = Promise.resolve(maybeReady);
|
|
30218
|
-
this.#pendingMulticastToken =
|
|
30699
|
+
this.#pendingMulticastToken = token2;
|
|
30219
30700
|
this.#sourceSwitchReady = ready;
|
|
30220
30701
|
void ready.then(
|
|
30221
|
-
() => this.#commitMulticastActivation(
|
|
30222
|
-
(err) => this.#rejectMulticastActivation(
|
|
30702
|
+
() => this.#commitMulticastActivation(token2),
|
|
30703
|
+
(err) => this.#rejectMulticastActivation(token2, err)
|
|
30223
30704
|
).finally(() => {
|
|
30224
30705
|
if (this.#sourceSwitchReady === ready) this.#sourceSwitchReady = null;
|
|
30225
30706
|
});
|
|
30226
30707
|
}
|
|
30227
|
-
#commitMulticastActivation(
|
|
30228
|
-
if (
|
|
30708
|
+
#commitMulticastActivation(token2) {
|
|
30709
|
+
if (token2 !== this.#sourceSwitchToken) return;
|
|
30229
30710
|
this.#active = "multicast";
|
|
30230
30711
|
this.#suppressed = true;
|
|
30231
30712
|
this.#pendingMulticastToken = null;
|
|
@@ -30236,9 +30717,9 @@ var MediaRouter = class {
|
|
|
30236
30717
|
if (video) this.#onVideoFrame?.(video.data, video.meta);
|
|
30237
30718
|
if (audio) this.#onAudioFrame?.(audio.data, audio.meta);
|
|
30238
30719
|
}
|
|
30239
|
-
#rejectMulticastActivation(
|
|
30240
|
-
if (
|
|
30241
|
-
if (this.#pendingMulticastToken ===
|
|
30720
|
+
#rejectMulticastActivation(token2, err) {
|
|
30721
|
+
if (token2 !== this.#sourceSwitchToken) return;
|
|
30722
|
+
if (this.#pendingMulticastToken === token2) this.#pendingMulticastToken = null;
|
|
30242
30723
|
this.#pendingMulticastVideo = null;
|
|
30243
30724
|
this.#pendingMulticastAudio = null;
|
|
30244
30725
|
console.warn("[MediaRouter] onSourceSwitch(multicast) failed", err);
|
|
@@ -31207,63 +31688,65 @@ var FecStarvationDetector = class {
|
|
|
31207
31688
|
|
|
31208
31689
|
// src/cmcd-producer.ts
|
|
31209
31690
|
var PLAY_MODES = ["full", "base-only", "single-track"];
|
|
31210
|
-
|
|
31211
|
-
|
|
31212
|
-
|
|
31213
|
-
|
|
31214
|
-
|
|
31215
|
-
|
|
31216
|
-
|
|
31217
|
-
|
|
31218
|
-
|
|
31219
|
-
|
|
31220
|
-
|
|
31221
|
-
|
|
31222
|
-
|
|
31223
|
-
|
|
31224
|
-
|
|
31225
|
-
|
|
31226
|
-
|
|
31227
|
-
|
|
31228
|
-
}
|
|
31229
|
-
if (snap.multicastSource != null) {
|
|
31230
|
-
params["x-bc-multicast-source"] = snap.multicastSource;
|
|
31231
|
-
}
|
|
31232
|
-
if (snap.amtRelay != null) {
|
|
31233
|
-
params["x-bc-amt-relay"] = snap.amtRelay;
|
|
31234
|
-
}
|
|
31235
|
-
return params;
|
|
31236
|
-
}
|
|
31237
|
-
function formatQueryString(params) {
|
|
31238
|
-
return Object.keys(params).sort().map((key) => {
|
|
31239
|
-
const v = params[key];
|
|
31240
|
-
if (typeof v === "string") return `${key}=${sanitize(v)}`;
|
|
31241
|
-
return `${key}=${v}`;
|
|
31691
|
+
var DEFAULT_INTERVAL_MS = 3e4;
|
|
31692
|
+
var CUSTOM_PREFIX = "com.blockcast-";
|
|
31693
|
+
var MAX_CUSTOM_VALUE = 64;
|
|
31694
|
+
var TRANSPORT_TOKEN = {
|
|
31695
|
+
native: "ssm",
|
|
31696
|
+
amt: "amt",
|
|
31697
|
+
moq: "moq"
|
|
31698
|
+
};
|
|
31699
|
+
function sfString(value) {
|
|
31700
|
+
return `"${value.replace(/[^\x20-\x7e]/g, "").replace(/[\\"]/g, "\\$&")}"`;
|
|
31701
|
+
}
|
|
31702
|
+
function encodeCmcdRecord(record) {
|
|
31703
|
+
return Object.keys(record).sort().map((key) => {
|
|
31704
|
+
const value = record[key];
|
|
31705
|
+
if (typeof value === "number") return `${key}=${value}`;
|
|
31706
|
+
if (typeof value === "string") return `${key}=${sfString(value)}`;
|
|
31707
|
+
if (Array.isArray(value)) return `${key}=(${value.map(sfString).join(" ")})`;
|
|
31708
|
+
return `${key}=${value.token}`;
|
|
31242
31709
|
}).join(",");
|
|
31243
31710
|
}
|
|
31711
|
+
var token = (value) => ({ token: value });
|
|
31712
|
+
function putCustom(record, name, value) {
|
|
31713
|
+
if (value === void 0) return;
|
|
31714
|
+
if (typeof value === "number") value = String(value);
|
|
31715
|
+
if (typeof value === "string" && value.length > MAX_CUSTOM_VALUE) return;
|
|
31716
|
+
record[CUSTOM_PREFIX + name] = value;
|
|
31717
|
+
}
|
|
31244
31718
|
var CmcdProducer = class {
|
|
31245
|
-
#onCmcdParams;
|
|
31246
31719
|
#onCmcdPost;
|
|
31720
|
+
#intervalMs;
|
|
31721
|
+
#sessionId;
|
|
31722
|
+
#now;
|
|
31723
|
+
#sn = 0;
|
|
31724
|
+
#lastHeartbeat = null;
|
|
31247
31725
|
#transport;
|
|
31248
31726
|
#lastStats;
|
|
31249
|
-
// Phase 14 state — Plan 03 Task 2 (D-12, D-15).
|
|
31250
31727
|
#playMode = null;
|
|
31251
31728
|
#deltaFailRate = null;
|
|
31252
31729
|
#switchMiscount = 0;
|
|
31253
31730
|
#manifestStats = null;
|
|
31254
31731
|
#fecFailClosed = null;
|
|
31732
|
+
/** Video-block resolutions from the repair lifecycle; null until the player feeds one. */
|
|
31733
|
+
#lifecycle = null;
|
|
31255
31734
|
constructor(options) {
|
|
31256
|
-
this.#onCmcdParams = options.onCmcdParams;
|
|
31257
31735
|
this.#onCmcdPost = options.onCmcdPost;
|
|
31736
|
+
this.#intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
31737
|
+
if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {
|
|
31738
|
+
throw new Error(`[CmcdProducer] invalid intervalMs "${String(options.intervalMs)}"; expected a positive number`);
|
|
31739
|
+
}
|
|
31740
|
+
this.#sessionId = options.sessionId ?? globalThis.crypto.randomUUID();
|
|
31741
|
+
this.#now = options.now ?? Date.now;
|
|
31258
31742
|
}
|
|
31259
31743
|
/** Update the stored transport state. Called by player wiring layer. */
|
|
31260
31744
|
updateTransport(snapshot) {
|
|
31261
31745
|
this.#transport = snapshot;
|
|
31262
31746
|
}
|
|
31263
31747
|
/**
|
|
31264
|
-
* Set the current play-mode
|
|
31265
|
-
*
|
|
31266
|
-
* (CLAUDE.md: error on bad init).
|
|
31748
|
+
* Set the current play-mode, reported as `com.blockcast-pm`. Throws on any
|
|
31749
|
+
* value outside {'full','base-only','single-track'} (CLAUDE.md: error on bad init).
|
|
31267
31750
|
*/
|
|
31268
31751
|
updatePlayMode(mode) {
|
|
31269
31752
|
if (typeof mode !== "string" || !PLAY_MODES.includes(mode)) {
|
|
@@ -31274,9 +31757,8 @@ var CmcdProducer = class {
|
|
|
31274
31757
|
this.#playMode = mode;
|
|
31275
31758
|
}
|
|
31276
31759
|
/**
|
|
31277
|
-
* Set the delta-track FEC block-failure rate (0..1 inclusive)
|
|
31278
|
-
* `
|
|
31279
|
-
* Omitted on single-track streams.
|
|
31760
|
+
* Set the delta-track FEC block-failure rate (0..1 inclusive), reported as
|
|
31761
|
+
* `com.blockcast-dfr` when play-mode is 'full' or 'base-only'.
|
|
31280
31762
|
*/
|
|
31281
31763
|
updateDeltaFailRate(rate) {
|
|
31282
31764
|
if (typeof rate !== "number" || !Number.isFinite(rate) || rate < 0 || rate > 1) {
|
|
@@ -31286,112 +31768,139 @@ var CmcdProducer = class {
|
|
|
31286
31768
|
}
|
|
31287
31769
|
this.#deltaFailRate = rate;
|
|
31288
31770
|
}
|
|
31289
|
-
/**
|
|
31290
|
-
* Bump the cumulative switching-set misalignment counter. Emitted as
|
|
31291
|
-
* `x-bc-switch-miscount` on snapshots when the counter is > 0.
|
|
31292
|
-
*/
|
|
31771
|
+
/** Bump the cumulative switching-set misalignment counter (`com.blockcast-sm`). */
|
|
31293
31772
|
incrementSwitchMiscount() {
|
|
31294
31773
|
this.#switchMiscount += 1;
|
|
31295
31774
|
}
|
|
31296
31775
|
/**
|
|
31297
|
-
* Record that FEC failed closed at runtime (fec-01 6.3.9).
|
|
31298
|
-
*
|
|
31299
|
-
* `
|
|
31300
|
-
* stream playing without FEC is told apart from one
|
|
31776
|
+
* Record that FEC failed closed at runtime (fec-01 6.3.9). Reported at once
|
|
31777
|
+
* as `e=e` with the reason code in `ec`, and on every later counter report
|
|
31778
|
+
* as `com.blockcast-ffc` / `com.blockcast-ffl` (the held layer whose total
|
|
31779
|
+
* B_i was undercut), so a stream playing without FEC is told apart from one
|
|
31780
|
+
* with no loss.
|
|
31301
31781
|
*/
|
|
31302
31782
|
updateFecFailClosed(reason) {
|
|
31783
|
+
const changed = this.#fecFailClosed?.code !== reason.code || this.#fecFailClosed?.layer !== reason.layer;
|
|
31303
31784
|
this.#fecFailClosed = reason;
|
|
31785
|
+
if (changed) this.#post([{ ...this.#base("e"), ec: [reason.code] }]);
|
|
31304
31786
|
}
|
|
31305
31787
|
updateManifestVerification(stats) {
|
|
31306
31788
|
this.#manifestStats = stats;
|
|
31307
31789
|
}
|
|
31308
31790
|
/**
|
|
31309
|
-
*
|
|
31310
|
-
*
|
|
31311
|
-
*
|
|
31312
|
-
*
|
|
31791
|
+
* Count a video block's resolution from the repair lifecycle: recovered in
|
|
31792
|
+
* band (`com.blockcast-fbr`), recovered by repair FETCH (`-fbq`), or failed
|
|
31793
|
+
* as a keyframe-class block (`-fbfk`). Audio blocks are not counted, matching
|
|
31794
|
+
* the video-track `-fbf`. Until the player feeds this, the three are absent.
|
|
31313
31795
|
*/
|
|
31796
|
+
onRepairLifecycle(event) {
|
|
31797
|
+
this.#lifecycle ??= { inband: 0, fetch: 0, failedKeyframe: 0 };
|
|
31798
|
+
if (event.type === "recovered" && event.blockClass !== "audio") {
|
|
31799
|
+
if (event.via === "inband") this.#lifecycle.inband++;
|
|
31800
|
+
else this.#lifecycle.fetch++;
|
|
31801
|
+
} else if (event.type === "failed" && event.blockClass === "keyframe") {
|
|
31802
|
+
this.#lifecycle.failedKeyframe++;
|
|
31803
|
+
}
|
|
31804
|
+
}
|
|
31805
|
+
/** One-shot custom event `com.blockcast-switch-drift` for a single misalignment. */
|
|
31314
31806
|
emitSwitchDrift(driftUs) {
|
|
31315
31807
|
if (typeof driftUs !== "number" || !Number.isFinite(driftUs) || driftUs < 0) {
|
|
31316
31808
|
throw new Error(
|
|
31317
31809
|
`[CmcdProducer] invalid drift-us "${String(driftUs)}"; expected a non-negative finite number`
|
|
31318
31810
|
);
|
|
31319
31811
|
}
|
|
31320
|
-
const
|
|
31321
|
-
|
|
31322
|
-
|
|
31323
|
-
if (this.#switchMiscount > 0) params["x-bc-switch-miscount"] = this.#switchMiscount;
|
|
31324
|
-
params["x-bc-switch-drift-us"] = driftUs;
|
|
31325
|
-
this.#emit(params);
|
|
31812
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "switch-drift" };
|
|
31813
|
+
putCustom(record, "sdu", Math.round(driftUs));
|
|
31814
|
+
this.#post([record]);
|
|
31326
31815
|
}
|
|
31327
|
-
/**
|
|
31328
|
-
* Process a FecTrackStats snapshot. Finds the video track, builds
|
|
31329
|
-
* x-bc-* vendor keys, and fires both delivery callbacks.
|
|
31330
|
-
*/
|
|
31816
|
+
/** Take a FecTrackStats snapshot (first video track) and send the heartbeat when due. */
|
|
31331
31817
|
onSnapshot(data) {
|
|
31332
31818
|
const videoTrack = data.tracks.find((t) => t.config.trackType === "video");
|
|
31333
31819
|
if (!videoTrack) return;
|
|
31334
31820
|
this.#lastStats = videoTrack;
|
|
31335
|
-
|
|
31336
|
-
...buildFecParams(videoTrack),
|
|
31337
|
-
...buildTransportParams(this.#transport)
|
|
31338
|
-
};
|
|
31339
|
-
if (this.#playMode !== null) {
|
|
31340
|
-
params["x-bc-play-mode"] = this.#playMode;
|
|
31341
|
-
}
|
|
31342
|
-
if (this.#fecFailClosed) {
|
|
31343
|
-
params["x-bc-fec-fail-closed"] = this.#fecFailClosed.code;
|
|
31344
|
-
params["x-bc-fec-fail-layer"] = this.#fecFailClosed.layer;
|
|
31345
|
-
}
|
|
31346
|
-
if (this.#playMode !== null && this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
31347
|
-
params["x-bc-delta-fail-rate"] = parseFloat(this.#deltaFailRate.toFixed(4));
|
|
31348
|
-
}
|
|
31349
|
-
if (this.#switchMiscount > 0) {
|
|
31350
|
-
params["x-bc-switch-miscount"] = this.#switchMiscount;
|
|
31351
|
-
}
|
|
31352
|
-
if (this.#manifestStats) {
|
|
31353
|
-
params["x-bc-manifest-verified"] = this.#manifestStats.verified > 0;
|
|
31354
|
-
params["x-bc-manifest-failures"] = Object.values(this.#manifestStats.failures).reduce((total, count) => total + count, 0);
|
|
31355
|
-
}
|
|
31356
|
-
this.#emit(params);
|
|
31821
|
+
this.#heartbeat();
|
|
31357
31822
|
}
|
|
31358
31823
|
/**
|
|
31359
|
-
*
|
|
31360
|
-
*
|
|
31824
|
+
* Take transport state for receivers that do not own FEC stats, and send the
|
|
31825
|
+
* heartbeat when due.
|
|
31361
31826
|
*/
|
|
31362
31827
|
onTransportSnapshot(data) {
|
|
31363
31828
|
if (!Number.isFinite(data.timestampMs) || data.timestampMs < 0) {
|
|
31364
31829
|
throw new Error("[CmcdProducer] transport snapshot timestamp must be a non-negative finite number");
|
|
31365
31830
|
}
|
|
31366
31831
|
if (data.playMode !== void 0) this.updatePlayMode(data.playMode);
|
|
31367
|
-
if (data.switchMiscount !== void 0
|
|
31368
|
-
|
|
31832
|
+
if (data.switchMiscount !== void 0) {
|
|
31833
|
+
if (!Number.isSafeInteger(data.switchMiscount) || data.switchMiscount < 0) {
|
|
31834
|
+
throw new Error("[CmcdProducer] transport snapshot switch-miscount must be a non-negative safe integer");
|
|
31835
|
+
}
|
|
31836
|
+
this.#switchMiscount = data.switchMiscount;
|
|
31369
31837
|
}
|
|
31370
31838
|
this.#transport = data.transport;
|
|
31371
|
-
|
|
31372
|
-
if (this.#playMode !== null) params["x-bc-play-mode"] = this.#playMode;
|
|
31373
|
-
const switchMiscount = data.switchMiscount ?? this.#switchMiscount;
|
|
31374
|
-
if (switchMiscount > 0) params["x-bc-switch-miscount"] = switchMiscount;
|
|
31375
|
-
this.#emit(params);
|
|
31839
|
+
this.#heartbeat();
|
|
31376
31840
|
}
|
|
31377
|
-
/**
|
|
31378
|
-
* Signal a transport transition event. Fires an immediate out-of-band
|
|
31379
|
-
* emit with x-bc-ct set. The subsequent onSnapshot() will NOT include
|
|
31380
|
-
* x-bc-ct (one-shot).
|
|
31381
|
-
*/
|
|
31841
|
+
/** Report a transport transition at once, as custom event `com.blockcast-ct`. */
|
|
31382
31842
|
onTransition(event) {
|
|
31383
|
-
const
|
|
31384
|
-
|
|
31385
|
-
|
|
31843
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "ct" };
|
|
31844
|
+
putCustom(record, "ct", token(event));
|
|
31845
|
+
this.#putTransport(record);
|
|
31846
|
+
this.#post([record]);
|
|
31847
|
+
}
|
|
31848
|
+
#base(event) {
|
|
31849
|
+
return { e: token(event), sid: this.#sessionId, sn: this.#sn++, ts: Math.floor(this.#now()), v: 2 };
|
|
31850
|
+
}
|
|
31851
|
+
#heartbeat() {
|
|
31852
|
+
const now = this.#now();
|
|
31853
|
+
if (this.#lastHeartbeat !== null && now - this.#lastHeartbeat < this.#intervalMs) return;
|
|
31854
|
+
this.#lastHeartbeat = now;
|
|
31855
|
+
this.#post([this.#base("t"), this.#counters()]);
|
|
31856
|
+
}
|
|
31857
|
+
#putTransport(record) {
|
|
31858
|
+
const snap = this.#transport;
|
|
31859
|
+
if (!snap) return;
|
|
31860
|
+
putCustom(record, "tr", token(TRANSPORT_TOKEN[snap.transport]));
|
|
31861
|
+
if (snap.multicastGroup != null && snap.multicastSource != null) {
|
|
31862
|
+
putCustom(record, "sg", `${snap.multicastGroup}@${snap.multicastSource}`);
|
|
31863
|
+
}
|
|
31864
|
+
putCustom(record, "ar", snap.amtRelay);
|
|
31865
|
+
}
|
|
31866
|
+
/** The `e=ce` counter report. */
|
|
31867
|
+
#counters() {
|
|
31868
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "fec" };
|
|
31869
|
+
const stats = this.#lastStats;
|
|
31870
|
+
if (stats) {
|
|
31871
|
+
putCustom(record, "fa", stats.config.algorithm);
|
|
31872
|
+
putCustom(record, "fk", stats.config.k);
|
|
31873
|
+
putCustom(record, "fp", stats.config.repairCount);
|
|
31874
|
+
putCustom(record, "pr", stats.sourceSymbols);
|
|
31875
|
+
putCustom(record, "pl", stats.sourcePacketsMissing);
|
|
31876
|
+
putCustom(record, "pu", stats.sourcePacketsUnrecovered);
|
|
31877
|
+
putCustom(record, "fbf", stats.blocksFailed);
|
|
31878
|
+
}
|
|
31879
|
+
if (this.#lifecycle) {
|
|
31880
|
+
putCustom(record, "fbr", this.#lifecycle.inband);
|
|
31881
|
+
putCustom(record, "fbq", this.#lifecycle.fetch);
|
|
31882
|
+
putCustom(record, "fbfk", this.#lifecycle.failedKeyframe);
|
|
31883
|
+
}
|
|
31884
|
+
this.#putTransport(record);
|
|
31885
|
+
if (this.#playMode !== null) {
|
|
31886
|
+
putCustom(record, "pm", token(this.#playMode));
|
|
31887
|
+
if (this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
31888
|
+
putCustom(record, "dfr", this.#deltaFailRate.toFixed(3));
|
|
31889
|
+
}
|
|
31890
|
+
}
|
|
31891
|
+
if (this.#fecFailClosed) {
|
|
31892
|
+
putCustom(record, "ffc", token(this.#fecFailClosed.code));
|
|
31893
|
+
putCustom(record, "ffl", this.#fecFailClosed.layer);
|
|
31894
|
+
}
|
|
31895
|
+
if (this.#switchMiscount > 0) putCustom(record, "sm", this.#switchMiscount);
|
|
31896
|
+
if (this.#manifestStats) {
|
|
31897
|
+
putCustom(record, "mv", this.#manifestStats.verified);
|
|
31898
|
+
putCustom(record, "mf", Object.values(this.#manifestStats.failures).reduce((a, b) => a + b, 0));
|
|
31386
31899
|
}
|
|
31387
|
-
|
|
31388
|
-
params["x-bc-ct"] = event;
|
|
31389
|
-
this.#emit(params);
|
|
31900
|
+
return record;
|
|
31390
31901
|
}
|
|
31391
|
-
|
|
31392
|
-
|
|
31393
|
-
this.#onCmcdParams?.(params);
|
|
31394
|
-
this.#onCmcdPost?.(formatQueryString(params));
|
|
31902
|
+
#post(records) {
|
|
31903
|
+
this.#onCmcdPost?.(records.map(encodeCmcdRecord).join("\n"));
|
|
31395
31904
|
}
|
|
31396
31905
|
};
|
|
31397
31906
|
|
|
@@ -31487,6 +31996,19 @@ function resolveRepairLayers(catalog, source) {
|
|
|
31487
31996
|
totalBaseRepairSymbols: binding.totalBaseRepairSymbols
|
|
31488
31997
|
};
|
|
31489
31998
|
}
|
|
31999
|
+
function valueAt(catalog, pointer) {
|
|
32000
|
+
let node = catalog;
|
|
32001
|
+
for (const segment of pointer.split("/").slice(1)) {
|
|
32002
|
+
if (typeof node !== "object" || node === null) return void 0;
|
|
32003
|
+
node = node[segment.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
32004
|
+
}
|
|
32005
|
+
return node;
|
|
32006
|
+
}
|
|
32007
|
+
function catalogTrackDeliveryMode(catalog, source) {
|
|
32008
|
+
const binding = bindingOf(catalog, source);
|
|
32009
|
+
const entry = binding ? valueAt(catalog, binding.pointer) : void 0;
|
|
32010
|
+
return entry?.deliveryMode === "stream" ? "stream" : "datagram";
|
|
32011
|
+
}
|
|
31490
32012
|
function moqtPriority2(value) {
|
|
31491
32013
|
return Number.isSafeInteger(value) && value >= 0 && value <= 255 ? value : null;
|
|
31492
32014
|
}
|
|
@@ -31530,6 +32052,7 @@ function fecParams(catalog, track, fps, sampleRate) {
|
|
|
31530
32052
|
repairTrackName: base.repairTrack,
|
|
31531
32053
|
repairLayers: repair.baseLayers,
|
|
31532
32054
|
repairOverlays: repair.overlays,
|
|
32055
|
+
deliveryMode: catalogTrackDeliveryMode(catalog, track),
|
|
31533
32056
|
...mediaRate
|
|
31534
32057
|
};
|
|
31535
32058
|
}
|
|
@@ -32054,7 +32577,7 @@ var RepairLayerSubscriptions = class {
|
|
|
32054
32577
|
* or interleaved sequences read as loss.
|
|
32055
32578
|
*/
|
|
32056
32579
|
noteSourceSequence(seq) {
|
|
32057
|
-
if (this.#disposed || this.#
|
|
32580
|
+
if (this.#disposed || this.#delivery() === "stream") return;
|
|
32058
32581
|
seq >>>= 0;
|
|
32059
32582
|
if (this.#lastSeq === void 0) {
|
|
32060
32583
|
this.#lastSeq = seq;
|
|
@@ -32087,12 +32610,12 @@ var RepairLayerSubscriptions = class {
|
|
|
32087
32610
|
this.#expected = 0;
|
|
32088
32611
|
this.#lost = 0;
|
|
32089
32612
|
this.#wantFewer = 0;
|
|
32090
|
-
this.#layerCount = Math.min(this.#layerCount, this.#layers().length);
|
|
32613
|
+
this.#layerCount = this.#delivery() === "stream" ? 0 : Math.min(this.#layerCount, this.#layers().length);
|
|
32091
32614
|
this.#reconcile();
|
|
32092
32615
|
}
|
|
32093
32616
|
snapshot() {
|
|
32094
32617
|
return {
|
|
32095
|
-
delivery: this.#
|
|
32618
|
+
delivery: this.#delivery(),
|
|
32096
32619
|
layerCount: this.#layerCount,
|
|
32097
32620
|
subscribedTracks: [...this.#subs.keys()],
|
|
32098
32621
|
repairPackets: this.#repairPackets,
|
|
@@ -32106,6 +32629,9 @@ var RepairLayerSubscriptions = class {
|
|
|
32106
32629
|
this.#closeAll();
|
|
32107
32630
|
this.#disposed = true;
|
|
32108
32631
|
}
|
|
32632
|
+
#delivery() {
|
|
32633
|
+
return this.#source.deliveryMode === "stream" ? "stream" : "datagram";
|
|
32634
|
+
}
|
|
32109
32635
|
#layers() {
|
|
32110
32636
|
return this.#source.repairLayers ?? [];
|
|
32111
32637
|
}
|
|
@@ -32848,6 +33374,7 @@ export {
|
|
|
32848
33374
|
catalogGroupDurationMs,
|
|
32849
33375
|
catalogKeyframeCadenceMs,
|
|
32850
33376
|
catalogRepairTarget,
|
|
33377
|
+
catalogTrackDeliveryMode,
|
|
32851
33378
|
catalogTrackFecUnavailable,
|
|
32852
33379
|
classifyH264Keyframe,
|
|
32853
33380
|
classifyHevcKeyframe,
|
|
@@ -32868,6 +33395,7 @@ export {
|
|
|
32868
33395
|
detectH264Keyframe,
|
|
32869
33396
|
detectHevcKeyframe,
|
|
32870
33397
|
driftCheck,
|
|
33398
|
+
encodeCmcdRecord,
|
|
32871
33399
|
encodeDataSegment,
|
|
32872
33400
|
encodeFecSourceInfo,
|
|
32873
33401
|
encodeLocTimestamp,
|