Commit graph

112 commits

Author SHA1 Message Date
Pauli Virtanen
5fa137cc0d meson.build: make spa-json-dump available for subprojects
Add override that provides host binary for subprojects to use.

Also fix cross-compilation to use the host binary.
2025-07-23 12:19:21 +00:00
Wim Taymans
7ce9b0daec spa-json-dump: fix compilation 2025-06-17 18:08:36 +02:00
Wim Taymans
b67226fa0c spa-json-dump: add -i and -s options
Add -i option to change the indentation
Add -s option to generate simplified SPA JSON
2025-06-17 17:27:10 +02:00
Wim Taymans
fa8208eeef tools: make some things configurable
Things like indentation and simplified spa layout are behind an if 0
but wil some option parsing this could be improved.
2025-06-12 17:16:27 +02:00
Carlos Rafael Giani
2fe77c47e1 spa: tools: spa-inspect: Output more detailed dlopen and dlsym errors
When writing a custom SPA plugin, it is very useful to get more detailed
errors related to libdl. One common error is that a symbol is not present
because a related library was not properly linked into the plugin. With
this change, the error will tell the user about the exact missing symbol.
2025-05-28 17:19:57 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +02:00
Wim Taymans
feccb882b6 spa: add spa_json_begin
That combines spa_json_init() and spa_json_next, a common thing to do.
2024-09-16 09:50:31 +02:00
Wim Taymans
a9fdc6a408 spa: improve JSON error reporting in spa-json-dump 2024-03-27 15:57:39 +01:00
Pauli Virtanen
04c5d3958b test: add tests validating all json conf files 2024-03-27 15:53:09 +01:00
Wim Taymans
d4581755e6 spa: Improve JSON error reporting
Add struct spa_error_location that holds information about some parsing
context such as the line and column number, error and line fragment
with the error.

Make spa_json_get_error() fill in the spa_error_location instead. Add
some error codes to the error state and use this to add a parsing reason
to the location.

Add a debug function to log the error location in a nice way. Also
add a FILE based debug context to log to any FILE.

Replace pw_properties_check_string() with
pw_properties_update_string_checked() and add
pw_properties_new_string_checked(). The check string behaviour can still
be done by setting props to NULL but the main purpose is to be able to
avoid parsing the json file twice in the future.

When using the old pw_properties_update_string(), log a warning to the
log when we fail to parse the complete string.

Use the new checked functions and the debug functions to report about
parsing errors in the tools and conf parsing.

This gives errors like:

```
> pw-loopback --playback-props '{ foo =  [ f : g ] }'
error: syntax error in --playback-props: Invalid array separator
line:      1 | { foo =  [ f : g ] }
col:      14 |              ^
```
2024-03-27 15:42:29 +01:00
Pauli Virtanen
7f5e0f0425 spa: spa-json-dump: read also from stdin, and report syntax errors
Support reading from stdin and report syntax errors.

