@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.
Files changed (300) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/server.js +0 -11
  4. package/utils/client-log-file.js +147 -42
  5. package/.claude/commands/opsx/apply.md +0 -155
  6. package/.claude/commands/opsx/archive.md +0 -160
  7. package/.claude/commands/opsx/explore.md +0 -174
  8. package/.claude/commands/opsx/propose.md +0 -109
  9. package/.claude/commands/opsx/sync.md +0 -143
  10. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  11. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  12. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  13. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  14. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  15. package/.dockerignore +0 -5
  16. package/AGENTS.md +0 -363
  17. package/CHANGELOG.md +0 -2377
  18. package/Dockerfile +0 -30
  19. package/biome.json +0 -412
  20. package/corpus.tmp.json +0 -1
  21. package/docs/browser-proxy-contract.md +0 -155
  22. package/docs/container-architecture.md +0 -273
  23. package/docs/download-architecture.md +0 -261
  24. package/docs/encode-architecture.md +0 -765
  25. package/docs/encode-run-state.md +0 -96
  26. package/docs/logs.md +0 -151
  27. package/docs/playback-start-forecast.md +0 -113
  28. package/docs/socks5-egress-research.md +0 -114
  29. package/docs/storage-architecture.md +0 -273
  30. package/knip.json +0 -14
  31. package/main2.cpuprofile +0 -1
  32. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  33. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  34. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  35. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  36. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  37. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  38. package/openspec/changes/binary-distribution/proposal.md +0 -53
  39. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  40. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  41. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  42. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  43. package/openspec/changes/cold-start/design.md +0 -98
  44. package/openspec/changes/cold-start/proposal.md +0 -62
  45. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  46. package/openspec/changes/cold-start/tasks.md +0 -48
  47. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  48. package/openspec/changes/disk-cap/proposal.md +0 -37
  49. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  50. package/openspec/changes/disk-cap/tasks.md +0 -19
  51. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  52. package/openspec/changes/proxy-observability/design.md +0 -38
  53. package/openspec/changes/proxy-observability/proposal.md +0 -49
  54. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  55. package/openspec/changes/proxy-observability/tasks.md +0 -21
  56. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  57. package/openspec/changes/seek-debounce/design.md +0 -118
  58. package/openspec/changes/seek-debounce/proposal.md +0 -59
  59. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  60. package/openspec/changes/seek-debounce/tasks.md +0 -33
  61. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  62. package/openspec/changes/subtitle-language/proposal.md +0 -50
  63. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  64. package/openspec/changes/subtitle-language/tasks.md +0 -26
  65. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  66. package/openspec/changes/track-selection/design.md +0 -47
  67. package/openspec/changes/track-selection/proposal.md +0 -45
  68. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  69. package/openspec/changes/track-selection/tasks.md +0 -20
  70. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  71. package/openspec/changes/transcode-quality/proposal.md +0 -51
  72. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  73. package/openspec/changes/transcode-quality/tasks.md +0 -63
  74. package/openspec/config.yaml +0 -38
  75. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  76. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  77. package/research/double-spawn-2026-09-10.md +0 -171
  78. package/research/handover-2026-09-13.md +0 -209
  79. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  80. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  81. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  82. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  83. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  84. package/scripts/build-audio-samples.mjs +0 -31
  85. package/scripts/render-run-graph.js +0 -173
  86. package/test/asset-paths.test.js +0 -28
  87. package/test/audio-buffer-continuity.test.js +0 -77
  88. package/test/audio-calibration.test.js +0 -23
  89. package/test/audio-inventory.test.js +0 -212
  90. package/test/audio-track-bitrate.test.js +0 -40
  91. package/test/audio-warm-recorded.test.js +0 -63
  92. package/test/auto-quality-step.test.js +0 -762
  93. package/test/available-share.test.js +0 -76
  94. package/test/background-fill.test.js +0 -190
  95. package/test/client-log-file.test.js +0 -126
  96. package/test/client-logs-route.test.js +0 -34
  97. package/test/coalesce.test.js +0 -39
  98. package/test/completed-files.test.js +0 -115
  99. package/test/concurrent-cost.test.js +0 -148
  100. package/test/container-media-info.test.js +0 -228
  101. package/test/contention.test.js +0 -76
  102. package/test/core-dumps.test.js +0 -57
  103. package/test/coverage-follows-the-disk.test.js +0 -233
  104. package/test/coverage-map.test.js +0 -195
  105. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  106. package/test/cut-times-timeline.test.js +0 -65
  107. package/test/cuts-follow-published-grid.test.js +0 -109
  108. package/test/data-channel-frame.test.js +0 -63
  109. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  110. package/test/dead-torrent-handle.test.js +0 -52
  111. package/test/declared-rates.test.js +0 -116
  112. package/test/declared-tracks.test.js +0 -43
  113. package/test/decode-cost-fit.test.js +0 -202
  114. package/test/decode-cost.test.js +0 -475
  115. package/test/delivery-probe-field.test.js +0 -173
  116. package/test/delivery-probe.test.js +0 -382
  117. package/test/demand-register.test.js +0 -206
  118. package/test/dht-bootstrap.test.js +0 -72
  119. package/test/drain-threat.test.js +0 -65
  120. package/test/duplicate-add.test.js +0 -48
  121. package/test/encode-admission.test.js +0 -170
  122. package/test/encode-cost.test.js +0 -275
  123. package/test/encode-exit.test.js +0 -111
  124. package/test/encode-orchestrator.test.js +0 -426
  125. package/test/encode-plan-viewers.test.js +0 -725
  126. package/test/encode-plan.test.js +0 -545
  127. package/test/encode-run-state.test.js +0 -314
  128. package/test/encode-run.test.js +0 -248
  129. package/test/encode-slope.test.js +0 -46
  130. package/test/encoded-output.test.js +0 -39
  131. package/test/encoder-kinds.test.js +0 -122
  132. package/test/encoder-readings.test.js +0 -68
  133. package/test/episode-naming.test.js +0 -131
  134. package/test/every-claimant-is-told-its-share.test.js +0 -152
  135. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  136. package/test/failed-start-breaker.test.js +0 -202
  137. package/test/fastest-wires.test.js +0 -143
  138. package/test/ffmpeg-stream-counts.test.js +0 -101
  139. package/test/file-edges.test.js +0 -191
  140. package/test/files-in-use.test.js +0 -34
  141. package/test/fixtures/audio-frame-boundary.json +0 -1
  142. package/test/fixtures/refused-audio-20261002.json +0 -10
  143. package/test/fmp4-presentation-clock.test.js +0 -148
  144. package/test/fmp4-self-contained.test.js +0 -80
  145. package/test/fmp4-timestamps.test.js +0 -140
  146. package/test/fmp4-track-completeness.test.js +0 -41
  147. package/test/format-keyed-outputs.test.js +0 -78
  148. package/test/health-metrics.test.js +0 -36
  149. package/test/held-read-ownership.test.js +0 -77
  150. package/test/held-request-width.test.js +0 -157
  151. package/test/helpers/encode-run.js +0 -248
  152. package/test/helpers/held-file.js +0 -77
  153. package/test/helpers/manager.js +0 -62
  154. package/test/helpers/matroska-file.js +0 -296
  155. package/test/helpers/output-spec.js +0 -63
  156. package/test/host-load.test.js +0 -68
  157. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  158. package/test/init-compat.test.js +0 -219
  159. package/test/input-lost-quiets-the-plan.test.js +0 -261
  160. package/test/input-unavailable.test.js +0 -48
  161. package/test/installation-id.test.js +0 -39
  162. package/test/keeping-period.test.js +0 -83
  163. package/test/keyframe-index-accuracy.test.js +0 -188
  164. package/test/keyframe-table-budget.test.js +0 -123
  165. package/test/keyframes-belong-to-the-file.test.js +0 -249
  166. package/test/learned-median.test.js +0 -37
  167. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  168. package/test/limit-row-by-area.test.js +0 -60
  169. package/test/link-budget.test.js +0 -111
  170. package/test/link-probe.test.js +0 -56
  171. package/test/local-encoding-data.test.js +0 -273
  172. package/test/logger-repeats.test.js +0 -134
  173. package/test/look-ahead-coverage.test.js +0 -56
  174. package/test/manager-surface.test.js +0 -291
  175. package/test/matroska-blocks.test.js +0 -0
  176. package/test/matroska-cluster-discovery.test.js +0 -323
  177. package/test/matroska-cues-track.test.js +0 -192
  178. package/test/media-time.test.js +0 -62
  179. package/test/memory-budget.test.js +0 -390
  180. package/test/move-cost.test.js +0 -216
  181. package/test/mp4-composition-times.test.js +0 -0
  182. package/test/mp4-subtitles.test.js +0 -173
  183. package/test/one-authority.test.js +0 -285
  184. package/test/one-budget.test.js +0 -149
  185. package/test/one-output-one-session.test.js +0 -273
  186. package/test/one-resource-divided.test.js +0 -185
  187. package/test/one-serving-output-per-height.test.js +0 -458
  188. package/test/orchestrator-wired.test.js +0 -207
  189. package/test/output-catalog.test.js +0 -39
  190. package/test/output-shape.test.js +0 -21
  191. package/test/output-spec.test.js +0 -251
  192. package/test/output-speed.test.js +0 -92
  193. package/test/outputs-being-prepared.test.js +0 -40
  194. package/test/packet-witness-ring.test.js +0 -236
  195. package/test/packet-witness.test.js +0 -148
  196. package/test/piece-completeness.test.js +0 -78
  197. package/test/piece-disk-store.test.js +0 -401
  198. package/test/piece-from-whole-file.test.js +0 -129
  199. package/test/piece-lru.test.js +0 -319
  200. package/test/piece-reader.test.js +0 -162
  201. package/test/piece-selection-offset.test.js +0 -85
  202. package/test/piece-store-eviction.test.js +0 -595
  203. package/test/piece-store-never-refuses.test.js +0 -153
  204. package/test/piece-store-reservations.test.js +0 -403
  205. package/test/piece-store-slow-disk.test.js +0 -159
  206. package/test/piece-tail.test.js +0 -97
  207. package/test/plan-host-timings.test.js +0 -68
  208. package/test/plan-is-steady.test.js +0 -225
  209. package/test/playback-readiness.test.js +0 -518
  210. package/test/playback-start-regressions.test.js +0 -101
  211. package/test/priority-map-download.test.js +0 -174
  212. package/test/priority-map-emptied.test.js +0 -204
  213. package/test/priority-map-per-output.test.js +0 -215
  214. package/test/priority-map.test.js +0 -163
  215. package/test/probe-wedge-certainty.test.js +0 -60
  216. package/test/produced-copy-choice.test.js +0 -213
  217. package/test/published-timeline.test.js +0 -83
  218. package/test/quality-offer.test.js +0 -160
  219. package/test/quality-variants.test.js +0 -1274
  220. package/test/rate-control-in-the-output.test.js +0 -181
  221. package/test/read-survives-withdrawal.test.js +0 -164
  222. package/test/read-window.test.js +0 -365
  223. package/test/reads-not-yet-arrived.test.js +0 -218
  224. package/test/resume-warm.test.js +0 -39
  225. package/test/run-graph-drift.test.js +0 -37
  226. package/test/run-inputs.test.js +0 -80
  227. package/test/run-intervals.test.js +0 -100
  228. package/test/run-position-follows-published-grid.test.js +0 -89
  229. package/test/run-progress.test.js +0 -64
  230. package/test/same-height-switch.test.js +0 -663
  231. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  232. package/test/seek-landing.test.js +0 -109
  233. package/test/seek-target-not-superseded.test.js +0 -195
  234. package/test/segment-closed-on-both-branches.test.js +0 -114
  235. package/test/segment-cut-times.test.js +0 -63
  236. package/test/segment-demand.test.js +0 -80
  237. package/test/segment-hold-supersede.test.js +0 -91
  238. package/test/segment-judged-by-its-own-header.test.js +0 -222
  239. package/test/segment-serve-wiring.test.js +0 -481
  240. package/test/segment-store-eviction.test.js +0 -247
  241. package/test/segment-store.test.js +0 -352
  242. package/test/segment-true-start.test.js +0 -86
  243. package/test/segments-are-shared.test.js +0 -176
  244. package/test/send-chunk-bytes.test.js +0 -86
  245. package/test/serving-existing-output.test.js +0 -111
  246. package/test/serving-output.test.js +0 -102
  247. package/test/shared-piece-store.test.js +0 -310
  248. package/test/sidecar-naming.test.js +0 -142
  249. package/test/soundtrack-rate-bound.test.js +0 -289
  250. package/test/source-file.test.js +0 -133
  251. package/test/source-files-route.test.js +0 -113
  252. package/test/source-registry.test.js +0 -18
  253. package/test/split-a-stretch.test.js +0 -139
  254. package/test/stale-request-after-seek.test.js +0 -158
  255. package/test/startup-readings.test.js +0 -124
  256. package/test/stream-route.test.js +0 -237
  257. package/test/subtitle-cue-framing.test.js +0 -200
  258. package/test/subtitle-cue-source.test.js +0 -102
  259. package/test/subtitle-cue-walk.test.js +0 -385
  260. package/test/subtitle-cursor.test.js +0 -63
  261. package/test/subtitle-defaults.test.js +0 -118
  262. package/test/subtitle-language.test.js +0 -252
  263. package/test/subtitle-metadata.test.js +0 -15
  264. package/test/subtitle-plan-waits.test.js +0 -125
  265. package/test/subtitle-track-numbering.test.js +0 -391
  266. package/test/supply-margin.test.js +0 -190
  267. package/test/swarm-follows-readers.test.js +0 -174
  268. package/test/swarm-reach.test.js +0 -130
  269. package/test/swarm-selection.test.js +0 -220
  270. package/test/tail-duplication.test.js +0 -167
  271. package/test/the-channel-has-both-ends.test.js +0 -91
  272. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  273. package/test/thread-pool.test.js +0 -53
  274. package/test/timeline.test.js +0 -84
  275. package/test/torrent-contents.test.js +0 -235
  276. package/test/torrent-cost.test.js +0 -71
  277. package/test/torrent-files.test.js +0 -221
  278. package/test/torrent-naming.test.js +0 -255
  279. package/test/tracks-begin-together.test.js +0 -209
  280. package/test/tunnel-renewal.test.js +0 -167
  281. package/test/two-viewers-one-picture.test.js +0 -508
  282. package/test/upload-hurry.test.js +0 -186
  283. package/test/usrsctp-state.test.js +0 -131
  284. package/test/video-facts.test.js +0 -102
  285. package/test/viewer-assignments.test.js +0 -143
  286. package/test/viewer-outputs.test.js +0 -285
  287. package/test/viewer-presence.test.js +0 -116
  288. package/test/viewer-requests-admission.test.js +0 -92
  289. package/test/viewer-starts-on-map.test.js +0 -27
  290. package/test/viewer-states.test.js +0 -192
  291. package/test/viewer-subtitle-subscription.test.js +0 -96
  292. package/test/viewer.test.js +0 -139
  293. package/test/viewing-generations.test.js +0 -390
  294. package/test/visible-rung.test.js +0 -37
  295. package/test/wait-ledger.test.js +0 -100
  296. package/test/webrtc-shim.test.js +0 -149
  297. package/test/wedge-certainty.test.js +0 -131
  298. package/test/whole-file-held-read.test.js +0 -30
  299. package/test/withdraw-piece-claim.test.js +0 -212
  300. package/test/worker-channel.test.js +0 -158
@@ -1,296 +0,0 @@
1
- /**
2
- * @file Synthetic Matroska files for the checks — built element by element,
3
- * so every check states exactly what the file says and where.
4
- *
5
- * Positions inside the Segment are known only after the elements before them
6
- * are built, so a file is described as a list of top-level elements, and the
7
- * SeekHead and Cues that point at others are built from the lengths of the
8
- * rest (all positions are fixed-width, so they do not change the lengths they
9
- * are computed from).
10
- */
11
-
12
- import { crc32 } from "node:zlib";
13
-
14
- export const ID = {
15
- EBML: 0x1a45dfa3,
16
- SEGMENT: 0x18538067,
17
- SEEK_HEAD: 0x114d9b74,
18
- SEEK: 0x4dbb,
19
- SEEK_ID: 0x53ab,
20
- SEEK_POSITION: 0x53ac,
21
- INFO: 0x1549a966,
22
- TIMESTAMP_SCALE: 0x2ad7b1,
23
- TRACKS: 0x1654ae6b,
24
- TRACK_ENTRY: 0xae,
25
- TRACK_NUMBER: 0xd7,
26
- TRACK_TYPE: 0x83,
27
- CODEC_ID: 0x86,
28
- LANGUAGE: 0x22b59c,
29
- LANGUAGE_BCP47: 0x22b59d,
30
- NAME: 0x536e,
31
- CUES: 0x1c53bb6b,
32
- CUE_POINT: 0xbb,
33
- CUE_TIME: 0xb3,
34
- CUE_TRACK_POSITIONS: 0xb7,
35
- CUE_TRACK: 0xf7,
36
- CUE_CLUSTER_POSITION: 0xf1,
37
- CLUSTER: 0x1f43b675,
38
- TIMESTAMP: 0xe7,
39
- CRC32: 0xbf,
40
- SIMPLE_BLOCK: 0xa3,
41
- BLOCK_GROUP: 0xa0,
42
- BLOCK: 0xa1,
43
- BLOCK_DURATION: 0x9b,
44
- VOID: 0xec
45
- };
46
-
47
- /** @param {number} id @returns {Buffer} */
48
- export function idBytes(id) {
49
- const bytes = [];
50
- let rest = id;
51
- while (rest > 0) {
52
- bytes.unshift(rest & 0xff);
53
- rest = Math.floor(rest / 256);
54
- }
55
- return Buffer.from(bytes);
56
- }
57
-
58
- /** A four-byte size: a valid vint whatever the payload. @param {number} size */
59
- function sizeBytes(size) {
60
- const buffer = Buffer.alloc(4);
61
- buffer.writeUInt32BE(size, 0);
62
- buffer[0] |= 0x10;
63
- return buffer;
64
- }
65
-
66
- /** @param {number} id @param {Buffer} payload @returns {Buffer} */
67
- export function element(id, payload) {
68
- return Buffer.concat([idBytes(id), sizeBytes(payload.length), payload]);
69
- }
70
-
71
- /** An element whose size field says "unknown" (one byte, all value bits set). */
72
- export function unknownSizeElement(id, payload) {
73
- return Buffer.concat([idBytes(id), Buffer.from([0xff]), payload]);
74
- }
75
-
76
- /** @param {number} id @param {number} value */
77
- export function uintElement(id, value) {
78
- const bytes = [];
79
- let rest = value;
80
- do {
81
- bytes.unshift(rest & 0xff);
82
- rest = Math.floor(rest / 256);
83
- } while (rest > 0);
84
- return element(id, Buffer.from(bytes));
85
- }
86
-
87
- /** A fixed-width unsigned integer, so a position computed twice keeps its length. */
88
- export function uint32Element(id, value) {
89
- const payload = Buffer.alloc(4);
90
- payload.writeUInt32BE(value, 0);
91
- return element(id, payload);
92
- }
93
-
94
- /** @param {number} id @param {string} value */
95
- export function stringElement(id, value) {
96
- return element(id, Buffer.from(value, "utf8"));
97
- }
98
-
99
- /**
100
- * @param {{ number: number, type: number, codecId: string, language?: string | null, languageBcp47?: string, name?: string }} track
101
- * @returns {Buffer}
102
- */
103
- export function trackEntry({ number, type, codecId, language = null, languageBcp47 = "", name = "" }) {
104
- const parts = [uintElement(ID.TRACK_NUMBER, number), uintElement(ID.TRACK_TYPE, type), stringElement(ID.CODEC_ID, codecId)];
105
- if (language !== null) {
106
- parts.push(stringElement(ID.LANGUAGE, language));
107
- }
108
- if (languageBcp47) {
109
- parts.push(stringElement(ID.LANGUAGE_BCP47, languageBcp47));
110
- }
111
- if (name) {
112
- parts.push(stringElement(ID.NAME, name));
113
- }
114
- return element(ID.TRACK_ENTRY, Buffer.concat(parts));
115
- }
116
-
117
- /**
118
- * One cue, as a BlockGroup carrying its own duration.
119
- *
120
- * @param {{ track: number, relativeTicks: number, durationTicks: number, text: string }} params
121
- */
122
- export function cueBlock({ track, relativeTicks, durationTicks, text }) {
123
- const header = Buffer.alloc(4);
124
- header[0] = 0x80 | track;
125
- header.writeInt16BE(relativeTicks, 1);
126
- header[3] = 0;
127
- const block = element(ID.BLOCK, Buffer.concat([header, Buffer.from(text, "utf8")]));
128
- return element(ID.BLOCK_GROUP, Buffer.concat([block, uintElement(ID.BLOCK_DURATION, durationTicks)]));
129
- }
130
-
131
- /**
132
- * A picture block: a SimpleBlock of `payload` bytes on `track`.
133
- *
134
- * @param {{ track: number, payload: Buffer }} params
135
- */
136
- export function pictureBlock({ track, payload }) {
137
- const header = Buffer.alloc(4);
138
- header[0] = 0x80 | track;
139
- header.writeInt16BE(0, 1);
140
- header[3] = 0x80;
141
- return element(ID.SIMPLE_BLOCK, Buffer.concat([header, payload]));
142
- }
143
-
144
- /**
145
- * A cluster's DATA: its Timestamp (optionally after a CRC-32) and its blocks.
146
- *
147
- * @param {{ ticks: number, blocks: Buffer[], crc?: boolean | "wrong" }} params
148
- * @returns {Buffer}
149
- */
150
- export function clusterData({ ticks, blocks, crc = false }) {
151
- const rest = Buffer.concat([uintElement(ID.TIMESTAMP, ticks), ...blocks]);
152
- if (!crc) {
153
- return rest;
154
- }
155
- const value = Buffer.alloc(4);
156
- value.writeUInt32LE(crc === "wrong" ? (crc32(rest) ^ 0xffffffff) >>> 0 : crc32(rest), 0);
157
- return Buffer.concat([Buffer.concat([idBytes(ID.CRC32), Buffer.from([0x84]), value]), rest]);
158
- }
159
-
160
- /**
161
- * A whole file.
162
- *
163
- * `clusters` are each `{ data, unknownSize? }`. `cues` says which tracks the
164
- * Cues table names for every cluster: an array of track numbers, or null for
165
- * no Cues element at all. `cuesBeforeClusters` puts the Cues element ahead of
166
- * the clusters with no SeekHead entry for it.
167
- *
168
- * @param {object} params
169
- * @param {Buffer[]} params.tracks - TrackEntry elements.
170
- * @param {Array<{ data: Buffer, unknownSize?: boolean, ticks: number }>} params.clusters
171
- * @param {number[] | null} [params.cues]
172
- * @param {boolean} [params.cuesBeforeClusters]
173
- * @returns {{ file: Buffer, clusterAt: number[], cuesAt: number | null, segmentDataOffset: number }}
174
- */
175
- export function buildMatroska({ tracks, clusters, cues = [], cuesBeforeClusters = false }) {
176
- const info = element(ID.INFO, uintElement(ID.TIMESTAMP_SCALE, 1_000_000));
177
- const tracksElement = element(ID.TRACKS, Buffer.concat(tracks));
178
- const clusterElements = clusters.map((cluster) =>
179
- cluster.unknownSize ? unknownSizeElement(ID.CLUSTER, cluster.data) : element(ID.CLUSTER, cluster.data)
180
- );
181
-
182
- const cuesWith = (positions) =>
183
- cues === null
184
- ? Buffer.alloc(0)
185
- : element(
186
- ID.CUES,
187
- Buffer.concat(
188
- clusters.map((cluster, index) =>
189
- element(
190
- ID.CUE_POINT,
191
- Buffer.concat([
192
- uint32Element(ID.CUE_TIME, cluster.ticks),
193
- ...cues.map((track) =>
194
- element(
195
- ID.CUE_TRACK_POSITIONS,
196
- Buffer.concat([uintElement(ID.CUE_TRACK, track), uint32Element(ID.CUE_CLUSTER_POSITION, positions[index])])
197
- )
198
- )
199
- ])
200
- )
201
- )
202
- )
203
- );
204
- const seekEntry = (targetId, position) =>
205
- element(ID.SEEK, Buffer.concat([element(ID.SEEK_ID, idBytes(targetId)), uint32Element(ID.SEEK_POSITION, position)]));
206
- const seekHeadWith = (infoAt, tracksAt, cuesAt) =>
207
- element(
208
- ID.SEEK_HEAD,
209
- Buffer.concat([
210
- seekEntry(ID.INFO, infoAt),
211
- seekEntry(ID.TRACKS, tracksAt),
212
- ...(cues !== null && !cuesBeforeClusters ? [seekEntry(ID.CUES, cuesAt)] : [])
213
- ])
214
- );
215
-
216
- const zeros = clusters.map(() => 0);
217
- const headLength = seekHeadWith(0, 0, 0).length;
218
- const infoAt = headLength;
219
- const tracksAt = infoAt + info.length;
220
- const cuesLength = cuesWith(zeros).length;
221
- const firstClusterAt = tracksAt + tracksElement.length + (cuesBeforeClusters ? cuesLength : 0);
222
- const positions = [];
223
- let at = firstClusterAt;
224
- for (const cluster of clusterElements) {
225
- positions.push(at);
226
- at += cluster.length;
227
- }
228
- const cuesAt = cues === null ? null : cuesBeforeClusters ? tracksAt + tracksElement.length : at;
229
- const parts = [seekHeadWith(infoAt, tracksAt, cuesAt ?? 0), info, tracksElement];
230
- if (cuesBeforeClusters) {
231
- parts.push(cuesWith(positions));
232
- }
233
- parts.push(...clusterElements);
234
- if (!cuesBeforeClusters) {
235
- parts.push(cuesWith(positions));
236
- }
237
- const payload = Buffer.concat(parts);
238
- const ebml = element(ID.EBML, Buffer.from([0x42, 0x86, 0x81, 0x01]));
239
- const segment = element(ID.SEGMENT, payload);
240
- const segmentDataOffset = ebml.length + segment.length - payload.length;
241
- return {
242
- file: Buffer.concat([ebml, segment]),
243
- clusterAt: positions.map((position) => segmentDataOffset + position),
244
- cuesAt: cuesAt === null ? null : segmentDataOffset + cuesAt,
245
- segmentDataOffset
246
- };
247
- }
248
-
249
- /**
250
- * A reader over a buffer that answers null for the ranges a check says are
251
- * not here, and records every range asked for.
252
- *
253
- * @param {Buffer} bytes
254
- * @param {{ missing?: (start: number, end: number) => boolean, short?: boolean }} [options]
255
- */
256
- export function readerOver(bytes, options = {}) {
257
- const reads = [];
258
- const read = async (start, end) => {
259
- reads.push({ start, end });
260
- if (options.missing?.(start, end)) {
261
- return null;
262
- }
263
- const slice = bytes.subarray(start, end + 1);
264
- return options.short ? slice.subarray(0, Math.max(0, slice.length - 1)) : Buffer.from(slice);
265
- };
266
- return { read, reads };
267
- }
268
-
269
- /**
270
- * What the cue walk may read: the held ranges, a strict read of them, a
271
- * portion and where viewers stand.
272
- *
273
- * @param {Buffer} bytes
274
- * @param {Array<[number, number]>} ranges
275
- * @param {{ portionBytes?: number, wantedSeconds?: number[], reads?: Array<{ start: number, end: number }> }} [options]
276
- * @returns {import("../../services/media/container/Container.js").HeldReader}
277
- */
278
- export function heldOver(bytes, ranges, options = {}) {
279
- const holds = (start, end) => ranges.some(([from, to]) => start >= from && end <= to);
280
- return {
281
- ranges,
282
- isHeld: (start, end) => holds(start, Math.min(end, bytes.length - 1)),
283
- read: async (start, end) => {
284
- options.reads?.push({ start, end });
285
- const last = Math.min(end, bytes.length - 1);
286
- if (!holds(start, last)) {
287
- const error = new Error(`bytes ${start}-${last} are not available yet`);
288
- error.name = "BytesUnavailable";
289
- throw error;
290
- }
291
- return Buffer.from(bytes.subarray(start, last + 1));
292
- },
293
- portionBytes: options.portionBytes ?? Number.POSITIVE_INFINITY,
294
- wantedSeconds: options.wantedSeconds ?? []
295
- };
296
- }
@@ -1,63 +0,0 @@
1
- import { AudioOutput, CutGrid, OutputSpec, VideoOutput } from "../../services/encode/output/OutputSpec.js";
2
-
3
- /**
4
- * Build the output identity used by production objects in focused tests.
5
- *
6
- * @param {object} [params]
7
- * @param {string} [params.sourceKey]
8
- * @param {number} [params.fileIndex]
9
- * @param {boolean} [params.transcodeVideo]
10
- * @param {boolean} [params.transcodeAudio]
11
- * @param {boolean} [params.audioOnly]
12
- * @param {boolean} [params.audioSeparate]
13
- * @param {number} [params.audioFileIndex]
14
- * @param {number} [params.audioSourceTrackIndex]
15
- * @param {number} [params.width]
16
- * @param {number} [params.height]
17
- * @param {string} [params.encoder]
18
- * @param {number} [params.fps]
19
- * @param {string | null} [params.preset]
20
- * @param {boolean} [params.tonemap]
21
- * @param {{ maxrateKbps: number, bufsizeKbps: number, level: string | null } | null} [params.rateControl]
22
- * @param {"keyframe" | "uniform"} [params.cutGrid]
23
- * @param {string} [params.segmentFormatId]
24
- * @returns {OutputSpec}
25
- */
26
- export function outputSpec({
27
- sourceKey = "source-1",
28
- fileIndex = 0,
29
- transcodeVideo = false,
30
- transcodeAudio = true,
31
- audioOnly = false,
32
- audioSeparate = false,
33
- audioFileIndex = fileIndex,
34
- audioSourceTrackIndex = 0,
35
- width = 0,
36
- height = 0,
37
- encoder = "libx264",
38
- fps = 24,
39
- preset = null,
40
- tonemap = false,
41
- rateControl = null,
42
- cutGrid = "uniform",
43
- segmentFormatId = "fmp4"
44
- } = {}) {
45
- return new OutputSpec({
46
- sourceKey,
47
- segmentFormatId,
48
- grid: new CutGrid({ kind: cutGrid, fileIndex }),
49
- video: audioOnly
50
- ? null
51
- : new VideoOutput({
52
- fileIndex,
53
- encode: transcodeVideo ? { encoder, width, height, fps, preset, tonemap, rateControl } : null
54
- }),
55
- audio: audioSeparate
56
- ? null
57
- : new AudioOutput({
58
- fileIndex: audioFileIndex,
59
- trackIndex: audioSourceTrackIndex,
60
- transcode: transcodeAudio
61
- })
62
- });
63
- }
@@ -1,68 +0,0 @@
1
- /**
2
- * @file The arithmetic that turns two readings of the machine into shares.
3
- *
4
- * The readings themselves are files this host may or may not have; what is
5
- * tested here is what is DERIVED from them, because that is where a wrong
6
- * number would quietly become a wrong conclusion about why an encoder is slow.
7
- */
8
-
9
- import assert from "node:assert/strict";
10
- import test from "node:test";
11
-
12
- import { readProcessCpuSeconds, readSystemCpu, sampleHost, shareOfMachine } from "../services/encode/host-load.js";
13
-
14
- test("a process using one core of four for a second reports a quarter of the machine", () => {
15
- const before = { takenAt: 1_000, processCpuSeconds: 10, system: null };
16
- const after = { takenAt: 2_000, processCpuSeconds: 11, system: null };
17
- const share = shareOfMachine(before, after, 4);
18
- assert.equal(share?.elapsedSec, 1);
19
- assert.equal(share?.processShare, 0.25);
20
- });
21
-
22
- test("a process using every core reports the whole machine", () => {
23
- const share = shareOfMachine(
24
- { takenAt: 0, processCpuSeconds: 0, system: null },
25
- { takenAt: 2_000, processCpuSeconds: 8, system: null },
26
- 4
27
- );
28
- assert.equal(share?.processShare, 1);
29
- });
30
-
31
- test("waiting for a disk is counted apart from working", () => {
32
- const before = { takenAt: 0, processCpuSeconds: null, system: { busySeconds: 100, idleSeconds: 900, iowaitSeconds: 10 } };
33
- const after = { takenAt: 1_000, processCpuSeconds: null, system: { busySeconds: 101, idleSeconds: 902, iowaitSeconds: 11 } };
34
- const share = shareOfMachine(before, after, 4);
35
- assert.equal(share?.systemShare, 0.25);
36
- assert.equal(share?.iowaitShare, 0.25);
37
- });
38
-
39
- test("two readings taken at the same instant say nothing rather than dividing by zero", () => {
40
- assert.equal(shareOfMachine({ takenAt: 5, processCpuSeconds: 1, system: null }, { takenAt: 5, processCpuSeconds: 2, system: null }, 4), null);
41
- });
42
-
43
- test("a missing reading leaves that share unknown, not zero", () => {
44
- const share = shareOfMachine(
45
- { takenAt: 0, processCpuSeconds: null, system: null },
46
- { takenAt: 1_000, processCpuSeconds: 1, system: null },
47
- 4
48
- );
49
- assert.equal(share?.processShare, null);
50
- assert.equal(share?.systemShare, null);
51
- });
52
-
53
- test("a process that does not exist reports nothing at all", async () => {
54
- assert.equal(await readProcessCpuSeconds(0), null);
55
- assert.equal(await readProcessCpuSeconds(-1), null);
56
- // A pid far above any real one on this machine.
57
- assert.equal(await readProcessCpuSeconds(4_000_000), null);
58
- });
59
-
60
- test("on a host without /proc the readings are null and the sampler still answers", async () => {
61
- // This runs on Linux in CI and on Windows here; both must be safe. What is
62
- // asserted is the SHAPE — a reading is either a number or null, never a throw.
63
- const system = await readSystemCpu();
64
- assert.ok(system === null || typeof system.busySeconds === "number");
65
- const sample = await sampleHost(null);
66
- assert.equal(typeof sample.takenAt, "number");
67
- assert.equal(sample.processCpuSeconds, null);
68
- });
@@ -1,128 +0,0 @@
1
- /**
2
- * @file What a produced piece reveals, and WHOSE fact it is.
3
- *
4
- * One reading is taken — how far a produced piece began from where its grid
5
- * said it would — and three different facts are drawn from it, which the code
6
- * that draws them already stated in its own three branches:
7
- *
8
- * 1. a COPIED picture can only be cut where a keyframe already is, so a
9
- * disagreement says the container's keyframe TABLE describes times the file
10
- * does not have. A fact of the FILE;
11
- * 2. a RE-ENCODED rung was told to put a keyframe at that instant and did not,
12
- * so its pieces no longer stand where the stream it accompanies would have
13
- * put them. A fact of that OUTPUT;
14
- * 3. a SOUNDTRACK is cut exactly where it is asked to be, to within an audio
15
- * frame, so it says nothing about any keyframe at all — only that the
16
- * picture's grid has moved under a run already going. A fact of that OUTPUT.
17
- *
18
- * Until 2026-09-15 all three went into ONE tally, and the tally was on the cut
19
- * table — which is held per (file, grid), so a picture and the soundtrack muxed
20
- * into the same file shared it. Three consequences, and these checks are about
21
- * all of them: the file's finding died with a grid it does not belong to, one
22
- * output's reading of a piece number silenced another's reading of its own, and
23
- * the summary could not say which of the three facts it was summarising.
24
- */
25
-
26
- import test from "node:test";
27
- import assert from "node:assert/strict";
28
- import { Timeline, Timelines } from "../services/encode/output/Timeline.js";
29
- import { Output } from "../services/encode/output/Output.js";
30
- import { KeyframeTable } from "../services/media/container/KeyframeTable.js";
31
-
32
- const KEYFRAMES = [0, 4.004, 8.008, 12.012, 16.016];
33
- const TOLERANCE = 0.25;
34
-
35
- /**
36
- * @param {number[]} boundaries
37
- * @returns {Timeline}
38
- */
39
- function timelineOver(boundaries) {
40
- return new Timeline({ boundaries: [...boundaries], cutGrid: "keyframe" });
41
- }
42
-
43
- /**
44
- * @returns {Output}
45
- */
46
- function anOutput() {
47
- return new Output({
48
- encodeWidth: 0,
49
- encodeHeight: 0,
50
- outputFps: 25,
51
- softwarePreset: null,
52
- applyTonemap: false
53
- });
54
- }
55
-
56
- test("a picture and the soundtrack inside the same file share one cut table, and no longer one tally", () => {
57
- // Sharing the table is right — it is what makes them cut at the same instants
58
- // and is the whole reason it is held per file and grid. What must not be
59
- // shared is what each of them LEARNS, since the two learn different things.
60
- const tables = new Timelines();
61
- const key = Timelines.keyFor("torrent:abc", 3, "keyframe");
62
-
63
- const picture = tables.get(key, () => timelineOver(KEYFRAMES));
64
- const sound = tables.get(key, () => timelineOver(KEYFRAMES));
65
-
66
- assert.equal(sound, picture, "one table, so the cuts cannot drift apart");
67
- assert.equal(
68
- Object.keys(picture).some((field) => /check|tally|deviation|landing/i.test(field)),
69
- false,
70
- "and nothing on it counts what anybody found, which two outputs would have shared"
71
- );
72
- });
73
-
74
- test("two outputs each keep their own reading of the same piece number", () => {
75
- // `seen` exists so that a piece asked for twice is not counted twice — right
76
- // for one producer, and wrong across two. Shared, it dropped whichever of the
77
- // two finished second, so which reading survived was decided by a race.
78
- const picture = anOutput();
79
- const sound = anOutput();
80
-
81
- picture.noteLanding({ index: 7, deviationSec: 0.9, toleranceSec: TOLERANCE });
82
- sound.noteLanding({ index: 7, deviationSec: 0, toleranceSec: TOLERANCE });
83
-
84
- assert.equal(picture.landing.checked, 1);
85
- assert.equal(picture.landing.disagreed, 1, "the picture's piece did begin away from its grid");
86
- assert.equal(sound.landing.checked, 1, "and the sound's reading of its own #7 is not a repeat");
87
- assert.equal(sound.landing.disagreed, 0, "the sound was cut exactly where it was asked");
88
-
89
- // What `seen` is FOR, which the split must not lose: within one output a
90
- // piece is produced and served over and over while a viewer is refused it,
91
- // and the same piece is one reading however many times it is read.
92
- picture.noteLanding({ index: 7, deviationSec: 0.9, toleranceSec: TOLERANCE });
93
- picture.noteLanding({ index: 7, deviationSec: 0.9, toleranceSec: TOLERANCE });
94
-
95
- assert.equal(picture.landing.checked, 1, "its own repeat is still the same piece, counted once");
96
- assert.equal(picture.landing.disagreed, 1);
97
- });
98
-
99
- test("only a copy's reading reaches the file's table, and it outlives any one grid", () => {
100
- // The whole point of moving it: the table is one per FILE, so what a copy
101
- // showed about it is there for every step and every later session of those
102
- // bytes — while a tally on a cut table died with the grid, and a grid is not
103
- // what the reading is about.
104
- const table = new KeyframeTable().learn({ times: KEYFRAMES, format: "matroska" });
105
-
106
- table.witness({ index: 2, trueStart: 12.012, deviationSec: 4.004, toleranceSec: TOLERANCE });
107
-
108
- assert.equal(table.evidence.checked, 1);
109
- assert.equal(table.evidence.disagreed, 1);
110
- assert.equal(
111
- table.evidence.landedOnAnotherKeyframe,
112
- 1,
113
- "and the table itself says the piece began at another time it names — the grid was built over a gap"
114
- );
115
- });
116
-
117
- test("each tally answers one question, so a summary of it cannot be a mixture", () => {
118
- // The distinction the three branches make when they WARN is now kept in what
119
- // they count, so the summary can restate it — and the summary is what is read
120
- // when nobody was watching the log live.
121
- const sound = anOutput();
122
- const table = new KeyframeTable().learn({ times: KEYFRAMES, format: "matroska" });
123
-
124
- sound.noteLanding({ index: 1, deviationSec: 0.8, toleranceSec: TOLERANCE });
125
-
126
- assert.equal(sound.landing.disagreed, 1, "the sound's grid moved under its run, and that is all it says");
127
- assert.equal(table.evidence, null, "nothing a soundtrack produced is evidence about the file's keyframes");
128
- });