Fix image subtitle memory and disk leaks
Tim Falken authored 6 months ago
- Subtitle event cache TTL now refreshes on every access, preventing
the entire subtitle track being re-parsed every 5 minutes during
active playback. Previously, watching a film with PGS subtitles for
longer than 5 minutes would silently re-decode all subtitle frames
from scratch, causing periodic CPU spikes and visible lag.
- clearCachesForFile now deletes the corresponding .sup file from disk
when it evicts an event cache entry, instead of only clearing the
in-memory cache. Without this, one .sup file was left on disk
permanently for every unique video+subtitle-stream combination ever
watched.
- purgeSubtitleCacheDir is called once at server startup to remove any
.sup files left over from a previous run, so the on-disk footprint is
always bounded to the current session.
- clearCachesForFile now maintains separate key lists for the event and
frame caches instead of one shared list, making the intent clear and
avoiding redundant no-op lookups.
- Removed dead code clearImageSubtitleCachesForSession from
video-stream.js (defined but never called).
- Updated image-subtitles tests to match the actual render scale (0.75)
and added coverage for purgeSubtitleCacheDir and the guarantee that
subtitle caches are cleared when a session's last stream is closed.