From 2d6d4b43cef63bd1f77952d37c8979ad57bad28a Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Tue, 14 Apr 2020 16:59:15 +0200 Subject: [PATCH 1/3] Work around performance regression in mpv's osd In mpv-player/mpv@07287262513c0d1ea46b7beaf100e73f2008295f, a strcmp on the previously displayed and the new text has been removed, causing excessive GPU usage especially on idle frames when playback was paused. I will submit a patch to upstream, but mpv versions 0.31 & 0.32 are already affected by this. See torque/mpv-progressbar#56 for a similar report to a different script. --- syncplay/resources/syncplayintf.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/syncplay/resources/syncplayintf.lua b/syncplay/resources/syncplayintf.lua index 9115faf03..839f4e46f 100644 --- a/syncplay/resources/syncplayintf.lua +++ b/syncplay/resources/syncplayintf.lua @@ -133,6 +133,7 @@ function add_chat(chat_message, mood) chat_log[entry] = { xpos=CANVAS_WIDTH, timecreated=mp.get_time(), text=tostring(chat_message), row=row } end +local old_ass_text = '' function chat_update() local ass = assdraw.ass_new() local chat_ass = '' @@ -179,7 +180,14 @@ function chat_update() ass:append(input_ass()) ass:append(chat_ass) end - mp.set_osd_ass(CANVAS_WIDTH,CANVAS_HEIGHT, ass.text) + + -- The commit that introduced the new API removed the internal heuristics on whether a refresh is required, + -- so we check for changed text manually to not cause excessive GPU load + -- https://github.com/mpv-player/mpv/commit/07287262513c0d1ea46b7beaf100e73f2008295f#diff-d88d582039dea993b6229da9f61ba76cL530 + if ass.text ~= old_ass_text then + mp.set_osd_ass(CANVAS_WIDTH,CANVAS_HEIGHT, ass.text) + old_ass_text = ass.text + end end function process_alert_osd() @@ -982,4 +990,4 @@ function set_syncplayintf_options(input) end chat_format = get_output_style() readyMpvAfterSettingsKnown() -end \ No newline at end of file +end From 6319fc5bb47b8af1dab73d781114cd1d30c68b5f Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Tue, 14 Apr 2020 16:49:49 +0200 Subject: [PATCH 2/3] Use mpv's new create_osd_overlay API The internal and previously used set_osd_ass API has been deprecated. --- syncplay/resources/syncplayintf.lua | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/syncplay/resources/syncplayintf.lua b/syncplay/resources/syncplayintf.lua index 839f4e46f..a00a1bed9 100644 --- a/syncplay/resources/syncplayintf.lua +++ b/syncplay/resources/syncplayintf.lua @@ -50,7 +50,6 @@ local FONT_SIZE_MULTIPLIER = 2 local chat_log = {} -local assdraw = require "mp.assdraw" local opt = require 'mp.options' @@ -94,6 +93,10 @@ function clear_chat() chat_log = {} end +local osd_overlay = mp.create_osd_overlay("ass-events") +osd_overlay.res_x = CANVAS_WIDTH +osd_overlay.res_y = CANVAS_HEIGHT + local alert_osd = "" local last_alert_osd_time = nil local alert_osd_mood = MOOD_NEUTRAL @@ -133,9 +136,7 @@ function add_chat(chat_message, mood) chat_log[entry] = { xpos=CANVAS_WIDTH, timecreated=mp.get_time(), text=tostring(chat_message), row=row } end -local old_ass_text = '' function chat_update() - local ass = assdraw.ass_new() local chat_ass = '' local rowsAdded = 0 local to_add = '' @@ -169,25 +170,23 @@ function chat_update() local ypos = opts['chatTopMargin'] chat_ass = "\n".."{\\pos("..xpos..","..ypos..")}".. chat_ass + local ass = '' if use_alpha_rows_for_chat == false and opts['chatDirectInput'] == true then - local alphawarning_ass = assdraw.ass_new() - alphawarning_ass = "{\\a6}{\\1c&H"..ALPHA_WARNING_TEXT_COLOUR.."}"..opts['alphakey-mode-warning-first-line'].."\n{\\a6}{\\1c&H"..ALPHA_WARNING_TEXT_COLOUR.."}"..opts['alphakey-mode-warning-second-line'] - ass:append(alphawarning_ass) + local alphawarning_ass = "{\\a6}{\\1c&H"..ALPHA_WARNING_TEXT_COLOUR.."}"..opts['alphakey-mode-warning-first-line'].."\n{\\a6}{\\1c&H"..ALPHA_WARNING_TEXT_COLOUR.."}"..opts['alphakey-mode-warning-second-line'] + ass = alphawarning_ass elseif opts['chatOutputMode'] == CHAT_MODE_CHATROOM and opts['chatInputPosition'] == "Top" then - ass:append(chat_ass) - ass:append(input_ass()) + ass = chat_ass .. input_ass() else - ass:append(input_ass()) - ass:append(chat_ass) + ass = input_ass() .. chat_ass end -- The commit that introduced the new API removed the internal heuristics on whether a refresh is required, -- so we check for changed text manually to not cause excessive GPU load -- https://github.com/mpv-player/mpv/commit/07287262513c0d1ea46b7beaf100e73f2008295f#diff-d88d582039dea993b6229da9f61ba76cL530 - if ass.text ~= old_ass_text then - mp.set_osd_ass(CANVAS_WIDTH,CANVAS_HEIGHT, ass.text) - old_ass_text = ass.text - end + if ass ~= osd_overlay.data then + osd_overlay.data = ass + osd_overlay:update() + end end function process_alert_osd() From 352a3dff6979c681b00e3872d82122059a6d4dbf Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Tue, 14 Apr 2020 16:50:32 +0200 Subject: [PATCH 3/3] Misc lua code cleanups --- syncplay/resources/syncplayintf.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/syncplay/resources/syncplayintf.lua b/syncplay/resources/syncplayintf.lua index a00a1bed9..3aa699c3a 100644 --- a/syncplay/resources/syncplayintf.lua +++ b/syncplay/resources/syncplayintf.lua @@ -204,7 +204,6 @@ function process_alert_osd() local messageString = wordwrapify_string(alert_osd) local startRow = 0 if messageString ~= '' and messageString ~= nil then - local toDisplay rowsCreated = rowsCreated + 1 messageString = messageColour..messageString if stringToAdd ~= "" then @@ -222,10 +221,8 @@ function process_notification_osd(startRow) local startRow = startRow local stringToAdd = "" if notification_osd ~= "" and mp.get_time() - last_notification_osd_time < opts['alertTimeout'] and last_notification_osd_time ~= nil then - local messageColour - messageColour = "{\\1c&H"..NOTIFICATION_TEXT_COLOUR.."}" - local messageString - messageString = wordwrapify_string(notification_osd) + local messageColour = "{\\1c&H"..NOTIFICATION_TEXT_COLOUR.."}" + local messageString = wordwrapify_string(notification_osd) messageString = messageColour..messageString messageString = format_chatroom(messageString) stringToAdd = messageString