@blockcast/mmt-container 2.2.0-main.d62748c7847f → 2.2.0-main.d79fbb738dc0
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 +125 -2
- package/dist/__tests__/ad-creative-signer.d.ts +11 -0
- package/dist/__tests__/ad-creative-signer.d.ts.map +1 -0
- package/dist/ad-creative-record.d.ts +65 -0
- package/dist/ad-creative-record.d.ts.map +1 -0
- package/dist/ad-creative-record.js +2281 -0
- package/dist/ad-creative-record.js.map +7 -0
- package/dist/ad-creative-timeline.d.ts +102 -0
- package/dist/ad-creative-timeline.d.ts.map +1 -0
- package/dist/ad-creative-timeline.js +2529 -0
- package/dist/ad-creative-timeline.js.map +7 -0
- package/dist/block-policy.d.ts +110 -20
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +358 -102
- package/dist/block-policy.js.map +2 -2
- package/dist/browser-runtime.js +798 -175
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +1 -0
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +34 -0
- package/dist/carp-catalog.js.map +4 -4
- package/dist/catalog-fec-params.js.map +1 -1
- package/dist/cmaf-block-assembler.d.ts +10 -2
- package/dist/cmaf-block-assembler.d.ts.map +1 -1
- package/dist/cmaf-block-assembler.js +17 -8
- package/dist/cmaf-block-assembler.js.map +3 -3
- package/dist/conceal-timeline.d.ts +24 -1
- package/dist/conceal-timeline.d.ts.map +1 -1
- package/dist/conceal-timeline.js +201 -4
- package/dist/conceal-timeline.js.map +3 -3
- package/dist/event-timeline-mmtp.d.ts +17 -0
- package/dist/event-timeline-mmtp.d.ts.map +1 -0
- package/dist/event-timeline-mmtp.js +3117 -0
- package/dist/event-timeline-mmtp.js.map +7 -0
- package/dist/fec-manager.d.ts +19 -4
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +391 -117
- package/dist/fec-manager.js.map +2 -2
- package/dist/feed-gate.d.ts +114 -0
- package/dist/feed-gate.d.ts.map +1 -0
- package/dist/feed-gate.js +175 -0
- package/dist/feed-gate.js.map +7 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +16 -0
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +28 -0
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/mfu-reassembler.d.ts +2 -0
- package/dist/mfu-reassembler.d.ts.map +1 -1
- package/dist/mfu-reassembler.js +4 -2
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts +10 -0
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +58 -2
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +63 -5
- package/dist/mmtp-container-parser.no-modules.js.map +2 -2
- package/dist/mmtp-decode-pipeline.js +58 -2
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +18 -3
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +119 -29
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-manager.d.ts +14 -1
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +563 -171
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +44 -22
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +58 -2
- package/dist/no-modules.js.map +2 -2
- package/dist/repair-fetch.d.ts +7 -2
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +58 -2
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +17 -5
- package/schemas/catalog.schema.json +7 -2
- package/src/ad-creative-record.ts +276 -0
- package/src/ad-creative-timeline.ts +409 -0
- package/src/block-policy.ts +531 -155
- package/src/carp-catalog.ts +9 -0
- package/src/cmaf-block-assembler.ts +17 -0
- package/src/conceal-timeline.ts +60 -5
- package/src/event-timeline-mmtp.ts +55 -0
- package/src/fec-manager.ts +48 -15
- package/src/feed-gate.ts +295 -0
- package/src/index.ts +21 -0
- package/src/iso-bmff-timing.ts +33 -0
- package/src/mfu-reassembler.ts +4 -0
- package/src/mmtp-container-parser.ts +42 -0
- package/src/mmtp-router.ts +81 -17
- package/src/multicast-manager.ts +20 -0
- package/src/repair-fetch.ts +7 -2
- package/test-vectors/catalog/README.md +1 -0
- package/test-vectors/catalog/negative/event-timeline-empty-event-type.json +41 -0
- package/test-vectors/catalog/positive/event-timeline-ad-creative.json +41 -0
- package/test-vectors/catalog/positive/event-timeline-wallclock-no-depends.json +38 -0
- package/test-vectors/catalog/positive/multicast-event-timeline.json +81 -0
- package/test-vectors/catalog/section-codes.json +1 -0
- package/test-vectors/frame-needs-v1.json +295 -0
package/dist/block-policy.js
CHANGED
|
@@ -37,11 +37,13 @@ function deriveBlockClassifierGeometry(input) {
|
|
|
37
37
|
} else if (isPositiveFinite(input.keyframeIntervalMs)) {
|
|
38
38
|
keyframeInterval = { ticks: input.keyframeIntervalMs, timescale: 1e3 };
|
|
39
39
|
}
|
|
40
|
+
const groupDuration = isPositiveFinite(input.groupDurationMs) ? { groupDurationMs: input.groupDurationMs } : {};
|
|
40
41
|
const protect = (reason) => ({
|
|
41
42
|
trackKind: "video",
|
|
42
43
|
mode: "all-protected",
|
|
43
44
|
reason,
|
|
44
|
-
...keyframeInterval === void 0 ? {} : { keyframeInterval }
|
|
45
|
+
...keyframeInterval === void 0 ? {} : { keyframeInterval },
|
|
46
|
+
...groupDuration
|
|
45
47
|
});
|
|
46
48
|
if (!isPositiveFinite(input.framerate)) return protect("framerate-absent");
|
|
47
49
|
const framerate = input.framerate;
|
|
@@ -57,9 +59,24 @@ function deriveBlockClassifierGeometry(input) {
|
|
|
57
59
|
frameDurationMs,
|
|
58
60
|
interleaveUnits,
|
|
59
61
|
gopFrames,
|
|
60
|
-
keyframeInterval
|
|
62
|
+
keyframeInterval,
|
|
63
|
+
...groupDuration
|
|
61
64
|
};
|
|
62
65
|
}
|
|
66
|
+
function isPositiveSafeInteger(value) {
|
|
67
|
+
return Number.isSafeInteger(value) && value > 0;
|
|
68
|
+
}
|
|
69
|
+
function mpuRuleCatalogReason(geometry) {
|
|
70
|
+
const interval = geometry.keyframeInterval;
|
|
71
|
+
if (interval === void 0 || !isPositiveSafeInteger(interval.ticks) || !isPositiveSafeInteger(interval.timescale)) {
|
|
72
|
+
return "keyframe-interval-absent";
|
|
73
|
+
}
|
|
74
|
+
const groupMs = geometry.groupDurationMs;
|
|
75
|
+
if (!isPositiveFinite(groupMs)) return "group-duration-absent";
|
|
76
|
+
const { ticks, timescale } = interval;
|
|
77
|
+
const equal = Number.isSafeInteger(groupMs) ? BigInt(ticks) * 1000n === BigInt(groupMs) * BigInt(timescale) : Math.abs(ticks / timescale * 1e3 - groupMs) <= 2 * Number.EPSILON * groupMs;
|
|
78
|
+
return equal ? null : "keyframe-interval-not-group-duration";
|
|
79
|
+
}
|
|
63
80
|
function keyframeIntervalMediaTicks(geometry, mediaTimescale) {
|
|
64
81
|
if (geometry.trackKind !== "video" || geometry.keyframeInterval === void 0) return null;
|
|
65
82
|
if (!Number.isSafeInteger(mediaTimescale) || mediaTimescale <= 0) return null;
|
|
@@ -87,6 +104,15 @@ function firstStartAtOrAfter(starts, sbn) {
|
|
|
87
104
|
}
|
|
88
105
|
return lo;
|
|
89
106
|
}
|
|
107
|
+
var ARRIVED_START_MAX = 4096;
|
|
108
|
+
function nextSampleHeader(headers, at) {
|
|
109
|
+
const of = headers[at];
|
|
110
|
+
for (let i = at + 1; i < headers.length; i++) {
|
|
111
|
+
const header = headers[i];
|
|
112
|
+
if (header.movieFragment !== of.movieFragment || header.idx !== of.idx) return header;
|
|
113
|
+
}
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
90
116
|
var LATE_RAP_MAX_MPUS_BACK = 64;
|
|
91
117
|
var UNPLACED = { rapNotMpuStart: false };
|
|
92
118
|
var BlockClassifier = class {
|
|
@@ -112,14 +138,49 @@ var BlockClassifier = class {
|
|
|
112
138
|
#dataUnitStarts = /* @__PURE__ */ new Map();
|
|
113
139
|
#highestMpu = null;
|
|
114
140
|
/**
|
|
115
|
-
* The DU headers held, per MPU in authored order, for the
|
|
141
|
+
* The DU headers held, per MPU in authored order, for the MPU rule. Kept in
|
|
116
142
|
* every mode (the rule needs no catalog cadence) for the same horizon and
|
|
117
143
|
* the same continuous SBN sequence as the P1 ledger.
|
|
118
144
|
*/
|
|
119
|
-
#
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
145
|
+
#headers = /* @__PURE__ */ new Map();
|
|
146
|
+
/**
|
|
147
|
+
* The source packets that arrived, per MPU. The MPU rule asks it whether
|
|
148
|
+
* every packet between two held DU headers arrived, and where. Same
|
|
149
|
+
* horizon as the headers.
|
|
150
|
+
*/
|
|
151
|
+
#arrived = /* @__PURE__ */ new Map();
|
|
152
|
+
#heldHighestMpu = null;
|
|
153
|
+
/** Two DU headers of this sequence lay in blocks against their authored order: the MPU rule proves nothing. */
|
|
154
|
+
#headerOrderRefuted = false;
|
|
155
|
+
/**
|
|
156
|
+
* A DU header held carried RAP_flag and was not of its MPU's first sample:
|
|
157
|
+
* not the first sample of its movie fragment, or in another movie fragment
|
|
158
|
+
* than the first DU header held of its MPU. This stream puts a RAP inside
|
|
159
|
+
* an MPU, and neither rule proves anything for the rest of the epoch. It is
|
|
160
|
+
* the MPU rule's own reading, in every DU-header layout and of rebuilt
|
|
161
|
+
* headers too. The first case is read on a header of an MPU behind the two
|
|
162
|
+
* kept as well. `mpuBoundsRaps`, which the stall or conceal decision reads,
|
|
163
|
+
* is set as before and not from here.
|
|
164
|
+
*/
|
|
165
|
+
#rapInsideMpu = false;
|
|
166
|
+
/** What the catalog lacks for the MPU rule, or null when it states a keyframe interval equal to the group duration. */
|
|
167
|
+
#mpuRuleCatalog = null;
|
|
168
|
+
/**
|
|
169
|
+
* The lowest and highest decode time known in an MPU, for the two MPUs of
|
|
170
|
+
* the highest numbers: those of the samples that held movie fragment
|
|
171
|
+
* metadata times (noteDecodeTimes). Valid within one MPU sequence, as the
|
|
172
|
+
* P1 ledger is; if MPU numbers go back with no source discontinuity, the
|
|
173
|
+
* new ones are not read until then, as their DU headers are not.
|
|
174
|
+
*/
|
|
175
|
+
#decodeSpans = /* @__PURE__ */ new Map();
|
|
176
|
+
/**
|
|
177
|
+
* An MPU held a sample one keyframe interval or more after another by
|
|
178
|
+
* decode time, so it lasts longer than the interval. A track of an earlier
|
|
179
|
+
* revision whose interval equals its group duration can hold a further RAP
|
|
180
|
+
* only in such an MPU: neither rule proves anything for the rest of the
|
|
181
|
+
* epoch.
|
|
182
|
+
*/
|
|
183
|
+
#mpuOutlastsInterval = false;
|
|
123
184
|
/**
|
|
124
185
|
* P3 layout, kept for the MPUs within the classification horizon and valid
|
|
125
186
|
* within one continuous SBN sequence (`noteSourceDiscontinuity`).
|
|
@@ -162,6 +223,20 @@ var BlockClassifier = class {
|
|
|
162
223
|
get mpuBoundsRaps() {
|
|
163
224
|
return this.#mpuBoundsRaps;
|
|
164
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Why the MPU rule classes no block on this track now, or null while it
|
|
228
|
+
* can. A catalog reason is known from the start of the epoch; the others
|
|
229
|
+
* name what the stream showed. A block the rule would have classed reads
|
|
230
|
+
* `unknown` under every one of them, and so does one the window rule would
|
|
231
|
+
* have classed, under every one but `du-headers-out-of-order`.
|
|
232
|
+
*/
|
|
233
|
+
get mpuRuleOff() {
|
|
234
|
+
if (this.#mpuRuleCatalog !== null) return this.#mpuRuleCatalog;
|
|
235
|
+
if (this.#rapInsideMpu) return "rap-inside-mpu";
|
|
236
|
+
if (this.#mpuOutlastsInterval) return "mpu-longer-than-keyframe-interval";
|
|
237
|
+
if (!this.#mpuBoundsRaps) return "mpu-bounds-raps-refuted";
|
|
238
|
+
return this.#headerOrderRefuted ? "du-headers-out-of-order" : null;
|
|
239
|
+
}
|
|
165
240
|
/** Begin a fresh epoch (catalog change or track reset). */
|
|
166
241
|
reset(geometry = this.#geometry) {
|
|
167
242
|
this.#geometry = geometry;
|
|
@@ -170,6 +245,9 @@ var BlockClassifier = class {
|
|
|
170
245
|
this.#clearMpuLayout();
|
|
171
246
|
this.#lastRap = null;
|
|
172
247
|
this.#mpuBoundsRaps = true;
|
|
248
|
+
this.#rapInsideMpu = false;
|
|
249
|
+
this.#mpuOutlastsInterval = false;
|
|
250
|
+
this.#mpuRuleCatalog = geometry.trackKind === "video" ? mpuRuleCatalogReason(geometry) : null;
|
|
173
251
|
if (geometry.trackKind === "video" && geometry.mode === "all-protected") {
|
|
174
252
|
this.#mode = "all-protected";
|
|
175
253
|
this.#reason = geometry.reason;
|
|
@@ -213,7 +291,7 @@ var BlockClassifier = class {
|
|
|
213
291
|
/**
|
|
214
292
|
* Register a block that exists without evidence of its own: a vanished
|
|
215
293
|
* block, or one only repair symbols state. The DU headers already held
|
|
216
|
-
* around it class it now (the
|
|
294
|
+
* around it class it now (the MPU rule); no later header need come between
|
|
217
295
|
* them to ask again.
|
|
218
296
|
*/
|
|
219
297
|
touch(sbn) {
|
|
@@ -229,12 +307,18 @@ var BlockClassifier = class {
|
|
|
229
307
|
if (this.#geometry.trackKind === "audio") return "audio";
|
|
230
308
|
return this.#blocks.get(sbn)?.cls ?? "unknown";
|
|
231
309
|
}
|
|
232
|
-
/**
|
|
233
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Record one first-arrival source symbol's evidence for block `sbn`.
|
|
312
|
+
* `ssId` is its FEC source symbol id (the block's SS_Start plus its ESI,
|
|
313
|
+
* ISO/IEC 23008-1 C.5.2). The publisher numbers the packets of the FEC
|
|
314
|
+
* flow with it, one each, so the MPU rule reads from it whether every
|
|
315
|
+
* packet between two DU headers arrived. Without it the rule's two
|
|
316
|
+
* exceptions prove nothing.
|
|
317
|
+
*/
|
|
318
|
+
observe(sbn, evidence, ssId) {
|
|
234
319
|
if (this.#geometry.trackKind === "audio") return [];
|
|
235
320
|
const changes = [];
|
|
236
321
|
const block = this.#blockFor(sbn);
|
|
237
|
-
const fragmentsCountedSamples = !this.#multiSampleFragment;
|
|
238
322
|
const placement = this.#place(evidence);
|
|
239
323
|
if (evidence.rap) block.rapSeen = true;
|
|
240
324
|
if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
|
|
@@ -243,28 +327,49 @@ var BlockClassifier = class {
|
|
|
243
327
|
block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
|
|
244
328
|
block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
|
|
245
329
|
}
|
|
246
|
-
if (placement.rapNotMpuStart) this.#
|
|
330
|
+
if (placement.rapNotMpuStart) this.#refuteMpuBounds(changes);
|
|
247
331
|
const violation = this.#checkInvariants(sbn, block, evidence, placement);
|
|
248
332
|
if (violation !== null) changes.push(...this.#disable(violation));
|
|
249
|
-
|
|
333
|
+
this.#noteArrived(sbn, evidence.mpu, ssId);
|
|
334
|
+
const bounds = this.#noteHeader(sbn, evidence, position, ssId, changes);
|
|
250
335
|
this.#reclassify(sbn, block, changes);
|
|
251
|
-
|
|
336
|
+
if (bounds) this.#reclassifyOthers(sbn, changes);
|
|
337
|
+
return changes;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* A first-arrival source symbol placed in a repair-less span (IsoBlockLocator:
|
|
341
|
+
* the SS_IDs between two stated blocks whose every repair was lost). A span
|
|
342
|
+
* is no block: it can hold several producer blocks, so nothing block-scoped
|
|
343
|
+
* is read from it (no record, P1, P2 or MPU-rule bound) and its blocks stay
|
|
344
|
+
* unknown. What its DU header says of its MPU (P3) still counts (BLO-57323).
|
|
345
|
+
*/
|
|
346
|
+
observeInSpan(evidence) {
|
|
347
|
+
if (this.#geometry.trackKind === "audio") return [];
|
|
348
|
+
const changes = [];
|
|
349
|
+
const placement = this.#place(evidence);
|
|
350
|
+
if (placement.rapNotMpuStart) this.#refuteMpuBounds(changes);
|
|
351
|
+
const geometry = this.#geometry;
|
|
352
|
+
if (this.#mode === "all-protected" || geometry.mode !== "classifying") return changes;
|
|
353
|
+
if (placement.rapNotMpuStart) changes.push(...this.#disable("rap-not-mpu-start"));
|
|
354
|
+
else if (placement.position !== void 0 && placement.position >= geometry.gopFrames) {
|
|
355
|
+
changes.push(...this.#disable("mpu-longer-than-gop"));
|
|
356
|
+
} else if (placement.violation !== void 0) changes.push(...this.#disable(placement.violation));
|
|
252
357
|
return changes;
|
|
253
358
|
}
|
|
254
359
|
/**
|
|
255
360
|
* The DU header of a source packet that a decode rebuilt, in block `sbn`.
|
|
256
|
-
* It bounds the blocks around that block for the
|
|
257
|
-
* arrived does:
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
361
|
+
* It bounds the blocks around that block for the MPU rule as a header that
|
|
362
|
+
* arrived does: the rule reads the DU headers the receiver holds. The
|
|
363
|
+
* rebuilt block is whole, so it gets no class and no record, and the
|
|
364
|
+
* packet is no evidence for P1 or P3, which rest on what arrived: it
|
|
365
|
+
* supports no class by the window rule, and can only end it. It is not
|
|
366
|
+
* counted as a packet that arrived either (#arrivedBetween).
|
|
261
367
|
*/
|
|
262
368
|
observeRecovered(sbn, evidence) {
|
|
263
369
|
if (this.#geometry.trackKind === "audio") return [];
|
|
264
370
|
const { mpu, idx, movieFragment } = evidence;
|
|
265
371
|
if (mpu === void 0 || idx === void 0 || movieFragment === void 0) return [];
|
|
266
372
|
const changes = [];
|
|
267
|
-
const fragmentsCountedSamples = !this.#multiSampleFragment;
|
|
268
373
|
if (idx !== 0) {
|
|
269
374
|
this.#multiSampleFragment = true;
|
|
270
375
|
const geometry = this.#geometry;
|
|
@@ -272,32 +377,74 @@ var BlockClassifier = class {
|
|
|
272
377
|
changes.push(...this.#disable("mpu-multiple-fragments"));
|
|
273
378
|
}
|
|
274
379
|
}
|
|
275
|
-
|
|
276
|
-
sbn,
|
|
277
|
-
|
|
278
|
-
this.#positionHeld(mpu, idx, movieFragment),
|
|
279
|
-
fragmentsCountedSamples,
|
|
280
|
-
changes
|
|
281
|
-
);
|
|
282
|
-
for (const other of bounded) this.#reclassify(other, this.#blocks.get(other), changes);
|
|
380
|
+
if (this.#noteHeader(sbn, evidence, this.#positionHeld(mpu, idx, movieFragment), void 0, changes)) {
|
|
381
|
+
this.#reclassifyOthers(sbn, changes);
|
|
382
|
+
}
|
|
283
383
|
return changes;
|
|
284
384
|
}
|
|
285
385
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
386
|
+
* Decode times the receiver can determine: `first` and `last` are those of
|
|
387
|
+
* the first and the last sample that one held movie fragment's metadata
|
|
388
|
+
* (FT=1) times, of MPU `mpu`, in ticks of `mediaTimescale`; a `trun` lists
|
|
389
|
+
* samples in decode order, so `first` is not after `last`. They are read
|
|
390
|
+
* for one thing, and only on a track the MPU rule applies to: an MPU with
|
|
391
|
+
* two samples a keyframe interval or more apart lasts longer than the
|
|
392
|
+
* interval, so its first sample need not be its only RAP. The rule then
|
|
393
|
+
* stops for the rest of the epoch, the window rule with it, and every delta
|
|
394
|
+
* class goes (fec-multicast-01 Block Classification). No class comes from
|
|
395
|
+
* a decode time. The MPU's first sample is never later than the earliest
|
|
396
|
+
* one known, so the known span is no longer than the real one.
|
|
289
397
|
*/
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
398
|
+
noteDecodeTimes(mpu, first, last, mediaTimescale) {
|
|
399
|
+
const changes = [];
|
|
400
|
+
const geometry = this.#geometry;
|
|
401
|
+
if (geometry.trackKind !== "video" || this.#mpuRuleCatalog !== null || !isPositiveSafeInteger(mediaTimescale)) {
|
|
402
|
+
return changes;
|
|
403
|
+
}
|
|
404
|
+
const held = this.#decodeSpans.get(mpu);
|
|
405
|
+
const known = held?.mediaTimescale === mediaTimescale ? held : void 0;
|
|
406
|
+
let late = false;
|
|
407
|
+
if (held === void 0 && this.#decodeSpans.size >= 2) {
|
|
408
|
+
const lowest = Math.min(...this.#decodeSpans.keys());
|
|
409
|
+
late = mpu < lowest;
|
|
410
|
+
if (!late) this.#decodeSpans.delete(lowest);
|
|
411
|
+
}
|
|
412
|
+
const min = known !== void 0 && known.min < first ? known.min : first;
|
|
413
|
+
const max = known !== void 0 && known.max > last ? known.max : last;
|
|
414
|
+
if (!late) this.#decodeSpans.set(mpu, { min, max, mediaTimescale });
|
|
415
|
+
const { ticks, timescale } = geometry.keyframeInterval;
|
|
416
|
+
if ((max - min) * BigInt(timescale) >= BigInt(ticks) * BigInt(mediaTimescale)) {
|
|
417
|
+
this.#mpuOutlastsInterval = true;
|
|
418
|
+
this.#withdraw(changes);
|
|
419
|
+
}
|
|
420
|
+
return changes;
|
|
421
|
+
}
|
|
422
|
+
/** Ask again for every block held but `own`: a new DU header can bound any of them. */
|
|
423
|
+
#reclassifyOthers(own, changes) {
|
|
424
|
+
for (const [sbn, block] of this.#blocks) {
|
|
425
|
+
if (sbn !== own) this.#reclassify(sbn, block, changes);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Move delta blocks back to unknown: a premise their class stood on is
|
|
430
|
+
* gone. After DU headers out of block order, what the window rule still
|
|
431
|
+
* holds for is classed again as its blocks are seen.
|
|
432
|
+
*/
|
|
433
|
+
#withdraw(changes) {
|
|
434
|
+
for (const [sbn, block] of this.#blocks) {
|
|
435
|
+
if (block.cls !== "delta") continue;
|
|
436
|
+
block.cls = "unknown";
|
|
437
|
+
changes.push({ kind: "reclassified", sbn, from: "delta", to: "unknown", evidence: "classifier-disabled" });
|
|
299
438
|
}
|
|
300
|
-
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* An MPU boundary stopped bounding this stream's RAPs: neither rule proves
|
|
442
|
+
* anything from now on, and every delta class goes.
|
|
443
|
+
*/
|
|
444
|
+
#refuteMpuBounds(changes) {
|
|
445
|
+
if (!this.#mpuBoundsRaps) return;
|
|
446
|
+
this.#mpuBoundsRaps = false;
|
|
447
|
+
this.#withdraw(changes);
|
|
301
448
|
}
|
|
302
449
|
#reclassify(sbn, block, changes) {
|
|
303
450
|
const next = this.#classify(block, sbn);
|
|
@@ -338,7 +485,9 @@ var BlockClassifier = class {
|
|
|
338
485
|
if (presentationTime === previous.presentationTime) return [];
|
|
339
486
|
const interval2 = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
|
|
340
487
|
if (interval2 === null || decodeTime === void 0 || previous.decodeTime === void 0 || (decodeTime - previous.decodeTime) % interval2 !== 0n) {
|
|
341
|
-
|
|
488
|
+
const changes = [];
|
|
489
|
+
this.#refuteMpuBounds(changes);
|
|
490
|
+
return changes;
|
|
342
491
|
}
|
|
343
492
|
return [];
|
|
344
493
|
}
|
|
@@ -446,7 +595,7 @@ var BlockClassifier = class {
|
|
|
446
595
|
/**
|
|
447
596
|
* The MPU position #place gives a DU header, read from the layout the
|
|
448
597
|
* arrived headers built and recording nothing: where a rebuilt header
|
|
449
|
-
* stands for the catalog interval's check in the
|
|
598
|
+
* stands for the catalog interval's check in the MPU rule.
|
|
450
599
|
*/
|
|
451
600
|
#positionHeld(mpu, idx, fragment) {
|
|
452
601
|
if (!this.#fragmentPerFrame || this.#multiSampleFragment) return idx;
|
|
@@ -481,9 +630,11 @@ var BlockClassifier = class {
|
|
|
481
630
|
this.#mpuSbnSpans.clear();
|
|
482
631
|
this.#dataUnitStarts.clear();
|
|
483
632
|
this.#highestMpu = null;
|
|
484
|
-
this.#
|
|
485
|
-
this.#
|
|
486
|
-
this.#
|
|
633
|
+
this.#headers.clear();
|
|
634
|
+
this.#arrived.clear();
|
|
635
|
+
this.#heldHighestMpu = null;
|
|
636
|
+
this.#headerOrderRefuted = false;
|
|
637
|
+
this.#decodeSpans.clear();
|
|
487
638
|
}
|
|
488
639
|
/**
|
|
489
640
|
* P1 check for one source packet of MPU `mpu` in block `sbn`, then record
|
|
@@ -577,11 +728,12 @@ var BlockClassifier = class {
|
|
|
577
728
|
#classify(block, sbn) {
|
|
578
729
|
if (block.rapSeen || block.mpus.size >= 2) return "keyframe";
|
|
579
730
|
if (block.cls === "delta") return "delta";
|
|
580
|
-
if (this.#windowHolds(block) || this.#
|
|
731
|
+
if (this.#windowHolds(block) || this.#mpuRuleHolds(block, sbn)) return "delta";
|
|
581
732
|
return "unknown";
|
|
582
733
|
}
|
|
583
734
|
#windowHolds(block) {
|
|
584
|
-
|
|
735
|
+
const off = this.mpuRuleOff;
|
|
736
|
+
if (this.#mode === "all-protected" || off !== null && off !== "du-headers-out-of-order") return false;
|
|
585
737
|
const geometry = this.#geometry;
|
|
586
738
|
if (geometry.trackKind !== "video" || geometry.mode !== "classifying") return false;
|
|
587
739
|
if (block.mpus.size !== 1 || block.positionMin === void 0 || block.positionMax === void 0) {
|
|
@@ -591,95 +743,199 @@ var BlockClassifier = class {
|
|
|
591
743
|
return block.positionMax - span >= 1 && block.positionMin + span <= geometry.gopFrames - 1;
|
|
592
744
|
}
|
|
593
745
|
/**
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
746
|
+
* Keep the header and arrival ledgers to the two newest MPUs. False for an
|
|
747
|
+
* MPU behind them, which is not kept: no block still asked lies there, and
|
|
748
|
+
* the ledgers stay bounded when MPU numbers go back with no source
|
|
749
|
+
* discontinuity (a restart nothing signalled, or the 2^32 wrap). The rule
|
|
750
|
+
* is then silent until the next one.
|
|
751
|
+
*/
|
|
752
|
+
#noteHeldMpu(mpu) {
|
|
753
|
+
const highest = this.#heldHighestMpu;
|
|
754
|
+
if (highest !== null && mpu <= highest) return mpu + 1 >= highest;
|
|
755
|
+
this.#heldHighestMpu = mpu;
|
|
756
|
+
for (const held of [this.#headers, this.#arrived]) {
|
|
757
|
+
for (const other of [...held.keys()]) {
|
|
758
|
+
if (other + 1 < mpu) held.delete(other);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
/** Record a source packet that arrived as source symbol `ssId`, for #arrivedBetween. */
|
|
764
|
+
#noteArrived(sbn, mpu, ssId) {
|
|
765
|
+
if (mpu === void 0 || ssId === void 0 || !this.#noteHeldMpu(mpu)) return;
|
|
766
|
+
const arrived = this.#arrived.get(mpu);
|
|
767
|
+
if (arrived === void 0) this.#arrived.set(mpu, { start: /* @__PURE__ */ new Map([[ssId, sbn]]), last: ssId });
|
|
768
|
+
else {
|
|
769
|
+
if (arrived.start.size < ARRIVED_START_MAX) arrived.start.set(ssId, sbn);
|
|
770
|
+
if (ssId > arrived.last) arrived.last = ssId;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Record a held DU header for the MPU rule; `ssId` is its source symbol id
|
|
775
|
+
* when it arrived, undefined for one that FEC rebuilt. True when it is new
|
|
776
|
+
* and in order: the blocks held are then asked again. Blocks follow
|
|
777
|
+
* authored order (P1), so the first header that lies against it withdraws
|
|
778
|
+
* every class, and the rule proves nothing for the rest of the sequence.
|
|
597
779
|
*/
|
|
598
|
-
#
|
|
780
|
+
#noteHeader(sbn, evidence, position, ssId, changes) {
|
|
599
781
|
const { mpu, idx, movieFragment } = evidence;
|
|
600
782
|
if (this.#geometry.trackKind !== "video" || mpu === void 0 || idx === void 0 || movieFragment === void 0) {
|
|
601
|
-
return
|
|
783
|
+
return false;
|
|
602
784
|
}
|
|
603
|
-
|
|
785
|
+
if (!this.#noteHeldMpu(mpu)) {
|
|
786
|
+
if (evidence.rap && idx !== 0 && !this.#rapInsideMpu) {
|
|
787
|
+
this.#rapInsideMpu = true;
|
|
788
|
+
this.#withdraw(changes);
|
|
789
|
+
}
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
const header = {
|
|
604
793
|
movieFragment,
|
|
605
794
|
idx,
|
|
606
795
|
offset: evidence.offset ?? 0,
|
|
607
796
|
sbn,
|
|
608
797
|
rap: evidence.rap,
|
|
609
|
-
|
|
798
|
+
...ssId === void 0 ? {} : { ssId },
|
|
610
799
|
...position === void 0 ? {} : { position }
|
|
611
800
|
};
|
|
612
|
-
let
|
|
613
|
-
if (
|
|
614
|
-
|
|
615
|
-
this.#
|
|
801
|
+
let headers = this.#headers.get(mpu);
|
|
802
|
+
if (headers === void 0) {
|
|
803
|
+
headers = [];
|
|
804
|
+
this.#headers.set(mpu, headers);
|
|
616
805
|
}
|
|
617
806
|
let at = 0;
|
|
618
|
-
let end =
|
|
807
|
+
let end = headers.length;
|
|
619
808
|
while (at < end) {
|
|
620
809
|
const mid = at + end >>> 1;
|
|
621
|
-
if (compareDataUnitStarts(
|
|
810
|
+
if (compareDataUnitStarts(headers[mid], header) < 0) at = mid + 1;
|
|
622
811
|
else end = mid;
|
|
623
812
|
}
|
|
624
|
-
if (at <
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
813
|
+
if (at < headers.length && compareDataUnitStarts(headers[at], header) === 0) return false;
|
|
814
|
+
headers.splice(at, 0, header);
|
|
815
|
+
const first = headers[0];
|
|
816
|
+
if (!this.#rapInsideMpu && (header.rap && header.idx !== 0 || (at === 0 ? headers : [header]).some((held) => held.rap && held.movieFragment !== first.movieFragment))) {
|
|
817
|
+
this.#rapInsideMpu = true;
|
|
818
|
+
this.#withdraw(changes);
|
|
631
819
|
}
|
|
632
|
-
const before =
|
|
633
|
-
const after =
|
|
820
|
+
const before = headers[at - 1]?.sbn;
|
|
821
|
+
const after = headers[at + 1]?.sbn;
|
|
634
822
|
if (before !== void 0 && before > sbn || after !== void 0 && after < sbn) {
|
|
635
|
-
this.#
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const bounded = [];
|
|
639
|
-
for (const other of this.#blocks.keys()) {
|
|
640
|
-
if (before !== void 0 && other >= before && other < sbn || after !== void 0 && other > sbn && other <= after) {
|
|
641
|
-
bounded.push(other);
|
|
823
|
+
if (!this.#headerOrderRefuted) {
|
|
824
|
+
this.#headerOrderRefuted = true;
|
|
825
|
+
this.#withdraw(changes);
|
|
642
826
|
}
|
|
827
|
+
return false;
|
|
643
828
|
}
|
|
644
|
-
return
|
|
829
|
+
return true;
|
|
645
830
|
}
|
|
646
831
|
/**
|
|
647
|
-
* The
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
832
|
+
* The MPU rule. L is the DU header held last before the block and U the
|
|
833
|
+
* one held first after it. Every packet carries its MPU number, and an MPU
|
|
834
|
+
* holds one RAP: its first sample.
|
|
835
|
+
*
|
|
836
|
+
* - R1, L and U in one MPU: the block holds no part of a RAP, provided the
|
|
837
|
+
* MPU's first sample ended before the block (#firstSampleEndedBefore).
|
|
838
|
+
* - R2, U in the next MPU: the block may hold the start of that MPU,
|
|
839
|
+
* unless that start arrived whole (#startArrivedWhole). The block is
|
|
840
|
+
* then the tail of L's MPU, and R1's proviso decides.
|
|
841
|
+
* - R3, more than one MPU apart: a whole MPU is gone, its RAP with it.
|
|
842
|
+
* - R4, no U held yet (or no L): not known. The next DU header asks again.
|
|
843
|
+
*
|
|
844
|
+
* It rests on the publisher keeping one RAP to an MPU, which no packet
|
|
845
|
+
* says. So it classes nothing unless the catalog states a keyframe interval
|
|
846
|
+
* equal to the group duration, and nothing once the stream showed
|
|
847
|
+
* otherwise: a RAP inside an MPU (mpuBoundsRaps, or a RAP-flagged DU header
|
|
848
|
+
* held that is not of its MPU's first sample: #noteHeader), an MPU longer than the
|
|
849
|
+
* keyframe interval by the decode times known (noteDecodeTimes), or DU
|
|
850
|
+
* headers against the block order. `mpuRuleOff` names which. `dep_counter`
|
|
851
|
+
* is not read.
|
|
651
852
|
*/
|
|
652
|
-
#
|
|
653
|
-
if (this
|
|
853
|
+
#mpuRuleHolds(block, sbn) {
|
|
854
|
+
if (this.mpuRuleOff !== null) return false;
|
|
654
855
|
let lower;
|
|
655
856
|
let upper;
|
|
656
857
|
let lowerMpu = 0;
|
|
657
858
|
let upperMpu = 0;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
859
|
+
let lowerAt = 0;
|
|
860
|
+
let upperAt = 0;
|
|
861
|
+
for (const [mpu, headers] of this.#headers) {
|
|
862
|
+
const before = firstStartAtOrAfter(headers, sbn) - 1;
|
|
863
|
+
const after = firstStartAtOrAfter(headers, sbn + 1);
|
|
864
|
+
const below = headers[before];
|
|
865
|
+
const above = headers[after];
|
|
866
|
+
if (below !== void 0 && (lower === void 0 || below.sbn > lower.sbn || below.sbn === lower.sbn && mpu > lowerMpu)) {
|
|
867
|
+
lower = below;
|
|
663
868
|
lowerMpu = mpu;
|
|
869
|
+
lowerAt = before;
|
|
664
870
|
}
|
|
665
|
-
if (
|
|
666
|
-
upper =
|
|
871
|
+
if (above !== void 0 && (upper === void 0 || above.sbn < upper.sbn || above.sbn === upper.sbn && mpu < upperMpu)) {
|
|
872
|
+
upper = above;
|
|
667
873
|
upperMpu = mpu;
|
|
874
|
+
upperAt = after;
|
|
668
875
|
}
|
|
669
876
|
}
|
|
670
|
-
if (lower === void 0 || upper === void 0
|
|
877
|
+
if (lower === void 0 || upper === void 0) return false;
|
|
671
878
|
if (block.mpus.size === 1 && !block.mpus.has(lowerMpu)) return false;
|
|
672
|
-
if (
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (
|
|
679
|
-
const geometry = this.#geometry;
|
|
680
|
-
if (geometry.trackKind === "video" && geometry.mode === "classifying" && lower.position !== void 0 && upper.position !== void 0 && Math.floor(upper.position / geometry.gopFrames) > Math.floor(lower.position / geometry.gopFrames)) {
|
|
879
|
+
if (upperMpu === lowerMpu) {
|
|
880
|
+
if (upper.rap) return false;
|
|
881
|
+
const geometry = this.#geometry;
|
|
882
|
+
if (geometry.trackKind === "video" && geometry.mode === "classifying" && lower.position !== void 0 && upper.position !== void 0 && Math.floor(upper.position / geometry.gopFrames) > Math.floor(lower.position / geometry.gopFrames)) {
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
} else if (upperMpu !== lowerMpu + 1 || !this.#startArrivedWhole(upperMpu, upperAt)) {
|
|
681
886
|
return false;
|
|
682
887
|
}
|
|
888
|
+
return this.#firstSampleEndedBefore(sbn, lowerMpu, lowerAt);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* R1's proviso for block `sbn`, where header `at` of MPU `mpu` is the one
|
|
892
|
+
* held last before it: no part of the MPU's first sample lies in the
|
|
893
|
+
* block. A sample start without RAP_flag is not the first sample. Any
|
|
894
|
+
* other header may be of it (a later data unit of a sample need not repeat
|
|
895
|
+
* the flag). That sample ended before the block only if every packet from
|
|
896
|
+
* the header to the next sample's DU header arrived, in earlier blocks.
|
|
897
|
+
*/
|
|
898
|
+
#firstSampleEndedBefore(sbn, mpu, at) {
|
|
899
|
+
const headers = this.#headers.get(mpu);
|
|
900
|
+
const lower = headers[at];
|
|
901
|
+
if (lower.offset === 0 && !lower.rap) return true;
|
|
902
|
+
const next = nextSampleHeader(headers, at);
|
|
903
|
+
return next !== void 0 && this.#arrivedBetween(mpu, lower, next, sbn);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* R2's exception: the start of MPU `mpu` arrived whole. Its header `at`,
|
|
907
|
+
* the DU header held first after the block, is of the MPU's RAP. Every
|
|
908
|
+
* packet before it arrived, back to the last packet of the MPU before: so
|
|
909
|
+
* did the MPU and movie fragment metadata sent before the sample. And
|
|
910
|
+
* every packet after it arrived, up to the next sample's DU header.
|
|
911
|
+
*/
|
|
912
|
+
#startArrivedWhole(mpu, at) {
|
|
913
|
+
const headers = this.#headers.get(mpu);
|
|
914
|
+
const first = headers[at];
|
|
915
|
+
const arrived = this.#arrived.get(mpu);
|
|
916
|
+
const previous = this.#arrived.get(mpu - 1);
|
|
917
|
+
if (!first.rap || first.ssId === void 0 || arrived === void 0 || previous === void 0) return false;
|
|
918
|
+
let ssId = first.ssId - 1;
|
|
919
|
+
while (arrived.start.has(ssId)) ssId--;
|
|
920
|
+
if (ssId !== previous.last) return false;
|
|
921
|
+
const next = nextSampleHeader(headers, at);
|
|
922
|
+
return next !== void 0 && this.#arrivedBetween(mpu, first, next);
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Whether every packet sent after DU header `from` and before DU header
|
|
926
|
+
* `to`, both of MPU `mpu`, arrived as a packet of that MPU, each in a block
|
|
927
|
+
* before `before` when one is given. The source symbol id counts every
|
|
928
|
+
* packet of the FEC flow, so no id may be missing between the two. Ids are
|
|
929
|
+
* read as plain numbers, as block starts are: past the 2^32 wrap of the id
|
|
930
|
+
* nothing is proved.
|
|
931
|
+
*/
|
|
932
|
+
#arrivedBetween(mpu, from, to, before) {
|
|
933
|
+
const arrived = this.#arrived.get(mpu);
|
|
934
|
+
if (arrived === void 0 || from.ssId === void 0 || to.ssId === void 0) return false;
|
|
935
|
+
for (let ssId = from.ssId + 1; ssId !== to.ssId; ssId++) {
|
|
936
|
+
const sbn = arrived.start.get(ssId);
|
|
937
|
+
if (sbn === void 0 || before !== void 0 && sbn >= before) return false;
|
|
938
|
+
}
|
|
683
939
|
return true;
|
|
684
940
|
}
|
|
685
941
|
#allowed(from, to) {
|
|
@@ -689,7 +945,7 @@ var BlockClassifier = class {
|
|
|
689
945
|
return false;
|
|
690
946
|
}
|
|
691
947
|
#evidenceFor(block, to) {
|
|
692
|
-
if (to === "delta") return this.#windowHolds(block) ? "window" : "
|
|
948
|
+
if (to === "delta") return this.#windowHolds(block) ? "window" : "mpu-rule";
|
|
693
949
|
return block.rapSeen ? "rap" : "mpu-span";
|
|
694
950
|
}
|
|
695
951
|
};
|