@torrent-tv/proxy 2.85.1 → 2.87.0
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 +2138 -1909
- package/CLAUDE.md +318 -197
- package/assets/calibration/NOTICE.md +2 -2
- package/bin/cli.js +684 -616
- package/biome.json +409 -233
- package/docs/container-architecture.md +218 -213
- package/docs/download-architecture.md +7 -7
- package/docs/encode-architecture.md +287 -11
- package/docs/encode-run-state.md +2 -2
- package/docs/logs.md +97 -97
- package/docs/{disk-architecture.md → storage-architecture.md} +107 -1
- package/openspec/changes/adaptive-bitrate/design.md +2 -2
- package/openspec/changes/adaptive-bitrate/proposal.md +1 -1
- package/openspec/changes/adaptive-bitrate/tasks.md +1 -1
- package/openspec/changes/chunked-request-bodies/design.md +1 -1
- package/openspec/changes/chunked-request-bodies/proposal.md +1 -1
- package/openspec/changes/chunked-request-bodies/tasks.md +1 -1
- package/openspec/changes/cold-start/design.md +1 -1
- package/openspec/changes/disk-cap/proposal.md +1 -1
- package/openspec/changes/proxy-observability/proposal.md +2 -2
- package/openspec/changes/track-selection/proposal.md +1 -1
- package/openspec/changes/transcode-quality/proposal.md +1 -1
- package/package.json +2 -2
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +329 -329
- package/research/double-spawn-2026-09-10.md +171 -171
- package/routes/api/playback-plan/post.js +2 -2
- package/routes/api/sources/files/get.js +1 -1
- package/routes/api/sources/stats/get.js +1 -1
- package/routes/api/sources/warm/post.js +10 -3
- package/routes/api/subtitles/get.js +230 -230
- package/routes/api/transcode-sessions/fragment-far/post.js +3 -3
- package/routes/api/transcode-sessions/net-report/post.js +129 -94
- package/routes/api/transcode-sessions/post.js +160 -139
- package/routes/api/transcode-sessions/progress/get.js +3 -3
- package/routes/api/transcode-sessions/release/post.js +3 -3
- package/routes/api/transcode-sessions/seek/post.js +12 -3
- package/routes/stream/get.js +2 -2
- package/routes/transcode/audio-file/get.js +15 -6
- package/routes/transcode/audio-warm/get.js +8 -5
- package/routes/transcode/session-file/get.js +429 -268
- package/routes/transcode/variant-file/get.js +47 -7
- package/routes/transcode/variant-warm/get.js +18 -6
- package/scripts/render-run-graph.js +1 -1
- package/server.js +720 -465
- package/services/encode/CoverageMap.js +428 -428
- package/services/encode/CushionReport.js +345 -0
- package/services/encode/EncodeAdmission.js +332 -0
- package/services/{orchestrators → encode}/EncodeOrchestrator.js +285 -17
- package/services/encode/EncodeRun.js +16 -9
- package/services/encode/EncodeRuns.js +1219 -0
- package/services/encode/Encoder.js +18 -2
- package/services/encode/EncoderSelection.js +38 -0
- package/services/encode/LocalObservations.js +359 -0
- package/services/encode/NvencEncoder.js +5 -0
- package/services/encode/OutputOpening.js +745 -0
- package/services/encode/OutputTimes.js +579 -0
- package/services/encode/Renditions.js +2162 -0
- package/services/encode/RunProgress.js +84 -0
- package/services/encode/SoftwareEncoder.js +12 -7
- package/services/encode/args.js +402 -186
- package/services/encode/calibration.js +361 -0
- package/services/encode/contention.js +128 -128
- package/services/encode/encode-run-state.js +16 -20
- package/services/encode/fingerprint.js +322 -0
- package/services/{hwaccel.js → encode/hwaccel.js} +82 -42
- package/services/{learned-median.js → encode/learned-median.js} +11 -0
- package/services/encode/output/EncodedOutput.js +57 -0
- package/services/encode/output/Output.js +131 -0
- package/services/{output/LiveOutputs.js → encode/output/OutputCatalog.js} +141 -40
- package/services/encode/output/OutputSpec.js +390 -0
- package/services/{output → encode/output}/Timeline.js +12 -37
- package/services/encode/output/index.js +20 -0
- package/services/encode/output/ladder.js +32 -0
- package/services/{output → encode/output}/playlists.js +3 -0
- package/services/encode/output-key-format.js +21 -0
- package/services/encode/quality/EncodeCost.js +1083 -0
- package/services/encode/quality/HostLoad.js +525 -0
- package/services/encode/quality/HostTimings.js +249 -0
- package/services/encode/quality/OutputQualityState.js +28 -0
- package/services/encode/quality/QualityController.js +931 -0
- package/services/encode/quality/QualityOffer.js +416 -0
- package/services/encode/quality/drain-threat.js +47 -0
- package/services/encode/quality/link-budget.js +254 -0
- package/services/encode/quality/output-format.js +266 -0
- package/services/encode/quality/serving-output.js +216 -0
- package/services/encode/quality/visible-rung.js +57 -0
- package/services/encode/run-command.js +23 -20
- package/services/encode/run-inputs.js +42 -0
- package/services/{segment-formats → encode/segment-formats}/fmp4.js +63 -0
- package/services/{segment-formats → encode/segment-formats}/index.js +3 -3
- package/services/encode/segment-formats/init-compat.js +324 -0
- package/services/{segment-formats → encode/segment-formats}/mp4-boxes.js +8 -3
- package/services/encode/throughput.js +97 -0
- package/services/{orchestrators → media}/ContainerOrchestrator.js +45 -7
- package/services/media/KeyframeTables.js +316 -0
- package/services/{source → media}/SourceFile.js +7 -55
- package/services/{torrent-worker/subtitle-cues.js → media/SubtitleCues.js} +103 -132
- package/services/media/SubtitleOrchestrator.js +167 -0
- package/services/{audio-inventory.js → media/audio-inventory.js} +7 -1
- package/services/{container → media/container}/AviContainer.js +266 -266
- package/services/{container → media/container}/Container.js +596 -601
- package/services/media/container/ContainerFactory.js +56 -0
- package/services/media/container/KeyframeTable.js +272 -0
- package/services/{container → media/container}/MatroskaContainer.js +1485 -1485
- package/services/{container → media/container}/Mp4Container.js +1244 -1244
- package/services/{container → media/container}/SubtitleFileContainer.js +322 -322
- package/services/media/keyframe-probe.js +157 -0
- package/services/media/media-info-probe.js +93 -0
- package/services/{playback-planner.js → media/playback-planner.js} +82 -39
- package/services/{tracks → media/tracks}/AudioTrack.js +131 -131
- package/services/{tracks → media/tracks}/language-detect.js +174 -174
- package/services/server/OutputLifecycle.js +418 -0
- package/services/server/SegmentServing.js +1146 -0
- package/services/server/ViewerRequests.js +522 -0
- package/services/server/controllers/PlaybackController.js +36 -0
- package/services/{controllers → server/controllers}/SubtitleController.js +17 -33
- package/services/server/wire-outputs.js +958 -0
- package/services/storage/Diagnostics.js +202 -0
- package/services/storage/MachineBudget.js +235 -0
- package/services/{piece-store → storage}/allowance.js +107 -107
- package/services/{core-dumps.js → storage/core-dumps.js} +1 -1
- package/services/{files → storage/files}/CompletedFiles.js +116 -1
- package/services/{disk → storage}/free.js +33 -0
- package/services/storage/machine-memory.js +56 -0
- package/services/{memory-report.js → storage/memory-report.js} +575 -596
- package/services/{piece-store → storage/piece-store}/piece-disk-store.js +0 -7
- package/services/{piece-store → storage/piece-store}/shared-piece-store.js +28 -21
- package/services/{encode → storage/segment-store}/SegmentStore.js +395 -8
- package/services/storage/wire.js +175 -0
- package/services/{download → torrent/download}/SwarmSelection.js +2 -2
- package/services/{download → torrent/download}/registry.js +2 -2
- package/services/torrent/files.js +1 -1
- package/services/torrent/piece-store-of.js +29 -0
- package/services/{torrent-pool.js → torrent/torrent-pool.js} +26 -119
- package/services/{torrent-worker → torrent/worker}/background-fill.js +2 -2
- package/services/{torrent-worker → torrent/worker}/channel.js +271 -250
- package/services/{torrent-worker → torrent/worker}/client.js +77 -58
- package/services/torrent/worker/held-bytes.js +155 -0
- package/services/{torrent-worker → torrent/worker}/install-webrtc-shim.js +1 -1
- package/services/{torrent-worker → torrent/worker}/piece-reader.js +21 -30
- package/services/{torrent-worker → torrent/worker}/pool-adapter.js +101 -137
- package/services/{torrent-worker → torrent/worker}/protocol.js +26 -30
- package/services/torrent/worker/resume-warm.js +107 -0
- package/services/{torrent-worker → torrent/worker}/webrtc-shim.js +2 -2
- package/services/{torrent-worker → torrent/worker}/worker.js +68 -159
- package/services/{data-channel-handler.js → transport/data-channel-handler.js} +1356 -1356
- package/services/{delivery-probe.js → transport/delivery-probe.js} +842 -842
- package/services/{health-collector.js → transport/health-collector.js} +6 -35
- package/services/{packet-witness.js → transport/packet-witness.js} +808 -784
- package/services/{port-mapper.js → transport/port-mapper.js} +1 -1
- package/services/{usrsctp-state.js → transport/usrsctp-state.js} +1 -1
- package/services/{webrtc-manager.js → transport/webrtc-manager.js} +1 -1
- package/services/viewer/Assignments.js +340 -0
- package/services/{priority → viewer}/PriorityMap.js +390 -390
- package/services/{priority → viewer}/PriorityOrchestrator.js +325 -320
- package/services/viewer/Viewer.js +657 -489
- package/services/viewer/Viewers.js +368 -257
- package/services/viewer/active-output.js +37 -54
- package/services/viewer/audio-start.js +46 -0
- package/services/viewer/buffer-trend.js +81 -0
- package/services/viewer/choices.js +647 -0
- package/services/viewer/positions.js +126 -120
- package/services/viewer/report-intake.js +46 -44
- package/test/asset-paths.test.js +28 -0
- package/test/audio-inventory.test.js +3 -3
- package/test/audio-track-bitrate.test.js +40 -0
- package/test/auto-quality-step.test.js +707 -518
- package/test/available-share.test.js +1 -1
- package/test/background-fill.test.js +1 -1
- package/test/client-log-file.test.js +110 -110
- package/test/completed-files.test.js +1 -1
- package/test/concurrent-cost.test.js +13 -3
- package/test/container-media-info.test.js +3 -3
- package/test/core-dumps.test.js +1 -1
- package/test/coverage-follows-the-disk.test.js +40 -8
- package/test/cue-push-carries-what-the-walk-found.test.js +58 -0
- package/test/cut-times-timeline.test.js +2 -2
- package/test/cuts-follow-published-grid.test.js +9 -8
- package/test/data-channel-frame.test.js +1 -1
- package/test/dead-torrent-handle.test.js +1 -1
- package/test/declared-rates.test.js +2 -2
- package/test/declared-tracks.test.js +2 -2
- package/test/decode-cost-fit.test.js +1 -1
- package/test/decode-cost.test.js +34 -25
- package/test/delivery-probe.test.js +1 -1
- package/test/demand-register.test.js +4 -4
- package/test/dht-bootstrap.test.js +1 -1
- package/test/drain-threat.test.js +65 -0
- package/test/duplicate-add.test.js +1 -1
- package/test/encode-admission.test.js +146 -0
- package/test/encode-cost.test.js +199 -10
- package/test/encode-orchestrator.test.js +39 -1
- package/test/encode-plan-viewers.test.js +2 -2
- package/test/encode-run.test.js +2 -2
- package/test/encode-slope.test.js +1 -1
- package/test/encoded-output.test.js +39 -0
- package/test/encoder-readings.test.js +1 -1
- package/test/every-claimant-is-told-its-share.test.js +152 -0
- package/test/failed-encoder-still-serves-what-exists.test.js +354 -0
- package/test/failed-start-breaker.test.js +81 -30
- package/test/fastest-wires.test.js +1 -1
- package/test/ffmpeg-stream-counts.test.js +1 -1
- package/test/file-edges.test.js +3 -3
- package/test/fmp4-self-contained.test.js +1 -1
- package/test/fmp4-timestamps.test.js +1 -1
- package/test/fmp4-track-completeness.test.js +1 -1
- package/test/format-keyed-outputs.test.js +78 -0
- package/test/health-metrics.test.js +3 -2
- package/test/held-request-width.test.js +22 -23
- package/test/helpers/encode-run.js +136 -136
- package/test/helpers/held-file.js +29 -0
- package/test/helpers/manager.js +57 -0
- package/test/helpers/output-spec.js +63 -0
- package/test/host-load.test.js +1 -1
- package/test/index-accuracy-is-about-the-file.test.js +128 -0
- package/test/init-compat.test.js +219 -0
- package/test/input-lost-quiets-the-plan.test.js +1 -1
- package/test/input-unavailable.test.js +1 -1
- package/test/keeping-period.test.js +4 -4
- package/test/keyframe-index-accuracy.test.js +97 -45
- package/test/keyframe-table-budget.test.js +28 -33
- package/test/keyframes-belong-to-the-file.test.js +174 -57
- package/test/learned-median.test.js +1 -1
- package/test/letting-go-asks-who-is-watching.test.js +191 -0
- package/test/limit-row-by-area.test.js +60 -0
- package/test/link-budget.test.js +111 -0
- package/test/link-probe.test.js +56 -56
- package/test/local-encoding-data.test.js +273 -0
- package/test/look-ahead-coverage.test.js +1 -1
- package/test/manager-surface.test.js +294 -0
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cues-track.test.js +1 -1
- package/test/memory-budget.test.js +2 -2
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +1 -1
- package/test/one-authority.test.js +45 -41
- package/test/one-budget.test.js +149 -0
- package/test/one-output-one-session.test.js +204 -0
- package/test/{disk-space.test.js → one-resource-divided.test.js} +30 -10
- package/test/one-serving-output-per-height.test.js +458 -0
- package/test/orchestrator-wired.test.js +46 -45
- package/test/output-catalog.test.js +39 -0
- package/test/output-shape.test.js +4 -51
- package/test/output-spec.test.js +251 -157
- package/test/output-speed.test.js +17 -15
- package/test/outputs-being-prepared.test.js +40 -0
- package/test/packet-witness-ring.test.js +2 -2
- package/test/packet-witness.test.js +1 -1
- package/test/piece-disk-store.test.js +2 -2
- package/test/piece-from-whole-file.test.js +1 -1
- package/test/piece-lru.test.js +1 -1
- package/test/piece-reader.test.js +2 -2
- package/test/piece-store-eviction.test.js +1 -1
- package/test/piece-store-never-refuses.test.js +1 -1
- package/test/piece-store-reservations.test.js +1 -1
- package/test/piece-store-slow-disk.test.js +1 -1
- package/test/piece-tail.test.js +1 -1
- package/test/plan-host-timings.test.js +1 -1
- package/test/plan-is-steady.test.js +225 -225
- package/test/priority-map-download.test.js +4 -4
- package/test/priority-map-emptied.test.js +204 -205
- package/test/priority-map-per-output.test.js +215 -209
- package/test/priority-map.test.js +1 -1
- package/test/probe-wedge-certainty.test.js +1 -1
- package/test/produced-copy-choice.test.js +15 -60
- package/test/quality-offer.test.js +162 -0
- package/test/quality-variants.test.js +1229 -1167
- package/test/rate-control-in-the-output.test.js +180 -0
- package/test/read-survives-withdrawal.test.js +2 -2
- package/test/read-window.test.js +10 -3
- package/test/resume-warm.test.js +1 -1
- package/test/run-inputs.test.js +80 -0
- package/test/run-position-follows-published-grid.test.js +13 -11
- package/test/run-progress.test.js +65 -0
- package/test/same-height-switch.test.js +664 -0
- package/test/seek-frees-the-viewers-requests.test.js +217 -0
- package/test/seek-landing.test.js +13 -13
- package/test/seek-target-not-superseded.test.js +28 -29
- package/test/segment-closed-on-both-branches.test.js +96 -0
- package/test/segment-cut-times.test.js +1 -1
- package/test/segment-hold-supersede.test.js +28 -35
- package/test/segment-judged-by-its-own-header.test.js +221 -0
- package/test/segment-serve-wiring.test.js +130 -39
- package/test/segment-store-eviction.test.js +22 -7
- package/test/segment-store.test.js +98 -14
- package/test/segment-true-start.test.js +1 -1
- package/test/segments-are-shared.test.js +17 -16
- package/test/send-chunk-bytes.test.js +1 -1
- package/test/serving-existing-output.test.js +102 -0
- package/test/serving-output.test.js +102 -0
- package/test/shared-piece-store.test.js +1 -1
- package/test/source-file.test.js +1 -1
- package/test/stale-request-after-seek.test.js +17 -21
- package/test/startup-readings.test.js +10 -5
- package/test/subtitle-cue-framing.test.js +5 -5
- package/test/subtitle-cue-source.test.js +36 -38
- package/test/subtitle-cue-walk.test.js +11 -10
- package/test/subtitle-defaults.test.js +1 -1
- package/test/subtitle-language.test.js +4 -4
- package/test/subtitle-track-numbering.test.js +5 -4
- package/test/supply-margin.test.js +1 -1
- package/test/swarm-follows-readers.test.js +3 -3
- package/test/swarm-reach.test.js +1 -1
- package/test/swarm-selection.test.js +3 -3
- package/test/tail-duplication.test.js +1 -1
- package/test/the-channel-has-both-ends.test.js +91 -0
- package/test/the-torrent-thread-serves-bytes.test.js +107 -0
- package/test/thread-pool.test.js +3 -3
- package/test/timeline.test.js +1 -12
- package/test/torrent-cost.test.js +1 -1
- package/test/tracks-begin-together.test.js +38 -24
- package/test/tunnel-renewal.test.js +1 -1
- package/test/two-viewers-one-picture.test.js +120 -87
- package/test/upload-hurry.test.js +3 -3
- package/test/usrsctp-state.test.js +1 -1
- package/test/video-facts.test.js +1 -1
- package/test/viewer-assignments.test.js +143 -0
- package/test/viewer-outputs.test.js +60 -52
- package/test/viewer-presence.test.js +22 -25
- package/test/viewer-requests-admission.test.js +89 -0
- package/test/viewer-states.test.js +189 -172
- package/test/viewer-subtitle-subscription.test.js +1 -1
- package/test/viewer.test.js +139 -136
- package/test/viewing-generations.test.js +390 -0
- package/test/visible-rung.test.js +37 -0
- package/test/wait-ledger.test.js +1 -1
- package/test/webrtc-shim.test.js +3 -3
- package/test/wedge-certainty.test.js +2 -2
- package/test/withdraw-piece-claim.test.js +2 -2
- package/test/worker-channel.test.js +1 -31
- package/utils/client-log-file.js +151 -151
- package/scripts/read-container-index.mjs +0 -108
- package/services/container/ContainerFactory.js +0 -122
- package/services/controllers/PlaybackController.js +0 -33
- package/services/disk/DiskSpace.js +0 -150
- package/services/disk/wire.js +0 -61
- package/services/hls-session-manager.js +0 -9689
- package/services/orchestrators/SubtitleOrchestrator.js +0 -160
- package/services/output/Output.js +0 -94
- package/services/output/OutputSpec.js +0 -202
- package/services/output/index.js +0 -1
- package/services/output/ladder.js +0 -26
- package/services/produced-index.js +0 -222
- package/services/quality/EncodeCost.js +0 -555
- package/services/torrent-worker/container-tracks.js +0 -414
- package/test/produced-index.test.js +0 -142
- /package/{services → bin}/thread-pool.js +0 -0
- /package/services/{available-share.js → encode/available-share.js} +0 -0
- /package/services/{decode-cost-fit.js → encode/decode-cost-fit.js} +0 -0
- /package/services/{encoder-readings.js → encode/encoder-readings.js} +0 -0
- /package/services/{host-load.js → encode/host-load.js} +0 -0
- /package/services/{output → encode/output}/cut-grid.js +0 -0
- /package/services/{output → encode/output}/rates.js +0 -0
- /package/services/{segment-formats → encode/segment-formats}/mpegts.js +0 -0
- /package/services/{torrent-cost.js → encode/torrent-cost.js} +0 -0
- /package/services/{container → media/container}/ebml-reader.js +0 -0
- /package/services/{ffmpeg-banner.js → media/ffmpeg-banner.js} +0 -0
- /package/services/{tracks → media/tracks}/ContainerTrack.js +0 -0
- /package/services/{tracks → media/tracks}/ImageSubtitleTrack.js +0 -0
- /package/services/{tracks → media/tracks}/SubtitleTrack.js +0 -0
- /package/services/{tracks → media/tracks}/TextSubtitleTrack.js +0 -0
- /package/services/{tracks → media/tracks}/VideoTrack.js +0 -0
- /package/services/{tracks → media/tracks}/index.js +0 -0
- /package/services/{files → storage/files}/piece-from-whole-file.js +0 -0
- /package/services/{disk → storage}/keep.js +0 -0
- /package/services/{piece-store → storage/piece-store}/piece-lru.js +0 -0
- /package/services/{disk → storage}/returns.js +0 -0
- /package/services/{demand → torrent/demand}/DemandRegister.js +0 -0
- /package/services/{demand → torrent/demand}/Urgency.js +0 -0
- /package/services/{demand → torrent/demand}/Window.js +0 -0
- /package/services/{demand → torrent/demand}/index.js +0 -0
- /package/services/{demand → torrent/demand}/pieces.js +0 -0
- /package/services/{download → torrent/download}/withdraw-claim.js +0 -0
- /package/services/{supply-margin.js → torrent/supply-margin.js} +0 -0
- /package/services/{torrent-source-key.js → torrent/torrent-source-key.js} +0 -0
- /package/services/{torrent-worker → torrent/worker}/fastest-wires.js +0 -0
- /package/services/{torrent-worker → torrent/worker}/handle-state.js +0 -0
- /package/services/{nat-classifier.js → transport/nat-classifier.js} +0 -0
- /package/services/{registry-api.js → transport/registry-api.js} +0 -0
- /package/services/{tunnel-client.js → transport/tunnel-client.js} +0 -0
- /package/services/{priority → viewer}/WaitLedger.js +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { OutputCatalog } from "../services/encode/output/OutputCatalog.js";
|
|
4
|
+
|
|
5
|
+
test("the catalog owns creation and access times", () => {
|
|
6
|
+
let now = 100;
|
|
7
|
+
const registry = new OutputCatalog({ now: () => now });
|
|
8
|
+
const output = { id: "picture" };
|
|
9
|
+
registry.set(output.id, output);
|
|
10
|
+
|
|
11
|
+
now = 250;
|
|
12
|
+
registry.touch(output);
|
|
13
|
+
|
|
14
|
+
assert.equal(registry.startedAt(output), 100);
|
|
15
|
+
assert.equal(registry.lastAccessedAt(output), 250);
|
|
16
|
+
assert.equal("startedAt" in output, false);
|
|
17
|
+
assert.equal("lastAccessedAt" in output, false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("expiry is decided from the catalog's access time", () => {
|
|
21
|
+
let now = 100;
|
|
22
|
+
const registry = new OutputCatalog({ now: () => now });
|
|
23
|
+
registry.set("old", { id: "old" });
|
|
24
|
+
now = 200;
|
|
25
|
+
registry.set("fresh", { id: "fresh" });
|
|
26
|
+
|
|
27
|
+
assert.deepEqual(registry.expiredBefore(150), ["old"]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("removal deletes both the output and its lifetime", () => {
|
|
31
|
+
const registry = new OutputCatalog({ now: () => 100 });
|
|
32
|
+
const output = { id: "picture" };
|
|
33
|
+
registry.set(output.id, output);
|
|
34
|
+
registry.delete(output.id);
|
|
35
|
+
|
|
36
|
+
assert.equal(registry.get(output.id), undefined);
|
|
37
|
+
assert.equal(registry.startedAt(output), null);
|
|
38
|
+
assert.equal(registry.touch(output, 200), false);
|
|
39
|
+
});
|
|
@@ -1,51 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file The shape an encoder is given for an output.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
* sessions of one output made minutes apart could be given different pictures
|
|
7
|
-
* while claiming the same identity — and everything downstream assumes they
|
|
8
|
-
* cannot be, from a segment of one standing in for a segment of the other to
|
|
9
|
-
* the single RESOLUTION the master names for both.
|
|
4
|
+
* The format itself is the output's identity (`OutputSpec`), decided before
|
|
5
|
+
* the output is named; this is that format in the terms the encoder takes.
|
|
10
6
|
*/
|
|
11
7
|
|
|
12
8
|
import test from "node:test";
|
|
13
9
|
import assert from "node:assert/strict";
|
|
14
|
-
import { Output
|
|
15
|
-
|
|
16
|
-
const KEY = "torrent:abc:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:auto";
|
|
17
|
-
|
|
18
|
-
test("the second session of one output is given the shape the first was", () => {
|
|
19
|
-
const outputs = new Outputs();
|
|
20
|
-
const first = outputs.get(KEY, () => new Output({
|
|
21
|
-
encodeWidth: 1280,
|
|
22
|
-
encodeHeight: 720,
|
|
23
|
-
outputFps: 24,
|
|
24
|
-
softwarePreset: "veryfast",
|
|
25
|
-
applyTonemap: false
|
|
26
|
-
}));
|
|
27
|
-
// A minute later the machine is busier and the budget would answer 480p. It
|
|
28
|
-
// is not asked: the shape of this output was settled when it was first made.
|
|
29
|
-
const second = outputs.get(KEY, () => {
|
|
30
|
-
throw new Error("deciding twice is how two sessions of one output diverge");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
assert.equal(second, first);
|
|
34
|
-
assert.equal(second.encodeHeight, 720);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("two outputs are two shapes", () => {
|
|
38
|
-
const outputs = new Outputs();
|
|
39
|
-
const tall = outputs.get(KEY, () => new Output({ encodeWidth: 1280, encodeHeight: 720, outputFps: 24 }));
|
|
40
|
-
const short = outputs.get(`${KEY}:other`, () => new Output({
|
|
41
|
-
encodeWidth: 854,
|
|
42
|
-
encodeHeight: 480,
|
|
43
|
-
outputFps: 24
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
assert.notEqual(short, tall);
|
|
47
|
-
assert.equal(short.encodeHeight, 480);
|
|
48
|
-
});
|
|
10
|
+
import { Output } from "../services/encode/output/Output.js";
|
|
49
11
|
|
|
50
12
|
test("a copied picture has no box of its own, and says so with zeroes", () => {
|
|
51
13
|
// Zero means the source's own size, which is what a copy is by definition:
|
|
@@ -57,12 +19,3 @@ test("a copied picture has no box of its own, and says so with zeroes", () => {
|
|
|
57
19
|
assert.equal(copied.softwarePreset, null, "and no speed setting, having no encoder");
|
|
58
20
|
});
|
|
59
21
|
|
|
60
|
-
test("a shape nobody holds is dropped", () => {
|
|
61
|
-
const outputs = new Outputs();
|
|
62
|
-
const kept = outputs.get(KEY, () => new Output({ encodeWidth: 1280, encodeHeight: 720, outputFps: 24 }));
|
|
63
|
-
outputs.get(`${KEY}:other`, () => new Output({ encodeWidth: 854, encodeHeight: 480, outputFps: 24 }));
|
|
64
|
-
|
|
65
|
-
assert.equal(outputs.size, 2);
|
|
66
|
-
assert.equal(outputs.forgetUnused(new Set([kept])), 1);
|
|
67
|
-
assert.equal(outputs.size, 1);
|
|
68
|
-
});
|
package/test/output-spec.test.js
CHANGED
|
@@ -1,157 +1,251 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
assert.notEqual(
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
audio: new AudioOutput({ fileIndex:
|
|
126
|
-
});
|
|
127
|
-
assert.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
audio: new AudioOutput({ fileIndex:
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
);
|
|
157
|
-
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { softwareRateControlFor } from "../services/encode/args.js";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { AudioOutput, CutGrid, isOutputName, OutputSpec, VideoOutput } from "../services/encode/output/OutputSpec.js";
|
|
6
|
+
|
|
7
|
+
const TORRENT = "torrent:11f0929918e2b5aa2e5b71ecdbe5c0f1a4bbf7d1";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The picture of a file, copied, cut at that file's own keyframes.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} [over]
|
|
13
|
+
* @returns {OutputSpec}
|
|
14
|
+
*/
|
|
15
|
+
function copiedPicture(over = {}) {
|
|
16
|
+
return new OutputSpec({
|
|
17
|
+
sourceKey: TORRENT,
|
|
18
|
+
segmentFormatId: "fmp4",
|
|
19
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
20
|
+
video: new VideoOutput({ fileIndex: 0, encode: null }),
|
|
21
|
+
audio: null,
|
|
22
|
+
...over
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test("two viewers who chose different soundtracks share one copied picture", () => {
|
|
27
|
+
// The measurement of 2026-09-03: both sessions described the same thing word
|
|
28
|
+
// for word and answered `segment-00000.mp4` with the same 4141899 bytes. The
|
|
29
|
+
// soundtrack they picked is not a property of a picture that carries no
|
|
30
|
+
// sound, so it cannot tell the two apart.
|
|
31
|
+
assert.equal(copiedPicture().toKey(), copiedPicture().toKey());
|
|
32
|
+
assert.equal(copiedPicture().carries, "video-only");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("the viewer's viewport does not fork a picture that is copied", () => {
|
|
36
|
+
// A copy is the source's own size whatever box was asked for, so there is
|
|
37
|
+
// nowhere for a target to appear in the key.
|
|
38
|
+
const key = copiedPicture().toKey();
|
|
39
|
+
assert.ok(!key.includes("x"), `a copied picture states no box: ${key}`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function encoded(over = {}) {
|
|
43
|
+
return copiedPicture({
|
|
44
|
+
video: new VideoOutput({
|
|
45
|
+
fileIndex: 0,
|
|
46
|
+
encode: { encoder: "libx264", width: 1280, height: 720, fps: 24, preset: "veryfast", tonemap: false, ...over }
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
test("two heights of one picture are two outputs", () => {
|
|
52
|
+
assert.notEqual(encoded().toKey(), encoded({ width: 854, height: 480 }).toKey());
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("an output is the format produced, and every part of it that reaches the header tells two apart", () => {
|
|
56
|
+
const base = encoded().toKey();
|
|
57
|
+
assert.notEqual(base, encoded({ preset: "ultrafast" }).toKey(), "the speed setting changes the PPS");
|
|
58
|
+
assert.notEqual(base, encoded({ encoder: "h264_nvenc" }).toKey(), "another encoder writes another SPS");
|
|
59
|
+
assert.notEqual(base, encoded({ fps: 30 }).toKey(), "the frame rate");
|
|
60
|
+
assert.notEqual(base, encoded({ tonemap: true }).toKey(), "a tone-mapped picture");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("how the format was asked for is not part of it", () => {
|
|
64
|
+
const asked = new VideoOutput({
|
|
65
|
+
fileIndex: 0,
|
|
66
|
+
encode: { encoder: "libx264", width: 1280, height: 720, fps: 24, preset: "veryfast", tonemap: false, exactSize: true }
|
|
67
|
+
});
|
|
68
|
+
assert.equal(copiedPicture({ video: asked }).toKey(), encoded().toKey());
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("a key reads back into the output it names", () => {
|
|
72
|
+
const muxed = new OutputSpec({
|
|
73
|
+
sourceKey: TORRENT,
|
|
74
|
+
segmentFormatId: "mpegts",
|
|
75
|
+
grid: new CutGrid({ kind: "uniform", fileIndex: 2 }),
|
|
76
|
+
video: new VideoOutput({
|
|
77
|
+
fileIndex: 2,
|
|
78
|
+
encode: { encoder: "libx264", width: 854, height: 480, fps: 25, preset: null, tonemap: true }
|
|
79
|
+
}),
|
|
80
|
+
audio: new AudioOutput({ fileIndex: 5, trackIndex: 1, transcode: true })
|
|
81
|
+
});
|
|
82
|
+
for (const spec of [copiedPicture(), encoded(), muxed]) {
|
|
83
|
+
assert.equal(OutputSpec.fromKey(spec.toKey())?.toKey(), spec.toKey());
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a key naming the box a viewer asked for does not read back, because it cannot say what format is inside", () => {
|
|
88
|
+
assert.equal(OutputSpec.fromKey(`${TORRENT}:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:exact`), null);
|
|
89
|
+
assert.equal(OutputSpec.fromKey(`${TORRENT}:fmt=fmp4:grid=even@0:video-only:v=0/enc:1280x720:budget`), null);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("the bitrate limit is part of the output: two limits are two outputs, and the key reads back", () => {
|
|
93
|
+
// Roadmap item 97, step 10. A limit changes the bytes of every piece, so it
|
|
94
|
+
// names the output; the level is the nominal output's, so it is the same for
|
|
95
|
+
// both limits of one size and their headers agree.
|
|
96
|
+
const nominal = softwareRateControlFor({ width: 1280, height: 720, fps: 24 });
|
|
97
|
+
const lower = softwareRateControlFor({ width: 1280, height: 720, fps: 24, capKbps: 1400 });
|
|
98
|
+
const atNominal = encoded({ rateControl: nominal });
|
|
99
|
+
const atLower = encoded({ rateControl: lower });
|
|
100
|
+
|
|
101
|
+
assert.notEqual(atNominal.toKey(), atLower.toKey());
|
|
102
|
+
assert.notEqual(atNominal.toKey(), encoded().toKey(), "a limit and none are two outputs too");
|
|
103
|
+
assert.equal(nominal.level, lower.level);
|
|
104
|
+
for (const spec of [atNominal, atLower, encoded()]) {
|
|
105
|
+
assert.equal(OutputSpec.fromKey(spec.toKey())?.toKey(), spec.toKey());
|
|
106
|
+
}
|
|
107
|
+
assert.deepEqual(OutputSpec.fromKey(atLower.toKey()).video.encode.rateControl, lower);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a key written before the limit was part of it does not read back", () => {
|
|
111
|
+
// Its directory could hold pieces made under any limit the budget had moved
|
|
112
|
+
// it to, so nothing can say what is inside, and it is not served.
|
|
113
|
+
const current = encoded().toKey();
|
|
114
|
+
assert.equal(OutputSpec.fromKey(current.replace("/vbv=-", "")), null);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a soundtrack is named by the file it lives in and the track inside it", () => {
|
|
118
|
+
// Not by the flat number the browser sends: that number spans the picture's
|
|
119
|
+
// own tracks and the files beside it, so it means different things for
|
|
120
|
+
// different pictures of one torrent.
|
|
121
|
+
const dub = new OutputSpec({
|
|
122
|
+
sourceKey: TORRENT,
|
|
123
|
+
segmentFormatId: "fmp4",
|
|
124
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
125
|
+
audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
|
|
126
|
+
});
|
|
127
|
+
assert.equal(dub.carries, "audio-only");
|
|
128
|
+
assert.ok(dub.toKey().includes("a=7/0/aac"), dub.toKey());
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("one soundtrack cut for two different pictures is two outputs", () => {
|
|
132
|
+
// The grid of a soundtrack is the picture's, so a rendition made for episode
|
|
133
|
+
// one cannot stand in for one made for episode two even when the dub is the
|
|
134
|
+
// same file.
|
|
135
|
+
const forFirst = new OutputSpec({
|
|
136
|
+
sourceKey: TORRENT,
|
|
137
|
+
segmentFormatId: "fmp4",
|
|
138
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
139
|
+
audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
|
|
140
|
+
});
|
|
141
|
+
const forSecond = new OutputSpec({
|
|
142
|
+
sourceKey: TORRENT,
|
|
143
|
+
segmentFormatId: "fmp4",
|
|
144
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 1 }),
|
|
145
|
+
audio: new AudioOutput({ fileIndex: 7, trackIndex: 0, transcode: true })
|
|
146
|
+
});
|
|
147
|
+
assert.notEqual(forFirst.toKey(), forSecond.toKey());
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("a copied soundtrack and a re-encoded one are two outputs", () => {
|
|
151
|
+
const copied = new OutputSpec({
|
|
152
|
+
sourceKey: TORRENT,
|
|
153
|
+
segmentFormatId: "fmp4",
|
|
154
|
+
grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
|
|
155
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: false })
|
|
156
|
+
});
|
|
157
|
+
const encoded = new OutputSpec({
|
|
158
|
+
sourceKey: TORRENT,
|
|
159
|
+
segmentFormatId: "fmp4",
|
|
160
|
+
grid: new CutGrid({ kind: "uniform", fileIndex: 0 }),
|
|
161
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 1, transcode: true })
|
|
162
|
+
});
|
|
163
|
+
assert.notEqual(copied.toKey(), encoded.toKey());
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("a browser without rendition groups gets an output carrying both tracks", () => {
|
|
167
|
+
const muxed = new OutputSpec({
|
|
168
|
+
sourceKey: TORRENT,
|
|
169
|
+
segmentFormatId: "mpegts",
|
|
170
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
171
|
+
video: new VideoOutput({ fileIndex: 0, encode: null }),
|
|
172
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 2, transcode: true })
|
|
173
|
+
});
|
|
174
|
+
assert.equal(muxed.carries, "muxed");
|
|
175
|
+
// And there the soundtrack DOES tell two of them apart, because the output
|
|
176
|
+
// really carries it.
|
|
177
|
+
const other = new OutputSpec({
|
|
178
|
+
sourceKey: TORRENT,
|
|
179
|
+
segmentFormatId: "mpegts",
|
|
180
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
181
|
+
video: new VideoOutput({ fileIndex: 0, encode: null }),
|
|
182
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 3, transcode: true })
|
|
183
|
+
});
|
|
184
|
+
assert.notEqual(muxed.toKey(), other.toKey());
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("the picture, its soundtrack and the two of them muxed are three outputs", () => {
|
|
188
|
+
const video = copiedPicture();
|
|
189
|
+
const audio = new OutputSpec({
|
|
190
|
+
sourceKey: TORRENT,
|
|
191
|
+
segmentFormatId: "fmp4",
|
|
192
|
+
grid: new CutGrid({ kind: "keyframe", fileIndex: 0 }),
|
|
193
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
|
|
194
|
+
});
|
|
195
|
+
const muxed = copiedPicture({
|
|
196
|
+
audio: new AudioOutput({ fileIndex: 0, trackIndex: 0, transcode: true })
|
|
197
|
+
});
|
|
198
|
+
assert.equal(new Set([video.toKey(), audio.toKey(), muxed.toKey()]).size, 3);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("two containers of the same tracks are two outputs", () => {
|
|
202
|
+
assert.notEqual(copiedPicture().toKey(), copiedPicture({ segmentFormatId: "mpegts" }).toKey());
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("the same tracks of two different torrents are two outputs", () => {
|
|
206
|
+
assert.notEqual(copiedPicture().toKey(), copiedPicture({ sourceKey: "torrent:0000" }).toKey());
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("a picture cut at keyframes and the same picture cut on the even grid are two outputs", () => {
|
|
210
|
+
assert.notEqual(
|
|
211
|
+
copiedPicture().toKey(),
|
|
212
|
+
copiedPicture({ grid: new CutGrid({ kind: "uniform", fileIndex: 0 }) }).toKey()
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("an output's name follows from its identity and from nothing else", () => {
|
|
217
|
+
// MANY VIEWERS OF ONE OUTPUT address one name because the name is the
|
|
218
|
+
// output's. Nobody arranges it, and nothing about the request enters it: two
|
|
219
|
+
// people opening the same film at different moments and at different places
|
|
220
|
+
// are handed the same name.
|
|
221
|
+
assert.equal(copiedPicture().toName(), copiedPicture().toName());
|
|
222
|
+
assert.notEqual(
|
|
223
|
+
copiedPicture().toName(),
|
|
224
|
+
copiedPicture({ video: new VideoOutput({ fileIndex: 1, encode: null }) }).toName(),
|
|
225
|
+
"and two different outputs are two different names"
|
|
226
|
+
);
|
|
227
|
+
// Stated against the key itself, which is the one thing that proves nothing
|
|
228
|
+
// ELSE got mixed in. Two specs built in one test run agree even if the name
|
|
229
|
+
// secretly carried the clock, because the clock has not moved between them —
|
|
230
|
+
// and "however far apart they arrive" is the whole property.
|
|
231
|
+
assert.equal(
|
|
232
|
+
copiedPicture().toName(),
|
|
233
|
+
createHash("sha256").update(copiedPicture().toKey()).digest("hex").slice(0, 16)
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test("a name is safe to carry whole, and the guard that admits it agrees", () => {
|
|
238
|
+
// The name reaches the filesystem: it is what the produced pieces of this
|
|
239
|
+
// output are found under. So the shape is asserted here AND where a request
|
|
240
|
+
// is admitted, and the two must be changed together — they were not, the
|
|
241
|
+
// first time this name was minted, and every guarded route would have refused
|
|
242
|
+
// every request while no check said a word.
|
|
243
|
+
const name = copiedPicture().toName();
|
|
244
|
+
|
|
245
|
+
assert.ok(isOutputName(name), "the guard admits what the minting produces");
|
|
246
|
+
assert.equal(encodeURIComponent(name), name, "and it needs no escaping to be carried whole");
|
|
247
|
+
// What the guard is FOR.
|
|
248
|
+
assert.equal(isOutputName("../../etc/passwd"), false);
|
|
249
|
+
assert.equal(isOutputName("aaaaaaaa1111222"), false, "fifteen is not sixteen");
|
|
250
|
+
assert.equal(isOutputName("11111111-2222-3333-4444-555555555555"), false, "and the old shape is gone");
|
|
251
|
+
});
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
import test from "node:test";
|
|
11
11
|
import assert from "node:assert/strict";
|
|
12
|
-
import { EncodeCost } from "../services/quality/EncodeCost.js";
|
|
13
|
-
import {
|
|
12
|
+
import { EncodeCost } from "../services/encode/quality/EncodeCost.js";
|
|
13
|
+
import { OutputCatalog } from "../services/encode/output/OutputCatalog.js";
|
|
14
|
+
import { outputSpec } from "./helpers/output-spec.js";
|
|
14
15
|
|
|
15
16
|
const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
16
17
|
|
|
@@ -19,9 +20,13 @@ const PICTURE = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
|
19
20
|
* @param {{ copySpeedX?: number | null, benchmark?: object[] | null }} host
|
|
20
21
|
*/
|
|
21
22
|
function costOf(sessions, host = {}) {
|
|
22
|
-
const
|
|
23
|
+
const outputs = new OutputCatalog();
|
|
24
|
+
sessions.forEach((session, index) => outputs.set(String(index), session));
|
|
23
25
|
return new EncodeCost({
|
|
24
|
-
|
|
26
|
+
runsFor: () => [],
|
|
27
|
+
stateFor: () => "IDLE",
|
|
28
|
+
progressFor: () => null,
|
|
29
|
+
outputs,
|
|
25
30
|
host: () => ({
|
|
26
31
|
benchmark: host.benchmark ?? null,
|
|
27
32
|
decodeModel: null,
|
|
@@ -40,7 +45,7 @@ test("a run on this output outranks every prediction", () => {
|
|
|
40
45
|
// It is this machine, this material and these settings. Nothing said before
|
|
41
46
|
// the fact beats something seen happening.
|
|
42
47
|
const cost = costOf(
|
|
43
|
-
[{ outputKey: PICTURE,
|
|
48
|
+
[{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 9.5 }],
|
|
44
49
|
{ copySpeedX: 600 }
|
|
45
50
|
);
|
|
46
51
|
assert.equal(cost.speedForOutput(PICTURE), 9.5);
|
|
@@ -52,7 +57,7 @@ test("a copied picture is priced by the startup copy measurement", () => {
|
|
|
52
57
|
// describes it, and a copied output was planned with no speed until its own
|
|
53
58
|
// run had been running long enough to report one.
|
|
54
59
|
const cost = costOf(
|
|
55
|
-
[{ outputKey: PICTURE,
|
|
60
|
+
[{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: null }],
|
|
56
61
|
{ copySpeedX: 602 }
|
|
57
62
|
);
|
|
58
63
|
assert.equal(cost.speedForOutput(PICTURE), 602);
|
|
@@ -62,25 +67,22 @@ test("the fastest reading wins where several sessions produce one output", () =>
|
|
|
62
67
|
// Two sessions whose output parameters agree ARE one output, so what either
|
|
63
68
|
// of them measured about this machine is true of the other.
|
|
64
69
|
const cost = costOf([
|
|
65
|
-
{ outputKey: PICTURE,
|
|
66
|
-
{ outputKey: PICTURE,
|
|
70
|
+
{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 4 },
|
|
71
|
+
{ outputKey: PICTURE, spec: outputSpec(), lastAloneSpeed: 7 }
|
|
67
72
|
]);
|
|
68
73
|
assert.equal(cost.speedForOutput(PICTURE), 7);
|
|
69
74
|
});
|
|
70
75
|
|
|
71
|
-
test("
|
|
72
|
-
const cost = costOf(
|
|
73
|
-
|
|
74
|
-
{ copySpeedX: 602 }
|
|
75
|
-
);
|
|
76
|
-
assert.equal(cost.speedForOutput(PICTURE), 0, "no live session, so nothing to say");
|
|
76
|
+
test("an output absent from the live registry says nothing about what the machine is doing", () => {
|
|
77
|
+
const cost = costOf([], { copySpeedX: 602 });
|
|
78
|
+
assert.equal(cost.speedForOutput(PICTURE), 0, "no registered output, so nothing to say");
|
|
77
79
|
});
|
|
78
80
|
|
|
79
81
|
test("another output's reading is not borrowed", () => {
|
|
80
82
|
// Two outputs are two different pieces of work — a picture re-encoded to 480p
|
|
81
83
|
// and the same picture copied are not the same speed.
|
|
82
84
|
const cost = costOf([
|
|
83
|
-
{ outputKey: "other",
|
|
85
|
+
{ outputKey: "other", spec: outputSpec(), lastAloneSpeed: 40 }
|
|
84
86
|
]);
|
|
85
87
|
assert.equal(cost.speedForOutput(PICTURE), 0);
|
|
86
88
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The places preparations hold on the machine are read off the viewers'
|
|
3
|
+
* own records (roadmap item 97, step 13): a step being warmed and a move to
|
|
4
|
+
* another limit of the height on screen are one list, and a place ends with
|
|
5
|
+
* the record — or the viewer — that holds it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import test from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import { Viewers } from "../services/viewer/Viewers.js";
|
|
11
|
+
import { outputsBeingPrepared } from "../services/viewer/choices.js";
|
|
12
|
+
|
|
13
|
+
const PICTURE = { id: "1111111122223333", outputKey: "picture" };
|
|
14
|
+
|
|
15
|
+
test("a warmed step and a move between limits are one list of places", () => {
|
|
16
|
+
const viewers = new Viewers();
|
|
17
|
+
const warming = viewers.of(PICTURE, "viewer-a");
|
|
18
|
+
warming.warmingVariantId = "2222222233334444";
|
|
19
|
+
const moving = viewers.of(PICTURE, "viewer-b");
|
|
20
|
+
moving.sameHeightSwitch = { outputId: "3333333344445555", outputKey: "limit", askedHeights: [720] };
|
|
21
|
+
assert.deepEqual([...outputsBeingPrepared(viewers)].sort(), ["2222222233334444", "3333333344445555"]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("one output prepared for two viewers is one place", () => {
|
|
25
|
+
const viewers = new Viewers();
|
|
26
|
+
viewers.of(PICTURE, "viewer-a").warmingVariantId = "2222222233334444";
|
|
27
|
+
viewers.of(PICTURE, "viewer-b").sameHeightSwitch = { outputId: "2222222233334444", outputKey: "step" };
|
|
28
|
+
assert.equal(outputsBeingPrepared(viewers).size, 1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("a place ends with its record, and with the viewer", () => {
|
|
32
|
+
const viewers = new Viewers();
|
|
33
|
+
const viewer = viewers.of(PICTURE, "viewer-a");
|
|
34
|
+
viewer.warmingVariantId = "2222222233334444";
|
|
35
|
+
viewer.warmingVariantId = null;
|
|
36
|
+
assert.equal(outputsBeingPrepared(viewers).size, 0, "the record cleared");
|
|
37
|
+
viewers.of(PICTURE, "viewer-b").warmingVariantId = "2222222233334444";
|
|
38
|
+
viewers.hasGone("viewer-b");
|
|
39
|
+
assert.equal(outputsBeingPrepared(viewers).size, 0, "the viewer gone");
|
|
40
|
+
});
|