@torrent-tv/proxy 2.80.5 → 2.80.7

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 (34) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/package.json +1 -1
  3. package/routes/api/delivery-sink/get.js +8 -4
  4. package/server.js +415 -403
  5. package/services/data-channel-handler.js +87 -25
  6. package/services/delivery-probe.js +38 -5
  7. package/services/encode/CoverageMap.js +77 -4
  8. package/services/encode/EncodePlan.js +1025 -358
  9. package/services/encode/EncodeRun.js +19 -1
  10. package/services/encode/SegmentDemand.js +0 -0
  11. package/services/encode/SegmentStore.js +53 -1
  12. package/services/encode/open-piece.js +22 -1
  13. package/services/encode/run-command.js +12 -2
  14. package/services/hls-session-manager.js +38 -158
  15. package/services/hwaccel.js +182 -54
  16. package/services/orchestrators/EncodeOrchestrator.js +118 -89
  17. package/services/output/LiveOutputs.js +233 -213
  18. package/services/output/Timeline.js +333 -256
  19. package/services/piece-store/shared-piece-store.js +13 -9
  20. package/services/priority/PriorityMap.js +262 -108
  21. package/services/priority/PriorityOrchestrator.js +31 -6
  22. package/services/quality/EncodeCost.js +555 -500
  23. package/services/torrent-pool.js +9 -4
  24. package/test/encode-orchestrator.test.js +195 -65
  25. package/test/encode-plan-viewers.test.js +719 -0
  26. package/test/encode-plan.test.js +174 -81
  27. package/test/open-piece.test.js +40 -0
  28. package/test/output-speed.test.js +86 -0
  29. package/test/piece-store-eviction.test.js +26 -0
  30. package/test/priority-map-download.test.js +25 -7
  31. package/test/priority-map.test.js +134 -83
  32. package/test/seek-landing.test.js +109 -76
  33. package/test/segment-demand.test.js +54 -56
  34. package/test/wedge-certainty.test.js +3 -3
@@ -1,5 +1,15 @@
1
1
  /**
2
- * @file What viewers want of an output, stated once each and read as a union.
2
+ * @file What is wanted of one output, in its own segment numbers.
3
+ *
4
+ * The class held a window per viewer per band and merged them itself. That was
5
+ * the priority layer's work done a second time in the wrong place, and it
6
+ * carried the viewer's name as the key of a claim — against the rule that the
7
+ * encoding and the viewer are not connected at all. The behaviours those checks
8
+ * pinned (a viewer's own bands, two viewers as a union) are the priority map's
9
+ * and are checked there.
10
+ *
11
+ * What is left is a holder: one map per output, replaced whole, and an empty one
12
+ * meaning nobody is coming.
3
13
  */
4
14
 
5
15
  import test from "node:test";
@@ -7,76 +17,64 @@ import assert from "node:assert/strict";
7
17
  import { SegmentDemand } from "../services/encode/SegmentDemand.js";
8
18
 
9
19
  const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
10
- const SOUND = "torrent:abc:fmt=fmp4:grid=kf@0:audio-only:a=0/1/copy";
20
+ const SOUND = "torrent:abc:fmt=fmp4:grid=kf@0:audio-only:a=0/0/aac";
11
21
 
12
- test("a viewer restating a window replaces it rather than adding to it", () => {
13
- // A player restates its window every few seconds. Accumulated, the demand
14
- // would grow to the whole film within a minute.
22
+ test("an output nothing has been said about wants nothing", () => {
15
23
  const demand = new SegmentDemand();
16
- demand.state({ claimant: "one", address: PICTURE, from: 0, to: 10, statedAt: 1 });
17
- demand.state({ claimant: "one", address: PICTURE, from: 30, to: 40, statedAt: 2 });
18
- assert.deepEqual(demand.spanOn(PICTURE), { from: 30, to: 40 });
19
- assert.equal(demand.stats().windows, 1);
24
+ assert.deepEqual(demand.mapOn(PICTURE), []);
25
+ assert.deepEqual(demand.addresses(), []);
20
26
  });
21
27
 
22
- test("one viewer states a window per output, and both stand", () => {
28
+ test("a map replaces whatever was wanted before, rather than adding to it", () => {
29
+ // The map is a statement of what is wanted NOW, built fresh each time from
30
+ // where the viewers are. Accumulating them would keep serving people who have
31
+ // moved or gone.
23
32
  const demand = new SegmentDemand();
24
- demand.state({ claimant: "one", address: PICTURE, from: 0, to: 10, statedAt: 1 });
25
- demand.state({ claimant: "one", address: SOUND, from: 0, to: 10, statedAt: 1 });
26
- assert.equal(demand.stats().windows, 2);
27
- assert.deepEqual(demand.addresses().sort(), [SOUND, PICTURE].sort());
28
- });
29
-
30
- test("two viewers of one output are a union, not a sum", () => {
31
- // Two viewers seconds apart want mostly the same segments; counted twice, a
32
- // stretch would look twice as wanted as it is.
33
- const demand = new SegmentDemand();
34
- demand.state({ claimant: "one", address: PICTURE, from: 10, to: 14, statedAt: 1 });
35
- demand.state({ claimant: "two", address: PICTURE, from: 12, to: 16, statedAt: 1 });
36
- assert.deepEqual(demand.wantedOn(PICTURE), [10, 11, 12, 13, 14, 15, 16]);
33
+ demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
34
+ demand.state(PICTURE, [{ from: 500, to: 530, priority: 32, withinSeconds: 0 }]);
35
+ assert.deepEqual(demand.mapOn(PICTURE), [{ from: 500, to: 530, priority: 32, withinSeconds: 0 }]);
37
36
  });
38
37
 
39
- test("two viewers far apart make a span that covers the ground between them", () => {
40
- // Not so it is all made so that a search for a gap considers all of it.
38
+ test("an empty map is a statement, and it is kept as one", () => {
39
+ // It says nobody is coming anywhere in this output, which is what stops the
40
+ // encoders on it. Dropped instead of stored, the output would look like one
41
+ // nothing had ever been said about, and the last map with people in it would
42
+ // stand as current.
41
43
  const demand = new SegmentDemand();
42
- demand.state({ claimant: "one", address: PICTURE, from: 0, to: 5, statedAt: 1 });
43
- demand.state({ claimant: "two", address: PICTURE, from: 900, to: 905, statedAt: 1 });
44
- assert.deepEqual(demand.spanOn(PICTURE), { from: 0, to: 905 });
44
+ demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
45
+ demand.state(PICTURE, []);
46
+ assert.deepEqual(demand.mapOn(PICTURE), []);
47
+ assert.deepEqual(demand.addresses(), [PICTURE], "the output is still one that has been spoken about");
45
48
  });
46
49
 
47
- test("a viewer who leaves takes every window they stated", () => {
50
+ test("each output holds its own map", () => {
51
+ // Two outputs of one film are cut independently — 454 pieces against 401 on
52
+ // the field file — so the same second is a different number in each, and one
53
+ // map cannot serve both.
48
54
  const demand = new SegmentDemand();
49
- demand.state({ claimant: "one", address: PICTURE, from: 0, to: 5, statedAt: 1 });
50
- demand.state({ claimant: "one", address: SOUND, from: 0, to: 5, statedAt: 1 });
51
- demand.state({ claimant: "two", address: PICTURE, from: 0, to: 5, statedAt: 1 });
52
- assert.equal(demand.forget("one"), 2);
53
- assert.equal(demand.stats().claimants, 1);
54
- assert.equal(demand.addresses().length, 1);
55
- });
56
-
57
- test("expiry is carried out here and decided elsewhere", () => {
58
- // The register has no clock on purpose: the rule that says how stale is too
59
- // stale lives with whoever measures it, and this stays exercisable with
60
- // numbers alone.
61
- const demand = new SegmentDemand();
62
- demand.state({ claimant: "one", address: PICTURE, from: 0, to: 5, statedAt: 1000 });
63
- demand.state({ claimant: "two", address: PICTURE, from: 0, to: 5, statedAt: 9000 });
64
- const dropped = demand.forgetStatedBefore(5000);
65
- assert.equal(dropped.length, 1);
66
- assert.equal(dropped[0].claimant, "one");
67
- assert.equal(demand.stats().windows, 1);
55
+ demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
56
+ demand.state(SOUND, [{ from: 88, to: 115, priority: 32, withinSeconds: 0 }]);
57
+ assert.equal(demand.mapOn(PICTURE)[0].from, 100);
58
+ assert.equal(demand.mapOn(SOUND)[0].from, 88);
59
+ assert.deepEqual(demand.addresses().sort(), [SOUND, PICTURE].sort());
68
60
  });
69
61
 
70
- test("a window that is not a window is refused rather than stored", () => {
62
+ test("an output can be forgotten entirely", () => {
71
63
  const demand = new SegmentDemand();
72
- assert.equal(demand.state({ claimant: "one", address: PICTURE, from: 5, to: 1, statedAt: 1 }), null);
73
- assert.equal(demand.state({ claimant: "", address: PICTURE, from: 0, to: 1, statedAt: 1 }), null);
74
- assert.equal(demand.state({ claimant: "one", address: "", from: 0, to: 1, statedAt: 1 }), null);
75
- assert.equal(demand.stats().windows, 0);
64
+ demand.state(PICTURE, [{ from: 100, to: 130, priority: 32, withinSeconds: 0 }]);
65
+ demand.forget(PICTURE);
66
+ assert.deepEqual(demand.addresses(), []);
76
67
  });
77
68
 
78
- test("nothing wanted on an output answers null rather than an empty span", () => {
69
+ test("nothing about a viewer can be stated, because nothing about one is held", () => {
70
+ // The check that the rule holds by construction: there is no name to pass and
71
+ // no way to ask about one.
79
72
  const demand = new SegmentDemand();
80
- assert.equal(demand.spanOn(PICTURE), null);
81
- assert.deepEqual(demand.wantedOn(PICTURE), []);
73
+ assert.equal(typeof (/** @type {any} */ (demand).want), "undefined");
74
+ assert.equal(typeof (/** @type {any} */ (demand).windowsOn), "undefined");
75
+ assert.equal(
76
+ demand.state.length,
77
+ 2,
78
+ "an address and a map, and nothing else"
79
+ );
82
80
  });
@@ -65,14 +65,14 @@ test("a tiny queue still waits for one round of probes", () => {
65
65
  assert.equal(verdict.needMs, PROBE_INTERVAL_MS);
66
66
  });
67
67
 
68
- test("nothing queued is not a wedge however long the counter has been still", () => {
68
+ test("nothing queued is still a wedge when the counter has been flat long enough — the channel queue was 0 on the real wedge while usrsctp held 399 MB", () => {
69
69
  const verdict = wedgeIsCertain({
70
70
  queuedBytes: 0,
71
71
  bytesPerSecond: 16 * MEGABYTE,
72
72
  flatForMs: 600_000
73
73
  });
74
- assert.equal(verdict.certain, false);
75
- assert.equal(verdict.needMs, null);
74
+ assert.equal(verdict.certain, true);
75
+ assert.equal(verdict.needMs, PROBE_INTERVAL_MS);
76
76
  });
77
77
 
78
78
  test("with no rate measured the answer is that nothing can be said", () => {