@torrent-tv/proxy 2.89.6 → 2.89.8
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/AGENTS.md +32 -12
- package/CHANGELOG.md +2340 -2330
- package/assets/calibration/audio/NOTICE.md +19 -19
- package/assets/calibration/audio/manifest.json +98 -98
- package/biome.json +412 -412
- package/docs/browser-proxy-contract.md +155 -155
- package/docs/container-architecture.md +273 -273
- package/docs/encode-run-state.md +1 -1
- package/docs/playback-start-forecast.md +113 -98
- package/package.json +51 -50
- package/routes/api/sources/files/get.js +106 -106
- package/scripts/build-audio-samples.mjs +31 -31
- package/services/encode/EncodeRun.js +67 -15
- package/services/encode/EncodeRuns.js +19 -7
- package/services/encode/OutputOpening.js +784 -784
- package/services/encode/audio-calibration.js +67 -67
- package/services/encode/audio-work-rate.js +15 -15
- package/services/encode/encode-exit.js +2 -0
- package/services/encode/hwaccel.js +1894 -1894
- package/services/encode/output/index.js +24 -24
- package/services/encode/piece-completeness.js +60 -2
- package/services/encode/run-command.js +757 -755
- package/services/encode/segment-formats/index.js +1 -0
- package/services/encode/segment-formats/mp4-boxes.js +8 -1
- package/services/media/ContainerOrchestrator.js +202 -202
- package/services/media/KeyframeTables.js +356 -356
- package/services/media/SubtitleCues.js +592 -592
- package/services/media/audio-inventory.js +299 -299
- package/services/media/container/AviContainer.js +268 -268
- package/services/media/container/Container.js +632 -632
- package/services/media/container/ContainerFactory.js +38 -38
- package/services/media/container/MatroskaContainer.js +1031 -1031
- package/services/media/container/Mp4Container.js +1354 -1354
- package/services/media/container/SubtitleFileContainer.js +339 -339
- package/services/media/container/ebml-stream.js +174 -174
- package/services/media/container/matroska-clusters.js +1165 -1165
- package/services/media/container/unavailable.js +77 -77
- package/services/media/tracks/ContainerTrack.js +84 -84
- package/services/media/tracks/TextSubtitleTrack.js +295 -295
- package/services/storage/piece-store/shared-piece-store.js +1937 -1937
- package/services/storage/segment-store/SegmentStore.js +1294 -1294
- package/services/torrent/Contents.js +382 -382
- package/services/torrent/episode-naming.js +182 -182
- package/services/torrent/torrent-pool.js +2688 -2688
- package/services/torrent/worker/client.js +836 -836
- package/services/torrent/worker/held-bytes.js +231 -231
- package/services/torrent/worker/worker.js +1137 -1137
- package/services/transport/data-channel-handler.js +1373 -1373
- package/services/viewer/PriorityMap.js +421 -421
- package/test/audio-calibration.test.js +23 -23
- package/test/auto-quality-step.test.js +762 -762
- package/test/coalesce.test.js +39 -39
- package/test/coverage-follows-the-disk.test.js +5 -0
- package/test/decode-cost.test.js +475 -475
- package/test/encode-run.test.js +58 -0
- package/test/episode-naming.test.js +131 -131
- package/test/failed-encoder-still-serves-what-exists.test.js +1 -1
- package/test/fixtures/audio-frame-boundary.json +1 -1
- package/test/fixtures/refused-audio-20261002.json +10 -0
- package/test/fmp4-presentation-clock.test.js +4 -2
- package/test/format-keyed-outputs.test.js +78 -78
- package/test/health-metrics.test.js +11 -13
- package/test/held-read-ownership.test.js +77 -77
- package/test/helpers/encode-run.js +14 -6
- package/test/helpers/held-file.js +77 -77
- package/test/helpers/manager.js +62 -62
- package/test/helpers/matroska-file.js +296 -296
- package/test/keyframe-table-budget.test.js +123 -123
- package/test/matroska-cluster-discovery.test.js +323 -323
- package/test/one-output-one-session.test.js +273 -273
- package/test/output-speed.test.js +6 -1
- package/test/piece-completeness.test.js +37 -1
- package/test/quality-variants.test.js +1274 -1270
- package/test/rate-control-in-the-output.test.js +4 -3
- package/test/reads-not-yet-arrived.test.js +218 -218
- package/test/seek-frees-the-viewers-requests.test.js +1 -1
- package/test/segment-closed-on-both-branches.test.js +114 -114
- package/test/segment-judged-by-its-own-header.test.js +222 -222
- package/test/segment-serve-wiring.test.js +481 -481
- package/test/serving-existing-output.test.js +111 -111
- package/test/source-files-route.test.js +113 -113
- package/test/subtitle-cue-walk.test.js +385 -385
- package/test/subtitle-metadata.test.js +15 -15
- package/test/subtitle-plan-waits.test.js +125 -125
- package/test/subtitle-track-numbering.test.js +391 -391
- package/test/two-viewers-one-picture.test.js +508 -508
- package/test/viewer-requests-admission.test.js +92 -92
- package/test/viewer-starts-on-map.test.js +27 -27
- package/test/viewer-states.test.js +5 -2
- package/test/viewing-generations.test.js +390 -390
- package/test/whole-file-held-read.test.js +30 -30
- package/utils/coalesce.js +41 -41
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file A piece is closed by one of two writers, and both must say so.
|
|
3
|
-
*
|
|
4
|
-
* The `segment` muxer writes under a working name and reports the closure on a
|
|
5
|
-
* channel of its own, which reaches `SegmentStore.publish`. The `hls` muxer
|
|
6
|
-
* writes through a temporary name of its own (`+temp_file`) and reports
|
|
7
|
-
* nothing: the file simply appears under the name it is served as. That branch
|
|
8
|
-
* is taken by every re-encoded output cut on the even grid — an ordinary
|
|
9
|
-
* quality step — and for it a wait could only end on its deadline, so a segment
|
|
10
|
-
* lying finished on disk was answered 503 after the whole hold.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import test from "node:test";
|
|
14
|
-
import assert from "node:assert/strict";
|
|
15
|
-
import { mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
-
import os from "node:os";
|
|
17
|
-
import path from "node:path";
|
|
18
|
-
import { SegmentStore } from "../services/storage/segment-store/SegmentStore.js";
|
|
19
|
-
import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
|
|
20
|
-
|
|
21
|
-
const KEY = "torrent:abc:fmt=fmp4:grid=uniform@0:video-only:v=libx264/854x480";
|
|
22
|
-
|
|
23
|
-
/** A deadline is the backstop of these waits, never what they measure. */
|
|
24
|
-
const BACKSTOP_MS = 10_000;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @returns {{ store: SegmentStore, root: string }}
|
|
28
|
-
*/
|
|
29
|
-
function storeInATempRoot() {
|
|
30
|
-
const root = mkdtempSync(path.join(os.tmpdir(), "segment-closed-"));
|
|
31
|
-
const store = new SegmentStore({ root, logger: { info: () => {}, warn: () => {} } });
|
|
32
|
-
store.useFormat(KEY, fmp4Format);
|
|
33
|
-
return { store, root };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
test("a piece that simply appears ends the wait that began before it", async (t) => {
|
|
37
|
-
const { store, root } = storeInATempRoot();
|
|
38
|
-
t.after(() => {
|
|
39
|
-
store.dropAll("the test is over");
|
|
40
|
-
rmSync(root, { recursive: true, force: true });
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const dir = store.directoryFor(KEY);
|
|
44
|
-
// The wait begins on a segment nobody has written yet — the cold case, and
|
|
45
|
-
// the only one the deadline used to decide.
|
|
46
|
-
const waited = store.waitFor(KEY, 7, BACKSTOP_MS);
|
|
47
|
-
|
|
48
|
-
// What the `hls` muxer does: a temporary name of its own, renamed into place
|
|
49
|
-
// when the piece is whole. Nothing is told; the directory simply moves.
|
|
50
|
-
const temp = path.join(dir, "segment-00007.mp4.tmp");
|
|
51
|
-
writeFileSync(temp, Buffer.alloc(64));
|
|
52
|
-
renameSync(temp, path.join(dir, fmp4Format.segmentFileName(7)));
|
|
53
|
-
|
|
54
|
-
assert.equal(await waited, true, "the piece was on disk and the wait did not end");
|
|
55
|
-
assert.ok(store.pathOf(KEY, 7), "and the store must be able to hand it over");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("clearing up after a run is not its pieces arriving", async (t) => {
|
|
59
|
-
const { store, root } = storeInATempRoot();
|
|
60
|
-
t.after(() => {
|
|
61
|
-
store.dropAll("the test is over");
|
|
62
|
-
rmSync(root, { recursive: true, force: true });
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const dir = store.directoryFor(KEY);
|
|
66
|
-
const unfinished = path.join(dir, fmp4Format.makingFileNameTemplate("3").replace("%05d", "00009"));
|
|
67
|
-
writeFileSync(unfinished, Buffer.alloc(64));
|
|
68
|
-
|
|
69
|
-
let ended = false;
|
|
70
|
-
// 200 ms is a grace before asserting that something did NOT happen, which can
|
|
71
|
-
// only ever pass too easily — never a measurement.
|
|
72
|
-
const waited = store.waitFor(KEY, 9, 200).then((value) => {
|
|
73
|
-
ended = value;
|
|
74
|
-
return value;
|
|
75
|
-
});
|
|
76
|
-
rmSync(unfinished, { force: true });
|
|
77
|
-
|
|
78
|
-
assert.equal(await waited, false, "a directory that moved because a file went holds nothing new");
|
|
79
|
-
assert.equal(ended, false);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("the writer that does report a closure is unaffected", async (t) => {
|
|
83
|
-
const { store, root } = storeInATempRoot();
|
|
84
|
-
t.after(() => {
|
|
85
|
-
store.dropAll("the test is over");
|
|
86
|
-
rmSync(root, { recursive: true, force: true });
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const dir = store.directoryFor(KEY);
|
|
90
|
-
const making = fmp4Format.makingFileNameTemplate("4").replace("%05d", "00004");
|
|
91
|
-
writeFileSync(path.join(dir, making), Buffer.alloc(64));
|
|
92
|
-
|
|
93
|
-
const waited = store.waitFor(KEY, 4, BACKSTOP_MS);
|
|
94
|
-
assert.equal(store.publish(KEY, making, fmp4Format), fmp4Format.segmentFileName(4));
|
|
95
|
-
assert.equal(await waited, true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("a directory removed from outside and made again is watched again", async (t) => {
|
|
99
|
-
const { store, root } = storeInATempRoot();
|
|
100
|
-
t.after(() => {
|
|
101
|
-
store.dropAll("the test is over");
|
|
102
|
-
rmSync(root, { recursive: true, force: true });
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Removed by something other than the store, so its watch was not stopped
|
|
106
|
-
// first. The watch held on that path watches a directory that is gone.
|
|
107
|
-
rmSync(store.directoryFor(KEY), { recursive: true, force: true });
|
|
108
|
-
const dir = store.directoryFor(KEY);
|
|
109
|
-
const waited = store.waitFor(KEY, 3, BACKSTOP_MS);
|
|
110
|
-
|
|
111
|
-
writeFileSync(path.join(dir, fmp4Format.segmentFileName(3)), Buffer.alloc(64));
|
|
112
|
-
|
|
113
|
-
assert.equal(await waited, true, "the piece arrived in the new directory and the wait did not end");
|
|
114
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file A piece is closed by one of two writers, and both must say so.
|
|
3
|
+
*
|
|
4
|
+
* The `segment` muxer writes under a working name and reports the closure on a
|
|
5
|
+
* channel of its own, which reaches `SegmentStore.publish`. The `hls` muxer
|
|
6
|
+
* writes through a temporary name of its own (`+temp_file`) and reports
|
|
7
|
+
* nothing: the file simply appears under the name it is served as. That branch
|
|
8
|
+
* is taken by every re-encoded output cut on the even grid — an ordinary
|
|
9
|
+
* quality step — and for it a wait could only end on its deadline, so a segment
|
|
10
|
+
* lying finished on disk was answered 503 after the whole hold.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import test from "node:test";
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { SegmentStore } from "../services/storage/segment-store/SegmentStore.js";
|
|
19
|
+
import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
|
|
20
|
+
|
|
21
|
+
const KEY = "torrent:abc:fmt=fmp4:grid=uniform@0:video-only:v=libx264/854x480";
|
|
22
|
+
|
|
23
|
+
/** A deadline is the backstop of these waits, never what they measure. */
|
|
24
|
+
const BACKSTOP_MS = 10_000;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns {{ store: SegmentStore, root: string }}
|
|
28
|
+
*/
|
|
29
|
+
function storeInATempRoot() {
|
|
30
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "segment-closed-"));
|
|
31
|
+
const store = new SegmentStore({ root, logger: { info: () => {}, warn: () => {} } });
|
|
32
|
+
store.useFormat(KEY, fmp4Format);
|
|
33
|
+
return { store, root };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test("a piece that simply appears ends the wait that began before it", async (t) => {
|
|
37
|
+
const { store, root } = storeInATempRoot();
|
|
38
|
+
t.after(() => {
|
|
39
|
+
store.dropAll("the test is over");
|
|
40
|
+
rmSync(root, { recursive: true, force: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const dir = store.directoryFor(KEY);
|
|
44
|
+
// The wait begins on a segment nobody has written yet — the cold case, and
|
|
45
|
+
// the only one the deadline used to decide.
|
|
46
|
+
const waited = store.waitFor(KEY, 7, BACKSTOP_MS);
|
|
47
|
+
|
|
48
|
+
// What the `hls` muxer does: a temporary name of its own, renamed into place
|
|
49
|
+
// when the piece is whole. Nothing is told; the directory simply moves.
|
|
50
|
+
const temp = path.join(dir, "segment-00007.mp4.tmp");
|
|
51
|
+
writeFileSync(temp, Buffer.alloc(64));
|
|
52
|
+
renameSync(temp, path.join(dir, fmp4Format.segmentFileName(7)));
|
|
53
|
+
|
|
54
|
+
assert.equal(await waited, true, "the piece was on disk and the wait did not end");
|
|
55
|
+
assert.ok(store.pathOf(KEY, 7), "and the store must be able to hand it over");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("clearing up after a run is not its pieces arriving", async (t) => {
|
|
59
|
+
const { store, root } = storeInATempRoot();
|
|
60
|
+
t.after(() => {
|
|
61
|
+
store.dropAll("the test is over");
|
|
62
|
+
rmSync(root, { recursive: true, force: true });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const dir = store.directoryFor(KEY);
|
|
66
|
+
const unfinished = path.join(dir, fmp4Format.makingFileNameTemplate("3").replace("%05d", "00009"));
|
|
67
|
+
writeFileSync(unfinished, Buffer.alloc(64));
|
|
68
|
+
|
|
69
|
+
let ended = false;
|
|
70
|
+
// 200 ms is a grace before asserting that something did NOT happen, which can
|
|
71
|
+
// only ever pass too easily — never a measurement.
|
|
72
|
+
const waited = store.waitFor(KEY, 9, 200).then((value) => {
|
|
73
|
+
ended = value;
|
|
74
|
+
return value;
|
|
75
|
+
});
|
|
76
|
+
rmSync(unfinished, { force: true });
|
|
77
|
+
|
|
78
|
+
assert.equal(await waited, false, "a directory that moved because a file went holds nothing new");
|
|
79
|
+
assert.equal(ended, false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("the writer that does report a closure is unaffected", async (t) => {
|
|
83
|
+
const { store, root } = storeInATempRoot();
|
|
84
|
+
t.after(() => {
|
|
85
|
+
store.dropAll("the test is over");
|
|
86
|
+
rmSync(root, { recursive: true, force: true });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const dir = store.directoryFor(KEY);
|
|
90
|
+
const making = fmp4Format.makingFileNameTemplate("4").replace("%05d", "00004");
|
|
91
|
+
writeFileSync(path.join(dir, making), Buffer.alloc(64));
|
|
92
|
+
|
|
93
|
+
const waited = store.waitFor(KEY, 4, BACKSTOP_MS);
|
|
94
|
+
assert.equal(store.publish(KEY, making, fmp4Format), fmp4Format.segmentFileName(4));
|
|
95
|
+
assert.equal(await waited, true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("a directory removed from outside and made again is watched again", async (t) => {
|
|
99
|
+
const { store, root } = storeInATempRoot();
|
|
100
|
+
t.after(() => {
|
|
101
|
+
store.dropAll("the test is over");
|
|
102
|
+
rmSync(root, { recursive: true, force: true });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Removed by something other than the store, so its watch was not stopped
|
|
106
|
+
// first. The watch held on that path watches a directory that is gone.
|
|
107
|
+
rmSync(store.directoryFor(KEY), { recursive: true, force: true });
|
|
108
|
+
const dir = store.directoryFor(KEY);
|
|
109
|
+
const waited = store.waitFor(KEY, 3, BACKSTOP_MS);
|
|
110
|
+
|
|
111
|
+
writeFileSync(path.join(dir, fmp4Format.segmentFileName(3)), Buffer.alloc(64));
|
|
112
|
+
|
|
113
|
+
assert.equal(await waited, true, "the piece arrived in the new directory and the wait did not end");
|
|
114
|
+
});
|