hud-9: render native (SRT) subtitles in the HUD; stop persisting the layout override

ADDENDUM 10. Two more independent subtitle problems found on device.

1. Normal (non-ASS) subtitles never reached the HUD. Jellyfin's
   htmlVideoPlayer-plugin only routes ssa/ass through SubtitlesOctopus
   (`if (!['ssa','ass'].includes(codec))` -> pgssub/vobsub/custom-element/native);
   subrip falls through to the browser's own TextTrack rendering, so there is no
   libass canvas at all (measured with the CN SRT selected: 0 libass canvases,
   0 .videoSubtitles overlays, textTracks[0] = manualTrack/mode=showing/315 cues).
   No layout setting could have made that work.

   updateSource() now picks the source every XR frame: the libass canvas when it
   exists, otherwise the active TextTrack cue (fallback: the .videoSubtitlesInner
   overlay). The native text is cleaned, wrapped and painted white-on-black into a
   private 1920x1080 canvas that flows through the unchanged crop/upload/HUD path.
   prepare() is skipped when there is no libass canvas. New diagnostics:
   stats.subSource / stats.subNativeText, Subtitles.getSourceKind().

2. ADDENDUM 9 persisted state.subLayout, and a stale 'mono' in jfvr.settings.v1
   silently forced the mono branch on the default dual-eye content (dual:false,
   eyeW:4320, crop across the seam -> both eyes side by side). The override is now
   per-session: not saved, not restored, 'auto' at boot.

Verified on device with hud-9:
  CN_dual_eye (ass)   -> subSource=libass, dual=true, eyeW=2160,
                         crop=[1040,768,1176,924], copyND=0.055
  CN (subrip)         -> subSource=native, dual=false, eyeW=1920, text="进去了呢",
                         crop 256x88, uploads climbing
The private cue canvas was read back and OCR'd (cue "怎么样?好好地" -> "怎么样? 好好地"),
and injecting/removing a fake libass canvas flips subSource with no errors.
This commit is contained in:
2026-10-12 19:53:10 +08:00
parent 164d692791
commit 22dd482d69
6 changed files with 549 additions and 26 deletions
+66
View File
@@ -1069,3 +1069,69 @@ __JFVR.Subtitles.getLayout(): string
- On device (before the UI became unreachable): the broker change was observed to carry
SubtitlesOctopus's loop through `immersive-vr` (`rafId` in the plugin's id range,
`eventStart` tracking, `subUploads` 4 → 7 over 20 s in VR).
# ADDENDUM 10 — normal (non-ASS) subtitles: Jellyfin does not use libass for them
## 1. Why normal subtitles were invisible
The HUD samples `canvas.libassjs-canvas`. That canvas only exists when Jellyfin
routes the subtitle through **SubtitlesOctopus (libass)**. From
`htmlVideoPlayer-plugin` (`renderTracksEvents`):
```js
a = (n.Codec || '').toLowerCase();
if (!X.includes(a)) { // X = ['ssa','ass']
if (a === 'pgssub') -> renderPgs
if (Y.includes(a)) -> renderVobSub // Y = ['dvdsub','vobsub']
if (!u(h.fe)) -> renderSubtitlesWithCustomElement // DOM overlay
/* else falls through to the native TextTrack path */
}
return renderSsaAss(...); // ssa/ass ONLY
```
So `subrip`/`vtt`/… never reach libass. Observed on device with the `CN` SRT track
selected: `canvas.libassjs-canvas` count **0**, `.libassjs-canvas-parent` 0,
`.videoSubtitles` 0 — and `video.textTracks[0] = { kind:'subtitles', label:'manualTrack',
mode:'showing', cues:315 }`, i.e. the **browser** is rendering the cues through
`::cue`. There was nothing for the plugin to read, at any layout setting.
## 2. What the module does now
`updateSource()` runs every XR frame and picks the source:
- a `canvas.libassjs-canvas` with a non-zero size → `srcKind = 'libass'` (unchanged path);
- otherwise, if the player has a showing TextTrack or a `.videoSubtitlesInner`
overlay → `srcKind = 'native'`. The active text comes from
`textTracks[i].activeCues` (fallback: the DOM overlay's `innerText`), is cleaned
of ASS/HTML tags and bidi marks, wrapped, and painted — white with a black outline,
centred — into a private 1920×1080 canvas. That canvas is fed through the exact
same crop/bbox/upload code as the libass one.
- neither → `srcKind = 'none'` and the strip is cleared once.
`prepare()` is a no-op without a libass canvas (blowing up the player box is only
needed so libass re-renders bigger; the native canvas is ours).
New diagnostics: `stats.subSource` (`'libass' | 'native' | 'none'`),
`stats.subNativeText`; `__JFVR.Subtitles.getSourceKind()`.
## 3. The persisted layout override was a trap
ADDENDUM 9 persisted `state.subLayout`. A stale `'mono'` in `jfvr.settings.v1`
silently forced the mono branch on the default **dual-eye** content: `dual:false`,
`eyeW:4320`, and a crop spanning the seam, so the HUD showed both eyes' text side by
side. Debugging that cost more time than the detection itself.
`subLayout` is therefore **not persisted** (same reasoning as `subtitles` and
`subMode:'off'` — a stored value that leaves the layer looking broken). It is
`'auto'` at boot, toggleable per session from the panel.
## 4. Verification (on device, build `hud-9`)
| selected track | `subSource` | result |
|---|---|---|
| `CN_dual_eye` (ass, idx 0) | `libass` | `dual:true`, `eyeW:2160`, `crop:[1040,768,1176,924]` (left half), `copyND:0.055`, uploads climbing |
| `CN` (subrip, idx 1) | `native` | `dual:false`, `eyeW:1920`, canvas 1920×1080, `text:"进去了呢"`, `crop` 256×88, uploads climbing |
The private cue canvas was read back and OCR'd ("怎么样? 好好地" for cue
"怎么样?好好地"), and injecting/removing a fake `canvas.libassjs-canvas` flips
`subSource` between `libass` and `native` with no errors.