Repository navigation
fix(playback): present the target frame after a paused seek - #18
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if outcome == .landed { | ||
| armPausedSeekFrame(generation: generation, minimumPTS: sourceSeconds) | ||
| } |
There was a problem hiding this comment.
Indefinitely pending picture requests occur on an autoplay=false software mount when a seek precedes the first Play, because paused-seek arming neither starts the demux loop nor attaches the video renderer; both operations exist only in play(). Initialize the paused decoding pipeline without starting transport or audio before releasing the seek window.
Prompt for LLM
File Sources/AetherEngine/Native/SoftwarePlaybackHost.swift:
Line 1482 to 1484:
Indefinitely pending picture requests occur on an autoplay=false software mount when a seek precedes the first Play, because paused-seek arming neither starts the demux loop nor attaches the video renderer; both operations exist only in play(). Initialize the paused decoding pipeline without starting transport or audio before releasing the seek window.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not a regression. Before this PR, a seek before the first Play showed no picture either, because the loops only start in play(). The request armed here is read only by the demux loop, so with no loop running it does nothing. play() clears it through .resumeHostPause before startDemuxLoop(), and playback starts from the seek target. Showing a picture before the first Play would be a new feature, so it stays out of this PR.
There was a problem hiding this comment.
Agreed—this suggestion should not block the PR. Based on the lifecycle you described, the armed request has no effect before the first Play: the demux loop is not running, and play() clears the request through .resumeHostPause before starting that loop. Playback then begins from the seek target.
Rendering a paused seek before the first Play would extend existing behavior, not fix a regression introduced here. I withdraw the recommendation to initialize the pipeline in this PR.
| audioOutput?.seekClock(to: targetTime, rate: 0) | ||
| pausedByHost = true | ||
| if outcome == .landed { | ||
| armPausedSeekFrame(generation: generation, minimumPTS: sourceSeconds) |
There was a problem hiding this comment.
Paused-picture request deadlock occurs when the existing VOD audio-lead read gate stops demuxing at four seconds of queued audio before the target video frame decodes, as with frame-threaded low-frame-rate content requiring more than four seconds of packets; waitForRenderer(.readGate) cannot clear because the seek clock stays at rate zero. Allow bounded preroll feeding independent of audio-lead pacing while the paused-picture request is pending.
Prompt for LLM
File Sources/AetherEngine/Native/SoftwarePlaybackHost.swift:
Line 1483:
Paused-picture request deadlock occurs when the existing VOD audio-lead read gate stops demuxing at four seconds of queued audio before the target video frame decodes, as with frame-threaded low-frame-rate content requiring more than four seconds of packets; waitForRenderer(.readGate) cannot clear because the seek clock stays at rate zero. Allow bounded preroll feeding independent of audio-lead pacing while the paused-picture request is pending.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Partly right, but it isn't a deadlock: Play clears the request and starts the clock, the audio lead drains, and the gate opens. The real regression was a busy-wait. While the request is pending, the loop runs at a stopped clock, and the parked wait polled every 5 ms for as long as the viewer stayed paused. 3d1d1ff makes a stopped, armed clock wait 0.5 s instead, the same interval the paused loops use. Play, stop and seek broadcast the condition, so they still end the wait at once; a test covers the new wait. If the decoder needs more than the 4 s audio lead to produce the target frame, the old picture stays until Play, as it did before this PR. Feeding past the audio-lead gate would need its own memory bound, so I've kept it out of this PR.
There was a problem hiding this comment.
Agreed—“deadlock” overstated the finding. Play provides an exit: it clears the request, starts the clock, and lets the queued audio drain so the read gate can reopen.
Based on your explanation, 3d1d1ff8 addresses the actual regression: repeated 5 ms polling while the paused-picture request remains pending. The 0.5 s wait reduces that polling, while condition broadcasts preserve prompt wakeups for Play, stop, and seek.
The decoder needing more than four seconds of packets is a separate limitation: the picture can remain stale until Play, but that behavior predates this PR. Bypassing the audio-lead gate would require a separate memory bound, so keeping it out of this fix is reasonable. My original suggestion should not be treated as a blocking deadlock finding.
| if !self.isPlaying, self.pausedBeforeFirstFrame { | ||
| self.pausedBeforeFirstFrame = false | ||
| self.heldEndOfMedia.hold(generation: generation) |
There was a problem hiding this comment.
Premature EOF handling occurs because the VOD EOF path calls videoDecoder.flush() before this branch, discarding delayed frames and causing the new EOF hold to treat a buffered target as a seek past the last picture; a paused seek into the decoder's final buffered frames retains the old picture, and Play immediately ends the session. Drain delayed decoder output before deciding that the pending picture request has reached EOF.
Prompt for LLM
File Sources/AetherEngine/Native/SoftwarePlaybackHost.swift:
Line 1793 to 1795:
Premature EOF handling occurs because the VOD EOF path calls videoDecoder.flush() before this branch, discarding delayed frames and causing the new EOF hold to treat a buffered target as a seek past the last picture; a paused seek into the decoder's final buffered frames retains the old picture, and Play immediately ends the session. Drain delayed decoder output before deciding that the pending picture request has reached EOF.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Right about the mechanism, but this PR doesn't change it. The software decoder's flush() discards delayed frames: it calls avcodec_flush_buffers without sending a draining null packet. Before this PR, a paused seek into those last delayed frames also kept the old picture, and Play then reached end of media through the same flush and ended without showing them. Ordinary playback to the end drops the same frames. Draining the decoder at end of media would change every end of media, so it belongs in a separate change.
There was a problem hiding this comment.
Agreed—the mechanism is real, but I incorrectly framed it as a regression introduced by this PR.
As you explain, avcodec_flush_buffers discards delayed output rather than draining it. That already affects both paused seeks into the final buffered frames and ordinary playback to EOF. The new EOF hold changes when the end is delivered, not whether those frames are preserved.
This suggestion should not block PR #18. Draining delayed decoder output at EOF belongs in a separate fix, with coverage for both ordinary playback and paused seeks. No issue or rule has been created.
A paused seek runs the loops at a stopped clock until the target frame decodes. When the audio-lead read gate closed first, the parked wait polled every 5 ms for as long as the viewer stayed paused. A stopped, armed clock now waits the paused loops' half second; play, stop and seek still cut the wait short.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Summary
On the software video path, a seek made while paused, such as choosing a chapter from Silo's Chapters menu, moves the clock but leaves the previous picture on screen until Play. This change decodes and shows the seek's target frame while transport and audio stay paused.
Related: Silo-Server/silo-server#1154 (chapter navigation on native clients).
What changed
PausedFrameGateholds that request with the seek generation and the target time. Frames from an older generation and preroll frames before the target are ignored. The first eligible frame drains the reorder buffer and is shown at the stopped clock. Then the loops park again. Play, stop and a newer seek cancel the request..ended, next-up) under a pause. That end is now held:play()delivers it, and a newer seek discards it (HeldEndOfMedia).CHANGELOG.md,docs/api.mdanddocs/architecture.mdare updated.Test plan
Device / OS: iPhone 17 Pro simulator, iOS 26.5, Silo iOS app at silo-apple
5c1dcfb0. That commit pins AetherEngineef0d2c7f, this branch's base. The "after" build used a local path override to this branch. Both builds used the software path (effective video route = software,[SWHost] session start).Source media: synthetic 120 s MP4, H.264 + AAC, SDR, with six 20 s solid colour bands and embedded chapters at 0 s, 40 s and 80 s, served by a local Silo server.
Result:
ef0d2c7f)Paused scrub to the end (seek lands at 120.00 s): neither build ends while paused. The after build logs
end of media under a paused seek: held until play. On Play, both builds restart from 0. That is becauseAetherEngine.play()already rewinds when within 0.5 s of the end, and it runs before the host. So the held end is only delivered when a paused seek lands past the last frame but more than 0.5 s before the end. That branch has unit tests but was not reproduced at runtime.swift buildandswift test: 4209 tests in 578 suites pass, including new tests for the frame gate and the held end.Not covered: physical devices, tvOS, the native AVPlayer path (unchanged), live and DVR sources, and HDR media.
Known limitation: when a paused seek lands past the last frame, the old picture stays on screen, because no frame at or after the target exists. Before this change the old picture also stayed.
Checklist
CHANGELOG.mdupdatedfeat(...),fix(...),chore(...))AI Disclosure