@torrent-tv/proxy 2.88.3 → 2.88.5
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 +16 -0
- package/assets/calibration/audio/NOTICE.md +19 -0
- package/assets/calibration/audio/aac.m4a +0 -0
- package/assets/calibration/audio/ac3.ac3 +0 -0
- package/assets/calibration/audio/alac.m4a +0 -0
- package/assets/calibration/audio/dts.dts +0 -0
- package/assets/calibration/audio/eac3.eac3 +0 -0
- package/assets/calibration/audio/flac.flac +0 -0
- package/assets/calibration/audio/manifest.json +98 -0
- package/assets/calibration/audio/mp2.mp2 +0 -0
- package/assets/calibration/audio/mp3.mp3 +0 -0
- package/assets/calibration/audio/opus.opus +0 -0
- package/assets/calibration/audio/pcm.wav +0 -0
- package/assets/calibration/audio/truehd.thd +0 -0
- package/assets/calibration/audio/vorbis.ogg +0 -0
- package/biome.json +1 -0
- package/docs/browser-proxy-contract.md +155 -133
- package/docs/playback-start-forecast.md +56 -0
- package/package.json +1 -1
- package/routes/api/transcode-sessions/post.js +5 -0
- package/routes/transcode/audio-warm/get.js +14 -3
- package/scripts/build-audio-samples.mjs +31 -0
- package/server.js +5 -0
- package/services/encode/EncodeRuns.js +3 -1
- package/services/encode/OutputOpening.js +40 -15
- package/services/encode/Renditions.js +129 -31
- package/services/encode/args.js +5 -3
- package/services/encode/audio-calibration.js +67 -0
- package/services/encode/audio-work-rate.js +15 -0
- package/services/encode/hwaccel.js +1 -1
- package/services/encode/quality/EncodeCost.js +29 -3
- package/services/encode/quality/link-budget.js +110 -15
- package/services/encode/quality/output-format.js +10 -6
- package/services/encode/segment-formats/fmp4.js +2 -0
- package/services/encode/segment-formats/mp4-boxes.js +12 -1
- package/services/media/audio-inventory.js +60 -6
- package/services/media/container/Container.js +7 -1
- package/services/media/container/Mp4Container.js +103 -3
- package/services/media/tracks/AudioTrack.js +12 -0
- package/services/media/tracks/audio-bound.js +233 -0
- package/services/server/ViewerRequests.js +30 -5
- package/services/server/playback-readiness.js +516 -708
- package/services/server/wire-outputs.js +31 -3
- package/services/storage/piece-store/shared-piece-store.js +6 -0
- package/services/storage/segment-store/SegmentStore.js +19 -4
- package/services/torrent/episode-naming.js +182 -182
- package/services/torrent/torrent-pool.js +13 -0
- package/test/audio-buffer-continuity.test.js +70 -70
- package/test/audio-calibration.test.js +23 -0
- package/test/episode-naming.test.js +131 -131
- package/test/fixtures/audio-frame-boundary.json +1 -1
- package/test/fmp4-presentation-clock.test.js +17 -2
- package/test/link-budget.test.js +7 -6
- package/test/one-output-one-session.test.js +77 -8
- package/test/playback-readiness.test.js +36 -6
- package/test/quality-variants.test.js +36 -8
- package/test/segment-store.test.js +15 -0
- package/test/serving-existing-output.test.js +3 -0
- package/test/soundtrack-rate-bound.test.js +289 -0
- package/test/source-files-route.test.js +113 -113
- package/test/two-viewers-one-picture.test.js +97 -0
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file WHAT THE BROWSER IS TOLD IS IN A TORRENT.
|
|
3
|
-
*
|
|
4
|
-
* This is the one place the product answers it. The browser used to answer it
|
|
5
|
-
* as well — a list of video extensions in its parser and a second, shorter pair
|
|
6
|
-
* inside its picker — and the three had already diverged: measured 2026-09-12,
|
|
7
|
-
* `.dat` was offered there as video and not counted here, which also decides
|
|
8
|
-
* whether a sidecar whose name matches nothing can belong to the only video
|
|
9
|
-
* present.
|
|
10
|
-
*
|
|
11
|
-
* So the shape of this answer is a contract with the page, and the page shows
|
|
12
|
-
* what it is given without looking at a name.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import test from "node:test";
|
|
16
|
-
import assert from "node:assert/strict";
|
|
17
|
-
import { handleApiSourceFilesGet } from "../routes/api/sources/files/get.js";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A request, a reply and the torrent behind them.
|
|
21
|
-
*
|
|
22
|
-
* @param {Array<{ path: string, length: number }>} files
|
|
23
|
-
* @returns {{ req: object, reply: object, sent: { body: object | null, code: number }, deps: object }}
|
|
24
|
-
*/
|
|
25
|
-
function harness(files) {
|
|
26
|
-
const sent = { body: null, code: 200 };
|
|
27
|
-
const reply = {
|
|
28
|
-
code(value) {
|
|
29
|
-
sent.code = value;
|
|
30
|
-
return reply;
|
|
31
|
-
},
|
|
32
|
-
send(body) {
|
|
33
|
-
sent.body = body;
|
|
34
|
-
return reply;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const deps = {
|
|
38
|
-
sourceRegistry: { get: () => ({ sourceType: "magnet", source: "magnet:?xt=urn:btih:abc" }) },
|
|
39
|
-
torrentPool: {
|
|
40
|
-
async getTorrent() {
|
|
41
|
-
return { name: "Drifters", infoHash: "abc", files };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
return { req: { params: { sourceKey: "key" }, query: {} }, reply, sent, deps };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
test("the files come back in reading order, each saying what it is", () => {
|
|
49
|
-
const { req, reply, sent, deps } = harness([
|
|
50
|
-
{ path: "Drifters/ep 10.mkv", length: 9 },
|
|
51
|
-
{ path: "Drifters/ep 2.mkv", length: 9 },
|
|
52
|
-
{ path: "Drifters/Rus Sound/ep 2.mka", length: 2 },
|
|
53
|
-
{ path: "Drifters/notes.nfo", length: 1 }
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
57
|
-
assert.equal(sent.code, 200);
|
|
58
|
-
assert.deepEqual(
|
|
59
|
-
sent.body.files.map((file) => [file.relativePath, file.kind]),
|
|
60
|
-
[
|
|
61
|
-
// Runs of digits compare as numbers, so 2 comes before 10; the torrent's
|
|
62
|
-
// own order is whatever the tool that made it chose.
|
|
63
|
-
["ep 2.mkv", "video"],
|
|
64
|
-
["ep 10.mkv", "video"],
|
|
65
|
-
["notes.nfo", "other"],
|
|
66
|
-
["Rus Sound/ep 2.mka", "audio"]
|
|
67
|
-
]
|
|
68
|
-
);
|
|
69
|
-
// Relative to the torrent root: WebTorrent prefixes its own name to every
|
|
70
|
-
// path, and stripping it here means one rule in the product rather than two
|
|
71
|
-
// that can disagree.
|
|
72
|
-
assert.ok(sent.body.files.every((file) => !file.relativePath.startsWith("Drifters/")));
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("each picture is named with what belongs to it, by index", () => {
|
|
77
|
-
const { req, reply, sent, deps } = harness([
|
|
78
|
-
{ path: "Drifters/ep 1.mkv", length: 9 },
|
|
79
|
-
{ path: "Drifters/Rus Sound/ep 1.mka", length: 2 },
|
|
80
|
-
{ path: "Drifters/Sub/ep 1.ass", length: 1 },
|
|
81
|
-
{ path: "Drifters/ep 2.mkv", length: 9 }
|
|
82
|
-
]);
|
|
83
|
-
|
|
84
|
-
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
85
|
-
const episode = (number) => ({
|
|
86
|
-
season: null,
|
|
87
|
-
episodes: [number],
|
|
88
|
-
part: null,
|
|
89
|
-
special: false,
|
|
90
|
-
showHint: "",
|
|
91
|
-
titleHint: ""
|
|
92
|
-
});
|
|
93
|
-
assert.deepEqual(sent.body.items, [
|
|
94
|
-
{ fileIndex: 0, audio: [1], subtitles: [2], images: [], episode: episode(1) },
|
|
95
|
-
{ fileIndex: 3, audio: [], subtitles: [], images: [], episode: episode(2) }
|
|
96
|
-
]);
|
|
97
|
-
// Two numbered pictures of one show: the release is a series.
|
|
98
|
-
assert.equal(sent.body.shape, "series");
|
|
99
|
-
// The files themselves are in the list above; saying them twice is how two
|
|
100
|
-
// copies of one fact start.
|
|
101
|
-
assert.ok(sent.body.items.every((item) => item.audio.every((one) => Number.isInteger(one))));
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("a torrent whose metadata has not arrived says so and lists nothing", () => {
|
|
106
|
-
const { req, reply, sent, deps } = harness([]);
|
|
107
|
-
|
|
108
|
-
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
109
|
-
assert.deepEqual(sent.body.files, []);
|
|
110
|
-
assert.deepEqual(sent.body.items, []);
|
|
111
|
-
assert.equal(sent.body.name, "Drifters");
|
|
112
|
-
});
|
|
113
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file WHAT THE BROWSER IS TOLD IS IN A TORRENT.
|
|
3
|
+
*
|
|
4
|
+
* This is the one place the product answers it. The browser used to answer it
|
|
5
|
+
* as well — a list of video extensions in its parser and a second, shorter pair
|
|
6
|
+
* inside its picker — and the three had already diverged: measured 2026-09-12,
|
|
7
|
+
* `.dat` was offered there as video and not counted here, which also decides
|
|
8
|
+
* whether a sidecar whose name matches nothing can belong to the only video
|
|
9
|
+
* present.
|
|
10
|
+
*
|
|
11
|
+
* So the shape of this answer is a contract with the page, and the page shows
|
|
12
|
+
* what it is given without looking at a name.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import test from "node:test";
|
|
16
|
+
import assert from "node:assert/strict";
|
|
17
|
+
import { handleApiSourceFilesGet } from "../routes/api/sources/files/get.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A request, a reply and the torrent behind them.
|
|
21
|
+
*
|
|
22
|
+
* @param {Array<{ path: string, length: number }>} files
|
|
23
|
+
* @returns {{ req: object, reply: object, sent: { body: object | null, code: number }, deps: object }}
|
|
24
|
+
*/
|
|
25
|
+
function harness(files) {
|
|
26
|
+
const sent = { body: null, code: 200 };
|
|
27
|
+
const reply = {
|
|
28
|
+
code(value) {
|
|
29
|
+
sent.code = value;
|
|
30
|
+
return reply;
|
|
31
|
+
},
|
|
32
|
+
send(body) {
|
|
33
|
+
sent.body = body;
|
|
34
|
+
return reply;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const deps = {
|
|
38
|
+
sourceRegistry: { get: () => ({ sourceType: "magnet", source: "magnet:?xt=urn:btih:abc" }) },
|
|
39
|
+
torrentPool: {
|
|
40
|
+
async getTorrent() {
|
|
41
|
+
return { name: "Drifters", infoHash: "abc", files };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return { req: { params: { sourceKey: "key" }, query: {} }, reply, sent, deps };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test("the files come back in reading order, each saying what it is", () => {
|
|
49
|
+
const { req, reply, sent, deps } = harness([
|
|
50
|
+
{ path: "Drifters/ep 10.mkv", length: 9 },
|
|
51
|
+
{ path: "Drifters/ep 2.mkv", length: 9 },
|
|
52
|
+
{ path: "Drifters/Rus Sound/ep 2.mka", length: 2 },
|
|
53
|
+
{ path: "Drifters/notes.nfo", length: 1 }
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
57
|
+
assert.equal(sent.code, 200);
|
|
58
|
+
assert.deepEqual(
|
|
59
|
+
sent.body.files.map((file) => [file.relativePath, file.kind]),
|
|
60
|
+
[
|
|
61
|
+
// Runs of digits compare as numbers, so 2 comes before 10; the torrent's
|
|
62
|
+
// own order is whatever the tool that made it chose.
|
|
63
|
+
["ep 2.mkv", "video"],
|
|
64
|
+
["ep 10.mkv", "video"],
|
|
65
|
+
["notes.nfo", "other"],
|
|
66
|
+
["Rus Sound/ep 2.mka", "audio"]
|
|
67
|
+
]
|
|
68
|
+
);
|
|
69
|
+
// Relative to the torrent root: WebTorrent prefixes its own name to every
|
|
70
|
+
// path, and stripping it here means one rule in the product rather than two
|
|
71
|
+
// that can disagree.
|
|
72
|
+
assert.ok(sent.body.files.every((file) => !file.relativePath.startsWith("Drifters/")));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("each picture is named with what belongs to it, by index", () => {
|
|
77
|
+
const { req, reply, sent, deps } = harness([
|
|
78
|
+
{ path: "Drifters/ep 1.mkv", length: 9 },
|
|
79
|
+
{ path: "Drifters/Rus Sound/ep 1.mka", length: 2 },
|
|
80
|
+
{ path: "Drifters/Sub/ep 1.ass", length: 1 },
|
|
81
|
+
{ path: "Drifters/ep 2.mkv", length: 9 }
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
85
|
+
const episode = (number) => ({
|
|
86
|
+
season: null,
|
|
87
|
+
episodes: [number],
|
|
88
|
+
part: null,
|
|
89
|
+
special: false,
|
|
90
|
+
showHint: "",
|
|
91
|
+
titleHint: ""
|
|
92
|
+
});
|
|
93
|
+
assert.deepEqual(sent.body.items, [
|
|
94
|
+
{ fileIndex: 0, audio: [1], subtitles: [2], images: [], episode: episode(1) },
|
|
95
|
+
{ fileIndex: 3, audio: [], subtitles: [], images: [], episode: episode(2) }
|
|
96
|
+
]);
|
|
97
|
+
// Two numbered pictures of one show: the release is a series.
|
|
98
|
+
assert.equal(sent.body.shape, "series");
|
|
99
|
+
// The files themselves are in the list above; saying them twice is how two
|
|
100
|
+
// copies of one fact start.
|
|
101
|
+
assert.ok(sent.body.items.every((item) => item.audio.every((one) => Number.isInteger(one))));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("a torrent whose metadata has not arrived says so and lists nothing", () => {
|
|
106
|
+
const { req, reply, sent, deps } = harness([]);
|
|
107
|
+
|
|
108
|
+
return handleApiSourceFilesGet(req, reply, deps).then(() => {
|
|
109
|
+
assert.deepEqual(sent.body.files, []);
|
|
110
|
+
assert.deepEqual(sent.body.items, []);
|
|
111
|
+
assert.equal(sent.body.name, "Drifters");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -405,3 +405,100 @@ test("a viewer whose picture has gone quiet holds no soundtrack encoder", async
|
|
|
405
405
|
"the first viewer moved on, so their old track is nobody's"
|
|
406
406
|
);
|
|
407
407
|
});
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The soundtracks of the field case of 2026-10-01: the picture's own track
|
|
411
|
+
* states its rate, and the dub shipped beside it states nothing.
|
|
412
|
+
*
|
|
413
|
+
* @param {object} manager
|
|
414
|
+
* @param {{ dubRate?: number | null }} [what]
|
|
415
|
+
*/
|
|
416
|
+
function withAStatedAndASilentTrack(manager, { dubRate = null } = {}) {
|
|
417
|
+
const inventory = [
|
|
418
|
+
{ index: 0, language: "jpn", title: "", isDefault: true, fileIndex: 0, sourceTrackIndex: 0, bitrateKbps: 128 },
|
|
419
|
+
{ index: 1, language: "rus", title: "", isDefault: false, fileIndex: 0, sourceTrackIndex: 1, bitrateKbps: dubRate }
|
|
420
|
+
];
|
|
421
|
+
manager.getCachedAudioTracks = () => inventory;
|
|
422
|
+
return inventory;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
test("a track nothing states a rate for is sent as AAC even to a browser that plays it, and another viewer's copy is left alone", async (t) => {
|
|
426
|
+
const { manager, base, renditions, dirPath } = await pictureWithTwoViewers();
|
|
427
|
+
t.after(async () => {
|
|
428
|
+
await manager.lifecycle.disposeAll();
|
|
429
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
430
|
+
});
|
|
431
|
+
withAStatedAndASilentTrack(manager);
|
|
432
|
+
manager.viewers.of(base, FIRST).audio = { trackIndex: 0, transcode: false };
|
|
433
|
+
manager.viewers.of(base, SECOND).audio = { trackIndex: 0, transcode: false };
|
|
434
|
+
const copy = await manager.renditions.resolveAudioRenditionFile(BASE_ID, 0, "segment-00003.mp4", FIRST);
|
|
435
|
+
|
|
436
|
+
// The second viewer's page says its browser plays the dub as it is.
|
|
437
|
+
const prepared = await manager.renditions.prepareAudioTrack(BASE_ID, 1, 12, SECOND, true);
|
|
438
|
+
const sent = await manager.renditions.resolveAudioRenditionFile(BASE_ID, 1, "segment-00003.mp4", SECOND);
|
|
439
|
+
|
|
440
|
+
assert.equal(prepared.sessionId, renditions.get(audioRenditionKey(1, true)).id, "prepared as AAC");
|
|
441
|
+
assert.equal(sent.sessionId, prepared.sessionId, "and its segments come from that same output");
|
|
442
|
+
assert.deepEqual(
|
|
443
|
+
manager.viewers.of(base, SECOND).audio,
|
|
444
|
+
{ trackIndex: 1, transcode: true },
|
|
445
|
+
"the viewer is recorded as receiving what they are sent"
|
|
446
|
+
);
|
|
447
|
+
assert.equal(
|
|
448
|
+
(await manager.renditions.resolveAudioRenditionFile(BASE_ID, 0, "segment-00004.mp4", FIRST)).sessionId,
|
|
449
|
+
copy.sessionId,
|
|
450
|
+
"the other viewer's copy is the same output it was"
|
|
451
|
+
);
|
|
452
|
+
assert.deepEqual(manager.viewers.of(base, FIRST).audio, { trackIndex: 0, transcode: false });
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("the page's statement about the track it moves to decides, and silence keeps what it needed before", async (t) => {
|
|
456
|
+
const { manager, base, renditions, dirPath } = await pictureWithTwoViewers();
|
|
457
|
+
t.after(async () => {
|
|
458
|
+
await manager.lifecycle.disposeAll();
|
|
459
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
460
|
+
});
|
|
461
|
+
withAStatedAndASilentTrack(manager, { dubRate: 192 });
|
|
462
|
+
manager.viewers.of(base, FIRST).audio = { trackIndex: 0, transcode: false };
|
|
463
|
+
manager.viewers.of(base, SECOND).audio = { trackIndex: 0, transcode: false };
|
|
464
|
+
|
|
465
|
+
await manager.renditions.prepareAudioTrack(BASE_ID, 1, 12, FIRST, false);
|
|
466
|
+
await manager.renditions.prepareAudioTrack(BASE_ID, 1, 12, SECOND, null);
|
|
467
|
+
|
|
468
|
+
assert.ok(renditions.has(audioRenditionKey(1, true)), "a browser that cannot play it gets AAC");
|
|
469
|
+
assert.ok(renditions.has(audioRenditionKey(1, false)), "one that says nothing is taken to play it, as it played the track it was on");
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
test("the soundtrack's load counts what is sent, not a figure learned after it was chosen", async (t) => {
|
|
473
|
+
const { manager, base, dirPath } = await pictureWithTwoViewers();
|
|
474
|
+
t.after(async () => {
|
|
475
|
+
await manager.lifecycle.disposeAll();
|
|
476
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
477
|
+
});
|
|
478
|
+
const inventory = withAStatedAndASilentTrack(manager);
|
|
479
|
+
manager.viewers.of(base, SECOND).audio = { trackIndex: 0, transcode: false };
|
|
480
|
+
await manager.renditions.prepareAudioTrack(BASE_ID, 1, 12, SECOND, true);
|
|
481
|
+
await manager.renditions.resolveAudioRenditionFile(BASE_ID, 1, "segment-00003.mp4", SECOND);
|
|
482
|
+
|
|
483
|
+
// The dub's header arrives late and states a bound after all.
|
|
484
|
+
inventory[1].peakKbps = 576;
|
|
485
|
+
|
|
486
|
+
assert.deepEqual(
|
|
487
|
+
manager.renditions.viewerAudioLoadOf(base, SECOND),
|
|
488
|
+
{ mbps: 0.128, peakClass: "estimated" },
|
|
489
|
+
"still the AAC being sent, not a copy nobody is receiving"
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test("a copied track's codec bound reaches the link's question through the viewer's choice", async (t) => {
|
|
494
|
+
const { manager, base, dirPath } = await pictureWithTwoViewers();
|
|
495
|
+
t.after(async () => {
|
|
496
|
+
await manager.lifecycle.disposeAll();
|
|
497
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
498
|
+
});
|
|
499
|
+
const inventory = withAStatedAndASilentTrack(manager);
|
|
500
|
+
inventory[0].peakKbps = 576;
|
|
501
|
+
manager.viewers.of(base, FIRST).audio = { trackIndex: 0, transcode: false };
|
|
502
|
+
|
|
503
|
+
assert.deepEqual(manager.renditions.viewerAudioLoadOf(base, FIRST), { mbps: 0.576, peakClass: "known" });
|
|
504
|
+
});
|