Repository navigation
Description
What happened?
Control test that isolates it to the bridge: the same episode from a different file with AAC audio (stream-copy, no bridge) starts at the same resume position flawlessly. The mp3 file also plays fine when started from 0. Only bridged audio + non-zero startPosition fails, reproducibly.
Failure mode A — anchored initial load: healthy producer, AVPlayer never ready
load(startPosition: 893.3) → producer anchors at seg207, segments are produced and served continuously and quickly (46+ segments, 0.4–0.9 s each). AVPlayer keeps fetching sequentially forever but:
[NativeAVPlayerHost] #1 timeControlStatus=waitingToPlay reason=AVPlayerWaitingToMinimizeStallsReason t+2.27s
[LagDiag] clk=891.16 dclk=0.00 tcs=waiting rate=1.00 wait=AVPlayerWaitingToMinimizeStallsReason fwd=- keepUp=n empty=n drop=0+0 stall=0 ready=n ... restarts=1
fwd=- = loadedTimeRanges stays EMPTY through hundreds of MB of served segments — CoreMedia downloads and silently discards everything, clock pinned at the anchor, black screen forever.
None of the #93 recovery paths arm: no -15628 errorLog is ever posted, playbackStalled never fires (playback never started), and the consumer's fetches never freeze (it fetches happily), so the backpressure re-anchor grace never trips either. The VOD initial load has no never-ready watchdog by design ("nil for initial loads, VOD"). Net result: permanent black with zero recovery.
Failure mode B — a seek during A kills the producer pump permanently
A user seek during the wedge triggers the 8 s reconcile + re-anchor, and the restarted producer's muxer dies on the bridged audio track:
[AetherEngine] #65 seek did not land within 8.0s and AVPlayer is starved (rendered=0.00s buffered=0.00s); reconciled clock to rendered position and re-anchored producer (recovery still aims at 0.00s)
[HLSSegmentProducer] init OK (baseIndex=0, segments=314, ...) audio=bridge inTb=1/48000
[HLSVideoEngine] producer restarted at idx=0 (seek=0.00s [absolute source-PTS], restart took 1ms)
[HLSSegmentProducer] video gate open: actual=0 anchorPts=0 target=-9223372036854775808 desired=0 shift=0
...
[mp4 @ 0x...] [error] Cannot write moov atom before EAC3 packets parsed. (repeated 8×)
[HLSSegmentProducer] seg-0.m4s cut FAILED; muxer is wedged, ending pump
[HLSSegmentProducer] pump finished: reason=muxerFailed packetsRead=338 packetsWritten=120 lastError=0 elapsed=49ms cacheCount=65
After that, restarts drops to 0 and nothing ever escalates — muxerFailed recovery only exists on the live reopen path, so a VOD session sits starved forever (empty=y, net=0.0). Note video gate open: target=-9223372036854775808 (AV_NOPTS) on this restart.
This is the same mp4-muxer error the stream-copy path pre-flights for (the HLSVideoEngine+AudioRoute comment about EAC3-from-MKV / "-22 Cannot write moov atom before EAC3 packets parsed") — but here the EAC3 comes from the bridge encoder itself, and the bridge path has no equivalent pre-flight/rebuild, and muxerFailed on VOD has no escalation.
Steps to reproduce
Steps to reproduce
- Pick an MKV whose audio requires the bridge — mp3 in my case
([Demuxer] stream[1] type=audio codec=mp3, load logs
audio: codec=mp3 (bridge required)/AudioBridge init: mode=surroundCompat).
Serve it over a remote HTTP source (mine is a WAN file host, ~100 Mb/s,
plain GET + Range). load(url:startPosition:)with a non-zero start position well into the
file (I used ~690 s and ~893 s of a 1340 s file, i.e. the resume-playback
flow), thenplay().- Failure mode A (100% for me on this file, at least 3 different positions
across sessions): the producer anchors at the right segment and serves
segments continuously and quickly, but AVPlayer stays
waitingToPlay/AVPlayerWaitingToMinimizeStallsReasonforever —
loadedTimeRangesnever gets a single range (fwd=-in LagDiag), the clock
stays pinned at the anchor, screen stays black. No-15628, no
playbackStalled, fetches never freeze → none of the recovery paths arm. - While stuck in A, call
seek(to:)(any target; the UI seek a user naturally
tries). After the 8 s no-land reconcile the producer re-anchors and —
failure mode B, intermittent but frequent — the restarted muxer dies:
Cannot write moov atom before EAC3 packets parsed→
seg-0.m4s cut FAILED; muxer is wedged, ending pump→
pump finished: reason=muxerFailed. From then on the session is permanently
starved; further seeks do nothing (no VOD escalation formuxerFailed).
Control tests (same episode, same host, same player code):
- same file,
startPosition: nil(start from 0) → plays fine; - different file of the same episode with AAC audio (stream-copy,
no bridge), same non-zerostartPosition→ plays fine.
AetherEngine version or commit SHA
Host app
Custom / my own integration
Platform
tvOS
OS version
tvOS 26.5
Device / chip
Apple TV 4K 3rd
Playback path
Native AVPlayer
Source media (for playback bugs)
MKV over WAN (HTTP), h264 [email protected] 1440×1080 25fps + 2× MP3 audio + subrip. Audio routes through AudioBridge (.surroundCompat, mp3 → EAC3), master playlist advertises avc1.640028,ec-3.
Error codes / log lines
Anything else
No response
Activity
fix(audio): bridged resume alignment and post-EOF bridge revive (#99)
superuser404notfound commentedon Jul 3, 2026
Fixed on main as of 257b5ee. Your isolation made this one fast to pin down; the two control tests (same position with AAC stream-copy fine, same file from 0 fine) pointed at exactly the right seam. Both failure modes are reproduced and root-caused, and B turned out to be a consequence of A plus one more latent defect.
Failure mode A: never-armed bridge timeline on an anchored initial load
Since 2ba710d (the #93 residual work, shipped 2026-07-02),
load(startPosition:)anchors the FIRST producer at the resume segment instead of starting at seg0 and restarting. The producer side of that path is correct, which is why your logs look healthy: the demuxer seeks, the video gate opens at the anchor, the audio gate follows, segments cut and serve.The hole was in
AudioBridge: its output PTS counter (nextEncoderPTS) only re-bases onto the source timeline whenstartSegment()arms it, and the ONLY caller ofstartSegment()wasperformRestart. An anchored initial load never restarts, so the bridge stamped its EAC3 output starting at 0 while video carried the anchor's absolute source PTS. Concretely, from a CLI repro of your setup (mp3 MKV,--start-position 60), the anchored segment before the fix contained:Every fragment held two tracks a full resume-offset apart, so CoreMedia could never build a muxed buffered range: it downloads, finds no usable window, and moves to the next segment. That is precisely your
fwd=-forever, clock pinned at the anchor, no-15628, noplaybackStalled, and no fetch freeze, so by design none of the #93 recovery arms could see it. Start-from-0 worked because 0-based happened to equal the source timeline, and AAC worked because stream-copy passes source PTS through untouched.Fix: the rebase is now armed at bridge init (not just on restarts), so bridge output tracks the gate-shifted source timeline from the first fed packet in every session. Same repro after the fix:
Failure mode B: EOF flush bricks the shared bridge encoder
While you stare at the black screen in A, AVPlayer keeps fetching and discarding, so backpressure never parks the pump and it races through the rest of the file to EOF. The EOF path calls
AudioBridge.flush(), which sends the encoderavcodec_send_frame(enc, nil). That puts an FFmpeg encoder into a terminal draining state, and unlike the decoder (whichstartSegment()revives viaavcodec_flush_buffers), the encoder was never rebuilt. Worse, both feed paths explicitly exemptedAVERROR_EOFfrom error handling, so every post-EOF pump fed the bridge and got zero packets back with zero diagnostics.That is why the muxer died the way it did: the restarted producer wrote ~4.8 s of video, no EAC3 packet ever arrived, and the first cut cannot write moov because movenc needs a parsed EAC3 packet to build the dec3 sample entry. Hence
Cannot write moov atom before EAC3 packets parsed,seg-0.m4s cut FAILED,reason=muxerFailed. It also explains the intermittency: B only bites when the pump reached EOF before your seek.Fixes, all in 833e0d1:
flush()latches the EOF drain;startSegment()rebuilds the encoder context when latched (the codecpar the muxer points at is refreshed in place, never reallocated).AVERROR_EOFfrom the bridge decoder or encoder now throws loudly instead of being swallowed.muxerFailedhad no VOD escalation: it now gets a bounded revive (2 attempts per session) through the normal restart path, aimed like the wedge re-anchor (pending seek target first, else the rendered position). Since that path re-arms the bridge and rebuilds the muxer, the known transient causes self-heal; a persistent one gives up with a clear log instead of restart-storming.Verification
Issue99BridgeResumeTests) cover the rebase-at-init invariant, the post-EOF encoder revive, the loud EOF error, and the revive gate; the full test suite stays green.aetherctl serve --start-position 60(flag added in the same commit so this stays reproducible): tfdt evidence above, plus a plain start-from-0 regression check (unchanged behavior, including the pre-existing and harmless -256-tick first audio fragment from EAC3 encoder padding, which CoreMedia clips at position 0).Could you retest against 257b5ee? Expected behavior on your file: resume at ~690 s / ~893 s becomes ready within the normal startup window, and if you have a session that was already wedged, a seek should now recover it instead of killing the pump.
RomanLiberda commentedon Jul 5, 2026
Tested. It works. Thanks
chore(release): 4.12.0
fix(video): recover from a VOD producer that dies mid-session at the …
fix(vod): open the restart scan-forward gate on keyframe pts and reco…
fix(vod): open the restart scan-forward gate on keyframe pts and reco…