From 1b0d65113b277610135b5599c8810ca7a4e3df4c Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Mon, 20 Sep 2021 14:29:45 +0300 Subject: meta-agl: split wireplumber to run in multiple instances The "IC SoundManager" design specifies that there needs to be a session manager running in the host to manage devices and permissions, but all the domain-specific policy and app management needs to run in the IVI container, together with the apps. With this split, we are able to achieve that. In addition to the "host" and "policy" instances, we are also adding a "bluetooth" one, which loads the bluetooth plugin and manages the bluetooth device. This can be moved to the IVI container as well, or elsewhere... it only depends on bluez (so it must run in the same container as bluez). For now, given the absence of an IVI container in the lxc-demo image, all instances are running in the host, but it is trivial to move all the non-host ones to another container later. To compliment pipewire-ic-ipc, this change also adds an "alsa-suspend" lua script that runs in the context of the "host" wireplumber instance and its purpose is to mute pipewire-managed alsa devices when there is a sound playing in the IC container (on another alsa device). Finally, this change also adds V4L2 configuration in the "host" wireplumber instance, which is still disabled (and untested), but you can easily enable it for experimentation by uncommenting the relevant line in host.lua.d/90-enable-all.lua Bug-AGL: SPEC-4027 Signed-off-by: George Kiagiadakis Change-Id: I9febc4f3919e7c559a5d7d32bfe7bc95c75934f2 Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/26662 Tested-by: Jenkins Job builder account ci-image-build: Jenkins Job builder account ci-image-boot-test: Jenkins Job builder account Reviewed-by: Naoto YAMAGUCHI Reviewed-by: Jan-Simon Moeller --- .../wireplumber-config-agl/10-default-policy.lua | 124 ----------------- .../wireplumber-config-agl/30-alsa-monitor.lua | 151 --------------------- .../wireplumber-config-agl/30-bluez-monitor.lua | 109 --------------- .../wireplumber-config-agl/99-load-modules.lua | 27 ---- .../wireplumber-config-agl/alsa-suspend.lua | 45 ++++++ .../wireplumber-config-agl/bluetooth.conf | 74 ++++++++++ .../bluetooth.lua.d/30-bluez-monitor.lua | 107 +++++++++++++++ .../host.lua.d/30-alsa-monitor.lua | 151 +++++++++++++++++++++ .../host.lua.d/30-v4l2-monitor.lua | 48 +++++++ .../host.lua.d/40-device-defaults.lua | 26 ++++ .../host.lua.d/90-enable-all.lua | 20 +++ .../wireplumber/wireplumber-config-agl/policy.conf | 73 ++++++++++ .../policy.lua.d/10-default-policy.lua | 122 +++++++++++++++++ .../wireplumber-config-agl/wireplumber.conf | 2 +- .../wireplumber/wireplumber-config-agl_git.bb | 51 +++++-- 15 files changed, 706 insertions(+), 424 deletions(-) delete mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/10-default-policy.lua delete mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-alsa-monitor.lua delete mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-bluez-monitor.lua delete mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/99-load-modules.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/alsa-suspend.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.conf create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.lua.d/30-bluez-monitor.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-alsa-monitor.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-v4l2-monitor.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/40-device-defaults.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/90-enable-all.lua create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.conf create mode 100644 meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.lua.d/10-default-policy.lua (limited to 'meta-pipewire/recipes-multimedia/wireplumber') diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/10-default-policy.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/10-default-policy.lua deleted file mode 100644 index f71b31316..000000000 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/10-default-policy.lua +++ /dev/null @@ -1,124 +0,0 @@ --- Default policy config file -- - -default_policy = {} - -default_policy.endpoints = { - -- [endpoint name] = { endpoint properties } - - ["endpoint.multimedia"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Multimedia", - }, - ["endpoint.speech_low"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Speech-Low", - }, - ["endpoint.custom_low"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Custom-Low", - }, - ["endpoint.navigation"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Navigation", - }, - ["endpoint.speech_high"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Speech-High", - }, - ["endpoint.custom_high"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Custom-High", - }, - ["endpoint.communication"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Communication", - }, - ["endpoint.emergency"] = { - ["media.class"] = "Audio/Sink", - ["role"] = "Emergency", - }, -} - -default_policy.policy = { - ["move"] = false, -- moves session items when metadata target.node changes - ["follow"] = true, -- moves session items to the default device when it has changed - - -- how much to lower the volume of lower priority streams when ducking - -- note that this is a linear volume modifier (not cubic as in the mixer) - ["duck.level"] = 0.2, - - ["roles"] = { - ["Multimedia"] = { - ["alias"] = { "Movie", "Music", "Game" }, - ["priority"] = 25, - ["action.default"] = "cork", - }, - ["Speech-Low"] = { - ["priority"] = 30, - ["action.default"] = "cork", - ["action.Speech-Low"] = "mix", - }, - ["Custom-Low"] = { - ["priority"] = 35, - ["action.default"] = "cork", - ["action.Custom-Low"] = "mix", - }, - ["Navigation"] = { - ["priority"] = 50, - ["action.default"] = "duck", - ["action.Navigation"] = "mix", - }, - ["Speech-High"] = { - ["priority"] = 60, - ["action.default"] = "cork", - ["action.Speech-High"] = "mix", - }, - ["Custom-High"] = { - ["priority"] = 65, - ["action.default"] = "cork", - ["action.Custom-High"] = "mix", - }, - ["Communication"] = { - ["priority"] = 75, - ["action.default"] = "cork", - ["action.Communication"] = "mix", - }, - ["Emergency"] = { - ["alias"] = { "Alert" }, - ["priority"] = 99, - ["action.default"] = "cork", - ["action.Emergency"] = "mix", - }, - }, -} - -function default_policy.enable() - -- Session item factories, building blocks for the session management graph - -- Do not disable these unless you really know what you are doing - load_module("si-node") - load_module("si-audio-adapter") - load_module("si-standard-link") - load_module("si-audio-endpoint") - - -- API to access default nodes from scripts - load_module("default-nodes-api") - - -- API to access mixer controls, needed for volume ducking - load_module("mixer-api") - - -- Create endpoints statically at startup - load_script("static-endpoints.lua", default_policy.endpoints) - - -- Create session items for nodes that appear in the graph - load_script("create-item.lua") - - -- Link nodes to each other to make media flow in the graph - load_script("policy-node.lua", default_policy.policy) - - -- Link client nodes with endpoints to make media flow in the graph - load_script("policy-endpoint-client.lua", default_policy.policy) - load_script("policy-endpoint-client-links.lua", default_policy.policy) - - -- Link endpoints with device nodes to make media flow in the graph - load_script("policy-endpoint-device.lua", default_policy.policy) -end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-alsa-monitor.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-alsa-monitor.lua deleted file mode 100644 index 75a169675..000000000 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-alsa-monitor.lua +++ /dev/null @@ -1,151 +0,0 @@ --- ALSA monitor config file -- - -alsa_monitor = {} - -alsa_monitor.properties = { - ["alsa.jack-device"] = false, - ["alsa.reserve"] = false, -} - -alsa_monitor.rules = { - -- disable ACP (PulseAudio-like profiles) - { - matches = { - { - { "device.name", "matches", "alsa_card.*" }, - }, - }, - apply_properties = { - ["api.alsa.use-acp"] = false, - }, - }, - - -- - -- Bump priority of well-known output devices - -- Higher priority means it gets selected as the default if it's present - -- - - -- USB card - { - matches = { - { - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.card.driver", "=", "USB-Audio" }, - }, - }, - apply_properties = { - ["priority.driver"] = 1300, - ["priority.session"] = 1300, - } - }, - - -- fiberdyne amp - { - matches = { - { - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.card.id", "=", "ep016ch" }, - }, - }, - apply_properties = { - ["priority.driver"] = 1200, - ["priority.session"] = 1200, - } - }, - - -- well-known internal devices - { - matches = { - { - -- ak4613 - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.card.id", "=", "ak4613" }, - { "api.alsa.pcm.device", "=", "0" }, - }, - { - -- imx8mq - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.card.id", "=", "wm8524audio" }, - }, - { - -- rcarsound - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.card.id", "=", "rcarsound" }, - { "api.alsa.pcm.device", "=", "0" }, - }, - { - -- rpi3 - { "node.name", "matches", "alsa_output.*" }, - { "api.alsa.pcm.name", "=", "bcm2835 ALSA" }, - }, - }, - apply_properties = { - ["priority.driver"] = 1100, - ["priority.session"] = 1100, - } - }, - - -- - -- Same for input devices - -- - - -- USB card - { - matches = { - { - { "node.name", "matches", "alsa_input.*" }, - { "api.alsa.card.driver", "=", "USB-Audio" }, - }, - }, - apply_properties = { - ["priority.driver"] = 2300, - ["priority.session"] = 2300, - } - }, - - -- microchip mic - { - matches = { - { - { "node.name", "matches", "alsa_input.*" }, - { "api.alsa.card.id", "=", "ep811ch" }, - }, - }, - apply_properties = { - ["priority.driver"] = 2200, - ["priority.session"] = 2200, - } - }, - - -- well-known internal devices - { - matches = { - { - -- ak4613 - { "node.name", "matches", "alsa_input.*" }, - { "api.alsa.card.id", "=", "ak4613" }, - }, - { - -- imx8mq - { "node.name", "matches", "alsa_input.*" }, - { "api.alsa.card.id", "=", "wm8524audio" }, - }, - { - -- rcarsound - { "node.name", "matches", "alsa_input.*" }, - { "api.alsa.card.id", "=", "rcarsound" }, - }, - }, - apply_properties = { - ["priority.driver"] = 2100, - ["priority.session"] = 2100, - } - }, -} - -function alsa_monitor.enable() - load_monitor("alsa", { - properties = alsa_monitor.properties, - rules = alsa_monitor.rules, - }) -end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-bluez-monitor.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-bluez-monitor.lua deleted file mode 100644 index fab9ac0e4..000000000 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/30-bluez-monitor.lua +++ /dev/null @@ -1,109 +0,0 @@ --- Bluez monitor config file -- - -bluez_monitor = {} - -bluez_monitor.properties = { - -- Enable mSBC support, disabled by default. Be aware that - -- mSBC is not expected to work on all headset + adapter combinations. - -- This can be overloaded for a specific device and native backend - -- in rules section. - --["bluez5.msbc-support"] = false, - - --["bluez5.sbc-xq-support"] = true, - - -- Enabled headset roles (default: [ hsp_hs hfp_ag ]), this - -- property only applies to native backend. Currently some headsets - -- (Sony WH-1000XM3) are not working with both hsp_ag and hfp_ag - -- enabled, disable either hsp_ag or hfp_ag to work around it. - -- - -- Supported headset roles: hsp_hs (HSP Headset), - -- hsp_ag (HSP Audio Gateway), - -- hfp_hf (HFP Hands-Free), - -- hfp_ag (HFP Audio Gateway) - ["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]", - - -- Enabled A2DP codecs (default: all). - --["bluez5.codecs"] = "[ sbc aac ldac aptx aptx_hd ]", - - -- Properties for the A2DP codec configuration - --["bluez5.default.rate"] = 48000, - --["bluez5.default.channels"] = 2, -} - -bluez_monitor.rules = { - -- An array of matches/actions to evaluate. - { - -- Rules for matching a device or node. It is an array of - -- properties that all need to match the regexp. If any of the - -- matches work, the actions are executed for the object. - matches = { - { - -- This matches all cards. - { "device.name", "matches", "bluez_card.*" }, - }, - }, - -- Apply properties on the matched object. - apply_properties = { - -- Auto-connect device profiles on start up or when only partial - -- profiles have connected. Disabled by default if the property - -- is not specified. - --["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink hfp_ag hsp_ag a2dp_source ]", - ["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink ]", - - -- Overload mSBC support for native backend and a specific device. - --["bluez5.msbc-support"] = false, - - -- Hardware volume control (default: [ hfp_ag hsp_ag a2dp_source ]) - --["bluez5.hw-volume"] = "[ hfp_hf hsp_hs a2dp_sink hfp_ag hsp_ag a2dp_source ]", - - -- LDAC encoding quality - -- Available values: auto (Adaptive Bitrate, default) - -- hq (High Quality, 990/909kbps) - -- sq (Standard Quality, 660/606kbps) - -- mq (Mobile use Quality, 330/303kbps) - --["bluez5.a2dp.ldac.quality"] = "auto", - - -- AAC variable bitrate mode - -- Available values: 0 (cbr, default), 1-5 (quality level) - --["bluez5.a2dp.aac.bitratemode"] = 0, - - -- Profile connected first - -- Available values: a2dp-sink (default), headset-head-unit - --["device.profile"] = "a2dp-sink", - }, - }, - { - -- Make output hsp/hfp stream nodes go through the Communication endpoint - -- Unfortunately we cannot match on "media.class" because this property - -- is not known before the node is created - matches = { - { - { "api.bluez5.profile", "equals", "headset-audio-gateway" }, - { "factory.name", "matches", "*source*" }, - }, - }, - apply_properties = { - ["media.role"] = "Communication", - }, - }, - { - -- Make output a2dp stream nodes go through the Multimedia endpoint - -- Unfortunately we cannot match on "media.class" because this property - -- is not known before the node is created - matches = { - { - { "api.bluez5.profile", "equals", "a2dp-source" }, - }, - }, - apply_properties = { - ["media.role"] = "Multimedia", - }, - }, -} - -function bluez_monitor.enable() - load_monitor("bluez", { - properties = bluez_monitor.properties, - rules = bluez_monitor.rules, - }) -end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/99-load-modules.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/99-load-modules.lua deleted file mode 100644 index 70251aebe..000000000 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/99-load-modules.lua +++ /dev/null @@ -1,27 +0,0 @@ --- Enable local & bluetooth audio devices -alsa_monitor.enable() -bluez_monitor.enable() - --- Load policy -default_policy.enable() - --- Implements storing metadata about objects in RAM -load_module("metadata") - --- Keeps track of the "default" sources and sinks -load_module("default-nodes", { - -- do not store runtime user changes in $HOME - ["use-persistent-storage"] = false, -}) - --- Selects default routes on devices that advertise routes -load_script("default-routes.lua", { - -- do not store runtime user changes in $HOME - ["use-persistent-storage"] = false, -}) - --- Automatically suspends idle nodes after 3 seconds -load_script("suspend-node.lua") - --- Automatically sets device profiles to 'On' -load_module("device-activation") diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/alsa-suspend.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/alsa-suspend.lua new file mode 100644 index 000000000..55edd12cf --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/alsa-suspend.lua @@ -0,0 +1,45 @@ +-- WirePlumber +-- +-- This script mutes all ALSA sinks when the "suspend.playback" metadata +-- key is set to 1; compliments pipewire-ic-ipc and the respective support +-- for handling "suspend.playback" in the policy scripts +-- +-- Copyright © 2021 Collabora Ltd. +-- @author George Kiagiadakis +-- +-- SPDX-License-Identifier: MIT + +mixer_api = Plugin.find("mixer-api") + +nodes_om = ObjectManager { + Interest { type = "node", + Constraint { "media.class", "matches", "Audio/Sink" }, + Constraint { "object.path", "matches", "alsa:pcm:*" }, + }, +} + +metadata_om = ObjectManager { + Interest { type = "metadata", + Constraint { "metadata.name", "=", "default" }, + } +} + +metadata_om:connect("object-added", function (om, metadata) + metadata:connect("changed", function (m, subject, key, t, value) + if key == "suspend.playback" then + local suspended = (value == "1") + + Log.info(string.format("%s ALSA nodes for IC sound", + suspended and "muting" or "unmuting")) + + for n in nodes_om:iterate() do + mixer_api:call("set-volume", n["bound-id"], { + ["mute"] = suspended, + }) + end + end + end) +end) + +nodes_om:activate() +metadata_om:activate() diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.conf b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.conf new file mode 100644 index 000000000..ebd0b6004 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.conf @@ -0,0 +1,74 @@ +# WirePlumber daemon context configuration # + +context.properties = { + ## Properties to configure the PipeWire context and some modules + + application.name = "WirePlumber Bluetooth" + log.level = 2 + wireplumber.script-engine = lua-scripting + wireplumber.export-core = false + + #mem.mlock-all = false + #support.dbus = true +} + +context.spa-libs = { + # = + # + # Used to find spa factory names. It maps an spa factory name + # regular expression to a library name that should contain + # that factory. + # + api.bluez5.* = bluez5/libspa-bluez5 + audio.convert.* = audioconvert/libspa-audioconvert + support.* = support/libspa-support +} + +context.modules = [ + #{ name = + # [ args = { = ... } ] + # [ flags = [ [ ifexists ] [ nofail ] ] + #} + # + # PipeWire modules to load. + # If ifexists is given, the module is ignored when it is not found. + # If nofail is given, module initialization failures are ignored. + # + + # The native communication protocol. + { name = libpipewire-module-protocol-native } + + # Allows creating nodes that run in the context of the + # client. Is used by all clients that want to provide + # data to PipeWire. + { name = libpipewire-module-client-node } + + # Allows creating devices that run in the context of the + # client. Is used by the session manager. + { name = libpipewire-module-client-device } + + # Makes a factory for wrapping nodes in an adapter with a + # converter and resampler. + { name = libpipewire-module-adapter } + + # Allows applications to create metadata objects. It creates + # a factory for Metadata objects. + { name = libpipewire-module-metadata } + + # Provides factories to make session manager objects. + { name = libpipewire-module-session-manager } +] + +wireplumber.components = [ + #{ name = , type = } + # + # WirePlumber components to load + # + + # The lua scripting engine + { name = libwireplumber-module-lua-scripting, type = module } + + # The lua configuration file + # Other components are loaded from there + { name = bluetooth.lua, type = config/lua } +] diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.lua.d/30-bluez-monitor.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.lua.d/30-bluez-monitor.lua new file mode 100644 index 000000000..36fe749bb --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/bluetooth.lua.d/30-bluez-monitor.lua @@ -0,0 +1,107 @@ +-- Bluez monitor config file -- + +bluez_monitor = {} + +bluez_monitor.properties = { + -- Enable mSBC support, disabled by default. Be aware that + -- mSBC is not expected to work on all headset + adapter combinations. + -- This can be overloaded for a specific device and native backend + -- in rules section. + --["bluez5.msbc-support"] = false, + + --["bluez5.sbc-xq-support"] = true, + + -- Enabled headset roles (default: [ hsp_hs hfp_ag ]), this + -- property only applies to native backend. Currently some headsets + -- (Sony WH-1000XM3) are not working with both hsp_ag and hfp_ag + -- enabled, disable either hsp_ag or hfp_ag to work around it. + -- + -- Supported headset roles: hsp_hs (HSP Headset), + -- hsp_ag (HSP Audio Gateway), + -- hfp_hf (HFP Hands-Free), + -- hfp_ag (HFP Audio Gateway) + ["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]", + + -- Enabled A2DP codecs (default: all). + --["bluez5.codecs"] = "[ sbc aac ldac aptx aptx_hd ]", + + -- Properties for the A2DP codec configuration + --["bluez5.default.rate"] = 48000, + --["bluez5.default.channels"] = 2, +} + +bluez_monitor.rules = { + -- An array of matches/actions to evaluate. + { + -- Rules for matching a device or node. It is an array of + -- properties that all need to match the regexp. If any of the + -- matches work, the actions are executed for the object. + matches = { + { + -- This matches all cards. + { "device.name", "matches", "bluez_card.*" }, + }, + }, + -- Apply properties on the matched object. + apply_properties = { + -- Auto-connect device profiles on start up or when only partial + -- profiles have connected. Disabled by default if the property + -- is not specified. + --["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink hfp_ag hsp_ag a2dp_source ]", + ["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink ]", + + -- Overload mSBC support for native backend and a specific device. + --["bluez5.msbc-support"] = false, + + -- Hardware volume control (default: [ hfp_ag hsp_ag a2dp_source ]) + --["bluez5.hw-volume"] = "[ hfp_hf hsp_hs a2dp_sink hfp_ag hsp_ag a2dp_source ]", + + -- LDAC encoding quality + -- Available values: auto (Adaptive Bitrate, default) + -- hq (High Quality, 990/909kbps) + -- sq (Standard Quality, 660/606kbps) + -- mq (Mobile use Quality, 330/303kbps) + --["bluez5.a2dp.ldac.quality"] = "auto", + + -- AAC variable bitrate mode + -- Available values: 0 (cbr, default), 1-5 (quality level) + --["bluez5.a2dp.aac.bitratemode"] = 0, + + -- Profile connected first + -- Available values: a2dp-sink (default), headset-head-unit + --["device.profile"] = "a2dp-sink", + }, + }, + { + -- Make output hsp/hfp stream nodes go through the Communication endpoint + -- Unfortunately we cannot match on "media.class" because this property + -- is not known before the node is created + matches = { + { + { "api.bluez5.profile", "equals", "headset-audio-gateway" }, + { "factory.name", "matches", "*source*" }, + }, + }, + apply_properties = { + ["media.role"] = "Communication", + }, + }, + { + -- Make output a2dp stream nodes go through the Multimedia endpoint + -- Unfortunately we cannot match on "media.class" because this property + -- is not known before the node is created + matches = { + { + { "api.bluez5.profile", "equals", "a2dp-source" }, + }, + }, + apply_properties = { + ["media.role"] = "Multimedia", + }, + }, +} + +load_monitor("bluez", { + properties = bluez_monitor.properties, + rules = bluez_monitor.rules, +}) diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-alsa-monitor.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-alsa-monitor.lua new file mode 100644 index 000000000..75a169675 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-alsa-monitor.lua @@ -0,0 +1,151 @@ +-- ALSA monitor config file -- + +alsa_monitor = {} + +alsa_monitor.properties = { + ["alsa.jack-device"] = false, + ["alsa.reserve"] = false, +} + +alsa_monitor.rules = { + -- disable ACP (PulseAudio-like profiles) + { + matches = { + { + { "device.name", "matches", "alsa_card.*" }, + }, + }, + apply_properties = { + ["api.alsa.use-acp"] = false, + }, + }, + + -- + -- Bump priority of well-known output devices + -- Higher priority means it gets selected as the default if it's present + -- + + -- USB card + { + matches = { + { + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.card.driver", "=", "USB-Audio" }, + }, + }, + apply_properties = { + ["priority.driver"] = 1300, + ["priority.session"] = 1300, + } + }, + + -- fiberdyne amp + { + matches = { + { + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.card.id", "=", "ep016ch" }, + }, + }, + apply_properties = { + ["priority.driver"] = 1200, + ["priority.session"] = 1200, + } + }, + + -- well-known internal devices + { + matches = { + { + -- ak4613 + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.card.id", "=", "ak4613" }, + { "api.alsa.pcm.device", "=", "0" }, + }, + { + -- imx8mq + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.card.id", "=", "wm8524audio" }, + }, + { + -- rcarsound + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.card.id", "=", "rcarsound" }, + { "api.alsa.pcm.device", "=", "0" }, + }, + { + -- rpi3 + { "node.name", "matches", "alsa_output.*" }, + { "api.alsa.pcm.name", "=", "bcm2835 ALSA" }, + }, + }, + apply_properties = { + ["priority.driver"] = 1100, + ["priority.session"] = 1100, + } + }, + + -- + -- Same for input devices + -- + + -- USB card + { + matches = { + { + { "node.name", "matches", "alsa_input.*" }, + { "api.alsa.card.driver", "=", "USB-Audio" }, + }, + }, + apply_properties = { + ["priority.driver"] = 2300, + ["priority.session"] = 2300, + } + }, + + -- microchip mic + { + matches = { + { + { "node.name", "matches", "alsa_input.*" }, + { "api.alsa.card.id", "=", "ep811ch" }, + }, + }, + apply_properties = { + ["priority.driver"] = 2200, + ["priority.session"] = 2200, + } + }, + + -- well-known internal devices + { + matches = { + { + -- ak4613 + { "node.name", "matches", "alsa_input.*" }, + { "api.alsa.card.id", "=", "ak4613" }, + }, + { + -- imx8mq + { "node.name", "matches", "alsa_input.*" }, + { "api.alsa.card.id", "=", "wm8524audio" }, + }, + { + -- rcarsound + { "node.name", "matches", "alsa_input.*" }, + { "api.alsa.card.id", "=", "rcarsound" }, + }, + }, + apply_properties = { + ["priority.driver"] = 2100, + ["priority.session"] = 2100, + } + }, +} + +function alsa_monitor.enable() + load_monitor("alsa", { + properties = alsa_monitor.properties, + rules = alsa_monitor.rules, + }) +end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-v4l2-monitor.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-v4l2-monitor.lua new file mode 100644 index 000000000..a4eb58ac8 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/30-v4l2-monitor.lua @@ -0,0 +1,48 @@ +-- V4L2 monitor config file -- + +v4l2_monitor = {} +v4l2_monitor.properties = {} + +v4l2_monitor.rules = { + -- An array of matches/actions to evaluate. + { + -- Rules for matching a device or node. It is an array of + -- properties that all need to match the regexp. If any of the + -- matches work, the actions are executed for the object. + matches = { + { + -- This matches all cards. + { "device.name", "matches", "v4l2_device.*" }, + }, + }, + -- Apply properties on the matched object. + apply_properties = { + -- ["device.nick"] = "My Device", + }, + }, + { + matches = { + { + -- Matches all sources. + { "node.name", "matches", "v4l2_input.*" }, + }, + { + -- Matches all sinks. + { "node.name", "matches", "v4l2_output.*" }, + }, + }, + apply_properties = { + --["node.nick"] = "My Node", + --["priority.driver"] = 100, + --["priority.session"] = 100, + --["node.pause-on-idle"] = false, + }, + }, +} + +function v4l2_monitor.enable() + load_monitor("v4l2", { + properties = v4l2_monitor.properties, + rules = v4l2_monitor.rules, + }) +end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/40-device-defaults.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/40-device-defaults.lua new file mode 100644 index 000000000..365bab59a --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/40-device-defaults.lua @@ -0,0 +1,26 @@ +device_defaults = {} + +device_defaults.properties = { + -- store preferences to the file system and restore them at startup; + -- when set to false, default nodes and routes are selected based on + -- their priorities and any runtime changes do not persist after restart + ["use-persistent-storage"] = false, +} + +function device_defaults.enable() + -- Selects appropriate default nodes and enables saving and restoring them + load_module("default-nodes", device_defaults.properties) + + -- Selects appropriate default routes ("ports" in pulseaudio terminology) + -- and enables saving and restoring them together with + -- their properties (per-route/port volume levels, channel maps, etc) + load_script("default-routes.lua", device_defaults.properties) + + if device_defaults.properties["use-persistent-storage"] then + -- Enables functionality to save and restore default device profiles + load_module("default-profile") + + -- Save and restore stream-specific properties + load_script("restore-stream.lua") + end +end diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/90-enable-all.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/90-enable-all.lua new file mode 100644 index 000000000..f6d73a3f1 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/host.lua.d/90-enable-all.lua @@ -0,0 +1,20 @@ +-- Provide the "default" pw_metadata, which stores +-- dynamic properties of pipewire objects in RAM +load_module("metadata") + +-- Load devices +alsa_monitor.enable() +--v4l2_monitor.enable() + +-- Track/store/restore user choices about devices +device_defaults.enable() + +-- Automatically suspends idle nodes after 3 seconds +load_script("suspend-node.lua") + +-- Automatically sets device profiles to 'On' +load_module("device-activation") + +-- Mute ALSA sinks when requested by pipewire-ic-ipc +load_module("mixer-api") +load_script("alsa-suspend.lua") diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.conf b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.conf new file mode 100644 index 000000000..42f714849 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.conf @@ -0,0 +1,73 @@ +# WirePlumber daemon context configuration # + +context.properties = { + ## Properties to configure the PipeWire context and some modules + + application.name = "WirePlumber Policy" + log.level = 2 + wireplumber.script-engine = lua-scripting + wireplumber.export-core = false + + #mem.mlock-all = false + #support.dbus = true +} + +context.spa-libs = { + # = + # + # Used to find spa factory names. It maps an spa factory name + # regular expression to a library name that should contain + # that factory. + # + audio.convert.* = audioconvert/libspa-audioconvert + support.* = support/libspa-support +} + +context.modules = [ + #{ name = + # [ args = { = ... } ] + # [ flags = [ [ ifexists ] [ nofail ] ] + #} + # + # PipeWire modules to load. + # If ifexists is given, the module is ignored when it is not found. + # If nofail is given, module initialization failures are ignored. + # + + # The native communication protocol. + { name = libpipewire-module-protocol-native } + + # Allows creating nodes that run in the context of the + # client. Is used by all clients that want to provide + # data to PipeWire. + { name = libpipewire-module-client-node } + + # Allows creating devices that run in the context of the + # client. Is used by the session manager. + { name = libpipewire-module-client-device } + + # Makes a factory for wrapping nodes in an adapter with a + # converter and resampler. + { name = libpipewire-module-adapter } + + # Allows applications to create metadata objects. It creates + # a factory for Metadata objects. + { name = libpipewire-module-metadata } + + # Provides factories to make session manager objects. + { name = libpipewire-module-session-manager } +] + +wireplumber.components = [ + #{ name = , type = } + # + # WirePlumber components to load + # + + # The lua scripting engine + { name = libwireplumber-module-lua-scripting, type = module } + + # The lua configuration file + # Other components are loaded from there + { name = policy.lua, type = config/lua } +] diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.lua.d/10-default-policy.lua b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.lua.d/10-default-policy.lua new file mode 100644 index 000000000..f70f38b1f --- /dev/null +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/policy.lua.d/10-default-policy.lua @@ -0,0 +1,122 @@ +-- Policy config file -- + +policy_config = {} + +policy_config.endpoints = { + -- [endpoint name] = { endpoint properties } + + ["endpoint.multimedia"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Multimedia", + }, + ["endpoint.speech_low"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Speech-Low", + }, + ["endpoint.custom_low"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Custom-Low", + }, + ["endpoint.navigation"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Navigation", + }, + ["endpoint.speech_high"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Speech-High", + }, + ["endpoint.custom_high"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Custom-High", + }, + ["endpoint.communication"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Communication", + }, + ["endpoint.emergency"] = { + ["media.class"] = "Audio/Sink", + ["role"] = "Emergency", + }, +} + +policy_config.policy = { + ["move"] = false, -- moves session items when metadata target.node changes + ["follow"] = true, -- moves session items to the default device when it has changed + + -- how much to lower the volume of lower priority streams when ducking + -- note that this is a linear volume modifier (not cubic as in pulseaudio) + ["duck.level"] = 0.2, + + ["roles"] = { + ["Multimedia"] = { + ["alias"] = { "Movie", "Music", "Game" }, + ["priority"] = 25, + ["action.default"] = "cork", + }, + ["Speech-Low"] = { + ["priority"] = 30, + ["action.default"] = "cork", + ["action.Speech-Low"] = "mix", + }, + ["Custom-Low"] = { + ["priority"] = 35, + ["action.default"] = "cork", + ["action.Custom-Low"] = "mix", + }, + ["Navigation"] = { + ["priority"] = 50, + ["action.default"] = "duck", + ["action.Navigation"] = "mix", + }, + ["Speech-High"] = { + ["priority"] = 60, + ["action.default"] = "cork", + ["action.Speech-High"] = "mix", + }, + ["Custom-High"] = { + ["priority"] = 65, + ["action.default"] = "cork", + ["action.Custom-High"] = "mix", + }, + ["Communication"] = { + ["priority"] = 75, + ["action.default"] = "cork", + ["action.Communication"] = "mix", + }, + ["Emergency"] = { + ["alias"] = { "Alert" }, + ["priority"] = 99, + ["action.default"] = "cork", + ["action.Emergency"] = "mix", + }, + }, +} + +-- Session item factories, building blocks for the session management graph +-- Do not disable these unless you really know what you are doing +load_module("si-node") +load_module("si-audio-adapter") +load_module("si-standard-link") +load_module("si-audio-endpoint") + +-- API to access default nodes from scripts +load_module("default-nodes-api") + +-- API to access mixer controls, needed for volume ducking +load_module("mixer-api") + +-- Create endpoints statically at startup +load_script("static-endpoints.lua", policy_config.endpoints) + +-- Create items for nodes that appear in the graph +load_script("create-item.lua") + +-- Link nodes to each other to make media flow in the graph +load_script("policy-node.lua", policy_config.policy) + +-- Link client nodes with endpoints to make media flow in the graph +load_script("policy-endpoint-client.lua", policy_config.policy) +load_script("policy-endpoint-client-links.lua", policy_config.policy) + +-- Link endpoints with device nodes to make media flow in the graph +load_script("policy-endpoint-device.lua", policy_config.policy) diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/wireplumber.conf b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/wireplumber.conf index 530393e23..680a791f3 100644 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/wireplumber.conf +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/wireplumber.conf @@ -70,5 +70,5 @@ wireplumber.components = [ # The lua configuration file(s) # Other components are loaded from there - { name = config.lua, type = config/lua } + { name = host.lua, type = config/lua } ] diff --git a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl_git.bb b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl_git.bb index 2b77df7f2..839a15fda 100644 --- a/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl_git.bb +++ b/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl_git.bb @@ -6,11 +6,13 @@ SECTION = "multimedia" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "\ + file://bluetooth.lua.d/ \ + file://host.lua.d/ \ + file://policy.lua.d \ file://00-functions.lua \ - file://10-default-policy.lua \ - file://30-alsa-monitor.lua \ - file://30-bluez-monitor.lua \ - file://99-load-modules.lua \ + file://alsa-suspend.lua \ + file://bluetooth.conf \ + file://policy.conf \ file://wireplumber.conf \ file://wireplumber-bluetooth.conf \ " @@ -19,26 +21,51 @@ PACKAGE_ARCH = "${MACHINE_ARCH}" do_configure[noexec] = "1" do_compile[noexec] = "1" do_install:append() { - config_dir="${D}${sysconfdir}/wireplumber/config.lua.d/" + config_dir="${D}${sysconfdir}/wireplumber/" + scripts_dir="${D}${datadir}/wireplumber/scripts/" dbus_config_dir="${D}${sysconfdir}/dbus-1/system.d/" + systemd_dir="${D}${sysconfdir}/systemd/system/pipewire.service.wants/" install -d ${config_dir} install -m 0644 ${WORKDIR}/00-functions.lua ${config_dir} - install -m 0644 ${WORKDIR}/10-default-policy.lua ${config_dir} - install -m 0644 ${WORKDIR}/30-alsa-monitor.lua ${config_dir} - install -m 0644 ${WORKDIR}/30-bluez-monitor.lua ${config_dir} - install -m 0644 ${WORKDIR}/99-load-modules.lua ${config_dir} - install -m 0644 ${WORKDIR}/wireplumber.conf ${D}${sysconfdir}/wireplumber/ + # config of the main (host) instance + install -d ${config_dir}/host.lua.d/ + ln -s ../00-functions.lua ${config_dir}/host.lua.d/00-functions.lua + install -m 0644 ${WORKDIR}/host.lua.d/*.lua ${config_dir}/host.lua.d/ + install -m 0644 ${WORKDIR}/wireplumber.conf ${config_dir} + # config of the policy instance + install -d ${config_dir}/policy.lua.d/ + ln -s ../00-functions.lua ${config_dir}/policy.lua.d/00-functions.lua + install -m 0644 ${WORKDIR}/policy.lua.d/*.lua ${config_dir}/policy.lua.d/ + install -m 0644 ${WORKDIR}/policy.conf ${config_dir} + + # config of the bluetooth instance + install -d ${config_dir}/bluetooth.lua.d/ + ln -s ../00-functions.lua ${config_dir}/bluetooth.lua.d/00-functions.lua + install -m 0644 ${WORKDIR}/bluetooth.lua.d/*.lua ${config_dir}/bluetooth.lua.d/ + install -m 0644 ${WORKDIR}/bluetooth.conf ${config_dir} + + # install the alsa-suspend script, loaded by the main instance + install -d ${scripts_dir} + install -m 0644 ${WORKDIR}/alsa-suspend.lua ${scripts_dir} + + # install dbus daemon configuration install -d ${dbus_config_dir} install -m 0644 ${WORKDIR}/wireplumber-bluetooth.conf ${dbus_config_dir} + + # enable additional systemd services + install -d ${systemd_dir} + ln -s ${systemd_system_unitdir}/wireplumber@.service ${systemd_dir}/wireplumber@policy.service + ln -s ${systemd_system_unitdir}/wireplumber@.service ${systemd_dir}/wireplumber@bluetooth.service } FILES:${PN} += "\ - ${sysconfdir}/wireplumber/* \ + ${sysconfdir}/* \ + ${datadir}/wireplumber/* \ " CONFFILES:${PN} += "\ - ${sysconfdir}/wireplumber/* \ + ${sysconfdir}/* \ " RPROVIDES:${PN} += "virtual/wireplumber-config" -- cgit 1.2.3-korg