@torrent-tv/proxy 2.89.16 → 2.89.18
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/routes/api/client-logs/post.js +9 -2
- package/server.js +0 -11
- 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 -2373
- 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 -138
- 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/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,92 +0,0 @@
|
|
|
1
|
-
# Design: Adaptive bitrate (proxy)
|
|
2
|
-
|
|
3
|
-
Read before coding: `services/encode/hwaccel.js` (`chooseSoftwareEncodeSettings`,
|
|
4
|
-
the software descriptor's `buildVideoArgs`), `services/hls-session-manager.js`
|
|
5
|
-
(the `BUDGET_*` constants, `#chooseEncodeBudget`, the budget interval check
|
|
6
|
-
`#enforceRealtimeBudget`, `#classifyTranscodeBound`, `#applyBudgetDownshift`,
|
|
7
|
-
session fields around `budgetLadder`), `routes/api/transcode-sessions/`
|
|
8
|
-
(route file conventions), `server.js` (route wiring, deps injection).
|
|
9
|
-
|
|
10
|
-
## (a) Caps — constrained CRF
|
|
11
|
-
|
|
12
|
-
Nominal H.264 rates by rung height (nearest rung wins for odd heights):
|
|
13
|
-
|
|
14
|
-
RUNG_NOMINAL_KBPS = { 1080: 5000, 720: 2800, 480: 1400, 360: 800, 240: 400 }
|
|
15
|
-
CAP_MAXRATE_FACTOR = 1.3
|
|
16
|
-
CAP_BUFSIZE_FACTOR = 1.5
|
|
17
|
-
|
|
18
|
-
In the software descriptor's video args (where `-crf`/`-preset` are emitted),
|
|
19
|
-
add for encode height H (the actual encode height after budget/manual
|
|
20
|
-
selection, not the source height):
|
|
21
|
-
|
|
22
|
-
-maxrate <round(nominal(H) * 1.3)>k
|
|
23
|
-
-bufsize <round(nominal(H) * 1.5)>k
|
|
24
|
-
|
|
25
|
-
CRF stays the quality driver; the caps only bound peaks (standard
|
|
26
|
-
constrained-CRF). Do NOT touch hardware descriptors in this change.
|
|
27
|
-
|
|
28
|
-
## (b) Net report intake
|
|
29
|
-
|
|
30
|
-
Route: `POST /api/transcode-sessions/:id/net-report` (data-channel path, so
|
|
31
|
-
add the prefix to the allowlist regex in `transport/data-channel-handler.js` if not
|
|
32
|
-
covered by the existing `/api/` rule — verify). Body:
|
|
33
|
-
|
|
34
|
-
{ linkMbps: number, bufferedAheadSec: number }
|
|
35
|
-
|
|
36
|
-
Validation: both finite numbers, `linkMbps > 0`, else 400. Unknown session →
|
|
37
|
-
404. On success 204. Handler stores on the session:
|
|
38
|
-
|
|
39
|
-
session.netReport = { linkMbps, bufferedAheadSec, at: Date.now() }
|
|
40
|
-
|
|
41
|
-
## (b) Budget-loop trigger
|
|
42
|
-
|
|
43
|
-
Constants (near the other BUDGET_ constants):
|
|
44
|
-
|
|
45
|
-
LINK_REPORT_FRESH_MS = 30_000 // ignore stale reports
|
|
46
|
-
LINK_SAFETY = 0.8 // usable share of reported link
|
|
47
|
-
LINK_SLOW_WINDOW_MS = 15_000 // sustained deficit before acting
|
|
48
|
-
LINK_LOW_BUFFER_SEC = 10 // only act while the viewer runs dry
|
|
49
|
-
|
|
50
|
-
In the periodic budget check, for each active software-transcode session,
|
|
51
|
-
alongside the CPU check:
|
|
52
|
-
|
|
53
|
-
report fresh (now - at < LINK_REPORT_FRESH_MS)?
|
|
54
|
-
manualQuality not set?
|
|
55
|
-
observed = observed stream bitrate, Mbit/s — recent produced segment
|
|
56
|
-
bytes / segment duration (reuse/extend whatever the CPU path
|
|
57
|
-
reads; a rolling average over the last ~5 segments)
|
|
58
|
-
deficit = report.linkMbps * LINK_SAFETY < observed
|
|
59
|
-
if deficit AND report.bufferedAheadSec < LINK_LOW_BUFFER_SEC:
|
|
60
|
-
accumulate slow-time (same pattern as the CPU slow window)
|
|
61
|
-
if slow ≥ LINK_SLOW_WINDOW_MS → #applyBudgetDownshift(session,
|
|
62
|
-
reason "link") // existing cooldown + step cap + floor apply
|
|
63
|
-
else: reset the link slow window
|
|
64
|
-
|
|
65
|
-
`#applyBudgetDownshift` is reused as-is except the log line carries the
|
|
66
|
-
reason: `budget downshift (link) …` vs the current CPU wording, so the
|
|
67
|
-
client-log pipeline can tell them apart in the field.
|
|
68
|
-
|
|
69
|
-
No upswitch in v1 (mirrors the CPU budget's conservatism). A downshifted
|
|
70
|
-
session stays down until re-opened.
|
|
71
|
-
|
|
72
|
-
## Interactions
|
|
73
|
-
|
|
74
|
-
- Caps make `observed` honest: without (a) a complex scene can spike far
|
|
75
|
-
above nominal and flap the trigger; with caps observed ≤ maxrate.
|
|
76
|
-
- CPU trigger and link trigger share the cooldown inside
|
|
77
|
-
`#applyBudgetDownshift` — they cannot double-fire.
|
|
78
|
-
- `manualQuality` set → link trigger skipped entirely (user pinned quality
|
|
79
|
-
explicitly; the proxy respects it, matching the manual-quality contract).
|
|
80
|
-
- Old browsers never POST reports → trigger never fires → behaviour
|
|
81
|
-
identical to today plus caps.
|
|
82
|
-
|
|
83
|
-
## Verification
|
|
84
|
-
|
|
85
|
-
- Unit: nominal table lookup (exact rungs + nearest for odd heights); ffmpeg
|
|
86
|
-
arg assembly contains the caps; trigger logic with a fake clock (fresh vs
|
|
87
|
-
stale report, deficit accumulating to a downshift, buffer-high suppresses,
|
|
88
|
-
manualQuality suppresses).
|
|
89
|
-
- `node --check` on touched files.
|
|
90
|
-
- Field (after the server change ships): cellular session shows
|
|
91
|
-
`budget downshift (link)` and the stream settles at a rung whose bitrate
|
|
92
|
-
fits the link; segment sizes bounded (~maxrate × segDur / 8 max).
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Proposal: Adaptive bitrate for thin viewer links (proxy side)
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
Field evidence (iPhone on cellular, 2026-07-10, session `14cc1017`): encode
|
|
6
|
-
bitrate is unbounded — transcoded segments reached 9 MB per 4 s (~18 Mbit/s)
|
|
7
|
-
against a measured 1–5.8 Mbit/s cellular link. Result: 45 s prebuffer, buffer
|
|
8
|
-
draining during playback (`bottleneck delta=-7.1s`), "было так себе". The
|
|
9
|
-
realtime budget protects the PROXY's CPU but nothing protects the VIEWER's
|
|
10
|
-
link: quality never adapts to how fast the viewer can actually download.
|
|
11
|
-
|
|
12
|
-
## What Changes
|
|
13
|
-
|
|
14
|
-
Two parts, one release:
|
|
15
|
-
|
|
16
|
-
- **(a) Bitrate caps (constrained CRF).** Software video encodes gain
|
|
17
|
-
`-maxrate`/`-bufsize` sized per resolution rung from a nominal-rate table
|
|
18
|
-
(H.264 ladder: 1080p→5000K, 720p→2800K, 480p→1400K, 360p→800K, 240p→400K;
|
|
19
|
-
nearest rung by encode height). Multipliers from webtor's production
|
|
20
|
-
ladder: `maxrate = 1.3×` nominal, `bufsize = 1.5×` nominal. CRF/preset
|
|
21
|
-
selection stays — the caps only bound the peaks that killed the cellular
|
|
22
|
-
session. Applies to the software (libx264) path; hardware encoders keep
|
|
23
|
-
their current args (follow-up — their rate-control flags differ and any
|
|
24
|
-
change must pass the strict startup test on real hardware).
|
|
25
|
-
- **(b) Viewer-link downshift trigger.** A new data-channel route lets the
|
|
26
|
-
browser report its measured link state (`linkMbps` — rolling median of
|
|
27
|
-
per-segment transfer throughput; `bufferedAheadSec`) every ~10 s. The
|
|
28
|
-
existing realtime-budget loop gains a SECOND downshift trigger: when
|
|
29
|
-
reports are fresh, `manualQuality` is not set, the viewer's link is
|
|
30
|
-
sustainedly slower than the produced stream (`linkMbps × 0.8 <` observed
|
|
31
|
-
segment bitrate for ≥ 15 s) AND the viewer's buffer is low (< 10 s), step
|
|
32
|
-
one rung down via the existing `#applyBudgetDownshift` (same cooldown,
|
|
33
|
-
step cap, no upswitch v1). Distinct log reason (`reason=link`) so field
|
|
34
|
-
logs distinguish CPU-bound from link-bound downshifts.
|
|
35
|
-
|
|
36
|
-
Missing/stale reports change nothing (old clients keep working — the trigger
|
|
37
|
-
simply never fires). Manual quality pins win: when `manualQuality` is set the
|
|
38
|
-
trigger is skipped.
|
|
39
|
-
|
|
40
|
-
## Capabilities
|
|
41
|
-
|
|
42
|
-
### Modified Capabilities
|
|
43
|
-
|
|
44
|
-
- `transcode-quality`: encodes are bitrate-capped per rung; the budget loop
|
|
45
|
-
adapts to the viewer's link, not only to the proxy's CPU.
|
|
46
|
-
|
|
47
|
-
## Impact
|
|
48
|
-
|
|
49
|
-
- `services/encode/hwaccel.js` — nominal-rate table + caps in the software
|
|
50
|
-
descriptor's video args.
|
|
51
|
-
- `services/hls-session-manager.js` — accept/store net reports per session;
|
|
52
|
-
link trigger in the budget check; log line.
|
|
53
|
-
- `routes/api/transcode-sessions/net-report/post.js` (new) + `server.js`
|
|
54
|
-
wiring — report intake.
|
|
55
|
-
- Proxy release + ha-addon bump. The server-side reporter is a separate
|
|
56
|
-
change (`server/viewer-net-report`); release proxy+addon FIRST.
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# adaptive-bitrate — delta spec (proxy)
|
|
2
|
-
|
|
3
|
-
## ADDED Requirements
|
|
4
|
-
|
|
5
|
-
### Requirement: Software encodes are bitrate-capped per resolution rung
|
|
6
|
-
|
|
7
|
-
Software video encodes SHALL carry `-maxrate`/`-bufsize` derived from a
|
|
8
|
-
per-rung nominal-rate table (1.3× / 1.5× of the rung's nominal), keeping the
|
|
9
|
-
existing CRF/preset quality selection (constrained CRF). The cap follows the
|
|
10
|
-
ACTUAL encode height after budget or manual selection.
|
|
11
|
-
|
|
12
|
-
#### Scenario: Complex scene on a capped encode
|
|
13
|
-
- **WHEN** a transcoded scene would spike far above the rung's nominal rate
|
|
14
|
-
- **THEN** the produced segments stay bounded by the cap instead of reaching
|
|
15
|
-
multi-megabyte sizes that a thin viewer link cannot download in time
|
|
16
|
-
|
|
17
|
-
### Requirement: The proxy accepts viewer link reports
|
|
18
|
-
|
|
19
|
-
A data-channel route SHALL accept periodic reports
|
|
20
|
-
`{ linkMbps, bufferedAheadSec }` for an active transcode session and store
|
|
21
|
-
the latest report with its arrival time. Invalid bodies are rejected;
|
|
22
|
-
unknown sessions get 404; missing reports are not an error condition.
|
|
23
|
-
|
|
24
|
-
#### Scenario: Old client
|
|
25
|
-
- **WHEN** a browser never sends net reports
|
|
26
|
-
- **THEN** the session behaves exactly as before this change (plus caps)
|
|
27
|
-
|
|
28
|
-
### Requirement: The budget loop downshifts on a sustained link deficit
|
|
29
|
-
|
|
30
|
-
When a fresh report shows the viewer's usable link (reported × safety
|
|
31
|
-
margin) sustainedly below the observed produced bitrate AND the viewer's
|
|
32
|
-
buffer is low, the existing budget downshift SHALL step the encode one rung
|
|
33
|
-
down (same cooldown, step cap and floor as the CPU trigger; no upswitch).
|
|
34
|
-
The trigger SHALL be skipped when `manualQuality` is set, when reports are
|
|
35
|
-
stale, or when the viewer's buffer is comfortable. The downshift log line
|
|
36
|
-
SHALL name the reason (`link`) distinctly from the CPU reason.
|
|
37
|
-
|
|
38
|
-
#### Scenario: Cellular viewer, stream too fat
|
|
39
|
-
- **WHEN** reports show 3 Mbit/s usable link against 6 Mbit/s produced
|
|
40
|
-
bitrate for longer than the slow window, with a draining buffer
|
|
41
|
-
- **THEN** the encode steps down one rung and the log shows a link-reason
|
|
42
|
-
downshift
|
|
43
|
-
|
|
44
|
-
#### Scenario: Slow link but full buffer
|
|
45
|
-
- **WHEN** the link is slower than the stream but the viewer's buffer stays
|
|
46
|
-
comfortable (e.g. paused playback filling ahead)
|
|
47
|
-
- **THEN** no downshift happens
|
|
48
|
-
|
|
49
|
-
#### Scenario: Manual quality pinned
|
|
50
|
-
- **WHEN** the viewer picked a forced quality
|
|
51
|
-
- **THEN** link reports never trigger a downshift
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Tasks: Adaptive bitrate (proxy)
|
|
2
|
-
|
|
3
|
-
## 1. Caps
|
|
4
|
-
|
|
5
|
-
- [x] 1.1 `encode/hwaccel.js`: `RUNG_NOMINAL_KBPS` table + nearest-rung lookup;
|
|
6
|
-
software descriptor's video args emit `-maxrate`/`-bufsize`
|
|
7
|
-
(1.3× / 1.5× nominal for the actual encode height). Hardware
|
|
8
|
-
descriptors untouched.
|
|
9
|
-
|
|
10
|
-
## 2. Net report intake
|
|
11
|
-
|
|
12
|
-
- [x] 2.1 `routes/api/transcode-sessions/net-report/post.js`: validate
|
|
13
|
-
`{ linkMbps, bufferedAheadSec }`, store
|
|
14
|
-
`session.netReport = { linkMbps, bufferedAheadSec, at }`, 204/400/404.
|
|
15
|
-
- [x] 2.2 Wire in `server.js`; verify the data-channel path allowlist covers
|
|
16
|
-
the route.
|
|
17
|
-
|
|
18
|
-
## 3. Budget trigger
|
|
19
|
-
|
|
20
|
-
- [x] 3.1 Constants `LINK_REPORT_FRESH_MS`, `LINK_SAFETY`,
|
|
21
|
-
`LINK_SLOW_WINDOW_MS`, `LINK_LOW_BUFFER_SEC`.
|
|
22
|
-
- [x] 3.2 Observed produced bitrate (rolling, last ~5 segments) available to
|
|
23
|
-
the budget check.
|
|
24
|
-
- [x] 3.3 Link deficit accumulation + `#applyBudgetDownshift(session,
|
|
25
|
-
reason "link")`; skip on manualQuality/stale/comfortable buffer; log
|
|
26
|
-
reason distinctly.
|
|
27
|
-
|
|
28
|
-
## 4. Verification
|
|
29
|
-
|
|
30
|
-
- [x] 4.1 Unit: table lookup, arg assembly, trigger logic (fake clock):
|
|
31
|
-
deficit→downshift, stale report→no-op, high buffer→no-op,
|
|
32
|
-
manualQuality→no-op.
|
|
33
|
-
- [x] 4.2 `node --check` on touched files.
|
|
34
|
-
|
|
35
|
-
## 5. Release
|
|
36
|
-
|
|
37
|
-
- [ ] 5.1 CHANGELOG (next patch) + `npm run patch` (user OTP), then addon
|
|
38
|
-
bump + push + HA update. Release BEFORE the server reporter change.
|
|
39
|
-
- [ ] 5.2 Field: cellular Poirot/Mavka run shows `budget downshift (link)`
|
|
40
|
-
and bounded segment sizes; correlate via client-log pipeline.
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Proposal: Proxy as a single binary + service registration (research, queued)
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
Bare-npm installation assumes Node.js on the host — a real barrier for the
|
|
6
|
-
non-technical proxy owners the pool model targets. Node's Single Executable
|
|
7
|
-
Applications (SEA, stable-ish since Node 20/21) allow shipping the proxy as
|
|
8
|
-
one self-contained binary per platform (win/linux/macOS, x64/arm64): download,
|
|
9
|
-
run, done. A binary can also offer — with the user's explicit consent — to
|
|
10
|
-
register itself as an auto-starting service, closing the "survives reboot"
|
|
11
|
-
gap that the HA addon solves today.
|
|
12
|
-
|
|
13
|
-
## What Changes (research scope first)
|
|
14
|
-
|
|
15
|
-
- **SEA build pipeline**: `node --experimental-sea-config` + postject-injected
|
|
16
|
-
blob, one artifact per platform/arch, published as GitHub release assets
|
|
17
|
-
alongside the npm package.
|
|
18
|
-
- **Known hard parts to resolve in research**:
|
|
19
|
-
- Native addons (`node-datachannel`, `utp-native`) cannot live inside the
|
|
20
|
-
SEA blob — they must ship next to the binary or self-extract on first
|
|
21
|
-
run to a data dir.
|
|
22
|
-
- `ffmpeg-static`'s binary likewise ships alongside (or the system ffmpeg
|
|
23
|
-
is required, as the HA addon already does with `--ffmpeg-bin`).
|
|
24
|
-
- **Service registration (opt-in, explicit user action)**:
|
|
25
|
-
- Linux: `proxy install-service` writes a systemd unit and runs
|
|
26
|
-
`systemctl enable --now` (requires sudo — the consent step).
|
|
27
|
-
- Windows: register via `sc create` / a service wrapper (admin prompt =
|
|
28
|
-
consent).
|
|
29
|
-
- macOS: launchd plist in `~/Library/LaunchAgents` (user-level, no admin).
|
|
30
|
-
- Uninstall counterpart mandatory (`proxy uninstall-service`).
|
|
31
|
-
- Stays deployment-agnostic: the binary is a fourth distribution channel
|
|
32
|
-
next to HA addon, bare npm and Docker; no code paths may assume it.
|
|
33
|
-
|
|
34
|
-
## Capabilities
|
|
35
|
-
|
|
36
|
-
### New Capabilities
|
|
37
|
-
|
|
38
|
-
- `distribution`: how the proxy is packaged and installed on bare hosts.
|
|
39
|
-
|
|
40
|
-
### Modified Capabilities
|
|
41
|
-
|
|
42
|
-
<!-- none -->
|
|
43
|
-
|
|
44
|
-
## Impact
|
|
45
|
-
|
|
46
|
-
- Build/release tooling in this repo; a `service` CLI subcommand.
|
|
47
|
-
- No changes to runtime behaviour for existing channels.
|
|
48
|
-
|
|
49
|
-
## Priority
|
|
50
|
-
|
|
51
|
-
MINIMAL — explicitly NOT part of the POC (owner decision, 2026-07-07).
|
|
52
|
-
Research for the eventual "pool of non-technical owners" product goal; do
|
|
53
|
-
not pick up while any POC work remains.
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# Design: Chunked request bodies (proxy side)
|
|
2
|
-
|
|
3
|
-
Written to be executed as specified — the wire format, constants, limits
|
|
4
|
-
and do-NOT list are normative. Read before coding:
|
|
5
|
-
|
|
6
|
-
- `services/transport/data-channel-handler.js`: the whole file — the wire-protocol
|
|
7
|
-
doc comment (~lines 9–37), `handleChannel` (onMessage string handling),
|
|
8
|
-
`handleRequest`, `sendChunk` (the response frame writer whose layout the
|
|
9
|
-
request frames mirror), `send`.
|
|
10
|
-
|
|
11
|
-
## Wire protocol (additions)
|
|
12
|
-
|
|
13
|
-
Existing messages are UNCHANGED. New:
|
|
14
|
-
|
|
15
|
-
Browser → Proxy, announcing a chunked request:
|
|
16
|
-
{ type: "request-start", requestId, method, path, query, headers,
|
|
17
|
-
bodyBytes } // bodyBytes = exact total body size in bytes
|
|
18
|
-
|
|
19
|
-
Browser → Proxy, body frames (BINARY messages — today the proxy only
|
|
20
|
-
ever receives strings, so binary is unambiguous):
|
|
21
|
-
byte 0 flags bit 0: done (last frame)
|
|
22
|
-
bit 1: aborted (drop this request, no reply)
|
|
23
|
-
byte 1 idLen requestId length in bytes
|
|
24
|
-
bytes 2..2+N requestId (ASCII)
|
|
25
|
-
bytes 2+N.. payload raw body bytes (UTF-8 of the body string;
|
|
26
|
-
may be empty on a done/abort frame)
|
|
27
|
-
|
|
28
|
-
Identical layout to the response frames (`sendChunk`) — one mental model,
|
|
29
|
-
and the browser already has a parser for it (its builder mirrors it).
|
|
30
|
-
|
|
31
|
-
No capability negotiation: POC, single-proxy pool, lockstep releases
|
|
32
|
-
(proxy first, then server). The 16 MB `maxMessageSize` advertisement in
|
|
33
|
-
webrtc-manager.js (pending 2.9.35) stays as a one-line transition cover
|
|
34
|
-
for tabs still running the single-send bundle.
|
|
35
|
-
|
|
36
|
-
## Constants
|
|
37
|
-
|
|
38
|
-
PROXY_MAX_REQUEST_BODY_BYTES = 32 * 1024 * 1024
|
|
39
|
-
PARTIAL_REQUEST_TTL_MS = 60_000
|
|
40
|
-
|
|
41
|
-
## Assembly (all state per channel, inside `handleChannel`'s closure)
|
|
42
|
-
|
|
43
|
-
const partials = new Map(); // requestId → { meta, chunks: [], receivedBytes, timer }
|
|
44
|
-
|
|
45
|
-
- `request-start`: validate like a legacy request (same path allowlist —
|
|
46
|
-
run the SAME validation before accepting the body; reject with
|
|
47
|
-
`response-error` immediately on a bad path). Reject `bodyBytes` >
|
|
48
|
-
PROXY_MAX_REQUEST_BODY_BYTES with `response-error` "Request body too
|
|
49
|
-
large." and do NOT create state. Otherwise store `{ meta, chunks: [],
|
|
50
|
-
receivedBytes: 0 }` and arm the TTL timer.
|
|
51
|
-
- Binary frame: parse header; unknown requestId → ignore (stale/aborted).
|
|
52
|
-
bit 1 (aborted) → clear timer, delete entry, no reply. Append payload,
|
|
53
|
-
add to receivedBytes; receivedBytes > bodyBytes (or > the cap) →
|
|
54
|
-
`response-error` + drop. bit 0 (done): concat chunks → body string via
|
|
55
|
-
`Buffer.concat(...).toString("utf8")`; receivedBytes !== bodyBytes →
|
|
56
|
-
`response-error` "Request body size mismatch." and drop; else clear
|
|
57
|
-
timer, delete entry, and execute through the SAME code path a legacy
|
|
58
|
-
`request` message takes (factor `handleRequest` so both entry points
|
|
59
|
-
call one function with `{requestId, method, path, query, headers, body}`).
|
|
60
|
-
- TTL fire: delete entry, log
|
|
61
|
-
`[dc] Session …: dropped stale partial request <id8> (<receivedBytes>B)`.
|
|
62
|
-
- `channel.onClosed`: clear ALL timers and the map (extend the existing
|
|
63
|
-
handler — do not replace its logging).
|
|
64
|
-
|
|
65
|
-
## Logging
|
|
66
|
-
|
|
67
|
-
Chunked request execution logs the SAME `[dc] <method> <path>` line as
|
|
68
|
-
legacy, with `body=<bytes> bytes (chunked)`.
|
|
69
|
-
|
|
70
|
-
## Rules — do NOT
|
|
71
|
-
|
|
72
|
-
- Do NOT change the legacy `{type:"request"}` handling, the response
|
|
73
|
-
framing, ping/pong, or the path allowlist semantics.
|
|
74
|
-
- Do NOT add capability/version negotiation — POC decision, revisit only
|
|
75
|
-
when the pool has independently-updated proxies.
|
|
76
|
-
- Do NOT revert the 16 MB `maxMessageSize` advertisement (pending 2.9.35).
|
|
77
|
-
- Do NOT hold partial bodies beyond the TTL or channel lifetime; no global
|
|
78
|
-
(cross-channel) state.
|
|
79
|
-
- Do NOT create a new proxy version: fold into the pending 2.9.35
|
|
80
|
-
CHANGELOG entry (accumulate bullets, per the versioning rules) and the
|
|
81
|
-
pending addon 0.2.56 entry.
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Proposal: Chunked request bodies over the data channel (proxy side)
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
The browser sends every request as ONE data-channel message, body included.
|
|
6
|
-
Registering a source carries the base64-encoded `.torrent` as that body — a
|
|
7
|
-
big multi-season pack (Poirot, 13 seasons: 420 KB `.torrent` → ~560 KB
|
|
8
|
-
base64) exceeded libdatachannel's default advertised `a=max-message-size`
|
|
9
|
-
of 256 KB, so the browser's `send()` threw "Trying to send message larger
|
|
10
|
-
than max-message-size" and playback dead-ended.
|
|
11
|
-
|
|
12
|
-
The committed-but-unpublished stopgap (advertise 16 MB, pending 2.9.35)
|
|
13
|
-
lifts the ceiling but keeps the flaw: any single-message body still has a
|
|
14
|
-
hard cap, and a large message is buffered whole on both ends. Responses
|
|
15
|
-
already solved this properly — they stream as small binary frames. Requests
|
|
16
|
-
should be symmetric.
|
|
17
|
-
|
|
18
|
-
## What Changes
|
|
19
|
-
|
|
20
|
-
- **Inbound binary body frames.** The proxy accepts request bodies as
|
|
21
|
-
binary frames with EXACTLY the response-frame layout
|
|
22
|
-
(`[flags][idLen][requestId][payload]`, bit 0 = done; new bit 1 = aborted),
|
|
23
|
-
announced by a new `{type:"request-start", …, bodyBytes}` control message.
|
|
24
|
-
On the done frame the assembled body runs through the SAME request
|
|
25
|
-
execution path as a legacy request. Bounded: per-body cap 32 MB, partial
|
|
26
|
-
bodies dropped after a 60 s TTL or an abort frame, all per-channel state
|
|
27
|
-
freed on channel close.
|
|
28
|
-
- **No capability negotiation.** POC: the pool is one proxy, released in
|
|
29
|
-
lockstep with the site (proxy first, then server). The browser just uses
|
|
30
|
-
chunked frames for large bodies; this proxy just understands them.
|
|
31
|
-
- **The 16 MB `max-message-size` advertisement (pending 2.9.35) stays** —
|
|
32
|
-
a single config value, no logic: it covers the transition window while
|
|
33
|
-
already-open tabs still run the single-send bundle.
|
|
34
|
-
- **Observability**: the `[dc]` request log line reports chunked bodies
|
|
35
|
-
(`body=<bytes> bytes (chunked)`).
|
|
36
|
-
|
|
37
|
-
Browser-side counterpart (chunk writer, threshold, backpressure, abort) is
|
|
38
|
-
the server repo's `chunked-request-bodies` change. Release order: proxy
|
|
39
|
-
(with addon bump) FIRST, then server.
|
|
40
|
-
|
|
41
|
-
## Capabilities
|
|
42
|
-
|
|
43
|
-
### New Capabilities
|
|
44
|
-
|
|
45
|
-
- `chunked-request-bodies`: request-body transport over the data channel.
|
|
46
|
-
|
|
47
|
-
## Impact
|
|
48
|
-
|
|
49
|
-
- `services/transport/data-channel-handler.js` — binary inbound frame parsing;
|
|
50
|
-
per-channel partial-body assembly with caps/TTL; `request-start`
|
|
51
|
-
handling; shared execution path.
|
|
52
|
-
- Release: folds into the PENDING proxy 2.9.35 (extend its CHANGELOG entry;
|
|
53
|
-
do not create a new version) + ha-addon 0.2.56 (same rule).
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# chunked-request-bodies — delta spec (proxy)
|
|
2
|
-
|
|
3
|
-
## ADDED Requirements
|
|
4
|
-
|
|
5
|
-
### Requirement: Request bodies arrive in bounded binary chunks
|
|
6
|
-
|
|
7
|
-
The proxy SHALL accept a request whose body is delivered as binary frames
|
|
8
|
-
(mirroring the response-frame layout) announced by a `request-start`
|
|
9
|
-
control message, assemble it, and execute it through the same path as a
|
|
10
|
-
single-message request. Assembly SHALL be bounded: a per-body byte cap, a
|
|
11
|
-
TTL for incomplete bodies, an abort flag that drops the partial state, and
|
|
12
|
-
release of all partial state when the channel closes. Legacy single-message
|
|
13
|
-
requests SHALL keep working unchanged.
|
|
14
|
-
|
|
15
|
-
#### Scenario: Large .torrent registration
|
|
16
|
-
- **WHEN** the browser registers a multi-season torrent whose base64 body
|
|
17
|
-
exceeds any single-message limit
|
|
18
|
-
- **THEN** the body arrives in frames, the source registers, and the
|
|
19
|
-
response streams back exactly as for a small request
|
|
20
|
-
|
|
21
|
-
#### Scenario: Oversized or inconsistent body
|
|
22
|
-
- **WHEN** the announced or delivered size exceeds the cap, or the
|
|
23
|
-
delivered bytes do not match the announcement
|
|
24
|
-
- **THEN** the proxy replies with a response-error for that request and
|
|
25
|
-
drops the partial state; the channel and other requests are unaffected
|
|
26
|
-
|
|
27
|
-
#### Scenario: Sender vanishes mid-body
|
|
28
|
-
- **WHEN** frames stop arriving (tab closed, aborted without a frame)
|
|
29
|
-
- **THEN** the partial body is dropped after the TTL (or immediately on
|
|
30
|
-
channel close) and its memory is released
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Tasks: Chunked request bodies (proxy side)
|
|
2
|
-
|
|
3
|
-
Execute in order; design.md is normative. Read the code regions listed at
|
|
4
|
-
its top first.
|
|
5
|
-
|
|
6
|
-
## 1. Implementation
|
|
7
|
-
|
|
8
|
-
- [ ] 1.1 `transport/data-channel-handler.js`: factor the execution tail of
|
|
9
|
-
`handleRequest` so a legacy `request` message and an assembled
|
|
10
|
-
chunked request run the SAME function. `node --check`.
|
|
11
|
-
- [ ] 1.2 `request-start` + binary inbound frames + per-channel assembly
|
|
12
|
-
with cap (32 MB), size-mismatch check, abort flag (bit 1), TTL
|
|
13
|
-
(60 s), cleanup on channel close. Unknown-requestId frames ignored.
|
|
14
|
-
- [ ] 1.3 Logging: `body=<bytes> bytes (chunked)` on execution; stale-drop
|
|
15
|
-
line on TTL.
|
|
16
|
-
|
|
17
|
-
## 2. Verification
|
|
18
|
-
|
|
19
|
-
- [ ] 2.1 Node loopback test (two node-datachannel PeerConnections in one
|
|
20
|
-
script, like the SDP test): drive a request-start + 64 KB frames of a
|
|
21
|
-
~600 KB body through a real channel into a handler instance wired to
|
|
22
|
-
a stub local server; assert the assembled body bytes match and a
|
|
23
|
-
response comes back. Also: abort frame → no reply, state dropped;
|
|
24
|
-
oversized announcement → response-error.
|
|
25
|
-
- [ ] 2.2 Legacy regression: single-message request path byte-identical
|
|
26
|
-
behaviour (run an existing small request through both entry points).
|
|
27
|
-
- [ ] 2.3 E2E (after the server-side change lands in preview): local stack
|
|
28
|
-
— preview server + local proxy (`node bin/cli.js --server-url
|
|
29
|
-
ws://localhost:8080`), register the real Poirot `.torrent`
|
|
30
|
-
(C:\Users\AntonNemtsev\Downloads\Пуаро_….torrent, ~560 KB base64)
|
|
31
|
-
via the UI; plan returns; `[dc] … body=… (chunked)` in the proxy log.
|
|
32
|
-
|
|
33
|
-
## 3. Release
|
|
34
|
-
|
|
35
|
-
- [ ] 3.1 EXTEND the pending 2.9.35 CHANGELOG entry (do not bump again) and
|
|
36
|
-
the pending addon 0.2.56 entry.
|
|
37
|
-
- [ ] 3.2 `npm run patch` in proxy (publishes 2.9.35), push addon bump,
|
|
38
|
-
update the addon in HA; verify `Starting @torrent-tv/proxy v2.9.35`
|
|
39
|
-
in the addon log. Proxy FIRST, then addon, then the server-side
|
|
40
|
-
change releases independently.
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# Design: Cold-start reduction (proxy side)
|
|
2
|
-
|
|
3
|
-
Written to be executed as specified. Read before coding:
|
|
4
|
-
|
|
5
|
-
- `services/playback-planner.js`: `probeStreamCodecs` (how the ffmpeg banner
|
|
6
|
-
is parsed today), `getPlan` (prefetch → probe → pending loop → plan cache
|
|
7
|
-
and its key/invalidation).
|
|
8
|
-
- `services/hls-session-manager.js`: `probeInputMediaInfo` (~line 383 — what
|
|
9
|
-
it parses: durationSeconds, width, height, fps, startTime, isHdr),
|
|
10
|
-
`createSession` (~line 806: the probe call at ~817, keyframe probe at
|
|
11
|
-
~854), the segment-ready path (where segment 00000 first becomes
|
|
12
|
-
servable — grep the long-poll the `routes/transcode/session-file/get.js`
|
|
13
|
-
route uses).
|
|
14
|
-
- `services/torrent/torrent-pool.js`: `prefetchFileEdges` (~line 608) — signature
|
|
15
|
-
`(torrent, fileIndex, { headBytes, tailBytes, timeoutMs })`.
|
|
16
|
-
- `server.js`: how `playbackPlanner` and `hlsSessionManager` are constructed
|
|
17
|
-
and injected.
|
|
18
|
-
|
|
19
|
-
## 1. Media-info reuse (kill ffmpeg scan #2)
|
|
20
|
-
|
|
21
|
-
Both probes run ffmpeg over the same input URL and parse the same stderr
|
|
22
|
-
banner; they just extract different fields. Unify:
|
|
23
|
-
|
|
24
|
-
1. Extract the banner-parsing helpers that `probeInputMediaInfo` uses
|
|
25
|
-
(duration/width/height/fps/startTime/HDR detection) so the planner can
|
|
26
|
-
apply them to ITS probe's stderr. Where they live is the executor's
|
|
27
|
-
choice (export from hls-session-manager or move to a small shared
|
|
28
|
-
module) — do NOT duplicate the parsing logic.
|
|
29
|
-
2. In the planner, on a probe whose codecs were detected (the same condition
|
|
30
|
-
that allows caching the plan), build a `mediaInfo` object
|
|
31
|
-
`{ durationSeconds, width, height, fps, startTime, isHdr }` and cache it
|
|
32
|
-
ALONGSIDE the plan — same key, same lifetime, same invalidation. A
|
|
33
|
-
pending (empty) probe caches nothing, exactly like the plan.
|
|
34
|
-
3. Planner exposes `getCachedMediaInfo({ sourceKey, fileIndex })` →
|
|
35
|
-
`MediaInfo | null`.
|
|
36
|
-
4. `server.js` passes it into HlsSessionManager (new constructor option
|
|
37
|
-
`getCachedMediaInfo`).
|
|
38
|
-
5. `createSession`:
|
|
39
|
-
|
|
40
|
-
const cached = this.getCachedMediaInfo?.({ sourceKey, fileIndex }) ?? null;
|
|
41
|
-
const usable = cached
|
|
42
|
-
&& Number.isFinite(cached.durationSeconds) && cached.durationSeconds > 0
|
|
43
|
-
&& Number.isFinite(cached.width) && cached.width > 0
|
|
44
|
-
&& Number.isFinite(cached.height) && cached.height > 0;
|
|
45
|
-
const mediaInfo = usable ? cached : await probeInputMediaInfo(this.ffmpegBin, inputUrl.toString());
|
|
46
|
-
|
|
47
|
-
Duration/width/height gate the cache because downstream logic depends on
|
|
48
|
-
them (synthetic VOD playlist, resolution ladder); fps/startTime/isHdr
|
|
49
|
-
have safe defaults and do not gate. The probe stays as the fallback —
|
|
50
|
-
behaviour is unchanged whenever the cache cannot serve.
|
|
51
|
-
|
|
52
|
-
Keyframe probe (`probeVideoKeyframeTimes`) is NOT touched: it runs only on
|
|
53
|
-
the video-copy path and probes different data (packet flags, not the
|
|
54
|
-
banner).
|
|
55
|
-
|
|
56
|
-
## 2. Body-start prefetch
|
|
57
|
-
|
|
58
|
-
In `getPlan`, at the point where the probe succeeded and the plan is about
|
|
59
|
-
to be cached/returned, fire and FORGET:
|
|
60
|
-
|
|
61
|
-
void torrentPool.prefetchFileEdges(torrent, fileIndex, {
|
|
62
|
-
headBytes: BODY_PREFETCH_BYTES, // 16 MB
|
|
63
|
-
tailBytes: 0,
|
|
64
|
-
timeoutMs: 60_000
|
|
65
|
-
}).catch(() => {});
|
|
66
|
-
|
|
67
|
-
const BODY_PREFETCH_BYTES = 16 * 1024 * 1024;
|
|
68
|
-
|
|
69
|
-
No new torrent-pool method — `prefetchFileEdges` with `tailBytes: 0` is
|
|
70
|
-
exactly a head prefetch. Not awaited: the client's session-create follows
|
|
71
|
-
within a couple of seconds and ffmpeg reads sequentially behind the
|
|
72
|
-
prefetch. 16 MB ≈ 25 s of typical 5 Mbit media — covers the first segments
|
|
73
|
-
without denting the disk cap. Do NOT start it on pending polls (the header
|
|
74
|
-
prefetch must keep absolute priority while the probe is starving).
|
|
75
|
-
|
|
76
|
-
## 3. Stage timings
|
|
77
|
-
|
|
78
|
-
- `createSession` measures and logs (one line, existing logger, prefix
|
|
79
|
-
matches the session log style):
|
|
80
|
-
|
|
81
|
-
cold-start <sessionId8>: media-info=<ms> (cached|probed) keyframes=<ms|skipped> create-total=<ms>
|
|
82
|
-
|
|
83
|
-
- When the FIRST segment file of a fresh session becomes servable (the
|
|
84
|
-
long-poll in the session-file path returns it), log once per session:
|
|
85
|
-
|
|
86
|
-
cold-start <sessionId8>: first-segment ready +<ms since createSession entry>
|
|
87
|
-
|
|
88
|
-
Store the create-entry timestamp on the session object; guard with a
|
|
89
|
-
boolean so the line logs once.
|
|
90
|
-
|
|
91
|
-
## Rules — do NOT
|
|
92
|
-
|
|
93
|
-
- Do NOT change probe semantics, the pending/poll contract, or the plan
|
|
94
|
-
cache key.
|
|
95
|
-
- Do NOT prioritise body bytes before the probe has succeeded.
|
|
96
|
-
- Do NOT make session create fail on a cache problem — any doubt → fall
|
|
97
|
-
back to the probe.
|
|
98
|
-
- No behavioural change for the video-copy path beyond the timing lines.
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Proposal: Cold-start reduction (proxy side)
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
Field recordings (mobile tester, 2026-07-08) show ~90 seconds from picking an
|
|
6
|
-
episode to a picture. The proxy owns two chunks of that:
|
|
7
|
-
|
|
8
|
-
1. **A redundant ffmpeg input scan.** The playback planner probes the input
|
|
9
|
-
(`probeStreamCodecs`) and CACHES the plan — then `createSession` in
|
|
10
|
-
hls-session-manager immediately probes the SAME input again
|
|
11
|
-
(`probeInputMediaInfo`) for duration/resolution/fps/startTime/HDR. Each
|
|
12
|
-
probe is a full ffmpeg startup + banner scan over the torrent-backed HTTP
|
|
13
|
-
stream — seconds on the HA host, on the critical path, twice.
|
|
14
|
-
2. **First-segment piece latency.** The planner prefetches only the file
|
|
15
|
-
EDGES (256 KB head + 2 MB tail — what the codec probe needs). The first
|
|
16
|
-
segment's encode then needs the first ~10–20 MB of the file BODY, whose
|
|
17
|
-
pieces start downloading only when ffmpeg asks for them — while the swarm
|
|
18
|
-
sat mostly idle during the plan poll.
|
|
19
|
-
|
|
20
|
-
There is also no per-stage timing in the logs, so field regressions in
|
|
21
|
-
session startup are invisible.
|
|
22
|
-
|
|
23
|
-
## What Changes
|
|
24
|
-
|
|
25
|
-
- **Reuse the planner's probe in session create.** The planner parses and
|
|
26
|
-
caches the full media info (duration, width/height, fps, startTime, isHdr)
|
|
27
|
-
from the probe it already runs; hls-session-manager consults that cache
|
|
28
|
-
and skips its own `probeInputMediaInfo` on a hit (probe stays as the
|
|
29
|
-
fallback). One full ffmpeg scan disappears from the critical path.
|
|
30
|
-
- **Prefetch the file-body start once the plan is ready.** After a successful
|
|
31
|
-
probe, fire-and-forget prefetch of the first 16 MB of the file, so the
|
|
32
|
-
session's ffmpeg reads hit already-downloaded data instead of paying piece
|
|
33
|
-
latency at encode time.
|
|
34
|
-
- **Stage timings in the log.** Session create logs probe ms (and
|
|
35
|
-
cache-hit/probed), keyframe-probe ms, and the time from create to the
|
|
36
|
-
first servable segment — so cold-start is measurable per stage in the
|
|
37
|
-
field, next to the client-side summary line (server `cold-start` change).
|
|
38
|
-
|
|
39
|
-
Client-side counterparts (phase instrumentation, earlier prebuffer start)
|
|
40
|
-
live in the server repo's `cold-start` change. The two changes are
|
|
41
|
-
independent — no wire-format coupling, either releases alone.
|
|
42
|
-
|
|
43
|
-
NOT in this change (candidates for later, kept out deliberately):
|
|
44
|
-
next-episode speculative prefetch (bandwidth cost needs field data first);
|
|
45
|
-
encoder-side first-segment speed-ups (faster warm-up preset would need a
|
|
46
|
-
mid-stream switch — parked with transcode-quality 2.2b).
|
|
47
|
-
|
|
48
|
-
## Capabilities
|
|
49
|
-
|
|
50
|
-
### New Capabilities
|
|
51
|
-
|
|
52
|
-
- `cold-start`: proxy-side session startup latency behaviour.
|
|
53
|
-
|
|
54
|
-
## Impact
|
|
55
|
-
|
|
56
|
-
- `services/playback-planner.js` — parse + cache full media info; expose
|
|
57
|
-
`getCachedMediaInfo`; body-start prefetch after a successful probe.
|
|
58
|
-
- `services/hls-session-manager.js` — consult the cache in `createSession`;
|
|
59
|
-
stage-timing log lines.
|
|
60
|
-
- `server.js` — wire `getCachedMediaInfo` into the HlsSessionManager deps.
|
|
61
|
-
- Release: proxy `npm run patch` + ha-addon version bump (standard order:
|
|
62
|
-
proxy first, then addon).
|