Commit Graph

12409 Commits

Author SHA1 Message Date
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 6bdeeb5881 conf: unmap on errors 2024-03-27 15:50:25 +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
Wim Taymans 96fb63dfa1 test: fix some compiler warnings 2024-03-26 10:23:37 +01:00
Wim Taymans eb1376acc9 conf: log errors for json content errors
Log some errors when we get something we don't expect.
2024-03-26 09:46:07 +01:00
Wim Taymans c954567021 spa-json: return value from spa_json_next()
So that we can check for errors or successful EOF.
2024-03-26 09:42:08 +01:00
Wim Taymans 1078df5212 spa-json: also check for len <= to avoid compiler warning 2024-03-26 09:41:02 +01:00
Pauli Virtanen 5987b0e65e daemon/conf: fix more JSON syntax 2024-03-25 21:42:26 +02:00
Pauli Virtanen 026d55df62 tools: check properties given by user for syntax errors
Check JSON passed in by user for syntax errors before processing it.
2024-03-25 21:42:26 +02:00
Pauli Virtanen 0da9255057 treewide: check for JSON parse errors
Check for JSON parse errors, and log error messages as appropriate.

It's mostly enough to do this where the input is parsed for the first
time, e.g. via pw_properties_new_string, as that already validates the
JSON syntax.
2024-03-25 21:42:26 +02:00
Pauli Virtanen 7ee8df39e8 properties: add pw_properties_check_string for checking parse errors
Add pw_properties_check_string which checks a props JSON string for
parse errors.
2024-03-25 21:42:26 +02: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
Pauli Virtanen 3775e4e624 spa: json: check object key-value pair parity during parsing
Check each object key is associated with value.  Disallow object or
array valued keys.

Add flag tracking whether the parser is at global top-level or not, as
there we may either be in object context or in a single-value context.

Save depth=0 array flag bit in state, so that spa_json_next preserves
its complete state across calls. The higher-depth flag bits can be in
temporary stack as they are not needed across calls.
2024-03-25 20:49:25 +02:00
Pauli Virtanen 921c8b99db spa: json: allow only ascii in bare values
Control characters probably are an error. We also are not validating any
utf8 here, so disallow bare utf8 too --- one likely should use strings
for such content anyway as spaces are not allowed otherwise.
2024-03-25 20:49:25 +02:00
Pauli Virtanen e63e8b8a37 test: add "strict" JSON tests
Adapt an existing JSON parsing test suite from
https://github.com/nst/JSONTestSuite for SPA JSON.
2024-03-25 20:49:25 +02:00
Pauli Virtanen 11e20ef7a8 spa: json: \x7f is allowed unquoted in JSON 2024-03-25 20:49:25 +02:00
Pauli Virtanen f45d89b75b spa: json: propagate parse error in spa_json_container_len
Successful return is always >= 2 since it includes {} or [], so use 0 to
indicate error.

Since there's existing code that doesn't check the return value, it's
better to use 0 for errors as it'll likely to just lead to producing an
empty string if the value is not checked.
2024-03-25 20:49:25 +02:00
Pauli Virtanen 31e5823010 spa: json: more parsing errors & add spa_json_get_error
Disallow = and : as bare items in [] containers, as that likely is
"[ { foo = bar } ]" mistyped as "[ foo = bar ]".

Disallow nesting errors, eg. "[ foo bar" or "[ foo bar }".

Fix handling of ", \ and # in bare strings.

Fix ignoring trailing comments.

Add a fixed-size stack (128 levels) to the tokenizer, so that it can
check these at levels below its depth.

When the tokenizer encounters an error, make it and its parents enter
error state where no further input will be processed. This allows caller
to check for parse errors later as convenient.

The error state can be queried using spa_json_get_error, which also
looks up the error line/column position.
2024-03-25 20:49:25 +02:00
Pauli Virtanen 41d7762f8b spa: json: fix string function usage in spa_json_parse_float/int
spa_json_parse_float/int receive non nul-terminated string, so calling
string functions assuming nul-termination is invalid.

Fix by copying data to a buffer before doing parsing.
2024-03-25 19:22:57 +02:00
Pauli Virtanen 0a70395502 daemon/conf: fix bad JSON syntax 2024-03-25 19:03:13 +02:00
Jonas Holmberg b868ba1f6f module-echo-cancel: Don't call _run() when inactive
Call _activate() in the aec spa plugin before both capture and sink
streams are started and call _deactivate() after both capture and sink
streams are stopped, to make sure _run() is not called while the spa
plugin is inactive.
2024-03-25 14:55:10 +00:00
George Kiagiadakis ddfe3daa22 bluez: print a nicer warning when the bluez service is not available 2024-03-25 14:54:30 +00:00
Samuel Thibault 7ee8192ce9 spa plugins: Include Linux headers on Linux only 2024-03-25 14:53:14 +00:00
Wim Taymans 8da8f90076 conf: add some warnings when keys are invalid and ignored 2024-03-25 14:28:43 +01:00
Wim Taymans dfe18ca996 filter-chain: improve json parsing error reporting
Warn when an invalid key is parsed instead of silently ignoring it.
2024-03-25 14:19:45 +01:00
Wim Taymans ac6011dfa5 module-rtp: save errno before doing pw_log_error
We can't assume the errno value won't be clobbered.
2024-03-25 13:21:42 +01:00
Wim Taymans 4ffd74ef46 module-rtp: handle state change errors better
Make a new function to set the rtp stream in the error state.

When we fail to start the stream, set the error state. Otherwise (like
when we try to use an invalid interface name) the socket create will
fail but the stream will still try to send data to the invalid socket.
2024-03-25 12:22:11 +01:00
Wim Taymans 6e7b893448 client-node: small cleanups 2024-03-22 16:48:29 +01:00
Wim Taymans 4db0811878 alsa: add option to skip the busy check
Makes the card exposed even if some of the pcms are busy.

