@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
|
@@ -1,128 +1,136 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file A real `EncodeRun` over a process that is not real.
|
|
3
|
-
*
|
|
4
|
-
* Tests used to set a session's process fields by hand — `session.ffmpeg`,
|
|
5
|
-
* `session.runState`, `session.encodeStartIndex` — which is how a test can pass
|
|
6
|
-
* over code that no longer works: the fields were the thing under test as much
|
|
7
|
-
* as the behaviour was. A run is an object now, so a test builds the object the
|
|
8
|
-
* product builds and injects only the one thing a test may not have, which is a
|
|
9
|
-
* child process.
|
|
10
|
-
*
|
|
11
|
-
* The pid is deliberately absent unless a test asks for one. `pause` and
|
|
12
|
-
* `resume` send signals by pid, and a made-up number is somebody else's process
|
|
13
|
-
* on the machine running the tests.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { EncodeRun } from "../../services/encode/EncodeRun.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A child process that records what was done to it.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} [options]
|
|
22
|
-
* @param {number | null} [options.pid] - Only where a test genuinely exercises
|
|
23
|
-
* suspend or resume, and then it must be this process's own.
|
|
24
|
-
* @returns {object}
|
|
25
|
-
*/
|
|
26
|
-
export function fakeProcess({ pid = null, exitsWhenKilled = true } = {}) {
|
|
27
|
-
/** @type {Map<string, (...args: unknown[]) => void>} */
|
|
28
|
-
const listeners = new Map();
|
|
29
|
-
return {
|
|
30
|
-
pid,
|
|
31
|
-
killed: false,
|
|
32
|
-
exitCode: null,
|
|
33
|
-
signalCode: null,
|
|
34
|
-
/** Every signal it was sent, in order. */
|
|
35
|
-
signals: [],
|
|
36
|
-
stdout: { on() {} },
|
|
37
|
-
stderr: { on() {} },
|
|
38
|
-
on(event, handler) {
|
|
39
|
-
const kept = listeners.get(event) ?? [];
|
|
40
|
-
kept.push(handler);
|
|
41
|
-
listeners.set(event, kept);
|
|
42
|
-
return this;
|
|
43
|
-
},
|
|
44
|
-
once(event, handler) {
|
|
45
|
-
return this.on(event, handler);
|
|
46
|
-
},
|
|
47
|
-
kill(signal = "SIGTERM") {
|
|
48
|
-
this.signals.push(signal);
|
|
49
|
-
this.killed = true;
|
|
50
|
-
// A real process answers a signal by exiting, and it does so on a later
|
|
51
|
-
// turn. A fake that never exits makes every disposal wait out the grace
|
|
52
|
-
// period, which is two seconds a test spends proving nothing.
|
|
53
|
-
if (exitsWhenKilled && this.exitCode === null && this.signalCode === null) {
|
|
54
|
-
queueMicrotask(() => this.exit(null, signal));
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
/**
|
|
59
|
-
* Report an exit, as the real thing would.
|
|
60
|
-
*
|
|
61
|
-
* @param {number | null} code
|
|
62
|
-
* @param {string | null} [signal]
|
|
63
|
-
*/
|
|
64
|
-
exit(code, signal = null) {
|
|
65
|
-
this.exitCode = code;
|
|
66
|
-
this.signalCode = signal;
|
|
67
|
-
for (const handler of listeners.get("exit") ?? []) {
|
|
68
|
-
handler(code, signal);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** A logger that says nothing, for tests that are not about the log. */
|
|
75
|
-
export const silentLogger = { info() {}, warn() {}, error() {} };
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Add a run to a session, started, over a fake process.
|
|
79
|
-
*
|
|
80
|
-
* A session holds a SET of runs — as many as the machine affords — so a test
|
|
81
|
-
* that wants two heads on one output calls this twice.
|
|
82
|
-
*
|
|
83
|
-
* @param {object} session - The session under test.
|
|
84
|
-
* @param {object} [options]
|
|
85
|
-
* @param {number} [options.from] - First segment number it is making.
|
|
86
|
-
* @param {number} [options.to] - Last, inclusive; below `from` means no end.
|
|
87
|
-
* @param {object} [options.process] - The process it should own.
|
|
88
|
-
* @param {boolean} [options.producing] - Whether it has already made its first
|
|
89
|
-
* segment, which is what moves it out of starting.
|
|
90
|
-
* @param {number | null} [options.lastSegmentIndex] - The film's last number,
|
|
91
|
-
* for telling a finished file from an input that dried up.
|
|
92
|
-
* @param {boolean} [options.usesExplicitCuts]
|
|
93
|
-
* @returns {import("../../services/encode/EncodeRun.js").EncodeRun}
|
|
94
|
-
*/
|
|
95
|
-
export function startRunOn(session, options = {}) {
|
|
96
|
-
const {
|
|
97
|
-
from = 0,
|
|
98
|
-
to = -1,
|
|
99
|
-
process: child = fakeProcess(),
|
|
100
|
-
producing = true,
|
|
101
|
-
lastSegmentIndex = null,
|
|
102
|
-
usesExplicitCuts = false
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file A real `EncodeRun` over a process that is not real.
|
|
3
|
+
*
|
|
4
|
+
* Tests used to set a session's process fields by hand — `session.ffmpeg`,
|
|
5
|
+
* `session.runState`, `session.encodeStartIndex` — which is how a test can pass
|
|
6
|
+
* over code that no longer works: the fields were the thing under test as much
|
|
7
|
+
* as the behaviour was. A run is an object now, so a test builds the object the
|
|
8
|
+
* product builds and injects only the one thing a test may not have, which is a
|
|
9
|
+
* child process.
|
|
10
|
+
*
|
|
11
|
+
* The pid is deliberately absent unless a test asks for one. `pause` and
|
|
12
|
+
* `resume` send signals by pid, and a made-up number is somebody else's process
|
|
13
|
+
* on the machine running the tests.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { EncodeRun } from "../../services/encode/EncodeRun.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A child process that records what was done to it.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} [options]
|
|
22
|
+
* @param {number | null} [options.pid] - Only where a test genuinely exercises
|
|
23
|
+
* suspend or resume, and then it must be this process's own.
|
|
24
|
+
* @returns {object}
|
|
25
|
+
*/
|
|
26
|
+
export function fakeProcess({ pid = null, exitsWhenKilled = true } = {}) {
|
|
27
|
+
/** @type {Map<string, (...args: unknown[]) => void>} */
|
|
28
|
+
const listeners = new Map();
|
|
29
|
+
return {
|
|
30
|
+
pid,
|
|
31
|
+
killed: false,
|
|
32
|
+
exitCode: null,
|
|
33
|
+
signalCode: null,
|
|
34
|
+
/** Every signal it was sent, in order. */
|
|
35
|
+
signals: [],
|
|
36
|
+
stdout: { on() {} },
|
|
37
|
+
stderr: { on() {} },
|
|
38
|
+
on(event, handler) {
|
|
39
|
+
const kept = listeners.get(event) ?? [];
|
|
40
|
+
kept.push(handler);
|
|
41
|
+
listeners.set(event, kept);
|
|
42
|
+
return this;
|
|
43
|
+
},
|
|
44
|
+
once(event, handler) {
|
|
45
|
+
return this.on(event, handler);
|
|
46
|
+
},
|
|
47
|
+
kill(signal = "SIGTERM") {
|
|
48
|
+
this.signals.push(signal);
|
|
49
|
+
this.killed = true;
|
|
50
|
+
// A real process answers a signal by exiting, and it does so on a later
|
|
51
|
+
// turn. A fake that never exits makes every disposal wait out the grace
|
|
52
|
+
// period, which is two seconds a test spends proving nothing.
|
|
53
|
+
if (exitsWhenKilled && this.exitCode === null && this.signalCode === null) {
|
|
54
|
+
queueMicrotask(() => this.exit(null, signal));
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Report an exit, as the real thing would.
|
|
60
|
+
*
|
|
61
|
+
* @param {number | null} code
|
|
62
|
+
* @param {string | null} [signal]
|
|
63
|
+
*/
|
|
64
|
+
exit(code, signal = null) {
|
|
65
|
+
this.exitCode = code;
|
|
66
|
+
this.signalCode = signal;
|
|
67
|
+
for (const handler of listeners.get("exit") ?? []) {
|
|
68
|
+
handler(code, signal);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A logger that says nothing, for tests that are not about the log. */
|
|
75
|
+
export const silentLogger = { info() {}, warn() {}, error() {} };
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Add a run to a session, started, over a fake process.
|
|
79
|
+
*
|
|
80
|
+
* A session holds a SET of runs — as many as the machine affords — so a test
|
|
81
|
+
* that wants two heads on one output calls this twice.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} session - The session under test.
|
|
84
|
+
* @param {object} [options]
|
|
85
|
+
* @param {number} [options.from] - First segment number it is making.
|
|
86
|
+
* @param {number} [options.to] - Last, inclusive; below `from` means no end.
|
|
87
|
+
* @param {object} [options.process] - The process it should own.
|
|
88
|
+
* @param {boolean} [options.producing] - Whether it has already made its first
|
|
89
|
+
* segment, which is what moves it out of starting.
|
|
90
|
+
* @param {number | null} [options.lastSegmentIndex] - The film's last number,
|
|
91
|
+
* for telling a finished file from an input that dried up.
|
|
92
|
+
* @param {boolean} [options.usesExplicitCuts]
|
|
93
|
+
* @returns {import("../../services/encode/EncodeRun.js").EncodeRun}
|
|
94
|
+
*/
|
|
95
|
+
export function startRunOn(session, options = {}) {
|
|
96
|
+
const {
|
|
97
|
+
from = 0,
|
|
98
|
+
to = -1,
|
|
99
|
+
process: child = fakeProcess(),
|
|
100
|
+
producing = true,
|
|
101
|
+
lastSegmentIndex = null,
|
|
102
|
+
usesExplicitCuts = false,
|
|
103
|
+
// WHAT FFMPEG HAS REPORTED IT IS RUNNING AT. It says so on its progress
|
|
104
|
+
// channel from the first seconds, before any piece closes — so a run can be
|
|
105
|
+
// starting and already have a speed, and every real one does. Left at zero,
|
|
106
|
+
// the plan has no speed to compute an arrival from, every arrangement of
|
|
107
|
+
// encoders is equally hopeless, they all tie, and the encoder is taken away
|
|
108
|
+
// for changing nothing.
|
|
109
|
+
speedX = 0
|
|
110
|
+
} = options;
|
|
111
|
+
const run = new EncodeRun({
|
|
112
|
+
address: session.outputKey ?? session.id ?? "output",
|
|
113
|
+
encoder: { name: "libx264", kind: "software" },
|
|
114
|
+
from,
|
|
115
|
+
to,
|
|
116
|
+
buildArgs: () => [],
|
|
117
|
+
spawn: () => child,
|
|
118
|
+
logger: silentLogger,
|
|
119
|
+
lastSegmentIndex: () => lastSegmentIndex,
|
|
120
|
+
usesExplicitCuts
|
|
121
|
+
});
|
|
122
|
+
run.start("a test asked for it");
|
|
123
|
+
run.noteSpeed(speedX);
|
|
124
|
+
if (producing) {
|
|
125
|
+
// What moves a run out of starting is its first segment, in the product as
|
|
126
|
+
// here — so a run that is producing has made one, and its head stands one
|
|
127
|
+
// past where it began. `from` is still where it started, which is what a
|
|
128
|
+
// test asserting a run's position asks for.
|
|
129
|
+
run.noteProduced(from);
|
|
130
|
+
}
|
|
131
|
+
if (!(session.runs instanceof Set)) {
|
|
132
|
+
session.runs = new Set();
|
|
133
|
+
}
|
|
134
|
+
session.runs.add(run);
|
|
135
|
+
return run;
|
|
136
|
+
}
|
|
@@ -49,7 +49,7 @@ function sessionOn({ id, dirPath, encodeStartIndex = 0, runEndIndex = -1, speed
|
|
|
49
49
|
cutGrid: "uniform"
|
|
50
50
|
}),
|
|
51
51
|
state: "ready",
|
|
52
|
-
file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" }),
|
|
52
|
+
file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" }).learn({ durationSeconds: 4000 }),
|
|
53
53
|
// An ordinary session reads its own file, and its sound is inside it. The
|
|
54
54
|
// three differ only for a soundtrack shipped as a file of its own.
|
|
55
55
|
get inputFile() { return this.file; },
|
|
@@ -99,10 +99,14 @@ test("what a viewer waits for reaches the plan without their name", (t) => {
|
|
|
99
99
|
|
|
100
100
|
manager.planEncodersNow();
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
// THE MAP IS BANDS NOW, not one window per viewer: what a viewer is stopped
|
|
103
|
+
// on, then what is in front of them band by band, then the rest of the track.
|
|
104
|
+
// The check is the same question asked of that shape — where the most urgent
|
|
105
|
+
// band begins, and that there is film in front of it.
|
|
106
|
+
const wanted = manager.encodeOrchestrator.demand.mapOn(KEY);
|
|
107
|
+
const first = [...wanted].sort((left, right) => right.priority - left.priority)[0];
|
|
108
|
+
assert.equal(first.from, 5, "where they are");
|
|
109
|
+
assert.ok(wanted.some((zone) => zone.to > 5), "and the cushion in front of them");
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
test("a viewer nothing has been heard from at all stops being waited for", (t) => {
|
|
@@ -120,7 +124,7 @@ test("a viewer nothing has been heard from at all stops being waited for", (t) =
|
|
|
120
124
|
|
|
121
125
|
manager.planEncodersNow();
|
|
122
126
|
|
|
123
|
-
assert.equal(manager.encodeOrchestrator.demand.
|
|
127
|
+
assert.equal(manager.encodeOrchestrator.demand.mapOn(KEY).length, 0);
|
|
124
128
|
});
|
|
125
129
|
|
|
126
130
|
test("a viewer who has arrived and asked for nothing is waited for", (t) => {
|
|
@@ -139,9 +143,10 @@ test("a viewer who has arrived and asked for nothing is waited for", (t) => {
|
|
|
139
143
|
|
|
140
144
|
manager.planEncodersNow();
|
|
141
145
|
|
|
142
|
-
const wanted = manager.encodeOrchestrator.demand.
|
|
143
|
-
assert.
|
|
144
|
-
|
|
146
|
+
const wanted = manager.encodeOrchestrator.demand.mapOn(KEY);
|
|
147
|
+
assert.ok(wanted.length > 0, "an output with a viewer on it is wanted");
|
|
148
|
+
const first = [...wanted].sort((left, right) => right.priority - left.priority)[0];
|
|
149
|
+
assert.equal(first.from, 0, "and the beginning is where an unplaced viewer is");
|
|
145
150
|
});
|
|
146
151
|
|
|
147
152
|
test("how many encoders the machine affords is measured, not chosen", (t) => {
|
|
@@ -155,7 +160,7 @@ test("how many encoders the machine affords is measured, not chosen", (t) => {
|
|
|
155
160
|
|
|
156
161
|
// Fast, but what a second job costs on THIS machine has not been measured,
|
|
157
162
|
// and an unmeasured penalty of 1 is not a statement that it is free.
|
|
158
|
-
cold.
|
|
163
|
+
cold.lastAloneSpeed = 7.12;
|
|
159
164
|
assert.equal(manager.maxRunsForOutput(KEY), 1, "no measurement, no second encoder");
|
|
160
165
|
|
|
161
166
|
// Measured on the addon host 2026-09-03: at 854x480 one run made 7.12x and
|
|
@@ -166,7 +171,7 @@ test("how many encoders the machine affords is measured, not chosen", (t) => {
|
|
|
166
171
|
|
|
167
172
|
// The same host at 1920x1080: one made 1.96x, two made 0.99x and 0.98x.
|
|
168
173
|
manager.contentionPenalties = new Map([[1, 1.98]]);
|
|
169
|
-
cold.
|
|
174
|
+
cold.lastAloneSpeed = 1.96;
|
|
170
175
|
assert.equal(manager.maxRunsForOutput(KEY), 1, "the machine is full at one");
|
|
171
176
|
});
|
|
172
177
|
|