From 0000e9a02e2222294c55c1b494029ae6b605a637 Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Tue, 12 Jul 2022 18:19:38 +0200 Subject: [PATCH] Automatically choose rendering frequency --- uosc.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/uosc.lua b/uosc.lua index 4e110bb..700db80 100644 --- a/uosc.lua +++ b/uosc.lua @@ -302,7 +302,9 @@ local options = { } opt.read_options(options, 'uosc') local config = { - render_delay = 0.03, -- sets max rendering frequency + -- sets max rendering frequency in case the + -- native rendering frequency could not be detected + render_delay = 1/60, font = mp.get_property('options/osd-font'), menu_parent_opacity = 0.4, menu_min_width = 260 @@ -348,6 +350,7 @@ local state = { end), mouse_bindings_enabled = false, cached_ranges = nil, + render_delay = config.render_delay, } local forced_key_bindings -- defined at the bottom next to events @@ -2172,7 +2175,7 @@ function request_render() if not state.render_timer:is_enabled() then local now = mp.get_time() - local timeout = config.render_delay - (now - state.render_last_time) + local timeout = state.render_delay - (now - state.render_last_time) if timeout < 0 then timeout = 0 end @@ -2962,6 +2965,20 @@ function load_file_in_current_directory(index) end end +function update_render_delay(name, fps) + if fps then + state.render_delay = 1/fps + end +end + +function observe_display_fps(name, fps) + if fps then + mp.unobserve_property(update_render_delay) + mp.unobserve_property(observe_display_fps) + mp.observe_property('display-fps', 'native', update_render_delay) + end +end + -- MENUS function create_select_tracklist_type_menu_opener(menu_title, track_type, track_prop) @@ -3154,6 +3171,8 @@ mp.observe_property('demuxer-cache-state', 'native', function(prop, cache_state) state.cached_ranges = #cache_ranges > 0 and cache_ranges or nil request_render() end) +mp.observe_property('display-fps', 'native', observe_display_fps) +mp.observe_property('estimated-display-fps', 'native', update_render_delay) -- CONTROLS