Commit graph

665 commits

Author SHA1 Message Date
George Kiagiadakis
4736d56557 log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.

Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.

Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.

Messages coming from GLib are checked inside the handler.

An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 20:42:28 +03:00
George Kiagiadakis
e908b93f3b log: describe the syslog priority numbers for code clarity 2023-05-16 16:46:43 +03:00
George Kiagiadakis
2e2ccd5934 component-loader: update documentation 2023-04-25 16:06:32 +03:00
George Kiagiadakis
67f1eb585f log: implement different debug level per topic, like in pipewire 2023-04-25 08:50:13 +03:00
George Kiagiadakis
0fa484ac55 log: map spa ERROR and WARN to GLib's CRITICAL and WARNING respectively
Previously we were mapping SPA ERROR to GLib WARNING and
SPA WARN to GLib MESSAGE, which has been causing some confusion.

After some careful consideration, it makes sense to change that and
leave the GLib MESSAGE level as something to be avoided. With that
change, WIREPLUMBER_DEBUG=M will still enable the MESSAGE level,
but WIREPLUMBER_DEBUG=2 will only enable the WARN level and it will
take WIREPLUMBER_DEBUG=3 to enable both the INFO and MESSAGE levels.
2023-04-25 08:50:13 +03:00
George Kiagiadakis
e55e8bb447 object-manager: set self->installed=TRUE before emiting the signal
This avoids recursing into the same signal, in rare cases where a
new object is registered from within the signal handler
2023-04-17 07:48:18 -04:00
George Kiagiadakis
903fab9c3c core: return true from _is_connected() only after receiving the info structure 2023-04-17 07:48:18 -04:00
Julian Bouzas
310232b810 meson: install scripts in /usr/share/wireplumber
Since the wireplumber configuration has been moved to /usr/share/pipewire, it
does not makes sense to have a different path for the WIREPLUMBER_CONFIG_DIR
environment variable. Therefore, the WIREPLUMBER_CONFIG_DIR environment variable
has been changed to just be an alias of PIPEWIRE_CONFIG_DIR. Finally, Lua
scripts are now installed under /usr/share/wireplumber/scripts instead of
/usr/share/pipewire/scripts as they are a wireplumber feature only.
2023-04-17 07:48:18 -04:00
Torge Matthies
ab6a3393e6 lib/wp: Fix lookup_dirs with WP_LOOKUP_DIR_ENV_DATA or WP_LOOKUP_DIR_ENV_TEST_SRCDIR
Fixes: aa2f7e9f308f ("lib/wp: add a new search folder to locate the Lua Test scripts")
2023-04-17 07:48:18 -04:00
Julian Bouzas
c61d1e4245 component-loader: make wp_core_load_component() API asynchronous
This change completely refactors the way components are loaded in wireplumber:
- The module_init() function must return a GObject now. This object is either
a WpPlugin or a WpSiFactory in the current modules.
- When the component loader initializes a module, it automatically registers
the WpPlugin or WpSiFactory with their respective methods. There is no need
to register the WpPlugin or WpSiFactory in the module now.
- The wp_core_load_component() API has been refactored to be asynchronows. This
allows the component loader to automatically activate WpPlugin objects, and
therefore allows the application to directly get the WpPlugin without having
to find it. This simplifies a lot of things.
- The 'ifexists' and 'nofail' component flags now work even if the respective
WpPlugin could not be activated.
- The code that loads components in main.c has also been simplified a lot,
and the option to load dangling components has also been removed.
2023-04-17 07:48:18 -04:00
Julian Bouzas
ad940b6efc component-loader: remove handling of 'pw_module' components 2023-04-17 07:48:18 -04:00
Julian Bouzas
9004362cda lib: remove WpEndpoint and WpSiEndpoint APIs 2023-04-17 07:48:18 -04:00
Julian Bouzas
360e0b3eaf scripts: use WpConf API to get configuration values
This patch also moves nested configuration objects that are not considered
settings from the wireplumber.settings section to its own configuration
section (eg the rules array, the spa plugin properties, etc...). This allows
those objects to be merged with other same sections defined in other files.
2023-04-17 07:48:18 -04:00
Julian Bouzas
cb80cb750b conf: add support to override sections and nested objects/arrays 2023-04-17 07:48:18 -04:00
Julian Bouzas
8f66b16673 lib: add WpConf API 2023-04-17 07:48:18 -04:00
George Kiagiadakis
18377fbf82 transition: don't allow _return_error() to be called recursively 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
fcfae4eeb3 lib/wp: add a new search folder to locate the Lua Test scripts 2023-04-17 07:48:18 -04:00
George Kiagiadakis
ffa85840ac event: move cancelling of events on pw-proxy-destroyed to m-std-event-source
It is really out of place to do this inside WpEvent, as it is not
a generic action. It should only happen for some events.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
3a23fb451a event-dispatcher: refactor to use before/after dependencies on hooks
* Remove entirely the hook priority numbers and use before/after dependencies
* Split the WpEvent code out of WpEventDispatcher
* Add methods on WpEvent to interface with it from the WpEventDispatcher.
  As a bonus, we can now also implement tooling to inspect which hooks would
  in theory run for an event and write tests around that
