@blockcast/mmt-container 0.4.0-main.d5ca55d82e33 → 0.4.0-main.d60c84364d2a
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 +1 -1
- package/dist/browser-runtime.js +173 -231
- package/dist/browser-runtime.js.map +4 -4
- package/dist/delivery-catalog.js +65 -222
- package/dist/delivery-catalog.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +72 -9
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +73 -10
- package/dist/mmtp-container-parser.no-modules.js.map +2 -2
- package/dist/mmtp-decode-pipeline.js +72 -9
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +11 -4
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +108 -9
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-manager.js +173 -231
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.js +65 -222
- package/dist/multicast-transport.js.map +3 -3
- package/dist/no-modules.js +72 -9
- package/dist/no-modules.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/wasm-mmtp-container-parser.js +72 -9
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +5 -5
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-router.ts +53 -5
- package/src/sample-combiner.ts +15 -2
package/README.md
CHANGED
|
@@ -135,7 +135,7 @@ if (hdr.packetType === 0x00) { // MPU
|
|
|
135
135
|
|
|
136
136
|
### MFU reassembler (`./mfu`)
|
|
137
137
|
|
|
138
|
-
Stateful reassembler for fragmented MFUs per ISO/IEC 23008-1:2023 §9.2.3.3 and the repository's contiguous-source producer profile. It partitions bounded continuation state by physical stream, MPU, and wrapping terminal source-packet sequence (`packet_sequence + fragment_counter`), queues FI=2/FI=3 by run and counter until FI=1 and any missing predecessor arrive, then propagates FI=1's intrinsic DU identity while draining the exact countdown. The terminal sequence is transport association only. ISO-permitted interleaving remains separated and incomplete; there is no scope, timestamp, SS_ID, or arrival-order fallback.
|
|
138
|
+
Stateful reassembler for fragmented MFUs per ISO/IEC 23008-1:2023 §9.2.3.3 and the repository's contiguous-source producer profile. It partitions bounded continuation state by physical stream, MPU, and wrapping terminal source-packet sequence (`packet_sequence + fragment_counter`), queues FI=2/FI=3 by run and counter until FI=1 and any missing predecessor arrive, then propagates FI=1's intrinsic DU identity while draining the exact countdown. The terminal sequence is transport association only. ISO-permitted interleaving remains separated and incomplete; there is no scope, timestamp, SS_ID, or arrival-order fallback. The router feeds a recovered packet under the wire u32 sequence its SS_ID maps to through the stream's received FEC sources, since a hop may re-stamp the sequence after protection.
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
141
|
interface MFUReassemblerOptions {
|
package/dist/browser-runtime.js
CHANGED
|
@@ -3894,8 +3894,14 @@ var SampleCombiner = class {
|
|
|
3894
3894
|
/**
|
|
3895
3895
|
* Add one reassembled data unit. Returns the combined sample once every
|
|
3896
3896
|
* constituent data unit has arrived and totals the authored size.
|
|
3897
|
+
*
|
|
3898
|
+
* `sampleSize` is the authored size the host resolves for the sample as the
|
|
3899
|
+
* data unit completes. It stands in only when no size was registered, which
|
|
3900
|
+
* happens when the data unit's FI=0/FI=1 reached the reassembler without the
|
|
3901
|
+
* host's own FT=2 parse: an FEC-recovered first fragment completed by source
|
|
3902
|
+
* fragments, or one decoded before its source copy arrived.
|
|
3897
3903
|
*/
|
|
3898
|
-
addMfu(mfu) {
|
|
3904
|
+
addMfu(mfu, sampleSize) {
|
|
3899
3905
|
if (mfu.movieFragmentSequenceNumber === void 0 || mfu.sampleNumber === void 0) {
|
|
3900
3906
|
this.#stats.passthroughSamples++;
|
|
3901
3907
|
return fromPassthrough(mfu);
|
|
@@ -3911,7 +3917,7 @@ var SampleCombiner = class {
|
|
|
3911
3917
|
return null;
|
|
3912
3918
|
}
|
|
3913
3919
|
const dataLen = mfu.data.byteLength;
|
|
3914
|
-
const authoredSize = this.#authoredSizes.get(key);
|
|
3920
|
+
const authoredSize = this.#authoredSizes.get(key) ?? sampleSize;
|
|
3915
3921
|
if (offset === 0 && !this.#pending.has(key)) {
|
|
3916
3922
|
const passesThrough = authoredSize === void 0 ? !this.#requireAuthoredSize : dataLen === authoredSize;
|
|
3917
3923
|
if (passesThrough) {
|
|
@@ -4205,6 +4211,12 @@ if (void 0) {
|
|
|
4205
4211
|
const out = c.addMfu(mfu(1, 9, 17, 5, [6, 7, 8, 9, 10], 1001n, false));
|
|
4206
4212
|
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
|
|
4207
4213
|
});
|
|
4214
|
+
test("a size handed with the data unit completes a sample no head registered", () => {
|
|
4215
|
+
const c = combiner({ requireAuthoredSize: true });
|
|
4216
|
+
const out = c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5);
|
|
4217
|
+
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
|
|
4218
|
+
expect(c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5)).toBeNull();
|
|
4219
|
+
});
|
|
4208
4220
|
test("duplicate offset is rejected", () => {
|
|
4209
4221
|
const c = combiner();
|
|
4210
4222
|
c.registerAuthoredSize(void 0, 1, 9, 17, 10);
|
|
@@ -6963,181 +6975,6 @@ var MoqFecAlgorithm;
|
|
|
6963
6975
|
MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
|
|
6964
6976
|
})(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
|
|
6965
6977
|
|
|
6966
|
-
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
6967
|
-
var MPU_HEADER_SIZE2 = 8;
|
|
6968
|
-
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
6969
|
-
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
6970
|
-
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
6971
|
-
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
6972
|
-
|
|
6973
|
-
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
6974
|
-
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
6975
|
-
|
|
6976
|
-
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
6977
|
-
var NTP_SHORT_BITS2 = 32;
|
|
6978
|
-
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
6979
|
-
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
6980
|
-
function isNtpShort(value) {
|
|
6981
|
-
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
6982
|
-
}
|
|
6983
|
-
function compareNtpShort(a, b) {
|
|
6984
|
-
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
6985
|
-
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
6986
|
-
}
|
|
6987
|
-
if (a === b)
|
|
6988
|
-
return "equal";
|
|
6989
|
-
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
6990
|
-
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
6991
|
-
return "after";
|
|
6992
|
-
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
6993
|
-
return "before";
|
|
6994
|
-
return "unordered";
|
|
6995
|
-
}
|
|
6996
|
-
|
|
6997
|
-
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
6998
|
-
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
6999
|
-
"iso-ssbg1-v1"
|
|
7000
|
-
]);
|
|
7001
|
-
|
|
7002
|
-
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
7003
|
-
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
7004
|
-
|
|
7005
|
-
// node_modules/@blockcast/mmt-transport/dist/driad-discovery.js
|
|
7006
|
-
var DRIADDiscovery = class {
|
|
7007
|
-
cache = /* @__PURE__ */ new Map();
|
|
7008
|
-
cacheExpiry = 3e5;
|
|
7009
|
-
// 5 minutes
|
|
7010
|
-
/**
|
|
7011
|
-
* Discover AMT relays for a multicast source address (RFC 8777)
|
|
7012
|
-
*
|
|
7013
|
-
* @param source - The multicast source IP address (NOT the group!)
|
|
7014
|
-
* @returns Array of discovered AMT relays that can tunnel traffic from this source
|
|
7015
|
-
*/
|
|
7016
|
-
async discoverRelays(source) {
|
|
7017
|
-
const cached = this.cache.get(source);
|
|
7018
|
-
if (cached) {
|
|
7019
|
-
return cached;
|
|
7020
|
-
}
|
|
7021
|
-
try {
|
|
7022
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
7023
|
-
const queryDomain = `${reversedSource}.amt.in-addr.arpa`;
|
|
7024
|
-
console.log(`[DRIAD] Discovering relays for source ${source} via ${queryDomain}`);
|
|
7025
|
-
const relays = await this.queryDRIADProxy(source);
|
|
7026
|
-
if (relays.length > 0) {
|
|
7027
|
-
this.cache.set(source, relays);
|
|
7028
|
-
setTimeout(() => this.cache.delete(source), this.cacheExpiry);
|
|
7029
|
-
}
|
|
7030
|
-
return relays;
|
|
7031
|
-
} catch (error) {
|
|
7032
|
-
console.warn(`[DRIAD] Discovery failed for source ${source}:`, error);
|
|
7033
|
-
return [];
|
|
7034
|
-
}
|
|
7035
|
-
}
|
|
7036
|
-
/**
|
|
7037
|
-
* Query DRIAD proxy service (browser-compatible)
|
|
7038
|
-
*/
|
|
7039
|
-
async queryDRIADProxy(source) {
|
|
7040
|
-
const proxyEndpoints = [
|
|
7041
|
-
"https://driad.amt.net/api/v1/relays",
|
|
7042
|
-
"https://multicast-gateway.cloudflare.com/driad"
|
|
7043
|
-
];
|
|
7044
|
-
for (const endpoint of proxyEndpoints) {
|
|
7045
|
-
try {
|
|
7046
|
-
const response = await fetch(`${endpoint}?source=${encodeURIComponent(source)}`, {
|
|
7047
|
-
method: "GET",
|
|
7048
|
-
headers: { Accept: "application/json" },
|
|
7049
|
-
signal: AbortSignal.timeout(5e3)
|
|
7050
|
-
});
|
|
7051
|
-
if (response.ok) {
|
|
7052
|
-
const data = await response.json();
|
|
7053
|
-
return data.relays || [];
|
|
7054
|
-
}
|
|
7055
|
-
} catch {
|
|
7056
|
-
}
|
|
7057
|
-
}
|
|
7058
|
-
const dohRelay = await this.queryDNSOverHTTPS(source);
|
|
7059
|
-
if (dohRelay) {
|
|
7060
|
-
return [dohRelay];
|
|
7061
|
-
}
|
|
7062
|
-
return [];
|
|
7063
|
-
}
|
|
7064
|
-
/**
|
|
7065
|
-
* Query DNS-over-HTTPS for DRIAD relay based on source address (RFC 8777)
|
|
7066
|
-
*/
|
|
7067
|
-
async queryDNSOverHTTPS(source) {
|
|
7068
|
-
try {
|
|
7069
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
7070
|
-
const queryName = `${reversedSource}.amt.in-addr.arpa`;
|
|
7071
|
-
const dohUrl = `https://cloudflare-dns.com/dns-query?name=${queryName}&type=A`;
|
|
7072
|
-
const response = await fetch(dohUrl, {
|
|
7073
|
-
headers: { Accept: "application/dns-json" },
|
|
7074
|
-
signal: AbortSignal.timeout(3e3)
|
|
7075
|
-
});
|
|
7076
|
-
if (!response.ok) {
|
|
7077
|
-
return null;
|
|
7078
|
-
}
|
|
7079
|
-
const result = await response.json();
|
|
7080
|
-
if (result.Answer && result.Answer.length > 0) {
|
|
7081
|
-
return {
|
|
7082
|
-
host: result.Answer[0].data,
|
|
7083
|
-
port: DEFAULT_AMT_RELAY_PORT2,
|
|
7084
|
-
priority: 10,
|
|
7085
|
-
weight: 100,
|
|
7086
|
-
asn: 0
|
|
7087
|
-
};
|
|
7088
|
-
}
|
|
7089
|
-
return null;
|
|
7090
|
-
} catch (error) {
|
|
7091
|
-
console.warn("[DRIAD] DNS-over-HTTPS query failed:", error);
|
|
7092
|
-
return null;
|
|
7093
|
-
}
|
|
7094
|
-
}
|
|
7095
|
-
/**
|
|
7096
|
-
* Select best relay based on RTT measurements
|
|
7097
|
-
*/
|
|
7098
|
-
async selectBestRelay(relays) {
|
|
7099
|
-
if (relays.length === 0)
|
|
7100
|
-
return null;
|
|
7101
|
-
const measured = await Promise.all(relays.map(async (relay) => {
|
|
7102
|
-
const rtt = await this.measureRTT(relay.host, relay.port);
|
|
7103
|
-
return { ...relay, rtt };
|
|
7104
|
-
}));
|
|
7105
|
-
measured.sort((a, b) => {
|
|
7106
|
-
if (a.priority !== b.priority)
|
|
7107
|
-
return a.priority - b.priority;
|
|
7108
|
-
return (a.rtt || Infinity) - (b.rtt || Infinity);
|
|
7109
|
-
});
|
|
7110
|
-
console.log(`[DRIAD] Selected relay: ${measured[0].host} (RTT: ${measured[0].rtt}ms)`);
|
|
7111
|
-
return measured[0];
|
|
7112
|
-
}
|
|
7113
|
-
async measureRTT(host, _port) {
|
|
7114
|
-
const start = performance.now();
|
|
7115
|
-
try {
|
|
7116
|
-
await fetch(`https://${host}/health`, {
|
|
7117
|
-
method: "HEAD",
|
|
7118
|
-
signal: AbortSignal.timeout(2e3),
|
|
7119
|
-
mode: "no-cors"
|
|
7120
|
-
});
|
|
7121
|
-
return performance.now() - start;
|
|
7122
|
-
} catch {
|
|
7123
|
-
return Infinity;
|
|
7124
|
-
}
|
|
7125
|
-
}
|
|
7126
|
-
/**
|
|
7127
|
-
* Clear the relay cache
|
|
7128
|
-
*/
|
|
7129
|
-
clearCache() {
|
|
7130
|
-
this.cache.clear();
|
|
7131
|
-
}
|
|
7132
|
-
/**
|
|
7133
|
-
* Get cached relays for a source address
|
|
7134
|
-
*/
|
|
7135
|
-
getCached(source) {
|
|
7136
|
-
return this.cache.get(source);
|
|
7137
|
-
}
|
|
7138
|
-
};
|
|
7139
|
-
var driadDiscovery = new DRIADDiscovery();
|
|
7140
|
-
|
|
7141
6978
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
7142
6979
|
function endpointKey(endpoint) {
|
|
7143
6980
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -7345,6 +7182,45 @@ var AdaptiveBitrateController = class {
|
|
|
7345
7182
|
}
|
|
7346
7183
|
};
|
|
7347
7184
|
|
|
7185
|
+
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
7186
|
+
var MPU_HEADER_SIZE2 = 8;
|
|
7187
|
+
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
7188
|
+
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
7189
|
+
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
7190
|
+
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
7191
|
+
|
|
7192
|
+
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
7193
|
+
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
7194
|
+
|
|
7195
|
+
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
7196
|
+
var NTP_SHORT_BITS2 = 32;
|
|
7197
|
+
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
7198
|
+
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
7199
|
+
function isNtpShort(value) {
|
|
7200
|
+
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
7201
|
+
}
|
|
7202
|
+
function compareNtpShort(a, b) {
|
|
7203
|
+
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
7204
|
+
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
7205
|
+
}
|
|
7206
|
+
if (a === b)
|
|
7207
|
+
return "equal";
|
|
7208
|
+
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
7209
|
+
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
7210
|
+
return "after";
|
|
7211
|
+
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
7212
|
+
return "before";
|
|
7213
|
+
return "unordered";
|
|
7214
|
+
}
|
|
7215
|
+
|
|
7216
|
+
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
7217
|
+
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
7218
|
+
"iso-ssbg1-v1"
|
|
7219
|
+
]);
|
|
7220
|
+
|
|
7221
|
+
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
7222
|
+
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
7223
|
+
|
|
7348
7224
|
// node_modules/@blockcast/mmt-transport/dist/multicast-orchestrator.js
|
|
7349
7225
|
var DEFAULT_DWELL_MS = 3e3;
|
|
7350
7226
|
var DEFAULT_JOIN_DEADLINE_MS = 5e3;
|
|
@@ -7651,7 +7527,8 @@ function normalizeMulticastEndpoint(endpoint) {
|
|
|
7651
7527
|
port: endpoint.port,
|
|
7652
7528
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7653
7529
|
...amtRelay ? { amtRelay } : {},
|
|
7654
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7530
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7531
|
+
...endpoint.amtDiscovery === "driad" ? { amtDiscovery: "driad" } : {}
|
|
7655
7532
|
};
|
|
7656
7533
|
}
|
|
7657
7534
|
function multicastEndpointKey(endpoint) {
|
|
@@ -7664,7 +7541,9 @@ function multicastEndpointKey(endpoint) {
|
|
|
7664
7541
|
normalized.port,
|
|
7665
7542
|
normalized.mode ?? "auto",
|
|
7666
7543
|
normalized.amtRelay ?? "",
|
|
7667
|
-
normalized.amtRelayPort ?? ""
|
|
7544
|
+
normalized.amtRelayPort ?? "",
|
|
7545
|
+
// A DRIAD join is a different gateway subscription from a native one.
|
|
7546
|
+
...normalized.amtDiscovery ? [normalized.amtDiscovery] : []
|
|
7668
7547
|
]);
|
|
7669
7548
|
}
|
|
7670
7549
|
function isMulticastTrackPacketId(value) {
|
|
@@ -7704,7 +7583,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7704
7583
|
port: config.port,
|
|
7705
7584
|
mode: config.mode,
|
|
7706
7585
|
amtRelay: config.amtRelay,
|
|
7707
|
-
amtRelayPort: config.amtRelayPort
|
|
7586
|
+
amtRelayPort: config.amtRelayPort,
|
|
7587
|
+
amtDiscovery: config.amtDiscovery
|
|
7708
7588
|
});
|
|
7709
7589
|
if (!endpoint)
|
|
7710
7590
|
throw new Error("Invalid multicast endpoint");
|
|
@@ -7770,7 +7650,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7770
7650
|
port: endpoint.port,
|
|
7771
7651
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7772
7652
|
...endpoint.amtRelay ? { amtRelay: endpoint.amtRelay } : {},
|
|
7773
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7653
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7654
|
+
...endpoint.amtDiscovery ? { amtDiscovery: endpoint.amtDiscovery } : {}
|
|
7774
7655
|
}));
|
|
7775
7656
|
const consumers = /* @__PURE__ */ new Map();
|
|
7776
7657
|
let entry;
|
|
@@ -7850,7 +7731,6 @@ var TransportManager = class {
|
|
|
7850
7731
|
};
|
|
7851
7732
|
capabilities = null;
|
|
7852
7733
|
subscription = null;
|
|
7853
|
-
driad = new DRIADDiscovery();
|
|
7854
7734
|
/** Built by `connect()` from the caller's ladder; there is no built-in one. */
|
|
7855
7735
|
abr = null;
|
|
7856
7736
|
multicastOrchestrator = null;
|
|
@@ -7900,8 +7780,8 @@ var TransportManager = class {
|
|
|
7900
7780
|
nativeIGMP: hasGatewayBytes,
|
|
7901
7781
|
directSockets: typeof win?.UDPSocket !== "undefined",
|
|
7902
7782
|
amt: false,
|
|
7903
|
-
driad:
|
|
7904
|
-
//
|
|
7783
|
+
driad: hasGatewayBytes,
|
|
7784
|
+
// the gateway runs RFC 8777 discovery
|
|
7905
7785
|
fecDecode: false
|
|
7906
7786
|
};
|
|
7907
7787
|
console.log("[Transport] Capabilities:", this.capabilities);
|
|
@@ -7912,7 +7792,7 @@ var TransportManager = class {
|
|
|
7912
7792
|
*
|
|
7913
7793
|
* Promotion hierarchy:
|
|
7914
7794
|
* 1. window.multicast gateway bytes
|
|
7915
|
-
* 2. AMT
|
|
7795
|
+
* 2. AMT: a configured relay via the AMT proxy, else gateway DRIAD discovery
|
|
7916
7796
|
* 3. MOQ WebTransport (final fallback)
|
|
7917
7797
|
*
|
|
7918
7798
|
* The ABR ladder (`abrLadder`) and initial rendition (`initialQuality`)
|
|
@@ -8006,7 +7886,7 @@ var TransportManager = class {
|
|
|
8006
7886
|
/**
|
|
8007
7887
|
* Connect via the lowercase window.multicast bytes gateway.
|
|
8008
7888
|
*/
|
|
8009
|
-
async connectWindowMulticast(config, generation) {
|
|
7889
|
+
async connectWindowMulticast(config, generation, mode = "multicast") {
|
|
8010
7890
|
try {
|
|
8011
7891
|
const gateway = this.getWindowMulticastGateway();
|
|
8012
7892
|
if (typeof gateway?.subscribe !== "function")
|
|
@@ -8041,7 +7921,7 @@ var TransportManager = class {
|
|
|
8041
7921
|
}
|
|
8042
7922
|
};
|
|
8043
7923
|
this.state = {
|
|
8044
|
-
mode
|
|
7924
|
+
mode,
|
|
8045
7925
|
connected: true,
|
|
8046
7926
|
group: config.group,
|
|
8047
7927
|
source: config.source,
|
|
@@ -8059,29 +7939,19 @@ var TransportManager = class {
|
|
|
8059
7939
|
}
|
|
8060
7940
|
}
|
|
8061
7941
|
/**
|
|
8062
|
-
* Connect via AMT proxy
|
|
7942
|
+
* Connect via AMT: a configured relay goes through the AMT proxy; with no
|
|
7943
|
+
* relay, the window.multicast gateway discovers one per RFC 8777 (DRIAD).
|
|
8063
7944
|
*/
|
|
8064
7945
|
async connectAmt(config, generation) {
|
|
8065
7946
|
try {
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
const relays = await this.driad.discoverRelays(config.source);
|
|
8070
|
-
if (generation !== this.connectionGeneration)
|
|
8071
|
-
return false;
|
|
8072
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
8073
|
-
if (generation !== this.connectionGeneration)
|
|
8074
|
-
return false;
|
|
8075
|
-
if (bestRelay) {
|
|
8076
|
-
amtRelay = bestRelay.host;
|
|
8077
|
-
this.state.amtRelay = amtRelay;
|
|
8078
|
-
}
|
|
8079
|
-
}
|
|
8080
|
-
if (!amtRelay) {
|
|
7947
|
+
if (config.amtRelay)
|
|
7948
|
+
return await this.connectAmtProxy(config, config.amtRelay, generation);
|
|
7949
|
+
if (config.driadEnabled === false || !config.source || config.mode === "native") {
|
|
8081
7950
|
console.warn("[Transport] No AMT relay available (DRIAD requires source address for SSM)");
|
|
8082
7951
|
return false;
|
|
8083
7952
|
}
|
|
8084
|
-
|
|
7953
|
+
console.log(`[Transport] Asking the gateway for a DRIAD relay for source ${config.source}...`);
|
|
7954
|
+
return await this.connectWindowMulticast({ ...config, amtDiscovery: "driad" }, generation, "amt");
|
|
8085
7955
|
} catch (error) {
|
|
8086
7956
|
console.warn("[Transport] AMT connection failed:", error);
|
|
8087
7957
|
return false;
|
|
@@ -8312,7 +8182,6 @@ var AMTGatewayManager = class {
|
|
|
8312
8182
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8313
8183
|
messageHandler;
|
|
8314
8184
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
8315
|
-
driad = new DRIADDiscovery();
|
|
8316
8185
|
constructor() {
|
|
8317
8186
|
this.messageHandler = (event) => {
|
|
8318
8187
|
const data = event.data;
|
|
@@ -8343,26 +8212,12 @@ var AMTGatewayManager = class {
|
|
|
8343
8212
|
return keyStr;
|
|
8344
8213
|
}
|
|
8345
8214
|
try {
|
|
8346
|
-
|
|
8347
|
-
let discoveryMethod;
|
|
8215
|
+
const relayAddress = config.relayAddress;
|
|
8348
8216
|
const relayPort = config.relayPort || DEFAULT_AMT_RELAY_PORT2;
|
|
8349
|
-
if (
|
|
8350
|
-
|
|
8351
|
-
discoveryMethod = "manual";
|
|
8352
|
-
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8353
|
-
} else if (key.source) {
|
|
8354
|
-
console.log(`[AMT] No relay configured, discovering via DRIAD for source ${key.source}...`);
|
|
8355
|
-
const relays = await this.driad.discoverRelays(key.source);
|
|
8356
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
8357
|
-
if (!bestRelay) {
|
|
8358
|
-
throw new Error(`AMT relay discovery failed for source ${key.source}. Please specify a relay address in the subscription configuration.`);
|
|
8359
|
-
}
|
|
8360
|
-
relayAddress = bestRelay.host;
|
|
8361
|
-
discoveryMethod = "driad";
|
|
8362
|
-
console.log(`[AMT] Discovered relay via DRIAD: ${relayAddress}:${relayPort}`);
|
|
8363
|
-
} else {
|
|
8364
|
-
throw new Error(`AMT relay discovery requires a source address for SSM (RFC 8777). Please specify either a relay address or source address.`);
|
|
8217
|
+
if (!relayAddress) {
|
|
8218
|
+
throw new Error(`AMT relay address required: this manager does no relay discovery. For RFC 8777 DRIAD discovery, join through window.multicast with amtDiscovery: "driad".`);
|
|
8365
8219
|
}
|
|
8220
|
+
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8366
8221
|
const subscriptionId = keyStr;
|
|
8367
8222
|
this.pendingPackets.set(subscriptionId, []);
|
|
8368
8223
|
const subscription = {
|
|
@@ -8373,7 +8228,7 @@ var AMTGatewayManager = class {
|
|
|
8373
8228
|
relay: {
|
|
8374
8229
|
address: relayAddress,
|
|
8375
8230
|
port: relayPort,
|
|
8376
|
-
discoveryMethod,
|
|
8231
|
+
discoveryMethod: "manual",
|
|
8377
8232
|
discoveredAt: Date.now()
|
|
8378
8233
|
}
|
|
8379
8234
|
};
|
|
@@ -17424,6 +17279,7 @@ function isFmp4Box(data) {
|
|
|
17424
17279
|
const type = String.fromCharCode(data[4], data[5], data[6], data[7]);
|
|
17425
17280
|
return FMPU_BOX_TYPES.has(type);
|
|
17426
17281
|
}
|
|
17282
|
+
var MAX_AWAITING_TIMING_HEADS = 8;
|
|
17427
17283
|
var MmtpContainerParser = class _MmtpContainerParser {
|
|
17428
17284
|
constructor(config) {
|
|
17429
17285
|
this.#tracks = /* @__PURE__ */ new Map();
|
|
@@ -17482,6 +17338,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17482
17338
|
* reordering into the parser. */
|
|
17483
17339
|
this.#reliableMoqStartupGate = /* @__PURE__ */ new Map();
|
|
17484
17340
|
this.#disposed = false;
|
|
17341
|
+
this.#replayingAwaitingTiming = false;
|
|
17485
17342
|
this.#fedObjects = 0;
|
|
17486
17343
|
this.#reassemblerFragmentsFed = 0;
|
|
17487
17344
|
this.#reassemblerDataUnitsReturned = 0;
|
|
@@ -17574,6 +17431,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17574
17431
|
#reorderStats;
|
|
17575
17432
|
#reliableMoqStartupGate;
|
|
17576
17433
|
#disposed;
|
|
17434
|
+
#replayingAwaitingTiming;
|
|
17577
17435
|
#fedObjects;
|
|
17578
17436
|
#reassemblerFragmentsFed;
|
|
17579
17437
|
#reassemblerDataUnitsReturned;
|
|
@@ -17823,7 +17681,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17823
17681
|
* a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
|
|
17824
17682
|
*/
|
|
17825
17683
|
#drop(reason) {
|
|
17826
|
-
this.#
|
|
17684
|
+
if (this.#replayingAwaitingTiming) this.#countDeferredOutcome(reason);
|
|
17685
|
+
else this.#countOutcome(`drop:${reason}`);
|
|
17827
17686
|
return null;
|
|
17828
17687
|
}
|
|
17829
17688
|
get reorderDiagnostics() {
|
|
@@ -17846,6 +17705,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17846
17705
|
for (const combiner of this.#sampleCombiners.values()) {
|
|
17847
17706
|
combiner.cleanupTimeouts(timeoutMs);
|
|
17848
17707
|
}
|
|
17708
|
+
const now = Date.now();
|
|
17709
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
17710
|
+
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
17711
|
+
awaitingTiming.shift();
|
|
17712
|
+
}
|
|
17713
|
+
}
|
|
17849
17714
|
}
|
|
17850
17715
|
/**
|
|
17851
17716
|
* Phase 1 of two-phase parsing. Returns structured header info for FEC feeding.
|
|
@@ -17926,7 +17791,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17926
17791
|
byteLength: packet.byteLength
|
|
17927
17792
|
};
|
|
17928
17793
|
}
|
|
17929
|
-
if (info.fecPayloadId !== null && this.#sourceSymbolCb) {
|
|
17794
|
+
if (info.fecPayloadId !== null && this.#sourceSymbolCb && !this.#replayingAwaitingTiming) {
|
|
17930
17795
|
const rawSymbol = packet.subarray(0, packet.length - 4);
|
|
17931
17796
|
try {
|
|
17932
17797
|
this.#sourceSymbolCb(info.packetId, info.fecPayloadId.ssId, rawSymbol);
|
|
@@ -17974,6 +17839,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17974
17839
|
}
|
|
17975
17840
|
return this.#drop("fragment-timing-refused");
|
|
17976
17841
|
}
|
|
17842
|
+
this.#replayAwaitingTiming(streamKey, resolver2);
|
|
17977
17843
|
return {
|
|
17978
17844
|
kind: "fragment",
|
|
17979
17845
|
packet: info,
|
|
@@ -17997,7 +17863,18 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17997
17863
|
mfuDuHeader.movieFragmentSequenceNumber,
|
|
17998
17864
|
mfuDuHeader.sampleNumber
|
|
17999
17865
|
);
|
|
18000
|
-
if (!headTiming)
|
|
17866
|
+
if (!headTiming) {
|
|
17867
|
+
this.#awaitTiming(streamKey, {
|
|
17868
|
+
packet,
|
|
17869
|
+
options,
|
|
17870
|
+
parsed,
|
|
17871
|
+
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
17872
|
+
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
17873
|
+
sampleNumber: mfuDuHeader.sampleNumber,
|
|
17874
|
+
arrivedAt: Date.now()
|
|
17875
|
+
});
|
|
17876
|
+
return this.#drop("mfu-sample-timing-missing");
|
|
17877
|
+
}
|
|
18001
17878
|
const offset = mfuDuHeader.offset;
|
|
18002
17879
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset >= headTiming.size)
|
|
18003
17880
|
return this.#drop("mfu-offset-out-of-range");
|
|
@@ -18073,16 +17950,17 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18073
17950
|
const sampleNumber = assembled.sampleNumber;
|
|
18074
17951
|
if (movieFragmentSequenceNumber === void 0 || sampleNumber === void 0)
|
|
18075
17952
|
return this.#drop("assembled-identity-missing");
|
|
18076
|
-
|
|
17953
|
+
const assembledTiming = resolver.sampleTiming(
|
|
18077
17954
|
assembled.mpuSequenceNumber,
|
|
18078
17955
|
movieFragmentSequenceNumber,
|
|
18079
17956
|
sampleNumber
|
|
18080
|
-
)
|
|
17957
|
+
);
|
|
17958
|
+
if (!assembledTiming) return this.#drop("assembled-timing-missing");
|
|
18081
17959
|
if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
|
|
18082
17960
|
return this.#drop("assembled-mpu-mismatch");
|
|
18083
17961
|
let combined;
|
|
18084
17962
|
try {
|
|
18085
|
-
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled);
|
|
17963
|
+
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled, assembledTiming.size);
|
|
18086
17964
|
} catch (error) {
|
|
18087
17965
|
if (!(error instanceof SampleCombineError)) throw error;
|
|
18088
17966
|
console.warn(
|
|
@@ -18391,9 +18269,37 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18391
18269
|
if (existing) return existing.resolver;
|
|
18392
18270
|
if (!create) return null;
|
|
18393
18271
|
const resolver = new IsoBmffTimingResolver(this.#maxPendingTimingSamples);
|
|
18394
|
-
this.#timingStreams.set(streamKey, { packetId, resolver });
|
|
18272
|
+
this.#timingStreams.set(streamKey, { packetId, resolver, awaitingTiming: [] });
|
|
18395
18273
|
return resolver;
|
|
18396
18274
|
}
|
|
18275
|
+
#awaitTiming(streamKey, head) {
|
|
18276
|
+
const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming;
|
|
18277
|
+
if (!awaitingTiming) return;
|
|
18278
|
+
awaitingTiming.push(head);
|
|
18279
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
|
|
18280
|
+
}
|
|
18281
|
+
/**
|
|
18282
|
+
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
18283
|
+
* FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
|
|
18284
|
+
* FEC path routes a source symbol that already arrived a second time.
|
|
18285
|
+
*/
|
|
18286
|
+
#replayAwaitingTiming(streamKey, resolver) {
|
|
18287
|
+
const state = this.#timingStreams.get(streamKey);
|
|
18288
|
+
if (!state || state.awaitingTiming.length === 0) return;
|
|
18289
|
+
const ready = state.awaitingTiming.filter((head) => resolver.sampleTiming(
|
|
18290
|
+
head.mpuSequenceNumber,
|
|
18291
|
+
head.movieFragmentSequenceNumber,
|
|
18292
|
+
head.sampleNumber
|
|
18293
|
+
));
|
|
18294
|
+
if (ready.length === 0) return;
|
|
18295
|
+
state.awaitingTiming = state.awaitingTiming.filter((head) => !ready.includes(head));
|
|
18296
|
+
this.#replayingAwaitingTiming = true;
|
|
18297
|
+
try {
|
|
18298
|
+
for (const head of ready) this.#feed(head.packet, head.options, head.parsed);
|
|
18299
|
+
} finally {
|
|
18300
|
+
this.#replayingAwaitingTiming = false;
|
|
18301
|
+
}
|
|
18302
|
+
}
|
|
18397
18303
|
#dropTimingStream(streamKey) {
|
|
18398
18304
|
const state = this.#timingStreams.get(streamKey);
|
|
18399
18305
|
if (!state) return;
|
|
@@ -18998,6 +18904,12 @@ var MmtpRouter = class {
|
|
|
18998
18904
|
// MSE recovery routes through CmafBlockAssembler and can reorder by block; the
|
|
18999
18905
|
// direct callback path has to preserve decode order before frames leave libmmt.
|
|
19000
18906
|
#latestVideoSeqByStream = /* @__PURE__ */ new Map();
|
|
18907
|
+
/**
|
|
18908
|
+
* Per stream, SS_ID - packet_sequence_number (mod 2^32) of its latest
|
|
18909
|
+
* first-arrival FEC source packet. A recovered source symbol's wire
|
|
18910
|
+
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
18911
|
+
*/
|
|
18912
|
+
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19001
18913
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
19002
18914
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
19003
18915
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -19072,6 +18984,7 @@ var MmtpRouter = class {
|
|
|
19072
18984
|
*/
|
|
19073
18985
|
#onPublisherRestart;
|
|
19074
18986
|
#publisherRestarts = 0;
|
|
18987
|
+
#restampedRecoveredSeqs = 0;
|
|
19075
18988
|
/** Inits delivered with no onTrackInit handler for their packetId (MOQT-01). */
|
|
19076
18989
|
#unmappedInitDeliveries = 0;
|
|
19077
18990
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
@@ -19292,6 +19205,14 @@ var MmtpRouter = class {
|
|
|
19292
19205
|
get publisherRestartCount() {
|
|
19293
19206
|
return this.#publisherRestarts;
|
|
19294
19207
|
}
|
|
19208
|
+
/**
|
|
19209
|
+
* FEC-recovered source symbols whose reconstructed header named a
|
|
19210
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to:
|
|
19211
|
+
* a hop re-stamped the sequence after the sender protected the packet.
|
|
19212
|
+
*/
|
|
19213
|
+
get restampedRecoveredSequenceCount() {
|
|
19214
|
+
return this.#restampedRecoveredSeqs;
|
|
19215
|
+
}
|
|
19295
19216
|
/**
|
|
19296
19217
|
* Packets whose Source or Repair FEC Payload ID was left unread because
|
|
19297
19218
|
* their (owner) packetId had no configured `fec.blockProfile`: FEC not
|
|
@@ -19936,6 +19857,7 @@ var MmtpRouter = class {
|
|
|
19936
19857
|
this.#trackSynced.delete(streamKey);
|
|
19937
19858
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19938
19859
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
19860
|
+
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
19939
19861
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19940
19862
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
19941
19863
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -20706,6 +20628,12 @@ var MmtpRouter = class {
|
|
|
20706
20628
|
} else if (fecUnreadable && info.fecPayloadId) {
|
|
20707
20629
|
parseSourceSymbol = !duplicates.parsedSymbols.has(info.fecPayloadId.ssId);
|
|
20708
20630
|
}
|
|
20631
|
+
if (fecPayloadId && !overlapCopy) {
|
|
20632
|
+
this.#ssIdSeqOffsetByStream.set(
|
|
20633
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
20634
|
+
fecPayloadId.ssId - info.sequenceNumber >>> 0
|
|
20635
|
+
);
|
|
20636
|
+
}
|
|
20709
20637
|
if (!this.#fecManager || !info.fecPayloadId || parseSourceSymbol) {
|
|
20710
20638
|
if (this.#fecManager && info.fecPayloadId) {
|
|
20711
20639
|
duplicates.parsedSymbols.add(info.fecPayloadId.ssId);
|
|
@@ -21282,6 +21210,20 @@ var MmtpRouter = class {
|
|
|
21282
21210
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
|
|
21283
21211
|
if (ownerPacketId == null) return;
|
|
21284
21212
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
21213
|
+
const ssIdSeqOffset = this.#ssIdSeqOffsetByStream.get(
|
|
21214
|
+
this.#mediaStreamKey(ownerPacketId, catalogTrackName)
|
|
21215
|
+
);
|
|
21216
|
+
if (ssIdSeqOffset !== void 0) {
|
|
21217
|
+
result = {
|
|
21218
|
+
...result,
|
|
21219
|
+
symbols: result.symbols.map((sym) => {
|
|
21220
|
+
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
21221
|
+
if (wire === sym.packetSequenceNumber) return sym;
|
|
21222
|
+
this.#restampedRecoveredSeqs++;
|
|
21223
|
+
return { ...sym, packetSequenceNumber: wire };
|
|
21224
|
+
})
|
|
21225
|
+
};
|
|
21226
|
+
}
|
|
21285
21227
|
this.#stream(ownerPacketId, catalogTrackName).duplicates.advance(blockId);
|
|
21286
21228
|
const deliveryProvenance = this.#fecManager?.blockDeliveryProvenance?.(
|
|
21287
21229
|
blockId,
|