Also don't do extra spa_json_enter when inserting a dummy "{" when
parsing files with top-level keys.  In this case the tokenizer is
already "entered" after spa_json_init, and will give parse error when we
are not inserting the closing "}" for the dummy "{".
2024-03-25 21:42:26 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Barnabás Pőcze
1a21da9898 spa: tools: spa-inspect: clear and free handles
Call the handle's `clear()` method after it has been
inspected, and free the allocated storage for the handle.
2022-06-16 16:59:40 +02:00
Wim Taymans
c46113faa3 json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
Barnabás Pőcze
2b110af366 treewide: meson.build: use dependency variable for SPA
Use `spa_dep` everywhere instead of `spa_inc`,
and remove `spa_inc` altogether.
2021-12-28 18:34:06 +01:00
Wim Taymans
016f02616b json: don't escape / 2021-06-24 16:18:59 +02:00
Wim Taymans
826f52344f spa: properly re-encode the keys and string values
Instead of pasting quotes around them.
2021-06-10 16:32:16 +02:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Andrea Gelmini
47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Wim Taymans
3c9996aa78 spa: add tool to dump spa json file to plain json 2021-02-13 20:17:27 +01:00
Wim Taymans
abe73c9146 meson: use global b_pie to build PIE executables 2021-01-14 16:29:32 +01:00
Wim Taymans
b8583799ff spa-monitor: fix the support array 2021-01-14 15:01:12 +01:00
Wim Taymans
c9354c238f Add -fPIE to installed executables
Fixes #570
2021-01-13 19:40:37 +01:00
Wim Taymans
8669fd03a6 initialize variables better 2020-05-20 15:24:25 +02:00
Wim Taymans
4cb2d58e89 factory: do more version checks
So that we don't accidentally load an old plugin.
2020-04-22 18:10:26 +02:00
Wim Taymans
539be881ba plugin: increment version and avoid inspecting old versions
There are incompatible version 0 plugins around (the compat ones)
that crash spa-inspect. Increment the version number to avoid this.
2020-04-22 17:52:54 +02:00
Wim Taymans
f391353c7f Make interface types a string
This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
2019-12-19 13:36:04 +01:00
Wim Taymans
ac24743b2e the epoll shim should only be used by the system library.
All other places should use the system library to get the right
fds.
2019-11-19 15:16:18 +01:00
Gleb Popov
fd937fa378 On FreeBSD, add dependency on epoll-shim library.
FreeBSD doesn't provide timerfd and eventfd functions. These are implemented in
3rd party library called epoll-shim. Link targets requiring these functions to
this library.
2019-11-19 13:41:40 +01:00
Wim Taymans
9ffec214b8 fix includes 2019-10-25 15:01:02 +02:00
Wim Taymans
6e0ffb0c47 flags: change flag macros
SPA_FLAG_CHECK -> SPA_FLAG_IS_SET
SPA_FLAG_UNSET -> SPA_FLAG_CLEAR
Add SPA_FLAG_UPDATE
2019-10-02 18:00:42 +02:00
Wim Taymans
6756a3c8fc monitor: remove monitor API and use device
Remove the monitor API, we can use the device API for it. Make sure
we support creating devices (like alsa) from another device (udev).

Use new object.id to store the object id in the object properties. Use
the port.id/node.id etc to make relations to other objects.
2019-09-20 13:04:14 +02:00
Wim Taymans
9934e62fe4 don't use error() 2019-06-21 16:14:36 +02:00
Wim Taymans
6720ded529 names: add standard factory name definitions
Define a set of standard factory names and document what they
contain. This makes it possible to change the implementation by
mapping the factory-name to a different shared library.
2019-06-21 13:31:34 +02:00
Wim Taymans
d46c239ab0 some printf fixes 2019-06-07 16:37:08 +02:00
Wim Taymans
86dc0496a5 simply use INTERFACE_Loop for the main-loop 2019-06-06 15:20:43 +02:00
Wim Taymans
d45569ce9e spa-inspect: zero listener to clear callback 2019-05-30 16:59:02 +02:00
Wim Taymans
9785d99821 monitor: Remove monitor event
Remove the monitor event and emit events with structures like we do
for the devices.
2019-05-30 12:51:12 +02:00
Wim Taymans
857b2a0cfb spa: add result type
We need this to know the type of result, especially when serializing.
2019-05-28 13:59:48 +02:00
Wim Taymans
5299677f88 add const to spa_event and spa_command 2019-05-28 13:51:12 +02:00
Wim Taymans
ff946e3d4b interface: add an interface struct
The interface struct has the type,version and methods of the
interface.
Make spa interfaces extend from spa_interface and make a
separate structure for the methods.
Pass a generic void* as the first argument of methods, like
we don in PipeWire.
Bundle the methods + implementation in a versioned inteface
and use that to invoke methods. This way we can do version
checks on the methods.
Make resource and proxy interfaces that we can can call. We
can then make the core interfaces independent on proxy/resource and
hide them in the lower layers.
Add add_listener method to methods of core interfaces, just
like SPA.
2019-05-23 12:59:24 +02:00
Wim Taymans
09c4683ef1 interfaces: make events return void
Events are dispatched with hooks and have no return value.

