Skip to content
Snippets Groups Projects
Commit 83d0f305 authored by Frederic Danis's avatar Frederic Danis
Browse files

d/patches: Add fallback sink script


When running PW/WP on board with only HDMI audio output, and this one is
not connected, PW fails to create the Dummy Output as policy endpoint are
created by WP.

Signed-off-by: default avatarFrédéric Danis <frederic.danis@collabora.com>
parent 6023da42
No related branches found
No related tags found
1 merge request!25d/patches: Add fallback sink script
From 57769c20715873a06a756494f50bd2c6a9c71bea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= <frederic.danis@collabora.com>
Date: Thu, 31 Mar 2022 14:57:20 +0200
Subject: [PATCH] scripts: Add script to create fallback sink
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
This script, base on PipeWire module fallback-sink will create a fallback
sink node if there's no other sink available except the endpoints created
by WirePlumber.
---
src/scripts/fallback-sink.lua | 93 +++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 src/scripts/fallback-sink.lua
diff --git a/src/scripts/fallback-sink.lua b/src/scripts/fallback-sink.lua
new file mode 100644
index 0000000..d7c3cfa
--- /dev/null
+++ b/src/scripts/fallback-sink.lua
@@ -0,0 +1,93 @@
+-- WirePlumber
+--
+-- Copyright © 2021 Collabora Ltd.
+-- @author Frédéric Danis <frederic.danis@collabora.com>
+--
+-- SPDX-License-Identifier: MIT
+
+local sink_ids = {}
+local fallback_node = nil
+
+node_om = ObjectManager {
+ Interest {
+ type = "node",
+ Constraint { "media.class", "matches", "Audio/Sink", type = "pw-global" },
+ -- Do not consider endpoints created by WirePlumber
+ Constraint { "wireplumber.is-endpoint", "!", true, type = "pw" },
+ -- or the fallback sink itself
+ Constraint { "wireplumber.is-fallback", "!", true, type = "pw" },
+ }
+}
+
+function createFallbackSink()
+ if fallback_node then
+ return
+ end
+
+ Log.info("Create fallback sink")
+
+ local properties = {}
+
+ properties["node.name"] = "auto_null"
+ properties["node.description"] = "Dummy Output"
+
+ properties["audio.rate"] = 48000
+ properties["audio.channels"] = 2
+ properties["audio.position"] = "FL,FR"
+
+ properties["media.class"] = "Audio/Sink"
+ properties["factory.name"] = "support.null-audio-sink"
+ properties["node.virtual"] = "true"
+ properties["monitor.channel-volumes"] = "true"
+
+ properties["wireplumber.is-fallback"] = "true"
+ properties["priority.session"] = 500
+
+ fallback_node = LocalNode("adapter", properties)
+ fallback_node:activate(Feature.Proxy.BOUND)
+end
+
+function checkSinks()
+ local sink_ids_items = 0
+ for _ in pairs(sink_ids) do sink_ids_items = sink_ids_items + 1 end
+
+ if sink_ids_items > 0 then
+ if fallback_node then
+ Log.info("Remove fallback sink")
+ fallback_node = nil
+ end
+ elseif not fallback_node then
+ createFallbackSink()
+ end
+end
+
+function checkSinksAfterTimeout()
+ if timeout_source then
+ timeout_source:destroy()
+ end
+ timeout_source = Core.timeout_add(1000, function ()
+ checkSinks()
+ timeout_source = nil
+ end)
+end
+
+node_om:connect("object-added", function (_, node)
+ Log.debug("object added: " .. node.properties["object.id"] .. " " ..
+ tostring(node.properties["node.name"]))
+
+ sink_ids[node.properties["object.id"]] = node.properties["node.name"]
+
+ checkSinksAfterTimeout()
+end)
+
+node_om:connect("object-removed", function (_, node)
+ Log.debug("object removed: " .. node.properties["object.id"] .. " " ..
+ tostring(node.properties["node.name"]))
+
+ sink_ids[node.properties["object.id"]] = nil
+ checkSinksAfterTimeout()
+end)
+
+node_om:activate()
+
+checkSinksAfterTimeout()
--
2.25.1
From c0659653b6b04a5aa2d00a04d153641a7f669c83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= <frederic.danis@collabora.com>
Date: Tue, 5 Apr 2022 09:38:06 +0200
Subject: [PATCH] scripts: Automatically load fallback sink
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
---
src/config/main.lua.d/90-enable-all.lua | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/config/main.lua.d/90-enable-all.lua b/src/config/main.lua.d/90-enable-all.lua
index d518805..86777e4 100644
--- a/src/config/main.lua.d/90-enable-all.lua
+++ b/src/config/main.lua.d/90-enable-all.lua
@@ -20,3 +20,6 @@ load_script("intended-roles.lua")
-- Automatically suspends idle nodes after 3 seconds
load_script("suspend-node.lua")
+
+-- Automatically create fallback sink node
+load_script("fallback-sink.lua")
--
2.25.1
0001-scripts-Add-script-to-create-fallback-sink.patch
apertis-0001-scripts-Automatically-load-fallback-sink.patch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment