summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorSagnac <83491030+Sagnac@users.noreply.github.com>2021-06-14 16:37:10 +0000
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2021-06-16 02:04:28 +0300
commit96b246d9283da99b82800bbd576037d115e3c6e9 (patch)
treebb63fb2e72cfe1690a273ee54f60f31b37d23c80 /player/lua
parentbc9d556f3a890cf5f99e9dced0117e2d8a91ff09 (diff)
downloadmpv-96b246d9283da99b82800bbd576037d115e3c6e9.tar.bz2
mpv-96b246d9283da99b82800bbd576037d115e3c6e9.tar.xz
osc: update chapter marker positions when duration changes
Commit 6abb7e3 updates the markers when the chapters change, but it doesn't update their relative position at the bar when the duration changes. This means that adding chapters to a live stream would result in corresponding chapter markers which were static while the duration changed and thus their positions became incorrect over time until the OSC was reinitialized. This is fixed by observing the duration property if chapters are present and reinitializing the OSC when the duration changes. The live_markers user option, which determines whether the duration property is observed when there are chapters, has been added in order to allow disabling this behaviour as calling request_init() frequently might have some impact on low-end systems. The impact of request_init() on render() was measured to increase from 1-1.5 ms to 2-3 ms on a 2010 MacBook Air, while the impact was neglible on a 2016 Surface Book (increasing only to an average of 1.4 ms from 1.3 ms for n=1500 render cycles). The live_markers option is enabled by default.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/osc.lua30
1 files changed, 29 insertions, 1 deletions
diff --git a/player/lua/osc.lua b/player/lua/osc.lua
index 95c61025fe..f2b6d3ed2d 100644
--- a/player/lua/osc.lua
+++ b/player/lua/osc.lua
@@ -48,6 +48,7 @@ local user_opts = {
windowcontrols = "auto", -- whether to show window controls
windowcontrols_alignment = "right", -- which side to show window controls on
greenandgrumpy = false, -- disable santa hat
+ livemarkers = true, -- update seekbar chapter markers on duration change
}
-- read options from config and command-line
@@ -1688,6 +1689,7 @@ function update_options(list)
validate_user_opts()
request_tick()
visibility_mode(user_opts.visibility, true)
+ update_duration_watch()
request_init()
end
@@ -2592,13 +2594,39 @@ function enable_osc(enable)
end
end
+-- duration is observed for the sole purpose of updating chapter markers
+-- positions. live streams with chapters are very rare, and the update is also
+-- expensive (with request_init), so it's only observed when we have chapters
+-- and the user didn't disable the livemarkers option (update_duration_watch).
+function on_duration() request_init() end
+
+local duration_watched = false
+function update_duration_watch()
+ local want_watch = user_opts.livemarkers and
+ (mp.get_property_number("chapters", 0) or 0) > 0 and
+ true or false -- ensure it's a boolean
+
+ if (want_watch ~= duration_watched) then
+ if want_watch then
+ mp.observe_property("duration", nil, on_duration)
+ else
+ mp.unobserve_property(on_duration)
+ end
+ duration_watched = want_watch
+ end
+end
+
validate_user_opts()
+update_duration_watch()
mp.register_event("shutdown", shutdown)
mp.register_event("start-file", request_init)
mp.observe_property("track-list", nil, request_init)
mp.observe_property("playlist", nil, request_init)
-mp.observe_property("chapter-list", nil, request_init)
+mp.observe_property("chapter-list", nil, function()
+ update_duration_watch()
+ request_init()
+end)
mp.register_script_message("osc-message", show_message)
mp.register_script_message("osc-chapterlist", function(dur)