Commit graph

2837 commits

Author SHA1 Message Date
Wim Taymans
2f5bba112f spa: Improve PropInfo fields
The PropInfo either has a registered id (and then also a name from the
type-info) or a custom name as a string.
In all cases, the description contains a free form text that clarifies
the property.

Use the description in the stream controls name.
2022-03-30 17:09:08 +02:00
Wim Taymans
5547f9a1b9 resample: take rate scale property into account as well 2022-03-29 17:51:03 +02:00
Wim Taymans
74da804e97 move some debug to fastpath 2022-03-28 16:25:00 +02:00
Wim Taymans
0d6fca5bba audioconvert: add queued samples as delay
The delay of the resampler also includes the queued samples on the
input port.
2022-03-28 14:56:29 +02:00
Wim Taymans
b02154bf77 resample: keep max in bytes
And make sure we calculate the in_queued size correctly because both
the size and offset are in bytes.
2022-03-28 13:14:54 +02:00
Wim Taymans
cf1d4b9140 audioconvert: make simple upmix the default
PSD seems to not always give good results.

fixes #2219
2022-03-26 21:43:52 +01:00
Joakim Olsson
d161019b0d module-echo-cancel: Correct naming in example and plugins 2022-03-21 09:54:20 +00:00
Wim Taymans
2b16df4e89 spa: add locale independent spa_dtoa
And use this in spa_json_format_float() where we also avoid invalid
json floats.
Use json float format in some places where we serialize json floats.
Add a unit test.

See #2223
2022-03-21 10:41:44 +01:00
Wim Taymans
5f4d031db0 spa: add locale independent spa_strtod/spa_strtod
Use those for spa_atof and spa_atod.
Use those for parsing json float.
2022-03-21 10:38:00 +01:00
Wim Taymans
6b423c3d25 spa: debug double like a float 2022-03-21 09:18:07 +01:00
Wim Taymans
b173198d3b audioconvert: remove useless parsing
We don't have float params.
2022-03-21 09:11:36 +01:00
Wim Taymans
93b5d440bc json: add locale independent parse and format functions
Use them in pw-dump.
Add some unit tests.

See #2223
2022-03-20 21:04:33 +01:00
Wim Taymans
947d15a60a json: empty string should not give a valid number 2022-03-20 20:37:26 +01:00
Wim Taymans
b868ec36c5 SPA_DATA_DIR is the source root when uninstalled
Add some more error logging to bluez5 quirk loading.
2022-03-18 21:33:02 +01:00
Wim Taymans
abe87f8008 audioconvert: use unaligned loads
We collect 4 channels from the source. When the number of channels is
not a multiple of 4, we need to do unaligned reads.

See #2221
2022-03-17 10:02:07 +01:00
Barnabás Pőcze
0f28309f07 audioconvert: fix sse2 deinterleave_32
Fixes #2213
2022-03-16 10:54:27 +01:00
Wim Taymans
bc5b486cb9 channelmix: add simple upmix method
Add a property to select the upmix method. PSD is enabled by default
but a new simple upmixing algorithm is available that duplicates
channels and avoids lowpass filter on the FC and disables widening.

Fixes #861
2022-03-14 15:33:07 +01:00
Wim Taymans
cec8898740 tests: add some options
Use S16_LE as the sampleformat, add option for S32_LE
Add support for setting samplerate and channels.
2022-03-13 15:08:22 +01:00
Barnabás Pőcze
25980f947f spa: utils: hook: add comments and fix code in documentation
Extend the examples with comments and fix issues in the code.
2022-03-11 21:21:24 +01:00
Pauli Virtanen
377bc16eb5 bluez5: handle any quantum in a2dp-sink
Remove quantum limitation from a2dp-sink, and adjust how flushing is
done.

The "low-latency" A2DP codecs are not able to flush all data at once, so
for them flush based on a timeout, such that "excess samples" for each
quantum is bounded.  We also limit excess samples for the other A2DP
codecs, based on some testing on flaky headset/adapter combinations (for
most cases, this does not appear to matter).

Leave decision of packet sizes to the codecs. Currently, we send packets
based on min_latency, but sendinf full packets might help with stutter
on some headset/adapter combinations.  The slightly increased latency
hardly matters against the 100ms delays in BT headsets.

