Commit graph

37 commits

Author SHA1 Message Date
Julian Bouzas
0a86653085 autoswitch-bluetooth-profile: Use event source object managers
This patch removes the manually created object managers in the BT profile
autoswitch logic, and instead uses the object managers from the event source,
simplifying the logic a bit.
2024-07-12 10:18:12 -04:00
George Kiagiadakis
47ec81408e scripts/device: avoid crashing if the device.name is not set
This should never happen, but there are odd cases with broken
configuration where such a device may appear and the least we can do
is not crash, at least not when the device.name is only used for
debug messages. In state-profile and other places where the name
really matters, we actually have checks in place.

Fixes: #674
2024-06-17 09:13:16 +03:00
Julian Bouzas
2353a0991b autoswitch-bluetooth-profile: Always destroy the restore timeout source before switching
We always have to destroy the restore timeout source when we want to switch to
HSP/HFP profile, even if the device is already set to HSP/HFP or has already an
input route. Apart from this, we also want to make sure there is no pending
timeout source when we are creating a new one. This should avoid an infinite
loop about switching BT profiles when capture nodes are created and destroyed
quickly.
2024-06-12 16:27:19 -04:00
Julian Bouzas
eb707096f7 scripts: Fix autoswitch BT profile when using filters
If a source filter is used, the BT profile autoswitch does not work because
WirePlumber thinks there is always a client capturing audio from it. This patch
fixes the issue by recursively walking through the source filters that are
linked to the BT loopback source until a stream is found. If a stream is found
at the end of the chain, then it switches to HSP/HFP profile, if the stream is
not found, the profile stays to A2DP.
2024-06-06 17:05:18 -04:00
George Kiagiadakis
e3e8c9cdcb device/state-profile: do not restore unavailable profiles from the state file
Fixes: #613
2024-05-31 12:14:19 +03:00
Pauli Virtanen
42370f0547 scripts: fix event:get_data() usage in apply-profile
event:set_data() coerces Lua tables to properties, so that keys and
values become strings.  Take into account that profile.index is a string
due to this.

Fixes WP setting the profile, even though it is already the active one.
2024-04-27 17:48:16 +03:00
Pauli Virtanen
61d1398f5b autoswitch-bluetooth-profile: never use headset profile without input
Autoswitch should make sure the saved headset profile always has an
input route.  Check this on loading/saving it, otherwise reselect it.

Headset mode profile without mic used to make some sense when it wasn't
using the loopback node (ie.  easy way to disable it), but now with the
loopback node this doesn't make sense any more and it's confusing if it
occurs, so we shouldn't allow it.
2024-03-23 14:02:21 +02:00
Julian Bouzas
5e19722491 scripts: fix regression in state-routes.lua when marking routes as 'active'
Like WirePlumber 0.4.17, we need to mark the current routes as 'active' if they
were previously not active as soon as we detect it. This avoids a possible
infinite loop that restores the routes and saves them constantly, which happens
when the device's Route param has changed more than once before the event
'select-routes' is triggered.
2024-03-11 09:47:31 +00:00
George Kiagiadakis
655a24acf0 scripts: remove cutils.evaluateRulesApplyProperties()
Cache the rules in a global variable in each script, as JSON,
and use JsonUtils directly to evaluate them. This will allow us to
close the WpConf in the future after loading the scripts.

Also change the order of the return values of the match_rules_apply_properties
function to be able to easily ignore the number of changed values,
which is useless in most cases.
2024-03-04 16:33:14 +00:00
Julian Bouzas
8935837cda scripts: remove settings-manager and use the Settings API
The settings manager is not needed anymore because the WpSettings Lua API
returns now the default value from the schema if the setting is not found.
2024-02-28 10:20:31 -05:00
Ashok Sidipotu
89b9218031 device-profile-hooks: add a hook to prioritize the profiles 2024-02-12 13:15:02 +05:30
Ashok Sidipotu
112a45a230 device-profile-hooks: move the selected profile check
move the check to the beginning of the hook.
2024-02-12 13:15:02 +05:30
Julian Bouzas
874a432c69 autoswitch-bluetooth-profile: remove applications array and use loopback filter
This patch improves the bluetooth profile autoswitch so that it works with any
application that wants to capture from a bluetooth device. To do so, a loopback
source filter is created per connected bluetooth device. If an application wants
to capture audio from such loopback source filter, the profile in the associated
bluetooth device is changed to HSP/HFP. If there isn't any application connected
to the loopback source filter, the profile switches back to A2DP.
2024-01-22 10:15:16 +00:00
George Kiagiadakis
c5c5317599 state-routes: use the correct device id when restoring route properties
Fixes: #551
2024-01-08 12:28:21 +02:00
George Kiagiadakis
0b0595a156 apply-routes.lua: rename variable to make the code easier to understand 2024-01-08 12:28:21 +02:00
George Kiagiadakis
a7d0dacd12 state-routes: fix restoring volumes when a Route is changed manually
When a manual change is applied, the store-or-restore-routes is the only
hook that gets executed for this event. In order to be able to test if a
route was changed, we need to reset all of them to 'active = false',
record the previous value of 'active' and test their difference.

