Commit graph

12535 commits

Author SHA1 Message Date
Wim Taymans 2f8740dee8 mem: add a PW_MEMBLOCK_FLAG_MAPPABLE flag and pass it around
This flags means that the fd can be mmaped without special handling. It
is the equivalent of the SPA_DATA_FLAG_MAPPABLE. Refuse to map memory
that is not mappable.

Make sure we make all allocated MemFd memory MAPPABLE by default. We can
then remove the stream and filter special handling for MemFd types and
just check the more generic MAPPABLE flag.

Make one exception when a client uploads MemFd buffer memory. We must
manually set the MAPPABLE flag for MemFd to make things backwards
compatible.
2024-04-02 12:27:58 +02:00
Wim Taymans 45984fef77 stream: only unmap data that was mapped and mappable. 2024-04-02 12:27:17 +02:00
Wim Taymans 0b42ec714d stream: handle node.name fallback better
If we don't have extra properties, set the node.name to the stream
name if it was not otherwise present.
2024-04-02 12:26:44 +02:00
Adam Gensler 63af3a4b5c Update 90-pipewire-alsa.rules with support for Astro Mixamp Pro TR. 2024-04-01 18:31:10 +00:00
Pauli Virtanen 5ae0dfb239 bluez5: bap: determine SDU interval from codec frame duration
BlueZ API as BAP Server gives us the ISO interval, instead of the SDU
interval, in the MediaTransport.QoS.Interval property.  They are not
necessarily the same. What we need is the SDU interval.

The SDU interval is the interval between packets the encoder outputs, so
it is determined by the codec configuration, and for LC3 is equal to the
frame duration.

Add codec method get_interval() that returns the correct interval, and
use it in iso-io.
2024-04-01 19:13:01 +03:00
Pauli Virtanen b9ac79e99a bluez5: bap: no need to check for mtu, kernel fragments as needed
It's not necessary for ISO SDU to fit into the adapter MTU, as kernel
will fragment the packet as needed.

Remove MTU checks.
2024-04-01 15:23:32 +03:00
Pauli Virtanen d02cec53c6 CI: put docs from both 1.0 and master on pages 2024-04-01 07:16:24 +00:00
Robert Mader bd5cc52c5c libcamera: add camera rotation property on nodes
Like the location, the orientation is a static property of libcamera
devices. While the rotation is already exposed as buffer transform,
knowing the property can be handy for applications in various ways.

See also: cd8ac5c1a ("libcamera: add camera location property on nodes")
2024-03-31 13:24:19 +02:00
Robert Mader e2e8cf7944 gst/src: Avoid unnecessary renegotiations during streaming
Some clients like many camera apps, including Cheese or Snapshot,
trigger a lot of unnessecary renegotiations. While arguably that should
be solved on a Gstreamer level, we can help out by checking if the
preferred new caps are the same that are already in use and skip the
renegotiation in this case.

This allows several apps to e.g. take pictures without a slow and heavy
stream restart.
2024-03-31 11:03:13 +00:00
Robert Mader 594e3fa09f gst/src: Cleanups for src_negotiate()
Using `g_autoptr` and related modern helpers more often makes
the code smaller, easier to follow and maintain.
No behavior changes intended.
2024-03-31 11:03:13 +00:00
Robert Mader 1a2fee260b v4l2: Drop the first frame after camera startup
A quite big number of UVC cameras - due to firmware or kernel driver
issues - have bad timestamps of the first frame, confusing clients
like pipewiresrc.
Drop the first frame, as this seems to be the most reliable workaround
for the time being.

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3910
2024-03-30 14:14:44 +01:00
Pauli Virtanen a9911f68a0 client-node: free port io memmap also if port gone
clear_port() clears all struct mix and removes the port, and can occur
before port io is set to NULL.  In this case the port memmaps are not
freed, and are leaked until client pool closes.

Fix by freeing the old io memmap when setting io to NULL, also when the
port was already cleared, so that the memmap lifecycle is the same as
that of the IO.
2024-03-29 20:39:13 +02:00
Robert Mader cc0f7596d6 gst: Always use Choice-pod for modifiers
In order to follow the documentation more closely. Also restructure the
code a bit to make it easier to follow.

See also: e3227b2b5 (gst: simplify modifier extraction)

Fixes: f1b75fc6f (gst: Add support for DMA_DRM / explicit modifiers)
2024-03-28 18:45:13 +01:00
Wim Taymans af310523db spa: improve null-audio-sink channels
We can just update the channels in the props, we don't need an extra
property that can go out of sync with the channels.

See #3931
2024-03-28 17:11:16 +01:00
Wim Taymans cddea858d9 context: add context.modules.allow-empty property
false by default, when true, no warning will be logged when the
context.modules in the config is empty. This can be useful when the
application wants to load all the modules itself.
2024-03-28 17:08:33 +01:00
Wim Taymans d0c9d2f99d conf: only count modules, objects and exec when added
We don't actually do anything when the name, factory or path is NULL so
don't count this as an action.

Commenting out these keys is a usual way for commenting out complete
sections.
2024-03-28 17:00:56 +01:00
Wim Taymans 8351a17197 conf: add more error checks
Fail when something goes wrong when adding spa-libs instead of silently
ignoring it.
2024-03-28 17:00:18 +01:00
Wim Taymans e3227b2b5d gst: simplify modifier extraction
spa_pod_get_values() handles both single values and Choice values and
turns the single value into a None choice.

Check that we have a None or Enum choice because we don't handle
anything else.

See !1952
2024-03-28 16:09:18 +01:00
Robert Mader 8848c7e792 gst: Re-enable handling of single long modifiers
A peer may announce support for a single modifier, in which case it may
not use a choice-pod. And while the documentation in `dma-buf.dox`
requires modifiers to always be announced as `SPA_CHOICE_Enum`, this has
been supported in the past - as well as matching Pipewire conventions.

Thus, in order to not break existing clients not crash, reintroduce
handling of modifiers as a single long.

Fixes: f1b75fc6f (gst: Add support for DMA_DRM / explicit modifiers)

Solution suggested by Barnabás Pőcze <pobrn@protonmail.com>
2024-03-28 15:09:34 +01:00
Wim Taymans d682d8c5aa properties: rework properties
Handle allocation errors better, propagate the errors to the caller.

Avoid doing some useless work updating the dict, do this only after we
have done adding all the items when creating and copying.

Make update_string keep a temp array of updates and only apply the
updates when error checking was enabled and there was success. This
makes it possible to parse the JSON string only once.

Fix some of the lookup logic. We can just use spa_dict_lookup() and
spa_dict_lookup_item(), we don't need the index.
2024-03-28 12:37:07 +01:00
Wim Taymans 29ff3f196c filter-chain: debug SOFA error codes better 2024-03-28 09:27:04 +01:00
Wim Taymans 6d4f255ae9 filter-chain: report more parsing errors 2024-03-28 09:16:15 +01:00
Wim Taymans 66b8cd3e32 json: fix SPA_JSON_STATE
It should copy the state as well or else parsing will fail.
2024-03-28 09:14:18 +01:00
Pauli Virtanen 27ccf32030 spa: fix spelling 2024-03-27 18:42:31 +02:00
Pauli Virtanen 3e99a0e839 spa: deal with non-null terminated strings in spa_error_location
Add len field to indicate number of valid characters after location.
2024-03-27 18:36:06 +02:00
Wim Taymans a0af514581 context: make error line debug a little better
Make a line to the ^ so that it is more visible. Spell out column
completely. Make the sizes a little smaller to avoid awkward gaps.
2024-03-27 16:23:38 +01: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 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