Repository navigation
fix(subtitles): gate synthetic PGS END flush on a complete object (#112) - #113
Merged
Merged
Conversation
…#112) The synthetic END flush (a9b493a) feeds a 3-byte 0x80 END after any PGS packet that decoded with gotSub=0 and >30 bytes, to rescue MKV converters that strip the trailing END from each display set. That assumed every packet carries a COMPLETE display set (only the terminator missing). On a Blu-ray M2TS the mpegts demuxer splits one display set across several PES packets (PCS | WDS | PDS | ODS | END). The flush then fired on the PCS/PDS intermediate packet, BEFORE the ODS arrived, and forced pgssubdec to compose against an object that was not defined yet: "[pgssub] Invalid object id 0", once per display set (issue #112, ijuniorfu's Blu-ray on AetherPlayer/macOS). Gate the flush: synthesize the END only when the decoded payload already carries a complete object (an ODS whose last-in-sequence flag is set) and no END of its own. That still rescues the MKV case (a full block missing only its END) and never fires on a split-M2TS fragment, so the object is always defined before the forced compose. The gate walks the effective payload (raw TS, or the stripped/inflated buffer for PG-PES and zlib/gzip Matroska), so it is correct across all delivery paths, and it can only REMOVE premature composes: correct cases (real END present, or complete object present) are unchanged. Pure segment-walk gate is unit-tested against the split-M2TS fragment, the MKV missing-END block, split-ODS fragments, and malformed lengths. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HFZVoTDayyEfpqrY8ohNyg
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
Selecting a PGS subtitle track on a Blu-ray logs
[pgssub] Invalid object id 0persistently (once per display set), reported by ijuniorfu on AetherPlayer/macOS (#112).Root cause
The synthetic END flush (a9b493a) feeds a 3-byte
0x80END after any PGS packet that decoded withgotSub=0and>30bytes, to rescue MKV converters that strip the trailing END from each display set. That assumed every packet carries a complete display set (only the terminator missing).On a Blu-ray M2TS the mpegts demuxer splits one display set across several PES packets (
PCS | WDS | PDS | ODS | END). The flush then fired on the PCS/PDS intermediate packet, before the ODS arrived, forcingpgssubdecto compose against an object not yet defined:Invalid object id 0, once per display set. Unlike a seek-into-mid-epoch artifact, it never self-heals because it re-triggers on every set.Fix
Gate the flush: synthesize the END only when the decoded payload already carries a complete object (an ODS whose last-in-sequence flag is set) and no END of its own.
Tests
New
PGSSyntheticEndGateTestsunit-tests the pure segment-walk gate against the split-M2TS fragment, the MKV missing-END block, split-ODS fragments, a real END, and malformed lengths. Full suite (447) green; strict-concurrency and tvOS-Simulator builds clean.🤖 Generated with Claude Code