Testing only the 'active' variable (and discarding 'prev_active') sounds
tempting here, but if a route is changed back and forth (from A to B
and back to A), there is nothing to reset the 'active' variable of A
when it gets deactivated and it will appear as previously active on
the second switch.

Related to: #551
2024-01-08 12:21:27 +02:00
George Kiagiadakis
eb2d6efcd4 state: add save_after_timeout() method to replace all custom timeout code
This was a common pattern that we had in many places, so it makes sense
to consolidate it.
2024-01-04 16:38:33 +02:00
George Kiagiadakis
38b6eec456 state-routes: use json to store info in the state file 2024-01-04 10:27:02 +02:00
George Kiagiadakis
7dfc346a7b script docs: rewrite all csv-table to list-table for better source readability 2023-12-23 11:32:56 +02:00
George Kiagiadakis
600adf003b scripts: tidy up device-related settings
* rename settings to make more sense
* split out monitor settings into a separate category
* add setting for restoring the default nodes in the node category
2023-12-08 12:06:28 +02:00
George Kiagiadakis
2f071a67be scripts: rename all foo-config libs to settings-foo
And also use the term 'settings' everywhere instead of 'config' to refer
to the options managed by the WpSettings architecture
2023-11-15 15:44:01 +02:00
Stefan Ursella
762ebad4c8 scripts: skip profile iteration when device.profile found
Do not continue iteration over all other profiles when
we found the profile set in the 'device.profile' property.
In other case we would overwrite this profile when
we find a best_profile.
2023-11-13 12:13:01 +01:00
George Kiagiadakis
eb6f569be8 Merge branch 'master' into next 2023-10-24 11:09:52 +03:00
t123yh
b6c1fdb2e1 scripts: Fix typo in autoswitch-bluetooth-profile.lua 2023-10-23 09:50:38 +00:00
Julian Bouzas
388acb6ff3 scripts: Fix bluetooth profile autoswitch
This patch updates the deprecated policy-bluetooth.lua script so that it works
with the current version. The script has been moved into the device sub-folder,
and renamed to autoswitch-blueooth-profile.lua. The settings-manager is also
used for the configuration, and the actual configuration has been moved from
linkind.conf to bluetooth.conf.
2023-10-19 11:24:42 -04:00
George Kiagiadakis
2f89c64b7f docs: add documentation on device, default-nodes and linking scripts 2023-09-29 16:14:08 +03:00
Stefan Ursella
407c2f04de scripts: run find-best-profile hook before running apply-profile hook 2023-07-17 17:33:40 +02:00
Duncan Overbruck
760ce55de1
device/state-routes.lua: fix finding stored routes
This wrongly stored the matched route in a new variable instead of the
locally declared variable it supposed to use.
2023-06-23 13:13:44 +02:00
Duncan Overbruck
7eb6ff3b9e
device/state-routes.lua: fix check for empty selected-routes
This hook and previous hooks hooks default to setting the
selected-routes event property to an empty table, not nil.
2023-06-23 13:13:44 +02:00
Ashok Sidipotu
b0460d8050 src/scripts: add few comments 2023-06-22 16:28:56 +05:30
George Kiagiadakis
982bebe5aa scripts: use log topics 2023-05-19 20:12:08 +03:00
Ashok Sidipotu
82c8269381 prepare-link.lua: fix unassigned variables 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
81c468cf23 find-best-routes.lua: add a null check while selecting routes 2023-04-17 07:48:18 -04:00
George Kiagiadakis
258d9f32e1 scripts: rename all hooks to follow a nicer naming scheme
Use the directory name and file name to construct the hook's name,
like a path. This way, when you see a hook name, it is clear where
to find that hook in the source code.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
85858c8a84 state-profile: dynamically respond to config.use-persistent-storage changes 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b5d8a7982f scripts: split/refactor the policy-device-routes script into smaller hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
f99c3005f2 scripts: rewrite policy-device-profile and m-default-profile into a set of hooks
... excluding the persistent profile functionality for now (I am not convinced)
2023-04-17 07:48:18 -04:00