Skip to content

fix(macos): show the current frame of a paused HLS stream - #261

Open
comprido96 wants to merge 1 commit into
kdroidFilter:masterfrom
comprido96:fix/macos-hls-paused-frame
Open

comprido96 wants to merge 1 commit into
kdroidFilter:masterfrom
comprido96:fix/macos-hls-paused-frame

Conversation

@comprido96

Copy link
Copy Markdown

Problem

On macOS, a paused HLS video never updates its picture:

  • pause(), a seek while paused and captureInitialFrame() all skip HLS (!isHLSStream), and frames are only pulled by the capture timer while playing;
  • so after a seek while paused the surface keeps the frame from before the seek, and an HLS media opened with InitialPlayerState.PAUSE shows nothing.

Fix

  • Native: for HLS, pause(), a seek that lands while paused (seek completion handler), and the item turning readyToPlay while paused call capturePausedFrame(), which copies the frame at the current time. AVPlayerItemVideoOutput decodes it asynchronously after a seek or an open, so the capture polls every 20 ms for up to a second. Non-HLS media keep their existing path.
  • Native → Kotlin: a frame counter (getFrameGeneration, nGetFrameGeneration) incremented on every retained frame.
  • Kotlin (MacVideoPlayerState): while paused, waitForPlaybackState re-arms its one-shot thumbnail read when the counter changes. Without it the paused producer spends that read right after the seek, on the old frame, and never sees the new one.

Testing

Tested on macOS 26 (Apple Silicon), against Frigate 0.17 HLS VOD clips (fMP4 segments, EXT-X-DISCONTINUITY between segments, keyframes every 2 s) from two cameras: H.264 Baseline 1280×720 25 fps, and H.264 High 2560×1920 ~30 fps VFR with AAC.

  • Native: a Swift driver built against this NativeVideoPlayer.swift, calling MacVideoPlayer with the same sequence the Kotlin layer uses. After each of 4 paused seeks the retained frame changes (before: never), and a media opened paused has a frame.
  • Kotlin + native: the same change in a desktop app. Over the paused seeks the surface shows the destination frame (checked against the camera's on-screen clock), and the media opened paused shows its first frame.
  • :mediaplayer:jvmJar (Swift build included) passes.

Prepared with an AI coding assistant (Claude Code) while integrating the library into a macOS desktop app, and tested as described above. Happy to adjust, split or drop anything that does not fit the project.

🤖 Generated with Claude Code

AVPlayerItemVideoOutput only delivers frames while the timer pulls them during
playback, and the paused-frame captures in pause(), seekTo() and at open were
all skipped for HLS. A paused HLS video therefore kept a stale frame after a
seek, and an HLS media opened paused showed nothing at all.

- pause(), a landed seek while paused, and an HLS item turning readyToPlay
  while paused capture the frame at the current time. The output decodes it
  asynchronously, so the capture polls for up to a second.
- The native side counts retained frames (getFrameGeneration). While paused,
  MacVideoPlayerState re-arms its one-shot thumbnail read when the count
  changes: the frame of a paused seek lands after the producer has already
  spent that read on the previous frame.

Non-HLS media keep their existing path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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