* Removed some internal debugging facilities and log calls, will redo it later.
* Using spa_list now for the list of hooks, to reduce the number of allocations
  happening in the "hook collection" algorithm
* Switched some internal data to use g_new0 instead of g_slice_new0
* Added g_free to free WpEvent structures... surprisingly, we were leaking them
  before
2023-04-17 07:48:18 -04:00
George Kiagiadakis
5a435fae11 event-dispatcher: expose iterator to iterate over the registered hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b100bdda4a event-hook: remove the exec type property & enumeration
With the latest changes, we can implement the "after-events" type
with external code that pushes a very low priority event that is
the "rescan" event.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
6c3bd9e27d event: add datalist to store arbitrary data on the event 2023-04-17 07:48:18 -04:00
George Kiagiadakis
24db3fe24a event-hook: rewrite the hook priorities enum
Hooks need to have a priority relative to the event they are executed on,
so it does not make much sense to have all kinds of different priorities
based also on the event type and/or the module where they are defined.
Also, it wouldn't be acceptable to have such an enumeration on the public API.
2023-04-17 07:48:18 -04:00
Julian Bouzas
102792527a lib: remove deprecated APIs 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
d9d3a49f5a settings: remove unnecessary log message 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
6f039003ec component-loader: support dangling components
- Dangling components are those not present in the json config files but present
in the wireplumber lookup folders.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
497f30453d lib: event-hook/dispatcher: constness and staticness fixes 2023-04-17 07:48:18 -04:00
Julian Bouzas
1da43c6031 settings: append matches if the rule name matches 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
119b99dc23 event-dispatcher: Add a trace log msg to indicate the events created 2023-04-17 07:48:18 -04:00
Julian Bouzas
5dcb4f0037 config: use the pipewire directory 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
f4382da5ba policy-hooks.lua: An example of user injectible hook 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
68eaede3e4 event-dispatcher: Group after-events-with-event hooks of a session item
after-events-with-event hooks are rendered based on the priority, this means
when a rescan event happens, all the findDefinedTarget hooks(of different
session items) are run first and then all the findDefinedTarget hooks, so on.

This kind of scheduling of hooks was removing the established link between zoom
voice engine and digial mic. Also It is slightly difficult to follow the flow in
the logs.

Instead of arranging the hooks flately based on priority, better scheme to
prioritize them in two layers. First all the hooks for an event or session items
are grouped and with in that group, priority of the hook is honored.

