mpv: sane-sysvol: optimize
This commit is contained in:
@@ -3,7 +3,7 @@ msg.trace('sane-sysvol: load: begin')
|
||||
|
||||
non_blocking_popen = require("non_blocking_popen")
|
||||
|
||||
RD_SIZE = 4096
|
||||
RD_SIZE = 65536
|
||||
|
||||
function startswith(superstring, substring)
|
||||
return superstring:sub(1, substring:len()) == substring
|
||||
@@ -104,6 +104,7 @@ function pwmon_parser_new()
|
||||
in_mute = false,
|
||||
|
||||
feed_line = function(self, line)
|
||||
msg.trace("pw-mon:", line)
|
||||
line = ltrim(line)
|
||||
if startswith(line, "changed:") or startswith(line, "added:") or startswith(line, "removed:") then
|
||||
self.changed_id = nil
|
||||
@@ -184,8 +185,15 @@ function pwmon_new()
|
||||
msg.debug("pw-mon unexpectedly closed!")
|
||||
end
|
||||
if buf ~= nil then
|
||||
local old_vol = self.pwmon_parser:get_effective_volume()
|
||||
self.stdout_unparsed = self.stdout_unparsed .. buf
|
||||
self:consume_stdout()
|
||||
local new_vol = self.pwmon_parser:get_effective_volume()
|
||||
|
||||
if new_vol ~= old_vol then
|
||||
msg.debug("pipewire volume change:", old_vol, new_vol)
|
||||
mp.set_property_native("user-data/sane-sysvol/pw-mon-volume", new_vol)
|
||||
end
|
||||
end
|
||||
end,
|
||||
consume_stdout = function(self)
|
||||
@@ -193,22 +201,12 @@ function pwmon_new()
|
||||
while next_newline ~= nil do
|
||||
next_newline = self.stdout_unparsed:find("\n", idx_newline + 1, true)
|
||||
if next_newline ~= nil then
|
||||
self:ingest_line(self.stdout_unparsed:sub(idx_newline + 1, next_newline - 1))
|
||||
self.pwmon_parser:feed_line(self.stdout_unparsed:sub(idx_newline + 1, next_newline - 1))
|
||||
idx_newline = next_newline
|
||||
end
|
||||
end
|
||||
self.stdout_unparsed = self.stdout_unparsed:sub(idx_newline + 1)
|
||||
end,
|
||||
ingest_line = function(self, line)
|
||||
msg.trace("pw-mon:", line)
|
||||
local old_vol = self.pwmon_parser:get_effective_volume()
|
||||
self.pwmon_parser:feed_line(line)
|
||||
local new_vol = self.pwmon_parser:get_effective_volume()
|
||||
if new_vol ~= old_vol then
|
||||
msg.debug("pipewire volume change:", old_vol, new_vol)
|
||||
mp.set_property_native("user-data/sane-sysvol/pw-mon-volume", new_vol)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user