@torrent-tv/proxy 2.80.9 → 2.80.11

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +1685 -1666
  2. package/package.json +1 -1
  3. package/services/data-channel-handler.js +2 -4
  4. package/services/encode/EncodePlan.js +0 -3
  5. package/services/encode/EncodeRun.js +14 -0
  6. package/services/encode/run-command.js +729 -707
  7. package/services/hls-session-manager.js +10168 -10494
  8. package/services/hwaccel.js +2 -2
  9. package/services/orchestrators/EncodeOrchestrator.js +4 -4
  10. package/services/output/LiveOutputs.js +49 -0
  11. package/services/priority/PriorityOrchestrator.js +278 -174
  12. package/services/quality/EncodeCost.js +555 -555
  13. package/test/auto-quality-step.test.js +514 -507
  14. package/test/contention.test.js +1 -1
  15. package/test/decode-cost-fit.test.js +57 -0
  16. package/test/decode-cost.test.js +13 -36
  17. package/test/encode-orchestrator.test.js +1 -2
  18. package/test/encode-plan-viewers.test.js +18 -19
  19. package/test/encode-plan.test.js +539 -539
  20. package/test/held-request-width.test.js +155 -154
  21. package/test/helpers/encode-run.js +136 -128
  22. package/test/keyframe-table-budget.test.js +7 -1
  23. package/test/one-authority.test.js +220 -105
  24. package/test/orchestrator-wired.test.js +16 -11
  25. package/test/piece-store-slow-disk.test.js +32 -2
  26. package/test/priority-map-per-output.test.js +211 -0
  27. package/test/produced-copy-choice.test.js +358 -327
  28. package/test/quality-variants.test.js +1222 -1209
  29. package/test/segment-serve-wiring.test.js +76 -20
  30. package/test/stale-request-after-seek.test.js +51 -77
  31. package/test/tracks-begin-together.test.js +195 -153
  32. package/test/tunnel-renewal.test.js +34 -5
  33. package/test/two-viewers-one-picture.test.js +374 -347
  34. package/test/viewer-outputs.test.js +18 -14
  35. package/test/behind-head-repair.test.js +0 -261
  36. package/test/decode-measurement.test.js +0 -83
  37. /package/services/{contention.js → encode/contention.js} +0 -0
@@ -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;
@@ -143,3 +143,60 @@ test("what a model prices a film at", () => {
143
143
  // Which is a decode speed of 1/cost — the figure the quality offer rests on.
144
144
  assert.ok(1 / cost > 1 && 1 / cost < 10, `decodes at ${(1 / cost).toFixed(2)}x`);
145
145
  });
