Commit graph

8761 commits

Author SHA1 Message Date
Barnabás Pőcze
3f7e240b28 gitignore: remove config.h.meson
The file has been removed in 2d238f1d33.
2022-03-12 03:16:45 +01:00
Barnabás Pőcze
4118d08f95 gitignore: remove build directories
meson automatically generates a .gitignore file that ignores
everything in the build directory when it is configured.
There is no need to explicitly add build directories
to the top-level .gitignore.
2022-03-12 03:16:45 +01:00
Barnabás Pőcze
5fccc19ed6 gitignore: add dot files
It is more convenient if dot files are ignored by default,
and only the necessary ones are explicitly added to git.
2022-03-12 03:15:10 +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
Théo Lebrun
344cacd24a module-rt: small fixes
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2022-03-11 18:47:25 +00:00
Théo Lebrun
6798b9a933 module-rt: allow building without RTKit 2022-03-11 18:47:25 +00: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
f06ee28140 pulse-server: add sink/source_properties
Support setting extra properties on the sink and source with the
sink/source_properties.
Fix construction of the module arguments, the sink/source.props needs to
be inside the object..

Fixes  #2201
2022-03-11 09:57:37 +01:00
Barnabás Pőcze
8fa4d5c43f pipewire: module-zeroconf-discover: handle when AvahiWatch is freed while dispatching
When a particular AvahiWatch is being dispatched, it cannot
be freed because `watch_callback()` accesses it after
the callback.

Introduce a member (`dispatching`) to coordinate
the deferred freeing in that case.

The timeouts are not affected because the `AvahiTimeout`
object is not accessed after the callback is called.
2022-03-10 21:44:27 +01:00
columbarius
8dccfbce4c doc: Clarify size properties wrt DMA-BUFs 2022-03-09 09:39:48 +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
Wim Taymans
dcbaed1251 pulse-server: also handle fix_ for capture 2022-03-07 10:26:59 +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
6e705da101 test: loop: add helper functions to simplify eventfd use
Add the `read_eventfd()` and `write_eventfd()` functions.
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
529b6fd1b8 test: loop: add test which destroys managed source before reentering
Add a test which triggers two event sources in the loop's "before"
control hook, and destroys the second source in the loop's "after"
control hook, and then reenters the loop in the event handler of
the first source. At the moment, this test triggers a use-after-free.

==2973914==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000000440 [...]
READ of size 4 at 0x608000000440 thread T0
    #0 0x7fa97f60c6b7 in loop_iterate ../spa/plugins/support/loop.c:376
    #1 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #2 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
    #8 0x7fa9836013c0 in __libc_start_main@GLIBC_2.2.5 (/usr/lib/libc.so.6+0x2d3c0)
    #9 0x559995aed754 in _start (/home/pb/temp/src/pipewire/build/test/test-loop+0x26754)

0x608000000440 is located 32 bytes inside of 96-byte region [0x608000000420,0x608000000480)
freed by thread T0 here:
    #0 0x7fa984ffda79 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x7fa97f60b03a in process_destroy ../spa/plugins/support/loop.c:344
    #2 0x7fa97f60cbf8 in loop_iterate ../spa/plugins/support/loop.c:387
    #3 0x559995af5b62 in dmsbd_recurse_on_event ../test/test-loop.c:298
    #4 0x7fa97f60d826 in source_io_func ../spa/plugins/support/loop.c:396
    #5 0x7fa97f60c7e7 in loop_iterate ../spa/plugins/support/loop.c:377
    #6 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #7 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #8 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #9 0x559995b06191 in run_test ../test/pwtest.c:1087
    #10 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #11 0x559995b0aea4 in main ../test/pwtest.c:1482
    #12 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

previously allocated by thread T0 here:
    #0 0x7fa984ffdfb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fa97f60d883 in loop_add_io ../spa/plugins/support/loop.c:408
    #2 0x559995af75de in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:349
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

SUMMARY: AddressSanitizer: heap-use-after-free ../spa/plugins/support/loop.c:376 in loop_iterate
2022-03-06 18:40:43 +00:00
Barnabás Pőcze
b1c189fa86 test: rewrite test which destroys active source before dispatching
Rewrite the test that destroys an active managed source
right after polling is done. There is no need to use a
thread loop because the same thing can be simulated using
the before/after loop control hooks in a more controlled
manner.
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
Barnabás Pőcze
1e99551233 test: loop: do not use NULL as event handler 2022-03-06 18:40:43 +00:00
Pauli Virtanen
67a27d80c6 gst: use target.object instead of node.target, soft-deprecate ids
Use target-object=<serial/name> instead of path=<id> for specifying
sink/src targets. Deprecate path= argument.

Change device provider to preferably expose serials instead of ids.
2022-03-06 18:34:47 +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
7ade8fa8fb pwtest: fix daemon log scrambling
Nonblocking pipes can scramble logs if we read too slow, so use max size
buffers.

Also use CLOEXEC for the pipes to be safer, and minor other fixes.
2022-03-06 02:29:35 +02:00
Pauli Virtanen
8673f8c03d pwtest: shorter default timeout 2022-03-05 17:51:22 +00:00
Pauli Virtanen
9cb55852f4 CI: add functional test program deps 2022-03-05 17:51:22 +00:00
Pauli Virtanen
f3831da67a pwtest: ARG_DAEMON tests don't work on valgrind 2022-03-05 17:51:22 +00:00
Pauli Virtanen
c604f1608a test: add simple functional tests
Try running openal-info.
2022-03-05 17:51:22 +00:00
Pauli Virtanen
76bab25afb pwtest: handle SIGTERM/SIGINT in runner
Catch SIGTERM/SIGINT in test runner, and clean up any spawned processes.

Fixes printing test output on termination by signal (e.g. meson
timeout), and doesn't leave spawned processes running.
2022-03-05 17:51:22 +00:00
Pauli Virtanen
ad3c90dbb9 pwtest: use default debug level 4 for spawned daemons 2022-03-05 17:51:22 +00:00
Pauli Virtanen
a7bd52d07d pwtest/Makefile: set SPA_DATA_DIR 2022-03-05 17:51:22 +00:00
Pauli Virtanen
581f6c7f1d pwtest: add pwtest_spawn for running external programs 2022-03-05 17:51:22 +00:00
Pauli Virtanen
df4f844daa pwtest: ensure all spawned daemons are terminated
Set process group, and send signal to them all.
2022-03-05 17:51:22 +00: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