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
fix(player): prevent direct passthrough seek stalls on Android TV - #1132
Closes#942
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (Android AudioFlinger and Media3 direct passthrough path only); Roku N/A (does not use Media3 AudioTrack); Web N/A (browser media stack)
Forward seeks that land inside the forward buffer (Auto Skip Intro, Skip Intro, or D-pad skip) can jump roughly 5 seconds ahead and stall in buffering for 20 seconds on Android TV devices using direct HDMI audio passthrough (such as DTS-HD MA and E-AC3 on NVIDIA Shield), until the startup stall detector forces a full stream reload.
When a seek lands inside already-buffered media, Media3 releases the old AudioTrack asynchronously (20 ms later) while constructing a replacement AudioTrack on the same audio session. Android's AudioPolicyManager can reuse the active DirectOutputThread, so the replacement track's getPlaybackHeadPosition() reads a stale counter from the previous segment or drops back to 0 when AudioFlinger invalidates the old track and flushes the shared output. In Media3 1.11.0, AudioTrackPositionTracker treats any backward drop (except 0 on API <= 29 while playing) as a 32-bit unsigned wrap (+2^32 frames, upstream androidx/media#3407), and a stale counter above writtenFrames flips DefaultAudioSink.hasPendingData() to false, leaving MediaCodecAudioRenderer stuck in STATE_BUFFERING.
Approach
Add DirectPassthroughAudioOutputProvider (implementing Media3 1.11's non-deprecated AudioOutputProvider) and wire it into DefaultAudioSink.Builder in SiloPlayerFactory.
Delegates format support, output configuration, and all PCM, offload, and virtual-device (virtualDeviceId != INDEX_UNSET) tracks to AudioTrackAudioOutputProvider unchanged, keeping explicit Format.channelMask handling intact.
Forwards routed AudioDeviceInfo callbacks from wrapped passthrough tracks into delegate's AudioCapabilitiesReceiver through FormatConfig.preferredDevice (including the first route) and keeps one persistent mirror AudioCapabilitiesReceiver registered once passthrough is supported. On recoverable write errors (ERROR_DEAD_OBJECT), direct passthrough falls back to PCM on the live delegate while preserving platform audio offload support flags/configs, and restores passthrough when HDMI capabilities refresh—even with unchanged codecs.
Wraps direct passthrough tracks (non-PCM, non-offload, local-device, including tunneled passthrough) in a DirectPassthroughAudioTrack whose DirectPassthroughHeadPositionFilter:
tracks active play time via play(), pause(), and stop() so paused or rebuffering wall time does not inflate forward-jump bounds;
absorbs stale initial counters above min(activePlay + 100 ms, 200 ms) (always below Media3's 250 ms minimum passthrough buffer) and implausible forward spikes above activeDelta + 200 ms as baseline shifts instead of advancing past writtenFrames;
holds the reported head on retrograde drops (including genuine 32-bit unsigned wraps across one poll) until either the pre-drop counter rebounds—reconciling both direct and staged rebounds (4800 -> 0 -> 240 -> 5040, including delayed polls) without double-counting—or a new counter epoch advances monotonically;
preserves API <= 29 zero pass-through while playing so Media3's 200 ms stall recovery keeps working;
shifts AudioTimestamp.framePosition by the same epoch offset, enforces strict monotonicity so Media3's AudioTimestampWrapper cannot permanently wrap by +2^32, and withholds timestamps across pending resets, ambiguous rebound windows (until the selected epoch confirms), or skew;
resets only when AudioTrack.flush() actually flushes an initialized non-playing track, and logs bounded anomalies via SiloLog.w outside the filter lock.
Reports the provider's audio capabilities from PassthroughSuppressingAudioSink.getAudioCapabilities(). DefaultAudioSink only reads them from Media3's own provider, and without them IAMF tracks decode to stereo.
Upgrading to Media3 1.12.0-rc01 was rejected because 1.12 is still a release candidate, requires rebuilding the bundled FFmpeg decoder AARs and verification metadata, and upstream 4c95cd96b53 only guards backward wraps without absorbing an inherited stale counter above writtenFrames.
Validation
Review re-verification on 56fed85 (NVIDIA Shield, Android 11): 9/9 DTS-HD MA in-buffer seeks settled with no rebuffer and no 2^32 timestamp warnings, all on a reused direct output, including a rapid double press and a seek after pause and resume; E-AC3 3/3 and TrueHD 3/3 clean. On main, 4 of 9 DTS-HD MA seeks rebuffered and the double press stalled for about 19 s. Waiting for the old track's release before opening the new one (tested as an alternative, not merged) still left a 5-6 s stale first reading on reused outputs, so the head filter is needed.
fails-on-base against 79be4c4: the two review regression tests (sink reports audio capabilities; no format-support notification on entering the write-error fallback) fail and pass on 56fed85.
Live on NVIDIA Shield TV Pro (Android 11) against a Silo dev deployment: before the fix (b15d2be293), the first in-buffer DTS-HD MA seek jumped +5.05 s, logged a 2^32 spurious audio timestamp mismatch, and stalled 20.0 s in STATE_BUFFERING until reload. On e9bee2fa2, 6/6 consecutive in-buffer DTS-HD MA seeks absorbed stale inherited heads (409k–424k frames) and held retrograde drops to 0, reaching player ready in 93–160 ms with zero buffering stalls and continuous AudioFlinger direct output writes (Total writes: 58 -> 68, Frames written: 7,602,176 -> 8,912,896 over 3 s, signal power -11.7 to -13.5 dB); 3/3 E-AC3 (125–281 ms) and 3/3 Dolby TrueHD (114–276 ms) in-buffer seeks also settled cleanly.
Phone, tablet, and foldable form-factor recordings do not apply: this change adds no UI or layout changes, and direct encoded bitstream passthrough (ENCODING_DTS_HD, ENCODING_DOLBY_TRUEHD, ENCODING_E_AC3) requires an HDMI AVR / Android TV sink; linear PCM output on phones, tablets, and foldables bypasses the wrapper (!DirectPassthroughAudioOutputProvider.shouldWrap(outputConfig)) and goes straight to Media3's AudioTrackAudioOutputProvider.
fails-on-base against b15d2be293: all 3 SiloPlayerFactoryDirectPassthroughTest cases compiled on main, failed for the stale-head jump and +2^32 wrap hasPendingData() collapse, and passed with the fix.
fails-on-base against da2ddd855: all 4 Round 2 regression cases compiled on da2ddd855, failed for the exact Round 1 review findings, and passed on e9bee2fa2.
fails-on-base against e9bee2fa2: both regression cases (transientZeroGlitchDirectAndStagedReboundsDoNotDoubleCountFrames with 60 ms delayed poll + old-epoch timestamp check, and recoverableWriteErrorPreservesAudioOffloadSupportAndConfig) compiled on e9bee2fa2, failed for the exact Round 2 council findings (S3, S4, S5/O3), and passed on 79be4c4b0.
Full Android unit test suite (./gradlew testDebugUnitTest), debug lint (:android-shared:lintDebug, :androidApp:lintDebug, :androidTvApp:lintDebug), and debug builds (:androidApp:assembleDebug, :androidTvApp:assembleDebug) passed on 79be4c4b0 with zero new warnings; release vital lint and TV release APK build passed on e9bee2fa2 and run in GitHub CI (Release readiness) on 79be4c4b0.
Supply-chain policy scripts (./scripts/check-build-supply-chain.sh) could not run locally because ruby is absent on this Linux builder; no build, workflow, or dependency files changed, and GitHub CI runs them on this PR.
Offloaded compressed tracks (isOffload = true) and API 34+ non-default virtual-device tracks (virtualDeviceId != C.INDEX_UNSET) delegate to stock AudioTrackAudioOutputProvider because those options require AudioTrack.Builder rather than an AudioTrack subclass. Local phone and TV video passthrough does not use either path.
Follow-ups
User manual: none needed — checked siloserver.org docs and milestone specs (src/content/docs/, src/data/, public/milestone/1.0/index.html); this change fixes an internal playback seek stall without altering settings, UI, or documented behavior.
Remove DirectPassthroughAudioOutputProvider once Silo upgrades to a stable Media3 release that addresses both backward wraps (androidx/media#3407) and stale inherited direct-output counters.
Council review
Rounds: 4, last reviewed 79be4c4b0 (review findings addressed in 56fed85)
Member
Round 1 (da2ddd855)
Round 2 (e9bee2fa2)
Review: redirect test (79be4c4b0)
Review (79be4c4b0)
Sol (gpt-6.2-sol, medium)
7/10
7/10
6/10
6/10
Opus (claude-opus-5-5, medium)
7/10
8/10
5/10
6/10
Gemini (gemini-4-neon, medium)
8/10
9.5/10
5/10
8/10
Visual review: skipped — no user-visible UI layout or styling changed.
Fixed: Round 1 (e9bee2fa2): S1/O1/G1 routed-device forwarding via FormatConfig.preferredDevice, S2/G2/Codex P2 live-delegate PCM + persistent mirror AudioCapabilitiesReceiver recovery on unchanged HDMI capabilities, O2 removal of redundant 32-bit wrap branch, and Kody/CodeRabbit maxInitial cap + staged-rebound reconciliation. Round 2 (79be4c4b0): S3 20 ms staged-rebound threshold for delayed polls, S4 withholding hardware timestamps across the ambiguous rebound window until the epoch confirms, S5/O3 preserving audio offload support flags and offload output configs during direct write-error fallback, and O4 simplifying getOutputConfig's fallback refresh.
Review (56fed85): IAMF capabilities reported through the sink (Sol S4, Gemini G1), no notification on entering the write-error fallback (Gemini G2), KDoc wording. Open for maintainers: trimming the staged-rebound and new-epoch logic (Opus O1), and low risks noted in their threads (sub-200 ms stale first reading, API <= 29 zero pass-through, route change during fallback).
Answered: Kody's three follow-up nits on e9bee2fa2 (reversing its maxInitial cap and 24.85-hour/6.21-hour single-track 32-bit wrap edge cases) were answered in-thread with evidence and left open for maintainer review.
Involvement: Fully AI-generated, hardware-verified on NVIDIA Shield TV Pro
Adversarial review: Tracked in Council review above (plus a plan round before implementation).
Note
Fix direct passthrough seek stalls on Android TV with filtered audio head positions
Adds DirectPassthroughAudioOutputProvider in DirectPassthroughAudioOutputProvider.kt, which wraps non-linear-PCM, non-offload direct passthrough outputs in a DirectPassthroughAudioTrack that filters playback-head positions and timestamps.
DirectPassthroughHeadPositionFilter caps implausible initial head positions (200 ms), absorbs impossible forward jumps, holds retrograde drops, and reconciles counter resets without adding the reset value to prior positions. Timestamps are shifted into the reported frame epoch or withheld when ambiguous, with a 2,000 ms skew limit.
SiloPlayerFactory now builds the audio sink through the new provider, and PassthroughSuppressingAudioSink can report capabilities from a supplied getter.
Recoverable write errors switch non-RAW capability reporting to defaults while offload output configuration stays available; an HDMI capability broadcast clears the fallback.
Risk: only direct passthrough outputs without a virtual device are wrapped; check the wrap predicate in the DirectPassthroughAudioOutputProvider companion and the tunneled audio attributes, since filtered head positions change what Media3 sees on affected TVs.
…alls
Wrap direct passthrough (non-PCM, non-offload, local-device, including tunneled) AudioTrack instances via a non-deprecated AudioOutputProvider so stale inherited head positions and retrograde AudioFlinger/HAL drops on reused DirectOutputThread outputs do not trigger Media3 1.11's false +2^32 wrap (androidx/media#3407) or collapse hasPendingData() into a 20 s buffering stall after in-buffer forward seeks.
Closes#942
The player now installs a custom audio output provider. For eligible passthrough outputs, the provider filters playback-head positions and timestamps and reports current audio capabilities. Tests cover filtering, capability changes, and seek playback.
Changes: Direct passthrough playback
Layer / File(s)
Summary
Output provider and capability handling android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/PassthroughSuppressionRegistry.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProviderCapabilityTest.kt
The provider delegates PCM, offload, and virtual-device outputs to Media3. For other eligible outputs, it creates direct passthrough outputs and tracks capability changes after route changes or recoverable write errors. The sink can return the provider’s capabilities. Tests cover routing, fallback, restoration, and offload behavior.
Playback position and timestamp filtering android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughHeadPositionFilterTest.kt
The direct track filters playback-head positions and timestamps. Unit tests cover counter anomalies, resets, rebounds, wraps, pause and resume, and output eligibility.
Player integration and seek validation android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/audio/SiloPlayerFactoryDirectPassthroughTest.kt
The player configures the provider on its audio sink. Robolectric tests use programmable track positions to test passthrough playback, pending data across simulated seeks, and capability reporting.
sequenceDiagram
participant SiloPlayerFactory
participant DefaultAudioSink
participant DirectPassthroughAudioOutputProvider
participant DirectPassthroughAudioTrack
SiloPlayerFactory->>DefaultAudioSink: configures the output provider
DefaultAudioSink->>DirectPassthroughAudioOutputProvider: requests an audio output
DirectPassthroughAudioOutputProvider->>DirectPassthroughAudioTrack: creates a track for an eligible output
DirectPassthroughAudioTrack->>DirectPassthroughAudioTrack: filters playback-head positions and timestamps
Loading
Suggested labels:bug, impact: playback
Suggested reviewers:rxwatcher, rhainland
Merge Risk: Low · up to 56fed
The change targets Android TV passthrough seek stalls and looks mergeable. Two minor edge cases in position filtering (a delayed rebound and a wrap) remain open and should be tracked by the owner.
Security architecture risk: Moderate · up to 56fed
The new provider addresses Android TV seek stalls, but two failure-containment gaps remain. A local passthrough error can disable encoded playback for another output on the same player, and a delayed playback-counter rebound can still make queued audio appear to have played.
Retained concerns
Minor · reliability · observed: A recoverable write error on a wrapped local direct track sets a provider-wide fallback flag. While it remains set, the provider reports non-PCM formats as unsupported and can reject non-offload encoded configuration for a virtual-device output, even though the PR intends to delegate virtual-device tracks unchanged. PCM remains available and eligible offload configuration is exempt, but neither exception contains the failure to the output that raised it.
Minor · reliability · inferred: The filter handles fast staged rebounds, but can still mistake a slower rebound for progress in a new counter epoch. At 48 kHz, for the sequence 4,800 → 0 → 240 → 5,040, a final poll 80 ms of active play after the 240 reading fits the normal-progress threshold. The filter discards the old anchor and reports 9,840 frames. This offset is new relative to the merge base and can make Media3 treat queued audio as played prematurely, undermining the seek recovery the filter is intended to protect.
inferred — The established failure scope is the affected player. Counter state is private to one track; fallback state is shared by outputs using that player’s provider, not by other player instances.
Trust Boundaries and Controls
observed — Media format information enters the existing format-selection path. The sink still suppresses passthrough for suppressed or force-decode formats before delegating, while the new provider’s recovery state is driven by local audio-output callbacks.
Dependencies
inferred — Restoration depends on Media3 notifications. The mirror clears fallback on a non-default capability callback, and the delegate listener clears it on any format-support notification. The reviewed source does not establish whether normal route or format queries can trigger those notifications during fallback, or whether Media3 guarantees that callbacks from retired tracks stop before replacement or provider release.
Resilience and Maintainability Implications
observed — During recovery, Media3 can still select PCM, and eligible offload configuration remains permitted. The provider can restore encoded support on capability notification, but until then a local direct-track failure can also deny an encoded virtual-device request.
inferred — A replacement track starts with independent filter state, and an effective flush resets that state. Within a single track, however, a delayed rebound can be mistaken for genuine post-reset progress, so the filtered head is not a guarantee that all credited frames have played.
Rollout and rollback
observed — The factory installs the provider without a separate enablement gate. At runtime the provider can disable encoded output after a write error and re-enable it on capability notifications. The inspected wiring adds no operator migration or independent rollback switch for this behavior.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a fix that prevents direct passthrough seek stalls on Android TV. The changeset adds a direct passthrough audio output provider and head-position filter, which address…
Description check
The description states the problem (in-buffer forward seeks stalling on Android TV with direct HDMI passthrough), the approach (a new DirectPassthroughAudioOutputProvider wired into SiloPlayerFactory,…
Linked Issues check
Directly linked issue #942 requires that in-buffer forward seeks with E-AC3 passthrough on an NVIDIA Shield TV Pro do not stall. The reviewed head adds DirectPassthroughAudioOutputProvider, wired thro…
Out of Scope Changes check
All described changes connect to the #942 fix or are required to keep the fix working. The changed areas are: the new provider and head-position filter (core fix); SiloPlayerFactory wiring (required t…
Full details: Title check
Explanation
The title names the main change: a fix that prevents direct passthrough seek stalls on Android TV. The changeset adds a direct passthrough audio output provider and head-position filter, which address stale playback-head readings during in-buffer seeks on Android TV. The title is specific and concise.
Full details: Description check
Explanation
The description states the problem (in-buffer forward seeks stalling on Android TV with direct HDMI passthrough), the approach (a new DirectPassthroughAudioOutputProvider wired into SiloPlayerFactory, with head-position and timestamp filtering), validation on hardware, risks, and follow-ups. All of this matches the changeset.
Full details: Linked Issues check
Explanation
Directly linked issue #942 requires that in-buffer forward seeks with E-AC3 passthrough on an NVIDIA Shield TV Pro do not stall. The reviewed head adds DirectPassthroughAudioOutputProvider, wired through DefaultAudioSink.Builder in SiloPlayerFactory. Local-device, non-PCM, non-offload direct passthrough tracks are wrapped in DirectPassthroughAudioTrack. The track forwards play(), pause(), stop(), flush(), getPlaybackHeadPosition(), and getTimestamp() to DirectPassthroughHeadPositionFilter. This filter absorbs stale inherited head counters, holds retrograde drops, and withholds ambiguous timestamps. This targets the stale AudioTrack head mechanism that the PR identifies as the stall cause. Unit tests (DirectPassthroughHeadPositionFilterTest) and Robolectric tests (SiloPlayerFactoryDirectPassthroughTest, DirectPassthroughAudioOutputProviderCapabilityTest) cover these paths. The PR reports live Shield TV Pro runs with 6/6 DTS-HD MA, 3/3 E-AC3, and 3/3 TrueHD in-buffer seeks settling without buffering stalls. Residual uncertainty: the live runs used Android 11 on the Shield, while the issue reports Android 9 (firmware 8.2.3). The live validation ran on e9bee2f, and the later commits (79be4c4, 56fed85) changed fallback and rebound logic. The whole-PR diff could not be read in this review (changed blobs unavailable), so those later edits were not verified line by line. The base seek path described at head still contains the filter. No unmet coding requirement is shown. Non-coding items in the issue (diagnostic reference, reproduction narrative) do not apply.
Full details: Out of Scope Changes check
Explanation
All described changes connect to the #942 fix or are required to keep the fix working. The changed areas are: the new provider and head-position filter (core fix); SiloPlayerFactory wiring (required to install the provider); PassthroughSuppressingAudioSink capability getter (DefaultAudioSink reads capabilities only from its own provider, so without this IAMF tracks would decode to stereo once the provider is installed); routed-device forwarding and mirror AudioCapabilitiesReceiver plus write-error PCM fallback (needed so the wrapper does not regress capability handling that stock Media3 provides); and unit and Robolectric tests for these paths. PCM, offload, and virtual-device tracks delegate to the stock AudioTrackAudioOutputProvider (shouldWrap in the provider companion). The breadth to all local direct passthrough codecs, not only E-AC3, is an intended design choice stated in the PR and shares the same stale-head root cause. The PR states that no UI, layout, build, dependency, or documentation changes were made, and the summaries list no such files. The Media3 upgrade was rejected and is rationale only. The whole-PR diff could not be read in this review, so this conclusion relies on the code read at head and the PR file summaries.
Finishing Touches
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 shared passthrough fix changes playback seek timing, and the PR reports live validation on Android TV. Because this code is in android-shared, the evidence page should also show a recording of an in-buffer passthrough seek on an Android phone, tablet, and foldable both folded and open; the PR gives no reason to omit these phone-app devices.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.
I checked the provider against the Media3 1.11.0 bytecode for AudioTrackAudioOutputProvider, its private CapabilityChangeListener, and AudioCapabilitiesReceiver. The track subclass is the right place to hook: the provider class is final, and setAudioTrackBuilderModifier can't swap in a subclass. I found two things, both low severity. Neither blocks the #942 fix.
Checked the diff and Media3 1.11.0 contracts (AudioTrackAudioOutputProvider, AudioTrackAudioOutput, AudioTrackPositionTracker, AudioTimestampPoller, AudioCapabilitiesReceiver, DefaultAudioSink). The core head-position and timestamp filter math, API <= 29 zero pass-through, 32-bit wrap handling, AudioOutputProvider delegation for PCM/offload/virtualDeviceId, and tunneling attributes match Media3 1.11.0. Two medium issues remain in DirectPassthroughAudioOutputProvider's CapabilityChangeListener wiring (annotated inline).
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments
1
The filter prevents double-counting when a transient drop rebounds directly to the old counter, but commits to a new epoch on the first plausible increase below that counter. If the old counter then returns, it is treated as further progress rather than a recovery. At 48 kHz, a staged rebound from 4,800 through 0 and 240 to 5,040 can be reported as 9,840 frames. The stock provider did not add this synthetic offset. The new offset can cause Media3 to conclude that no audio remains queued before playback has caught up. Keep the epoch decision reversible while a rebound is still plausible, and cover the staged rebound separately from a genuine reset.
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: cd7f0fee-dced-474f-94c9-ed5e41c64a53
Commits
Reviewing files that changed from the base of the PR and between b15d2be and da2ddd8.
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.
…e-error recovery
Addresses review findings on DirectPassthroughAudioOutputProvider:
- Forward routed AudioDeviceInfo from wrapped tracks into delegate's AudioCapabilitiesReceiver via FormatConfig.preferredDevice (including first route).
- Keep non-wrapped outputs on the live delegate and maintain one persistent mirror AudioCapabilitiesReceiver so transient ERROR_DEAD_OBJECT fallback restores passthrough when HDMI capabilities refresh with unchanged pre-error codecs.
- Remove the redundant dedicated 32-bit wrap branch in favor of the generic retrograde hold-then-advance path.
- Cap initial head absorption below Media3's 250 ms passthrough buffer and reconcile staged rebounds without double-counting frames.
The new route-change and write-error recovery handling in DirectPassthroughAudioOutputProvider.kt changes which audio modes remain available during playback, but the linked evidence is described as in-buffer seek validation on Android TV. Please add a recording of route-change and recovery behavior for the Android phone, tablet, foldable folded and open, and Android TV, or explain why the code cannot reach any omitted device.
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.
Delayed first polls discard legitimate playback progress
Revises an earlier Kody suggestion on android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt:350 (2026-12-03 23:08 UTC).
Discarding legitimate frames shifts the playback clock backward and can delay end-of-stream detection. Change maxInitialCap to distinguish elapsed playback from an inherited counter rather than applying an unconditional cap.
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, lines 460-464:
**Revises an earlier Kody suggestion** on `android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt:350` (2026-12-03 23:08 UTC).
Delayed first polls discard legitimate playback progress
A genuine first head reading above 200 ms is treated as entirely stale even when the first poll is delayed and the new track has already played that audio. This permanently shifts the playback clock backward by the discarded frames and can delay end-of-stream detection; distinguish legitimate elapsed playback from an inherited counter instead of applying an unconditional cap.
The reason will be displayed to describe this comment to others. Learn more.
Keeping the 200 ms maxInitialCap as designed (🤖 T3 Code / Antigravity, gemini-4-neon).
The cap stays strictly below Media3's 250 ms minimum passthrough buffer so a stale counter inherited across a rapid double-seek cannot exceed writtenFrames and collapse hasPendingData(). In ExoPlayer's playback loop getPlaybackHeadPosition() is polled on every tick right after play() (live Shield hardware runs showed maxInitial of 4,831–5,097 frames = 0.6–6.2 ms of active play time at first poll, versus 360k–1.05M frames for inherited counters), and compressed AudioTrack.write only sees encoded bitstream bytes rather than decoded frame counts. Leaving open for maintainer decision.
The reason will be displayed to describe this comment to others. Learn more.
Keeping the 200 ms cap is a reasonable tradeoff for the observed seek-stall failure, and the Shield measurements support it for the tested playback path.
The original concern remains valid as an edge case: if the first head-position poll occurs after more than 200 ms of legitimate playback, the filter can treat that progress as stale and permanently underreport the position. The reported polling behavior makes that appear unlikely, but it does not establish a hard timing guarantee.
I’d leave the cap in place and the comment open for the maintainer, with the delayed-first-poll limitation explicitly acknowledged.
The reason will be displayed to describe this comment to others. Learn more.
Genuine playback-head wraps permanently lose the first wrap interval
Losing the wrap interval leaves playback position and pending-audio accounting behind for the rest of the track. Preserve the plausible wrap delta instead of treating raw as a reset.
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, lines 486-489:
Genuine playback-head wraps permanently lose the first wrap interval
A genuine 32-bit head wrap now enters the reset path, which holds the old head and never counts the frames between that head and the first post-wrap reading. The added test demonstrates a 4,800-frame loss at 48 kHz, leaving playback position and pending-audio accounting 100 ms behind for the remainder of the track; preserve the plausible wrap delta when detecting a genuine wrap.
The reason will be displayed to describe this comment to others. Learn more.
Intentionally keeping the simplified generic retrograde path (🤖 T3 Code / Antigravity, gemini-4-neon).
A genuine 32-bit unsigned head wrap requires 24.85 hours of continuous un-seeked playback on one direct passthrough AudioTrack at 48 kHz (6.21 hours at 192 kHz). Under Media3's 5–30 ms poll interval, re-anchoring through the generic path drops only a single 5–30 ms poll delta without wrapping or stalling (the unit test uses a synthetic 100 ms step), and the dedicated wrap state machine was removed to keep the filter minimal (review O2). Leaving open for maintainer decision.
The reason will be displayed to describe this comment to others. Learn more.
Understood. The wrap-related position loss is a known tradeoff: the simplified retrograde path avoids additional state-machine complexity but may lose an interval at a genuine wrap. The 5–30 ms estimate depends on normal polling; longer gaps could increase the loss.
Leaving the suggestion open for a maintainer decision is reasonable. No changes were made.
The reason will be displayed to describe this comment to others. Learn more.
64-bit hardware timestamps are rejected after the playback head wraps
Adding epochOffsetFrames to a 64-bit rawFramePosition double-counts the wrap, causing Media3 to reject valid timestamps for the rest of playback. Normalize 64-bit and wrapped 32-bit timestamps separately before applying the epoch adjustment.
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, lines 500-502:
64-bit hardware timestamps are rejected after the playback head wraps
After a head wrap, `epochOffsetFrames` already contains approximately `2^32`, so adding it to a hardware timestamp that is itself 64-bit double-counts the wrap and fails the skew check. The track then rejects all such timestamps for the remainder of long playback, forcing Media3 away from timestamp-based position tracking; normalize 64-bit and wrapped 32-bit timestamps separately before applying the epoch adjustment.
The reason will be displayed to describe this comment to others. Learn more.
Intentionally keeping the simplified timestamp fallback past 2^32 frames (🤖 T3 Code / Antigravity, gemini-4-neon).
Same 24.85-hour (48 kHz) / 6.21-hour (192 kHz) continuous single-track threshold: if a 64-bit hardware timestamp disagrees after a 32-bit head wrap, filterTimestamp() rejects it cleanly and Media3 continues tracking position from the monotonic filtered getPlaybackHeadPosition() without stalling or wrapping. Leaving open for maintainer decision.
The reason will be displayed to describe this comment to others. Learn more.
Understood. The 64-bit timestamp issue remains a known trade-off for maintainer review, with no change requested.
The threshold is approximately 24.86 hours at 48 kHz or 6.21 hours at 192 kHz on a continuous track. If the skew check rejects timestamps after the head wraps, Media3 is expected to fall back to the filtered playback head. That fallback avoids the timestamp mismatch, though confirming stall-free behavior at the wrap threshold would require a targeted test.
Round 1 items: O1 (routed device not forwarded, no capability tests) is resolved. onRoutedDeviceChanged now reaches the delegate's receiver through FormatConfig.preferredDevice, which matches what Media3's internal CapabilityChangeListener does, and DirectPassthroughAudioOutputProviderCapabilityTest covers both the route and the recovery path. O2 (duplicate wrap branch) is resolved; the wrap state and the timestamp wrap special case are gone, and a 32-bit wrap now goes through the generic retrograde/new-epoch path.
The mirror receiver works and has a clear reason to exist: our wrapped tracks can't reach the delegate's private onRecoverableWriteError, which would otherwise do the same overrideCapabilities(DEFAULT_AUDIO_CAPABILITIES). The staged-rebound reconciliation and the 200 ms initial cap look correct to me. Two inline notes: one Low behavioral regression and one simplification.
…en staged rebound
Addresses Round 2 review findings on DirectPassthroughAudioOutputProvider:
- Preserve delegate's audio offload support flags and allow offload output configuration while direct passthrough is temporarily disabled after a recoverable write error, matching Media3's AudioTrackAudioOutputProvider.
- Simplify getOutputConfig's fallback receiver refresh to call delegate.getFormatSupport(formatConfig) directly.
- Tighten staged-rebound jump threshold to 20 ms so delayed polls (e.g. 60 ms) still reconcile without double-counting, and withhold hardware timestamps until the selected epoch is confirmed past the rebound window.
The seek-stall fix is visible on Android TV and can also reach the Android phone, tablet, and foldable (folded and open): SiloPlayerFactory is shared, and DirectPassthroughAudioOutputProvider.shouldWrap() filters by output encoding/offload/device ID, not app form factor. The stated reason for omitting mobile captures (that they use PCM) does not rule out a compatible local HDMI passthrough route. Please add seek recordings for those mobile form factors using such a route, or identify a code/device constraint that excludes them. The evidence page should also show the route-change and write-error fallback/recovery behavior on each reachable surface. No diff needed; add the recordings to the linked evidence page.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.
The head counter wraps at 2^32, which is about 24.9 hours at 48 kHz. When the head moves from 0xFFFF_F000 to 704, the filter treats 704 as the origin of a new epoch. The 4,800 frames between the two readings are lost. At 48 kHz, that is 100 ms. The next reading at 1,664 adds only the 960 frames after 704. Later head reports and timestamps stay 100 ms behind for the rest of the playback epoch.
The Android AudioTimestamp reference defines the low 32 bits of framePosition in wrapping frame units. A move from 0xFFFF_F000 to 704 is a forward advance of 4,800 frames. Credit a forward advance that crosses 2^32 as its modular delta when that delta is plausible for the elapsed time. Use the same plausibility bound as other forward steps. The startup stale-counter path must not change. A -1 error return followed by small raw values must still report 0, 0, and then 240.
Update genuine32BitWrapReanchorsCleanlyAndStartupErrorCodeDoesNotWrap. The expectations at 704 and 1,664 must match the confirmation behavior you choose. After the wrap is confirmed at raw 11,264, the unsigned head must read 11,264. The timestamp must read 2^32 + 11,264, which is 4,294,978,560. The current expectations encode the 4,800-frame deficit.
2
The earlier staged-rebound issue is fixed for the tested polling intervals, but not for every plausible interval. At 48 kHz, if the final poll in 4,800 → 0 → 240 → 5,040 arrives 80 ms of active play after the 240 reading, the 4,800-frame step fits the normal-progress threshold. The filter drops the old anchor and reports 9,840. The merge base did not add this offset. Media3 can therefore treat queued audio as played prematurely despite the filter's intent to contain counter glitches.
A recoverable write error on a wrapped local direct track sets fallback for the entire provider, not just the failing route. While fallback remains set, the provider reports non-PCM formats as unsupported and blocks non-offload encoded configurations before checking whether the output would be wrapped. A virtual-device request can therefore be blocked even though its track would be delegated unchanged. PCM remains available and eligible offload configuration is exempt; neither exception confines the fallback to the output that failed.
456-459: Major · Functional Correctness · Heavy lift
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Do not discard valid progress on a late first poll.
At 48 kHz, a track can have presented 14,400 frames when the first poll runs 400 ms after play(). The 9,600-frame cap treats those frames as inherited and stores an offset of −14,400. Later valid head positions and timestamps stay 300 ms behind. The merge-base Media3 path accepted that first positive head. (raw.githubusercontent.com)
Use independent evidence, such as frames submitted to this track, to distinguish valid progress from an inherited counter. Keep the stale-counter check for a new track that has not received enough frames to account for the reading.
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: 07335d47-784f-451a-adcd-aee24ff30bb0
Commits
Reviewing files that changed from the base of the PR and between da2ddd8 and 79be4c4.
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 reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Heavy lift
A staged rebound can report 9,840 when the final poll is about 80 ms late.
For 4,800 → 0 → 240 → 5,040, a final poll delay of 100 ms makes the 4,800-frame step pass the normal step bound but fail the staged check. The filter then reports 9,840 instead of 5,040. It also sets epochOffsetFrames to 4,800, so later timestamps keep the extra 4,800 frames. The staged-rebound test states that 9,840 is the double-count result to avoid. The test covers only 5 ms and 60 ms final delays, and the 60 ms case still reconciles to 5,040.
Keep 5,040 for this sequence at longer final delays too, or state the timing rule that separates a real advance from a rebound. Add a test for a delay that takes this path. Do not count the same 4,800-frame progress twice.
The reason will be displayed to describe this comment to others. Learn more.
Keeping the 20 ms step-excess threshold as the boundary between a real HAL reset and a staged rebound (🤖 T3 Code / Antigravity, gemini-4-neon).
At 48 kHz, a real HAL reset at t = 105 ms (0) that plays 5 ms (240 at t = 110 ms) and then plays 100 ms (5,040 at t = 210 ms) advances at an exact 48,000 frames/s—producing the exact same (time, raw) sequence as a frozen pre-drop counter rebounding 100 ms late. By contrast, a pre-drop counter that continues ticking at real time during a 100 ms gap rebounds to ~10,080 (delta = 9,840 vs 5,784 threshold), which still reconciles onto the pre-drop timeline without double-counting. Leaving open for maintainer decision.
@Quick104 You’re right: those readings cannot distinguish a real reset from a frozen-counter rebound. My original recommendation should not require 5,040 unconditionally.
For the 100 ms case, the current threshold favors the reset and reports 9,840. If the same readings represent a rebound, that result can overcount by 4,800 frames.
I’m not marking the finding as addressed. I’ll leave the trade-off to a maintainer.
Learnings added
Learnt from: Quick104
Repo: Silo-Server/silo-android PR: 1132
File: android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt:574-577
Timestamp: 2026-12-04T00:21:51.062Z
Learning: Within repository "Silo-Server/silo-android", only for files matching one of ["android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt"]: In DirectPassthroughHeadPositionFilter in android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/audio/DirectPassthroughAudioOutputProvider.kt, do not assume that a 48 kHz sequence of 4,800 → 0 → 240 → 5,040 with 5 ms and then 100 ms between the last readings necessarily represents a staged rebound. The same timed readings can represent normal progress after a real HAL reset. The 20 ms step-excess boundary favors the reset for a plausible forward step; that preserves real reset progress but can double-count a frozen-counter rebound. The trade-off is left for a maintainer decision.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
Update: I'm withdrawing this redirect. I built the release gate it describes and ran it on an NVIDIA Shield (Android 11) with the same in-buffer DTS-HD MA seeks, against a build of main.
The gate worked as designed. Each seek waited 55 to 64 ms for the old track to be released before opening the new one, and the false 2^32 wrap went away. But whenever Android reused the same direct output, the new track's first position still came back 5 to 6 seconds ahead, carried over from the old track, and playback stalled in buffering as it does on main (4 of 9 seeks on each build). This device's HDMI HAL doesn't reset its render position when the old track is flushed and released, so sequencing the rebuild can't fix the stall on its own, and the branch's absorption of a stale first head reading is needed. Nothing was pushed to this branch.
Original redirect (withdrawn)
This PR fixes a real stall, but sequencing the track rebuild would fix it more simply: have the provider refuse to build a new direct passthrough AudioTrack while the previous one is still releasing, and let Media3 retry. This branch instead filters the playback head with a timing heuristic, and because it builds AudioTrackAudioOutput itself, it also has to re-implement Media3's routed-device, capability, and write-error handling. I recommend reworking it that way, so I haven't reviewed the code line by line. Reviewed head: 79be4c4.
Why. For a direct compressed track, Android reports getPlaybackHeadPosition() from the HAL render position of the output stream (AudioTrack::getPosition calls AudioSystem::getRenderPosition), which every track on that output shares. A direct flush resets it (DirectOutputThread::flushHw_l). Media3 1.11 builds the replacement track as soon as DefaultAudioSink.flush() returns, but flushes and releases the old track 20 ms later on a background thread (AudioTrackAudioOutput.releaseAudioTrackAsync). The new track reads the old counter, then drops to 0 when that flush lands. That one ordering race produces both symptoms the filter absorbs.
The change. Wrap AudioTrackAudioOutputProvider in a ForwardingAudioOutputProvider. Count each direct passthrough output (non-PCM, non-offload, default device) from release() until its onReleased callback, and throw InitializationException from getAudioOutput while that count is above zero. Media3's PendingExceptionHolder already waits for pending releases before it retries or starts its 200 ms deadline, and onReleased arrives on the playback thread, so the count can't drop in the middle of the buffer-size retry loop. Add a time limit so a lost callback can't hold the gate shut. Every output then comes from the stock provider, so the mirror AudioCapabilitiesReceiver, the routed-device forwarding, and the PCM fallback go away, along with the two edge cases still open in the threads (a first head poll later than 200 ms, and a real 32-bit wrap). The cost is about 50 to 70 ms of extra wait on each in-buffer passthrough seek, and an audio sink error in the log for each refused build.
What needs hardware. Source can't say whether the Shield's HDMI HAL zeroes its counter after the old track's flush and release, before the new track's first head read, or whether the receiver has to re-lock the bitstream after a sequenced rebuild. A Shield run of the same DTS-HD MA, E-AC3, and TrueHD in-buffer seeks, plus rapid repeat seeks and pause and resume, should log the first raw head after each rebuild and show no Spurious audio timestamp lines. If the counter still comes back stale after the release, a much narrower head correction would sit on top of the gate.
Fit: 5/10. Fixing passthrough seek stalls on Android TV is core playback work. This version adds a second audio output path beside Media3's that duplicates handling Media3 already does, and it relies on timing thresholds rather than fixing the ordering that causes the bug.
The reason will be displayed to describe this comment to others. Learn more.
Adversarial review of 79be4c4 after the withdrawn redirect above. I ran a multi-agent code review and a three-provider council over the head, and checked each finding against Media3 1.11.0 and the Android 11 audio sources. Two findings are fixes I'm pushing to this branch (IAMF capabilities and the extra notification on write errors), one is a maintainer decision about trimming the rebound logic, and the rest are low-risk notes. A summary with scores follows once the fixes are verified.
The reason will be displayed to describe this comment to others. Learn more.
Maintainer decision: the staged-rebound and new-epoch logic covers head sequences Android doesn't produce.
For a direct compressed track, AudioTrack::getPosition reports the output's HAL render position and returns 0 when that read fails (AudioTrack.cpp:1318-1322); the only real drop comes from a direct flush (DirectOutputThread::flushHw_l), after which the old counter doesn't come back. In this branch's own Shield runs, all 15 logged retrograde drops were to exactly 0, and no forward spike, non-zero drop, or rebound was logged. The rebound state (reboundRaw, reboundReported, reboundPlayNs, newEpochStartPlayNs, STAGED_REBOUND_JUMP_MS, NEW_EPOCH_CONFIRM_*) and the timestamp withholding tied to it exist for the hypothetical 4800 -> 0 -> 240 -> 5040 case.
That code also has two arithmetic edges if such a sequence did occur: 4800 -> 0 -> 240 -> 4800 -> 5040 at 5 ms polls keeps 240 speculative frames in the offset, and a bursty counter crossing reboundRaw inside the confirm window loses the jump.
Options: (a) keep it as is; (b) replace it with "a raw 0 is held, a non-zero drop is a new epoch when plausible for the elapsed time", roughly 15 lines in place of about 110 plus their tests, then re-run the Shield matrix. This is left for the maintainers to settle.
The reason will be displayed to describe this comment to others. Learn more.
Low (not fixing): a stale first reading below the 200 ms cap is accepted as real progress.
Trigger: two committed seeks less than about 100 ms apart, so the old track played under 200 ms on the reused output. Impact: the stale count (for example 4,000 frames) becomes the baseline; once the old track's flush drops the counter to 0, the hold-then-advance path keeps those frames, and the clock stays about 80 ms ahead for the rest of the track. If fewer frames than that have been written, hasPendingData() can briefly read false. The filter can't see written frames for compressed writes, so there's no cheap exact bound. Silo commits seeks more than a second apart in practice (two key presses 300 ms apart committed 1.2 s apart on the Shield), which makes this unlikely.
The reason will be displayed to describe this comment to others. Learn more.
Low, unverified (not fixing): on Android 10 and older, passing 0 through can trip Media3's stall reset.
Trigger: API 29 or lower, a wrapped track playing, and the counter at 0 after the forced flush for longer than 200 ms. Impact: Media3's Bluetooth workaround (AudioTrackPositionTracker.java:532-546) then marks the track stalled and DefaultAudioSink rebuilds it (DefaultAudioSink.java:1084-1087), which reuses the same output and can repeat the stale-counter case. That workaround targets failed Bluetooth connections, which never carry a direct compressed track, so holding the reported head on every API level would avoid it. There's no API 29 passthrough device in our test set to confirm either way.
The reason will be displayed to describe this comment to others. Learn more.
Low (not fixing): a route change on the replacement PCM track doesn't end the write-error fallback.
Trigger: after a write error, the PCM track gets rerouted to an output whose capabilities equal the delegate's cached pre-error capabilities, with no device add or remove. Impact: the delegate suppresses the unchanged notification, and the mirror receiver never sees the route, so passthrough stays off until the next device event or player release. Forwarding route changes from delegated tracks to the mirror receiver would close it; it's a narrow case.
DefaultAudioSink only reports audio capabilities when its provider is
Media3's own AudioTrackAudioOutputProvider, so with the passthrough
provider installed it returned null and MediaCodecAudioRenderer decoded
every IAMF track to stereo. Report the provider's capabilities from
PassthroughSuppressingAudioSink instead.
Entering the PCM fallback after a recoverable write error no longer
notifies a format-support change. Stock Media3 doesn't either: ExoPlayer's
renderer-error recovery reselects tracks, and that reselection already sees
the fallback through getFormatSupport.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)
This PR fixes the stall after in-buffer passthrough seeks on Android TV. I tested a smaller alternative first: waiting for the old track's release before opening the new one. The Shield showed that isn't enough, because the HDMI HAL keeps its render counter across the flush and release. So the head filter here is the fix that works, and I reviewed the PR on that basis.
Fixed on this branch (56fed85)
IAMF tracks no longer drop to stereo. With a custom provider installed, DefaultAudioSink.getAudioCapabilities() returned null; the sink now reports the provider's capabilities.
Entering the PCM fallback after a recoverable write error no longer sends a format-support change, which matches stock Media3. ExoPlayer's own error recovery already reselects tracks.
A KDoc line overstated the timestamp check.
Both regression tests fail on 79be4c4 and pass on 56fed85.
Verified on hardware (NVIDIA Shield, Android 11, 56fed85)
DTS-HD MA: 9 of 9 in-buffer seeks settled, all on a reused direct output, including a rapid double press and a seek after pause and resume. None rebuffered after player ready, and there were no 2^32 timestamp warnings. On main, 4 of 9 rebuffered and the double press stalled for about 19 s.
E-AC3 3/3 and TrueHD 3/3 settled cleanly, 5 of 6 on a reused output.
The DTS-HD direct output stayed live in AudioFlinger.
No write error happened in these runs, so the write-error path rests on its unit test.
Left for the maintainers
Whether to trim the staged-rebound and new-epoch logic. Android's source and every Shield log point to drops always going to exactly 0, so that code covers sequences nobody has seen. It also has two arithmetic edges if such a sequence did occur. See the thread on that code.
Low risks, noted in their threads and not changed:
a stale first reading under 200 ms on seeks less than about 100 ms apart;
the zero pass-through on Android 10 and older, which no device in our set can test;
a route change during the write-error fallback.
Checks
Validated features: no passed validation case on Android TV touches this path. The phone and tablet marker-seek case (#321 C2) runs on speaker or Bluetooth, which stays on Media3's stock provider. Validation tasks: none stands.
User manual: unaffected; no setting, screen, or documented behavior changes.
Apple and Android: the Apple apps play through a different engine and don't use Media3's position tracker, so no Apple change is needed.
Council (multi-provider review)
Member
Redirect test (79be4c4)
Review (79be4c4)
Sol (gpt-6.2-sol, medium)
6/10
6/10
Opus (claude-opus-5-5, medium)
5/10
6/10
Gemini (gemini-4-neon, medium)
5/10
8/10
Fit 8: this fixes a stall in core playback on Android TV. It stretches one principle: it layers about 670 lines of workaround on Media3, including a copy of Media3's capability handling that a custom AudioTrack forces. The PR plans to remove the workaround once a stable Media3 handles both cases.
Readiness 8: verified live, and the tests fail on the base. The open maintainer decision and the untested Android 10 path keep it below 9.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments
2
A recoverable write error on a wrapped local direct track sets a provider-wide fallback flag. While it remains set, the provider reports non-PCM formats as unsupported and can reject non-offload encoded configuration for a virtual-device output, even though the PR intends to delegate virtual-device tracks unchanged. PCM remains available and eligible offload configuration is exempt, but neither exception contains the failure to the output that raised it.
The filter handles fast staged rebounds, but can still mistake a slower rebound for progress in a new counter epoch. At 48 kHz, for the sequence 4,800 → 0 → 240 → 5,040, a final poll 80 ms of active play after the 240 reading fits the normal-progress threshold. The filter discards the old anchor and reports 9,840 frames. This offset is new relative to the merge base and can make Media3 treat queued audio as played prematurely, undermining the seek recovery the filter is intended to protect.
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: 98e8ec67-d548-4c0a-a3f6-3d905ab2afe5
Commits
Reviewing files that changed from the base of the PR and between 79be4c4 and 56fed85.
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.
On CodeRabbit's two notes for 56fed85, no change for either:
The write-error fallback is provider-wide. Stock Media3 behaves the same way. Its onRecoverableWriteError sets the provider's cached capabilities to DEFAULT_AUDIO_CAPABILITIES (AudioTrackAudioOutputProvider.java:570-576 in 1.11.0), so every non-offload encoded config fails, virtual-device outputs included, until the capabilities refresh. This branch matches that, and keeps the offload exemption the stock offload path already has. It isn't something this PR introduces.
A slow staged rebound (4,800 → 0 → 240 → 5,040 with an 80 ms final poll). This is in the staged-rebound logic, which is already open as a maintainer decision in this thread. For a direct compressed track, Android reports the output's HAL render position, which reads 0 when the read fails, and a real drop comes only from a direct flush, after which the old counter doesn't come back. Every drop in the Shield runs on this branch went to exactly 0 (8 on 56fed85, 15 earlier), so the sequence hasn't been seen. Whether to keep that code or replace it with a simpler hold-on-zero rule is the open question there.
Brings in Silo main at ecd3423: server edition and version order for
playback starts (Silo-Server#1133), which hand-offs follow through Silo's TV starter,
and direct passthrough seek fixes for Silo's own player (Silo-Server#1132). Neither
touches the External Player's dependencies.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012qpc8JWornyCaGCu28gSBU
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
bugSomething isn't workingimpact: playbackCan't play, stalls, or wrong mediasize/XXL1000–2999 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
Closes #942
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (Android AudioFlinger and Media3 direct passthrough path only); Roku N/A (does not use Media3 AudioTrack); Web N/A (browser media stack)
Forward seeks that land inside the forward buffer (Auto Skip Intro, Skip Intro, or D-pad skip) can jump roughly 5 seconds ahead and stall in buffering for 20 seconds on Android TV devices using direct HDMI audio passthrough (such as DTS-HD MA and E-AC3 on NVIDIA Shield), until the startup stall detector forces a full stream reload.
When a seek lands inside already-buffered media, Media3 releases the old
AudioTrackasynchronously (20 ms later) while constructing a replacementAudioTrackon the same audio session. Android'sAudioPolicyManagercan reuse the activeDirectOutputThread, so the replacement track'sgetPlaybackHeadPosition()reads a stale counter from the previous segment or drops back to0when AudioFlinger invalidates the old track and flushes the shared output. In Media3 1.11.0,AudioTrackPositionTrackertreats any backward drop (except0on API <= 29 while playing) as a 32-bit unsigned wrap (+2^32 frames, upstreamandroidx/media#3407), and a stale counter abovewrittenFramesflipsDefaultAudioSink.hasPendingData()tofalse, leavingMediaCodecAudioRendererstuck inSTATE_BUFFERING.Approach
Add
DirectPassthroughAudioOutputProvider(implementing Media3 1.11's non-deprecatedAudioOutputProvider) and wire it intoDefaultAudioSink.BuilderinSiloPlayerFactory.virtualDeviceId != INDEX_UNSET) tracks toAudioTrackAudioOutputProviderunchanged, keeping explicitFormat.channelMaskhandling intact.AudioDeviceInfocallbacks from wrapped passthrough tracks intodelegate'sAudioCapabilitiesReceiverthroughFormatConfig.preferredDevice(including the first route) and keeps one persistent mirrorAudioCapabilitiesReceiverregistered once passthrough is supported. On recoverable write errors (ERROR_DEAD_OBJECT), direct passthrough falls back to PCM on the livedelegatewhile preserving platform audio offload support flags/configs, and restores passthrough when HDMI capabilities refresh—even with unchanged codecs.DirectPassthroughAudioTrackwhoseDirectPassthroughHeadPositionFilter:play(),pause(), andstop()so paused or rebuffering wall time does not inflate forward-jump bounds;min(activePlay + 100 ms, 200 ms)(always below Media3's 250 ms minimum passthrough buffer) and implausible forward spikes aboveactiveDelta + 200 msas baseline shifts instead of advancing pastwrittenFrames;4800 -> 0 -> 240 -> 5040, including delayed polls) without double-counting—or a new counter epoch advances monotonically;AudioTimestamp.framePositionby the same epoch offset, enforces strict monotonicity so Media3'sAudioTimestampWrappercannot permanently wrap by +2^32, and withholds timestamps across pending resets, ambiguous rebound windows (until the selected epoch confirms), or skew;AudioTrack.flush()actually flushes an initialized non-playing track, and logs bounded anomalies viaSiloLog.woutside the filter lock.PassthroughSuppressingAudioSink.getAudioCapabilities().DefaultAudioSinkonly reads them from Media3's own provider, and without them IAMF tracks decode to stereo.Upgrading to Media3
1.12.0-rc01was rejected because1.12is still a release candidate, requires rebuilding the bundled FFmpeg decoder AARs and verification metadata, and upstream4c95cd96b53only guards backward wraps without absorbing an inherited stale counter abovewrittenFrames.Validation
56fed85(NVIDIA Shield, Android 11): 9/9 DTS-HD MA in-buffer seeks settled with no rebuffer and no 2^32 timestamp warnings, all on a reused direct output, including a rapid double press and a seek after pause and resume; E-AC3 3/3 and TrueHD 3/3 clean. On main, 4 of 9 DTS-HD MA seeks rebuffered and the double press stalled for about 19 s. Waiting for the old track's release before opening the new one (tested as an alternative, not merged) still left a 5-6 s stale first reading on reused outputs, so the head filter is needed.fails-on-baseagainst79be4c4: the two review regression tests (sink reports audio capabilities; no format-support notification on entering the write-error fallback) fail and pass on56fed85.b15d2be293), the first in-buffer DTS-HD MA seek jumped +5.05 s, logged a2^32spurious audio timestamp mismatch, and stalled 20.0 s inSTATE_BUFFERINGuntil reload. One9bee2fa2, 6/6 consecutive in-buffer DTS-HD MA seeks absorbed stale inherited heads (409k–424kframes) and held retrograde drops to0, reachingplayer readyin 93–160 ms with zero buffering stalls and continuousAudioFlingerdirect output writes (Total writes: 58 -> 68,Frames written: 7,602,176 -> 8,912,896over 3 s, signal power-11.7 to -13.5 dB); 3/3 E-AC3 (125–281 ms) and 3/3 Dolby TrueHD (114–276 ms) in-buffer seeks also settled cleanly.ENCODING_DTS_HD,ENCODING_DOLBY_TRUEHD,ENCODING_E_AC3) requires an HDMI AVR / Android TV sink; linear PCM output on phones, tablets, and foldables bypasses the wrapper (!DirectPassthroughAudioOutputProvider.shouldWrap(outputConfig)) and goes straight to Media3'sAudioTrackAudioOutputProvider.fails-on-baseagainstb15d2be293: all 3SiloPlayerFactoryDirectPassthroughTestcases compiled onmain, failed for the stale-head jump and+2^32wraphasPendingData()collapse, and passed with the fix.fails-on-baseagainstda2ddd855: all 4 Round 2 regression cases compiled onda2ddd855, failed for the exact Round 1 review findings, and passed one9bee2fa2.fails-on-baseagainste9bee2fa2: both regression cases (transientZeroGlitchDirectAndStagedReboundsDoNotDoubleCountFrameswith 60 ms delayed poll + old-epoch timestamp check, andrecoverableWriteErrorPreservesAudioOffloadSupportAndConfig) compiled one9bee2fa2, failed for the exact Round 2 council findings (S3,S4,S5/O3), and passed on79be4c4b0../gradlew testDebugUnitTest), debug lint (:android-shared:lintDebug,:androidApp:lintDebug,:androidTvApp:lintDebug), and debug builds (:androidApp:assembleDebug,:androidTvApp:assembleDebug) passed on79be4c4b0with zero new warnings; release vital lint and TV release APK build passed one9bee2fa2and run in GitHub CI (Release readiness) on79be4c4b0../scripts/check-build-supply-chain.sh) could not run locally becauserubyis absent on this Linux builder; no build, workflow, or dependency files changed, and GitHub CI runs them on this PR.Evidence: https://evidence.siloserver.org/r/silo-android/issue-942/
Risks
isOffload = true) and API 34+ non-default virtual-device tracks (virtualDeviceId != C.INDEX_UNSET) delegate to stockAudioTrackAudioOutputProviderbecause those options requireAudioTrack.Builderrather than anAudioTracksubclass. Local phone and TV video passthrough does not use either path.Follow-ups
siloserver.orgdocs and milestone specs (src/content/docs/,src/data/,public/milestone/1.0/index.html); this change fixes an internal playback seek stall without altering settings, UI, or documented behavior.DirectPassthroughAudioOutputProvideronce Silo upgrades to a stable Media3 release that addresses both backward wraps (androidx/media#3407) and stale inherited direct-output counters.Council review
Rounds: 4, last reviewed
79be4c4b0(review findings addressed in56fed85)da2ddd855)e9bee2fa2)79be4c4b0)79be4c4b0)Visual review: skipped — no user-visible UI layout or styling changed.
Fixed: Round 1 (
e9bee2fa2):S1/O1/G1routed-device forwarding viaFormatConfig.preferredDevice,S2/G2/CodexP2live-delegate PCM + persistent mirrorAudioCapabilitiesReceiverrecovery on unchanged HDMI capabilities,O2removal of redundant 32-bit wrap branch, and Kody/CodeRabbitmaxInitialcap + staged-rebound reconciliation. Round 2 (79be4c4b0):S320 ms staged-rebound threshold for delayed polls,S4withholding hardware timestamps across the ambiguous rebound window until the epoch confirms,S5/O3preserving audio offload support flags and offload output configs during direct write-error fallback, andO4simplifyinggetOutputConfig's fallback refresh.Review (
56fed85): IAMF capabilities reported through the sink (Sol S4, Gemini G1), no notification on entering the write-error fallback (Gemini G2), KDoc wording. Open for maintainers: trimming the staged-rebound and new-epoch logic (Opus O1), and low risks noted in their threads (sub-200 ms stale first reading, API <= 29 zero pass-through, route change during fallback).Answered: Kody's three follow-up nits on
e9bee2fa2(reversing itsmaxInitialcap and 24.85-hour/6.21-hour single-track 32-bit wrap edge cases) were answered in-thread with evidence and left open for maintainer review.AI Disclosure
Note
Fix direct passthrough seek stalls on Android TV with filtered audio head positions
DirectPassthroughAudioOutputProviderin DirectPassthroughAudioOutputProvider.kt, which wraps non-linear-PCM, non-offload direct passthrough outputs in aDirectPassthroughAudioTrackthat filters playback-head positions and timestamps.DirectPassthroughHeadPositionFiltercaps implausible initial head positions (200 ms), absorbs impossible forward jumps, holds retrograde drops, and reconciles counter resets without adding the reset value to prior positions. Timestamps are shifted into the reported frame epoch or withheld when ambiguous, with a 2,000 ms skew limit.SiloPlayerFactorynow builds the audio sink through the new provider, andPassthroughSuppressingAudioSinkcan report capabilities from a supplied getter.DirectPassthroughAudioOutputProvidercompanion and the tunneled audio attributes, since filtered head positions change what Media3 sees on affected TVs.Macroscope summarized 56fed85.