146
+
147
+ /**
148
+ * THE ORDERINGS, STATED WHERE THEY ARE DETERMINISTIC.
149
+ *
150
+ * What the quality offer needs of this model is not precision but ORDER: a
151
+ * bigger, richer, dearer-to-decode source must never be priced cheaper, because
152
+ * the model is asked about rungs nobody has decoded. That is a property of the
153
+ * fit, and it is a property of the fit whatever machine runs the test.
154
+ *
155
+ * These three used to be asserted over LIVE readings — decode two clips through
156
+ * real ffmpeg and require the smaller to come back faster. That measures the
157
+ * scheduler, not the code: four failures in one day, and the worst of them read
158
+ * 480p at 8.4x against 1080p at 20.8x, an inversion of two and a half times
159
+ * with nothing wrong. The readings themselves are unavailable to a test at all,
160
+ * since a clip that "said nothing" under load makes the whole benchmark answer
161
+ * with nothing.
162
+ */
163
+
164
+ test("a bigger picture is priced dearer than a smaller one of the same bitrate", () => {
165
+ const model = fitDecodeCost(wellConditionedSet({ pixel: 0.0055, bitrate: 0.0099, constant: 0.057 }));
166
+ const big = decodeCostOf(model, { megapixelsPerSecond: (1920 * 1080 * FPS) / 1e6, megabitsPerSecond: 4 });
167
+ const small = decodeCostOf(model, { megapixelsPerSecond: (854 * 480 * FPS) / 1e6, megabitsPerSecond: 4 });
168
+
169
+ assert.ok(big > small, `1080p at ${big.toFixed(4)} s/s against 480p at ${small.toFixed(4)}`);
170
+ });
171
+
172
+ test("a thicker stream is priced dearer than a thin one of the same size", () => {
173
+ const model = fitDecodeCost(wellConditionedSet({ pixel: 0.0055, bitrate: 0.0099, constant: 0.057 }));
174
+ const pixels = (854 * 480 * FPS) / 1e6;
175
+ const thick = decodeCostOf(model, { megapixelsPerSecond: pixels, megabitsPerSecond: 9.5 });
176
+ const thin = decodeCostOf(model, { megapixelsPerSecond: pixels, megabitsPerSecond: 1.1 });
177
+
178
+ assert.ok(thick > thin, `9.5 Mbit/s at ${thick.toFixed(4)} s/s against 1.1 at ${thin.toFixed(4)}`);
179
+ });
180
+
181
+ test("a family measured to be dearer prices its own sources dearer", () => {
182
+ // Why the model is fitted per codec family at all: HEVC costs more than H.264
183
+ // for the same picture on the same machine, so a source that has to be
184
+ // re-encoded — which is usually one the browser could not decode — must be
185
+ // priced by its own family and not by H.264's.
186
+ const cheap = { pixel: 0.0055, bitrate: 0.0099, constant: 0.057 };
187
+ const dear = { pixel: 0.011, bitrate: 0.0198, constant: 0.114 };
188
+ const model = {
189
+ ...fitDecodeCost(wellConditionedSet(cheap)),
190
+ families: {
191
+ h264: fitDecodeCost(wellConditionedSet(cheap)),
192
+ hevc: fitDecodeCost(wellConditionedSet(dear))
193
+ }
194
+ };
195
+ const source = { megapixelsPerSecond: (854 * 480 * FPS) / 1e6, megabitsPerSecond: 1.1 };
196
+
197
+ assert.ok(
198
+ decodeCostOf(model, { ...source, codec: "hevc" }) >
199
+ decodeCostOf(model, { ...source, codec: "h264" }),
200
+ "the family chooses the terms, and the dearer family answers dearer"
201
+ );
202
+ });
@@ -6,10 +6,19 @@
6
6
  * claiming the host cleared the bar 2.5 times over — the error on that rung was
7
7
  * 209 %. The decode term brings a controlled measurement to within 5 %.
8
8
  *
9
- * The first test runs the real benchmark against the shipped clips with the
10
- * real ffmpeg, because a fit that only ever runs against invented numbers can
11
- * be wrong in every way that matters (2.9.124: a module tested only through its
12
- * own exports missed the caller that never called it).
9
+ * WHAT IS ASSERTED HERE IS ARITHMETIC, over constants that were measured once
10
+ * on the addon host and written down. The live benchmark used to run here too —
11
+ * on the reasoning that a fit which only ever meets invented numbers can be
12
+ * wrong in every way that matters and it could not be asserted about: a clip
13
+ * that "said nothing" under load makes the whole benchmark answer with nothing,
14
+ * so the very first line of that test failed by luck. The orderings it was for
15
+ * are held over the fit itself, deterministically, in `decode-cost-fit.test.js`.
16
+ *
17
+ * What no test covers as a result is the live path — lifting a clip out of its
18
+ * container, feeding it through the pipe, reading the slope. That is integration
19
+ * over real ffmpeg, and it belongs to a stand run before a release rather than
20
+ * to a check that measures whatever else the machine was doing (roadmap item
21
+ * 52).
13
22
  */
14
23
 
15
24
  import test from "node:test";
@@ -23,7 +32,6 @@ import { Output } from "../services/output/Output.js";
23
32
  import os from "node:os";
24
33
  import path from "node:path";
