device-settings: Switch device settings to wpsettings

- move all the device based settings and scripts to JSON config and
  remove config/lua references.
This commit is contained in:
Ashok Sidipotu 2022-05-09 12:48:10 +05:30 committed by Julian Bouzas
parent 3a25bc14d2
commit e180ff2f94
5 changed files with 24 additions and 110 deletions

View file

@ -657,22 +657,23 @@ wp_default_nodes_class_init (WpDefaultNodesClass * klass)
WP_PLUGIN_EXPORT gboolean
wireplumber__module_init (WpCore * core, GVariant * args, GError ** error)
{
guint save_interval_ms = DEFAULT_SAVE_INTERVAL_MS;
gint64 save_interval_ms = DEFAULT_SAVE_INTERVAL_MS;
gboolean use_persistent_storage = DEFAULT_USE_PERSISTENT_STORAGE;
gboolean auto_echo_cancel = DEFAULT_AUTO_ECHO_CANCEL;
const gchar *echo_cancel_sink_name = DEFAULT_ECHO_CANCEL_SINK_NAME;
const gchar *echo_cancel_source_name = DEFAULT_ECHO_CANCEL_SOURCE_NAME;
if (args) {
g_variant_lookup (args, "save-interval-ms", "u", &save_interval_ms);
g_variant_lookup (args, "use-persistent-storage", "b",
&use_persistent_storage);
g_variant_lookup (args, "auto-echo-cancel", "&s", &auto_echo_cancel);
g_variant_lookup (args, "echo-cancel-sink-name", "&s",
&echo_cancel_sink_name);
g_variant_lookup (args, "echo-cancel-source-name", "&s",
&echo_cancel_source_name);
}
g_autoptr (WpSettings) settings = wp_settings_get_instance(core, NULL);
wp_settings_get_int (settings, "device.save-interval-ms",
&save_interval_ms);
wp_settings_get_boolean (settings, "device.use-persistent-storage",
&use_persistent_storage);
wp_settings_get_boolean (settings, "device.auto-echo-cancel",
&auto_echo_cancel);
wp_settings_get_string (settings, "device.echo-cancel-sink-name",
&echo_cancel_sink_name);
wp_settings_get_string (settings, "device.echo-cancel-source-name",
&echo_cancel_source_name);
wp_plugin_register (g_object_new (wp_default_nodes_get_type (),
"name", NAME,
@ -685,3 +686,5 @@ wireplumber__module_init (WpCore * core, GVariant * args, GError ** error)
NULL));
return TRUE;
}

View file

@ -1,63 +0,0 @@
device_defaults = {}
device_defaults.enabled = true
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"] = true,
-- the default volumes to apply to ACP device nodes, in the linear scale
--["default-volume"] = 0.064,
--["default-input-volume"] = 1.0,
-- Whether to auto-switch to echo cancel sink and source nodes or not
["auto-echo-cancel"] = true,
-- Sets the default echo-cancel-sink node name to automatically switch to
["echo-cancel-sink-name"] = "echo-cancel-sink",
-- Sets the default echo-cancel-source node name to automatically switch to
["echo-cancel-source-name"] = "echo-cancel-source",
}
-- Sets persistent device profiles that should never change when wireplumber is
-- running, even if a new profile with higher priority becomes available
device_defaults.persistent_profiles = {
{
matches = {
{
-- Matches all devices
{ "device.name", "matches", "*" },
},
},
profile_names = {
"off",
"pro-audio"
}
},
}
function device_defaults.enable()
if device_defaults.enabled == false then
return
end
-- Selects appropriate default nodes and enables saving and restoring them
load_module("default-nodes", device_defaults.properties)
-- Selects appropriate profile for devices
load_script("policy-device-profile.lua", {
persistent = device_defaults.persistent_profiles
})
-- Selects appropriate device 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("policy-device-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")
end
end

View file

@ -2,9 +2,6 @@
-- dynamic properties of pipewire objects in RAM
load_module("metadata")
-- Track/store/restore user choices about devices
device_defaults.enable()
-- Track/store/restore user choices about streams
stream_defaults.enable()

View file

@ -6,41 +6,19 @@
-- SPDX-License-Identifier: MIT
local self = {}
self.config = ... or {}
self.config.persistent = self.config.persistent or {}
self.active_profiles = {}
self.default_profile_plugin = Plugin.find("default-profile")
-- Preprocess persisten profiles and create Interest objects
for _, p in ipairs(self.config.persistent or {}) do
p.interests = {}
for _, i in ipairs(p.matches) do
local interest_desc = { type = "properties" }
for _, c in ipairs(i) do
c.type = "pw"
table.insert(interest_desc, Constraint(c))
end
local interest = Interest(interest_desc)
table.insert(p.interests, interest)
end
p.matches = nil
end
-- Checks whether a device profile is persistent or not
function isProfilePersistent(device_props, profile_name)
for _, p in ipairs(self.config.persistent or {}) do
if p.profile_names then
for _, interest in ipairs(p.interests) do
if interest:matches(device_props) then
for _, pn in ipairs(p.profile_names) do
if pn == profile_name then
return true
end
end
end
end
local matched, mprops = Settings.apply_rule ("device", device_props)
if (matched and mprops) then
if string.find (mprops["profile_names"], profile_name) then
return true
end
end
return false
end

View file

@ -8,14 +8,13 @@
--
-- SPDX-License-Identifier: MIT
local config = ... or {}
-- whether to store state on the file system
use_persistent_storage = config["use-persistent-storage"] or false
use_persistent_storage =
Settings.get_boolean ("device.use-persistent-storage") or false
-- the default volume to apply
default_volume = tonumber(config["default-volume"] or 0.4^3)
default_input_volume = tonumber(config["default-input-volume"] or 1.0)
default_volume = tonumber (Settings.get_float ("device.default-volume") or 0.4^3)
default_input_volume = tonumber (Settings.get_float ("default-input-volume") or 1.0)
-- table of device info
dev_infos = {}