Make it possible to get the last resource and proxy sender value
for where we need it.
2019-03-01 14:04:05 +01:00
Wim Taymans
0390969228 node: make add_listener method
Make struct spa_node_events for events emited from the main thread
and keep the spa_node_callbacks for the data thread callbacks.

The add_listener method installs the events and it's possible to
install multiple handles. Adding a listener first emits the info
and port_info events when installed, similar to how the PipeWire
proxy bind works.

This removes the need for the spa_pending_queue and makes it easier
to implement the _sync versions.

Add some helpers to make it easier for plugins to emit all the info
to new listeners.

Use the listeners for devices as well.
2019-03-01 12:00:42 +01:00
Wim Taymans
499dd3ff22 node: add port and node params
Add a new struct spa_param_info that lists the available params on
a node/port and if they are readable/writable/updated. We can use
this to replace and improve the PARAM_List and also to notify
property change and updates.

Update elements and code to deal with this new param stuff. Add
port and node info to most elements and signal changes.

Use async enum_params in -inspect and use the param info to know
which ones to enumerate.

Use the port info to know what parameters to update in the
remote-node.
2019-02-27 16:43:01 +01:00
Wim Taymans
d2c18c7b1a Improve async handling
Don't use special callback in node to receive the results. Instead,
use a generic result callback to receive the result. This makes things
a bit more symetric and generic again because then you can choose how
to match the result to the request and you have a generic way to handle
both the sync and async case. We can then also remove the wait method.
This also makes the remote interface and spa interface to objects very
similar.

Make a helper object to receive and dispatch results. Use this in the
helper for enum_params.

Make device use the same result callbacks.
2019-02-25 12:29:57 +01:00
Wim Taymans
7b12212eeb node: improve async handling
Remove the done and error callbacks. The error callback is in an
error message. The done callback is replace with spa_pending.

Make enum_params take a callback and data for the results. This allows
us to push the results one after another to the app and avoids ownership
issues of the passed data. We can then extend this to handle the async
case by doing a _wait call with a spa_pending+callback+data that will
be called when the _enum_params returns and async result.
Add a sync method.

All methods can now return SPA_RESULT_IS_ASYNC return values and you
can use spa_node_wait() to register a callback when they complete
with optional extra parameters. This makes it easier to sync and
handle the reply.

Make helper methods to simulate the sync enum_params behaviour for
sync nodes.

Let the transport generate the sequence number for pw_resource_sync()
and pw_proxy_sync(). That way we don't need to keep track of numbers
ourselves and we can match the reply to the request easily.
2019-02-21 09:40:12 +01:00
Wim Taymans
eea062ee53 interfaces: improve remote API
Add return values to events and method callbacks. This makes it
possible to pass any error or async return value.
Add sync/done/error in both directions so that both proxy and resource
and perform/reply sync and produce errors.
Return a SPA_ASYNC from remote method calls (and events), keep the
sequence number in the connection.
With the core sync/done we can remove the client-node done method and
it's internal sequence number along with the seq number in method calls.
We can also use the method/event async return value to perform a sync
with as the unique sequence number for this method.
Add sync method and done/error event to proxy and resource.
2019-02-18 12:31:36 +01:00
Wim Taymans
e9bedae5fa node: add max_ports to node info 2019-02-14 17:40:01 +01:00
Wim Taymans
21957e9e8d node: Add port_info event
Add a port_info event. With this, we get updates to ports pushed to
us, which is more convenient and also allows for better dynamic
add/remove of ports.
We don't need to the PortChanged event anymore
We can remove the get_port_ids/get_n_ports/port_get_info methods.
Update plugins
2019-02-14 17:08:46 +01:00
Wim Taymans
04f1046113 node: pass struct to info callback to make it more extensible 2019-02-13 11:44:58 +01:00