You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(playback): draw embedded subtitles from the stream and switch them without a remount - #770
Embedded subtitles on the phone and TV apps cost the server too much and kept viewers waiting. Picking an embedded track usually made the server extract it from the whole source file, which takes minutes on large files on slow storage (Silo-Server/silo-server#1406). Image-based tracks went through a .sup extraction or a burn-in transcode. A slow sidecar was retried like media, and each retry started another whole-file read. A slow sidecar could also hold back or fail the video. Switching subtitles always remounted the player, even when the stream already carried the track.
This pull request makes the apps draw more embedded tracks straight from the stream, bounds sidecar retries, and switches subtitles on the playing stream without a remount. It combines five pull requests (#731–#735) into one, one commit each, so the team can review the stack in one place.
Approach
Server dependency
The in-place switching (fifth section) uses two parts of Silo-Server/silo-server#3331: the stream_index, container_track_id and native_selectable fields on inventory rows, and hls_subtitle_renditions_all_v1, which lists every embedded text track as an HLS rendition. The apps ask for the new behavior only when the server advertises it, and behave as before against a server without it. The vendored playback-v3 fixtures come from that unmerged server change and need a re-sync from server main once it lands. The first four sections need no server change.
What: the phone checks its native and rendition mount deadline every 5 s, counts it only once the mount has text tracks, and gives up after 30 s. The window starts at the first check that finds tracks, so tracks published just before a check still get a whole window to confirm. PlayerScreen reports whether the current mount has text tracks. Android TV already polled this way; it doesn't have the window fix.
Why: a fixed 5 s deadline failed mounts whose stream hadn't published text tracks yet. Each false failure replanned with subtitle_embedded_failed and cost a whole-file sidecar extraction.
Risk: a track that never mounts now takes up to 30 s, instead of 5 s, to fall back to the sidecar.
HLS subtitle renditions on copy remuxes (was #732)
What: the apps send hls_remux_subtitle_renditions_v1 when the server advertises it, and accept a WebVTT rendition on server_remux_hls plans as well as transcodes. The gate matches buffering_quality_v1's, so Cast never asks. A rendition that fails to mount still replans for the sidecar.
Why: a copy remux delivered the selected text track as a whole-file sidecar, when the server can carry it in the remux playlist. The server feature is already on main.
Risk: none identified. A server that doesn't advertise the feature gets the same requests as before.
Embedded MKV bitmap subtitles from the stream (was #734)
What: the MKV native_embedded capability on original_http lists hdmv_pgs_subtitle, dvd_subtitle and dvb_subtitle. Media3 1.11's MatroskaExtractor gives these tracks their Matroska TrackNumber as Format.id, so the existing container_track_id selection works unchanged. validateForMedia3 accepts the server's short codec aliases, and dvd_subtitle now maps to VobSub instead of DVB. The subtitle sync offset now applies to these cues, whose times are relative to their sample: PGS and DVB report no start of their own, and VobSub a small relative one. Before, a positive offset was lost on PGS and DVB, a negative one made those cues never appear, and a negative offset on VobSub (and on Matroska text tracks) was clamped away. A negative offset now advances them, as it did on the .sup sidecar path. Sidecars keep their absolute, clamped starts.
Why: PGS went through a .sup extraction of the whole file, and VobSub and DVB through a burn-in transcode, even in direct play.
Risk: cue position, scaling and timing for these formats on real devices is unchecked. Dropping the codecs from the capability sends these tracks back to the old routes. Cast is unaffected; it doesn't use native_embedded.
Each sidecar gets its own retry policy. A failure that costs the server an extraction (a timeout after the connection opened, or a response cut off mid-body) is retried at most twice, and at most once after a timeout. Failures that cost nothing (an error status, a refused connection, a connect or TLS handshake timeout) keep the media retry window.
The budget belongs to the sidecar, not to a load task. It resets only on prepare, a seek, or turning the track back on, so Media3's own restarts of an unseekable response share it.
Sidecar requests wait 180 s for data instead of 30 s.
A sidecar never holds back or moves the video. Its media period reports itself prepared at once from the known track format. A late selection keeps the extraction already running. Media3's restart discontinuity is read but not passed on, so the video can't jump to the start. When the budget runs out, Media3 disables only the text track.
Switching subtitles on the playing stream (was #733)
What:
A pick of a track the playing media already carries shows at once, and its track_change replan goes out in the same step. That covers a native_selectable row on direct play, an every-track rendition on HLS, and Off on either.
For a subtitle pick only, the session manager treats the server's answer as in place when it keeps the transport the player renders and changes only the subtitle. Audio the player switched inside the file counts as the plan's audio. The phone and TV adopt that answer without remounting.
A failed replan, or a newer pick that needs one, puts the previous subtitle back. TV's two-phase publication confirms the selection on the tracks already published and rolls back without a remount.
Answers that change the transport, or return a sidecar, remount as before.
docs/playback/README.md records the design and the rollback rules.
Why: every subtitle pick made the viewer wait for the server and then sit through a rebuffer, even when the stream already had the track.
Risk: TV's two-phase publication and its in-place rollback are the most involved paths. They're unit-tested; no device has run them. On direct play, Off now switches in place against older servers too, and an answer that changes the transport still remounts.
./gradlew testDebugUnitTest: pass, 6,687 tests, 0 failures. One earlier run failed LocalRouteTransportTest, in network code this change doesn't touch; it passed on three reruns and in the full rerun.
:android-shared:lintDebug, :androidApp:lintDebug, :androidTvApp:lintDebug, :androidApp:lintVitalRelease, :androidTvApp:lintVitalRelease: pass, no new findings.
:androidApp:assembleDebug and :androidTvApp:assembleDebug: pass.
Review fixes (db26b83, e2cd7d3, 17b3a5b, f9818dd), checked on f9818dd: testDebugUnitTest passes, 6,691 tests with 0 failures. TvItemDetailSubtitlePreferenceTest failed once in a coroutine teardown and passed on three reruns. Lint on all three modules found nothing new, and assembleDebug passes for phone and TV. The two new tests failed on 593e0f8. The supply-chain scripts weren't run on the review host, which has no Ruby, so CI covers them.
CI's Lint job fails on main and on every open pull request for a reason outside this change. Gradle dependency verification rejects the org.jetbrains.kotlin.plugin.serialization 2.1.20 marker POM that the Gradle Plugin Portal now serves; gradle/verification-metadata.xml trusts the Maven Central copy.
Android device coverage: the TV debug build from this content was installed on an onn 4K Streaming Device (Android TV). No scripted playback run followed, and no phone, tablet or foldable was tested.
The same server change was exercised end to end with the Silo iPhone app (shared dev, 2026-10-31) and a Roku TV (sandbox, 2026-10-30). Those runs show the server's side: native tracks drawn from the stream with no subtitle request or extraction, every embedded track listed as a rendition, and in-place switches that reuse the running HLS transport. They don't test this Android code.
Not covered on any device: the bitmap formats, sidecar retries under a stalled response, the phone's mount deadline, and TV's in-place rollback.
The vendored fixtures follow the unmerged server branches. If the wire shape changes before those merge, the fixtures and the model need an update.
Each section above lists its own risks.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
The Evidence section shows every change a user can see, or says there is none.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): Claude Code
Model(s): claude-opus-5-5
Involvement: Fully AI-generated. Nobody has verified it by hand yet. The only Android device step was installing the TV debug build on an onn 4K Streaming Device; no device or emulator run of the features happened.
Adversarial review:
Two read-only reviews by separate Claude Code agents (claude-opus-5-5) covered the whole stack. The TV-path review found six ways the player and server could disagree during an in-place switch. The full-branch review found that connect timeouts counted against the sidecar budget, that a sidecar that never answered failed the video, and seven smaller issues in the switching code. All are fixed.
a late sidecar selection restarted the extraction;
the sync offset was lost on PGS and DVB cues;
a mount deadline race on the phone;
a negative sync offset was clamped away on PGS and DVB cues;
the same clamp dropped a negative offset on VobSub's sample-relative starts.
Fixing the retry budget turned up a related bug, also fixed: Media3's restart of a sidecar could move the video back to the start.
A maintainer review of 593e0f8 (Claude Code in T3 Code, claude-opus-5-5, with a Codex gpt-6.1-sol round) found four problems, all fixed on this branch:
a phone audio pick could be adopted in place, leaving the old audio playing (db26b83);
a sidecar reset after the body started bypassed the extraction budget, and a body closed between chunks wasn't retried (e2cd7d3);
a TV in-place rollback could remount with older audio claims (17b3a5b);
a misplaced KDoc (f9818dd).
One is left open for the maintainers: going back to the committed native track while another pick's replan is in flight leaves the server on that pick until the next replan.
Three bot findings weren't changed:
A false positive, raised twice: Media3 disables only the text track on a sidecar error.
An older catalog-matching issue that affects every saved subtitle choice, not just these formats.
Unbounded replan resends during an outage. That's main's deliberate policy: a replan goes again once the device is back online.
Draw embedded subtitles from the stream and switch them without a remount
Adds native Media3 playback for embedded PGS, VobSub, and DVB bitmap subtitle tracks on Matroska, including codec alias mapping in nativeEmbeddedSubtitleCodec and a native-selectability flag in PlaybackSubtitleInventoryItemV3 (PlaybackProtocolV3.kt).
Adds HLS subtitle renditions for both transcode and remux delivery via carriesHlsSubtitleRendition, switchableHlsRendition, and new feature-gated request helpers so every embedded text track can be exposed as a rendition.
Adds in-place subtitle switching: canSwitchSubtitleInPlace and PlaybackPlanV3.inPlaceMismatch decide eligibility, PlaybackSessionManager marks subtitle-only replan candidates as in-place, and the TV/mobile adapters apply the pick on the playing stream before the replan response arrives, with rollback to the committed subtitle on failure.
Adds a dedicated SidecarSubtitleLoadErrorHandlingPolicy with its own retry budget, and NonGatingSidecarPeriod announced-track state so sidecar tracks are listed before the sidecar loads (SidecarSubtitleMediaSource.kt).
Behavioral Change: TvPlayerScreen and PlayerScreen now key the player preparation effect on the plan's mediaMountKey, so plan changes that preserve that key no longer remount; subtitle rows in session responses now carry rendition and container-track identity for in-place switches.
The phone failed a native or rendition subtitle mount after a fixed 5 s,
even when the replanned stream had not published its text tracks yet.
Each false failure replanned with subtitle_embedded_failed and cost a
whole-file sidecar extraction on the server.
Poll the deadline the way TV does: check every 5 s, count only once the
current mount exposes a text track, and give up after 30 s regardless.
The window starts at the first check that finds tracks, or at once when
the mount already has them, so tracks published just before a check
still leave the selection a whole window to confirm. PlayerScreen
reports text-track presence for the current mount from onTracksChanged
and the selection effect.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A server_remux_hls plan extracted the selected embedded text track as a
whole-file sidecar. The server can carry it as a WebVTT SUBTITLES rendition
of the remux playlist instead, once the client lists
hls_remux_subtitle_renditions_v1 next to hls_subtitle_renditions_v1.
SequencedPlayback adds the feature to start and replan requests only when
the server advertises it (in its /api/v2 capability features or a
decision's server_features) and the request already lists
hls_subtitle_renditions_v1, the same gate buffering_quality_v1 uses, so
Cast contexts never ask. validateForMedia3, the session projection and the
staged-replan subtitle check accept hls_rendition on server_remux_hls as
well as server_transcode_hls. A failed rendition mount still replans with
subtitle_hls_rendition_failed for the sidecar plan.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Advertise hdmv_pgs_subtitle, dvd_subtitle and dvb_subtitle in the MKV
native_embedded entry on original_http. Media3 1.11's MatroskaExtractor
exposes S_HDMV/PGS, S_VOBSUB and S_DVBSUB with Format.id set to the
TrackNumber, and DefaultSubtitleParserFactory decodes all three, so the
existing container_track_id selection works unchanged. The server already
plans subtitle.embedded for these codecs when the client lists them, which
replaces the PGS .sup whole-file extraction and the VobSub/DVB burn-in
transcode in direct play.
validateForMedia3 accepts the server's short aliases (pgs, pgssub, dvdsub,
vobsub, dvbsub). A VobSub or DVB track committed as Embedded now resolves
on the detail screen instead of being dropped. codecToMimeType mapped
dvd_subtitle/dvdsub to DVBSUBS; it now maps them to VOBSUB and maps
dvb_subtitle/dvbsub to DVBSUBS.
The offset wrapper around the embedded parsers added the user's sync
offset to each cue's start, but the PGS and DVB parsers report none
(C.TIME_UNSET; the cue starts at its sample). A positive offset was
clamped away and a negative one overflowed into a time the cue never
reaches. A missing start now counts as the sample-relative 0 it stands
for. The .sup sidecar extractor offsets the sample itself and is
unaffected.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sidecar subtitle loads shared the media retry policy: unbounded retries
inside a 90 s window on a 30 s idle timeout. A cold server extraction sends
the WebVTT header and then nothing until the first cue, so every attempt
timed out and started another whole-file read on the server (#458).
Sidecars now get their own policy, one per sidecar. Failures that cost
the server an extraction, a timeout after the connection opened or a
response cut off mid-body, are retried at most twice, and at most once
after a timeout. The budget is the sidecar's, not the load task's or
Media3's errorCount: Media3 resets errorCount after progress, and for a
response of unknown length it restarts the stream from byte zero under a
new load task once the queued cues run out (a deferred retry). The
sidecar's period resets the budget only when the load starts over on
purpose: on prepare, on a seek, and when the text track is enabled
again. Failures that cost no extraction (an error status, a refused
connection, a connect or TLS handshake timeout) keep the media window.
Sidecar requests wait 180 s for data instead of 30 s, on the same
connection pool. Media and HLS retries are unchanged.
A sidecar no longer holds back or moves the video:
- Its period reports itself prepared at once from the track format the
SubtitleConfiguration already fixes, and passes the selection to the
HTTP-backed period once that has prepared. A spent budget or a
failure before preparing reaches the text renderer, and Media3
disables the text track while the video keeps playing.
- A late handover uses the delegate's own adjusted position (0 for an
unseekable response), because ProgressiveMediaPeriod treats a first
selection anywhere else as a seek and would cancel the running
extraction and request the sidecar again.
- The delegate's discontinuity is read but never reported:
ProgressiveMediaPeriod reports one at 0 after a deferred retry, and
MergingMediaPeriod would seek the video there.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picking another subtitle used to replan and then remount the MediaItem,
even when the playing media already carried the track: a native track of
an original_http file, or a rendition of an HLS stream that lists every
embedded text track. The viewer waited for the server and then sat
through a rebuffer.
Phone and TV now show such a pick at once and send its track_change
replan in the same step, including a pick queued while a commit is in
flight. A row qualifies when the server marks it native_selectable
(falling back to the client's own evaluation when the server sends none
of the C1 fields), or has an every-track rendition; Off qualifies on the
same streams, and Media3 must list the track.
For a subtitle pick only, the session manager marks a staged candidate
inPlace when it keeps the transport the player renders and changes only
a subtitle selectable in that media. Audio the player switched inside
the file without a replan counts as the plan's audio. The manager
carries the transport's first-frame report, local mutations and
passthrough scope across the commit.
The view models lay the adopted plan's subtitle decision, identity and
menus over the mounted plan, so a change the client made to the mount
(a PCM retry's audio claim) stays and nothing remounts. Phone adopts
without a new mount generation. TV adopts without a mount nonce and keys
its mount effect on a media mount key that ignores the subtitle
decision; its two-phase publication confirms the selection on the tracks
already published, and an in-place publication rolls back by restoring
the predecessor's plan and reselecting its subtitle without a remount.
A failed replan, or a newer pick that needs one, restores the previous
subtitle locally. A plan that changes the transport or returns a sidecar
is adopted with a remount as before.
Stall detectors key on the mount rather than the plan id. A pick of
another server-placed track that cannot switch in place always goes to
the server, and TV counts a stale sidecar as mountable only while the
plan selects it. TV's same-route remount restores a native or rendition
track by its exact identity, since the reloaded playlist still marks the
original track DEFAULT, and its mount-request flow keeps the newest
request.
An in-place plan sends no plan_summary of its own: the transport's
summary covers it, and the server keys summaries, samples and learned
limits by connection. The design and its rollback rules are in
docs/playback/README.md.
The server names each embedded inventory row's track in the source
(stream_index, container_track_id), marks rows the player may switch to
on the original stream (native_selectable), and, under
hls_subtitle_renditions_all_v1, lists every cue-indexed embedded text
track as a rendition of an HLS plan's stream. The client models those
fields and sends hls_subtitle_renditions_all_v1 only to a server that
advertises it, and only when the request already lists
hls_subtitle_renditions_v1. The playback-v3 fixtures are re-vendored
from the unmerged server branches and must be re-synced from server main
once those land.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
Walkthrough
The change adds protocol support for native and HLS subtitle renditions, in-place subtitle switching on mobile and TV, and dedicated sidecar subtitle loading and retry handling. It also updates playback fixtures, tests, and documentation.
Protocol models and request gating add indexed HLS rendition metadata, copy-remux rendition support, and embedded native track identity. Native subtitle matching expands to additional Matroska bitmap codecs. Tests and fixtures cover validation, feature negotiation, and protocol decoding.
Player subtitle projection and plan adoption android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/*, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/*
Player code projects native track IDs and HLS renditions, checks in-place switch eligibility, and derives media mount keys. Session publication marks eligible subtitle replans as in-place and preserves active playback state. Tests cover projection and adoption.
Sidecar subtitle transport and loading android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/*, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/subtitle/*, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/*
Sidecar subtitles use a dedicated HTTP data source and retry budget. Sidecar periods can announce a track before delegate preparation and report fresh-load events. Tests cover retry limits, preparation, selection handover, and error reporting.
Mobile and TV subtitle switching androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/*, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/*, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/*, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/*, docs/playback/README.md
Mobile and TV adapters apply eligible subtitle selections while a replan is pending, then confirm or restore selections based on adoption. ViewModels track mounted tracks and avoid remounting when plans qualify for in-place adoption. Tests and documentation cover these flows.
sequenceDiagram
participant SubtitleTransactionAdapter
participant PlaybackSessionManager
participant PlayerViewModel
participant Media3Player
SubtitleTransactionAdapter->>PlaybackSessionManager: Stage subtitle replan
PlaybackSessionManager-->>SubtitleTransactionAdapter: Publish candidate with inPlace status
SubtitleTransactionAdapter->>Media3Player: Apply eligible subtitle selection
SubtitleTransactionAdapter->>PlayerViewModel: Report adopted plan
PlayerViewModel->>PlayerViewModel: Update plan and retain media mount
PlayerViewModel-->>SubtitleTransactionAdapter: Confirm adopted selection
Loading
Suggested reviewers:rxwatcher, rhainland
Merge Risk: Minimal · up to 95147
No actionable issue remains from this review; the change is mergeable after normal checks.
Security architecture risk: Low · up to 95147
The inspected playback changes retain session and media identity checks, protect active sessions during cleanup, and bound retries for expensive subtitle requests. No introduced security regression was established. Compatibility with the forthcoming server behavior and broader security coverage remain unverified, so the assessment is not minimal risk.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The directly evidenced exposure is the current device playback session, its subtitle requests and parser resources, and server work triggered by those requests. The 180-second timeout is per read rather than a total request deadline, so a slow response can retain resources longer than before. Retry limits and PGS lookahead constrain parts of this exposure; they do not establish a global resource bound or cross-tenant server isolation.
Trust Boundaries and Controls
observed — Server-provided subtitle identity is checked before local selection: native switching requires original-file delivery, an embedded row, a canonical unique container track ID and selectability; HLS switching rejects malformed or duplicate group/name identities. These checks constrain selection identity, while the server remains authoritative for plan production.
Resilience and Maintainability Implications
observed — Session cleanup remains manager-owned. Discard protects the base session, active session and candidates referenced by another staged handle; disposable sessions are registered for cleanup before a non-cancellable stop attempt. Sidecar release delegates to the underlying media source. These ownership rules contain interruption and overlap without treating a live same-session replan as disposable.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly summarizes the two primary changes: drawing embedded subtitles from the stream and switching subtitles without remounting.
Description check
The description directly explains the subtitle playback, sidecar retry, and in-place switching changes, including implementation approach, risks, validation, and known limitations.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 80 functions across 44 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The Evidence URL is now present. However, the PR description says its device runs exercised the server with the iPhone app and Roku TV, not this Android code, and that these playback behaviors were not covered on any device. The private evidence page should show the following Android effects for reviewer verification:
Direct-play MKV PGS, VobSub, and DVB subtitle rendering — playback recordings on Android phone, tablet, foldable folded and open, and Android TV.
In-place embedded/HLS subtitle and Off switching, and sidecar loading/retry while video continues — recordings of these multi-step/timing behaviors on Android phone, tablet, foldable folded and open, and Android TV.
The phone app’s delayed subtitle-mount deadline and fallback — a recording on Android phone, tablet, and foldable folded and open.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.
The reason will be displayed to describe this comment to others. Learn more.
Preserve negative offsets for sample-relative bitmap cues
When a viewer advances a newly supported native MKV PGS/VobSub/DVB track with a negative subtitle delay, these parsers report TIME_UNSET, so this normalization makes start zero and the subsequent coerceAtLeast(0L) discards the entire delay for every caption. These times are sample-relative, not absolute movie timestamps: Media3 adds them to the sample timestamp, so a negative relative start does not necessarily precede the movie. Preserve the signed relative offset or apply it to the sample timestamp; otherwise advancing subtitles stops working when PGS playback moves from the existing .sup sidecar path to native rendering.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 807c7b1 on this branch. A cue with no start of its own now takes the signed offset as its sample-relative start (OffsetSubtitleParserFactory.kt, the TIME_UNSET branch), so a negative offset advances PGS and DVB cues instead of being clamped away. OffsetSubtitleParserFactoryTest covers it.
The reason will be displayed to describe this comment to others. Learn more.
Fatal source error occurs when AnnouncedSampleStream propagates a terminal sidecar IOException through maybeThrowError: ExoPlayer treats it as a source error rather than a text-decoder failure, so a sidecar that returns 403 or exhausts the new timeout budget stops video playback. Terminate the failed subtitle stream and report its failure separately instead of throwing the delegate's load error into the player.
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/subtitle/SidecarSubtitleMediaSource.kt:
Line 413 to 419:
Fatal source error occurs when AnnouncedSampleStream propagates a terminal sidecar IOException through maybeThrowError: ExoPlayer treats it as a source error rather than a text-decoder failure, so a sidecar that returns 403 or exhausts the new timeout budget stops video playback. Terminate the failed subtitle stream and report its failure separately instead of throwing the delegate's load error into the player.
The reason will be displayed to describe this comment to others. Learn more.
This doesn't stop the video. The error reaches Media3 through the text renderer's own SampleStream. Media3 1.11 checks that in ExoPlayerImplInternal.maybeThrowRendererStreamError, which doSomeWork calls for the playing period's renderers. For C.TRACK_TYPE_TEXT and C.TRACK_TYPE_METADATA it catches the IOException, logs "Disabling track due to error", and disables only that renderer. It rethrows for every other track type. The announced period never surfaces the delegate's error through maybeThrowPrepareError (it reports itself prepared), so the fatal source-error path isn't reached.
The reason will be displayed to describe this comment to others. Learn more.
You're right. My original finding conflated a SampleStream error with a fatal period/source preparation error.
In the Media3 1.11 path you describe:
AnnouncedSampleStream.maybeThrowError() exposes the failure through the text renderer’s stream.
maybeThrowRendererStreamError catches that IOException for text and metadata renderers and disables only the affected renderer.
Because the announced period reports itself prepared and does not propagate the delegate’s preparation error through its own maybeThrowPrepareError, that separate fatal path is avoided.
The claim that a 403 or exhausted sidecar retry budget stops video playback is therefore a false positive. The proposed change is not warranted on that basis.
Re-vendor the fixtures after the server branches merge.
The fixtures come from the unmerged server branches feat/subtitle-renditions-all and feat/subtitles-native-limitations. The file already says to re-sync after they land.
If the server changes the wire shape before the merge, the conformance tests will assert against a stale contract. Do not merge this PR before the server branches land, or confirm that no wire change is pending.
Move the older KDoc above commitLocallyMountableSelection.
Two KDoc blocks now sit in a row above beginInPlaceSwitch. Kotlin attaches only the block that immediately precedes a declaration, so the older block documents beginInPlaceSwitch by position while describing commitLocallyMountableSelection. commitLocallyMountableSelection has no KDoc. The older block also states a caller contract: the function returns false when the pending carries audio, quality, or output-route preferences. Callers need that contract on the correct function.
Suggested fix
/**
- * Commits a locally-mountable identity — an embedded (muxed) track the- * stream already carries — without a server round trip.- *- * Replanning to reach a track that is already in the stream tears it down- * and restarts it: black flash, rebuffer, re-seek, for the same picture. A- * pending is force-validated against the synthetic `tv-local` candidate so- * the state machine reaches committed with no server involved.- *- * Returns false — meaning "you must replan after all" — when the pending- * also carries an audio, quality or output-route preference. Those can only- * be applied by the server, and short-circuiting it would drop them- * silently. Both callers must respect that: this is shared precisely- * because the two paths had drifted, and a subtitle press replayed out of- * `queuedMutations` was replanning where a direct press did not.- */
/**
* Shows [identity] on the playing stream at once and sends its replan
* with it, when the stream already carries the track (or it is Off) and
* the pick changes nothing but the subtitle. The replan's answer is
* adopted without a remount when it keeps the transport; a failure
* restores the previous subtitle.
*/
private fun beginInPlaceSwitch(
identity: SubtitleIdentity,
state: SubtitleTransitionState,
): Boolean {
...
return true
}
+ /**+ * Commits a locally-mountable identity — an embedded (muxed) track the+ * stream already carries — without a server round trip.+ *+ * Replanning to reach a track that is already in the stream tears it down+ * and restarts it: black flash, rebuffer, re-seek, for the same picture. A+ * pending is force-validated against the synthetic `tv-local` candidate so+ * the state machine reaches committed with no server involved.+ *+ * Returns false — meaning "you must replan after all" — when the pending+ * also carries an audio, quality or output-route preference. Those can only+ * be applied by the server, and short-circuiting it would drop them+ * silently. Both callers must respect that: this is shared precisely+ * because the two paths had drifted, and a subtitle press replayed out of+ * `queuedMutations` was replanning where a direct press did not.+ */
private fun commitLocallyMountableSelection(
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 7da621ca-62c0-439a-ae23-5905cd80917c
Commits
Reviewing files that changed from the base of the PR and between 0a387af and 05aedd5.
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
… the stream
PGS, VobSub and DVB cues read from an MKV report no start of their own,
and the offset wrapper treated that as a start of 0 and clamped the
shifted start at 0, so a negative offset (advancing subtitles) did
nothing. Their times are sample-relative: Media3 adds the start to the
sample time. The wrapper now passes the signed offset as that start, so
a negative offset advances the cue as the `.sup` sidecar path already
did.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s them
The in-place rendition test built its subtitle rows by hand with
`forced` unset, while the session projects each row with the plan's
`forced` (false). The replan runs on real dispatchers, so when its answer
was adopted before the test checked the local selection, the snapshot
held the adopted identity (`forced=false`) and the check against the
picked one (`forced=null`) failed. CI hit that order. The rows now carry
`forced = false`, so both identities are equal whichever the snapshot
holds.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
…ed cues
The offset wrapper clamped every shifted cue start at 0. For an embedded
track that is wrong: extractors run the parser per sample and Media3 adds
the start to the sample time, so a VobSub cue (start = its control
sequence delay, usually 0) in the sample at 20 s with a -1 s offset still
started at 20 s. The same clamp dropped negative offsets on Matroska text
tracks.
The embedded parser factory now keeps a signed start for tracks whose cue
times are sample-relative (Media3's default, which MKV keeps); TIME_UNSET
starts from PGS and DVB stay as before. Sidecar extractors use the start
as the absolute cue time, so the sidecar factory keeps the clamp, and so
does an HLS WebVTT track, whose format carries an absolute offset.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Review of 593e0f8. Five findings below: I'm fixing four on this branch, and one is left for the maintainers. A summary comment with the scores follows once the fixes are pushed.
The reason will be displayed to describe this comment to others. Learn more.
Low, maintainer decision: going back to the committed native track while another pick's replan is in flight leaves the server on that pick.
Trigger: native track A is committed. The viewer picks B, which switches in place with its replan in flight, then picks A again before B's answer arrives. isServerPick(A, A) is false and canSwitchSubtitleInPlace rejects a target equal to the committed track, so both adapters commit A locally without a replan. B's answer then comes back stale and is discarded. Because it kept the session id, discardStagedVideoReplan sends nothing, and the server session stays on B until the next replan.
This narrows a gap main already has: main never told the server about embedded picks, and a sidecar round trip races the same way. So it isn't a regression. Closing it means queuing a replan back to A behind B's, which changes how both adapters adopt an answer while B is showing locally. I'm leaving that for the maintainers to decide rather than changing it here.
The phone sent every replan that was not a quality change as subtitle_track_changed, so the session manager could adopt an audio pick's answer in place: no remount, the old audio still playing, and the server recording the new one. A request whose audio differs from the committed audio now goes out as audio_track_changed, as on TV.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…action budget
Only a read timeout and an unexpected end of stream counted as extractions. A connection reset after the body started got the media window's retries, about 13 whole-file extractions, and a body closed between chunks (EOFException) or an HTTP/2 stream reset was never retried. A reset, EOF or stream shutdown after this attempt read bytes now counts as a cut-off and is retried within the budget.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rollback restored the whole plan snapshot taken before the adoption. If a PCM retry had changed the audio claims since, that changed the media mount key and remounted the item with the old claims. The predecessor's subtitle decision is now laid over the mounted plan, as the adoption does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
beginInPlaceSwitch landed between the function and its KDoc. Move it back and say that a server-selected track takes the replan.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewed head: f9818dd (the PR's 593e0f8 plus four review fixes).
Fit: 7/10 · Readiness: 6/10 — conditional
Addressed in this review
The phone adopted an audio pick without a remount (db26b83). Every phone replan that wasn't a quality change went out as subtitle_track_changed, so the session manager could adopt an audio change in place while the old audio kept playing. An audio change now goes out as audio_track_changed, as it does on TV. A new test failed on 593e0f8 and passes now.
The sidecar extraction budget missed resets and closed connections (e2cd7d3). A reset after the body started got about 13 retries in the 90 s window, and a body closed between chunks or reset over HTTP/2 got none. Both now count as a cut-off and retry within the two-extraction budget. A new test failed on 593e0f8 and passes now.
A TV in-place rollback could remount with old audio claims (17b3a5b). The rollback now lays the predecessor's subtitle decision over the mounted plan, as the adoption does. This was traced, not reproduced, and has no test.
Misplaced KDoc in TvSubtitleTransactionAdapter (f9818dd).
Earlier bot threads: the two offset findings were already fixed on the branch (807c7b1, 593e0f8). The fatal-sidecar-error claim doesn't hold, because Media3 1.11 disables only the text track on a text stream error. The unbounded-replan point predates this PR. Each thread has a reply with the evidence.
For the maintainers
Returning to the committed native track while another pick is in flight leaves the server session on the abandoned pick until the next replan (inline thread). Main already diverges here, and more widely, so this isn't a regression. Closing it changes how both adapters adopt an answer during a local switch.
No device has run any of the new behavior. That covers bitmap subtitles drawn from the stream, in-place switching, TV rollback, the sidecar retries and the phone mount deadline. The repository asks for before-and-after evidence on phone, tablet, foldable and TV for user-visible changes.
These failed on main's merge base for the behavior they cover: TrackSelectionFingerprintTest, NativeEmbeddedSubtitleProtocolTest, PlaybackCapabilityDetectorDolbyVisionTest, SubtitleManagerTrackSelectionTest and HlsSubtitleRenditionTest.
These don't build on the base because they test code the PR adds, so they aren't evidence of a fix: the in-place, sidecar-period and retry-policy tests, the phone and TV adapter tests, SequencedPlaybackTest, HlsSubtitleRenditionProtocolTest and OffsetSubtitleParserFactoryTest. NativeEmbeddedSubtitleTest passes on the base, so it doesn't detect the change either.
Validated features
The board couldn't be read in this run, so no passed case was checked against it. By hand:
using-silo/subtitles.md says that turning on or switching a subtitle from inside the file "restarts the video at the same spot". With this PR, its Apple pair and the server change, that switch happens in place. I recommend a siloserver.org issue for that paragraph once the three merge. No open issue covers it.
Unit tests (6,691, 0 failures; one TV test failed once in a coroutine teardown and passed on three reruns), lint on all three modules (no findings over the baseline), and assembleDebug for phone and TV, all on this head. The supply-chain scripts need Ruby, which the review host doesn't have, so CI covers them. The fixes touch no build files.
Review method
Claude Code finders on three angles, a Codex (gpt-6.1-sol) adversarial round on 593e0f8, and a verifier for each candidate. Validation-board access was unavailable.
Takes #770's tree as is: the integration branch's older copies of the
same changes give way to the reviewed versions on #770.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The media source factory builds an item's content from a copy with its
subtitle configurations removed and merges each sidecar beside it.
MergingMediaSource reports its first child's item, so the player's
timeline and Player.getMediaItemAt named the copy. The subtitle sync
reprepare rebuilds the playlist from those items, so changing subtitle
timing dropped every sidecar. On TV that also changed the merged track
layout the text selection pointed at, and the subtitle went off while
the HUD still showed it selected. #770's in-place switching made this
common on HLS, because a switch keeps the previous sidecar in the item.
The merged source now reports the item it was built from, sidecars
included, in its media item and its timeline.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reopens
A same-route reopen (the first answer to a startup stall) armed the
subtitle reselection from what the player showed. A stalled transport can
show none while a pick the adapter is mounting has not been confirmed, so
the reopen armed Off over that pick at the same authority. The pick then
failed its mount deadline and replanned for a whole-file sidecar. On the
Onn, Woman of the Hour went about 75 s without subtitles this way.
A reopen now keeps the adapter's in-flight mount, under its own owner,
and restores the player's selection only when nothing is in flight.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
TV checks its local subtitle mount deadline every 5 s and counts it only
once the mount has text tracks, but it failed at the first check that
found tracks, however recently they had appeared. Tracks published just
before a check left the selection a fraction of a second to confirm. On
the Onn this failed a native pick 9.7 s after it was armed, right as the
reopened transport published its tracks, and replanned for a whole-file
sidecar. The phone got the same fix earlier in this branch.
The window now starts at the first check that finds tracks, or at once
when the mount already has them, and the 30 s cap still applies.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a subtitle pick's replan answer fails the transport-keep check, the
app remounts and logged nothing about why. The check now names the first
part of the plan that changed (stream URL, headers, audio, a sidecar
artifact and so on), and the session manager logs it as
subtitle_replan_not_in_place.
The regression run on shared dev showed direct-play switches remounting
on both phone and TV. #3331 reuses the transport only for HLS and mints
a new stream URL for each original_http answer, so the expected reason
there is stream_url; the log lets a device run confirm it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
enhancementNew feature or requestevidence-requiredNeeds before-and-after evidence before the Evidence check passesimpact: playbackCan't play, stalls, or wrong medianeeds-reviewNeeds maintainer review to resolve uncertain classification, scope, or changed evidence.priority: P2Limited scope, workaround exists, or polishsize/XXXL3000+ added + deleted lines (all files); change volume, not priority.
1 participant
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
Related issue: #458, #457, #79, Silo-Server/silo-server#1406
Validation tasks: changes #323 C3, C4; changes #324 C3, C4, C5
Pairs with Silo-Server/silo-apple#970
Embedded subtitles on the phone and TV apps cost the server too much and kept viewers waiting. Picking an embedded track usually made the server extract it from the whole source file, which takes minutes on large files on slow storage (Silo-Server/silo-server#1406). Image-based tracks went through a
.supextraction or a burn-in transcode. A slow sidecar was retried like media, and each retry started another whole-file read. A slow sidecar could also hold back or fail the video. Switching subtitles always remounted the player, even when the stream already carried the track.This pull request makes the apps draw more embedded tracks straight from the stream, bounds sidecar retries, and switches subtitles on the playing stream without a remount. It combines five pull requests (#731–#735) into one, one commit each, so the team can review the stack in one place.
Approach
Server dependency
The in-place switching (fifth section) uses two parts of Silo-Server/silo-server#3331: the
stream_index,container_track_idandnative_selectablefields on inventory rows, andhls_subtitle_renditions_all_v1, which lists every embedded text track as an HLS rendition. The apps ask for the new behavior only when the server advertises it, and behave as before against a server without it. The vendored playback-v3 fixtures come from that unmerged server change and need a re-sync from servermainonce it lands. The first four sections need no server change.Phone native subtitle mount deadline (was #731)
PlayerScreenreports whether the current mount has text tracks. Android TV already polled this way; it doesn't have the window fix.subtitle_embedded_failedand cost a whole-file sidecar extraction.HLS subtitle renditions on copy remuxes (was #732)
hls_remux_subtitle_renditions_v1when the server advertises it, and accept a WebVTT rendition onserver_remux_hlsplans as well as transcodes. The gate matchesbuffering_quality_v1's, so Cast never asks. A rendition that fails to mount still replans for the sidecar.main.Embedded MKV bitmap subtitles from the stream (was #734)
native_embeddedcapability onoriginal_httplistshdmv_pgs_subtitle,dvd_subtitleanddvb_subtitle. Media3 1.11'sMatroskaExtractorgives these tracks their Matroska TrackNumber asFormat.id, so the existingcontainer_track_idselection works unchanged.validateForMedia3accepts the server's short codec aliases, anddvd_subtitlenow maps to VobSub instead of DVB. The subtitle sync offset now applies to these cues, whose times are relative to their sample: PGS and DVB report no start of their own, and VobSub a small relative one. Before, a positive offset was lost on PGS and DVB, a negative one made those cues never appear, and a negative offset on VobSub (and on Matroska text tracks) was clamped away. A negative offset now advances them, as it did on the.supsidecar path. Sidecars keep their absolute, clamped starts..supextraction of the whole file, and VobSub and DVB through a burn-in transcode, even in direct play.native_embedded.Sidecar subtitle retries (was #735)
Switching subtitles on the playing stream (was #733)
track_changereplan goes out in the same step. That covers anative_selectablerow on direct play, an every-track rendition on HLS, and Off on either.docs/playback/README.mdrecords the design and the rollback rules.Validation
test-check-build-supply-chain.sh,check-build-supply-chain.sh): pass../gradlew testDebugUnitTest: pass, 6,687 tests, 0 failures. One earlier run failedLocalRouteTransportTest, in network code this change doesn't touch; it passed on three reruns and in the full rerun.:android-shared:lintDebug,:androidApp:lintDebug,:androidTvApp:lintDebug,:androidApp:lintVitalRelease,:androidTvApp:lintVitalRelease: pass, no new findings.:androidApp:assembleDebugand:androidTvApp:assembleDebug: pass.testDebugUnitTestpasses, 6,691 tests with 0 failures.TvItemDetailSubtitlePreferenceTestfailed once in a coroutine teardown and passed on three reruns. Lint on all three modules found nothing new, andassembleDebugpasses for phone and TV. The two new tests failed on 593e0f8. The supply-chain scripts weren't run on the review host, which has no Ruby, so CI covers them.mainand on every open pull request for a reason outside this change. Gradle dependency verification rejects theorg.jetbrains.kotlin.plugin.serialization2.1.20 marker POM that the Gradle Plugin Portal now serves;gradle/verification-metadata.xmltrusts the Maven Central copy.Evidence
Evidence: https://evidence.siloserver.org/r/silo-android/pr-770/
Risks
Checklist
AI Disclosure
One is left open for the maintainers: going back to the committed native track while another pick's replan is in flight leaves the server on that pick until the next replan.
main's deliberate policy: a replan goes again once the device is back online.🤖 Generated with Claude Code
Note
Draw embedded subtitles from the stream and switch them without a remount
nativeEmbeddedSubtitleCodecand a native-selectability flag inPlaybackSubtitleInventoryItemV3(PlaybackProtocolV3.kt).carriesHlsSubtitleRendition,switchableHlsRendition, and new feature-gated request helpers so every embedded text track can be exposed as a rendition.canSwitchSubtitleInPlaceandPlaybackPlanV3.inPlaceMismatchdecide eligibility,PlaybackSessionManagermarks subtitle-only replan candidates as in-place, and the TV/mobile adapters apply the pick on the playing stream before the replan response arrives, with rollback to the committed subtitle on failure.SidecarSubtitleLoadErrorHandlingPolicywith its own retry budget, andNonGatingSidecarPeriodannounced-track state so sidecar tracks are listed before the sidecar loads (SidecarSubtitleMediaSource.kt).TvPlayerScreenandPlayerScreennow key the player preparation effect on the plan'smediaMountKey, so plan changes that preserve that key no longer remount; subtitle rows in session responses now carry rendition and container-track identity for in-place switches.Macroscope summarized 951475c.