Repository navigation
fix(subtitles): decode bitmap subtitles off the MainActor (AE#628) - #635
Merged
Merged
Conversation
Enabling a PGS track on a Blu-ray remux put imageForSubtitleRect at the top of the Main Thread profile under subtitleDrainTick. Every display set was expanded pixel by pixel on the MainActor, twice per set (alpha bounding box, then RGBA), and a selection or seek backfilled a whole 75 s window in one tick. The Phase D OCR worker decoded the same packets a second time there. - The drain tick is split into prepare (MainActor), decode (detached) and finish (MainActor). One tick at most is in flight; a tick asked for meanwhile is queued. A channel re-selected, cleared or rebuilt while its batch decoded is skipped with its cursor unmoved, and stopping the drainer drops the batch by serial. - The OCR worker plans and resolves on the MainActor and decodes in its own detached loop. - imageForSubtitleRect resolves the palette once into a premultiplied lookup table and scans rows for the crop, byte-identical output. Full 1080p set on an M1: 5.08 -> 1.31 ms release, 215 -> 52 ms debug. Verified with aetherctl play on a generated full-canvas 1920x1080 PGS track: identical cue windows on main and on this branch, across a seek. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014AVNwe8YDG9EQM7uHdjT3f
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.
Refs #628.
imageForSubtitleRectwas the top Main Thread frame with a PGS track enabled. Two causes, both fixed:The overlay drain decoded on the MainActor. Each display set was expanded there. A selection or seek backfilled the whole 75 s window in one tick, and the Phase D OCR worker (PiP/AirPlay rendition) decoded the same packets a second time on it.
subtitleDrainTickis split intoprepareSubtitleDrainTick(MainActor), a detached decode, andfinishSubtitleDrainTick(MainActor). The drain loop goes throughrequestSubtitleDrainTick. At most one tick is in flight; a tick asked for meanwhile is queued, because the decoders are not reentrant.finishskips a channel whose target or decoder changed while its batch decoded (re-selection, teletext rebuild, clear). The cursor does not move, so the next tick redoes it.stopSubtitleDrainerdrops the in-flight batch by serial.subtitleDrainTickstays for the teletext page change and for tests, and queues itself if a tick is in flight.The blit was per pixel, twice. It now resolves the palette once into a premultiplied lookup table and finds the crop by row scans. Output is byte-identical to the old blit (a reference test pins it). Full-canvas 1080p set with one text band, M1:
The debug figure matters: a host running a Debug build of the package paid about 200 ms of main thread per bitmap.
Verification
swift test: 3504 swift-testing tests (5 new inIssue628PGSOffMainDecodeTests) and XCTest all green.aetherctl play --subs pgssubon a generated Blu-ray-shaped track (full 1920x1080 ODS per set), with one seek: identical cue windows onmainand on this branch.🤖 Generated with Claude Code
https://claude.ai/code/session_014AVNwe8YDG9EQM7uHdjT3f