Fixes #3914
2024-03-22 12:42:48 +01:00
Wim Taymans e2ad924cbb examples: add some more debug to video-play
Debug the latency param, debug the pts vs current time.
2024-03-22 11:31:05 +01:00
Wim Taymans 842ac9e110 v4l2: set latency on port
Use the duration of one frame as the latency.

See #3910
2024-03-22 11:15:10 +01:00
Wim Taymans 58d626fec8 log: init topic_init function
Fixes #3916
2024-03-21 17:28:50 +01:00
Wim Taymans e66bdb016a tools: print ??? when the quantum is unknown 2024-03-21 09:51:12 +01:00
Wim Taymans 832f7f5ba5 spa: a quick fix for compiling with -Werror=shadow
spa_exchange() is used in spa_clear_ptr() and spa_clear_fd() which
already use the _old_value variable. So make it use a slightly different
local variable name to avoid shadow warnings.

Fixes #3915
2024-03-20 10:06:44 +01:00
Wim Taymans a3eca706ce module-ffado: add some more debug
Add some code to dyanmically switch period_size but it seems to keep
crashing ffado no matter what I try.
2024-03-19 15:46:46 +01:00
Wim Taymans 61dbad2cf3 module-ffado: make sure we close and open when suspend
Rework some things so that we can actually completely close and reopen
the driver when suspending. Leaving the device opened but not streaming
causes trouble when ffado-mixer changes the settings in between.

Do this by first doing a probe to get the ports and streams and then
link those to the actual buffers when we start streaming.

Follow the graph rate and quantum so that we open with the right
settings, this makes pw-metadata work on the quantum and rate. It
requires a driver reopen so it might be slower.

Try to handle some errors better.

See #3558
2024-03-19 13:20:29 +01:00
Wim Taymans 0e380de809 conf: improve matching rules a bit more
Handle "null", null, !null, "!null", !"null" and "!\"null\""
matches, copy some docs from wireplumber about the rules and
add some more cases.
2024-03-18 17:53:44 +01:00
Wim Taymans c52c56621d utils: use memmove when src and dst can overlap
spa_json_parse_stringn() can be used when the strings source and
destination are overlapping so use memmove instead of strncpy to
avoid corruption of the strings.
2024-03-18 16:32:30 +01:00
Wim Taymans ce86b9a398 alsa: improve acp device/node object paths
Use alsa:acp: as the object prefix to make it different from the
alsa:pcm prefix when we are not using ACP.

Replace the card index in the object.path with the card_name, which
we try to construct from the alsa.id when it is available. This brings
the object.path in line with the alsa-pcm-device naming and adds the
user configurable id in the object.path to make it possible to
differentiate between identical devices.

Place the acp device index after the card_name instead of the unstable
device name (which depends on the alsa card number, which depends on the
kernel probing order).

This should make the object.path stable accross reboots for ACP and user
configurable with udev. With such a stable id, the other fields can be
made stable as well with custom rules.

See #3912
2024-03-18 11:41:37 +01:00
Wim Taymans aec07d974e acp: move acp_dict_lookup to public header 2024-03-18 11:41:01 +01:00
Wim Taymans 37a51533e0 acp: add more properties for the card
Use snd_ctl_card_info to set some more card properties such as the
alsa.id, alsa.mixer_name and alsa.components.

alsa.id is interesting because it is possible to use udev rules to set a
custom id, which is handy when you have two identical cards in the
system and want to assign unique ids to them.

See #3912
2024-03-18 10:59:23 +01:00
Charlie Li 2821b05d0b module-raop-sink: explicitly include <openssl/evp.h>
As part of LibreSSL's cleanup of removed ENGINE support, <openssl/x509.h> is no longer included in <openssl/engine.h>. <openssl/evp.h> was transiently included in <openssl/x509.h>, compared to <openssl/rand.h> for OpenSSL.
2024-03-16 14:39:00 -04:00
Steve Langasek 4af8b0f5a7 v4l2: unset _TIME_BITS in addition to _FILE_OFFSET_BITS
The v4l2 build unsets _FILE_OFFSET_BITS, which is not allowed when setting
_TIME_BITS=64.  Having verified that nothing in this module is sensitive to
64-bit time_t (none of the functions it intercepts handle time), we also
unset _TIME_BITS to allow this to build as before.

Signed-off-by: Steve Langasek <steve.langasek@canonical.com>
Reviewed-by: Dylan Aïssi <dylan.aissi@collabora.com>
2024-03-16 09:25:27 +01:00
Wim Taymans 2c0d73ab49 gst: handle latency in the pipewiresrc
Get the delay in the graph and subtract this from the cycle start time
to get the timestamp of the buffer.

Report this latency as well.

Fixes #30
2024-03-15 17:31:43 +01:00
Wim Taymans 1fe498560b gst: refactor some of the param handling
Clear the caps when the param is NULL.
2024-03-15 17:31:05 +01:00
Wim Taymans 2bd85e08cf gst: parse the audio rate from caps
Parse the audio rate from the caps and set this as the stream node.rate
property. This will try to switch the graph to this rate and avoids
resampling.

Rework some of the property handling.
2024-03-15 17:27:32 +01:00
Wim Taymans 9f74a31e9e include: install new header 2024-03-15 13:18:22 +01:00
Wim Taymans 9c072832f0 tests: cleanup correctly to avoid leaks 2024-03-15 13:08:58 +01:00
Wim Taymans c2ba66bef6 protocol-native: clean up security context on unload 2024-03-15 13:00:30 +01:00