@torrent-tv/proxy 2.89.17 → 2.89.19
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/README.md +14 -3
- package/package.json +10 -2
- package/server.js +0 -11
- package/utils/client-log-file.js +147 -42
- package/.claude/commands/opsx/apply.md +0 -155
- package/.claude/commands/opsx/archive.md +0 -160
- package/.claude/commands/opsx/explore.md +0 -174
- package/.claude/commands/opsx/propose.md +0 -109
- package/.claude/commands/opsx/sync.md +0 -143
- package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
- package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
- package/.claude/skills/openspec-explore/SKILL.md +0 -289
- package/.claude/skills/openspec-propose/SKILL.md +0 -113
- package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
- package/.dockerignore +0 -5
- package/AGENTS.md +0 -363
- package/CHANGELOG.md +0 -2377
- package/Dockerfile +0 -30
- package/biome.json +0 -412
- package/corpus.tmp.json +0 -1
- package/docs/browser-proxy-contract.md +0 -155
- package/docs/container-architecture.md +0 -273
- package/docs/download-architecture.md +0 -261
- package/docs/encode-architecture.md +0 -765
- package/docs/encode-run-state.md +0 -96
- package/docs/logs.md +0 -151
- package/docs/playback-start-forecast.md +0 -113
- package/docs/socks5-egress-research.md +0 -114
- package/docs/storage-architecture.md +0 -273
- package/knip.json +0 -14
- package/main2.cpuprofile +0 -1
- package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
- package/openspec/changes/adaptive-bitrate/design.md +0 -92
- package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
- package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
- package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
- package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
- package/openspec/changes/binary-distribution/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/design.md +0 -81
- package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
- package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
- package/openspec/changes/cold-start/design.md +0 -98
- package/openspec/changes/cold-start/proposal.md +0 -62
- package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
- package/openspec/changes/cold-start/tasks.md +0 -48
- package/openspec/changes/disk-cap/.openspec.yaml +0 -2
- package/openspec/changes/disk-cap/proposal.md +0 -37
- package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
- package/openspec/changes/disk-cap/tasks.md +0 -19
- package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
- package/openspec/changes/proxy-observability/design.md +0 -38
- package/openspec/changes/proxy-observability/proposal.md +0 -49
- package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
- package/openspec/changes/proxy-observability/tasks.md +0 -21
- package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
- package/openspec/changes/seek-debounce/design.md +0 -118
- package/openspec/changes/seek-debounce/proposal.md +0 -59
- package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
- package/openspec/changes/seek-debounce/tasks.md +0 -33
- package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
- package/openspec/changes/subtitle-language/proposal.md +0 -50
- package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
- package/openspec/changes/subtitle-language/tasks.md +0 -26
- package/openspec/changes/track-selection/.openspec.yaml +0 -2
- package/openspec/changes/track-selection/design.md +0 -47
- package/openspec/changes/track-selection/proposal.md +0 -45
- package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
- package/openspec/changes/track-selection/tasks.md +0 -20
- package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
- package/openspec/changes/transcode-quality/proposal.md +0 -51
- package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
- package/openspec/changes/transcode-quality/tasks.md +0 -63
- package/openspec/config.yaml +0 -38
- package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
- package/research/double-spawn-2026-09-10.md +0 -171
- package/research/handover-2026-09-13.md +0 -209
- package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
- package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
- package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
- package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
- package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
- package/scripts/build-audio-samples.mjs +0 -31
- package/scripts/render-run-graph.js +0 -173
- package/test/asset-paths.test.js +0 -28
- package/test/audio-buffer-continuity.test.js +0 -77
- package/test/audio-calibration.test.js +0 -23
- package/test/audio-inventory.test.js +0 -212
- package/test/audio-track-bitrate.test.js +0 -40
- package/test/audio-warm-recorded.test.js +0 -63
- package/test/auto-quality-step.test.js +0 -762
- package/test/available-share.test.js +0 -76
- package/test/background-fill.test.js +0 -190
- package/test/client-log-file.test.js +0 -126
- package/test/client-logs-route.test.js +0 -34
- package/test/coalesce.test.js +0 -39
- package/test/completed-files.test.js +0 -115
- package/test/concurrent-cost.test.js +0 -148
- package/test/container-media-info.test.js +0 -228
- package/test/contention.test.js +0 -76
- package/test/core-dumps.test.js +0 -57
- package/test/coverage-follows-the-disk.test.js +0 -233
- package/test/coverage-map.test.js +0 -195
- package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
- package/test/cut-times-timeline.test.js +0 -65
- package/test/cuts-follow-published-grid.test.js +0 -109
- package/test/data-channel-frame.test.js +0 -63
- package/test/data-channel-viewer-lifecycle.test.js +0 -193
- package/test/dead-torrent-handle.test.js +0 -52
- package/test/declared-rates.test.js +0 -116
- package/test/declared-tracks.test.js +0 -43
- package/test/decode-cost-fit.test.js +0 -202
- package/test/decode-cost.test.js +0 -475
- package/test/delivery-probe-field.test.js +0 -173
- package/test/delivery-probe.test.js +0 -382
- package/test/demand-register.test.js +0 -206
- package/test/dht-bootstrap.test.js +0 -72
- package/test/drain-threat.test.js +0 -65
- package/test/duplicate-add.test.js +0 -48
- package/test/encode-admission.test.js +0 -170
- package/test/encode-cost.test.js +0 -275
- package/test/encode-exit.test.js +0 -111
- package/test/encode-orchestrator.test.js +0 -426
- package/test/encode-plan-viewers.test.js +0 -725
- package/test/encode-plan.test.js +0 -545
- package/test/encode-run-state.test.js +0 -314
- package/test/encode-run.test.js +0 -248
- package/test/encode-slope.test.js +0 -46
- package/test/encoded-output.test.js +0 -39
- package/test/encoder-kinds.test.js +0 -122
- package/test/encoder-readings.test.js +0 -68
- package/test/episode-naming.test.js +0 -131
- package/test/every-claimant-is-told-its-share.test.js +0 -152
- package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
- package/test/failed-start-breaker.test.js +0 -202
- package/test/fastest-wires.test.js +0 -143
- package/test/ffmpeg-stream-counts.test.js +0 -101
- package/test/file-edges.test.js +0 -191
- package/test/files-in-use.test.js +0 -34
- package/test/fixtures/audio-frame-boundary.json +0 -1
- package/test/fixtures/refused-audio-20261002.json +0 -10
- package/test/fmp4-presentation-clock.test.js +0 -148
- package/test/fmp4-self-contained.test.js +0 -80
- package/test/fmp4-timestamps.test.js +0 -140
- package/test/fmp4-track-completeness.test.js +0 -41
- package/test/format-keyed-outputs.test.js +0 -78
- package/test/health-metrics.test.js +0 -36
- package/test/held-read-ownership.test.js +0 -77
- package/test/held-request-width.test.js +0 -157
- package/test/helpers/encode-run.js +0 -248
- package/test/helpers/held-file.js +0 -77
- package/test/helpers/manager.js +0 -62
- package/test/helpers/matroska-file.js +0 -296
- package/test/helpers/output-spec.js +0 -63
- package/test/host-load.test.js +0 -68
- package/test/index-accuracy-is-about-the-file.test.js +0 -128
- package/test/init-compat.test.js +0 -219
- package/test/input-lost-quiets-the-plan.test.js +0 -261
- package/test/input-unavailable.test.js +0 -48
- package/test/installation-id.test.js +0 -39
- package/test/keeping-period.test.js +0 -83
- package/test/keyframe-index-accuracy.test.js +0 -188
- package/test/keyframe-table-budget.test.js +0 -123
- package/test/keyframes-belong-to-the-file.test.js +0 -249
- package/test/learned-median.test.js +0 -37
- package/test/letting-go-asks-who-is-watching.test.js +0 -191
- package/test/limit-row-by-area.test.js +0 -60
- package/test/link-budget.test.js +0 -111
- package/test/link-probe.test.js +0 -56
- package/test/local-encoding-data.test.js +0 -273
- package/test/logger-repeats.test.js +0 -134
- package/test/look-ahead-coverage.test.js +0 -56
- package/test/manager-surface.test.js +0 -291
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cluster-discovery.test.js +0 -323
- package/test/matroska-cues-track.test.js +0 -192
- package/test/media-time.test.js +0 -62
- package/test/memory-budget.test.js +0 -390
- package/test/move-cost.test.js +0 -216
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +0 -173
- package/test/one-authority.test.js +0 -285
- package/test/one-budget.test.js +0 -149
- package/test/one-output-one-session.test.js +0 -273
- package/test/one-resource-divided.test.js +0 -185
- package/test/one-serving-output-per-height.test.js +0 -458
- package/test/orchestrator-wired.test.js +0 -207
- package/test/output-catalog.test.js +0 -39
- package/test/output-shape.test.js +0 -21
- package/test/output-spec.test.js +0 -251
- package/test/output-speed.test.js +0 -92
- package/test/outputs-being-prepared.test.js +0 -40
- package/test/packet-witness-ring.test.js +0 -236
- package/test/packet-witness.test.js +0 -148
- package/test/piece-completeness.test.js +0 -78
- package/test/piece-disk-store.test.js +0 -401
- package/test/piece-from-whole-file.test.js +0 -129
- package/test/piece-lru.test.js +0 -319
- package/test/piece-reader.test.js +0 -162
- package/test/piece-selection-offset.test.js +0 -85
- package/test/piece-store-eviction.test.js +0 -595
- package/test/piece-store-never-refuses.test.js +0 -153
- package/test/piece-store-reservations.test.js +0 -403
- package/test/piece-store-slow-disk.test.js +0 -159
- package/test/piece-tail.test.js +0 -97
- package/test/plan-host-timings.test.js +0 -68
- package/test/plan-is-steady.test.js +0 -225
- package/test/playback-readiness.test.js +0 -518
- package/test/playback-start-regressions.test.js +0 -101
- package/test/priority-map-download.test.js +0 -174
- package/test/priority-map-emptied.test.js +0 -204
- package/test/priority-map-per-output.test.js +0 -215
- package/test/priority-map.test.js +0 -163
- package/test/probe-wedge-certainty.test.js +0 -60
- package/test/produced-copy-choice.test.js +0 -213
- package/test/published-timeline.test.js +0 -83
- package/test/quality-offer.test.js +0 -160
- package/test/quality-variants.test.js +0 -1274
- package/test/rate-control-in-the-output.test.js +0 -181
- package/test/read-survives-withdrawal.test.js +0 -164
- package/test/read-window.test.js +0 -365
- package/test/reads-not-yet-arrived.test.js +0 -218
- package/test/resume-warm.test.js +0 -39
- package/test/run-graph-drift.test.js +0 -37
- package/test/run-inputs.test.js +0 -80
- package/test/run-intervals.test.js +0 -100
- package/test/run-position-follows-published-grid.test.js +0 -89
- package/test/run-progress.test.js +0 -64
- package/test/same-height-switch.test.js +0 -663
- package/test/seek-frees-the-viewers-requests.test.js +0 -217
- package/test/seek-landing.test.js +0 -109
- package/test/seek-target-not-superseded.test.js +0 -195
- package/test/segment-closed-on-both-branches.test.js +0 -114
- package/test/segment-cut-times.test.js +0 -63
- package/test/segment-demand.test.js +0 -80
- package/test/segment-hold-supersede.test.js +0 -91
- package/test/segment-judged-by-its-own-header.test.js +0 -222
- package/test/segment-serve-wiring.test.js +0 -481
- package/test/segment-store-eviction.test.js +0 -247
- package/test/segment-store.test.js +0 -352
- package/test/segment-true-start.test.js +0 -86
- package/test/segments-are-shared.test.js +0 -176
- package/test/send-chunk-bytes.test.js +0 -86
- package/test/serving-existing-output.test.js +0 -111
- package/test/serving-output.test.js +0 -102
- package/test/shared-piece-store.test.js +0 -310
- package/test/sidecar-naming.test.js +0 -142
- package/test/soundtrack-rate-bound.test.js +0 -289
- package/test/source-file.test.js +0 -133
- package/test/source-files-route.test.js +0 -113
- package/test/source-registry.test.js +0 -18
- package/test/split-a-stretch.test.js +0 -139
- package/test/stale-request-after-seek.test.js +0 -158
- package/test/startup-readings.test.js +0 -124
- package/test/stream-route.test.js +0 -237
- package/test/subtitle-cue-framing.test.js +0 -200
- package/test/subtitle-cue-source.test.js +0 -102
- package/test/subtitle-cue-walk.test.js +0 -385
- package/test/subtitle-cursor.test.js +0 -63
- package/test/subtitle-defaults.test.js +0 -118
- package/test/subtitle-language.test.js +0 -252
- package/test/subtitle-metadata.test.js +0 -15
- package/test/subtitle-plan-waits.test.js +0 -125
- package/test/subtitle-track-numbering.test.js +0 -391
- package/test/supply-margin.test.js +0 -190
- package/test/swarm-follows-readers.test.js +0 -174
- package/test/swarm-reach.test.js +0 -130
- package/test/swarm-selection.test.js +0 -220
- package/test/tail-duplication.test.js +0 -167
- package/test/the-channel-has-both-ends.test.js +0 -91
- package/test/the-torrent-thread-serves-bytes.test.js +0 -107
- package/test/thread-pool.test.js +0 -53
- package/test/timeline.test.js +0 -84
- package/test/torrent-contents.test.js +0 -235
- package/test/torrent-cost.test.js +0 -71
- package/test/torrent-files.test.js +0 -221
- package/test/torrent-naming.test.js +0 -255
- package/test/tracks-begin-together.test.js +0 -209
- package/test/tunnel-renewal.test.js +0 -167
- package/test/two-viewers-one-picture.test.js +0 -508
- package/test/upload-hurry.test.js +0 -186
- package/test/usrsctp-state.test.js +0 -131
- package/test/video-facts.test.js +0 -102
- package/test/viewer-assignments.test.js +0 -143
- package/test/viewer-outputs.test.js +0 -285
- package/test/viewer-presence.test.js +0 -116
- package/test/viewer-requests-admission.test.js +0 -92
- package/test/viewer-starts-on-map.test.js +0 -27
- package/test/viewer-states.test.js +0 -192
- package/test/viewer-subtitle-subscription.test.js +0 -96
- package/test/viewer.test.js +0 -139
- package/test/viewing-generations.test.js +0 -390
- package/test/visible-rung.test.js +0 -37
- package/test/wait-ledger.test.js +0 -100
- package/test/webrtc-shim.test.js +0 -149
- package/test/wedge-certainty.test.js +0 -131
- package/test/whole-file-held-read.test.js +0 -30
- package/test/withdraw-piece-claim.test.js +0 -212
- package/test/worker-channel.test.js +0 -158
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The bitrate limit and the level are decided with the rest of an
|
|
3
|
-
* output's format, before it is named — roadmap item 97, step 10.
|
|
4
|
-
*
|
|
5
|
-
* Nothing here starts ffmpeg, a torrent or a worker: the decision is a pure
|
|
6
|
-
* function of values.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import test from "node:test";
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
import { decideOutputFormat } from "../services/encode/quality/output-format.js";
|
|
12
|
-
import { nominalKbpsFor, softwareRateControlFor } from "../services/encode/args.js";
|
|
13
|
-
import { AudioOutput, CutGrid, OutputSpec, VideoOutput } from "../services/encode/output/OutputSpec.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A 720p output asked for exactly, from a 1080p source, on the encoder given.
|
|
17
|
-
*
|
|
18
|
-
* @param {{ kind: string, name: string }} encoder
|
|
19
|
-
* @param {number | null} [capKbps]
|
|
20
|
-
* @returns {ReturnType<typeof decideOutputFormat>}
|
|
21
|
-
*/
|
|
22
|
-
function decide(encoder, capKbps = null) {
|
|
23
|
-
return decideOutputFormat({
|
|
24
|
-
encodesPicture: true,
|
|
25
|
-
exact: true,
|
|
26
|
-
target: { width: 1280, height: 720 },
|
|
27
|
-
source: { width: 1920, height: 1080, megabitsPerSecond: 8, decode: null },
|
|
28
|
-
fps: 24,
|
|
29
|
-
encoder,
|
|
30
|
-
benchmark: null,
|
|
31
|
-
cost: { decodeModel: null, observedDecodeCostSec: null, requiredSpeed: null },
|
|
32
|
-
chooseBudget: () => null,
|
|
33
|
-
tonemap: false,
|
|
34
|
-
capKbps,
|
|
35
|
-
specWith: (encode) => new OutputSpec({
|
|
36
|
-
sourceKey: "torrent:abc",
|
|
37
|
-
segmentFormatId: "fmp4",
|
|
38
|
-
grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
|
|
39
|
-
video: new VideoOutput({ fileIndex: 0, encode }),
|
|
40
|
-
audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
|
|
41
|
-
}),
|
|
42
|
-
serving: { mode: "manual", linkMbps: null, keys: [], readyAt: () => false }
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const SOFTWARE = { kind: "software", name: "libx264" };
|
|
47
|
-
const HARDWARE = { kind: "nvenc", name: "h264_nvenc" };
|
|
48
|
-
|
|
49
|
-
test("a software output is bounded at its size's nominal rate unless a lower limit is asked for", () => {
|
|
50
|
-
const plain = decide(SOFTWARE).spec.video.encode.rateControl;
|
|
51
|
-
const lower = decide(SOFTWARE, 1400).spec.video.encode.rateControl;
|
|
52
|
-
|
|
53
|
-
assert.deepEqual(plain, softwareRateControlFor({ width: 1280, height: 720, fps: 24 }));
|
|
54
|
-
assert.deepEqual(lower, softwareRateControlFor({ width: 1280, height: 720, fps: 24, capKbps: 1400 }));
|
|
55
|
-
assert.equal(lower.level, plain.level, "both are declared at the nominal output's level");
|
|
56
|
-
assert.notEqual(decide(SOFTWARE).spec.toKey(), decide(SOFTWARE, 1400).spec.toKey(), "and are two outputs");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("a limit named in the request is not answered by an output of another limit already here", () => {
|
|
60
|
-
// The nominal 720p output exists and is ready, and it suits this viewer —
|
|
61
|
-
// which is exactly what a move to a lower limit is for leaving.
|
|
62
|
-
const nominal = decide(SOFTWARE).spec.toKey();
|
|
63
|
-
const asked = decideOutputFormat({
|
|
64
|
-
encodesPicture: true,
|
|
65
|
-
exact: true,
|
|
66
|
-
target: { width: 1280, height: 720 },
|
|
67
|
-
source: { width: 1920, height: 1080, megabitsPerSecond: 8, decode: null },
|
|
68
|
-
fps: 24,
|
|
69
|
-
encoder: SOFTWARE,
|
|
70
|
-
benchmark: null,
|
|
71
|
-
cost: { decodeModel: null, observedDecodeCostSec: null, requiredSpeed: null },
|
|
72
|
-
chooseBudget: () => null,
|
|
73
|
-
tonemap: false,
|
|
74
|
-
capKbps: 1400,
|
|
75
|
-
specWith: (encode) => new OutputSpec({
|
|
76
|
-
sourceKey: "torrent:abc",
|
|
77
|
-
segmentFormatId: "fmp4",
|
|
78
|
-
grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
|
|
79
|
-
video: new VideoOutput({ fileIndex: 0, encode }),
|
|
80
|
-
audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
|
|
81
|
-
}),
|
|
82
|
-
serving: { mode: "manual", linkMbps: null, keys: [nominal], readyAt: () => true }
|
|
83
|
-
});
|
|
84
|
-
assert.equal(asked.reusedKey, null);
|
|
85
|
-
assert.deepEqual(asked.spec.video.encode.rateControl, softwareRateControlFor({ width: 1280, height: 720, fps: 24, capKbps: 1400 }));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("a hardware output states no limit, because it is given none", () => {
|
|
89
|
-
assert.equal(decide(HARDWARE).spec.video.encode.rateControl, null);
|
|
90
|
-
assert.ok(decide(HARDWARE).spec.toKey().endsWith("/vbv=-:a=0/0/aac"));
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("a limit above the size's own is refused rather than lowered", () => {
|
|
94
|
-
assert.throws(() => decide(SOFTWARE, nominalKbpsFor({ width: 1280, height: 720 }) + 1), RangeError);
|
|
95
|
-
assert.throws(() => decide(SOFTWARE, 0), RangeError, "and a limit that is not a positive rate is not a limit");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// Step 11: the viewer's own link decides whether a format may be given at all.
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* A 720p output of a 1080p source for a viewer whose link measured `linkMbps`.
|
|
104
|
-
*
|
|
105
|
-
* @param {{ mode?: "auto" | "manual", linkMbps?: number | null, limits?: number[], encoder?: object, audioLoad?: object | null }} how
|
|
106
|
-
*/
|
|
107
|
-
function decideFor({ mode = "manual", linkMbps = null, limits = null, encoder = SOFTWARE, audioLoad = null } = {}) {
|
|
108
|
-
return decideOutputFormat({
|
|
109
|
-
encodesPicture: true,
|
|
110
|
-
exact: true,
|
|
111
|
-
target: { width: 1280, height: 720 },
|
|
112
|
-
source: { width: 1920, height: 1080, megabitsPerSecond: 8, decode: null },
|
|
113
|
-
fps: 24,
|
|
114
|
-
encoder,
|
|
115
|
-
benchmark: null,
|
|
116
|
-
cost: { decodeModel: null, observedDecodeCostSec: null, requiredSpeed: null },
|
|
117
|
-
chooseBudget: () => null,
|
|
118
|
-
tonemap: false,
|
|
119
|
-
...(limits ? { limitsFor: (frame) => (frame.height === 720 ? limits : [nominalKbpsFor(frame)]) } : {}),
|
|
120
|
-
audioLoad,
|
|
121
|
-
specWith: (encode) => new OutputSpec({
|
|
122
|
-
sourceKey: "torrent:abc",
|
|
123
|
-
segmentFormatId: "fmp4",
|
|
124
|
-
grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
|
|
125
|
-
video: new VideoOutput({ fileIndex: 0, encode }),
|
|
126
|
-
audio: null
|
|
127
|
-
}),
|
|
128
|
-
serving: { mode, linkMbps, keys: [], readyAt: () => false }
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
test("a size picked by hand keeps its height and takes the highest limit the link admits", () => {
|
|
133
|
-
// 720p nominal peaks at 3.64 Mbit/s; a 3 Mbit/s link admits 2.4 of it.
|
|
134
|
-
const decided = decideFor({ mode: "manual", linkMbps: 3, limits: [2800, 1400] });
|
|
135
|
-
assert.equal(decided.unavailable, null);
|
|
136
|
-
assert.equal(decided.spec.video.encode.height, 720, "the height picked by hand is kept");
|
|
137
|
-
assert.deepEqual(
|
|
138
|
-
decided.spec.video.encode.rateControl,
|
|
139
|
-
softwareRateControlFor({ width: 1280, height: 720, fps: 24, capKbps: 1400 })
|
|
140
|
-
);
|
|
141
|
-
assert.equal(decided.answer.verdict, "fits");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test("AUTO moves to a smaller rung only when that rung's own load is admitted", () => {
|
|
145
|
-
// Nothing at 720p fits 3 Mbit/s with only the nominal limit, and 480p's
|
|
146
|
-
// nominal peak (1.82 Mbit/s) does.
|
|
147
|
-
const decided = decideFor({ mode: "auto", linkMbps: 3 });
|
|
148
|
-
assert.equal(decided.unavailable, null);
|
|
149
|
-
assert.ok(decided.spec.video.encode.height < 720, "a smaller rung");
|
|
150
|
-
assert.ok(decided.answer.admitted, "whose own load the link admits");
|
|
151
|
-
assert.equal(
|
|
152
|
-
decideFor({ mode: "auto", linkMbps: 0.3 }).unavailable?.reason?.length > 0,
|
|
153
|
-
true,
|
|
154
|
-
"and with nothing admitted at any rung, nothing is handed over"
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test("nothing admitted is answered as unavailable, with the figures, and names no output", () => {
|
|
159
|
-
const decided = decideFor({ mode: "manual", linkMbps: 3 });
|
|
160
|
-
assert.equal(decided.spec, null, "a format known not to fit is never handed over");
|
|
161
|
-
assert.ok(decided.unavailable.reason.length > 0);
|
|
162
|
-
assert.equal(decided.unavailable.figures.verdict, "does not fit");
|
|
163
|
-
assert.equal(decided.unavailable.figures.linkMbps, 3);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("a hardware output is unavailable against a measured link, and given while nothing measured it", () => {
|
|
167
|
-
assert.equal(decideFor({ encoder: HARDWARE, linkMbps: 50 }).unavailable.figures.verdict, "no safe bound");
|
|
168
|
-
assert.equal(decideFor({ encoder: HARDWARE, linkMbps: null }).answer.verdict, "no measurement");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test("the soundtrack the viewer hears counts toward what their link carries", () => {
|
|
172
|
-
// 720p nominal peaks at 3.64 Mbit/s, and the whole measured link is compared
|
|
173
|
-
// with the stream (no share of it is set aside since proxy 2.89.4). A 3.7 Mbit/s
|
|
174
|
-
// link carries the picture, not the picture and 128 kbit/s of sound (3.768).
|
|
175
|
-
const linkMbps = 3.7;
|
|
176
|
-
assert.equal(decideFor({ mode: "manual", linkMbps }).answer.verdict, "fits");
|
|
177
|
-
assert.ok(
|
|
178
|
-
decideFor({ mode: "manual", linkMbps, audioLoad: { mbps: 0.128, peakClass: "known" } }).unavailable,
|
|
179
|
-
"with the sound it no longer fits"
|
|
180
|
-
);
|
|
181
|
-
});
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file A read whose piece is withdrawn under it waits, rather than failing.
|
|
3
|
-
*
|
|
4
|
-
* The store drops a piece once every reader is past it, and the claim is
|
|
5
|
-
* withdrawn with it, so the piece is fetched again. A read that meets the gap in
|
|
6
|
-
* between must therefore WAIT — until 2026-09-12 it threw, ffmpeg read the empty
|
|
7
|
-
* body as the end of the file, the encoder died, and the plan restarted it into
|
|
8
|
-
* the same emptiness: 2432 starts in 23 minutes and a viewer looking at a still
|
|
9
|
-
* picture for 92 minutes.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import test from "node:test";
|
|
13
|
-
import assert from "node:assert/strict";
|
|
14
|
-
import { EventEmitter } from "node:events";
|
|
15
|
-
import os from "node:os";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import fs from "node:fs/promises";
|
|
18
|
-
import { readFragments } from "../services/torrent/worker/piece-reader.js";
|
|
19
|
-
import { SharedPieceStore } from "../services/storage/piece-store/shared-piece-store.js";
|
|
20
|
-
|
|
21
|
-
const PIECE = 1024;
|
|
22
|
-
const TOTAL = 4 * PIECE;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A torrent of four pieces over a real store, whose `reside` can be made to
|
|
26
|
-
* answer "gone" for a chosen piece a chosen number of times — which is what the
|
|
27
|
-
* store does between dropping a piece and the swarm bringing it back.
|
|
28
|
-
*
|
|
29
|
-
* @param {{ emptyFor: number, times: number }} gap
|
|
30
|
-
*/
|
|
31
|
-
async function torrentWithAGap({ emptyFor, times }) {
|
|
32
|
-
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "withdrawal-read-"));
|
|
33
|
-
const store = new SharedPieceStore(PIECE, {
|
|
34
|
-
length: TOTAL,
|
|
35
|
-
memoryBytes: 64 * PIECE,
|
|
36
|
-
path: directory,
|
|
37
|
-
name: "test",
|
|
38
|
-
files: [{ offset: 0, length: TOTAL, name: "file.bin" }]
|
|
39
|
-
});
|
|
40
|
-
for (let index = 0; index < 4; index += 1) {
|
|
41
|
-
const piece = Buffer.alloc(PIECE);
|
|
42
|
-
for (let at = 0; at < PIECE; at += 1) {
|
|
43
|
-
piece[at] = (index * PIECE + at) % 251;
|
|
44
|
-
}
|
|
45
|
-
await new Promise((resolve, reject) => {
|
|
46
|
-
store.put(index, piece, (error) => (error ? reject(error) : resolve()));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const held = new Set([0, 1, 2, 3]);
|
|
51
|
-
let left = times;
|
|
52
|
-
/** How many times the piece was asked of the store at all. */
|
|
53
|
-
let asked = 0;
|
|
54
|
-
// The gap is injected at the one method that answers "can you produce this
|
|
55
|
-
// piece" — subclassed rather than wrapped, because `findSharedStore` walks
|
|
56
|
-
// the chain looking for the real class and would find the real one behind a
|
|
57
|
-
// facade.
|
|
58
|
-
store.reside = async function resideWithAGap(index) {
|
|
59
|
-
if (index !== emptyFor) {
|
|
60
|
-
return SharedPieceStore.prototype.reside.call(this, index);
|
|
61
|
-
}
|
|
62
|
-
asked += 1;
|
|
63
|
-
if (left > 0) {
|
|
64
|
-
left -= 1;
|
|
65
|
-
// THE CLAIM GOES WITH THE BYTES. That is what makes the wait a wait for a
|
|
66
|
-
// download and not a wait for nothing, and it is what the withdrawal now
|
|
67
|
-
// does in production.
|
|
68
|
-
held.delete(index);
|
|
69
|
-
// Back a moment later, as the swarm brings it: the reader's own wait ends
|
|
70
|
-
// on the torrent's `verified` event.
|
|
71
|
-
setImmediate(() => {
|
|
72
|
-
held.add(index);
|
|
73
|
-
torrent.emit("verified", index);
|
|
74
|
-
});
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
return SharedPieceStore.prototype.reside.call(this, index);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const torrent = Object.assign(new EventEmitter(), {
|
|
81
|
-
pieceLength: PIECE,
|
|
82
|
-
store,
|
|
83
|
-
bitfield: { get: (index) => held.has(index) },
|
|
84
|
-
files: [{ offset: 0, length: TOTAL, name: "file.bin" }],
|
|
85
|
-
select() {},
|
|
86
|
-
critical() {}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
torrent,
|
|
91
|
-
clean: async () => {
|
|
92
|
-
store.destroy(() => undefined);
|
|
93
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
94
|
-
},
|
|
95
|
-
asksFor: () => asked
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Read a range as the worker does. */
|
|
100
|
-
async function readRange(torrent, start, end) {
|
|
101
|
-
const collected = [];
|
|
102
|
-
for await (const fragment of readFragments({
|
|
103
|
-
torrent,
|
|
104
|
-
fileIndex: 0,
|
|
105
|
-
start,
|
|
106
|
-
end,
|
|
107
|
-
cancellation: { isCancelled: () => false }
|
|
108
|
-
})) {
|
|
109
|
-
const source = fragment.buffer
|
|
110
|
-
? Buffer.from(fragment.buffer, fragment.offset, fragment.length)
|
|
111
|
-
: Buffer.alloc(0);
|
|
112
|
-
collected.push(Buffer.from(source));
|
|
113
|
-
fragment.release();
|
|
114
|
-
}
|
|
115
|
-
return Buffer.concat(collected);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function expectedBytes(absoluteStart, length) {
|
|
119
|
-
const expected = Buffer.alloc(length);
|
|
120
|
-
for (let at = 0; at < length; at += 1) {
|
|
121
|
-
expected[at] = (absoluteStart + at) % 251;
|
|
122
|
-
}
|
|
123
|
-
return expected;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
test("a piece withdrawn once is asked for again and the read completes", async () => {
|
|
127
|
-
// Piece 0 is the case the field met: an encoder restart re-opens its input at
|
|
128
|
-
// byte 0, and byte 0 is behind every read head by then.
|
|
129
|
-
const { torrent, clean, asksFor } = await torrentWithAGap({ emptyFor: 0, times: 1 });
|
|
130
|
-
try {
|
|
131
|
-
const bytes = await readRange(torrent, 0, 2 * PIECE - 1);
|
|
132
|
-
assert.deepEqual(bytes, expectedBytes(0, 2 * PIECE), "the read returns the film, not an empty body");
|
|
133
|
-
assert.equal(asksFor(), 2, "the piece is asked for a second time, not given up on");
|
|
134
|
-
} finally {
|
|
135
|
-
await clean();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test("a piece that does not come back ends the read with a named error", async () => {
|
|
140
|
-
const { torrent, clean } = await torrentWithAGap({ emptyFor: 0, times: 5 });
|
|
141
|
-
try {
|
|
142
|
-
await assert.rejects(
|
|
143
|
-
() => readRange(torrent, 0, PIECE - 1),
|
|
144
|
-
// NOT "verified but absent": the claim has been withdrawn, so the honest
|
|
145
|
-
// statement is that the bytes did not come back.
|
|
146
|
-
/piece 0 was withdrawn from the store and did not come back/i,
|
|
147
|
-
"a second emptiness is a failure the caller must hear about"
|
|
148
|
-
);
|
|
149
|
-
} finally {
|
|
150
|
-
await clean();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("every piece of a long read gets its own second chance", async () => {
|
|
155
|
-
// The allowance is per piece: a read of many pieces may legitimately meet the
|
|
156
|
-
// gap more than once, and one exhausted allowance must not condemn the rest.
|
|
157
|
-
const { torrent, clean } = await torrentWithAGap({ emptyFor: 2, times: 1 });
|
|
158
|
-
try {
|
|
159
|
-
const bytes = await readRange(torrent, 0, 4 * PIECE - 1);
|
|
160
|
-
assert.deepEqual(bytes, expectedBytes(0, 4 * PIECE));
|
|
161
|
-
} finally {
|
|
162
|
-
await clean();
|
|
163
|
-
}
|
|
164
|
-
});
|