Skip to content

Commit

Permalink
osc.lua: add option to use display fps for update interval
Browse files Browse the repository at this point in the history
If the display fps is unavailable, use the tick_delay as a fallback.
  • Loading branch information
na-na-hi authored and kasper93 committed Jun 8, 2024
1 parent fa52526 commit f8f47d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions DOCS/man/osc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,14 @@ Configurable Options
Sets the minimum interval between OSC redraws in seconds. This can be
decreased on fast systems to make OSC rendering smoother.

Ignored if ``tick_delay_follow_display_fps`` is set to yes and the VO
supports the ``display-fps`` property.

``tick_delay_follow_display_fps``
Default: no

Use display fps to calculate the interval between OSC redraws.


Script Commands
~~~~~~~~~~~~~~~
Expand Down
18 changes: 16 additions & 2 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ local user_opts = {
time_pos_outline_color = "#000000", -- color of the border timecodes in slimbox and TimePosBar

tick_delay = 1 / 60, -- minimum interval between OSC redraws in seconds
tick_delay_follow_display_fps = false -- use display fps as the minimum interval
}

local osc_param = { -- calculated by osc_init()
Expand Down Expand Up @@ -2730,6 +2731,15 @@ local function update_duration_watch()
end
end

local function set_tick_delay(_, display_fps)
-- may be nil if unavailable or 0 fps is reported
if not display_fps or not user_opts.tick_delay_follow_display_fps then
tick_delay = user_opts.tick_delay
return
end
tick_delay = 1 / display_fps
end

mp.register_event("shutdown", shutdown)
mp.register_event("start-file", request_init)
mp.observe_property("track-list", "native", request_init)
Expand Down Expand Up @@ -2779,6 +2789,7 @@ mp.observe_property("idle-active", "bool", function(_, val)
request_tick()
end)

mp.observe_property("display-fps", "number", set_tick_delay)
mp.observe_property("pause", "bool", pause_state)
mp.observe_property("demuxer-cache-state", "native", cache_state)
mp.observe_property("vo-configured", "bool", request_tick)
Expand Down Expand Up @@ -2970,10 +2981,12 @@ local function validate_user_opts()
end

-- read options from config and command-line
opt.read_options(user_opts, "osc", function()
opt.read_options(user_opts, "osc", function(changed)
validate_user_opts()
set_osc_styles()
tick_delay = user_opts.tick_delay
if changed.tick_delay or changed.tick_delay_follow_display_fps then
set_tick_delay("display_fps", mp.get_property_number("display_fps", nil))
end
request_tick()
visibility_mode(user_opts.visibility, true)
update_duration_watch()
Expand All @@ -2982,6 +2995,7 @@ end)

validate_user_opts()
set_osc_styles()
set_tick_delay("display_fps", mp.get_property_number("display_fps", nil))
visibility_mode(user_opts.visibility, true)
update_duration_watch()

Expand Down

0 comments on commit f8f47d0

Please sign in to comment.