@torrent-tv/proxy 2.80.8 → 2.80.10
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/CHANGELOG.md +1675 -1658
- package/bin/cli.js +606 -596
- package/package.json +51 -50
- package/services/data-channel-handler.js +2 -4
- package/services/encode/CoverageMap.js +428 -401
- package/services/encode/EncodePlan.js +0 -3
- package/services/encode/EncodeRun.js +14 -0
- package/services/encode/SegmentStore.js +718 -669
- package/services/hls-session-manager.js +44 -162
- package/services/hwaccel.js +2 -2
- package/services/memory-report.js +596 -592
- package/services/orchestrators/EncodeOrchestrator.js +143 -11
- package/services/quality/EncodeCost.js +555 -555
- package/test/auto-quality-step.test.js +514 -507
- package/test/contention.test.js +1 -1
- package/test/coverage-follows-the-disk.test.js +187 -0
- package/test/coverage-map.test.js +195 -178
- package/test/encode-orchestrator.test.js +1 -2
- package/test/encode-plan-viewers.test.js +18 -19
- package/test/encode-plan.test.js +3 -4
- package/test/held-request-width.test.js +155 -154
- package/test/helpers/encode-run.js +136 -128
- package/test/orchestrator-wired.test.js +16 -11
- package/test/produced-copy-choice.test.js +358 -327
- package/test/run-intervals.test.js +100 -100
- package/test/segment-serve-wiring.test.js +76 -20
- package/test/segment-store.test.js +216 -187
- package/test/stale-request-after-seek.test.js +51 -77
- package/test/tracks-begin-together.test.js +176 -153
- package/test/viewer-outputs.test.js +278 -273
- package/test/behind-head-repair.test.js +0 -261
- /package/services/{contention.js → encode/contention.js} +0 -0
- /package/{test/decode-cost.test.js → test-measured/decode-cost.measured.js} +0 -0
- /package/{test/decode-measurement.test.js → test-measured/decode-measurement.measured.js} +0 -0
package/test/contention.test.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import assert from "node:assert/strict";
|
|
11
11
|
import test from "node:test";
|
|
12
12
|
|
|
13
|
-
import { contentionPenalty, costWithContention, penaltiesFrom } from "../services/contention.js";
|
|
13
|
+
import { contentionPenalty, costWithContention, penaltiesFrom } from "../services/encode/contention.js";
|
|
14
14
|
|
|
15
15
|
/** The addon host's own readings. */
|
|
16
16
|
const ALONE = 2.2;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file What the plan believes exists is what the disk holds — with a real
|
|
3
|
+
* store, a real directory, and no ffmpeg.
|
|
4
|
+
*
|
|
5
|
+
* The failure these are written against, field 2026-09-07, twice in one evening
|
|
6
|
+
* on `Star.Trek.Strange.New.Worlds.S04E03`:
|
|
7
|
+
*
|
|
8
|
+
* > `encode: … ready=482 zones=[p100:#0..#0 …] runs=[#0..#0@0.0x] waiting=nobody`
|
|
9
|
+
* > `encode-run stopped #0..#0 …, reached #-1 (0 segment(s)) after 2778ms,`
|
|
10
|
+
* > `signal SIGTERM: the film is no worse off without it`
|
|
11
|
+
* > `encode: … ready=482 … runs=[] waiting=nobody`
|
|
12
|
+
*
|
|
13
|
+
* The map claimed every one of the film's 482 segments while the directory held
|
|
14
|
+
* nothing a header could be lifted out of, so every arrangement scored perfect,
|
|
15
|
+
* the only encoder was taken away as unnecessary and none was placed again. The
|
|
16
|
+
* viewer's browser asked for the init segment, was never answered, and gave up.
|
|
17
|
+
*
|
|
18
|
+
* Readiness had been accumulating for the life of the process: the map was told
|
|
19
|
+
* what existed and never told what had stopped existing — the word for that
|
|
20
|
+
* existed and was called from no line of the product. So these check the one
|
|
21
|
+
* property that makes the whole class of failure impossible: what the map says
|
|
22
|
+
* is ready is what the store can prove right now, and nothing older.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import test from "node:test";
|
|
26
|
+
import assert from "node:assert/strict";
|
|
27
|
+
import { EventEmitter } from "node:events";
|
|
28
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
29
|
+
import os from "node:os";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import { EncodeRun } from "../services/encode/EncodeRun.js";
|
|
32
|
+
import { SegmentStore } from "../services/encode/SegmentStore.js";
|
|
33
|
+
import { SoftwareEncoder } from "../services/encode/SoftwareEncoder.js";
|
|
34
|
+
import { EncodeOrchestrator } from "../services/orchestrators/EncodeOrchestrator.js";
|
|
35
|
+
import { fmp4Format } from "../services/segment-formats/fmp4.js";
|
|
36
|
+
|
|
37
|
+
const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
38
|
+
const SEGMENTS = 482;
|
|
39
|
+
|
|
40
|
+
class FakeProcess extends EventEmitter {
|
|
41
|
+
constructor() {
|
|
42
|
+
super();
|
|
43
|
+
this.pid = 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
kill(signal) {
|
|
47
|
+
this.emit("exit", null, signal);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A store on a real directory, and an orchestrator that owns it.
|
|
53
|
+
*
|
|
54
|
+
* @returns {{ made: EncodeOrchestrator, store: SegmentStore, dir: string,
|
|
55
|
+
* root: string, lines: string[] }}
|
|
56
|
+
*/
|
|
57
|
+
function orchestratorWithAStore() {
|
|
58
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "coverage-disk-"));
|
|
59
|
+
const lines = [];
|
|
60
|
+
const logger = { info: (line) => lines.push(line), warn: (line) => lines.push(line) };
|
|
61
|
+
const store = new SegmentStore({ root, logger });
|
|
62
|
+
store.useFormat(PICTURE, fmp4Format);
|
|
63
|
+
const dir = store.directoryFor(PICTURE);
|
|
64
|
+
/** @type {EncodeOrchestrator} */
|
|
65
|
+
let made;
|
|
66
|
+
made = new EncodeOrchestrator({
|
|
67
|
+
maxRunsFor: () => 1,
|
|
68
|
+
segmentSeconds: 6,
|
|
69
|
+
killCostSec: 0,
|
|
70
|
+
firstByteWaitSec: 0.12,
|
|
71
|
+
refetchSecPerFilmSecond: () => 0.25,
|
|
72
|
+
startingSpeedFor: () => 2,
|
|
73
|
+
segmentStore: store,
|
|
74
|
+
now: () => 1000,
|
|
75
|
+
logger,
|
|
76
|
+
makeRun: ({ address, from, to }) => new EncodeRun({
|
|
77
|
+
address,
|
|
78
|
+
encoder: new SoftwareEncoder(),
|
|
79
|
+
from,
|
|
80
|
+
to,
|
|
81
|
+
buildArgs: () => ["-i", "in", "out"],
|
|
82
|
+
spawn: () => new FakeProcess(),
|
|
83
|
+
logger,
|
|
84
|
+
now: () => 1000,
|
|
85
|
+
onEnded: (ended) => made.noteEnded(ended)
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
made.setSegmentCount(PICTURE, SEGMENTS);
|
|
89
|
+
return { made, store, dir, root, lines };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A viewer stopped at the beginning, which is what a fresh session states. */
|
|
93
|
+
function aViewerAtTheStart(made) {
|
|
94
|
+
made.notePriorityMap(PICTURE, [
|
|
95
|
+
{ from: 0, to: 0, priority: 100, withinSeconds: 0 },
|
|
96
|
+
{ from: 1, to: SEGMENTS - 1, priority: 91, withinSeconds: 6 }
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Every segment of the film, written and reported closed — what the store looked
|
|
102
|
+
* like while the film was being watched.
|
|
103
|
+
*/
|
|
104
|
+
function theWholeFilmIsOnDisk(store, dir) {
|
|
105
|
+
for (let index = 0; index < SEGMENTS; index += 1) {
|
|
106
|
+
writeFileSync(path.join(dir, fmp4Format.segmentFileName(index)), Buffer.alloc(16));
|
|
107
|
+
store.markClosed(PICTURE, index);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
test("a film that is entirely made needs no encoder", (t) => {
|
|
112
|
+
const { made, store, dir, root } = orchestratorWithAStore();
|
|
113
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
114
|
+
|
|
115
|
+
theWholeFilmIsOnDisk(store, dir);
|
|
116
|
+
aViewerAtTheStart(made);
|
|
117
|
+
made.reconcile();
|
|
118
|
+
|
|
119
|
+
// The other half of the property, and the reason the failure looked
|
|
120
|
+
// reasonable: when the film really is all there, taking the encoder away IS
|
|
121
|
+
// right, and the viewer is served from the disk.
|
|
122
|
+
assert.equal(made.runsOn(PICTURE).length, 0, "nothing left to make");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("segments the store has lost stop being ready, and an encoder is placed again", (t) => {
|
|
126
|
+
const { made, store, dir, root } = orchestratorWithAStore();
|
|
127
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
128
|
+
|
|
129
|
+
theWholeFilmIsOnDisk(store, dir);
|
|
130
|
+
aViewerAtTheStart(made);
|
|
131
|
+
made.reconcile();
|
|
132
|
+
assert.equal(made.runsOn(PICTURE).length, 0);
|
|
133
|
+
|
|
134
|
+
// THE FIELD FAILURE. The output's directory goes — dropped for room, or by the
|
|
135
|
+
// idle rule, or because a killed process left it and the sweep cleared it. The
|
|
136
|
+
// map used to keep all 482 numbers and the plan went on believing the film was
|
|
137
|
+
// made, for the life of the process.
|
|
138
|
+
store.drop(PICTURE, "the test is taking its files away");
|
|
139
|
+
store.useFormat(PICTURE, fmp4Format);
|
|
140
|
+
store.directoryFor(PICTURE);
|
|
141
|
+
|
|
142
|
+
made.reconcile();
|
|
143
|
+
const runs = made.runsOn(PICTURE);
|
|
144
|
+
assert.equal(runs.length, 1, "the film is unmade again, so somebody makes it");
|
|
145
|
+
assert.equal(runs[0].from, 0, "beginning where the viewer is stopped");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a piece discarded with the run that had it open is not ready either", (t) => {
|
|
149
|
+
const { made, store, dir, root } = orchestratorWithAStore();
|
|
150
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
151
|
+
|
|
152
|
+
theWholeFilmIsOnDisk(store, dir);
|
|
153
|
+
aViewerAtTheStart(made);
|
|
154
|
+
made.reconcile();
|
|
155
|
+
assert.equal(made.runsOn(PICTURE).length, 0);
|
|
156
|
+
|
|
157
|
+
// A run stopped the instant after opening #0 leaves a file of no bytes under a
|
|
158
|
+
// name that reads as a segment; the store throws it away. Field 2026-09-07,
|
|
159
|
+
// 20:13:13 and 20:13:57 — printed twice while the map went on saying 482.
|
|
160
|
+
rmSync(path.join(dir, fmp4Format.segmentFileName(0)), { force: true });
|
|
161
|
+
|
|
162
|
+
made.reconcile();
|
|
163
|
+
assert.equal(made.runsOn(PICTURE).length, 1, "one number missing is one encoder");
|
|
164
|
+
assert.equal(made.runsOn(PICTURE)[0].from, 0);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("nobody making what somebody waits for is said out loud", (t) => {
|
|
168
|
+
const { made, root, lines } = orchestratorWithAStore();
|
|
169
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
170
|
+
|
|
171
|
+
// A HOST THAT CANNOT BUILD AN ENCODER. Whatever the reason — and there are
|
|
172
|
+
// several — the state it leaves is the one that cost two sessions on
|
|
173
|
+
// 2026-09-07: somebody is waiting, nothing is being made, and every line
|
|
174
|
+
// above reads as a healthy proxy. It ran for 41 seconds in the field with no
|
|
175
|
+
// word about it on either side, and ended at the browser's own timeout with a
|
|
176
|
+
// message naming no cause.
|
|
177
|
+
made.makeRun = () => null;
|
|
178
|
+
aViewerAtTheStart(made);
|
|
179
|
+
made.reconcile();
|
|
180
|
+
|
|
181
|
+
assert.equal(made.runsOn(PICTURE).length, 0);
|
|
182
|
+
const said = lines.find((line) => line.includes("NO ENCODER IS MAKING IT"));
|
|
183
|
+
assert.ok(said, "the state has a line of its own");
|
|
184
|
+
assert.ok(said.includes("#0"), "which number is wanted");
|
|
185
|
+
assert.ok(said.includes(PICTURE), "of which output, whole — not cut to sixty characters");
|
|
186
|
+
assert.ok(/files=\d+/.test(said), "and what the disk holds, beside what is proven");
|
|
187
|
+
});
|
|
@@ -1,178 +1,195 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The three states of a segment number, and the two questions that decide
|
|
3
|
-
* where an encoder goes.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import assert from "node:assert/strict";
|
|
8
|
-
import { CoverageMap } from "../services/encode/CoverageMap.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A stand-in for a run.
|
|
12
|
-
*
|
|
13
|
-
* The map files a claim under the run ITSELF: a run has no name, and needs
|
|
14
|
-
* none — what identifies it is that it is itself, and what identifies it in a
|
|
15
|
-
* line is the stretch it was given, which no other live run of one output can
|
|
16
|
-
* hold.
|
|
17
|
-
*
|
|
18
|
-
* @returns {object}
|
|
19
|
-
*/
|
|
20
|
-
function aRun() {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
test("a number nobody has made and nobody is making is free", () => {
|
|
25
|
-
const map = new CoverageMap({ segmentCount: 10 });
|
|
26
|
-
assert.equal(map.stateOf(3), "free");
|
|
27
|
-
assert.equal(map.firstGapFrom(0), 0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("a closed file is ready whoever made it", () => {
|
|
31
|
-
const map = new CoverageMap({ segmentCount: 10 });
|
|
32
|
-
map.markReady(0);
|
|
33
|
-
map.markReady(1);
|
|
34
|
-
assert.equal(map.stateOf(1), "ready");
|
|
35
|
-
assert.equal(map.firstGapFrom(0), 2);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("a run claims a stretch, and the gap search skips it", () => {
|
|
39
|
-
// The claim is an interval and not a head, which is the whole reason two runs
|
|
40
|
-
// can work on one output: the second is sent past what the first will reach.
|
|
41
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
42
|
-
const runA = aRun();
|
|
43
|
-
map.claim(runA, 0, 40);
|
|
44
|
-
assert.equal(map.stateOf(20), "making");
|
|
45
|
-
assert.equal(map.makerOf(20), runA);
|
|
46
|
-
assert.equal(map.firstGapFrom(0), 41);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("a run that ends gives back what it did not finish, and keeps what it did", () => {
|
|
50
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
51
|
-
const runA = aRun();
|
|
52
|
-
map.claim(runA, 0, 40);
|
|
53
|
-
map.markReady(0);
|
|
54
|
-
map.markReady(1);
|
|
55
|
-
map.release(runA);
|
|
56
|
-
assert.equal(map.stateOf(0), "ready", "a closed file survives its maker");
|
|
57
|
-
assert.equal(map.stateOf(2), "free", "the rest of the stretch is free again");
|
|
58
|
-
assert.equal(map.firstGapFrom(0), 2);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("a run with no end claims everything ahead of it", () => {
|
|
62
|
-
// Which is what every run was before ends existed, and is why a second run
|
|
63
|
-
// could never be placed.
|
|
64
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
65
|
-
const runA = aRun();
|
|
66
|
-
map.claim(runA, 10, Number.POSITIVE_INFINITY);
|
|
67
|
-
assert.equal(map.firstGapFrom(10), null);
|
|
68
|
-
assert.equal(map.firstGapFrom(0), 0, "behind it is still free");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("claiming again replaces the earlier claim rather than adding to it", () => {
|
|
72
|
-
// A run moved forward past ready material states its new stretch; if the two
|
|
73
|
-
// accumulated, the ground it has left would stay unavailable for ever.
|
|
74
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
75
|
-
const runA = aRun();
|
|
76
|
-
map.claim(runA, 0, 20);
|
|
77
|
-
map.claim(runA, 50, 70);
|
|
78
|
-
assert.equal(map.stateOf(10), "free");
|
|
79
|
-
assert.equal(map.stateOf(60), "making");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("the covered stretch ahead is measured, which is what prices a move", () => {
|
|
83
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
84
|
-
const runA = aRun();
|
|
85
|
-
const runB = aRun();
|
|
86
|
-
for (let index = 10; index <= 24; index += 1) {
|
|
87
|
-
map.markReady(index);
|
|
88
|
-
}
|
|
89
|
-
map.claim(runB, 25, 30);
|
|
90
|
-
// Ready 10..24 then another run's 25..30, so fifteen plus six.
|
|
91
|
-
assert.equal(map.coveredRunFrom(10, runA), 21);
|
|
92
|
-
assert.equal(map.firstGapFrom(10), 31);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test("a run's own claim is not counted as somebody else's coverage", () => {
|
|
96
|
-
// Otherwise a run would read its own stretch as a reason to move off it.
|
|
97
|
-
const map = new CoverageMap({ segmentCount: 100 });
|
|
98
|
-
const runA = aRun();
|
|
99
|
-
map.claim(runA, 10, 30);
|
|
100
|
-
assert.equal(map.coveredRunFrom(10, runA), 0);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("nothing free ahead answers null rather than a number past the end", () => {
|
|
104
|
-
const map = new CoverageMap({ segmentCount: 5 });
|
|
105
|
-
map.
|
|
106
|
-
assert.equal(map.firstGapFrom(0), null);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("a file that has gone stops being ready", () => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
map
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
map
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
assert.equal(map.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const map = new CoverageMap();
|
|
168
|
-
|
|
169
|
-
assert.equal(map.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file The three states of a segment number, and the two questions that decide
|
|
3
|
+
* where an encoder goes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { CoverageMap } from "../services/encode/CoverageMap.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A stand-in for a run.
|
|
12
|
+
*
|
|
13
|
+
* The map files a claim under the run ITSELF: a run has no name, and needs
|
|
14
|
+
* none — what identifies it is that it is itself, and what identifies it in a
|
|
15
|
+
* line is the stretch it was given, which no other live run of one output can
|
|
16
|
+
* hold.
|
|
17
|
+
*
|
|
18
|
+
* @returns {object}
|
|
19
|
+
*/
|
|
20
|
+
function aRun() {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test("a number nobody has made and nobody is making is free", () => {
|
|
25
|
+
const map = new CoverageMap({ segmentCount: 10 });
|
|
26
|
+
assert.equal(map.stateOf(3), "free");
|
|
27
|
+
assert.equal(map.firstGapFrom(0), 0);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("a closed file is ready whoever made it", () => {
|
|
31
|
+
const map = new CoverageMap({ segmentCount: 10 });
|
|
32
|
+
map.markReady(0);
|
|
33
|
+
map.markReady(1);
|
|
34
|
+
assert.equal(map.stateOf(1), "ready");
|
|
35
|
+
assert.equal(map.firstGapFrom(0), 2);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("a run claims a stretch, and the gap search skips it", () => {
|
|
39
|
+
// The claim is an interval and not a head, which is the whole reason two runs
|
|
40
|
+
// can work on one output: the second is sent past what the first will reach.
|
|
41
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
42
|
+
const runA = aRun();
|
|
43
|
+
map.claim(runA, 0, 40);
|
|
44
|
+
assert.equal(map.stateOf(20), "making");
|
|
45
|
+
assert.equal(map.makerOf(20), runA);
|
|
46
|
+
assert.equal(map.firstGapFrom(0), 41);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("a run that ends gives back what it did not finish, and keeps what it did", () => {
|
|
50
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
51
|
+
const runA = aRun();
|
|
52
|
+
map.claim(runA, 0, 40);
|
|
53
|
+
map.markReady(0);
|
|
54
|
+
map.markReady(1);
|
|
55
|
+
map.release(runA);
|
|
56
|
+
assert.equal(map.stateOf(0), "ready", "a closed file survives its maker");
|
|
57
|
+
assert.equal(map.stateOf(2), "free", "the rest of the stretch is free again");
|
|
58
|
+
assert.equal(map.firstGapFrom(0), 2);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a run with no end claims everything ahead of it", () => {
|
|
62
|
+
// Which is what every run was before ends existed, and is why a second run
|
|
63
|
+
// could never be placed.
|
|
64
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
65
|
+
const runA = aRun();
|
|
66
|
+
map.claim(runA, 10, Number.POSITIVE_INFINITY);
|
|
67
|
+
assert.equal(map.firstGapFrom(10), null);
|
|
68
|
+
assert.equal(map.firstGapFrom(0), 0, "behind it is still free");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("claiming again replaces the earlier claim rather than adding to it", () => {
|
|
72
|
+
// A run moved forward past ready material states its new stretch; if the two
|
|
73
|
+
// accumulated, the ground it has left would stay unavailable for ever.
|
|
74
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
75
|
+
const runA = aRun();
|
|
76
|
+
map.claim(runA, 0, 20);
|
|
77
|
+
map.claim(runA, 50, 70);
|
|
78
|
+
assert.equal(map.stateOf(10), "free");
|
|
79
|
+
assert.equal(map.stateOf(60), "making");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("the covered stretch ahead is measured, which is what prices a move", () => {
|
|
83
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
84
|
+
const runA = aRun();
|
|
85
|
+
const runB = aRun();
|
|
86
|
+
for (let index = 10; index <= 24; index += 1) {
|
|
87
|
+
map.markReady(index);
|
|
88
|
+
}
|
|
89
|
+
map.claim(runB, 25, 30);
|
|
90
|
+
// Ready 10..24 then another run's 25..30, so fifteen plus six.
|
|
91
|
+
assert.equal(map.coveredRunFrom(10, runA), 21);
|
|
92
|
+
assert.equal(map.firstGapFrom(10), 31);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("a run's own claim is not counted as somebody else's coverage", () => {
|
|
96
|
+
// Otherwise a run would read its own stretch as a reason to move off it.
|
|
97
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
98
|
+
const runA = aRun();
|
|
99
|
+
map.claim(runA, 10, 30);
|
|
100
|
+
assert.equal(map.coveredRunFrom(10, runA), 0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("nothing free ahead answers null rather than a number past the end", () => {
|
|
104
|
+
const map = new CoverageMap({ segmentCount: 5 });
|
|
105
|
+
map.setReady([0, 1, 2, 3, 4]);
|
|
106
|
+
assert.equal(map.firstGapFrom(0), null);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("a file that has gone stops being ready", () => {
|
|
110
|
+
// THE CHECK THE FIELD FAILURE OF 2026-09-07 NEEDED. Readiness used to
|
|
111
|
+
// accumulate: a number told once stayed ready for the life of the process
|
|
112
|
+
// however its file ended, so the map claimed a whole film that was not there,
|
|
113
|
+
// the plan scored every arrangement as perfect and took the only encoder away.
|
|
114
|
+
const map = new CoverageMap({ segmentCount: 10 });
|
|
115
|
+
map.setReady([3, 4]);
|
|
116
|
+
assert.equal(map.stateOf(4), "ready");
|
|
117
|
+
map.setReady([3]);
|
|
118
|
+
assert.equal(map.stateOf(4), "free", "the picture is replaced, not added to");
|
|
119
|
+
assert.equal(map.stateOf(3), "ready", "and what is still there stays");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("the whole picture is replaced, so nothing survives that the disk has lost", () => {
|
|
123
|
+
const map = new CoverageMap({ segmentCount: 500 });
|
|
124
|
+
for (let index = 0; index < 500; index += 1) {
|
|
125
|
+
map.markReady(index);
|
|
126
|
+
}
|
|
127
|
+
assert.equal(map.stats().ready, 500);
|
|
128
|
+
map.setReady([]);
|
|
129
|
+
assert.equal(map.stats().ready, 0, "an empty directory is an empty map");
|
|
130
|
+
assert.equal(map.firstGapFrom(0), 0, "and the first gap is the beginning again");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("a run's own claim does not hide the gap it is trying to move into", () => {
|
|
134
|
+
// Found by the plan's own checks: a run that had claimed the rest of the film
|
|
135
|
+
// — which is what every run did before ends existed — could find no gap
|
|
136
|
+
// anywhere, so it was stopped instead of moved.
|
|
137
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
138
|
+
const runA = aRun();
|
|
139
|
+
map.claim(runA, 0, 99);
|
|
140
|
+
map.setReady([10, 11, 12]);
|
|
141
|
+
assert.equal(map.firstGapFrom(10, 90), null, "to anybody else its ground is taken");
|
|
142
|
+
assert.equal(map.firstGapFrom(10, 90, runA), 13, "to itself the ground beyond is a gap");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("the free stretch ahead is measured, which is what gives a run its end", () => {
|
|
146
|
+
// A run handed the whole rest of the film would drive through the stretch
|
|
147
|
+
// another run is making. Handed the free stretch, it stops where the covered
|
|
148
|
+
// material begins.
|
|
149
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
150
|
+
const runB = aRun();
|
|
151
|
+
map.claim(runB, 30, 60);
|
|
152
|
+
assert.equal(map.freeRunFrom(10), 20, "free from 10 up to 29");
|
|
153
|
+
map.markReady(15);
|
|
154
|
+
assert.equal(map.freeRunFrom(10), 5, "a ready segment ends the free stretch too");
|
|
155
|
+
assert.equal(map.freeRunFrom(15), 0, "a number that is not free has no free stretch");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("a run's own claim does not end its own free stretch", () => {
|
|
159
|
+
const map = new CoverageMap({ segmentCount: 100 });
|
|
160
|
+
const runA = aRun();
|
|
161
|
+
map.claim(runA, 10, 40);
|
|
162
|
+
assert.equal(map.freeRunFrom(10, runA), 90, "its own ground is still its to fill");
|
|
163
|
+
assert.equal(map.freeRunFrom(10), 0, "to anybody else it is taken");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("with the length unknown, a gap search needs its own bound", () => {
|
|
167
|
+
const map = new CoverageMap();
|
|
168
|
+
assert.equal(map.firstGapFrom(0), null, "no length and no bound answers nothing");
|
|
169
|
+
assert.equal(map.firstGapFrom(0, 3), 0);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("with the length unknown, the free stretch is answered without walking to it", () => {
|
|
173
|
+
// What this pins: on the addon host, 2026-09-05, a map with no length walked
|
|
174
|
+
// one number at a time to MAX_SAFE_INTEGER, scanning every claim at each step.
|
|
175
|
+
// The main thread spun at 100% from the look-ahead timer and the proxy stopped
|
|
176
|
+
// answering anything, its own log included. The length was missing because the
|
|
177
|
+
// field naming it had moved to the timeline and three readers were left on the
|
|
178
|
+
// old name — but this walk must not be able to do that even when it is.
|
|
179
|
+
//
|
|
180
|
+
// This check cannot FAIL against the old code — a synchronous walk cannot be
|
|
181
|
+
// interrupted by the runner, so it would hang the whole run instead, which is
|
|
182
|
+
// worse than no check. What it pins is the contract that replaced the walk:
|
|
183
|
+
// the answer comes from what the map holds.
|
|
184
|
+
const map = new CoverageMap();
|
|
185
|
+
|
|
186
|
+
assert.equal(map.freeRunFrom(0), Number.POSITIVE_INFINITY, "nothing is covered, so nothing bounds it");
|
|
187
|
+
|
|
188
|
+
const run = aRun();
|
|
189
|
+
map.claim(run, 500, 900);
|
|
190
|
+
assert.equal(map.freeRunFrom(0), 500, "and a claim ahead is where the free stretch ends");
|
|
191
|
+
assert.equal(map.freeRunFrom(0, run), Number.POSITIVE_INFINITY, "its own claim does not bound it");
|
|
192
|
+
|
|
193
|
+
map.markReady(200);
|
|
194
|
+
assert.equal(map.freeRunFrom(0), 200, "so is a segment somebody has already made");
|
|
195
|
+
});
|
|
@@ -15,7 +15,7 @@ import { EncodeRun } from "../services/encode/EncodeRun.js";
|
|
|
15
15
|
import { ENCODE_EXIT } from "../services/encode/encode-exit.js";
|
|
16
16
|
import { SoftwareEncoder } from "../services/encode/SoftwareEncoder.js";
|
|
17
17
|
import { EncodeOrchestrator } from "../services/orchestrators/EncodeOrchestrator.js";
|
|
18
|
-
import {
|
|
18
|
+
import { penaltiesFrom } from "../services/encode/contention.js";
|
|
19
19
|
|
|
20
20
|
// WHAT A SECOND ENCODER COSTS THE FIRST — measured, never a formula.
|
|
21
21
|
//
|
|
@@ -25,7 +25,6 @@ import { contentionPenalty, penaltiesFrom } from "../services/contention.js";
|
|
|
25
25
|
// so nothing here invents a shape: beyond what was measured the reading is held
|
|
26
26
|
// rather than extrapolated.
|
|
27
27
|
const MEASURED_PENALTIES = penaltiesFrom(7.12, [{ others: 1, speed: 4.18 }]);
|
|
28
|
-
const penaltyFor = (others) => contentionPenalty(others, MEASURED_PENALTIES).penalty;
|
|
29
28
|
|
|
30
29
|
// What a start and a stop cost, measured on the same host: a spawn with its
|
|
31
30
|
// input open is 0.12 s there.
|