state-stream: fix storing/restoring notification volume

We apparently store things in the <media-class>:<key>:<value>
format, while pipewire-pulse expects <media-class>.<key>:<value>
and this detail was missed in the latest refactoring.

It also seems that I forgot to ensure that restoring this metadata
key worked. The hook was there, but not registered.
Remove the hook and directly populate the metadata object when
it is activated, as it seems simpler.

Fixes: #604
This commit is contained in:
George Kiagiadakis
2024-03-30 11:53:45 +02:00
parent 2a45842169
commit 3b0c0fcd7e

View File

@@ -264,32 +264,25 @@ store_stream_target_hook = SimpleEventHook {
end end
} }
-- track route-settings metadata changes -- populate route-settings metadata
route_settings_metadata_added_hook = SimpleEventHook { function populateMetadata (metadata)
name = "node/route-settings-metadata-added", -- copy state into the metadata
interests = { local key = "Output/Audio:media.role:Notification"
EventInterest { local p = getStoredStreamProps (key)
Constraint { "event.type", "=", "metadata-added" }, if p then
Constraint { "metadata.name", "=", "route-settings" }, p.channels = p.channelMap and Json.Array (p.channelMap)
}, p.volumes = p.channelVolumes and Json.Array (p.channelVolumes)
}, p.channelMap = nil
execute = function (event) p.channelVolumes = nil
local metadata = event:get_subject () p.target = nil
-- copy state into the metadata -- pipewire-pulse expects the key to be
local key = "Output/Audio:media.role:Notification" -- "restore.stream.Output/Audio.media.role:Notification"
local p = getStoredStreamProps (key) key = string.gsub (key, ":", ".", 1);
if p then metadata:set (0, "restore.stream." .. key, "Spa:String:JSON",
p.channels = p.channelMap and Json.Array (p.channelMap) Json.Object (p):to_string ())
p.volumes = p.channelVolumes and Json.Array (p.channelVolumes)
p.channelMap = nil
p.channelVolumes = nil
p.target = nil
metadata:set (0, "restore.stream." .. key, "Spa:String:JSON",
Json.Object (p):to_string ())
end
end end
} end
-- track route-settings metadata changes -- track route-settings metadata changes
route_settings_metadata_changed_hook = SimpleEventHook { route_settings_metadata_changed_hook = SimpleEventHook {
@@ -299,7 +292,7 @@ route_settings_metadata_changed_hook = SimpleEventHook {
Constraint { "event.type", "=", "metadata-changed" }, Constraint { "event.type", "=", "metadata-changed" },
Constraint { "metadata.name", "=", "route-settings" }, Constraint { "metadata.name", "=", "route-settings" },
Constraint { "event.subject.key", "=", Constraint { "event.subject.key", "=",
"restore.stream.Output/Audio:media.role:Notification" }, "restore.stream.Output/Audio.media.role:Notification" },
Constraint { "event.subject.spa_type", "=", "Spa:String:JSON" }, Constraint { "event.subject.spa_type", "=", "Spa:String:JSON" },
Constraint { "event.subject.value", "is-present" }, Constraint { "event.subject.value", "is-present" },
}, },
@@ -316,6 +309,8 @@ route_settings_metadata_changed_hook = SimpleEventHook {
end end
local vparsed = json:parse () local vparsed = json:parse ()
-- we store the key as "Output/Audio:media.role:Notification"
local key = string.sub (key, string.len ("restore.stream.") + 1) local key = string.sub (key, string.len ("restore.stream.") + 1)
key = string.gsub (key, "%.", ":", 1); key = string.gsub (key, "%.", ":", 1);
@@ -427,6 +422,8 @@ function toggleState (enable)
rs_metadata:activate (Features.ALL, function (m, e) rs_metadata:activate (Features.ALL, function (m, e)
if e then if e then
log:warning ("failed to activate route-settings metadata: " .. tostring (e)) log:warning ("failed to activate route-settings metadata: " .. tostring (e))
else
populateMetadata (m)
end end
end) end)