Skip to content

feat(playback): let profiles start on the embedded subtitle track - #461

Closed
d3mystified wants to merge 1 commit into
Silo-Server:mainfrom
d3mystified:feat/prefer-embedded-subtitles
Closed

d3mystified wants to merge 1 commit into
Silo-Server:mainfrom
d3mystified:feat/prefer-embedded-subtitles

Conversation

@d3mystified

@d3mystified d3mystified commented Oct 3, 2026 •

Copy link
Copy Markdown

Problem

Related issue: Silo-Server/silo-server#1848
Validation tasks: none

When a file carries a subtitle track inside it and an external sidecar in the
same language, both Android clients start on the external one. A sidecar is cut
for one release of the title, so it drifts against the picture; the track inside
the file cannot. playback.prefer_embedded_subtitles (settings contract
revision 17, shipped server-side) lets a profile ask for the other one. This
pull request wires it through both clients: the flag reaches every
auto-selection site on phone and TV, and both settings screens expose the
switch.

Approach

The flag is threaded exactly where playback.show_forced_subtitles already
runs, and it re-ranks only one thing: the source tier, and only inside a single
track class. Five behaviours hold with the preference on:

  • Language still decides first. An embedded French track never beats an
    external English one for a viewer who asked for English.
  • A full-dialogue track still beats a forced one. An embedded forced track is
    not full dialogue, so it cannot become the default while a full one exists.
  • Text still beats bitmap within a tier, so the preference cannot trade a text
    sidecar for an embedded PGS.
  • An explicit pick and the remembered series track signature are untouched.
  • With the preference off, every surface picks exactly what it picked before.

The ranking is mirrored in the shared resolver (AutoSubtitleContext), in TV's
resolveTvAutoSubtitleSelection / resolveTvAutoSubtitleIdentity, and in the
phone's own cascade. The tiers mirror rather than list: an external sidecar
drops to the embedded track's place, embedded rises to the sidecar's, and a
downloaded subtitle — which the server can re-time — keeps its place either way.

TV's detail page resolves the same preference the player uses, so the Auto pill
previews the track playback will start on. Offline playback on the phone gets it
too, via OfflineSubtitlePreferences.

The phone's private cascade leads with a forced track when "show forced" is on,
which the shared resolver does not do. That divergence predates this setting and
is left alone; the new tests pin that the preference does not move that answer.

The vendored settings contract fixtures are re-copied from the server at
eb55481, so SettingsConformanceTest keeps the manifest revision, the
fixture, and the generated SettingKeys.REVISION in agreement.

Validation

ANDROID_HOME=$HOME/Android/Sdk ./gradlew --no-daemon \
  :shared:testDebugUnitTest :androidApp:testDebugUnitTest :androidTvApp:testDebugUnitTest

BUILD SUCCESSFUL — 1603 shared, 814 phone, 1210 TV tests, no failures. The same
two compile tasks, run together, are also BUILD SUCCESSFUL.

Tests cover the ranking on the shared resolver, the phone cascade, the offline
inventory, TV's launch-time fallback, and TV's Auto pill; plus the settings
viewmodels on both apps (canonical load, optimistic rollback, and a device
override narrowing the switch back). Each new case asserts one of the five
invariants above, and each suite pins its OFF behaviour against the answer it
gave before. The phone forced-track case also pins the pre-existing short
circuit described under Approach.

Not run: ./scripts/test-check-build-supply-chain.sh,
./scripts/check-build-supply-chain.sh, lintDebug, lintVitalRelease,
assembleDebug, and manual playback on a real deployment. No screenshots or
recordings are attached.

Risks

Off by default, and a server before contract revision 17 sends no field, which
reads as off — so no existing viewer moves. The setting is canonical-only: the
server resolves it, the clients mirror nothing into user_profiles, and both
settings screens show the effective value rather than the value the PUT stored,
so a profile_device row that narrows the choice is visible. The player start
contract is unchanged; subtitle ordinals remain identity, so only Auto's choice
among them shifts.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: omp
  • Tool(s): omp agent tools
  • Model(s): opencode-go/deepseek-v4.1-flash
  • Involvement: AI-assisted
  • Adversarial review: none. No independent or adversarial review was run over
    this change; the validation above is the author's own test run.

Note

Add embedded-subtitle track preference to playback subtitle auto-selection

  • Adds a new playback.prefer_embedded_subtitles boolean profile setting (settings contract revision 17), exposed through ProfileSettingsController snapshots and the settings writer in ProfileSettingsController.kt
  • Android and TV settings screens show a toggle for the preference. Writes are optimistic and roll back on failure
  • The shared resolveAutoSubtitle resolver in AutoSubtitleResolver.kt now ranks candidates by source (embedded > downloaded > external) when the preference is on. Source ranking applies only within an already-selected language and subtitle class, so language, forced, hearing-impaired, and bitmap precedence is unchanged
  • WatchDetail carries the server-resolved value into playback-start results and player state on both platforms, so selection, offline playback, and TV subtitle previews all use the same resolved preference
  • Default is off everywhere, including when the server does not supply the setting; tests cover the resolver, settings writes, TV previews, and offline selection

Macroscope summarized 576dee6.

A sidecar is cut for one release of the title and can play out of sync; the
track inside the file cannot. Every client ranks the external one first, so
there was no way to ask for the other one.

playback.prefer_embedded_subtitles (settings contract revision 17, shipped
server-side) re-ranks only the source tier, and only inside one track class.
Language still decides first, a full track still beats a forced one, text
still beats bitmap, an explicit pick and the remembered series signature are
untouched, and with the preference off every surface picks what it picked
before.

Thread the flag through both starters, both player view models, TV's detail
preview, and the phone's offline inventory, and add the switch beside "Show
forced subtitles" on both settings screens.
@silo-kody

silo-kody Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 3, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b7ef3edd-25c0-498c-8050-e769fd2bfcd6
📥 Commits

Reviewing files that changed from the base of the PR and between 844ff74 and 576dee6.

📒 Files selected for processing (33)
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/diagnostics/DiagnosticsBundleBuilder.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlaybackSessionCoordinator.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlaybackStartResult.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlayerUiState.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelection.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/MobileVideoPlaybackStarter.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/OfflinePlaybackTracks.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsPages.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsViewModel.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SubtitleSettings.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelectionTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/OfflinePlaybackTracksTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsViewModelOfflinePreferencesTest.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvPlaybackFormatting.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvPlaybackSelectorRow.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvVideoPlaybackStarter.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailSubtitlePreferenceTest.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvPlaybackFormattingTest.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvAutoSubtitleFallbackTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/domain/settings/ProfileSettingsController.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/catalog/CatalogModels.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolver.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/SettingKeys.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolverTest.kt
  • shared/src/commonTest/resources/settings/v1/SOURCE
  • shared/src/commonTest/resources/settings/v1/conformance.json
  • shared/src/commonTest/resources/settings/v1/manifest.json
 ________________________
< Tree-sitter is my GPS. >
 ------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@d3mystified

Copy link
Copy Markdown
Author

Closing this. Silo-Server/silo-server#1849 is the server and web half, and it says Android and Apple "get matching PRs" — so the client halves are covered there and this was about to race them. Nothing here is needed for it: the pieces that would have transferred are the source tier on the candidate types, the class-before-source ordering, and the burn-in tier, all of which #1849 spells out precisely enough to implement against, and #1849's own tests name the cases.

The branch is left up for now in case the diff is useful to whoever writes the client PR; delete it whenever.

@d3mystified d3mystified closed this Oct 3, 2026
@d3mystified
d3mystified deleted the feat/prefer-embedded-subtitles branch October 3, 2026 22:12
Comment on lines +250 to 251
pool.bestInClass(preferEmbedded) { (_, subtitle) -> !subtitle.isBitmap() }
?.let { return it.index }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Source-preference bypass occurs because the phone's terminal selection branches return pool.first() when every matching track is bitmap or every forced track is hearing-impaired, causing an external-first pair in either class to select the sidecar even with preferEmbedded enabled. Apply bestInClass(preferEmbedded) { true } to both terminal returns, matching the shared resolver.

pool.bestInClass(preferEmbedded) { (_, subtitle) -> !subtitle.isBitmap() }
    ?.let { return it.index }
return pool.bestInClass(preferEmbedded) { true }?.index
Prompt for LLM

File androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelection.kt:

Line 250 to 251:

Source-preference bypass occurs because the phone's terminal selection branches return pool.first() when every matching track is bitmap or every forced track is hearing-impaired, causing an external-first pair in either class to select the sidecar even with preferEmbedded enabled. Apply bestInClass(preferEmbedded) { true } to both terminal returns, matching the shared resolver.

Suggested Code:

    pool.bestInClass(preferEmbedded) { (_, subtitle) -> !subtitle.isBitmap() }
        ?.let { return it.index }
    return pool.bestInClass(preferEmbedded) { true }?.index

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

resolved(write(SettingKeys.PLAYBACK_SHOW_FORCED_SUBTITLES, JsonPrimitive(enabled)))

suspend fun setPreferEmbeddedSubtitles(enabled: Boolean): WriteResult =
resolved(write(SettingKeys.PLAYBACK_PREFER_EMBEDDED_SUBTITLES, JsonPrimitive(enabled)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Kody Rules high

Race condition identified in write() and resolved(): write() calls setProfileValue() without a captured server/profile/authentication scope, and resolved() calls reresolve() without that scope, allowing an identity change during the suspended write to make the effective-settings reread resolve another profile or server's settings. Capture one scope before the operation, pass it through both helpers, and check its generation before publishing or caching the returned snapshot; apply the same fix at androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt:588-588 and androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsViewModel.kt:740-740, :688-688, :699-699, :239-239, and :692-692.

Kody rule violation: Bind settings operations and serialization to their captured identity

Prompt for LLM

File shared/src/commonMain/kotlin/org/siloserver/silo/domain/settings/ProfileSettingsController.kt:

Line 133:

Race condition identified in write() and resolved(): write() calls setProfileValue() without a captured server/profile/authentication scope, and resolved() calls reresolve() without that scope, allowing an identity change during the suspended write to make the effective-settings reread resolve another profile or server's settings. Capture one scope before the operation, pass it through both helpers, and check its generation before publishing or caching the returned snapshot; apply the same fix at androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt:588-588 and androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsViewModel.kt:740-740, :688-688, :699-699, :239-239, and :692-692.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

codec = row.codec,
title = row.catalogLabel ?: row.label,
forced = row.forced == true,
source = row.source,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Incorrect source classification occurs because inventory candidate adaptation uses only row.source, assigning embedded rather than downloaded priority to a row identified by downloadId or catalogSource without a runtime source; with preferEmbedded enabled, an earlier downloaded row can beat a genuine embedded track in the same language/class. Preserve downloaded provenance when constructing candidates and apply the same classification in the phone's subtitleSourcePriority.

Prompt for LLM

File shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolver.kt:

Line 284:

Incorrect source classification occurs because inventory candidate adaptation uses only row.source, assigning embedded rather than downloaded priority to a row identified by downloadId or catalogSource without a runtime source; with preferEmbedded enabled, an earlier downloaded row can beat a genuine embedded track in the same language/class. Preserve downloaded provenance when constructing candidates and apply the same classification in the phone's subtitleSourcePriority.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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