Skip to content

fix(playback): present the target frame after a paused seek - #18

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/paused-seek-frame
Oct 11, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/paused-seek-frame

Conversation

@Rhainland

Copy link
Copy Markdown

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

  • A landed VOD seek made while paused requests one picture, the way a pause before the first frame already does. PausedFrameGate holds 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.
  • If a paused seek lands past the last video frame, the loops read to end of media while the viewer is still paused. Without a guard that ended the session (.ended, next-up) under a pause. That end is now held: play() delivers it, and a newer seek discards it (HeldEndOfMedia).
  • The existing first-frame-under-pause path now runs through the same gate.
  • No public API change. CHANGELOG.md, docs/api.md and docs/architecture.md are updated.

Test plan

  • Device / OS: iPhone 17 Pro simulator, iOS 26.5, Silo iOS app at silo-apple 5c1dcfb0. That commit pins AetherEngine ef0d2c7f, 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:

    Step while paused Before (ef0d2c7f) After
    Choose chapter at 0:40 clock 0:40, picture still the old yellow frame green frame at 0:40
    Choose chapter at 1:20 clock 1:20, picture still the old yellow frame blue frame at 1:20
    Play advances advances from 1:20, blue

    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 because AetherEngine.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 build and swift 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.md updated
  • Commit messages follow Conventional Commits (feat(...), fix(...), chore(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented

AI Disclosure

  • Harness: T3 Code, with the Codex harness for the first implementation and the Claude Code harness for the port onto 7.28.3, review fix and simulator check
  • Tool(s): Codex, Claude Code, GitHub CLI, Xcode simulator tools, FFmpeg
  • Model(s): gpt-6.1-sol, claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: A scoped code review of the diff against main found one issue: a paused seek past the last frame could end the session while paused. It is fixed by holding the end until Play.

@silo-kody

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d54b259-a84c-4bfa-b8d2-94d0f506f4ce

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +1482 to +1484
if outcome == .landed {
armPausedSeekFrame(generation: generation, minimumPTS: sourceSeconds)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1793 to +1795
if !self.isPlaying, self.pausedBeforeFirstFrame {
self.pausedBeforeFirstFrame = false
self.heldEndOfMedia.hold(generation: generation)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

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.

​

​

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit f1b3ba4 into Silo-Server:main Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants