From 56087777f69ba05d174e8c5bd2109791eff20238 Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Thu, 6 Oct 2022 11:49:39 -0400 Subject: [PATCH] bluez.lua: use default rules if none are defined --- src/config/wireplumber.conf.d/bluetooth.conf | 153 ++++++++++--------- src/scripts/monitors/bluez.lua | 9 +- 2 files changed, 91 insertions(+), 71 deletions(-) diff --git a/src/config/wireplumber.conf.d/bluetooth.conf b/src/config/wireplumber.conf.d/bluetooth.conf index a6096867..9fc5c73d 100644 --- a/src/config/wireplumber.conf.d/bluetooth.conf +++ b/src/config/wireplumber.conf.d/bluetooth.conf @@ -83,78 +83,91 @@ wireplumber.settings = { ## The list of monitor rules monitor.bluetooth = [ - { - ## 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 = "~bluez_card.*" - } - ] - actions = { - update-props = { - ## Auto-connect device profiles on start up or when only partial - ## profiles have connected. Disabled by default if the property - ## is not specified. - ## Example: bluez5.auto-connect = "[ hfp_hf hsp_hs a2dp_sink hfp_ag hsp_ag a2dp_source ]" - bluez5.auto-connect = "[ hfp_hf hsp_hs a2dp_sink ]" + ## The following are the default rules applied if none overrides them. + # { + # matches = [ + # { + # device.name = "~bluez_card.*" + # } + # ] + # actions = { + # update-props = { + # bluez5.auto-connect = "[ hfp_hf hsp_hs a2dp_sink ]" + # } + # } + # } - ## 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 ]" + ## This rule example allows changing properties on all Bluetooth devices. + # { + # matches = [ + # { + # ## This matches all cards. + # device.name = "~bluez_card.*" + # } + # ] + # actions = { + # update-props = { + # ## 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 ]" + # + # ## 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" + # + # ## Opus Pro Audio encoding mode: audio, voip, lowdelay + # bluez5.a2dp.opus.pro.application = "audio" + # bluez5.a2dp.opus.pro.bidi.application = "audio" + # } + # } + # } - ## 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" - - ## Opus Pro Audio encoding mode: audio, voip, lowdelay - # bluez5.a2dp.opus.pro.application = "audio" - # bluez5.a2dp.opus.pro.bidi.application = "audio" - } - } - } - { - matches = [ - { - ## Matches all sources. - node.name = "~bluez_input.*" - } - { - ## Matches all sinks. - node.name = "~bluez_output.*" - } - ] - actions = { - update-props = { - # node.nick = "My Node" - # priority.driver = 100 - # priority.session = 100 - # node.pause-on-idle = false - # resample.quality = 4 - # channelmix.normalize = false - # channelmix.mix-lfe = false - # session.suspend-timeout-seconds = 5 - # monitor.channel-volumes = false - - ## Media source role, "input" or "playback" - ## Defaults to "playback", playing stream to speakers - ## Set to "input" to use as an input for apps - # bluez5.media-source-role = "input" - } - } - } + ## This rule example allows changing properties on all Bluetooth nodes. + # { + # matches = [ + # { + # ## Matches all sources. + # node.name = "~bluez_input.*" + # } + # { + # ## Matches all sinks. + # node.name = "~bluez_output.*" + # } + # ] + # actions = { + # update-props = { + # node.nick = "My Node" + # priority.driver = 100 + # priority.session = 100 + # node.pause-on-idle = false + # resample.quality = 4 + # channelmix.normalize = false + # channelmix.mix-lfe = false + # session.suspend-timeout-seconds = 5 + # monitor.channel-volumes = false + # + # ## Media source role, "input" or "playback" + # ## Defaults to "playback", playing stream to speakers + # ## Set to "input" to use as an input for apps + # bluez5.media-source-role = "input" + # } + # } + # } ] ## The list of monitor MIDI rules diff --git a/src/scripts/monitors/bluez.lua b/src/scripts/monitors/bluez.lua index 9b892a07..bee38bc2 100644 --- a/src/scripts/monitors/bluez.lua +++ b/src/scripts/monitors/bluez.lua @@ -32,6 +32,10 @@ nodes_om = ObjectManager { } } +function applyDefaultDeviceProperties (properties) + properties["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink ]" +end + function setOffloadActive(device, value) local pod = Pod.Object { "Spa:Pod:Object:Param:Props", "Props", bluetoothOffloadActive = value @@ -340,7 +344,10 @@ function createDevice(parent, id, type, factory, properties) properties["api.bluez5.id"] = id -- apply properties from bluetooth.conf - cutils.evaluateRulesApplyProperties (properties, "monitor.bluetooth") + local applied = cutils.evaluateRulesApplyProperties (properties, "monitor.bluetooth") + if not applied then + applyDefaultDeviceProperties (properties) + end -- create the device device = SpaDevice(factory, properties)