meta-agl: split wireplumber to run in multiple instances
[AGL/meta-agl.git] / meta-pipewire / recipes-multimedia / wireplumber / wireplumber-config-agl / alsa-suspend.lua
1 -- WirePlumber
2 --
3 -- This script mutes all ALSA sinks when the "suspend.playback" metadata
4 -- key is set to 1; compliments pipewire-ic-ipc and the respective support
5 -- for handling "suspend.playback" in the policy scripts
6 --
7 -- Copyright © 2021 Collabora Ltd.
8 --    @author George Kiagiadakis <george.kiagiadakis@collabora.com>
9 --
10 -- SPDX-License-Identifier: MIT
11
12 mixer_api = Plugin.find("mixer-api")
13
14 nodes_om = ObjectManager {
15   Interest { type = "node",
16     Constraint { "media.class", "matches", "Audio/Sink" },
17     Constraint { "object.path", "matches", "alsa:pcm:*" },
18   },
19 }
20
21 metadata_om = ObjectManager {
22   Interest { type = "metadata",
23     Constraint { "metadata.name", "=", "default" },
24   }
25 }
26
27 metadata_om:connect("object-added", function (om, metadata)
28   metadata:connect("changed", function (m, subject, key, t, value)
29     if key == "suspend.playback" then
30       local suspended = (value == "1")
31
32       Log.info(string.format("%s ALSA nodes for IC sound",
33                              suspended and "muting" or "unmuting"))
34
35       for n in nodes_om:iterate() do
36         mixer_api:call("set-volume", n["bound-id"], {
37           ["mute"] = suspended,
38         })
39       end
40     end
41   end)
42 end)
43
44 nodes_om:activate()
45 metadata_om:activate()