Bump codec API version.
2022-03-11 18:09:55 +02:00
Pauli Virtanen
9377ae5fcd bluez5: make codec ABI mismatch messages warnings
The user should be notified of these, so that they can fix their
installation.
2022-03-11 18:09:55 +02:00
Pauli Virtanen
c3a8041e0f bluez5: fix aptx-ll max_frames handling 2022-03-11 18:09:55 +02:00
Pauli Virtanen
f6a83a91e0 bluez5: a2dp-sink: Fail flush on EAGAIN instead of delaying it
If we get an EAGAIN, the device has started lagging in processing its
packets. We should not try to stuff the same packet in again, because
the device will just lag more. Instead, just drop current data, and hope
bitpool reduction takes care of it.

Also increase bitpool only if the socket buffer is empty.
2022-03-11 18:09:55 +02:00
Wim Taymans
734470f0cd audioconvert: add SSE (de)interleave_32(s) versions 2022-03-11 15:02:02 +01:00
Wim Taymans
ca5e0e5837 audioconvert: don't fixate rate
We alwats want to adapt to the rate of the graph and not the
samplerate that was configured with the PortConfig.

This fixes samplerate switching again.
2022-03-08 17:49:13 +01:00
Wim Taymans
54933b67fd loop: clean polling flag when leaving the loop
When we leave the last recursive enter of the loop, clear the polling
flag.

It might be possible that it was not cleared because the loop might have
been killed with pthread_kill. In any case, the _leave calls need to be
made in this case as well.

This fixes issues when jack clients stop because it triggers and assert
because the polling flag is still active when the object is cleared.

See !1171
2022-03-07 10:27:22 +01:00
Barnabás Pőcze
b12f24efb9 spa: support: loop: don't initialize source->loop
There is no need to initialize the `loop`, `rmask`, or `priv`
members of a `spa_source` because `loop_add_source()` will
take care of that.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
d6dfa93b40 spa: support: loop: assert source's loop when dispatching 2022-03-06 18:40:43 +00:00
Barnabás Pőcze
235b155b75 spa: support: loop: assert loop is not polling when destroyed
Assert that the loop is not polling when `impl_clear()` is called.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
616519d704 spa: support: loop: assert loop is not polling when source is removed
`spa_source`s whose backing storage is not managed by the loop
cannot be safely removed while the loop is polling.
Assert that it does not happen.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
60b9d9081b spa: only remove embedded source from data loop from within the loop
Use `spa_loop_invoke()` to invoke a callback on the data loop
to remove an embedded `spa_source` from the data loop.

Embedded `spa_source` objects cannot be safely removed
while the loop is polling without risking potential
use-after-frees.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
7647ea7c83 spa: support: loop: fix use-after-free when loop is reentered
The core of the issue is the following: what happens if an
active source is destroyed before it could be dispatched?

For loop-managed sources (`struct source_impl`) this was addressed
by storing all destroyed sources in a list, and only freeing them
after dispatching has been finished. (0eb73f0f06)
This approach works for both strictly single-threaded
and `pw_thread_loop` loops assuming the loop is not
reentered.

However, if the loop is reentered, there can still be issues.
Assume that in one iteration sources A and B are active,
and returned from the system call, and source B is destroyed
before the loop starts dispatching. Consider what happens when
"A" is dispatched first, and it reenters the loop with timeout 0.
Imagine there are no new events, so `loop_iterate()` will immediately
return, but it will first destroy everything in the destroy list
(this is done at the end of `loop_iterate()`).
And herein lies the problem. In the previous iteration,
there exists a `spa_poll_event` object which points to source "B",
but that has just been destroyed at the end of the recursive
iteration. This will trigger a use-after-free once the previous
iteration inspects it.

Fix that by processing the destroy list right after first
processing the returned `spa_poll_event` objects, and
"detach" the source from the loop and its iterations
in `process_destroy()` before the source is destroyed.

See #2114 #2147
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
2eb36c00c1 spa: support: loop: add polling flag
Store whether or not the loop is currently polling, i.e.
calling `spa_system_pollfd_wait()`.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
4ed0365976 spa: support: loop: assert source type 2022-03-06 18:40:43 +00:00
Barnabás Pőcze
cfc8510ce8 spa: support: loop: add some invariant assertions 2022-03-06 18:40:43 +00:00
Barnabás Pőcze
55ee5ec8b2 spa: support: loop: rename variables
It may be a little confusing that both the loop object
and the `source_impl` objects are referred to with variables
named `impl`. For this reason, rename all source_impl objects
named `impl` to `s`.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
a4e7042176 spa: support: loop: do not return early in case of an error
It is expected that `nfds` is non-negative in the vast majority
of cases, so hopefully the runtime performance will not be
significantly affected by removing the check. This way
it is guaranteed that the destroy list is processed.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
275e23a34d spa: support: loop: print previous mask when updating
Print the previous event mask in `loop_update_io()`
as well as the new one.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
8941fc2866 spa: support: loop: get array size using macro 2022-03-06 18:40:43 +00:00
Barnabás Pőcze
cb8c2d8857 spa: support: loop: reset rmask after dispatch
Reset the `rmask` of the sources to zero after
dispatching the callbacks. This way the sources
are always as up-to-date as possible.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
a22ce76dbf spa: support: loop: initialize rmask
Set `rmask` to zero when a source is added to,
or removed from the loop.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
e2287f35db spa: support: loop: move struct members
Move the boolean members of `struct source_impl` to the end
of the struct. This changes the size of the struct from
104 bytes to 96 bytes on x86-64.

