Skip to content

fix: make media player seeking, position and queue memory reliable - #537

Merged
devopvoid merged 6 commits into
mainfrom
fix/media-player-seek-position
Nov 5, 2026
Merged

devopvoid merged 6 commits into
mainfrom
fix/media-player-seek-position

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Positions now count from the first frame played, video or audio, so sources that do not start at zero seek, loop and replay correctly. This changes seek and getPositionUs for such sources.

  • A seek while paused no longer hangs behind a queue the old position keeps full: each seek starts a generation of the pacer.
  • The video queue is held to 256 MiB per player, down from over 700 MiB in 4K. New getMaxQueuedVideoBytes, getQueuedVideoBytes and getPeakQueuedVideoBytes make this measurable across players.
  • The position only moves forward, and restarts as the next pass of a loop reaches delivery.
  • Video ahead of audio no longer goes out in a burst at the start.
  • The duration of a Matroska file that starts late is how long it runs, not where it ends.

A seek went to the container's clock as it was, while the decoders gave
out its times unchanged, so a source that does not start at zero sought
to the wrong place and could not be looped or played again. Positions now
count from the first frame played, video or audio, and a seek before the
video starts keeps the audio that comes first.
The seek emptied the queues to free the decode thread, but a decoder with
more on its way than a queue takes filled them again, and with playback
paused nothing made room, so the thread never got to the seek. Each seek
now starts a generation of the pacer, which turns away what is pushed for
the one before.
Sixty pictures take over 700 MiB in 4K. The queue is now held to 256 MiB
as well, which leaves 1080p its sixty pictures, and a player reports what
its queue takes and has taken, so that this can be measured across players
running side by side.
Video set the position outright, so a frame delivered late took it back
behind audio already played. Delivery now only moves it forward. Items
also carry the loop offset of their pass, as the player's own is ahead of
playback by the whole queue: looping held the position at zero for most
of a short source, and now restarts it as the next pass reaches delivery.
The clock mapping came from whatever reached the pacer first, which on a
decoder with many threads was audio starting after the video: the first
pictures were overdue by then, and WebRTC dropped all but the last. The
mapping now starts at the position when audio gets there first.
Matroska gives where a file ends on its clock, which libavformat passes
on as the duration. With positions counting from the first frame, that
was too long for a slider and left a gap of the start time at each seam
of a loop.
@devopvoid
devopvoid merged commit 45b41bc into main Nov 5, 2026
26 checks passed
@devopvoid
devopvoid deleted the fix/media-player-seek-position branch November 5, 2026 00:14
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.

1 participant