@blockcast/mmt-container 2.2.0-main.f480a7ede8b1 → 2.2.0-main.fde7aee36726
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 +5 -2
- package/dist/block-policy.d.ts +88 -16
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +164 -56
- package/dist/block-policy.js.map +3 -3
- package/dist/browser-runtime.js +2163 -303
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +40 -1
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +163 -10
- package/dist/carp-catalog.js.map +4 -4
- package/dist/catalog-fec-params.d.ts +1 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +48 -1
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.js +34 -0
- package/dist/catalog-network-source.js.map +3 -3
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +68 -0
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/delta-fallback-config.js +39 -1
- package/dist/delta-fallback-config.js.map +4 -4
- package/dist/fec-manager.d.ts +222 -21
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +875 -131
- package/dist/fec-manager.js.map +4 -4
- package/dist/fec-state.d.ts +17 -5
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +41 -1
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.js +34 -0
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/held-layer-admission.js +34 -0
- package/dist/held-layer-admission.js.map +3 -3
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +55 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +142 -25
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/media-router.js.map +1 -1
- package/dist/mfu-reassembler.js +34 -0
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts +72 -10
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +260 -18
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +411 -34
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +260 -18
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- package/dist/mmtp-fec-session.js +34 -0
- package/dist/mmtp-fec-session.js.map +3 -3
- package/dist/mmtp-mode-selection.d.ts +48 -0
- package/dist/mmtp-mode-selection.d.ts.map +1 -0
- package/dist/mmtp-mode-selection.js +79 -0
- package/dist/mmtp-mode-selection.js.map +7 -0
- package/dist/mmtp-router.d.ts +94 -16
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +754 -78
- package/dist/mmtp-router.js.map +4 -4
- package/dist/multicast-auth-catalog.js +42 -2
- package/dist/multicast-auth-catalog.js.map +3 -3
- package/dist/multicast-input.js +42 -2
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +121 -4
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1774 -248
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.js +70 -2
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +34 -0
- package/dist/multicast-unwrap.js.map +3 -3
- package/dist/no-modules.d.ts +1 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +415 -35
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +2 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +69 -2
- package/dist/phase14-catalog-override.js.map +3 -3
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +336 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.js +34 -0
- package/dist/repair-layer-subscriptions.js.map +3 -3
- package/dist/signaling.js +34 -0
- package/dist/signaling.js.map +3 -3
- package/dist/timestamp-codec.js +34 -0
- package/dist/timestamp-codec.js.map +3 -3
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js +34 -0
- package/dist/wasm-mfu-reassembler.js.map +3 -3
- package/dist/wasm-mmtp-container-parser.js +260 -18
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/package.json +5 -5
- package/schemas/catalog.schema.json +2 -2
- package/src/block-policy.ts +324 -83
- package/src/carp-catalog.ts +165 -5
- package/src/catalog-fec-params.ts +1 -0
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +835 -66
- package/src/fec-state.ts +21 -5
- package/src/index.ts +25 -0
- package/src/iso-block-locator.ts +148 -31
- package/src/mmtp-container-parser.ts +259 -24
- package/src/mmtp-mode-selection.ts +80 -0
- package/src/mmtp-router.ts +774 -86
- package/src/multicast-manager.ts +262 -16
- package/src/no-modules.ts +3 -0
- package/src/phase14-catalog-override.ts +14 -3
- package/src/repair-fetch.ts +389 -50
- package/src/track-session.ts +3 -0
- package/test-vectors/catalog/README.md +36 -2
- package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
- package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
- package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
- package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
- package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
- package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
- package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
- package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
- package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
- package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
- package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
- package/test-vectors/catalog/section-codes.json +3 -3
- package/test-vectors/catalog-validation.json +266 -7
- package/test-vectors/moq/mmtp-mode-selection.json +259 -0
package/dist/repair-fetch.js
CHANGED
|
@@ -1,13 +1,131 @@
|
|
|
1
1
|
// ../mmt-base/dist/mmtp.js
|
|
2
|
+
var MMTP_HEADER_SIZE = 12;
|
|
2
3
|
var MPU_HEADER_SIZE = 8;
|
|
3
4
|
var MPU_LENGTH_FIELD_SIZE = 2;
|
|
4
5
|
var MPU_HEADER_REMAINDER_SIZE = MPU_HEADER_SIZE - MPU_LENGTH_FIELD_SIZE;
|
|
6
|
+
var PACKET_TYPE_REPAIR = 3;
|
|
7
|
+
function parseMMTPHeader(buffer) {
|
|
8
|
+
if (buffer.length < MMTP_HEADER_SIZE) {
|
|
9
|
+
throw new Error(`MMTP packet too small: ${buffer.length} bytes`);
|
|
10
|
+
}
|
|
11
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
12
|
+
const version = buffer[0] >> 6 & 3;
|
|
13
|
+
if (version !== 0) {
|
|
14
|
+
throw new Error(`Unsupported MMTP version: ${version}`);
|
|
15
|
+
}
|
|
16
|
+
const fecType = buffer[0] >> 3 & 3;
|
|
17
|
+
const packetCounterFlag = (buffer[0] & 32) !== 0;
|
|
18
|
+
const extensionFlag = (buffer[0] & 2) !== 0;
|
|
19
|
+
const rapFlag = (buffer[0] & 1) === 1;
|
|
20
|
+
const packetType = buffer[1] & 63;
|
|
21
|
+
let offset = 2;
|
|
22
|
+
const packetId = view.getUint16(offset, false);
|
|
23
|
+
offset += 2;
|
|
24
|
+
const timestamp = BigInt(view.getUint32(offset, false));
|
|
25
|
+
offset += 4;
|
|
26
|
+
const sequenceNumber = view.getUint32(offset, false);
|
|
27
|
+
offset += 4;
|
|
28
|
+
let packetCounter;
|
|
29
|
+
if (packetCounterFlag) {
|
|
30
|
+
if (offset + 4 > buffer.length)
|
|
31
|
+
throw new Error("MMTP packet truncated in packet_counter");
|
|
32
|
+
packetCounter = view.getUint32(offset, false);
|
|
33
|
+
offset += 4;
|
|
34
|
+
}
|
|
35
|
+
let extension;
|
|
36
|
+
if (extensionFlag) {
|
|
37
|
+
if (offset + 4 > buffer.length)
|
|
38
|
+
throw new Error("MMTP packet truncated in header extension");
|
|
39
|
+
const type = view.getUint16(offset, false);
|
|
40
|
+
const length = view.getUint16(offset + 2, false);
|
|
41
|
+
offset += 4;
|
|
42
|
+
if (offset + length > buffer.length)
|
|
43
|
+
throw new Error("MMTP packet truncated in header extension value");
|
|
44
|
+
extension = { type, data: buffer.subarray(offset, offset + length) };
|
|
45
|
+
offset += length;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
version,
|
|
49
|
+
packetType,
|
|
50
|
+
packetId,
|
|
51
|
+
timestamp,
|
|
52
|
+
sequenceNumber,
|
|
53
|
+
payloadLength: buffer.length - offset,
|
|
54
|
+
fecType,
|
|
55
|
+
packetCounterFlag,
|
|
56
|
+
packetCounter,
|
|
57
|
+
extensionFlag,
|
|
58
|
+
extension,
|
|
59
|
+
headerLength: offset,
|
|
60
|
+
rapFlag
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
64
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
65
|
+
let header;
|
|
66
|
+
if (parsedHeader) {
|
|
67
|
+
header = parsedHeader;
|
|
68
|
+
} else {
|
|
69
|
+
try {
|
|
70
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
76
|
+
return null;
|
|
77
|
+
const off = header.headerLength;
|
|
78
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
79
|
+
return null;
|
|
80
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
81
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
82
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
83
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
84
|
+
return {
|
|
85
|
+
packetId: header.packetId,
|
|
86
|
+
ssStart,
|
|
87
|
+
rsbLength,
|
|
88
|
+
rsId,
|
|
89
|
+
ssbLength,
|
|
90
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function extractRepairFecPayloadId(mmtpPacket) {
|
|
94
|
+
const fields = readRepairFecPayloadIdFields(mmtpPacket);
|
|
95
|
+
if (!fields)
|
|
96
|
+
return null;
|
|
97
|
+
return {
|
|
98
|
+
ssStart: fields.ssStart,
|
|
99
|
+
rsbLength: fields.rsbLength,
|
|
100
|
+
rsId: fields.rsId,
|
|
101
|
+
ssbLength: fields.ssbLength
|
|
102
|
+
};
|
|
103
|
+
}
|
|
5
104
|
|
|
6
105
|
// ../mmt-base/dist/ntp-short.js
|
|
7
106
|
var NTP_SHORT_BITS = 32;
|
|
8
107
|
var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
|
|
9
108
|
var NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
|
|
10
109
|
|
|
110
|
+
// ../mmt-base/dist/serial-number.js
|
|
111
|
+
var SERIAL32_SPAN = 4294967296;
|
|
112
|
+
var SERIAL32_HALF = 2147483648;
|
|
113
|
+
function assertUint32(value, name) {
|
|
114
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
115
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function serial32Add(s, n) {
|
|
119
|
+
assertUint32(s, "s");
|
|
120
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
121
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
122
|
+
}
|
|
123
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
124
|
+
}
|
|
125
|
+
function serial32Distance(from, to) {
|
|
126
|
+
return to - from >>> 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
11
129
|
// ../mmt-base/dist/fec-block-profile.js
|
|
12
130
|
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
13
131
|
"iso-ssbg1-v1"
|
|
@@ -31,6 +149,40 @@ var RUNTIME_FEC_RECEIVER = Object.freeze({
|
|
|
31
149
|
overlays: true
|
|
32
150
|
});
|
|
33
151
|
|
|
152
|
+
// ../mmt-base/dist/mmtp-siblings.js
|
|
153
|
+
var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
|
|
154
|
+
var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
|
|
155
|
+
"namespace",
|
|
156
|
+
"timescale",
|
|
157
|
+
"presentationAnchorTicks",
|
|
158
|
+
"groupDuration"
|
|
159
|
+
]);
|
|
160
|
+
var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
|
|
161
|
+
"codec",
|
|
162
|
+
"width",
|
|
163
|
+
"height",
|
|
164
|
+
"framerate",
|
|
165
|
+
"bitrate",
|
|
166
|
+
"samplerate",
|
|
167
|
+
"channelConfig",
|
|
168
|
+
"lang"
|
|
169
|
+
]);
|
|
170
|
+
var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
|
|
171
|
+
"initRef",
|
|
172
|
+
"keyframeIntervalMs",
|
|
173
|
+
"keyframeIntervalTicks",
|
|
174
|
+
"isLive",
|
|
175
|
+
"altGroup"
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
// ../mmt-base/dist/datagram-leg-size.js
|
|
179
|
+
var DATAGRAM_LEG_UDP_FLOOR = 1200;
|
|
180
|
+
var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
|
|
181
|
+
var DATAGRAM_LEG_OBJECT_HEADER = 13;
|
|
182
|
+
var DATAGRAM_LEG_RELAY_ROOM = 16;
|
|
183
|
+
var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
|
|
184
|
+
var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
|
|
185
|
+
|
|
34
186
|
// src/repair-fetch.ts
|
|
35
187
|
import { extendSsId, repairFetchRange } from "@blockcast/mmt-fec";
|
|
36
188
|
|
|
@@ -53,6 +205,7 @@ var REPAIR_PRIORITY_MIN = 192;
|
|
|
53
205
|
|
|
54
206
|
// src/repair-fetch.ts
|
|
55
207
|
var MOQT_PRIORITY_MAX = 255;
|
|
208
|
+
var WALK_LEAD_MS = 3;
|
|
56
209
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
57
210
|
function isMoqtPriority(value) {
|
|
58
211
|
return Number.isSafeInteger(value) && value >= 0 && value <= MOQT_PRIORITY_MAX;
|
|
@@ -103,8 +256,17 @@ function wireRepairFetch(mc, opts) {
|
|
|
103
256
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
104
257
|
};
|
|
105
258
|
const clearEntry = (entry) => {
|
|
106
|
-
|
|
107
|
-
|
|
259
|
+
const { range } = entry;
|
|
260
|
+
if (range) {
|
|
261
|
+
atReport(range, () => mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, range.holeLength));
|
|
262
|
+
} else {
|
|
263
|
+
clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const atReport = (range, work) => {
|
|
267
|
+
const fec = mc.fecManager;
|
|
268
|
+
if (range.groups !== null || fec.withReceiptTime === void 0) work();
|
|
269
|
+
else fec.withReceiptTime(range.reportedAt, work);
|
|
108
270
|
};
|
|
109
271
|
const releaseHold = (entry) => {
|
|
110
272
|
if (entry.range) return;
|
|
@@ -116,7 +278,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
116
278
|
if (!run) return;
|
|
117
279
|
entry.running = null;
|
|
118
280
|
run.stopped = reason;
|
|
119
|
-
run.controller.abort();
|
|
281
|
+
run.controller.abort(reason);
|
|
120
282
|
if (reason === "preempted") releaseHold(entry);
|
|
121
283
|
mc.noteRepairStopped?.(reason, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
122
284
|
};
|
|
@@ -171,21 +333,42 @@ function wireRepairFetch(mc, opts) {
|
|
|
171
333
|
const admit = (entry, now) => {
|
|
172
334
|
const budgetMs = entry.deadlineAt - now;
|
|
173
335
|
const rttMs = readRtt();
|
|
174
|
-
const reason =
|
|
336
|
+
const reason = refusal(entry, now, rttMs);
|
|
175
337
|
if (reason === null) return rttMs;
|
|
176
338
|
skip(entry, reason, rttMs, budgetMs);
|
|
177
339
|
return null;
|
|
178
340
|
};
|
|
341
|
+
const refusal = (entry, now, rttMs) => !entry.range && !groupCanComplete(entry.sbn, entry.packetId, entry.catalogTrackName) ? "group-cannot-complete" : rttMs === null ? "rtt-unmeasured" : rttMs < entry.deadlineAt - now ? null : "rtt-exceeds-budget";
|
|
179
342
|
const retire = (entry) => {
|
|
180
343
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
181
344
|
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
182
345
|
};
|
|
183
|
-
const
|
|
346
|
+
const holdsBack = (entry, priority, videoWalks = true) => {
|
|
347
|
+
if (entry.priority >= priority) return false;
|
|
348
|
+
const { walk } = entry;
|
|
349
|
+
if (walk === void 0) return true;
|
|
350
|
+
if (entry.priority !== 0 || !videoWalks) return false;
|
|
351
|
+
return entry.running === null || walk.group !== null && !walk.group.controller.signal.aborted;
|
|
352
|
+
};
|
|
353
|
+
const outstandingBelow = (priority, videoWalks = true) => {
|
|
184
354
|
for (const entry of entries.values()) {
|
|
185
|
-
if (entry
|
|
355
|
+
if (holdsBack(entry, priority, videoWalks)) return true;
|
|
186
356
|
}
|
|
187
357
|
return false;
|
|
188
358
|
};
|
|
359
|
+
const yieldVideoWalks = (queued) => {
|
|
360
|
+
const now = performance.now();
|
|
361
|
+
const rttMs = readRtt();
|
|
362
|
+
const due = queued.some((entry) => entry.priority !== 0 && entry.walk === void 0 && !outstandingBelow(entry.priority, false) && refusal(entry, now, rttMs) === null);
|
|
363
|
+
if (!due) return;
|
|
364
|
+
for (const entry of entries.values()) {
|
|
365
|
+
const walk = entry.walk;
|
|
366
|
+
if (entry.priority !== 0 || walk === void 0 || walk.group === null) continue;
|
|
367
|
+
if (walk.group.controller.signal.aborted) continue;
|
|
368
|
+
walk.yielded = true;
|
|
369
|
+
walk.group.controller.abort();
|
|
370
|
+
}
|
|
371
|
+
};
|
|
189
372
|
const preemptBestEffort = () => {
|
|
190
373
|
for (const entry of entries.values()) {
|
|
191
374
|
if (entry.priority === 0 || !entry.running) continue;
|
|
@@ -214,7 +397,8 @@ function wireRepairFetch(mc, opts) {
|
|
|
214
397
|
}
|
|
215
398
|
const rttMs = admit(entry, now);
|
|
216
399
|
if (rttMs === null) return;
|
|
217
|
-
if (entry.priority === 0) preemptBestEffort();
|
|
400
|
+
if (entry.priority === 0 && entry.walk === void 0) preemptBestEffort();
|
|
401
|
+
if (entry.range === void 0) leaveWalkedGroup(entry);
|
|
218
402
|
if (counted) entry.attempts++;
|
|
219
403
|
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
220
404
|
rttMs,
|
|
@@ -236,6 +420,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
236
420
|
}
|
|
237
421
|
void execute(entry, run);
|
|
238
422
|
};
|
|
423
|
+
const leaveWalkedGroup = (block) => {
|
|
424
|
+
for (const entry of entries.values()) {
|
|
425
|
+
const group = entry.walk?.group;
|
|
426
|
+
if (group?.sbn === block.sbn && entry.packetId === block.packetId && entry.catalogTrackName === block.catalogTrackName) {
|
|
427
|
+
group.controller.abort();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
239
431
|
const dispatch = () => {
|
|
240
432
|
if (disposed) return;
|
|
241
433
|
const now = performance.now();
|
|
@@ -260,6 +452,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
260
452
|
for (const entry of queued) {
|
|
261
453
|
if (entry.priority === 0) start(entry);
|
|
262
454
|
}
|
|
455
|
+
yieldVideoWalks(queued);
|
|
263
456
|
if (outstandingBelow(1)) return;
|
|
264
457
|
for (const entry of queued) {
|
|
265
458
|
if (entry.priority === 1) start(entry);
|
|
@@ -286,6 +479,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
286
479
|
}
|
|
287
480
|
return counts.sources + counts.repairGroupLength >= counts.authoredLength;
|
|
288
481
|
};
|
|
482
|
+
const groupServed = (sbn, packetId, catalogTrackName) => {
|
|
483
|
+
if (mc.fecManager.blockSymbolCounts === void 0) return false;
|
|
484
|
+
const counts = symbolCounts(sbn, packetId, catalogTrackName);
|
|
485
|
+
if (counts === void 0 || counts.authoredLength === void 0) return true;
|
|
486
|
+
return counts.sources + counts.repairs >= counts.authoredLength || !groupCanComplete(sbn, packetId, catalogTrackName);
|
|
487
|
+
};
|
|
488
|
+
const statedEnd = (sbn, packetId, catalogTrackName) => {
|
|
489
|
+
const length = symbolCounts(sbn, packetId, catalogTrackName)?.authoredLength;
|
|
490
|
+
return length === void 0 ? void 0 : serial32Add(sbn, length);
|
|
491
|
+
};
|
|
289
492
|
const finish = (entry, run, fed, error) => {
|
|
290
493
|
if (run.stopped !== null || entry.running !== run || entries.get(entry.key) !== entry) {
|
|
291
494
|
return;
|
|
@@ -330,27 +533,81 @@ function wireRepairFetch(mc, opts) {
|
|
|
330
533
|
signal: run.controller.signal,
|
|
331
534
|
subscriberPriority: entry.subscriberPriority
|
|
332
535
|
};
|
|
536
|
+
const { range } = entry;
|
|
537
|
+
const feed = (packet) => {
|
|
538
|
+
if (entry.catalogTrackName === void 0) {
|
|
539
|
+
mc.processRepairFromMoQ(packet, entry.packetId);
|
|
540
|
+
} else {
|
|
541
|
+
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
333
544
|
try {
|
|
334
|
-
const packets = entry.
|
|
545
|
+
const packets = range === void 0 ? opts.transport({ ...common, sbn: entry.sbn }) : entry.walk !== void 0 ? walkHole(entry, entry.walk, range, common) : opts.rangeTransport({
|
|
335
546
|
...common,
|
|
336
|
-
startGroup:
|
|
337
|
-
endGroup:
|
|
338
|
-
lostSsId:
|
|
339
|
-
})
|
|
547
|
+
startGroup: range.groups.startGroup,
|
|
548
|
+
endGroup: range.groups.endGroup,
|
|
549
|
+
lostSsId: range.lostSsId
|
|
550
|
+
});
|
|
340
551
|
for await (const packet of packets) {
|
|
341
552
|
if (run.stopped !== null || entry.running !== run) break;
|
|
342
553
|
fed++;
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
} else {
|
|
346
|
-
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
347
|
-
}
|
|
554
|
+
if (range === void 0) feed(packet);
|
|
555
|
+
else atReport(range, () => feed(packet));
|
|
348
556
|
}
|
|
349
557
|
finish(entry, run, fed, void 0);
|
|
350
558
|
} catch (error) {
|
|
351
559
|
finish(entry, run, fed, error ?? new Error("repair transport rejected"));
|
|
352
560
|
}
|
|
353
561
|
};
|
|
562
|
+
async function* walkHole(entry, walk, hole, common) {
|
|
563
|
+
const lostAt = serial32Distance(entry.sbn, hole.lostSsId);
|
|
564
|
+
for (let first = true; !common.signal.aborted; first = false) {
|
|
565
|
+
if (!first && entry.priority !== 0 && outstandingBelow(1)) {
|
|
566
|
+
stop(entry, "preempted");
|
|
567
|
+
note("repair-preempted", entry);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (!first && entry.priority === 0) {
|
|
571
|
+
dispatch();
|
|
572
|
+
if (common.signal.aborted) return;
|
|
573
|
+
}
|
|
574
|
+
const sbn = walk.next;
|
|
575
|
+
let next;
|
|
576
|
+
if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
|
|
577
|
+
const rsIds = /* @__PURE__ */ new Set();
|
|
578
|
+
const group = new AbortController();
|
|
579
|
+
const cancel = () => group.abort(common.signal.reason);
|
|
580
|
+
common.signal.addEventListener("abort", cancel, { once: true });
|
|
581
|
+
walk.group = { sbn, controller: group };
|
|
582
|
+
try {
|
|
583
|
+
for await (const packet of opts.transport({ ...common, sbn, signal: group.signal })) {
|
|
584
|
+
yield packet;
|
|
585
|
+
const id = extractRepairFecPayloadId(packet);
|
|
586
|
+
if (id === null || id.ssStart !== sbn || id.ssbLength === 0) continue;
|
|
587
|
+
next ??= serial32Add(sbn, id.ssbLength);
|
|
588
|
+
rsIds.add(id.rsId);
|
|
589
|
+
if (rsIds.size >= id.rsbLength || groupServed(sbn, entry.packetId, entry.catalogTrackName)) {
|
|
590
|
+
group.abort();
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
} catch (error) {
|
|
595
|
+
if (!group.signal.aborted || common.signal.aborted) throw error;
|
|
596
|
+
} finally {
|
|
597
|
+
common.signal.removeEventListener("abort", cancel);
|
|
598
|
+
walk.group = null;
|
|
599
|
+
}
|
|
600
|
+
if (walk.yielded) {
|
|
601
|
+
walk.yielded = false;
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
next ??= statedEnd(sbn, entry.packetId, entry.catalogTrackName);
|
|
606
|
+
if (next === void 0) return;
|
|
607
|
+
if (serial32Distance(entry.sbn, next) > lostAt) return;
|
|
608
|
+
walk.next = next;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
354
611
|
const removeResetObserver = mc.addTrackResetObserver((packetId, catalogTrackName) => {
|
|
355
612
|
for (const entry of [...entries.values()]) {
|
|
356
613
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
@@ -399,6 +656,22 @@ function wireRepairFetch(mc, opts) {
|
|
|
399
656
|
dispatch();
|
|
400
657
|
return;
|
|
401
658
|
}
|
|
659
|
+
if (event.type === "gap") {
|
|
660
|
+
if (event.action !== "stall" || event.reason !== "discontinuity") return;
|
|
661
|
+
const now = performance.now();
|
|
662
|
+
let expired = false;
|
|
663
|
+
for (const entry2 of [...entries.values()]) {
|
|
664
|
+
if (entry2.packetId !== event.stream.packetId) continue;
|
|
665
|
+
if (entry2.catalogTrackName !== (event.stream.catalogTrackName ?? void 0)) continue;
|
|
666
|
+
if (!entry2.running || entry2.deadlineAt > now) continue;
|
|
667
|
+
stop(entry2, "expired");
|
|
668
|
+
retire(entry2);
|
|
669
|
+
clearEntry(entry2);
|
|
670
|
+
expired = true;
|
|
671
|
+
}
|
|
672
|
+
if (expired) dispatch();
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
402
675
|
if (event.type !== "recovered" && event.type !== "failed") return;
|
|
403
676
|
const entry = entries.get(
|
|
404
677
|
requestKey(event.block.sbn, event.block.packetId, event.block.catalogTrackName ?? void 0)
|
|
@@ -546,7 +819,37 @@ function wireRepairFetch(mc, opts) {
|
|
|
546
819
|
throw error;
|
|
547
820
|
}
|
|
548
821
|
};
|
|
549
|
-
|
|
822
|
+
const trackKind = (packetId) => {
|
|
823
|
+
try {
|
|
824
|
+
return mc.fecManager.trackKindFor?.(packetId);
|
|
825
|
+
} catch {
|
|
826
|
+
return void 0;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
const walkDeadlineAt = (packetId, now, deadlineAt) => {
|
|
830
|
+
let repairDeadlineMs;
|
|
831
|
+
try {
|
|
832
|
+
repairDeadlineMs = mc.fecManager.repairDeadlineMsForPacket?.(packetId);
|
|
833
|
+
} catch {
|
|
834
|
+
repairDeadlineMs = void 0;
|
|
835
|
+
}
|
|
836
|
+
if (repairDeadlineMs === void 0 || !Number.isFinite(repairDeadlineMs)) return deadlineAt;
|
|
837
|
+
return Math.min(deadlineAt, now + repairDeadlineMs - WALK_LEAD_MS);
|
|
838
|
+
};
|
|
839
|
+
const onHoleExpired = (hole) => {
|
|
840
|
+
if (disposed) return false;
|
|
841
|
+
const entry = [...entries.values()].find((candidate) => candidate.walk !== void 0 && candidate.packetId === hole.packetId && candidate.catalogTrackName === hole.catalogTrackName && serial32Distance(candidate.sbn, hole.holeStart) < candidate.range.holeLength);
|
|
842
|
+
if (entry === void 0) return false;
|
|
843
|
+
queueMicrotask(() => {
|
|
844
|
+
if (entries.get(entry.key) !== entry) return;
|
|
845
|
+
retire(entry);
|
|
846
|
+
stop(entry, "expired");
|
|
847
|
+
clearEntry(entry);
|
|
848
|
+
dispatch();
|
|
849
|
+
});
|
|
850
|
+
return true;
|
|
851
|
+
};
|
|
852
|
+
if (mc.onUndelimitedLoss !== void 0 && mc.closeIsoHoles !== void 0) {
|
|
550
853
|
mc.onUndelimitedLoss((loss) => {
|
|
551
854
|
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
552
855
|
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
@@ -554,9 +857,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
554
857
|
const blockProfile = blockProfileOf(packetId);
|
|
555
858
|
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
556
859
|
if (!target) return close();
|
|
557
|
-
const
|
|
558
|
-
const
|
|
559
|
-
|
|
860
|
+
const walked = opts.rangeTransport === void 0;
|
|
861
|
+
const holeClass = walked && trackKind(packetId) === "audio" ? "audio" : "unknown";
|
|
862
|
+
const priority = repairPriorityForClass(holeClass);
|
|
863
|
+
const groups = walked ? null : rangeFor(loss, target.repairTrack);
|
|
864
|
+
if (!walked && groups === null) {
|
|
560
865
|
close();
|
|
561
866
|
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
562
867
|
return;
|
|
@@ -567,8 +872,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
567
872
|
packetId,
|
|
568
873
|
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
569
874
|
};
|
|
570
|
-
const wire = wirePriority(identity,
|
|
571
|
-
|
|
875
|
+
const wire = wirePriority(identity, holeClass);
|
|
876
|
+
if (wire === null) return close();
|
|
877
|
+
const now = performance.now();
|
|
878
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, now, holeClass);
|
|
572
879
|
if (deadline === null) {
|
|
573
880
|
close();
|
|
574
881
|
mc.noteRepairSkipped(
|
|
@@ -580,6 +887,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
580
887
|
);
|
|
581
888
|
return;
|
|
582
889
|
}
|
|
890
|
+
const deadlineAt = walked ? walkDeadlineAt(packetId, now, deadline.deadlineAt) : deadline.deadlineAt;
|
|
583
891
|
const entry = {
|
|
584
892
|
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
585
893
|
...identity,
|
|
@@ -587,15 +895,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
587
895
|
blockProfile,
|
|
588
896
|
priority,
|
|
589
897
|
subscriberPriority: wire.subscriberPriority,
|
|
590
|
-
deadlineAt
|
|
591
|
-
playoutDeadlineAt:
|
|
898
|
+
deadlineAt,
|
|
899
|
+
playoutDeadlineAt: deadlineAt - deadline.extensionMs,
|
|
592
900
|
anchorAt: deadline.anchorAt,
|
|
593
901
|
delayMs: deadline.delayMs,
|
|
594
902
|
bound: deadline.bound,
|
|
595
903
|
order: enqueueOrder++,
|
|
596
904
|
attempts: 0,
|
|
597
905
|
running: null,
|
|
598
|
-
range: {
|
|
906
|
+
range: { lostSsId: loss.lostSsId, holeLength, groups, reportedAt: now },
|
|
907
|
+
...walked ? { walk: { next: holeStart, group: null, yielded: false } } : {}
|
|
599
908
|
};
|
|
600
909
|
const previous = entries.get(entry.key);
|
|
601
910
|
if (previous) {
|
|
@@ -605,7 +914,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
605
914
|
entries.set(entry.key, entry);
|
|
606
915
|
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
607
916
|
dispatch();
|
|
608
|
-
});
|
|
917
|
+
}, onHoleExpired);
|
|
609
918
|
}
|
|
610
919
|
const removeRapObserver = mc.addRapCompleteObserver?.((packetId) => {
|
|
611
920
|
queueMicrotask(() => {
|