Skip to content

fix(subtitles): gate synthetic PGS END flush on a complete object (#112) - #113

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/pgs-synthetic-end-split-m2ts
Jul 7, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/pgs-synthetic-end-split-m2ts

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Problem

Selecting a PGS subtitle track on a Blu-ray logs [pgssub] Invalid object id 0 persistently (once per display set), reported by ijuniorfu on AetherPlayer/macOS (#112).

Root cause

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, forcing pgssubdec to 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.

  • Still rescues the MKV case (a full block missing only its END).
  • Never fires on a split-M2TS fragment, so the referenced object is always defined before the forced compose.
  • Walks the effective payload (raw TS, or the stripped/inflated buffer for PG-PES and zlib/gzip Matroska), so it is correct across every delivery path.
  • Can only remove premature composes: correct cases (real END present, or complete object present) are byte-identical.

Tests

New PGSSyntheticEndGateTests unit-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

…#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
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.

1 participant