src/scripts/policy-hooks.lua #	modified:   src/scripts/policy-node.lua #
2023-04-17 07:48:18 -04:00
Julian Bouzas
89dcd64003 settings: make sure WpSpaJson is valid after doing wp_iterator_next() 2023-04-17 07:48:18 -04:00
Julian Bouzas
b84261773a settings: make sure WpSpaJson is not NULL when checking its type 2023-04-17 07:48:18 -04:00
Julian Bouzas
d0e27ac82e settings: remove wp_settings_get_all() API
Not used anymore. It is better to use parse_object_safe() Lua API instead.
2023-04-17 07:48:18 -04:00
Julian Bouzas
d28d7d4278 settings: use WpSpaJson instead of raw string in WpSettingsChangedCallback
Avoids users to construct a WpSpaJson every time the callback is triggered.
2023-04-17 07:47:09 -04:00
Julian Bouzas
a77fe0b021 settings: add APIs to parse all types safely 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
a060c6a130 m-default-nodes{-api}: optimize for event-stack
- Sharpen the hooks, so that they are called only when needed.
- Make settings live, apply them when they are changed.
- Remove the state saver after events hook, call it directly.
- Remove the settings bookkeeping as the gobject properties.
- Remove the scheduling of default-nodes-changed signal via core.
2023-04-17 07:47:09 -04:00
Julian Bouzas
63fbcdc82c session-item: remove ID property
Not needed anymore, the object API has a unique ID now.
2023-04-17 07:47:09 -04:00
Julian Bouzas
69c241c4b8 object: add ID property
This is a WirePlumber object unique ID, which comes very useful when identifying
objects in the Lua scripts.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
72536261e9 policy-node.lua: Second round of cleanup.
- WirePlumber Lua now facilitates Lua libraries/modules, utilize this and create
  modules. Add some tests around this functionality.
- Create policy-hooks.lua containing all the hooks to find-target events
- Create policy-utils.lua module and push all the policy utility functions to it.
- Create common-utils.lua module and push the common utility functions to it.
- Remove all the above functionality from policy-node.lua and clean it up.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
3b211d9082 event-dispatcher: Introduce after-events-with-event hook type
after-events hooks are instantiated with rescan event, not with the event which
actually triggered it. after-events-with-event fills this gap.

policy-node clean needed this kind of hooks.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
33ee9984ed Revert "event-dispatcher: after-events hooks to get the trigger event info"
This reverts commit f97e60a331e72e1c1b79075a9498517628e2a349.
2023-04-17 07:47:09 -04:00
Julian Bouzas
51b78e3572 settings: don't show warning if rule or action are empty objects 2023-04-17 07:47:09 -04:00
Julian Bouzas
2f1aece8b6 settings: remove _get_{boolean|int|float|string}() APIs
They is really no needed with the new _get() API and the WpSpaJson API. In C,
users can use 'wp_spa_json_parse_{boolean|int|float|string}()' APIs to parse the
WpSpaJson. In Lua, users can just do 'Settings.get(setting, m):parse()'.
2023-04-17 07:47:09 -04:00
Julian Bouzas
d79c0f45d5 settings: fix code format 2023-04-17 07:47:09 -04:00
Julian Bouzas
271b6931de settings: fix memory leaks 2023-04-17 07:47:09 -04:00
Julian Bouzas
1a98155599 settings: add new _get_all() API 2023-04-17 07:47:09 -04:00
Julian Bouzas
2223cd47d4 settings: use WpSpaJson to parse the settings
We need to use WpSpaJson to parse the values in WpSettings. This is because the
wireplumber configuration is written in JSON, so WpSettings should only hold
JSON values. To fix this, 2 API changes have been done:

- wp_settings_get_int() only accepts gint values, instead of gint64 values. This
is because the WpSpaJson API only parses int values, like spa_json_parse_int().

- wp_settings_get_string() now returns a newly allocated string, this is because
the string needs to be decoded in case it has quotes.
2023-04-17 07:47:09 -04:00
Julian Bouzas
9f2168e022 spa-json: add _add_from_string() and _add_from_stringn() builder APIs 2023-04-17 07:47:09 -04:00