Skip to content

vo_kitty: keep shared frames intact until the terminal reads them - #18928

Open
yucheng-du wants to merge 2 commits into
mpv-player:masterfrom
yucheng-du:fix/kitty-shared-frame-lifetime
Open

yucheng-du wants to merge 2 commits into
mpv-player:masterfrom
yucheng-du:fix/kitty-shared-frame-lifetime

Conversation

@yucheng-du

Copy link
Copy Markdown

Fixes #18899.

mpv reused one shared memory name before the terminal had finished reading the previous frame. On macOS, resizing that object failed and the frame never reached the terminal. Thanks to @mschirrmeister for tracing this.

Create shared objects exclusively and reuse a name once the terminal has unlinked it. If all three names are busy, send that frame inline. The first commit fixes the inline path for images that fit in a single chunk.

Tested on Apple Silicon with a 48-frame, 24 fps clip. With the final paused redraw, mpv 0.42.0 sent 25 of 49 frames when the receiver left the name linked. With this change, all 49 RGB payloads matched direct transfer, in order, with immediate reads, reads delayed by one or five frames, and a receiver that never unlinked. Also checked a terminal resize, single-chunk frames, and cleanup on exit. The same cases passed under ASan/UBSan, and all 41 Meson tests passed.

AI assistance: Codex with GPT 6.2 Astra (ultra reasoning effort).

Mark the first chunk as final when it contains the whole image. Small
frames previously left the terminal waiting for a continuation.
Opening the same object for each frame could overwrite an unread image.
On macOS, sizing that object again failed and discarded every other
frame while the terminal still had the name.

Create up to three objects exclusively and send a frame inline when
all three are pending. This keeps memory use bounded even if the
terminal never unlinks a name.
@mschirrmeister

Copy link
Copy Markdown

Tested on macOS 27.2.1 (Apple M5 Pro) in Ghostty 1.4.1: this fixes #18899 for me. I compared the PR (2b8365d) with its parent commit (6a98198), using the 1080p testsrc2 clip from the issue, 10 s, 241 frames.

In Ghostty, the parent commit sent 163 and 192 frames in two runs (15.9 and 18.8 fps). The PR sent all 241 both times (23.6 fps), all through shared memory, with no errors in the log. Watching it, the wave line is now smooth with the PR, where it stuttered before.

The single-chunk fix also works: small inline frames now start with m=0.

I also tried a test reader that unlinks late. When it's 1 or 2 frames behind, every frame still goes through shared memory. From 3 frames behind, frames go inline, and at this window size one inline frame is about 24 MB of base64. The frame rate drops to 18.8 fps at 3 frames behind, 10.8 fps at 5, and 7.3 fps for a reader that never unlinks (11.9 fps before the PR). Ghostty never hit the fallback, so this is just a question: was dropping the frame (or more slots) considered for the case when the terminal falls behind? I can see why inline is safer for the last frame before a pause and for terminals that never unlink.

Note: Builds, scripts and measurements were done with help from Claude (Anthropic). I checked the result myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vo_kitty: --vo-kitty-use-shm=yes silently skips every second frame on macOS (same shm name for every frame)

2 participants