Before:

struct source_impl {
        struct spa_source          source;               /*     0    48 */
        struct impl *              impl;                 /*    48     8 */
        struct spa_list            link;                 /*    56    16 */
        /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
        _Bool                      close;                /*    72     1 */

        /* XXX 7 bytes hole, try to pack */

        union {
                spa_source_io_func_t io;                 /*    80     8 */
                spa_source_idle_func_t idle;             /*    80     8 */
                spa_source_event_func_t event;           /*    80     8 */
                spa_source_timer_func_t timer;           /*    80     8 */
                spa_source_signal_func_t signal;         /*    80     8 */
        } func;                                          /*    80     8 */
        _Bool                      enabled;              /*    88     1 */

        /* XXX 7 bytes hole, try to pack */

        struct spa_source *        fallback;             /*    96     8 */

        /* size: 104, cachelines: 2, members: 7 */
        /* sum members: 90, holes: 2, sum holes: 14 */
        /* last cacheline: 40 bytes */
};

After:

struct source_impl {
        struct spa_source          source;               /*     0    48 */
        struct impl *              impl;                 /*    48     8 */
        struct spa_list            link;                 /*    56    16 */
        /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
        union {
                spa_source_io_func_t io;                 /*    72     8 */
                spa_source_idle_func_t idle;             /*    72     8 */
                spa_source_event_func_t event;           /*    72     8 */
                spa_source_timer_func_t timer;           /*    72     8 */
                spa_source_signal_func_t signal;         /*    72     8 */
        } func;                                          /*    72     8 */
        struct spa_source *        fallback;             /*    80     8 */
        _Bool                      close;                /*    88     1 */
        _Bool                      enabled;              /*    89     1 */

        /* size: 96, cachelines: 2, members: 7 */
        /* padding: 6 */
        /* last cacheline: 32 bytes */
};
2022-03-06 18:40:43 +00:00
Pauli Virtanen
d66e9f1ae1 bluez5: a2dp-sink: stop flushing if source was removed
The flush source gets removed on I/O error. We should not continue
flushing after that.
2022-03-06 16:47:25 +02:00
Pauli Virtanen
24fd273820 bluez5: backend-ofono: don't do codec probe connections + add wait
Codec probe connections can trigger bad behavior from oFono if done when
device is busy (e.g. at connect), and they might be done at the same
time as A2DP transport is acquired which cannot work.

Also, oFono will not reply to DBus Acquire, if device does not complete
codec negotiation correctly. This is most likely to happen just after
device connect, when it is busy with other stuff (eg A2DP).

Remove codec probe connections altogether: instead, we guess mSBC if
mSBC is enabled and otherwise CVSD. If the guess turns out to be wrong,
which is unlikely (almost all devices have mSBC), we recreate the
transport with correct codec (from main loop, must not be done in
*_acquire because that can destroy nodes + unload the spa libs while
we're being called from there).

To avoid oFono DBus hangs at startup, add delay before marking the
profile connected, enforcing a time difference to A2DP operations.
2022-03-05 17:46:40 +00:00
Wim Taymans
1647c169b2 alsa: improve latency update 2022-03-04 17:21:17 +01:00
Wim Taymans
bcdd1ea811 alsa: set better ranges on properties 2022-03-04 17:21:14 +01:00
Wim Taymans
c7de69eac7 channelmix: improve disabled flag
Also parse updates to the disabled flag when disabled so that we can
enabled it again.
2022-03-04 17:21:11 +01:00
Wim Taymans
c03850fd76 merger: also remove PropInfo
We use the PropInfo from the channelmixer.
2022-03-03 19:46:33 +01:00
Wim Taymans
d25bb89cc0 channelmix: enable upmixing by default, disable normalization 2022-03-03 12:33:02 +01:00
Wim Taymans
99f9f729ff handle open_memstream errors
Fixes #2182
2022-03-02 11:48:31 +01:00