Repository navigation
fix(playback): speed bitmap subtitle startup - #751
Conversation
Bitmap (PGS/DVD/DVB) tracks have to be burned in on the web player. Putting them on the opening plan forces a transcode, and HDR sources refuse that start when tone mapping and 4K transcoding are off — the defaults — leaving no stream to fall back to. Text subtitles still go on the start request; bitmap selection is applied after a playable plan exists. Co-authored-by: Quick <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d688c12ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (selectedTrack && isBitmapCodec(selectedTrack.codec)) { | ||
| continue; |
There was a problem hiding this comment.
Normalize bitmap codec aliases before sending the start
When a catalog track uses a supported legacy spelling such as pgssub, dvdsub, dvbsub, or vobsub, this condition is false because isBitmapCodec recognizes only the canonical FFmpeg names. The server explicitly normalizes those aliases and treats them as burn-in codecs in internal/playback/capabilities_v3.go:335-351 and internal/playback/subtitles.go:15-38, so the selected ordinal is still included in the initial request and an HDR title can hit the same terminal this change is intended to avoid. Use the same normalized codec family as the playback policy, or extend the web classifier and its tests to cover every server-supported alias.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 621ff08305
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "dvb_subtitle", | ||
| "dvbsub", |
There was a problem hiding this comment.
Defer DVB teletext from the initial start
When an auto-selected or explicit track has FFmpeg codec dvb_teletext, this set still makes isBitmapCodec return false, so buildInitialSubtitleTrackIndexes sends its ordinal on /playback/start. Fresh evidence beyond the resolved alias comment is internal/playback/subtitle_policy_v3.go:72-74 and its test at internal/playback/subtitle_policy_v3_test.go:26-42, which explicitly classify dvb_teletext as requiring bitmap burn-in. Consequently, an HDR/4K title with the default transcode or tone-mapping restrictions can still terminal the initial plan instead of starting without subtitles; include this codec in the deferred classifier and its tests.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3609eb3463
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| initialSubtitleErrorTitle: initialSubtitleFailure?.title ?? null, | ||
| initialSubtitleError: initialSubtitleFailure?.message ?? null, |
There was a problem hiding this comment.
Keep the subtitle fallback pinned across replans
When the bitmap-bearing start is refused and the subtitle-free fallback succeeds, any later successful quality, output-change, or recovery replan calls adoptDecision without initialSubtitleFailure, clearing these fields. WatchPage then restores the persisted subtitle mode, and VideoPlayer auto-selects the same rejected bitmap track and issues a track_change replan, producing another refusal and toast. Preserve the fallback-off marker for the lifetime of this playback session unless the viewer explicitly selects a subtitle.
Useful? React with 👍 / 👎.
|
Follow-up startup and playback-hardening work is now pushed in What changed:
Validation added for async side-effect ordering, concurrent settings reads, fresh/reconstructed readiness windows, local and remote Dolby Vision remux recipes, Safari native HDR selection, and Chromium HDR hls.js selection. Latest validation: All passed. The unfiltered web suite also ran 2,127 tests: 2,121 passed; the six failures are the repository's already-excluded SeasonContent and ServerStorageStep harness failures ( The updated image is deployed to shared dev and healthy. The deployed frontend contains the Chromium/Safari engine split and loads without console errors. The automation browser had a fresh signed-out profile, so the final authenticated replay of the reported Chrome title remains a manual confirmation rather than an automated claim. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 481dc4d3eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /Safari\//i.test(userAgent) && | ||
| !/(?:Chrome|Chromium|CriOS|Edg|EdgiOS|OPR|OPiOS|Firefox|FxiOS)\//i.test(userAgent) |
There was a problem hiding this comment.
Keep HDR capability evidence tied to the selected HLS engine
When a non-Safari browser both advertises native HLS and supports hls.js, buildDeliveriesV3 can advertise Dolby Vision or HDR10 based on the native media element, but this classifier makes runtime playback select hls.js instead. The playback contract explicitly does not transfer that native evidence to the hls.js MSE path, so the server may return an HDR-preserving remux that the engine actually chosen never claimed it could decode; this also affects iOS Chrome/Firefox user agents when MSE is available. Either keep those plans on native HLS or make capability advertisement use the same engine that will be selected.
Useful? React with 👍 / 👎.
| h.ChapterThumbnailQueuer.QueuePriorityFileAtPosition(ctx, task.file.ID, task.session.Position) | ||
| } | ||
| h.maybeQueueLazyPlaybackMarkers(ctx, &task.session, &task.file) | ||
| h.persistSeriesSelectionsV3(ctx, task.userID, task.profileID, &task.file, task.audioTrackIndex) |
There was a problem hiding this comment.
Prevent delayed start writes from undoing track changes
If the viewer changes audio while the asynchronous start task is still blocked on scrobbling, thumbnail work, or the worker queue, the track_change replan first persists the newly selected audio index, after which this delayed call writes the initial index back over it. The next episode then loads the old audio preference even though the user's replan succeeded; serialize these preference updates or skip the stale start write once a newer selection has committed.
Useful? React with 👍 / 👎.
| waitCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), playbackStartSideEffectsTimeoutV3) | ||
| defer cancel() | ||
| select { | ||
| case <-done: | ||
| case <-waitCtx.Done(): | ||
| slog.WarnContext(ctx, "timed out waiting for playback start side effects", "component", "api", "session", sessionID) |
There was a problem hiding this comment.
Wait for queued start work before emitting stop events
Under load, when all four workers are occupied and this session's start task is still queued, the stop-side timeout begins immediately while the task's own 15-second timeout begins only after a worker dequeues it. The wait can therefore expire and emit a provider pause/stop before the queued task later emits ScrobbleStart, reversing provider history and allowing post-stop bookkeeping for an ended playback session. Tie stop ordering to task completion or cancel/remove the queued task rather than using an independent fixed wait.
AGENTS.md reference: AGENTS.md:L60-L64
Useful? React with 👍 / 👎.
| if opts.FastStart && bitmapBurnInActive(opts) && opts.HWAccel != "" && opts.HWAccel != HWAccelNone { | ||
| return 1 |
There was a problem hiding this comment.
Exclude reconstructed sessions from the one-fragment window
When an integrated hardware transcode is reconstructed after an API restart, NewRecipeCard has persisted the original FastStart: true, and doReconstructTranscode restores it without clearing it. This condition therefore misclassifies the reconstructed bitmap-burn-in generation as fresh and serves its manifest after only one fragment, despite the stated three-fragment restart cushion, leaving the player with no encoding headroom precisely during recovery. Track fresh-generation state separately or clear FastStart on reconstruction.
AGENTS.md reference: AGENTS.md:L12-L17
Useful? React with 👍 / 👎.
| func StartupSegmentDuration(subtitleBurnIn bool, subtitleCodec string) int { | ||
| if subtitleBurnIn && NeedsBurnIn(subtitleCodec) { | ||
| return bitmapFastStartSegmentDuration |
There was a problem hiding this comment.
Keep one-second fragments limited to hardware burn-in
When bitmap burn-in runs on CPU—either because hardware acceleration is disabled or because a hardware tone-map start falls back to software—this function still changes the segment duration from two seconds to one. Although startupSegmentRequirement retains three fragments for CPU, that now represents only three seconds of buffered output rather than the prior six-second cushion, so a slower CPU encode can expose playback much closer to the production edge and stall shortly after startup. Pass the resolved execution mode into this choice or restore two-second fragments for CPU paths.
AGENTS.md reference: AGENTS.md:L60-L64
Useful? React with 👍 / 👎.
This reverts commit 481dc4d.
|
Scope update: the general playback-startup follow-up previously added in PR #751 is again limited to the bitmap-subtitle startup/reload work. PR #761 is based directly on current The shared-dev image still contains the combined iteration deployed during testing; it should be treated as preview evidence for #761, not as the current #751 branch artifact. |
…liases # Conflicts: # docs/feature-changelog.md # internal/api/handlers/playback_v3.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c8048b796
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| legacySuffix := "?" + rawQuery | ||
| variableSuffix := "?{$" + manifestQueryVariable + "}" | ||
| savingsPerSegment := len(legacySuffix) - len(variableSuffix) | ||
| if savingsPerSegment <= 0 || int64(segmentCount)*int64(savingsPerSegment) < minManifestQuerySubstitutionSavings || strings.ContainsAny(rawQuery, "\"\r\n") { |
There was a problem hiding this comment.
Negotiate HLS v8 before emitting variable references
For any signed playlist whose repeated query crosses this threshold, the server unconditionally switches to EXT-X-DEFINE and advertises HLS version 8, although the playback capability contract records only generic HLS support. A third-party or older native client limited to HLS v7 can therefore reject the playlist or leave {$silo_query} unexpanded, causing every segment request to fail authentication. Gate this representation on an explicit HLS-v8/variable-substitution capability, or retain literal query strings for clients that have not advertised it.
AGENTS.md reference: AGENTS.md:L19-L22
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1685bc128b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let initialSubtitleFailure: PlaybackSessionErrorState | null = null; | ||
| const bitmapSubtitleTrackIndex = initialBitmapSubtitleTrackIndexByFileId?.[selectedFileId]; | ||
| if (!decision.playback_plan && bitmapSubtitleTrackIndex !== undefined) { | ||
| initialSubtitleFailure = describeDecisionWithoutPlan(decision); |
There was a problem hiding this comment.
Report a successful fallback as a subtitle failure
When bitmap burn-in is the only reason HLS or transcode capacity is needed, the first request can return client_hls_unsupported or capacity_unavailable while the subtitle-free retry successfully direct-plays the file. Saving the original terminal description here makes WatchPage toast “This browser can't play the stream” or “The server is busy” while playback is visibly working. After a successful retry, replace arbitrary first-attempt terminal text with a subtitle-specific explanation that only the selected captions were disabled.
Useful? React with 👍 / 👎.
Problem
Related issue: N/A — narrow fix
The web player auto-selects subtitle tracks before playback. Bitmap formats such as PGS, DVD, and DVB cannot be rendered by the browser, so selecting one forces server-side burn-in and a video transcode.
The previous fix protected HDR playback by starting without the bitmap track and applying it through a replan. That avoided a terminal start when conversion was unavailable, but it also exposed the first stream before the replan completed. The viewer saw playback begin, reload, and begin again. On the shared development deployment, that sequence took roughly 10 seconds (
/playback/start3.43 s plus the first/replan5.87 s).Approach
The opening request now includes the selected bitmap subtitle, so the normal path produces the final transport once and never reloads it. If that request is terminal because the server cannot perform the required conversion, the web client cleans it up and performs one fresh subtitle-free start with a new playback-attempt ID. Playback remains available and the viewer gets the existing subtitle-specific notice.
Startup latency is reduced without weakening readiness guarantees:
pgssub,dvdsub,vobsub, anddvbsub).No v1 response shape or client capability contract changes. Apple, Android, and jellycompat require no coordinated client change.
Shared-dev browser validation
Tested through the real web UI against the shared backend with an explicitly selected bitmap subtitle. Each measurement started after using the player's Exit action so the previous transcode was cleaned up.
/playback/startThe final state was playing with captions active and no playback error. The large signed manifest request dropped from 798 ms to 10 ms after compaction.
This removes the original roughly 10-second start/reload sequence and makes the UI usable in about 3.1 seconds. The sub-second goal was not reached end to end: the safe floor for this 4K bitmap-burn-in path is still the first encoded fragment plus browser HLS buffering. An experiment that returned
/playback/startearlier made the API look faster but worsened actual controls to 3.6 seconds, so it was not retained.Validation
make test-gowas also run. Every touched package passed; the complete local run ended on two unchangedinternal/jellycompatprocess-lock tests whose current-process identity checks fail on this macOS host. The PR's previous Go CI run was green; the new CI run remains the authoritative full-suite result.Risks
One-second fragments create more playlist entries for bitmap burn-in sessions. The change is deliberately limited to fresh hardware burn-in, and large signed playlists are compacted to avoid transferring and parsing repeated credentials. If burn-in is unavailable, the fallback costs one failed planner attempt before starting without subtitles, but it avoids both a fatal start and a mid-playback transport reload.
AI Disclosure
Checklist