mpv-player / mpv-player/mpv

osd seekbar fails to keep up with playback, especially with high polling rate mice

Open
#10,110 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

priority:on-ice scripting:osc
Dominant language
C
Stars
37k
Forks
3.5k
Avg merge
1d 10h
Merged PRs (30d)
22

Description

Important Information

Provide following Information:

  • mpv version: 0.34.1
  • Platform and Version: Arch Linux rolling
  • Source of the mpv binary: Arch Linux repo
Reproduction steps

Drag-seek the osd seekbar somewhat fast, with a 1000hz mouse if possible.

Expected behavior

The osd seekbar fluidly keeps up with playback.

Actual behavior

The osd seekbar hangs when overwhelmed with mouse move events.

Log file

Does not show any relevant information. Will upload anyway if requested.

Sample files

issue: https://0x0.st/oc0Z.mp4
with proof of concept fix: https://0x0.st/oc0P.mp4

Notes

This appears to be an issue with mp.get_mouse_pos taking longer than expected due to being mutex locked on the playback thread while seeking.

Offending function: https://github.com/mpv-player/mpv/blob/v0.34.1/player/lua/osc.lua#L174

Caller: https://github.com/mpv-player/mpv/blob/v0.34.1/player/lua/osc.lua#L2508

Trash code proof of concept to show this can be fixed:

local cache_x, cache_y = mp.get_mouse_pos()
local throttle = 0
function get_virt_mouse_pos()
    if state.mouse_in_window then
        local sx, sy = get_virt_scale_factor()
        
        throttle = throttle + 1
        if throttle > 10 then
            cache_x, cache_y = mp.get_mouse_pos()
            throttle = 0
        end
        
        local x, y = cache_x, cache_y
        return x * sx, y * sy
    else
        return -1, -1
    end
end

Another line that's a bit costly for being called VERY often: https://github.com/mpv-player/mpv/blob/v0.34.1/player/lua/osc.lua#L2020
I've changed this to mp.command_native_async to further reduce blocking but I don't know if this is correct

I don't know the proper way to fix this issue, should mouse events be throttled or should the mutex lock itself be looked into?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the high-polling-rate mouse drag described in the issue, then inspect player/lua/osc.lua at the cited get_virt_mouse_pos, caller, and frequently called line around 2020. Compare the seekbar behavior against the provided proof-of-concept recording and verify that the chosen change prevents event overload while keeping seeking responsive.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
desktop, frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.