@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
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
558
|
+
const { made, watches } = orchestrator({ maxRuns: 3 });
|
|
560
559
|
watches("one", { atSeconds: 400 });
|
|
561
560
|
made.reconcile();
|
|
562
561
|
const [run] = made.runsOn(PICTURE);
|
package/test/encode-plan.test.js
CHANGED
|
@@ -12,7 +12,7 @@ import assert from "node:assert/strict";
|
|
|
12
12
|
import { CoverageMap } from "../services/encode/CoverageMap.js";
|
|
13
13
|
import { endOfRun } from "../services/encode/EncodeRun.js";
|
|
14
14
|
import { firstUnmetWant, planEncoders } from "../services/encode/EncodePlan.js";
|
|
15
|
-
import { contentionPenalty, penaltiesFrom } from "../services/contention.js";
|
|
15
|
+
import { contentionPenalty, penaltiesFrom } from "../services/encode/contention.js";
|
|
16
16
|
|
|
17
17
|
// WHAT A SECOND ENCODER COSTS THE FIRST — measured, never a formula.
|
|
18
18
|
//
|
|
@@ -440,10 +440,9 @@ test("a viewer joining behind a running encoder gets their own, not a dragged on
|
|
|
440
440
|
|
|
441
441
|
test("the lowest thing a viewer is waiting for is reported, so a stalled plan is visible", () => {
|
|
442
442
|
const coverage = new CoverageMap({ segmentCount: 100 });
|
|
443
|
-
coverage.
|
|
444
|
-
coverage.markReady(41);
|
|
443
|
+
coverage.setReady([40, 41]);
|
|
445
444
|
assert.equal(firstUnmetWant(coverage, [{ from: 40, to: 70 }]), 42);
|
|
446
|
-
coverage.
|
|
445
|
+
coverage.setReady([40, 41, 42, 43, 44]);
|
|
447
446
|
assert.equal(firstUnmetWant(coverage, [{ from: 40, to: 44 }]), null);
|
|
448
447
|
});
|
|
449
448
|
|
|
@@ -1,154 +1,155 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file How far ahead of the viewer a held segment request may sit.
|
|
3
|
-
*
|
|
4
|
-
* A request is released when the viewer has moved away from it. "Moved away"
|
|
5
|
-
* used to mean more than `MAX_LOOKAHEAD_SEGMENTS` — eight segments, which
|
|
6
|
-
* happened to match a browser holding thirty seconds and would refuse three
|
|
7
|
-
* quarters of the requests of one holding the whole cushion. The width is the
|
|
8
|
-
* encoder's own look-ahead now, which is the same figure the browser sizes its
|
|
9
|
-
* buffer from. Roadmap item 4, step 2.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import test from "node:test";
|
|
13
|
-
import assert from "node:assert/strict";
|
|
14
|
-
import { Timeline } from "../services/output/Timeline.js";
|
|
15
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
16
|
-
import os from "node:os";
|
|
17
|
-
import path from "node:path";
|
|
18
|
-
import { HlsSessionManager } from "../services/hls-session-manager.js";
|
|
19
|
-
import { fmp4Format } from "../services/segment-formats/fmp4.js";
|
|
20
|
-
|
|
21
|
-
const SESSION_ID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
|
22
|
-
const SEGMENT_SECONDS = 4;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @returns {Promise<{ manager: HlsSessionManager, dirPath: string }>}
|
|
26
|
-
*/
|
|
27
|
-
async function managerWithSession() {
|
|
28
|
-
const dirPath = await mkdtemp(path.join(os.tmpdir(), "held-request-"));
|
|
29
|
-
const manager = new HlsSessionManager({
|
|
30
|
-
enabled: true,
|
|
31
|
-
ffmpegBin: "ffmpeg",
|
|
32
|
-
localBindHost: "127.0.0.1",
|
|
33
|
-
localPort: 9090
|
|
34
|
-
});
|
|
35
|
-
manager.sessionsById.set(SESSION_ID, {
|
|
36
|
-
id: SESSION_ID,
|
|
37
|
-
dirPath,
|
|
38
|
-
// Where this file is cut, held by the file. A fixture that stated it
|
|
39
|
-
// on the session was describing what production no longer does.
|
|
40
|
-
timeline: new Timeline({
|
|
41
|
-
boundaries: Array.from({ length: 201 }, (_, index) => index * SEGMENT_SECONDS),
|
|
42
|
-
cutGrid: "uniform"
|
|
43
|
-
}),
|
|
44
|
-
state: "ready",
|
|
45
|
-
segmentFormat: fmp4Format,
|
|
46
|
-
segmentCount: 200,
|
|
47
|
-
useSyntheticPlaylist: true,
|
|
48
|
-
// The viewer is at segment #25.
|
|
49
|
-
furthestViewerSeconds: 100
|
|
50
|
-
});
|
|
51
|
-
return { manager, dirPath };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param {number} index
|
|
56
|
-
* @returns {string}
|
|
57
|
-
*/
|
|
58
|
-
function segment(index) {
|
|
59
|
-
return `segment-${String(index).padStart(5, "0")}.mp4`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
test("the width is the encoder's own look-ahead, in segments", async (t) => {
|
|
63
|
-
const { manager, dirPath } = await managerWithSession();
|
|
64
|
-
t.after(async () => {
|
|
65
|
-
await rm(dirPath, { recursive: true, force: true });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const width = Math.ceil(manager.lookaheadSeconds / manager.segmentDurationSec);
|
|
69
|
-
assert.equal(width, 30, "120 s of look-ahead over 4 s segments");
|
|
70
|
-
assert.equal(manager.requestStillWanted(SESSION_ID, segment(25 + width)), true, "the far edge");
|
|
71
|
-
assert.equal(
|
|
72
|
-
manager.requestStillWanted(SESSION_ID, segment(25 + width + 1)),
|
|
73
|
-
false,
|
|
74
|
-
"past everything the encoder is allowed to have produced"
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("a request the old eight-segment width would have refused is kept", async (t) => {
|
|
79
|
-
const { manager, dirPath } = await managerWithSession();
|
|
80
|
-
t.after(async () => {
|
|
81
|
-
await rm(dirPath, { recursive: true, force: true });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// #34 is nine segments ahead of the viewer — inside a 120 s cushion and
|
|
85
|
-
// outside the eight the width used to be. This is the request a browser
|
|
86
|
-
// holding the whole cushion makes constantly.
|
|
87
|
-
assert.equal(manager.requestStillWanted(SESSION_ID, segment(34)), true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("a segment behind the viewer is still released", async (t) => {
|
|
91
|
-
const { manager, dirPath } = await managerWithSession();
|
|
92
|
-
t.after(async () => {
|
|
93
|
-
await rm(dirPath, { recursive: true, force: true });
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
assert.equal(manager.requestStillWanted(SESSION_ID, segment(24)), false);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test("a seek by one viewer does not release the request held for another", async (t) => {
|
|
100
|
-
const { manager, dirPath } = await managerWithSession();
|
|
101
|
-
t.after(async () => {
|
|
102
|
-
await rm(dirPath, { recursive: true, force: true });
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
assert.equal(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
assert.equal(manager.requestStillWanted(SESSION_ID, segment(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
assert.equal(manager.requestStillWanted(SESSION_ID, segment(
|
|
154
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file How far ahead of the viewer a held segment request may sit.
|
|
3
|
+
*
|
|
4
|
+
* A request is released when the viewer has moved away from it. "Moved away"
|
|
5
|
+
* used to mean more than `MAX_LOOKAHEAD_SEGMENTS` — eight segments, which
|
|
6
|
+
* happened to match a browser holding thirty seconds and would refuse three
|
|
7
|
+
* quarters of the requests of one holding the whole cushion. The width is the
|
|
8
|
+
* encoder's own look-ahead now, which is the same figure the browser sizes its
|
|
9
|
+
* buffer from. Roadmap item 4, step 2.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import { Timeline } from "../services/output/Timeline.js";
|
|
15
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { HlsSessionManager } from "../services/hls-session-manager.js";
|
|
19
|
+
import { fmp4Format } from "../services/segment-formats/fmp4.js";
|
|
20
|
+
|
|
21
|
+
const SESSION_ID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
|
22
|
+
const SEGMENT_SECONDS = 4;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns {Promise<{ manager: HlsSessionManager, dirPath: string }>}
|
|
26
|
+
*/
|
|
27
|
+
async function managerWithSession() {
|
|
28
|
+
const dirPath = await mkdtemp(path.join(os.tmpdir(), "held-request-"));
|
|
29
|
+
const manager = new HlsSessionManager({
|
|
30
|
+
enabled: true,
|
|
31
|
+
ffmpegBin: "ffmpeg",
|
|
32
|
+
localBindHost: "127.0.0.1",
|
|
33
|
+
localPort: 9090
|
|
34
|
+
});
|
|
35
|
+
manager.sessionsById.set(SESSION_ID, {
|
|
36
|
+
id: SESSION_ID,
|
|
37
|
+
dirPath,
|
|
38
|
+
// Where this file is cut, held by the file. A fixture that stated it
|
|
39
|
+
// on the session was describing what production no longer does.
|
|
40
|
+
timeline: new Timeline({
|
|
41
|
+
boundaries: Array.from({ length: 201 }, (_, index) => index * SEGMENT_SECONDS),
|
|
42
|
+
cutGrid: "uniform"
|
|
43
|
+
}),
|
|
44
|
+
state: "ready",
|
|
45
|
+
segmentFormat: fmp4Format,
|
|
46
|
+
segmentCount: 200,
|
|
47
|
+
useSyntheticPlaylist: true,
|
|
48
|
+
// The viewer is at segment #25.
|
|
49
|
+
furthestViewerSeconds: 100
|
|
50
|
+
});
|
|
51
|
+
return { manager, dirPath };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {number} index
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
function segment(index) {
|
|
59
|
+
return `segment-${String(index).padStart(5, "0")}.mp4`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
test("the width is the encoder's own look-ahead, in segments", async (t) => {
|
|
63
|
+
const { manager, dirPath } = await managerWithSession();
|
|
64
|
+
t.after(async () => {
|
|
65
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const width = Math.ceil(manager.lookaheadSeconds / manager.segmentDurationSec);
|
|
69
|
+
assert.equal(width, 30, "120 s of look-ahead over 4 s segments");
|
|
70
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(25 + width)), true, "the far edge");
|
|
71
|
+
assert.equal(
|
|
72
|
+
manager.requestStillWanted(SESSION_ID, segment(25 + width + 1)),
|
|
73
|
+
false,
|
|
74
|
+
"past everything the encoder is allowed to have produced"
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("a request the old eight-segment width would have refused is kept", async (t) => {
|
|
79
|
+
const { manager, dirPath } = await managerWithSession();
|
|
80
|
+
t.after(async () => {
|
|
81
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// #34 is nine segments ahead of the viewer — inside a 120 s cushion and
|
|
85
|
+
// outside the eight the width used to be. This is the request a browser
|
|
86
|
+
// holding the whole cushion makes constantly.
|
|
87
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(34)), true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("a segment behind the viewer is still released", async (t) => {
|
|
91
|
+
const { manager, dirPath } = await managerWithSession();
|
|
92
|
+
t.after(async () => {
|
|
93
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(24)), false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("a seek by one viewer does not release the request held for another", async (t) => {
|
|
100
|
+
const { manager, dirPath } = await managerWithSession();
|
|
101
|
+
t.after(async () => {
|
|
102
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
103
|
+
});
|
|
104
|
+
// Both are watching the same copied picture, so both are this one session.
|
|
105
|
+
// One is at segment #25, the other far ahead at #150 — inside the fixture's
|
|
106
|
+
// own 200-segment timeline, since a position past the end of the grid is
|
|
107
|
+
// clamped to it and would prove nothing about the width.
|
|
108
|
+
manager.requestSeek(SESSION_ID, 100, "behind");
|
|
109
|
+
manager.requestSeek(SESSION_ID, 600, "ahead");
|
|
110
|
+
|
|
111
|
+
// A SEEK DOES ONE THING: it puts the viewer where they now are. It used to
|
|
112
|
+
// write that position into five places, this session's shared field among
|
|
113
|
+
// them, and every held request was then judged against whoever moved last —
|
|
114
|
+
// which is exactly what this test exists to refuse. Each viewer's own
|
|
115
|
+
// position is what decides, and the two below are asked separately.
|
|
116
|
+
assert.equal(manager.viewers.get("behind").positionSeconds(), 100);
|
|
117
|
+
assert.equal(manager.viewers.get("ahead").positionSeconds(), 600);
|
|
118
|
+
|
|
119
|
+
assert.equal(
|
|
120
|
+
manager.requestStillWanted(SESSION_ID, segment(26), "behind"),
|
|
121
|
+
true,
|
|
122
|
+
"the segment the viewer behind is waiting for is still theirs to wait for"
|
|
123
|
+
);
|
|
124
|
+
assert.equal(
|
|
125
|
+
manager.requestStillWanted(SESSION_ID, segment(26), "ahead"),
|
|
126
|
+
false,
|
|
127
|
+
"and for the one in front it is a place they have left"
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a viewer's own head moves with their seek", async (t) => {
|
|
132
|
+
const { manager, dirPath } = await managerWithSession();
|
|
133
|
+
t.after(async () => {
|
|
134
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Their last request was at #25; they jump to 600 s, which is #150. The
|
|
138
|
+
// segment at the target must be wanted — refusing it there is the freeze of
|
|
139
|
+
// 2026-08-18.
|
|
140
|
+
manager.requestSeek(SESSION_ID, 600, "viewer");
|
|
141
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(150), "viewer"), true);
|
|
142
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(25), "viewer"), false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("a viewer nobody can name is judged against the one shared position", async (t) => {
|
|
146
|
+
const { manager, dirPath } = await managerWithSession();
|
|
147
|
+
t.after(async () => {
|
|
148
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// A plain HTTP transport builds its own URLs and carries no id. The old
|
|
152
|
+
// behaviour is what remains, which for a single viewer is the same thing.
|
|
153
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(26), ""), true);
|
|
154
|
+
assert.equal(manager.requestStillWanted(SESSION_ID, segment(24), ""), false);
|
|
155
|
+
});
|