@blockcast/mmt-container 2.2.0-main.cc3fe0684403 → 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/__tests__/test-utils.d.ts +1 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -1
- 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 +128 -14
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +472 -27
- package/dist/block-policy.js.map +2 -2
- package/dist/browser-runtime.js +1040 -120
- 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/catalog-network-source.d.ts +1 -17
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +25 -19
- package/dist/catalog-network-source.js.map +3 -3
- 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 +30 -8
- package/dist/cmaf-block-assembler.js.map +3 -3
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +16 -3
- package/dist/codec-utils.js.map +2 -2
- 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/datagram-leg-deadline.d.ts +26 -2
- package/dist/datagram-leg-deadline.d.ts.map +1 -1
- package/dist/datagram-leg-deadline.js +14 -2
- package/dist/datagram-leg-deadline.js.map +2 -2
- 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 +24 -3
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +531 -38
- 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 +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- 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 +12 -0
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +73 -3
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +103 -25
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +73 -3
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +20 -2
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +150 -23
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.js.map +1 -1
- package/dist/multicast-input.js.map +1 -1
- package/dist/multicast-manager.d.ts +23 -2
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +737 -86
- 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 +98 -22
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +15 -7
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +34 -7
- package/dist/repair-fetch.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +73 -3
- 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 +673 -42
- package/src/carp-catalog.ts +9 -0
- package/src/catalog-network-source.ts +3 -37
- package/src/cmaf-block-assembler.ts +17 -0
- package/src/codec-utils.ts +19 -3
- package/src/conceal-timeline.ts +60 -5
- package/src/datagram-leg-deadline.ts +34 -2
- package/src/event-timeline-mmtp.ts +55 -0
- package/src/fec-manager.ts +84 -12
- package/src/feed-gate.ts +295 -0
- package/src/index.ts +22 -0
- package/src/iso-bmff-timing.ts +33 -0
- package/src/mfu-reassembler.ts +4 -0
- package/src/mmtp-container-parser.ts +51 -5
- package/src/mmtp-router.ts +116 -4
- package/src/multicast-manager.ts +31 -0
- package/src/repair-fetch.ts +70 -19
- 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/catalog-timing.json +184 -1
- package/test-vectors/frame-needs-v1.json +295 -0
- package/test-vectors/repair-policy-v1.json +98 -18
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
* - {@link videoConcealModeForCodec} says whether a video decoder can be fed
|
|
11
11
|
* straight through a delta gap (H.264 conceals missing references itself)
|
|
12
12
|
* or must hold until the next RAP.
|
|
13
|
-
* - {@link HoldLastTimeline} gives MSE sinks gapless per-sample durations.
|
|
13
|
+
* - {@link HoldLastTimeline} gives MSE sinks gapless per-sample durations. It
|
|
14
|
+
* owns a {@link VideoFeedGate}, so a stream that states what each frame
|
|
15
|
+
* needs holds only the frames a loss reaches.
|
|
14
16
|
* - {@link AudioGapConcealer} sizes audio concealment exactly: repeat the last
|
|
15
17
|
* good access unit (MSE) or insert PCM silence (WebCodecs).
|
|
16
18
|
*/
|
|
17
19
|
import type { FrameGapDecision } from './block-policy.js';
|
|
20
|
+
import { type DecoderTolerance, type FrameNeeds, type VideoFeedGateStats } from './feed-gate.js';
|
|
18
21
|
/**
|
|
19
22
|
* `feed-through`: keep feeding deltas after a delta-only gap; the decoder
|
|
20
23
|
* conceals missing references and the canvas keeps the last frame.
|
|
@@ -26,6 +29,7 @@ export type VideoConcealMode = 'feed-through' | 'hold-to-rap';
|
|
|
26
29
|
* AVC decoders conceal a missing reference and resynchronise on their own;
|
|
27
30
|
* HEVC, AV1 and VP9 decoders error or freeze on a broken reference chain.
|
|
28
31
|
* Any codec not known to conceal is held to the next RAP (fail-closed).
|
|
32
|
+
* The codec table itself is {@link decoderTolerance}.
|
|
29
33
|
*/
|
|
30
34
|
export declare function videoConcealModeForCodec(codec: string): VideoConcealMode;
|
|
31
35
|
/** One video sample in its media timescale. */
|
|
@@ -40,6 +44,8 @@ export interface TimelineSample<T> {
|
|
|
40
44
|
readonly mpu?: number;
|
|
41
45
|
/** Decision attached by libmmt to the first frame released after a gap. */
|
|
42
46
|
readonly gapBefore?: FrameGapDecision;
|
|
47
|
+
/** The frame's dependency statement (`RoutedFrameMeta.needs`), forwarded as is. */
|
|
48
|
+
readonly needs?: FrameNeeds;
|
|
43
49
|
}
|
|
44
50
|
/** A sample ready to append, with an explicit per-sample duration. */
|
|
45
51
|
export interface TimelineEmit<T> {
|
|
@@ -51,6 +57,8 @@ export interface TimelineEmit<T> {
|
|
|
51
57
|
}
|
|
52
58
|
export interface HoldLastTimelineOptions {
|
|
53
59
|
readonly concealMode: VideoConcealMode;
|
|
60
|
+
/** `decoderTolerance(codec)`. Omitted, no statement is read. */
|
|
61
|
+
readonly tolerance?: DecoderTolerance;
|
|
54
62
|
}
|
|
55
63
|
export interface HoldLastTimelineStats {
|
|
56
64
|
/** Non-RAP frames dropped while waiting for a RAP. */
|
|
@@ -72,11 +80,26 @@ export interface HoldLastTimelineStats {
|
|
|
72
80
|
* stream shows composition offsets (dts ≠ pts), samples pass straight
|
|
73
81
|
* through with their authored durations and MSE starves until the RAP is
|
|
74
82
|
* appended — the one documented case where the element also waits on audio.
|
|
83
|
+
*
|
|
84
|
+
* Inside a GOP the feed gate reads, a sample whose anchor was not fed is
|
|
85
|
+
* withheld alone: the held frame stays held and the next fed sample sizes it.
|
|
86
|
+
* With composition offsets there is no stretch, so a withheld sample holds to
|
|
87
|
+
* the next RAP. So does the first sample with an offset when it follows a
|
|
88
|
+
* withheld one.
|
|
75
89
|
*/
|
|
76
90
|
export declare class HoldLastTimeline<T> {
|
|
77
91
|
#private;
|
|
78
92
|
constructor(options: HoldLastTimelineOptions);
|
|
79
93
|
get stats(): Readonly<HoldLastTimelineStats>;
|
|
94
|
+
/** What the feed gate withheld and fed across a gap. */
|
|
95
|
+
get gateStats(): Readonly<VideoFeedGateStats>;
|
|
96
|
+
/**
|
|
97
|
+
* The sink's decoder failed. True when a frame had been fed across a gap: the gate then
|
|
98
|
+
* reads no statement on this track again. The rest of a GOP in which the gate withheld a
|
|
99
|
+
* sample or fed one across a gap is not appended. Nothing else changes; to start over,
|
|
100
|
+
* call {@link reset}.
|
|
101
|
+
*/
|
|
102
|
+
onDecoderFailure(): boolean;
|
|
80
103
|
push(sample: TimelineSample<T>): TimelineEmit<T>[];
|
|
81
104
|
/** Release the held sample with its authored duration (end of stream). */
|
|
82
105
|
flush(): TimelineEmit<T>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conceal-timeline.d.ts","sourceRoot":"","sources":["../src/conceal-timeline.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"conceal-timeline.d.ts","sourceRoot":"","sources":["../src/conceal-timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAEf,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAA;AAIvB;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,aAAa,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAExE;AAID,+CAA+C;AAC/C,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,uBAAuB;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAA;IACrC,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAC5B;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,GA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ACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B,GACD;IACE,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB,CAAA;AAEL;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,CAAC;;IAI9B,IAAI,KAAK,IAAI,QAAQ,CAAC,sBAAsB,CAAC,CAE5C;IAED;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IASlC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,EAAE,IAAI,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,YAAY,CAAC,CAAC,CAAC;IA2B7F,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/conceal-timeline.js
CHANGED
|
@@ -1,22 +1,206 @@
|
|
|
1
|
+
// src/feed-gate.ts
|
|
2
|
+
var FRAME_NEEDS_KEYFRAME = 254;
|
|
3
|
+
var NOTHING_STATED = Object.freeze({ map: false, distance: 0, mayBeNeeded: true });
|
|
4
|
+
var MAP_KEYFRAME = Object.freeze({ map: true, distance: 0, mayBeNeeded: true });
|
|
5
|
+
function decodeFrameNeeds(code, keyframe) {
|
|
6
|
+
if (keyframe) return code === FRAME_NEEDS_KEYFRAME ? MAP_KEYFRAME : NOTHING_STATED;
|
|
7
|
+
if (!Number.isInteger(code) || code < 1 || code > 126 || code === 63 || code === 64) {
|
|
8
|
+
return NOTHING_STATED;
|
|
9
|
+
}
|
|
10
|
+
return { map: false, distance: code & 63, mayBeNeeded: code > 64 };
|
|
11
|
+
}
|
|
12
|
+
function decoderTolerance(codec) {
|
|
13
|
+
const lower = codec.toLowerCase();
|
|
14
|
+
return lower.startsWith("avc1") || lower.startsWith("avc3") ? "conceals" : "none";
|
|
15
|
+
}
|
|
16
|
+
var VideoFeedGate = class {
|
|
17
|
+
#inert;
|
|
18
|
+
/** A statement was false, or a decoder failed on a selective feed: this track is read no more. */
|
|
19
|
+
#off = false;
|
|
20
|
+
/** `hold`: reading stopped inside a GOP in which the gate had answered for a hole. */
|
|
21
|
+
#mode = "unread";
|
|
22
|
+
#keyMpu = 0;
|
|
23
|
+
#keyPosition = 0;
|
|
24
|
+
/** Slot `position & 63` holds the position fed there: the last 64 positions. */
|
|
25
|
+
#fedAt = new Float64Array(64).fill(-1);
|
|
26
|
+
/** Frames fed since the keyframe. */
|
|
27
|
+
#fedCount = 0;
|
|
28
|
+
/** Place after the keyframe of the last frame fed. */
|
|
29
|
+
#top = 0;
|
|
30
|
+
/** Place after the keyframe of the last frame the gate allowed. */
|
|
31
|
+
#allowed = 0;
|
|
32
|
+
#withheldInGop = false;
|
|
33
|
+
#fedAcrossGap = false;
|
|
34
|
+
/** A decoder may report a failure after the next keyframe went in. */
|
|
35
|
+
#fedAcrossGapBefore = false;
|
|
36
|
+
#lastWithheld;
|
|
37
|
+
#stats = {
|
|
38
|
+
fedAcrossGap: 0,
|
|
39
|
+
withheld: 0,
|
|
40
|
+
selectiveFeedFailures: 0,
|
|
41
|
+
statementViolations: 0
|
|
42
|
+
};
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.#inert = options.tolerance !== "none";
|
|
45
|
+
}
|
|
46
|
+
/** True while the gate answers from the statements of the current GOP. */
|
|
47
|
+
get reading() {
|
|
48
|
+
return this.#mode === "reading";
|
|
49
|
+
}
|
|
50
|
+
get stats() {
|
|
51
|
+
return { ...this.#stats };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* May this frame be fed? Records no frame as fed, so a sink may ask twice
|
|
55
|
+
* about one frame. `unread` for a keyframe, a concealing decoder, a GOP
|
|
56
|
+
* whose keyframe did not carry 254, and a track switched off. A late or
|
|
57
|
+
* repeated frame is refused with `withhold` and not counted.
|
|
58
|
+
*/
|
|
59
|
+
admit(frame) {
|
|
60
|
+
if (frame.keyframe) return "unread";
|
|
61
|
+
const needs = frame.needs;
|
|
62
|
+
if (this.#mode === "reading") {
|
|
63
|
+
if (needs === void 0 || needs.code > 128) {
|
|
64
|
+
this.#stopReading();
|
|
65
|
+
} else {
|
|
66
|
+
const offset = this.#offset(needs);
|
|
67
|
+
if (offset < 0) return "withhold";
|
|
68
|
+
if (offset === 0) return this.#withhold(needs);
|
|
69
|
+
const { distance } = decodeFrameNeeds(needs.code, false);
|
|
70
|
+
if (distance > offset) {
|
|
71
|
+
this.#stats.statementViolations++;
|
|
72
|
+
this.#off = true;
|
|
73
|
+
this.#stopReading();
|
|
74
|
+
} else {
|
|
75
|
+
const whole = this.#fedCount === offset - 1;
|
|
76
|
+
const anchor = needs.position - distance >>> 0;
|
|
77
|
+
const anchorFed = distance === 0 ? whole : distance === offset || this.#fedAt[anchor & 63] === anchor;
|
|
78
|
+
if (!anchorFed) return this.#withhold(needs);
|
|
79
|
+
this.#allowed = Math.max(this.#allowed, offset);
|
|
80
|
+
return "feed";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return this.#mode === "hold" ? this.#withhold(needs) : "unread";
|
|
85
|
+
}
|
|
86
|
+
/** The sink handed this frame to its decoder or buffer. */
|
|
87
|
+
fed(frame) {
|
|
88
|
+
const needs = frame.needs;
|
|
89
|
+
if (frame.keyframe) {
|
|
90
|
+
this.#fedAcrossGapBefore = this.#fedAcrossGap;
|
|
91
|
+
this.#fedAcrossGap = false;
|
|
92
|
+
this.#clear();
|
|
93
|
+
if (this.#inert || this.#off || needs === void 0 || !decodeFrameNeeds(needs.code, true).map) return;
|
|
94
|
+
this.#mode = "reading";
|
|
95
|
+
this.#keyMpu = needs.mpu;
|
|
96
|
+
this.#keyPosition = needs.position >>> 0;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.#mode !== "reading") return;
|
|
100
|
+
if (needs === void 0 || needs.code > 128) {
|
|
101
|
+
this.#stopReading();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const offset = this.#offset(needs);
|
|
105
|
+
if (offset <= 0) return;
|
|
106
|
+
if (this.#fedCount !== offset - 1) {
|
|
107
|
+
this.#fedAcrossGap = true;
|
|
108
|
+
this.#stats.fedAcrossGap++;
|
|
109
|
+
}
|
|
110
|
+
const position = needs.position >>> 0;
|
|
111
|
+
this.#fedAt[position & 63] = position;
|
|
112
|
+
this.#fedCount++;
|
|
113
|
+
this.#top = offset;
|
|
114
|
+
}
|
|
115
|
+
/** The sink stalled, reset its decoder or emptied its queue: nothing is read before the next keyframe. */
|
|
116
|
+
requireKeyframe() {
|
|
117
|
+
this.#clear();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The decoder raised an error or closed. Returns true when a frame had been
|
|
121
|
+
* fed across a gap: the decoder could not take the selective feed, so no
|
|
122
|
+
* statement is read on this track again. Either way the reading of this GOP
|
|
123
|
+
* stops, and the rest of a GOP with a hole the gate answered for is withheld.
|
|
124
|
+
*/
|
|
125
|
+
onDecoderFailure() {
|
|
126
|
+
const selective = this.#fedAcrossGap || this.#fedAcrossGapBefore;
|
|
127
|
+
this.#fedAcrossGap = false;
|
|
128
|
+
this.#fedAcrossGapBefore = false;
|
|
129
|
+
if (selective) {
|
|
130
|
+
this.#stats.selectiveFeedFailures++;
|
|
131
|
+
this.#off = true;
|
|
132
|
+
}
|
|
133
|
+
if (this.#mode === "reading") this.#stopReading();
|
|
134
|
+
if (this.#mode !== "hold") this.#clear();
|
|
135
|
+
return selective;
|
|
136
|
+
}
|
|
137
|
+
#clear() {
|
|
138
|
+
this.#mode = "unread";
|
|
139
|
+
this.#fedAt.fill(-1);
|
|
140
|
+
this.#fedCount = 0;
|
|
141
|
+
this.#top = 0;
|
|
142
|
+
this.#allowed = 0;
|
|
143
|
+
this.#withheldInGop = false;
|
|
144
|
+
}
|
|
145
|
+
/** The frame's place after the keyframe. 0: another MPU. -1: late or repeated, not after the last frame fed. */
|
|
146
|
+
#offset(needs) {
|
|
147
|
+
if (needs.mpu !== this.#keyMpu) return 0;
|
|
148
|
+
const offset = needs.position - this.#keyPosition >>> 0;
|
|
149
|
+
return offset > this.#top && offset < 2147483648 ? offset : -1;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The sink's own hold never saw a hole the gate answered for: a frame it
|
|
153
|
+
* withheld, or one it allowed that was not fed. The gate then holds the
|
|
154
|
+
* rest of that GOP itself.
|
|
155
|
+
*/
|
|
156
|
+
#stopReading() {
|
|
157
|
+
this.#mode = this.#withheldInGop || this.#fedCount < this.#allowed ? "hold" : "unread";
|
|
158
|
+
}
|
|
159
|
+
#withhold(needs) {
|
|
160
|
+
this.#withheldInGop = true;
|
|
161
|
+
const last = this.#lastWithheld;
|
|
162
|
+
if (needs === void 0 || last === void 0 || needs.mpu !== last.mpu || needs.position !== last.position) {
|
|
163
|
+
this.#stats.withheld++;
|
|
164
|
+
}
|
|
165
|
+
this.#lastWithheld = needs;
|
|
166
|
+
return "withhold";
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
1
170
|
// src/conceal-timeline.ts
|
|
2
171
|
function videoConcealModeForCodec(codec) {
|
|
3
|
-
|
|
4
|
-
if (lower.startsWith("avc1") || lower.startsWith("avc3")) return "feed-through";
|
|
5
|
-
return "hold-to-rap";
|
|
172
|
+
return decoderTolerance(codec) === "conceals" ? "feed-through" : "hold-to-rap";
|
|
6
173
|
}
|
|
7
174
|
var U32_MAX = 0xffffffffn;
|
|
8
175
|
var HoldLastTimeline = class {
|
|
9
176
|
#concealMode;
|
|
177
|
+
#gate;
|
|
10
178
|
#held = null;
|
|
11
179
|
#dropping = false;
|
|
12
180
|
#compositionOffsets = false;
|
|
181
|
+
/** A sample was withheld and the held frame has not yet been stretched over it. */
|
|
182
|
+
#skipped = false;
|
|
13
183
|
#stats = { droppedFrames: 0, extendedHolds: 0 };
|
|
14
184
|
constructor(options) {
|
|
15
185
|
this.#concealMode = options.concealMode;
|
|
186
|
+
this.#gate = new VideoFeedGate({ tolerance: options.tolerance ?? "conceals" });
|
|
16
187
|
}
|
|
17
188
|
get stats() {
|
|
18
189
|
return { ...this.#stats };
|
|
19
190
|
}
|
|
191
|
+
/** What the feed gate withheld and fed across a gap. */
|
|
192
|
+
get gateStats() {
|
|
193
|
+
return this.#gate.stats;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The sink's decoder failed. True when a frame had been fed across a gap: the gate then
|
|
197
|
+
* reads no statement on this track again. The rest of a GOP in which the gate withheld a
|
|
198
|
+
* sample or fed one across a gap is not appended. Nothing else changes; to start over,
|
|
199
|
+
* call {@link reset}.
|
|
200
|
+
*/
|
|
201
|
+
onDecoderFailure() {
|
|
202
|
+
return this.#gate.onDecoderFailure();
|
|
203
|
+
}
|
|
20
204
|
push(sample) {
|
|
21
205
|
if (sample.dts !== sample.pts) this.#compositionOffsets = true;
|
|
22
206
|
if (this.#dropping) {
|
|
@@ -27,7 +211,16 @@ var HoldLastTimeline = class {
|
|
|
27
211
|
this.#dropping = false;
|
|
28
212
|
return this.#accept(sample);
|
|
29
213
|
}
|
|
30
|
-
|
|
214
|
+
const gap = sample.gapBefore;
|
|
215
|
+
const stalls = !sample.keyframe && gap?.trackKind === "video" && gap.action === "stall";
|
|
216
|
+
const answer = stalls ? "unread" : this.#gate.admit(sample);
|
|
217
|
+
const selective = answer !== "unread" && !this.#compositionOffsets;
|
|
218
|
+
if (selective && answer === "withhold") {
|
|
219
|
+
this.#skipped = true;
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const holed = this.#skipped && this.#compositionOffsets && !sample.keyframe;
|
|
223
|
+
if (answer === "withhold" || holed || !selective && this.#dropsUntilRap(sample)) {
|
|
31
224
|
this.#dropping = true;
|
|
32
225
|
this.#stats.droppedFrames++;
|
|
33
226
|
return this.#compositionOffsets ? this.#releaseHeld() : [];
|
|
@@ -43,8 +236,12 @@ var HoldLastTimeline = class {
|
|
|
43
236
|
this.#held = null;
|
|
44
237
|
this.#dropping = false;
|
|
45
238
|
this.#compositionOffsets = false;
|
|
239
|
+
this.#skipped = false;
|
|
240
|
+
this.#gate.requireKeyframe();
|
|
46
241
|
}
|
|
47
242
|
#accept(sample) {
|
|
243
|
+
this.#gate.fed(sample);
|
|
244
|
+
this.#skipped = false;
|
|
48
245
|
if (this.#compositionOffsets) {
|
|
49
246
|
const out2 = this.#releaseHeld();
|
|
50
247
|
out2.push(this.#emit(sample, sample.duration));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/conceal-timeline.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Sink-side concealment helpers for the keyframe-protected FEC policy.\n *\n * Concealment is hold-last-good-frame. No bitstream is ever synthesised:\n * a generated \"fill\" picture is codec-specific, resets the reference chain\n * (an IDR) or is not a picture at all, and every later delta would decode\n * against it until the next RAP. Instead the sink keeps presenting the last\n * good frame, sized exactly from authored timestamps, until media resumes.\n *\n * - {@link videoConcealModeForCodec} says whether a video decoder can be fed\n * straight through a delta gap (H.264 conceals missing references itself)\n * or must hold until the next RAP.\n * - {@link HoldLastTimeline} gives MSE sinks gapless per-sample durations.\n * - {@link AudioGapConcealer} sizes audio concealment exactly: repeat the last\n * good access unit (MSE) or insert PCM silence (WebCodecs).\n */\n\nimport type { FrameGapDecision } from './block-policy.js'\n\n// \u2500\u2500\u2500 Video conceal mode \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * `feed-through`: keep feeding deltas after a delta-only gap; the decoder\n * conceals missing references and the canvas keeps the last frame.\n * `hold-to-rap`: drop non-RAP frames until the next RAP (no queue flush, no\n * A/V sync reset).\n */\nexport type VideoConcealMode = 'feed-through' | 'hold-to-rap'\n\n/**\n * AVC decoders conceal a missing reference and resynchronise on their own;\n * HEVC, AV1 and VP9 decoders error or freeze on a broken reference chain.\n * Any codec not known to conceal is held to the next RAP (fail-closed).\n */\nexport function videoConcealModeForCodec(codec: string): VideoConcealMode {\n const lower = codec.toLowerCase()\n if (lower.startsWith('avc1') || lower.startsWith('avc3')) return 'feed-through'\n return 'hold-to-rap'\n}\n\n// \u2500\u2500\u2500 HoldLastTimeline \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** One video sample in its media timescale. */\nexport interface TimelineSample<T> {\n readonly payload: T\n readonly dts: bigint\n readonly pts: bigint\n /** Authored duration in media ticks. */\n readonly duration: number\n /** Codec-aware RAP. */\n readonly keyframe: boolean\n readonly mpu?: number\n /** Decision attached by libmmt to the first frame released after a gap. */\n readonly gapBefore?: FrameGapDecision\n}\n\n/** A sample ready to append, with an explicit per-sample duration. */\nexport interface TimelineEmit<T> {\n readonly payload: T\n readonly dts: bigint\n readonly pts: bigint\n readonly duration: number\n readonly keyframe: boolean\n}\n\nexport interface HoldLastTimelineOptions {\n readonly concealMode: VideoConcealMode\n}\n\nexport interface HoldLastTimelineStats {\n /** Non-RAP frames dropped while waiting for a RAP. */\n droppedFrames: number\n /** Held frames whose duration was extended over a gap. */\n extendedHolds: number\n}\n\nconst U32_MAX = 0xffff_ffffn\n\n/**\n * Holds one video sample back so its duration can run to the next emitted\n * sample's dts. That costs exactly one frame of MSE latency (1000/framerate\n * ms, from the catalog) and buys a gapless hold-last without synthesising a\n * bitstream: a gap simply lengthens the last good frame.\n *\n * On a stall, or on any conceal under `hold-to-rap` except a RAP arriving\n * right after the gap, frames are dropped until the next RAP and the held\n * frame stays held until that RAP arrives, then runs exactly to its dts. The\n * element waits on the held frame for the length of the outage, but the\n * buffer never gets a hole, however many RAPs the outage took. Once the\n * stream shows composition offsets (dts \u2260 pts), samples pass straight\n * through with their authored durations and MSE starves until the RAP is\n * appended \u2014 the one documented case where the element also waits on audio.\n */\nexport class HoldLastTimeline<T> {\n readonly #concealMode: VideoConcealMode\n #held: TimelineSample<T> | null = null\n #dropping = false\n #compositionOffsets = false\n readonly #stats: HoldLastTimelineStats = { droppedFrames: 0, extendedHolds: 0 }\n\n constructor(options: HoldLastTimelineOptions) {\n this.#concealMode = options.concealMode\n }\n\n get stats(): Readonly<HoldLastTimelineStats> {\n return { ...this.#stats }\n }\n\n push(sample: TimelineSample<T>): TimelineEmit<T>[] {\n if (sample.dts !== sample.pts) this.#compositionOffsets = true\n\n if (this.#dropping) {\n if (!sample.keyframe) {\n this.#stats.droppedFrames++\n return []\n }\n this.#dropping = false\n return this.#accept(sample)\n }\n\n if (this.#dropsUntilRap(sample)) {\n this.#dropping = true\n this.#stats.droppedFrames++\n // The held frame stays held: the RAP's #accept sizes it exactly.\n return this.#compositionOffsets ? this.#releaseHeld() : []\n }\n\n return this.#accept(sample)\n }\n\n /** Release the held sample with its authored duration (end of stream). */\n flush(): TimelineEmit<T>[] {\n return this.#releaseHeld()\n }\n\n /** Drop all state for a new epoch. */\n reset(): void {\n this.#held = null\n this.#dropping = false\n this.#compositionOffsets = false\n }\n\n #accept(sample: TimelineSample<T>): TimelineEmit<T>[] {\n if (this.#compositionOffsets) {\n const out = this.#releaseHeld()\n out.push(this.#emit(sample, sample.duration))\n return out\n }\n const out: TimelineEmit<T>[] = []\n const held = this.#held\n if (held) out.push(this.#emit(held, this.#durationTo(held, sample.dts)))\n this.#held = sample\n return out\n }\n\n #dropsUntilRap(sample: TimelineSample<T>): boolean {\n const gap = sample.gapBefore\n if (!gap || gap.trackKind !== 'video' || sample.keyframe) return false\n if (gap.action === 'stall') return true\n return this.#concealMode === 'hold-to-rap' && gap.reason !== 'rap-next'\n }\n\n #durationTo(held: TimelineSample<T>, target: bigint): number {\n if (target <= held.dts) return held.duration\n const span = target - held.dts\n if (span > U32_MAX) return held.duration\n const duration = Number(span)\n if (duration !== held.duration) this.#stats.extendedHolds++\n return duration\n }\n\n #releaseHeld(): TimelineEmit<T>[] {\n const held = this.#held\n this.#held = null\n return held ? [this.#emit(held, held.duration)] : []\n }\n\n #emit(sample: TimelineSample<T>, duration: number): TimelineEmit<T> {\n return {\n payload: sample.payload,\n dts: sample.dts,\n pts: sample.pts,\n duration,\n keyframe: sample.keyframe,\n }\n }\n}\n\n// \u2500\u2500\u2500 AudioGapConcealer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * One audio access unit on its track's authored clock: the ISO-BMFF media\n * timescale the `audio-gap` decision was computed in (`decideGap`, from\n * `AuthoredTiming`). An AAC AU is exactly 1024 ticks there. Never pass values\n * rescaled to another timescale: 1024 samples at 48 kHz is 21333.33... \u00B5s,\n * which no integer tick count can hold.\n */\nexport interface AudioAccessUnit<T> {\n readonly payload: T\n /** Authored presentation time in media ticks (`AuthoredTiming.presentationTime`). */\n readonly pts: bigint\n /** Authored duration in media ticks (`AuthoredTiming.durationTicks`): a positive safe integer. */\n readonly duration: number\n}\n\nexport interface AudioGapConcealerStats {\n /**\n * Access units `note()` refused because their duration was not a positive\n * safe integer: not media ticks, so the AU cannot size a gap. The concealer\n * then holds no good AU and the next gap re-anchors. Non-zero means a caller\n * noted a rescaled value (e.g. microseconds) instead of authored ticks.\n */\n rejectedUnits: number\n}\n\nexport type AudioGapPlan<T> =\n | { readonly kind: 'none' }\n | {\n readonly kind: 'conceal'\n /**\n * MSE: the last good AU repeated into each missing slot. Empty when no\n * good AU has been seen yet; an AAC access unit is not portable across\n * AudioSpecificConfigs, so none is ever synthesised.\n */\n readonly repeat: AudioAccessUnit<T>[]\n /** WebCodecs: exactly this much PCM silence, in media ticks. */\n readonly silenceTicks: bigint\n }\n | {\n /** The gap is not a whole number of AUs: re-anchor at `pts`. */\n readonly kind: 're-anchor'\n readonly pts: bigint\n }\n\n/**\n * Sizes an audio gap from the libmmt gap decision. Audio never touches video\n * state: every plan is local to the audio sink.\n */\nexport class AudioGapConcealer<T> {\n #last: AudioAccessUnit<T> | null = null\n readonly #stats: AudioGapConcealerStats = { rejectedUnits: 0 }\n\n get stats(): Readonly<AudioGapConcealerStats> {\n return { ...this.#stats }\n }\n\n /**\n * Record a good access unit as it is emitted. An AU whose duration is not\n * whole media ticks is refused and counted (`stats.rejectedUnits`), and the\n * concealer forgets its previous AU: that one no longer precedes the gap, so\n * sizing from it would misplace every slot. Refusing here keeps `plan()`\n * total, so a bad AU never throws out of the packet path.\n */\n note(au: AudioAccessUnit<T>): void {\n if (!Number.isSafeInteger(au.duration) || au.duration <= 0) {\n this.#stats.rejectedUnits++\n this.#last = null\n return\n }\n this.#last = au\n }\n\n plan(decision: FrameGapDecision | undefined, next: { readonly pts: bigint }): AudioGapPlan<T> {\n if (!decision || decision.trackKind !== 'audio') return { kind: 'none' }\n const missing = decision.missingFrames\n if (\n decision.reason !== 'audio-gap' ||\n missing === null ||\n !Number.isSafeInteger(missing) ||\n missing <= 0\n ) {\n return { kind: 're-anchor', pts: next.pts }\n }\n const last = this.#last\n // Exact sizing needs the preceding AU's duration; a sink that has not\n // emitted one yet has nothing to hold and simply starts at the next AU.\n if (last === null) return { kind: 're-anchor', pts: next.pts }\n const duration = BigInt(last.duration)\n const repeat: AudioAccessUnit<T>[] = []\n for (let slot = 1; slot <= missing; slot++) {\n repeat.push({\n payload: last.payload,\n pts: last.pts + BigInt(slot) * duration,\n duration: last.duration,\n })\n }\n return { kind: 'conceal', repeat, silenceTicks: BigInt(missing) * duration }\n }\n\n reset(): void {\n this.#last = null\n }\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../src/feed-gate.ts", "../src/conceal-timeline.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The video feed gate: one loss rule for every codec.\n *\n * Each video frame states, in the `priority` byte of its MFU data-unit\n * header, the one earlier frame it needs (its anchor). The rule:\n *\n * Feed a frame only if its anchor was fed since the last keyframe.\n * A frame that states nothing needs every frame since the keyframe.\n * A decoder known to conceal a missing reference is fed everything.\n *\n * The gate answers only inside a GOP whose keyframe carried 254, and only\n * for a decoder that does not conceal. Everywhere else it answers `unread`\n * and the sink runs its own stall and hold: a stream whose keyframes carry\n * 255 takes no other path.\n *\n * - {@link decodeFrameNeeds} is the value map of the byte.\n * - {@link decoderTolerance} is the one codec table.\n * - {@link VideoFeedGate} is the rule. It keeps no timer and no deadline.\n */\n\n// \u2500\u2500\u2500 The value map \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** `priority` on a keyframe whose producer follows the map up to the next keyframe. */\nexport const FRAME_NEEDS_KEYFRAME = 254\n\n/** What one `priority` byte states. */\nexport interface FrameStatement {\n /** On a keyframe: every frame up to the next keyframe follows the map. */\n readonly map: boolean\n /** The anchor is this many frames back in decode order, 1 to 62. 0: nothing stated. */\n readonly distance: number\n /** False only when the frame states that no later frame needs it. */\n readonly mayBeNeeded: boolean\n}\n\nconst NOTHING_STATED: FrameStatement = Object.freeze({ map: false, distance: 0, mayBeNeeded: true })\nconst MAP_KEYFRAME: FrameStatement = Object.freeze({ map: true, distance: 0, mayBeNeeded: true })\n\n/**\n * Read one `priority` byte. On a keyframe only 254 states anything. On any\n * other frame bit 6 is \"a later frame may need me\" and bits 5 to 0 are the\n * distance back to the anchor; 0, 63, 64, 127 and every value above 127\n * state nothing.\n */\nexport function decodeFrameNeeds(code: number, keyframe: boolean): FrameStatement {\n if (keyframe) return code === FRAME_NEEDS_KEYFRAME ? MAP_KEYFRAME : NOTHING_STATED\n if (!Number.isInteger(code) || code < 1 || code > 126 || code === 63 || code === 64) {\n return NOTHING_STATED\n }\n return { map: false, distance: code & 0x3f, mayBeNeeded: code > 64 }\n}\n\n// \u2500\u2500\u2500 The decoder table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * `conceals`: the decoder draws through a missing reference and recovers by\n * itself, so it is fed everything. `none`: it errors, closes or draws a wrong\n * picture, so a frame whose reference is missing is never fed.\n */\nexport type DecoderTolerance = 'conceals' | 'none'\n\n/**\n * The only place a codec name decides loss handling. A page cannot ask which\n * decoder it got, so a codec conceals only when every decoder known for it\n * does: today that is H.264. Any other codec, known or not, gets `none`.\n */\nexport function decoderTolerance(codec: string): DecoderTolerance {\n const lower = codec.toLowerCase()\n return lower.startsWith('avc1') || lower.startsWith('avc3') ? 'conceals' : 'none'\n}\n\n// \u2500\u2500\u2500 The gate \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** One frame's statement as the router read it. Opaque to a sink: forward it like `gapBefore`. */\nexport interface FrameNeeds {\n /** MPU_sequence_number of the frame. */\n readonly mpu: number\n /** The frame's place in decode order: its movie_fragment_sequence_number. */\n readonly position: number\n /** The `priority` byte. */\n readonly code: number\n}\n\n/** `unread`: the gate states nothing about this frame, run your own code. */\nexport type GateAnswer = 'unread' | 'feed' | 'withhold'\n\nexport interface GateFrame {\n /** Codec-aware RAP check on this frame's bitstream. */\n readonly keyframe: boolean\n readonly needs?: FrameNeeds\n}\n\nexport interface VideoFeedGateOptions {\n readonly tolerance: DecoderTolerance\n}\n\nexport interface VideoFeedGateStats {\n /** Frames fed after a missing frame of their GOP. */\n fedAcrossGap: number\n /** Frames the gate answered `withhold` for. A late or repeated frame is not counted. */\n withheld: number\n /** Decoder failures after a frame was fed across a gap. Must stay 0. */\n selectiveFeedFailures: number\n /** Statements that reached before their keyframe. Must stay 0. */\n statementViolations: number\n}\n\n/**\n * Per-decoder feed state. A sink asks {@link admit} about every frame that\n * is not a keyframe, after its own stall test; reports with {@link fed} each\n * frame it hands to its decoder or buffer, keyframes included; and calls\n * {@link requireKeyframe} where it stalls, resets its decoder or empties its\n * queue. \"Fed\" is what the sink reports, never what the gate allowed: a frame\n * the sink drops for a reason of its own is not recorded, so every frame\n * anchored on it is withheld. An answer rests on the reports made before it,\n * so a sink reports one frame before it asks about the next.\n */\nexport class VideoFeedGate {\n readonly #inert: boolean\n /** A statement was false, or a decoder failed on a selective feed: this track is read no more. */\n #off = false\n /** `hold`: reading stopped inside a GOP in which the gate had answered for a hole. */\n #mode: 'unread' | 'reading' | 'hold' = 'unread'\n #keyMpu = 0\n #keyPosition = 0\n /** Slot `position & 63` holds the position fed there: the last 64 positions. */\n readonly #fedAt = new Float64Array(64).fill(-1)\n /** Frames fed since the keyframe. */\n #fedCount = 0\n /** Place after the keyframe of the last frame fed. */\n #top = 0\n /** Place after the keyframe of the last frame the gate allowed. */\n #allowed = 0\n #withheldInGop = false\n #fedAcrossGap = false\n /** A decoder may report a failure after the next keyframe went in. */\n #fedAcrossGapBefore = false\n #lastWithheld: FrameNeeds | undefined\n readonly #stats: VideoFeedGateStats = {\n fedAcrossGap: 0,\n withheld: 0,\n selectiveFeedFailures: 0,\n statementViolations: 0,\n }\n\n constructor(options: VideoFeedGateOptions) {\n // Anything but an explicit `none` leaves the sink on its own code.\n this.#inert = options.tolerance !== 'none'\n }\n\n /** True while the gate answers from the statements of the current GOP. */\n get reading(): boolean {\n return this.#mode === 'reading'\n }\n\n get stats(): Readonly<VideoFeedGateStats> {\n return { ...this.#stats }\n }\n\n /**\n * May this frame be fed? Records no frame as fed, so a sink may ask twice\n * about one frame. `unread` for a keyframe, a concealing decoder, a GOP\n * whose keyframe did not carry 254, and a track switched off. A late or\n * repeated frame is refused with `withhold` and not counted.\n */\n admit(frame: GateFrame): GateAnswer {\n if (frame.keyframe) return 'unread'\n const needs = frame.needs\n if (this.#mode === 'reading') {\n if (needs === undefined || needs.code > 128) {\n // No position, or a keyframe's byte on a frame the sink takes for none: this GOP cannot be read.\n this.#stopReading()\n } else {\n const offset = this.#offset(needs)\n // A late or repeated frame is no hole in the GOP.\n if (offset < 0) return 'withhold'\n if (offset === 0) return this.#withhold(needs)\n const { distance } = decodeFrameNeeds(needs.code, false)\n if (distance > offset) {\n // An anchor is never earlier than the keyframe: this sender does not follow the map.\n this.#stats.statementViolations++\n this.#off = true\n this.#stopReading()\n } else {\n const whole = this.#fedCount === offset - 1\n const anchor = (needs.position - distance) >>> 0\n const anchorFed = distance === 0\n ? whole\n : distance === offset || this.#fedAt[anchor & 63] === anchor\n if (!anchorFed) return this.#withhold(needs)\n this.#allowed = Math.max(this.#allowed, offset)\n return 'feed'\n }\n }\n }\n return this.#mode === 'hold' ? this.#withhold(needs) : 'unread'\n }\n\n /** The sink handed this frame to its decoder or buffer. */\n fed(frame: GateFrame): void {\n const needs = frame.needs\n if (frame.keyframe) {\n this.#fedAcrossGapBefore = this.#fedAcrossGap\n this.#fedAcrossGap = false\n this.#clear()\n if (\n this.#inert || this.#off || needs === undefined ||\n !decodeFrameNeeds(needs.code, true).map\n ) return\n this.#mode = 'reading'\n this.#keyMpu = needs.mpu\n this.#keyPosition = needs.position >>> 0\n return\n }\n if (this.#mode !== 'reading') return\n if (needs === undefined || needs.code > 128) {\n this.#stopReading()\n return\n }\n const offset = this.#offset(needs)\n if (offset <= 0) return\n if (this.#fedCount !== offset - 1) {\n this.#fedAcrossGap = true\n this.#stats.fedAcrossGap++\n }\n const position = needs.position >>> 0\n this.#fedAt[position & 63] = position\n this.#fedCount++\n this.#top = offset\n }\n\n /** The sink stalled, reset its decoder or emptied its queue: nothing is read before the next keyframe. */\n requireKeyframe(): void {\n this.#clear()\n }\n\n /**\n * The decoder raised an error or closed. Returns true when a frame had been\n * fed across a gap: the decoder could not take the selective feed, so no\n * statement is read on this track again. Either way the reading of this GOP\n * stops, and the rest of a GOP with a hole the gate answered for is withheld.\n */\n onDecoderFailure(): boolean {\n const selective = this.#fedAcrossGap || this.#fedAcrossGapBefore\n this.#fedAcrossGap = false\n this.#fedAcrossGapBefore = false\n if (selective) {\n this.#stats.selectiveFeedFailures++\n this.#off = true\n }\n if (this.#mode === 'reading') this.#stopReading()\n if (this.#mode !== 'hold') this.#clear()\n return selective\n }\n\n #clear(): void {\n this.#mode = 'unread'\n this.#fedAt.fill(-1)\n this.#fedCount = 0\n this.#top = 0\n this.#allowed = 0\n this.#withheldInGop = false\n }\n\n /** The frame's place after the keyframe. 0: another MPU. -1: late or repeated, not after the last frame fed. */\n #offset(needs: FrameNeeds): number {\n // Positions may restart per MPU, so a stale bit of another MPU must never look like a fed anchor.\n if (needs.mpu !== this.#keyMpu) return 0\n const offset = (needs.position - this.#keyPosition) >>> 0\n return offset > this.#top && offset < 0x8000_0000 ? offset : -1\n }\n\n /**\n * The sink's own hold never saw a hole the gate answered for: a frame it\n * withheld, or one it allowed that was not fed. The gate then holds the\n * rest of that GOP itself.\n */\n #stopReading(): void {\n this.#mode = this.#withheldInGop || this.#fedCount < this.#allowed ? 'hold' : 'unread'\n }\n\n #withhold(needs: FrameNeeds | undefined): GateAnswer {\n this.#withheldInGop = true\n const last = this.#lastWithheld\n // A sink may ask twice about one frame: it is counted once.\n if (\n needs === undefined || last === undefined ||\n needs.mpu !== last.mpu || needs.position !== last.position\n ) {\n this.#stats.withheld++\n }\n this.#lastWithheld = needs\n return 'withhold'\n }\n}\n", "/**\n * Sink-side concealment helpers for the keyframe-protected FEC policy.\n *\n * Concealment is hold-last-good-frame. No bitstream is ever synthesised:\n * a generated \"fill\" picture is codec-specific, resets the reference chain\n * (an IDR) or is not a picture at all, and every later delta would decode\n * against it until the next RAP. Instead the sink keeps presenting the last\n * good frame, sized exactly from authored timestamps, until media resumes.\n *\n * - {@link videoConcealModeForCodec} says whether a video decoder can be fed\n * straight through a delta gap (H.264 conceals missing references itself)\n * or must hold until the next RAP.\n * - {@link HoldLastTimeline} gives MSE sinks gapless per-sample durations. It\n * owns a {@link VideoFeedGate}, so a stream that states what each frame\n * needs holds only the frames a loss reaches.\n * - {@link AudioGapConcealer} sizes audio concealment exactly: repeat the last\n * good access unit (MSE) or insert PCM silence (WebCodecs).\n */\n\nimport type { FrameGapDecision } from './block-policy.js'\nimport {\n VideoFeedGate,\n decoderTolerance,\n type DecoderTolerance,\n type FrameNeeds,\n type GateAnswer,\n type VideoFeedGateStats,\n} from './feed-gate.js'\n\n// \u2500\u2500\u2500 Video conceal mode \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * `feed-through`: keep feeding deltas after a delta-only gap; the decoder\n * conceals missing references and the canvas keeps the last frame.\n * `hold-to-rap`: drop non-RAP frames until the next RAP (no queue flush, no\n * A/V sync reset).\n */\nexport type VideoConcealMode = 'feed-through' | 'hold-to-rap'\n\n/**\n * AVC decoders conceal a missing reference and resynchronise on their own;\n * HEVC, AV1 and VP9 decoders error or freeze on a broken reference chain.\n * Any codec not known to conceal is held to the next RAP (fail-closed).\n * The codec table itself is {@link decoderTolerance}.\n */\nexport function videoConcealModeForCodec(codec: string): VideoConcealMode {\n return decoderTolerance(codec) === 'conceals' ? 'feed-through' : 'hold-to-rap'\n}\n\n// \u2500\u2500\u2500 HoldLastTimeline \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** One video sample in its media timescale. */\nexport interface TimelineSample<T> {\n readonly payload: T\n readonly dts: bigint\n readonly pts: bigint\n /** Authored duration in media ticks. */\n readonly duration: number\n /** Codec-aware RAP. */\n readonly keyframe: boolean\n readonly mpu?: number\n /** Decision attached by libmmt to the first frame released after a gap. */\n readonly gapBefore?: FrameGapDecision\n /** The frame's dependency statement (`RoutedFrameMeta.needs`), forwarded as is. */\n readonly needs?: FrameNeeds\n}\n\n/** A sample ready to append, with an explicit per-sample duration. */\nexport interface TimelineEmit<T> {\n readonly payload: T\n readonly dts: bigint\n readonly pts: bigint\n readonly duration: number\n readonly keyframe: boolean\n}\n\nexport interface HoldLastTimelineOptions {\n readonly concealMode: VideoConcealMode\n /** `decoderTolerance(codec)`. Omitted, no statement is read. */\n readonly tolerance?: DecoderTolerance\n}\n\nexport interface HoldLastTimelineStats {\n /** Non-RAP frames dropped while waiting for a RAP. */\n droppedFrames: number\n /** Held frames whose duration was extended over a gap. */\n extendedHolds: number\n}\n\nconst U32_MAX = 0xffff_ffffn\n\n/**\n * Holds one video sample back so its duration can run to the next emitted\n * sample's dts. That costs exactly one frame of MSE latency (1000/framerate\n * ms, from the catalog) and buys a gapless hold-last without synthesising a\n * bitstream: a gap simply lengthens the last good frame.\n *\n * On a stall, or on any conceal under `hold-to-rap` except a RAP arriving\n * right after the gap, frames are dropped until the next RAP and the held\n * frame stays held until that RAP arrives, then runs exactly to its dts. The\n * element waits on the held frame for the length of the outage, but the\n * buffer never gets a hole, however many RAPs the outage took. Once the\n * stream shows composition offsets (dts \u2260 pts), samples pass straight\n * through with their authored durations and MSE starves until the RAP is\n * appended \u2014 the one documented case where the element also waits on audio.\n *\n * Inside a GOP the feed gate reads, a sample whose anchor was not fed is\n * withheld alone: the held frame stays held and the next fed sample sizes it.\n * With composition offsets there is no stretch, so a withheld sample holds to\n * the next RAP. So does the first sample with an offset when it follows a\n * withheld one.\n */\nexport class HoldLastTimeline<T> {\n readonly #concealMode: VideoConcealMode\n readonly #gate: VideoFeedGate\n #held: TimelineSample<T> | null = null\n #dropping = false\n #compositionOffsets = false\n /** A sample was withheld and the held frame has not yet been stretched over it. */\n #skipped = false\n readonly #stats: HoldLastTimelineStats = { droppedFrames: 0, extendedHolds: 0 }\n\n constructor(options: HoldLastTimelineOptions) {\n this.#concealMode = options.concealMode\n this.#gate = new VideoFeedGate({ tolerance: options.tolerance ?? 'conceals' })\n }\n\n get stats(): Readonly<HoldLastTimelineStats> {\n return { ...this.#stats }\n }\n\n /** What the feed gate withheld and fed across a gap. */\n get gateStats(): Readonly<VideoFeedGateStats> {\n return this.#gate.stats\n }\n\n /**\n * The sink's decoder failed. True when a frame had been fed across a gap: the gate then\n * reads no statement on this track again. The rest of a GOP in which the gate withheld a\n * sample or fed one across a gap is not appended. Nothing else changes; to start over,\n * call {@link reset}.\n */\n onDecoderFailure(): boolean {\n return this.#gate.onDecoderFailure()\n }\n\n push(sample: TimelineSample<T>): TimelineEmit<T>[] {\n if (sample.dts !== sample.pts) this.#compositionOffsets = true\n\n if (this.#dropping) {\n if (!sample.keyframe) {\n this.#stats.droppedFrames++\n return []\n }\n this.#dropping = false\n return this.#accept(sample)\n }\n\n const gap = sample.gapBefore\n // The timeline's own stall test comes first: the gate is not asked about a frame that stalls.\n const stalls = !sample.keyframe && gap?.trackKind === 'video' && gap.action === 'stall'\n const answer: GateAnswer = stalls ? 'unread' : this.#gate.admit(sample)\n // Without the stretch a withheld sample would leave a hole, so offsets keep the hold to the RAP.\n const selective = answer !== 'unread' && !this.#compositionOffsets\n if (selective && answer === 'withhold') {\n // The held frame stays held: the next fed sample sizes it.\n this.#skipped = true\n return []\n }\n // Offsets end the stretch, so a sample after a skipped one would be appended behind a hole.\n const holed = this.#skipped && this.#compositionOffsets && !sample.keyframe\n if (answer === 'withhold' || holed || (!selective && this.#dropsUntilRap(sample))) {\n this.#dropping = true\n this.#stats.droppedFrames++\n // The held frame stays held: the RAP's #accept sizes it exactly.\n return this.#compositionOffsets ? this.#releaseHeld() : []\n }\n\n return this.#accept(sample)\n }\n\n /** Release the held sample with its authored duration (end of stream). */\n flush(): TimelineEmit<T>[] {\n return this.#releaseHeld()\n }\n\n /** Drop all state for a new epoch. */\n reset(): void {\n this.#held = null\n this.#dropping = false\n this.#compositionOffsets = false\n this.#skipped = false\n this.#gate.requireKeyframe()\n }\n\n #accept(sample: TimelineSample<T>): TimelineEmit<T>[] {\n this.#gate.fed(sample)\n this.#skipped = false\n if (this.#compositionOffsets) {\n const out = this.#releaseHeld()\n out.push(this.#emit(sample, sample.duration))\n return out\n }\n const out: TimelineEmit<T>[] = []\n const held = this.#held\n if (held) out.push(this.#emit(held, this.#durationTo(held, sample.dts)))\n this.#held = sample\n return out\n }\n\n #dropsUntilRap(sample: TimelineSample<T>): boolean {\n const gap = sample.gapBefore\n if (!gap || gap.trackKind !== 'video' || sample.keyframe) return false\n if (gap.action === 'stall') return true\n return this.#concealMode === 'hold-to-rap' && gap.reason !== 'rap-next'\n }\n\n #durationTo(held: TimelineSample<T>, target: bigint): number {\n if (target <= held.dts) return held.duration\n const span = target - held.dts\n if (span > U32_MAX) return held.duration\n const duration = Number(span)\n if (duration !== held.duration) this.#stats.extendedHolds++\n return duration\n }\n\n #releaseHeld(): TimelineEmit<T>[] {\n const held = this.#held\n this.#held = null\n return held ? [this.#emit(held, held.duration)] : []\n }\n\n #emit(sample: TimelineSample<T>, duration: number): TimelineEmit<T> {\n return {\n payload: sample.payload,\n dts: sample.dts,\n pts: sample.pts,\n duration,\n keyframe: sample.keyframe,\n }\n }\n}\n\n// \u2500\u2500\u2500 AudioGapConcealer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * One audio access unit on its track's authored clock: the ISO-BMFF media\n * timescale the `audio-gap` decision was computed in (`decideGap`, from\n * `AuthoredTiming`). An AAC AU is exactly 1024 ticks there. Never pass values\n * rescaled to another timescale: 1024 samples at 48 kHz is 21333.33... \u00B5s,\n * which no integer tick count can hold.\n */\nexport interface AudioAccessUnit<T> {\n readonly payload: T\n /** Authored presentation time in media ticks (`AuthoredTiming.presentationTime`). */\n readonly pts: bigint\n /** Authored duration in media ticks (`AuthoredTiming.durationTicks`): a positive safe integer. */\n readonly duration: number\n}\n\nexport interface AudioGapConcealerStats {\n /**\n * Access units `note()` refused because their duration was not a positive\n * safe integer: not media ticks, so the AU cannot size a gap. The concealer\n * then holds no good AU and the next gap re-anchors. Non-zero means a caller\n * noted a rescaled value (e.g. microseconds) instead of authored ticks.\n */\n rejectedUnits: number\n}\n\nexport type AudioGapPlan<T> =\n | { readonly kind: 'none' }\n | {\n readonly kind: 'conceal'\n /**\n * MSE: the last good AU repeated into each missing slot. Empty when no\n * good AU has been seen yet; an AAC access unit is not portable across\n * AudioSpecificConfigs, so none is ever synthesised.\n */\n readonly repeat: AudioAccessUnit<T>[]\n /** WebCodecs: exactly this much PCM silence, in media ticks. */\n readonly silenceTicks: bigint\n }\n | {\n /** The gap is not a whole number of AUs: re-anchor at `pts`. */\n readonly kind: 're-anchor'\n readonly pts: bigint\n }\n\n/**\n * Sizes an audio gap from the libmmt gap decision. Audio never touches video\n * state: every plan is local to the audio sink.\n */\nexport class AudioGapConcealer<T> {\n #last: AudioAccessUnit<T> | null = null\n readonly #stats: AudioGapConcealerStats = { rejectedUnits: 0 }\n\n get stats(): Readonly<AudioGapConcealerStats> {\n return { ...this.#stats }\n }\n\n /**\n * Record a good access unit as it is emitted. An AU whose duration is not\n * whole media ticks is refused and counted (`stats.rejectedUnits`), and the\n * concealer forgets its previous AU: that one no longer precedes the gap, so\n * sizing from it would misplace every slot. Refusing here keeps `plan()`\n * total, so a bad AU never throws out of the packet path.\n */\n note(au: AudioAccessUnit<T>): void {\n if (!Number.isSafeInteger(au.duration) || au.duration <= 0) {\n this.#stats.rejectedUnits++\n this.#last = null\n return\n }\n this.#last = au\n }\n\n plan(decision: FrameGapDecision | undefined, next: { readonly pts: bigint }): AudioGapPlan<T> {\n if (!decision || decision.trackKind !== 'audio') return { kind: 'none' }\n const missing = decision.missingFrames\n if (\n decision.reason !== 'audio-gap' ||\n missing === null ||\n !Number.isSafeInteger(missing) ||\n missing <= 0\n ) {\n return { kind: 're-anchor', pts: next.pts }\n }\n const last = this.#last\n // Exact sizing needs the preceding AU's duration; a sink that has not\n // emitted one yet has nothing to hold and simply starts at the next AU.\n if (last === null) return { kind: 're-anchor', pts: next.pts }\n const duration = BigInt(last.duration)\n const repeat: AudioAccessUnit<T>[] = []\n for (let slot = 1; slot <= missing; slot++) {\n repeat.push({\n payload: last.payload,\n pts: last.pts + BigInt(slot) * duration,\n duration: last.duration,\n })\n }\n return { kind: 'conceal', repeat, silenceTicks: BigInt(missing) * duration }\n }\n\n reset(): void {\n this.#last = null\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAuBO,IAAM,uBAAuB;AAYpC,IAAM,iBAAiC,OAAO,OAAO,EAAE,KAAK,OAAO,UAAU,GAAG,aAAa,KAAK,CAAC;AACnG,IAAM,eAA+B,OAAO,OAAO,EAAE,KAAK,MAAM,UAAU,GAAG,aAAa,KAAK,CAAC;AAQzF,SAAS,iBAAiB,MAAc,UAAmC;AAChF,MAAI,SAAU,QAAO,SAAS,uBAAuB,eAAe;AACpE,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAAO,SAAS,MAAM,SAAS,IAAI;AACnF,WAAO;AAAA,EACT;AACA,SAAO,EAAE,KAAK,OAAO,UAAU,OAAO,IAAM,aAAa,OAAO,GAAG;AACrE;AAgBO,SAAS,iBAAiB,OAAiC;AAChE,QAAM,QAAQ,MAAM,YAAY;AAChC,SAAO,MAAM,WAAW,MAAM,KAAK,MAAM,WAAW,MAAM,IAAI,aAAa;AAC7E;AAgDO,IAAM,gBAAN,MAAoB;AAAA,EAChB;AAAA;AAAA,EAET,OAAO;AAAA;AAAA,EAEP,QAAuC;AAAA,EACvC,UAAU;AAAA,EACV,eAAe;AAAA;AAAA,EAEN,SAAS,IAAI,aAAa,EAAE,EAAE,KAAK,EAAE;AAAA;AAAA,EAE9C,YAAY;AAAA;AAAA,EAEZ,OAAO;AAAA;AAAA,EAEP,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,gBAAgB;AAAA;AAAA,EAEhB,sBAAsB;AAAA,EACtB;AAAA,EACS,SAA6B;AAAA,IACpC,cAAc;AAAA,IACd,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AAAA,EAEA,YAAY,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,QACZ,CAAC,OAAO,cAAc,OAAO,KAC7B,WAAW,GACX;AACA,aAAO,EAAE,MAAM,aAAa,KAAK,KAAK,IAAI;AAAA,IAC5C;AACA,UAAM,OAAO,KAAK;AAGlB,QAAI,SAAS,KAAM,QAAO,EAAE,MAAM,aAAa,KAAK,KAAK,IAAI;AAC7D,UAAM,WAAW,OAAO,KAAK,QAAQ;AACrC,UAAM,SAA+B,CAAC;AACtC,aAAS,OAAO,GAAG,QAAQ,SAAS,QAAQ;AAC1C,aAAO,KAAK;AAAA,QACV,SAAS,KAAK;AAAA,QACd,KAAK,KAAK,MAAM,OAAO,IAAI,IAAI;AAAA,QAC/B,UAAU,KAAK;AAAA,MACjB,CAAC;AAAA,IACH;AACA,WAAO,EAAE,MAAM,WAAW,QAAQ,cAAc,OAAO,OAAO,IAAI,SAAS;AAAA,EAC7E;AAAA,EAEA,QAAc;AACZ,SAAK,QAAQ;AAAA,EACf;AACF;",
|
|
6
6
|
"names": ["out"]
|
|
7
7
|
}
|
|
@@ -63,7 +63,8 @@ export interface DatagramLegWatchOptions {
|
|
|
63
63
|
/**
|
|
64
64
|
* The limits, read each time a clock is armed, so a delay target that moves
|
|
65
65
|
* is followed (call `refresh()` when it shrinks). A result without numbers
|
|
66
|
-
* keeps the last good ones
|
|
66
|
+
* keeps the last good ones; with none yet, the watch arms nothing until
|
|
67
|
+
* `refresh()`. `() => computeDatagramLegDeadlines(...)` fits.
|
|
67
68
|
*/
|
|
68
69
|
readonly limits: () => Partial<DatagramLegLimits> | undefined;
|
|
69
70
|
/** true: the subscription starts at the next group. false: the join brings the current group by a fill. */
|
|
@@ -111,8 +112,31 @@ export declare class DatagramLegWatch {
|
|
|
111
112
|
}): void;
|
|
112
113
|
/** false while the player itself does not read the track: that time is not silence. */
|
|
113
114
|
setReading(reading: boolean): void;
|
|
114
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* The limits moved: arm on the new ones now. Call it when the delay target
|
|
117
|
+
* shrinks, and when `limits()` first has numbers after the watch started
|
|
118
|
+
* without them: an unarmed watch stays unarmed through frames and through
|
|
119
|
+
* every source datagram but the first.
|
|
120
|
+
*/
|
|
115
121
|
refresh(): void;
|
|
116
122
|
stop(): void;
|
|
117
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* How long a player stays on the "mfu" sibling before it takes the
|
|
126
|
+
* "mfu-datagram" leg again, after the leg was handed back on a timer:
|
|
127
|
+
* `ceil(joinDarkMs x 2^n x (1 + rand))`. `n` counts the timed hand-backs in a
|
|
128
|
+
* row (0 after the first; the player resets it once a leg held the rendition
|
|
129
|
+
* longer than its last wait). `rand` in [0, 1) comes from the caller, so the
|
|
130
|
+
* function stays pure and its vectors exact.
|
|
131
|
+
*
|
|
132
|
+
* Never throws, and never waits less than `joinDarkMs`: an `n` that is not a
|
|
133
|
+
* finite number >= 0 counts as 0 (a fraction is floored), a `rand` outside
|
|
134
|
+
* [0, 1) counts as 0. A `joinDarkMs` that is not a finite number > 0 has no
|
|
135
|
+
* leg to return to: undefined. A very large `n` yields Infinity, never a wrap.
|
|
136
|
+
*
|
|
137
|
+
* Not a `setTimeout` delay as it stands. A delay above 2147483647 ms
|
|
138
|
+
* (2^31 - 1) fires early, and Infinity at once: arm no timer for Infinity,
|
|
139
|
+
* and clamp the rest.
|
|
140
|
+
*/
|
|
141
|
+
export declare function datagramLegRetryDelayMs(joinDarkMs: number, n: number, rand: number): number | undefined;
|
|
118
142
|
//# sourceMappingURL=datagram-leg-deadline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datagram-leg-deadline.d.ts","sourceRoot":"","sources":["../src/datagram-leg-deadline.ts"],"names":[],"mappings":"AASA,yEAAyE;AACzE,MAAM,WAAW,sBAAsB;IACrC,+DAA+D;IAC/D,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IACnC,8EAA8E;IAC9E,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CACrC;AAED,MAAM,WAA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MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,IAAI;IAUtG,uFAAuF;IACvF,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAYlC;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAMf,IAAI,IAAI,IAAI;CAoGb;AAKD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIvG"}
|
|
@@ -113,7 +113,12 @@ var DatagramLegWatch = class {
|
|
|
113
113
|
this.#pausedAt = void 0;
|
|
114
114
|
if (this.#timer === void 0) this.#arm();
|
|
115
115
|
}
|
|
116
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* The limits moved: arm on the new ones now. Call it when the delay target
|
|
118
|
+
* shrinks, and when `limits()` first has numbers after the watch started
|
|
119
|
+
* without them: an unarmed watch stays unarmed through frames and through
|
|
120
|
+
* every source datagram but the first.
|
|
121
|
+
*/
|
|
117
122
|
refresh() {
|
|
118
123
|
if (this.#stopped) return;
|
|
119
124
|
this.#suspect = void 0;
|
|
@@ -210,8 +215,15 @@ var DatagramLegWatch = class {
|
|
|
210
215
|
this.#options.onVerdict(verdict, silentMs, clock.limit);
|
|
211
216
|
}
|
|
212
217
|
};
|
|
218
|
+
var wholeCount = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : 0;
|
|
219
|
+
function datagramLegRetryDelayMs(joinDarkMs, n, rand) {
|
|
220
|
+
if (!positive(joinDarkMs)) return void 0;
|
|
221
|
+
const jitter = typeof rand === "number" && rand >= 0 && rand < 1 ? rand : 0;
|
|
222
|
+
return Math.ceil(joinDarkMs * 2 ** wholeCount(n) * (1 + jitter));
|
|
223
|
+
}
|
|
213
224
|
export {
|
|
214
225
|
DatagramLegWatch,
|
|
215
|
-
computeDatagramLegDeadlines
|
|
226
|
+
computeDatagramLegDeadlines,
|
|
227
|
+
datagramLegRetryDelayMs
|
|
216
228
|
};
|
|
217
229
|
//# sourceMappingURL=datagram-leg-deadline.js.map
|