@torrent-tv/proxy 2.16.0 → 2.18.0

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.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file A rung is judged against the machine it will actually have.
3
+ *
4
+ * The field case of 2026-08-15, in arithmetic: a copy of the picture took about
5
+ * 0.125 s of work per second of video (7.9-8.0x measured), a 240p rung needed
6
+ * about 1.05, and the two together are more than the one second per second the
7
+ * machine has. The budget priced the copy at nothing, offered the rung, and the
8
+ * viewer watched it fail.
9
+ */
10
+
11
+ import assert from "node:assert/strict";
12
+ import test from "node:test";
13
+
14
+ import { canSustainOutput } from "../services/hwaccel.js";
15
+
16
+ // A host that encodes 640x360 at 24 fps about eleven times over, and decodes
17
+ // 1080p24 at 2.6x — the addon host's own figures.
18
+ const BENCHMARK = [
19
+ { preset: "fast", pixelsPerSec: 17.0e6 },
20
+ { preset: "ultrafast", pixelsPerSec: 67.5e6 }
21
+ ];
22
+ const DECODE_MODEL = { pixelTerm: 0.007742, bitrateTerm: 0, constantTerm: 0 };
23
+ const SOURCE = { megapixelsPerSecond: (1920 * 1080 * 24) / 1e6, megabitsPerSecond: 8 };
24
+ const RUNG_240P = 426 * 240 * 24;
25
+
26
+ test("a rung is judged on the machine it will have, not on an empty one", () => {
27
+ const alone = canSustainOutput({
28
+ benchmark: BENCHMARK,
29
+ decodeModel: DECODE_MODEL,
30
+ source: SOURCE,
31
+ outputPixelsPerSec: RUNG_240P
32
+ });
33
+ const beside = canSustainOutput({
34
+ benchmark: BENCHMARK,
35
+ decodeModel: DECODE_MODEL,
36
+ source: SOURCE,
37
+ outputPixelsPerSec: RUNG_240P,
38
+ // The picture is being copied beside it, at the cost the field measured.
39
+ concurrentCostSec: 0.125
40
+ });
41
+ assert.ok(alone.speed !== null && beside.speed !== null);
42
+ assert.ok(beside.speed < alone.speed, "sharing the machine cannot make a rung faster");
43
+ });
44
+
45
+ test("nothing else running leaves the answer exactly as it was", () => {
46
+ const withZero = canSustainOutput({
47
+ benchmark: BENCHMARK,
48
+ decodeModel: DECODE_MODEL,
49
+ source: SOURCE,
50
+ outputPixelsPerSec: RUNG_240P,
51
+ concurrentCostSec: 0
52
+ });
53
+ const without = canSustainOutput({
54
+ benchmark: BENCHMARK,
55
+ decodeModel: DECODE_MODEL,
56
+ source: SOURCE,
57
+ outputPixelsPerSec: RUNG_240P
58
+ });
59
+ assert.equal(withZero.speed, without.speed);
60
+ });
61
+
62
+ test("a host with nothing measured still refuses nothing", () => {
63
+ const answer = canSustainOutput({
64
+ benchmark: [],
65
+ outputPixelsPerSec: RUNG_240P,
66
+ concurrentCostSec: 0.125
67
+ });
68
+ assert.equal(answer.sustainable, true);
69
+ assert.equal(answer.speed, null);
70
+ });
71
+
72
+ test("a cost heavy enough to fill the machine puts a rung below realtime", () => {
73
+ const answer = canSustainOutput({
74
+ benchmark: BENCHMARK,
75
+ decodeModel: DECODE_MODEL,
76
+ source: SOURCE,
77
+ outputPixelsPerSec: RUNG_240P,
78
+ concurrentCostSec: 0.9
79
+ });
80
+ assert.ok(answer.speed !== null && answer.speed < 1, "0.9 of the machine spent elsewhere leaves less than realtime");
81
+ assert.equal(answer.sustainable, false);
82
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file The slope that turns ffmpeg's progress reports into a preset's speed.
3
+ *
4
+ * Written against the faults a review found in it on 2026-08-15, each of which
5
+ * would have opened the quality ladder rather than closing it: a window of no
6
+ * width at all, and a position ffmpeg reports as the smallest signed 64-bit
7
+ * integer when it has none yet.
8
+ */
9
+
10
+ import assert from "node:assert/strict";
11
+ import test from "node:test";
12
+
13
+ import { slopeOf } from "../services/hwaccel.js";
14
+
15
+ const at = (wallSec, outSec) => ({ wallSec, outSec });
16
+
17
+ test("a steady run measures its own speed", () => {
18
+ assert.equal(slopeOf([at(1, 10), at(2, 14)]), 4);
19
+ });
20
+
21
+ test("a window of no width is refused, however tempting the numbers", () => {
22
+ // Two reports a millisecond apart: 0.042 s of video over 0.001 s of clock is
23
+ // 42x, on a host that may be doing 3x.
24
+ assert.equal(slopeOf([at(1.0, 10), at(1.001, 10.042)], 0.2), null);
25
+ });
26
+
27
+ test("a run that produced nothing between two reports says nothing", () => {
28
+ assert.equal(slopeOf([at(1, 10), at(3, 10)]), null);
29
+ });
30
+
31
+ test("one report is not a measurement", () => {
32
+ assert.equal(slopeOf([at(1, 10)]), null);
33
+ assert.equal(slopeOf([]), null);
34
+ });
35
+
36
+ test("an impossible speed is a fault, not a fast machine", () => {
37
+ // Nothing encodes 640x360 five thousand times realtime; a reading that says
38
+ // so is a measurement fault, and letting it through raises the bar every
39
+ // ladder decision is taken from.
40
+ assert.equal(slopeOf([at(1, 0), at(2, 5000)]), null);
41
+ });
42
+
43
+ test("the narrowest allowed window is honoured", () => {
44
+ assert.equal(slopeOf([at(1.0, 10), at(1.3, 11)], 0.5), null);
45
+ assert.ok(slopeOf([at(1.0, 10), at(1.6, 12)], 0.5) > 0);
46
+ });