Repository navigation
Image subtitles turned on mid-play show the read-ahead window's lines instead of a ~10 s gap - #1393
Merged
Merged
Conversation
…them when one is turned on The main demuxer reads about ten seconds ahead of the playhead. While no subtitle was selected, SubTracks::decode dropped every image-track packet, so an image track (PGS) turned on mid-play showed nothing until the read-ahead had been used up, while a text track answered at once because text cues are observed whatever the selection. SubTracks now keeps an owned copy of each image packet while the gate is closed (ImageBacklog: per track, from the last packet at or before the playhead onward, with no cap of its own; the playhead is CaptionRetention::anchor_ns, the earlier of playhead and seek target, and an unknown playhead retires nothing). The demux loop checks on every packet it reads whether a subtitle is on and, if so, decodes the backlog in file order per track through the same decoder a live packet takes, ahead of the packet just read, emitting under the current generation. A seek and a close discard it. The decode feeds a scratch packet pointing at the owned bytes: no new FFmpeg symbol or struct offset. CaptionRetention::anchor_ns is the one definition of the measuring point; subtitle_floor_ns now uses it instead of its own copy of the seek-target rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g selection, drop test-only members, test a mid-read flip A selection that lands between the demux loop's release check and the subtitle branch's own read of it no longer decodes the current image packet ahead of the held ones: the packet is held and released with the next read. The backlog's test helpers move into its test module, and the end-to-end test gains the case that matters on the television, a track turned on between the 0 s display set and its 8 s clear. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ests both call, PGS sets kept whole from their PCS, live stream table The demux loop's subtitle step lived in ff.rs and the end-to-end tests drove a hand-written copy of it, so reverting every ff.rs change left them green. The release-if-selected check, the decode gate, decode-or-hold and the seek discard are now SubTracks methods (release_if_selected, on_packet, discard_held) that demux() and the tests both call; hold and release_held are private, so a test cannot reach around the gate. A new test lands the selection between a packet's release check and its decode, the race the gate closes. A PGS display set is one packet in Matroska but one packet per segment (PCS, WDS, PDS, ODS, END) from libavformat's MPEG-TS demuxer, so keeping only "from the last packet at or before the playhead" could drop the PCS and ODS of the set on screen and leave a lone END. For PGS tracks the backlog now retires only up to the PCS of the newest set at or before the playhead; the other image codecs keep the packet rule. The held packets and the live packet are read through (*fmt).streams with its bound, not the table captured at open, which a transport stream reallocates when it grows streams (AVFMTCTX_NOHEADER). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e backlog on an allocation failure, pin the padding ImageBacklog::take returned the held packets one whole track after another, so the bitmap store (push_subtitle_bitmap_locked) got a track-grouped batch where it documents and relies on demux (increasing-pts) order for its budget eviction. Every held packet now takes a read sequence number at hold time and take merges the tracks by it: exactly the order the demuxer read them, with no dependence on a timestamp a packet may lack. release_held took the backlog before checking the scratch packet allocation, so a failed av_packet_alloc silently dropped every held packet. It allocates first now; on failure it logs one line and leaves the backlog held for the next packet's release check. INPUT_PADDING is pinned against the bundled headers in ci/ffabi-assert.c instead of claiming to match every FFmpeg the app links, and request_subtitle's comment names the mechanism that replaced the desired_sub_idx gate it used to cite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
present_zlib_fixture indexed the stream table with the packet's stream_index unchecked; it now resolves it through the demux loop's bounded live_stream (exported via ff_test_support) and skips a packet the table does not describe. Co-Authored-By: Claude Opus 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.
Problem
Turn on an image subtitle track (PGS, VobSub, DVB) during playback while subtitles are Off, and nothing appears for about as long as the player reads ahead. On a 4K direct play that was ~10 s. Text tracks (SRT and others) show up straight away.
Cause: the main demuxer (
play-feed/src/ff.rs) reads ahead of the playhead. Text-track cues are kept for every track. Image-track packets were decoded only while some subtitle was on, and thrown away otherwise. Switching from one image track to another was fine; only Off → image had the gap.Fix
While subtitles are Off,
SubTracks(play-feed/src/ff_subs.rs) keeps an owned copy of each image-track packet in anImageBackloginstead of dropping it. On the first packet read after a subtitle is selected, the backlog is decoded through the existing image decoders, in demux order across tracks, before the live packet. It is then emitted under the current generation, exactly like live cues.CaptionRetention::anchor_ns(): the earlier of the playhead and the seek target, now also used bysubtitle_floor_ns. Memory is bounded by the read-ahead window. For PGS (hdmv_pgs_subtitle), the cut moves back to the newest display set's PCS (0x16). In M2TS/TS each segment is its own packet: the bundled FFmpeg 9.0.2 has no PGS parser and mpegts emits one packet per PES.SubTracksmethods.demux()and the tests both call them. The gate also requires an empty backlog, so a selection that lands mid-packet cannot put a live packet ahead of the held ones.av_packet_allocscratch packet withbuf == NULL.INPUT_PADDINGis pinned againstAV_INPUT_BUFFER_PADDING_SIZEinci/ffabi-assert.c. If the allocation fails, the backlog stays held for the next packet and one log line is written.(*fmt).streamsinstead of the stream table captured at open, which goes stale when a transport stream adds streams.Verification
Regression tests, red before the fix, green after:
backlog_testsinff_subs.rs(retention, PGS segment framing, demux order).media/src/ff_image_subtitle_tests.rs, run with the host build and--ignored: flip after the read, flip mid-read, a selection racing the decode, and a seek discard.Gates on the committed tree:
make test-crate C=plx_play_feed: 322 passedmake test-crate C=plx_media: 2134 passedmake test-crate C=plx_playback_contract: 42 passedmake check-nodef: cleanci/check-deps.sh: greenci/ffabi-assert.ccompiled for the host only, plus a negative control.make checkand the ARM build are left to CI.On the dev TV (webOS 4.5): debug build, guest on
tests/mock_pms.py, a 3-minute 1080p H.264 clip with one PGS track (a cue every 10 s, held 8 s), subtitles Off at start.image cue [0ms]andimage cue [10000ms]were both emitted at the flip, then 20, 30, 40 and 50 s on schedule.Not covered by a host test: the three call sites in
demux(). The only PGS test file has no video, sodemux()cannot open it. The TV run above covers them.Reviews: pr-reviewer (one round; all findings addressed), fw-compat-reviewer (source-only: no new imports or
DT_NEEDED; the AVPacket use is valid for the bundled FFmpeg), doc-claim-auditor (two stale comments fixed).Known limits
Observed during the TV run and not caused by this change: the track menu open over 1080p video ran at ~40 fps, and 60 fps came back when it closed, with subtitles still drawing. The cause was not determined.
🤖 Generated with Claude Code