25
34
  import {
26
- benchmarkDecodeCost,
27
35
  canSustainOutput,
28
36
  decodeSpeedFor,
29
37
  predictedRealtimeSpeed,
@@ -45,37 +53,6 @@ const ADDON_HOST_MODEL = { pixelTerm: 0.005555, bitrateTerm: 0.00990, constantTe
45
53
  // The film measured that day: 1920x1080 at 24 fps, about 8 Mbit/s.
46
54
  const MEASURED_FILM = { megapixelsPerSecond: (1920 * 1080 * 24) / 1e6, megabitsPerSecond: 8 };
47
55
 
48
- test("the fit comes out of the real clips, and predicts one of them back", async () => {
49
- const model = await benchmarkDecodeCost({ ffmpegBin });
50
-
51
- assert.ok(model, "the clips ship with the package and this host has ffmpeg");
52
- assert.ok(model.pixelTerm > 0, "more pixels cannot decode faster");
53
- assert.ok(Number.isFinite(model.bitrateTerm) && Number.isFinite(model.constantTerm));
54
-
55
- // What the model must get right is how cost SCALES from one source to
56
- // another — that is the whole of its job, since it is asked about rungs
57
- // nobody has decoded. So: a bigger, richer source is never cheaper.
58
- //
59
- // Deliberately not a numeric bound. This suite runs its files in parallel and
60
- // the benchmark is a live measurement, so the fit it produces depends on what
61
- // else the machine was doing: on this desktop the same clips have solved to
62
- // pixels+bitrate+constant, to pixels alone, and — under load — to a
63
- // constant-dominated shape whose 720p/1080p ratio was 1.32 rather than the
64
- // ~2.4 of a quiet run. That instability is real and is recorded against
65
- // roadmap item 1; pinning a number here would only pin how busy the machine
66
- // happened to be. What the FIGURES are worth is checked where it is quiet:
67
- // against the addon host's recorded constants below, and against the real
68
- // film in the field.
69
- const clip720 = { megapixelsPerSecond: (1280 * 720 * 24) / 1e6, megabitsPerSecond: 2.248 };
70
- const clip1080 = { megapixelsPerSecond: (1920 * 1080 * 24) / 1e6, megabitsPerSecond: 11.375 };
71
- const ratio = decodeSpeedFor(model, clip720) / decodeSpeedFor(model, clip1080);
72
-
73
- assert.ok(
74
- ratio >= 1,
75
- `720p at a fifth of the bitrate cannot decode slower than 1080p; the fit says ${ratio.toFixed(2)}x`
76
- );
77
- });
78
-
79
56
  test("decode cost prices the film it was checked against", () => {
80
57
  const speed = decodeSpeedFor(ADDON_HOST_MODEL, MEASURED_FILM);
81
58
 
@@ -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 { contentionPenalty, penaltiesFrom } from "../services/contention.js";
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.
@@ -31,7 +31,7 @@ import { EncodeRun } from "../services/encode/EncodeRun.js";
31
31
  import { SoftwareEncoder } from "../services/encode/SoftwareEncoder.js";
32
32
  import { EncodeOrchestrator } from "../services/orchestrators/EncodeOrchestrator.js";
33
33
  import { mapForViewer, mergeMaps, runsOf } from "../services/priority/PriorityMap.js";
34
- import { contentionPenalty, penaltiesFrom } from "../services/contention.js";
34
+ import { penaltiesFrom } from "../services/encode/contention.js";
35
35
 
36
36
  // WHAT A SECOND ENCODER COSTS THE FIRST — measured, never a formula.
37
37
  //
@@ -41,7 +41,6 @@ import { contentionPenalty, penaltiesFrom } from "../services/contention.js";
41
41
  // so nothing here invents a shape: beyond what was measured the reading is held
42
42
  // rather than extrapolated.
43
43
  const MEASURED_PENALTIES = penaltiesFrom(7.12, [{ others: 1, speed: 4.18 }]);
44
- const penaltyFor = (others) => contentionPenalty(others, MEASURED_PENALTIES).penalty;
45
44
 
46
45
  // What a start and a stop cost, measured on the same host: a spawn with its
47
46
  // input open is 0.12 s there.
@@ -195,7 +194,7 @@ function assertNoOverlap(made) {
195
194
  // ---------------------------------------------------------------- one viewer
196
195
 
197
196
  test("one viewer playing: one encoder, exactly where they are", () => {
198
- const { made, watches, leaves } = orchestrator();
197
+ const { made, watches } = orchestrator();
199
198
  watches("one", { atSeconds: 400 });
200
199
  made.reconcile();
201
200
  assert.deepEqual(placements(made), [100], "at their own position, 400s / 4s");
@@ -206,7 +205,7 @@ test("one viewer playing: the encoder keeping up buys no second one", () => {
206
205
  // The peak moves forward on its own as they watch, and an encoder that stays
207
206
  // in front of it is never late. This is the case that must NOT spend a
208
207
  // process, and the one the old head-as-a-barrier rule got wrong.
209
- const { made, watches, leaves } = orchestrator();
208
+ const { made, watches } = orchestrator();
210
209
  watches("one", { atSeconds: 400 });
211
210
  made.reconcile();
212
211
  const [run] = made.runsOn(PICTURE);
@@ -223,7 +222,7 @@ test("one viewer playing: the encoder keeping up buys no second one", () => {
223
222
  });
224
223
 
225
224
  test("one viewer seeking far ahead: an encoder is placed there", () => {
226
- const { made, watches, leaves } = orchestrator();
225
+ const { made, watches } = orchestrator();
227
226
  watches("one", { atSeconds: 400 });
228
227
  made.reconcile();
229
228
  made.runsOn(PICTURE)[0].noteSpeed(6);
@@ -241,7 +240,7 @@ test("one viewer paused: nothing is late, so no encoder is added", () => {
241
240
  // A paused viewer states the whole film at one undifferentiated rank and no
242
241
  // time by which any of it must exist. The encoder already working goes on
243
242
  // encoding the track; nothing justifies a second process.
244
- const { made, watches, leaves } = orchestrator();
243
+ const { made, watches } = orchestrator();
245
244
  watches("one", { atSeconds: 400 });
246
245
  made.reconcile();
247
246
  made.runsOn(PICTURE)[0].noteSpeed(1);
@@ -280,7 +279,7 @@ test("one viewer paused states no deadline anywhere", () => {
280
279
  test("two viewers close together share one encoder", () => {
281
280
  // Film both of them want is made once. This is what merging the map is for,
282
281
  // and it must survive the deadline being carried alongside the rank.
283
- const { made, watches, leaves } = orchestrator();
282
+ const { made, watches } = orchestrator();
284
283
  watches("one", { atSeconds: 400 });
285
284
  watches("two", { atSeconds: 408 });
286
285
  made.reconcile();
@@ -293,7 +292,7 @@ test("two viewers close together share one encoder", () => {
293
292
  });
294
293
 
295
294
  test("two viewers far apart get an encoder each", () => {
296
- const { made, watches, leaves } = orchestrator();
295
+ const { made, watches } = orchestrator();
297
296
  watches("one", { atSeconds: 400 });
298
297
  made.reconcile();
299
298
  made.runsOn(PICTURE)[0].noteSpeed(6);
@@ -308,7 +307,7 @@ test("two viewers far apart get an encoder each", () => {
308
307
  });
309
308
 
310
309
  test("two viewers: one seeking does not take the other's encoder", () => {
311
- const { made, watches, leaves } = orchestrator();
310
+ const { made, watches } = orchestrator();
312
311
  watches("one", { atSeconds: 400 });
313
312
  made.reconcile();
314
313
  // A speed has to be measured before a second encoder can be justified: how
@@ -338,7 +337,7 @@ test("two viewers: one seeking does not take the other's encoder", () => {
338
337
  });
339
338
 
340
339
  test("two viewers: one pausing leaves the other served", () => {
341
- const { made, watches, leaves } = orchestrator();
340
+ const { made, watches } = orchestrator();
342
341
  watches("one", { atSeconds: 400 });
343
342
  watches("two", { atSeconds: 3000 });
344
343
  made.reconcile();
@@ -374,7 +373,7 @@ test("two viewers: the one who leaves takes nothing from the one who stays", ()
374
373
  // ------------------------------------------------------------- three viewers
375
374
 
376
375
  test("three viewers far apart get an encoder each when the machine affords it", () => {
377
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
376
+ const { made, watches } = orchestrator({ maxRuns: 3 });
378
377
  watches("one", { atSeconds: 400 });
379
378
  watches("two", { atSeconds: 2000 });
380
379
  watches("three", { atSeconds: 3600 });
@@ -397,7 +396,7 @@ test("three viewers, a machine that affords two: the budget binds, not the map",
397
396
  // machine can hold. Which two are served follows from the order the work is
398
397
  // taken in; what must not happen is a third process on a host that cannot
399
398
  // hold it, or two processes writing one number.
400
- const { made, watches, leaves } = orchestrator({ maxRuns: 2 });
399
+ const { made, watches } = orchestrator({ maxRuns: 2 });
401
400
  watches("one", { atSeconds: 400 });
402
401
  watches("two", { atSeconds: 2000 });
403
402
  watches("three", { atSeconds: 3600 });
@@ -413,7 +412,7 @@ test("three viewers, a machine that affords two: the budget binds, not the map",
413
412
  });
414
413
 
415
414
  test("three viewers: one seeks onto another, and the two of them share", () => {
416
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
415
+ const { made, watches } = orchestrator({ maxRuns: 3 });
417
416
  watches("one", { atSeconds: 400 });
418
417
  made.reconcile();
419
418
  made.runsOn(PICTURE)[0].noteSpeed(6);
@@ -436,7 +435,7 @@ test("three viewers: one seeks onto another, and the two of them share", () => {
436
435
  });
437
436
 
438
437
  test("three viewers: all paused, and no encoder is added for any of them", () => {
439
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
438
+ const { made, watches } = orchestrator({ maxRuns: 3 });
440
439
  watches("one", { atSeconds: 400 });
441
440
  made.reconcile();
442
441
  made.runsOn(PICTURE)[0].noteSpeed(1);
@@ -457,7 +456,7 @@ test("three viewers: all paused, and no encoder is added for any of them", () =>
457
456
  test("the plan is a function of the state: the same state twice gives the same answer", () => {
458
457
  // What stops a moving map from becoming a thrash: the decision is arithmetic
459
458
  // over the state, so a pass that finds nothing changed changes nothing.
460
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
459
+ const { made, watches } = orchestrator({ maxRuns: 3 });
461
460
  watches("one", { atSeconds: 400 });
462
461
  watches("two", { atSeconds: 2000 });
463
462
  made.reconcile();
@@ -481,7 +480,7 @@ test("exactly realtime arrives exactly on time, and no second encoder is bought"
481
480
  // something quite different — `speed / (1 - speed)` divides by zero here and
482
481
  // claims the encoder stays ahead FOR EVER, which is the same answer arrived
483
482
  // at by nonsense.
484
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
483
+ const { made, watches } = orchestrator({ maxRuns: 3 });
485
484
  watches("one", { atSeconds: 400 });
486
485
  made.reconcile();
487
486
  made.runsOn(PICTURE)[0].noteSpeed(1);
@@ -525,7 +524,7 @@ test("two viewers arriving together on a cold output get one encoder, then are m
525
524
  // would take to reach the second viewer is not a known quantity. Buying a
526
525
  // process on that is buying it on no evidence, which is refused; one is placed
527
526
  // and the speed it reports is what justifies the next.
528
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
527
+ const { made, watches } = orchestrator({ maxRuns: 3 });
529
528
  watches("one", { atSeconds: 400 });
530
529
  watches("two", { atSeconds: 3000 });
531
530
  made.reconcile();
@@ -540,7 +539,7 @@ test("two viewers arriving together on a cold output get one encoder, then are m
540
539
  });
541
540
 
542
541
  test("an encoder comfortably faster than realtime is left to do the whole stretch", () => {
543
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
542
+ const { made, watches } = orchestrator({ maxRuns: 3 });
544
543
  watches("one", { atSeconds: 400 });
545
544
  made.reconcile();
546
545
  made.runsOn(PICTURE)[0].noteSpeed(6);
@@ -556,7 +555,7 @@ test("a swarm that feeds one encoder moves it to whoever is late, rather than se
556
555
  // the viewer left — so it is moved to the soonest number that IS due. Without
557
556
  // this the viewer who seeked was served by nobody at all: the run kept its
558
557
  // road because nothing covered what lay in front of IT.
559
- const { made, watches, leaves } = orchestrator({ maxRuns: 3 });
558
+ const { made, watches } = orchestrator({ maxRuns: 3 });
560
559
  watches("one", { atSeconds: 400 });
561
560
  made.reconcile();
562
561
  const [run] = made.runsOn(PICTURE);