Repository navigation
Conversation
… recovery Findings from a code survey of seven open-source Android players (jellyfin-androidtv, Findroid, jellyfin-android, Streamyfin, NextPlayer, Just Player, mpv-android), written up in docs/media3/10. - Mobile player-error recovery (parity with TV): wire onPlayerError and PlaybackRecoveryPlanner into PlayerViewModel — bounded transient-network same-route retry, alternate direct engine with attemptedEngines guard and route-event telemetry, then server remux/transcode, single-flighted. Previously decoder/IO failures were dropped and every preflight issue forced a FULL transcode. - Dolby Vision Profile 7: allow native direct play when the decoder claims dual-layer DV with multi-instance HEVC (the probe's existing gate); DisplayHdrProbe no longer strips P7 from the panel intersection (Android panels can't report per-profile DV support). Non-native P7 now prefers an alternate direct engine (mpv renders the HDR10 base layer) over transcode, and never remuxes (a remux re-sends the same rejected stream). - mpv audio passthrough: default ao is now audiotrack,aaudio — mpv's AAudio AO cannot open IEC61937 streams, so audio-spdif passthrough silently decoded Atmos/TrueHD to PCM under aaudio. - mpv hwdec: direct-first (mediacodec,mediacodec-copy) instead of forced copy-back, halving decode memory bandwidth on 4K. - TS extractor hardening: FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS and a 1500-packet timestamp search window for Blu-ray-sourced M2TS and high-bitrate transport streams. Server follow-up: the resolver still emits dolby_vision_profile_7_not_launch_claimed, which preempts the new client ladder; it should stop blocking P7 (or offer MPV_DIRECT as a fallback) now that clients claim and handle it honestly. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AaKRXz1mtnsDm6pn1LDkmz
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughThis PR revises Dolby Vision profile 7 handling across HDR probing, direct-play eligibility, and recovery planning, adds a bounded playback error-recovery ladder to PlayerViewModel with alternate-engine and server-transcode fallback, updates mpv/TS extractor defaults, and documents the changes. ChangesDolby Vision profile 7 policy and playback recovery
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PlayerScreen
participant PlayerViewModel
participant PlaybackRecoveryPlanner
participant PlaybackSessionManager
PlayerScreen->>PlayerViewModel: onPlayerError(error)
alt transient IO network error
PlayerViewModel->>PlayerViewModel: retry same route (bounded)
else other error
PlayerViewModel->>PlaybackRecoveryPlanner: planForPlayability(...)
PlaybackRecoveryPlanner-->>PlayerViewModel: PlaybackRecoveryAction
alt AlternateDirectEngine
PlayerViewModel->>PlaybackSessionManager: report PlaybackRouteEventRequest
else
PlayerViewModel->>PlayerViewModel: startServerRecoveryFallback (single-flight)
end
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47292802e9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (positionSec > 0 && transientNetworkRetries > 0) { | ||
| transientNetworkRetries = 0 | ||
| } |
There was a problem hiding this comment.
Keep retry budget until playback actually advances
When a transient network error happens after the playhead is already >0, the remount enters STATE_BUFFERING; PlayerScreen still calls onPositionChanged while buffering with the same currentPosition. This resets transientNetworkRetries before any playback has advanced, so a persistent outage after the first retry can keep getting another “one” retry instead of falling through to the recovery ladder. Compare against the previous position, or reset from an actual playing/progress signal, so the budget is restored only after forward progress.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/media3/README.md (1)
66-69: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winStale quick-answer contradicts the new P7 policy just added below.
Line 68 still states "Profile 7 is not a launch-safe Android TV DV direct-play claim and needs the fallback policy in 09", but the newly-added entry at lines 82-87 says P7 direct-plays when the decoder reports dual-layer DV with multi-instance HEVC support. These two quick-answers now disagree on whether P7 can ever direct-play, which will confuse readers.
📝 Suggested fix
- **"Why doesn't Dolby Vision work on my TV?"** Check the profile and selected route. DV Profile 5 needs a decoder **and** a DV-capable HDMI link; Profile 7 - is not a launch-safe Android TV DV direct-play claim and needs the fallback - policy in **09**. + direct-plays only when the decoder reports dual-layer DV with multi-instance + HEVC support; otherwise it falls back per the policy in **09** and **10 §4**.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/media3/README.md` around lines 66 - 69, The Dolby Vision quick-answer in the README is stale and conflicts with the newer Profile 7 policy entry. Update the existing FAQ text near the “Why doesn’t Dolby Vision work on my TV?” item so it matches the current P7 behavior described by the newer Dolby Vision policy section, and make sure the wording in the README is consistent with the logic in the Dolby Vision decoder/direct-play guidance.
🧹 Nitpick comments (1)
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/mpv/MpvPlayer.kt (1)
65-77: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuempv AO/hwdec priority-list defaults look correct.
The comma-separated fallback ordering for
audioOutput/hwDecmatches documented mpv behavior for these options, and the rationale comments are clear and accurate.One minor note: these default string literals (
"audiotrack,aaudio","mediacodec,mediacodec-copy") are now duplicated between the class constructor defaults (Lines 71, 77) and theBuilderdefaults (Lines 135, 138). Pre-existing pattern, but consider hoisting them intocompanion objectconstants to prevent the two copies drifting apart on a future tuning change.♻️ Optional: single source of truth for defaults
companion object { private const val TAG = "SiloMpvPlayer" private const val AUDIO_FOCUS_DUCKING = 0.5f + private const val DEFAULT_AUDIO_OUTPUT = "audiotrack,aaudio" + private const val DEFAULT_HWDEC = "mediacodec,mediacodec-copy"Then reference
MpvPlayer.DEFAULT_AUDIO_OUTPUT/MpvPlayer.DEFAULT_HWDECfrom both the class constructor default andBuilder.Also applies to: 135-138
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/mpv/MpvPlayer.kt` around lines 65 - 77, The mpv fallback defaults are correct, but the `audioOutput` and `hwDec` string literals are duplicated between `MpvPlayer` constructor defaults and `Builder` defaults, which risks them drifting over time. Hoist these defaults into shared `companion object` constants on `MpvPlayer` (for example, `DEFAULT_AUDIO_OUTPUT` and `DEFAULT_HWDEC`) and update both the primary constructor and `Builder` to reference those symbols so there is a single source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt`:
- Around line 76-84: The TS extractor overrides in SiloPlayerFactory are only
being applied through the shared ExtractorsFactory, which does not affect HLS
playback. Update the HLS setup in this class so the same TS/M2TS settings are
applied separately to the HLS extractor factory as well, ensuring the
FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS and timestamp search bytes overrides are used
for .m3u8 streams too.
In
`@androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt`:
- Around line 284-293: The new recoveryJob in PlayerViewModel can outlive
content/version/exit changes and later overwrite _uiState with stale session
data. Cancel and null recoveryJob anywhere playback context changes or ends
(loadContent, onSelectVersion, onExit, onCleared), and reset attemptedEngines
plus transientNetworkRetries when switching versions like the existing
engineSwitchFallbackAttempted reset. Also add a staleness guard in the recovery
completion path, following resolveNextEpisode’s forContentId check, so any late
recovery result is ignored if the active content/session has changed.
---
Outside diff comments:
In `@docs/media3/README.md`:
- Around line 66-69: The Dolby Vision quick-answer in the README is stale and
conflicts with the newer Profile 7 policy entry. Update the existing FAQ text
near the “Why doesn’t Dolby Vision work on my TV?” item so it matches the
current P7 behavior described by the newer Dolby Vision policy section, and make
sure the wording in the README is consistent with the logic in the Dolby Vision
decoder/direct-play guidance.
---
Nitpick comments:
In
`@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/mpv/MpvPlayer.kt`:
- Around line 65-77: The mpv fallback defaults are correct, but the
`audioOutput` and `hwDec` string literals are duplicated between `MpvPlayer`
constructor defaults and `Builder` defaults, which risks them drifting over
time. Hoist these defaults into shared `companion object` constants on
`MpvPlayer` (for example, `DEFAULT_AUDIO_OUTPUT` and `DEFAULT_HWDEC`) and update
both the primary constructor and `Builder` to reference those symbols so there
is a single source of truth.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 49760559-d1cf-454a-906e-723787f43e37
📒 Files selected for processing (11)
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/DisplayHdrProbe.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/PlaybackCapabilityDetector.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/PlaybackRecoveryPlanner.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/mpv/MpvPlayer.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/PlaybackCapabilityDetectorDolbyVisionTest.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/PlaybackRecoveryPlannerTest.ktandroidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerScreen.ktandroidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.ktdocs/media3/10-reference-player-comparison.mddocs/media3/README.md
| // HDMV DTS streams (Blu-ray-sourced M2TS) use a stream type the TS | ||
| // payload reader skips by default, so DTS tracks vanish from | ||
| // Blu-ray-remux transport streams without this flag. | ||
| .setTsExtractorFlags(DefaultTsPayloadReaderFactory.FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS) | ||
| // The default PCR search window is too small for high-bitrate 4K | ||
| // remux/transcode TS segments with sparse PTS — startup then fails | ||
| // with "timestamp not found" (androidx/media #8571-class failures). | ||
| // 1500 packets matches what battle-tested players ship. | ||
| .setTsExtractorTimestampSearchBytes(1500 * TsExtractor.TS_PACKET_SIZE) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Does DefaultMediaSourceFactory pass a custom ExtractorsFactory to HlsMediaSource in current androidx media3?
💡 Result:
No, DefaultMediaSourceFactory does not pass a custom ExtractorsFactory to HlsMediaSource [1][2]. The ExtractorsFactory provided to the DefaultMediaSourceFactory constructor is intended for and used by ProgressiveMediaSource (the fallback media source for regular media files) [1][2]. HlsMediaSource uses a different type of factory for its segments, called an HlsExtractorFactory [3][4]. HlsMediaSource.Factory uses DefaultHlsExtractorFactory by default [3][4]. If you need to customize extraction for HLS, you must use the HlsMediaSource.Factory.setExtractorFactory method directly, rather than providing an ExtractorsFactory to the DefaultMediaSourceFactory [3][4].
Citations:
- 1: https://developer.android.com/reference/androidx/media3/exoplayer/source/DefaultMediaSourceFactory
- 2: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/DefaultMediaSourceFactory
- 3: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsMediaSource.Factory
- 4: https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsMediaSource.Factory
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant factory and surrounding wiring.
file="android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt"
sed -n '1,220p' "$file"
printf '\n\n--- grep for HLS/extractor wiring ---\n'
rg -n "DefaultMediaSourceFactory|HlsMediaSource|ExtractorsFactory|setExtractorFactory|setTsExtractorFlags|setTsExtractorTimestampSearchBytes" \
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt \
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player \
|| trueRepository: Silo-Server/silo-android
Length of output: 13692
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Probe Media3 API docs from the codebase? No network here, so just inspect local references if any.
rg -n "setExtractorFactory\\(|DefaultHlsExtractorFactory|HlsExtractorFactory" android-shared/src || trueRepository: Silo-Server/silo-android
Length of output: 162
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt"
# Show the relevant region with line numbers.
nl -ba "$file" | sed -n '1,220p'
printf '\n--- HLS / extractor references in the repo ---\n'
rg -n "DefaultMediaSourceFactory|HlsMediaSource|ExtractorsFactory|setExtractorFactory|DefaultHlsExtractorFactory|setTsExtractorFlags|setTsExtractorTimestampSearchBytes" android-shared/src || trueRepository: Silo-Server/silo-android
Length of output: 202
Apply the TS extractor overrides to HLS separately
DefaultMediaSourceFactory(context, extractorsFactory) only forwards this ExtractorsFactory to progressive playback; HLS builds its own extractor factory. If these TS/M2TS streams can be delivered as .m3u8, the DTS and timestamp-search settings won’t apply there, and the same playback failures can still surface on that path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt`
around lines 76 - 84, The TS extractor overrides in SiloPlayerFactory are only
being applied through the shared ExtractorsFactory, which does not affect HLS
playback. Update the HLS setup in this class so the same TS/M2TS settings are
applied separately to the HLS extractor factory as well, ensuring the
FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS and timestamp search bytes overrides are used
for .m3u8 streams too.
|
|
||
| // Recovery ladder state — mirrors TvPlayerViewModel. The planner picks the | ||
| // cheapest viable fallback (alternate direct engine → server remux → | ||
| // transcode); attemptedEngines prevents Media3↔mpv ping-pong; the | ||
| // transient-network budget lets a single blip retry the SAME route instead | ||
| // of demoting a healthy direct stream for the rest of playback. | ||
| private val recoveryPlanner = PlaybackRecoveryPlanner() | ||
| private val attemptedEngines = mutableSetOf<PlaybackEngineKind>() | ||
| private var transientNetworkRetries = 0 | ||
| private var recoveryJob: Job? = null |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
recoveryJob isn't cancelled (or staleness-guarded) across content/version/exit transitions.
recoveryJob is new state, but none of loadContent, onSelectVersion, onExit, or onCleared cancel it — unlike resolveNextEpisodeJob, which loadContent already cancels for this exact class of race. If a server recovery fallback is in flight when the user advances episodes, switches version, or exits, its eventual completion unconditionally overwrites _uiState (sessionId, playbackPlan, streamUrl, startPosition, …) with data belonging to the old, already-stopped session — corrupting the new session's playback state. attemptedEngines/transientNetworkRetries have the same gap in onSelectVersion (only engineSwitchFallbackAttempted is reset there).
Cancelling the job is necessary but not sufficient on its own (cooperative cancellation can't preempt a coroutine already past its last suspension point). The existing resolveNextEpisode() guards exactly this hazard by capturing forContentId and checking it before applying the update — recommend the same pattern here.
🔧 Proposed fix
autoAdvanceHandled = false
engineSwitchFallbackAttempted = false
attemptedEngines.clear()
transientNetworkRetries = 0
+ recoveryJob?.cancel()
+ recoveryJob = null
resolveNextEpisodeJob?.cancel()Apply the same recoveryJob?.cancel(); recoveryJob = null (plus attemptedEngines.clear() / transientNetworkRetries = 0) in onSelectVersion() near engineSwitchFallbackAttempted = false, and in onExit() / onCleared() alongside the other job cancellations.
Additionally, guard the completion handler itself:
when (val r = playbackSessionManager.startTranscodeFallbackRecoveringMissingSession(...)) {
is ApiResult.Success -> {
val fallback = r.data
+ // Skip a stale completion that raced a subsequent
+ // loadContent/onSelectVersion/onExit for a different session.
+ if (_uiState.value.sessionId != sessionId) return@launch
sessionLifecycle.adoptActiveSession(...)Also applies to: 398-399
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt`
around lines 284 - 293, The new recoveryJob in PlayerViewModel can outlive
content/version/exit changes and later overwrite _uiState with stale session
data. Cancel and null recoveryJob anywhere playback context changes or ends
(loadContent, onSelectVersion, onExit, onCleared), and reset attemptedEngines
plus transientNetworkRetries when switching versions like the existing
engineSwitchFallbackAttempted reset. Also add a staleness guard in the recovery
completion path, following resolveNextEpisode’s forContentId check, so any late
recovery result is ignored if the active content/session has changed.
|
Closing this in favor of a consolidated parity/open-issues PR from fix/open-issues-upstream-main. The current branch already contains this work plus later followups and review-comment fixes will land in the consolidated PR. |
Summary
Follow-up to a code-level survey of seven open-source Android video players (jellyfin-androidtv, Findroid, jellyfin-android, Streamyfin, NextPlayer, Just Player, mpv-android — shallow-cloned and read end-to-end). The survey's conclusion: our player architecture already exceeds every surveyed app on engine routing, capability probing, and fallback planning — so no rewrite, but five concrete gaps were found and are fixed here. The full comparison lives in
docs/media3/10-reference-player-comparison.md.Fixes
onPlayerErrorwiring and forced a FULL transcode on any preflight failure. It now runs the TV ladder: bounded transient-network same-route retry →PlaybackRecoveryPlanner→ alternate direct engine (attemptedEnginesping-pong guard, route-event telemetry) → server remux → transcode, single-flighted. (PlayerViewModel.kt,PlayerScreen.kt)MediaCodecCapabilitiesProbe's existing gate — the same model jellyfin-androidtv ships).DisplayHdrProbeno longer fabricates a[5, 8]panel profile list that silently vetoed legitimate P7 decoder claims.UnsupportedDvProfilenow prefers an alternate direct engine (mpv renders the P7/P8 HDR10 base layer, tone-maps P5) and excludes remux (it re-sends the exact stream the decoder rejected) before conceding a transcode — Just Player'smapDV7ToHevcoutcome without maintaining a Media3 fork.aowasaaudio, whose mpv AO cannot open IEC61937 (compressed) streams, so the existingaudio-spdifconfig silently decoded to PCM. Nowaudiotrack,aaudio.mediacodec,mediacodec-copyinstead of forced copy-back (double memory bandwidth on 4K); mpv falls back per-codec automatically.FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS(DTS in Blu-ray-sourced M2TS) + 1500-packet timestamp search window. (SiloPlayerFactory.kt)Server follow-up (separate repo)
The resolver still emits the
dolby_vision_profile_7_not_launch_claimedblocker, which preempts the new client ladder with an immediate FULL transcode. To realize the P7 benefit it should stop blocking P7 (or listMPV_DIRECTas a fallback) now that clients claim and handle it honestly.Test plan
:android-shared:testDebugUnitTest— passes, including new tests: P7 policy (native-gated, P5 unchanged, P8 unchanged) and planner behavior (UnsupportedDvProfile→ alternate engine, never remux):androidApp:testDebugUnitTest,:shared:testDebugUnitTest— pass:androidApp:assembleDebug,:androidTvApp:assembleDebug— build:androidTvApp:testDebugUnitTest— passes; noteTvAuthSingleFlightTestis load-flaky on main too (KtorMockEnginereal-dispatcher work racing a virtual-timewithTimeout) — unrelated to this diff, worth a separate fix🤖 Generated with Claude Code
https://claude.ai/code/session_01AaKRXz1mtnsDm6pn1LDkmz
Summary by CodeRabbit
New Features
Bug Fixes
Documentation