Repository navigation
player: image subtitles scale from the canvas they were authored against - #9
Merged
Merged
Conversation
A decoded PGS/VobSub rect's x/y/w/h are in the SUBTITLE stream's own authoring canvas, not in screen pixels. We composited them 1:1 into our 1920x1080 UI and said so in a comment — which is right for Blu-ray PGS and wrong for everything else: a DVD VobSub rip is authored on 720x480, so it landed as a postage stamp in the upper-left quadrant, and a 4K-authored PGS track drew at double size with half of it off the panel. The track menu offers those tracks and badges them, so the failure was reachable from the UI with no warning. The canvas now comes off the decoder and travels with the cue to the renderer, which stretches the display set into the video rect — the same stretch the TV applies to the picture itself, since a subtitle canvas is the video's own storage grid. A 1920x1080 canvas is exactly identity, so every PGS track in the library renders as it did before; an undeclared canvas (0) falls back to 1:1, which is what the whole path did unconditionally. Reading it is FFI into the TV's own libavcodec, so it is done WITHOUT a new struct offset: `avcodec_parameters_from_context` copies the decoder's dimensions into the AVCodecParameters this crate already models, so the read runs inside the library's own code. That it does so for subtitles at all is not a header claim — the device's `libavcodec.so.57.89.100` is stripped, so the subtitle case (`cmp r3,#3`) and the exact loads (`ldr r2,[r5,#124] / ldr r3,[r5,#128]` into par+48/+52) were read out of its disassembly, which incidentally corroborates `OFF_CTX_WIDTH`/`OFF_CTX_HEIGHT` and the modeled sizeof=136. A canvas outside 160..8192 is reported as unknown rather than used, because scaling by a garbage ratio is worse than not scaling at all. Two smaller fidelity losses on the same path, both from the same audit entry: * EVERY rect of a display set is decoded and drawn, not just rect 0. Two-line dialogue and sign-plus-dialogue are authored as separate rects of one set, so the old code silently dropped half the line and logged that it had. The store now holds a set of rects per cue, which also makes the supersede rule correct by construction — pushing rects individually would have had the second one close the first at its own start. The 24 MB ceiling counts a set's rects together, and a pathological set is capped at 8 rects. * image cues lift clear of the transport like text cues do. They lift by their overhang rather than by a fixed offset, so a full-height set is clamped instead of pushed off screen. The shift is measured over — and applied to — only the rects that actually overhang: measuring the whole set lets a sign at y=100 clamp the lift to 100, sliding the sign for no reason and leaving the dialogue behind the scrim anyway. It is not per-rect either, because two-line dialogue is two rects with different overhangs and lifting each by its own collapses them onto each other. Both paths now take the same `subs_lift` expression from app.rs (an open track menu counts — that is exactly when the bottom of the screen is being read) and share the baseline/ceiling constants. The store's byte ceiling had to change ends. `v[0]` is the cue AT the playhead once the time-retain has run, and the tail is the demuxer's 10-20s read-ahead, so evicting index 0 blanked the subtitle being read while keeping cues nobody had reached. A set costing up to 8 rects instead of 1 is what made that reachable. It now drops a cue the playhead has already passed, and only falls back to the far end of the read-ahead when there is none; the test fails against the old policy. Two guards on the decode side went in with it: `rect_to_rgba` null-checks the rect (the loop walks up to 8 now, not just [0]) and bounds w/h before multiplying, since `usize` is 32 bits here and a wrapped `w*h*4` would size the buffer below what the write loop and glTexImage2D then read. The renderer keeps one texture per rect and re-specs the ids it can reuse, so the steady one-rect case still never allocates twice; its cache key gains the selected track, because two image tracks of one file routinely start a display set on the same pts and the timestamp alone left the outgoing track on screen. Tests: +7 host (65) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc
Goo6i
added a commit
to Goo6i/plx-native
that referenced
this pull request
Oct 24, 2026
An Arabic or Hebrew paragraph (its first strong character, UAX plxnative#9 P2/P3) is drawn right-aligned in a left-aligned TextView; a wrapped line that opens with a Latin word keeps the paragraph's direction with an RLM. A truncated block dissolves at its left end into a MORE on the left, and the About card's MORE follows. Marquees glide mirrored: a right-to-left run rests on its first words at the window's right edge and moves right; the paused player title reveals its end to the left. Signed-off-by: Goo6i <[email protected]>
GLinnik21
pushed a commit
that referenced
this pull request
Oct 29, 2026
Arabic and Hebrew in titles, summaries, cast names and menus drew as boxes. They now draw shaped and in reading order, through the HarfBuzz, FriBidi and FreeType that libass-plx already bundles. No crate is added and the screen layout stays left-to-right. - libass-plx ABI 4: `src/ass_text.c` adds five `plx_ass_text_*` calls (bidi levels and order, shaping, raster). `NATIVE_ABI` is 4 in `player/ass.rs` and in the new `gfx/src/rtl.rs`, a gated `dynlib!` table loaded by absolute path from the app directory. Without the library, or at another ABI, Arabic and Hebrew draw as boxes as before; subtitles and RTL UI text share `libass-plx.so.0`, so a library at the wrong ABI turns both off. The Makefile keeps `ass_text.c` out of the app ELF, so no FreeType/HarfBuzz/FriBidi symbol is added to `plxnative`. - Fonts: Noto Kufi Arabic 2.110 and Noto Sans Hebrew 3.001, regular and bold, unmodified (OFL 1.1, 312 KB), fetched by `tools/fetch-noto-rtl.py`, in every font list; `ci/test_shipped_faces.py` holds the lists to the files `text.rs` opens. - Layout: Arabic and Hebrew are links 4 and 5 of the fallback chain. A line holding right-to-left text is cut into bidi runs; shaped runs go through the facade, the rest through SDL2_ttf as before. Latin, CJK and emoji text draw as before. - Direction follows a paragraph's first strong character (UAX #9 P2/P3). Right-to-left summaries are right-aligned with the fade and MORE on the left, marquees rest on their first words and glide right, and each wrapped line is pinned to its block's direction (RLM in a right-to-left block, LRM in a left-to-right one), since each drawn line is its own FriBidi paragraph. - `plx_ui::label` gains `HAlign::Start`, resolved by the line's direction; `TextView` and the About card's title and genres use it instead of a screen-local rule. Tests: 49 new, plus the LRM and `HAlign::Start` tests. The firmware load matrix grades `plxnative` and `libass-plx.so.0` OK on 4.4.2 to 11.2.0; the armv7 binary grows about 16 KB. Checked by the author on a webOS 6.5.3 set with Arabic metadata (Home, Library, Detail, About card); the subtitle track menu was not checked on a set. The Arabic was reviewed by a native speaker; no Hebrew reader has reviewed the Hebrew. Closes #760 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unit 14 — parity-gaps.md: "Image-subtitle bitmaps are drawn at raw stream coordinates with no scaling from the subtitle canvas — VobSub/DVD subs land as a postage stamp" (
major/small), plus thepolish/smallfollow-up "PGS/VobSub image subtitles don't lift for the HUD, and only rect 0 of a multi-rect display set is drawn".What was wrong
A decoded PGS/VobSub rect's
x/y/w/hare in the subtitle stream's own authoring canvas, not in screen pixels. We composited them 1:1 into our 1920x1080 UI and asserted in a comment that this was correct. It is correct for Blu-ray PGS and wrong for everything else: a DVD VobSub rip is authored on 720x480 and landed as a postage stamp in the upper-left quadrant; a 4K-authored PGS track drew at double size with half of it off the panel. The track menu offers those tracks and badges themVOBSUB, so the failure was reachable from the UI.What changed
ff::sub_canvasreads the canvas off the decoder after each decode; it travels with the cue through the store to the renderer.player_hud::sub_screen_rectstretches the display set into the video rect — the same stretch the TV applies to the picture, since a subtitle canvas is the video's own storage grid. A 1920x1080 canvas is exactly identity (1920.0/1920.0 == 1.0,x * 1.0 == x), so every PGS track in the library renders as it did before. An undeclared canvas (0) falls back to 1:1 — today's unconditional behaviour.subs_liftexpression fromapp.rs.Scaled content is not
gfx::snapped, per the crispness contract.Did I prove the ABI against the device's own binaries? YES — and no new offset was added
No new struct-field offset is introduced by this change. The canvas is read through the library's own
avcodec_parameters_from_context, which copies the decoder's dimensions into theAVCodecParametersthis crate already models (width/heightat +48/+52 — the same fields the video path has read on-device since the demuxer landed). The read therefore runs inside libavcodec's own code, which is thebind-tv-lib-abiskill's preferred route ("prefer the library's own name-based API — no offset, no risk").Two things were proven against the device, not inferred:
tools/abi-probe.sh has libavcodec.so.57 avcodec_parameters_alloc avcodec_parameters_free avcodec_parameters_from_context→ allPRESENTon the device's ownlibavcodec.so.57.89.100. Recorded in the extern block, because the stub.solinks either way.avcodec_parameters_from_contextactually handles subtitles. The device build is stripped, so a header claim would be worthless. I pulled the library and disassembled the function with the NDK'sobjdump:The subtitle case is present in this build, and this incidentally corroborates three offsets already in
ff.rsfrom an independent direction:OFF_CTX_WIDTH/OFF_CTX_HEIGHT(124/128) andAVCodecParameters.width/height(48/52). The prologue'smemset(par, 0, 136)likewise confirms the modeledsizeof == 136. The whole derivation is insub_canvas's doc comment so it is not lost.A canvas outside
160..8192is reported as unknown rather than used — scaling by a garbage ratio is worse than not scaling.Device verification: deferred to coordinator
I did not run anything on the TV. I queued for the shared lock, never acquired it, and killed the job on the coordinator's instruction. The TV was never touched by me — no deploy, no launch, no stale binary. (I did pull
libavcodec.so.57off the device read-only for the disassembly above.)Case to run
Toy Story 2 (
rk=1919, HEVC 4K direct-play). The harness seedsviewOffsetto 600000 ms (10:00) and selects the PGS track from the track menu (tab 1, row 1) once playing, so a cue should appear within seconds of the switch.--no-earlyruns the full 90 s so there is a comfortable capture window; the existing assertions (directplay,codec_id=174,min_video_width=3000, timeline climb, noPlaying error, video bound) are the regression gate.What to look for in
/tmp/plxnative-events.log— the new evidence is thecanvas=field:canvas=1920x1080→ the canvas read works and the render is byte-identical to before (scale is exact identity). This is the expected result for a 1080p-authored PGS track and is a clean pass.canvas=3840x2160→ this track is 4K-authored, and the fix is visible: the old build drew it at 2x with half off the panel; it should now sit correctly.canvas=0x0→ the decoder declared nothing, so the 1:1 fallback is in play. Not a crash and not a regression, but it means the canvas read did not fire for PGS and the VobSub case would still be unfixed — worth reporting back.rects=should normally be 1; a 2 is the multi-rect path working.Capture — service capture only
taken while a cue is up. The in-app capture stream (
/tmp/plxnative-capture, TCP :8910) cannot see this at all —capture.rsgrabs the app's own GLES frames, i.e. the UI plane only, and the subtitle composites over the hardware VIDEO overlay plane.DISPLAYis the composited panel output and is the only evidence. (VIDEOalone would show the picture without the subtitle;GRAPHICalone shows the subtitle without the picture — that pair is a useful split if something looks wrong.)What the frame should look like if the scaling is right
A PGS dialogue line on a 1920x1080 canvas is a wide, short strip: roughly 60-85% of the frame width (~1150-1650 px), 6-10% of its height (~70-110 px), horizontally centred, sitting in the bottom sixth of the frame (top edge around y≈900-1000 of 1080). Failure signatures:
One more check, free while you are there: with a cue on screen, press any key to raise the transport. The bitmap should rise so its bottom edge sits at y = 780 (
SCR_H - 300), clear of the scrubber — matching where text subtitles lift to. It should not move if it was already above that line.No VobSub item exists to test against. I scanned all 477 movie + episode items on the PMS via
/library/metadata/{rk}: every image-subtitle track in the library ispgs. There is novobsub/dvd_subtitleanywhere, so the 720x480 path cannot be exercised on this server and is covered by host tests only. That is the one gap in this verification, and it is a library limitation, not a skipped step.Tests
make check— 65 passed (58 baseline + 7 new),make(ARM cross-build) clean, no new warnings.Per the stated boundary, the new tests exercise the arithmetic, not the FFI (
ff.rs's#[link]directives arecfg_attr(not(test))-gated, so a test that calls FFmpeg cannot link):image_sub_1080p_canvas_is_identity— the 1920x1080 regression guard, asserted exactimage_sub_dvd_canvas_fills_the_panel— 720x480, the bug this unit exists forimage_sub_pal_and_4k_canvases— 720x576 and 3840x2160 (the latter scales down)image_sub_unknown_canvas_stays_1to1— the 0 / negative fallbackimage_sub_lifts_only_over_the_transportandimage_sub_lift_spans_only_the_rects_that_overhang— the lift, including sign-plus-dialogue and two-line dialoguean_image_display_set_round_trips_whole_and_is_superseded_as_a_unit(player/mod.rs, takes the crate-widetestlock) — the multi-rect store, the supersede handover, and the eviction order belowReview pass
An independent reviewer went over the diff for memory safety, GL texture lifetime, arithmetic and cross-thread invariants. Everything it found is fixed in this commit:
v[0]is the cue being drawn once the time-retain has run, and the tail is the demuxer's 10-20 s read-ahead — so the budget blanked the subtitle being read and kept ones nobody had reached. A set costing up to 8 rects instead of 1 is what made it reachablehud_liftmeasured the whole set, so a sign at y=100 clamped the lift and left the dialogue behind the scrimrect_to_rgbadid not null-check the rect pointer — the loop now walks up to 8, not just[0]w*h*4can wrap:usizeis 32-bit on this target, and w/h are unvalidated decoder output. A wrapped product sizes the buffer below what the write loop andglTexImage2Dthen readchecked_mulstart_nsalone, but two image tracks of one file routinely start a set on the same pts — a switch left the outgoing track on screen(track, start_ns); both halves reset togethertests/README.mddocumented the oldimage cueformatThe reviewer confirmed no texture leak, double-delete, draw-after-delete or stale draw across every early-return and both the grow and shrink directions, and that the 1080p path is bit-identical.
🤖 Generated with Claude Code
https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc