Commit graph

12787 commits

Author SHA1 Message Date
Barnabás Pőcze
2d43b6b515 pipewire-jack: fix property list underallocation
`(n_items) + 1 * sizeof(*items)` is not the correct size to allocate
for `n_items + 1` count of objects each with size `sizeof(*items)`,
the `+ 1` should be inside the parentheses.

Fixes #4481
Fixes: 4baa94fce2 ("thread: make it possible to set a custom create function")
2025-01-23 10:37:23 +01:00
Barnabás Pőcze
4fa78021c7 spa: debug: pod: print unsigned numbers as unsigned
Both `spa_rectangle` and `spa_fraction` store unsigned numbers,
so print them as unsigned, the same way it is already done in
`spa_debug_strbuf_format_value()`.
2025-01-23 10:37:10 +01:00
Barnabás Pőcze
1c2fe03498 pipewire: context: pw_context_find_format(): fix stack use-after-free
Since fc49c1697a ("context: improve negotiation") it is possible
that the out parameter `format` will be set to `filter`. However,
`filter` is a SPA POD from the local SPA POD builder `fb`, which
references the local buffer `fbuf`.

In those cases, if the callers then make use of the returned SPA POD,
a stack use-after-free happens, such as the one displayed below.

The issue could be reliably triggered by executing the `video-play`
example program, and then trying to use the same camera in firefox.
As seen below, the input node, firefox's, provides no format preference,
causing the output format to be used. Previously, this had led
to the use-after-free described above.

pw.link    | [impl-link.c: 130 link_update_state()] (46.0.1 -> 114.0.0) init -> negotiating (paused-configure)
pw.context | [  context.c: 935 pw_context_find_format()] 0x51e000000080: finding best format 3 1
pw.context | [  context.c: 943 pw_context_find_format()] 0x51e000000080: states 3 1
pw.context | [  context.c: 958 pw_context_find_format()] 0x51e000000080: Got output format:
pw.context | [  context.c: 959 pw_context_find_format()]  video/raw
pw.context | [  context.c: 959 pw_context_find_format()]            format : (Id) YUY2
pw.context | [  context.c: 959 pw_context_find_format()]              size : (Rectangle) 640x480
pw.context | [  context.c: 959 pw_context_find_format()]         framerate : (Fraction) 30/1
pw.context | [  context.c: 966 pw_context_find_format()] 0x51e000000080: no input format filter, using output format: Success
=================================================================
==418404==ERROR: AddressSanitizer: stack-use-after-return on address 0x73993ee46200 at pc 0x739941d31020 bp 0x7fff526b4670 sp 0x7fff526b4660
READ of size 4 at 0x73993ee46200 thread T0
    #0 0x739941d3101f in spa_pod_builder_raw ../spa/include/spa/pod/builder.h:150
    #1 0x739941d3b35d in do_negotiate ../src/pipewire/impl-link.c:294
    #2 0x739941d46214 in check_states ../src/pipewire/impl-link.c:727
    #3 0x739941f14405 in process_work_queue ../src/pipewire/work-queue.c:64
    #4 0x73993d0dbe99 in source_event_func ../spa/plugins/support/loop.c:894
    #5 0x73993d0d6881 in loop_iterate ../spa/plugins/support/loop.c:727
    #6 0x739941d76b05 in spa_loop_control_enter ../spa/include/spa/support/loop.h:264
    #7 0x739941d76d93 in spa_loop_control_leave ../spa/include/spa/support/loop.h:268
    #8 0x739941d78946 in pw_main_loop_quit ../src/pipewire/main-loop.c:109
    #9 0x5a64b3cb1cec in main ../src/daemon/pipewire.c:130
    #10 0x739940c34e07  (/usr/lib/libc.so.6+0x25e07) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #11 0x739940c34ecb in __libc_start_main (/usr/lib/libc.so.6+0x25ecb) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #12 0x5a64b3caf3b4 in _start (/pipewire/build/src/daemon/pipewire+0x173b4) (BuildId: f9e8403a377e28bf8bd9cf0a5b89d33f08499917)

Address 0x73993ee46200 is located in stack of thread T0 at offset 512 in frame
    #0 0x739941c6ed5e in pw_context_find_format ../src/pipewire/context.c:907

  This frame has 15 object(s):
    [...]
    [432, 480) 'fb' (line 911)
    [512, 4608) 'fbuf' (line 912) <== Memory access at offset 512 is inside this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return ../spa/include/spa/pod/builder.h:150 in spa_pod_builder_raw
    [...]

Fixes: fc49c1697a ("context: improve negotiation")
2025-01-23 10:33:03 +01:00
Barnabás Pőcze
de609ff994 spa: v4l2: query_ext_ctrl_ioctl(): only check errno on failure
`errno` is not guaranteed to be cleared, so only check it if
the previous call actually failed.
2025-01-23 10:27:43 +01:00
Taruntej Kanakamalla
0549996c87 gst: deviceprovider: allow pulseaudio and exclude pipewire for audio
Don't hide pulsedeviceprovider so pulsesink/src are listed by the device provider
and exclude pipewire's audio devices in its deviceprovider.
Continue showing video devices in pipewiredeviceprovider, so that pipewiresrc is
listed for the video devices
2025-01-20 16:36:07 +05:30
Wim Taymans
223569dc4a spa: initialize all fields explicitly
Patch by Petar Popovic

Fixes #4325

(cherry picked from commit 0ca64277b3)
2024-12-14 10:59:12 +00:00
Wim Taymans
8d9269374d filter-chain: handle 0 length IR
Make sure we copy the DSP functions in the convolver before leaving the
function because we need them to clear memory.

Don't store the DSP functions in the head and tail convolvers but pass
them from the main convolver because the convolvers might be NULL but we
still need the DSP functions to clear memory.

Fixes #4433
2024-12-03 15:43:56 +01:00
Wim Taymans
e42de413e8 spa: fix some param type info
Add an int array type and use this in the route properties.

Fixes #4441
2024-12-03 12:41:07 +01:00
Wim Taymans
91e26d6011 gst: add slave-method property
Set the slave-method to none by default to disable the resampler.

Fixes #4374
2024-12-03 12:29:07 +01:00
Wim Taymans
1e2b7f7c00 gst: add rate control to the sink
Track the elapsed time between buffers and try to keep the buffer fill
level constant by changing the rate of the stream.

See #4374
2024-12-03 12:29:07 +01:00
Wim Taymans
938283aee4 gst: mark the pipewiresink as EARLY_PROCESS
We want to receive process callbacks as soon as a buffer is ready for
reuse because we dequeue it for use in our buffer pool.
2024-12-03 12:29:07 +01:00
Arun Raghavan
a6019e6dd7 spa: alsa: Don't assume all PCMs have a card
dmix/dsnoop devices, for example, don't have an associated card, so all
the card-related checks don't make sense. Let's explicitly deal with
this case.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4432
2024-12-02 11:52:10 -05:00
Arun Raghavan
1993383ddf spa: alsa: Fix key name suggestion in log message
We use api.alsa.pcm.card to look up the PCM's card if we don't know it
by other means.
2024-12-02 11:52:08 -05:00
Wim Taymans
cc7439187f 1.2.7 2024-11-26 10:07:54 +01:00
Pauli Virtanen
858f6f3210 pw-dump: don't emit remove events when not monitoring
When pw-dump is called without --monitor, it should output exactly one
JSON array, and no remove event indicators.
2024-11-26 10:01:52 +01:00
Arun Raghavan
ff63ca4d36 spa: alsa: Try to initialise card_index from path if needed
If the PCM is loaded directly using only api.alsa.path,
state->card_index may never be initialised, and then we end up opening
the wrong ctl device. Let's try a fallback for this case.
2024-11-26 10:01:11 +01:00
Wim Taymans
e7db5e9a00 doc: fix the SPA POD enum docs
The first argument should be the element count.
Fix the format for float, it should be with captial F.
2024-11-26 10:00:40 +01:00
Wim Taymans
4ba1d2cbe7 stream: fix EARLY_PROCESS again
It got removed with the async improvements. We shouñd simply ask more
buffers whenever we push one to be dequeued.

See #3480
2024-11-26 10:00:29 +01:00
Wim Taymans
8bfdd3c24a pass the right types to the methods
This currently works because we accept void* for these functions but it
will fail when we will use the real types.
2024-11-26 10:00:07 +01:00
Pauli Virtanen
48ad0861e4 pulse-server: ensure positive stream delay in GET_PLAYBACK/RECORD_LATENCY
Pulseaudio protocol requires stream latency is uint64. Clamp the
Pipewire signed latency to the range, better than wrapping around.
2024-11-26 09:59:53 +01:00
Wim Taymans
5a492c2265 module-eq: format floats as JSON floats
Don't use %f to serialize floats to JSON but use the json formatter
because in some locales, the decimal point becomes a , which does not
parse as a float anymore.

Also reformat some lines.

Fixes #4418
2024-11-26 09:40:03 +01:00
Wim Taymans
d2857c2129 module-rtp: allocate receive buffer based on MTU
Use the MTU to allocate the receive buffer instead of using a hardcoded
size.

Fixes #4394
2024-11-18 11:11:14 +01:00
Wim Taymans
ba7a8664a1 module-rtp: calculate payload_size based on MTU
The actual payload size depends on the MTU but should not include the
IP/UDP and RTP headers.

Fixes #4396
2024-11-18 11:10:18 +01:00
Wim Taymans
b409f5f5d1 v4l2: Add mmap fallback when USERPTR is not supported
When we don't support EXPBUF according to the probe, the host will
allocate memory for us. We will then try to use USERPTR to import the
memory into v4l2.

If this is not supported, try to fall back to MMAP support, mmap the
buffers and memcpy the MMAP buffer to the host allocated buffers.
2024-11-18 11:02:09 +01:00
Wim Taymans
7a0aea835a v4l2: improve debug a little 2024-11-18 11:01:39 +01:00
Wim Taymans
0056fdac83 v4l2: fix sign 2024-11-18 11:01:23 +01:00
Wim Taymans
4c487ea59d v4l2: use a separate flag to skip the first buffer
The buf.sequence value might stay to 0 (v4l2loopback)
2024-11-18 11:01:10 +01:00
Wim Taymans
cba2fad86b v4l2: probe number of buffers as well
Instead of just probing with 2 buffers, probe with the MAX_BUFFERS and
remember how many buffers we received.

Some drivers (v4l2loopback) work with less than MAX_BUFFERS (8) and we
need to set the max number of buffers in the Buffers param.
2024-11-18 11:00:58 +01:00
Wim Taymans
bfbf38d5f7 impl-node: save all previous timestamps on start
When the driver starts, save all previous node timestamps, not just the
previous signal time.

For async nodes, uses the previous timestamps in the profiler messages
so that we get stats with 1 cycle of delay instead of bogus values
because the node is still processing.

Fixes pw-top for async nodes.
2024-11-18 10:56:58 +01:00
Wim Taymans
02c332bb78 alsa: handle the case where the driver is destroyed
When the driver node is destroyed (like when unplugging the cable) it
will drop/pause all of the follower ALSA nodes. This is something that
happens internally because of how the ALSA nodes work together, on the
PipeWire level, the nodes are still running and they will just be moved to
another driver.

The problem is that nothing will then start the nodes again after moving
it to the new driver. Fix this by keeping track of the desired target
state of the ALSA node and restoring that state when we detect that we are
paused when moved to a new driver.

Fixes #4401
2024-11-18 10:54:30 +01:00
Wim Taymans
070374e7ee doc: fix spa_pod_parser_get_object example 2024-11-18 10:53:41 +01:00
Wim Taymans
0266b82e78 alsa: remove unused variable 2024-11-18 10:50:51 +01:00
Wim Taymans
ff984da67c examples: update the examples with new lazy scheduling flags
The src can listen to RequestProcess commands and so gets the
node.supports-request = 1 property.

The play-pull example can both be a driver that listens to
RequestProcess or a lazy driver so set this in properties as well.
We can now remove the priority.driver property because automatic
priority selection will make us a driver or not.

With this change, video-src to video-play-pull will use lazy scheduling
with play-pull as the driver. video-play-pull to v4l2src will use
normal scheduling and video-src to video-play will also use normal
scheduling.
2024-11-11 15:05:40 +01:00
Wim Taymans
61f15734e1 stream: expose the lazy flag with pw_stream_is_lazy()
Together with the is_driver() status, this can be used to check if the
stream is using lazy scheduling or not.
2024-11-11 15:05:17 +01:00
Wim Taymans
75e54ddc4f context: set lazy scheduling flags in clock
Collect the request scheduling flags and when there is a lazy driver,
set the lazy scheduling flag in its clock. This means that the driver
can expect RequestProcess commands to start the scheduling.

Pass the lazy scheduling clock flag to the node.

Make sure lazy scheduling driver have a higher priority than their
request drivers.
2024-11-11 15:04:00 +01:00
Wim Taymans
c57f2345f3 keys: add lazy scheduling flags and docs 2024-11-11 15:03:43 +01:00
Wim Taymans
d57e20b0e9 gst: take the thread lock before calling pw_stream functions 2024-11-08 13:10:40 +01:00
Wim Taymans
3a167d4be1 filter-chain: pass dict in plugin load function
So that we can pass some more properties around and remove the
quantum_limit hardcoded value.
2024-11-08 13:10:35 +01:00
George Kiagiadakis
270669be0d filter-chain: move dsp_ops pointers to dynamically allocated memory
Make a plugin structure that is dynamically allocated for each plugin
and pass it around to the descriptor instance structures, so that they
all have access to dsp_ops without sharing a static pointer.

The problem with the static pointer is that the dsp_ops structure is
actually allocated in module-filter-chain's instance structure,
so it always points to the instance of the last filter-chain that was
loaded in the process. When this is unloaded, the other filter-chains
crash.
2024-11-08 13:09:14 +01:00
Wim Taymans
5759a88f27 v4l2: first probe and then update port flags
The probe is to decide it we can use EXPBUF or not and this is used to
decide on the flags.

This got broken with 842ac9e110
2024-11-07 11:20:32 +01:00
Wim Taymans
af69f15dc2 modules: add ratelimit to xrun warnings in jack-tunnel
Take the current cycle times early and in all cases. We can use this to
get the current frame time for debugging purposes instead of the more
heavy jack_frame_time().

Rate limit the xrun warnings.
2024-11-06 12:26:40 +01:00
Wim Taymans
92c7c56e15 audioconvert: only output when there is something to output
Or else we get 0 sized output buffers.
2024-11-06 11:19:27 +01:00
George Kiagiadakis
b0de2a9b7a pw-dot: fix information on the link labels 2024-11-06 11:02:24 +01:00
Niklas Carlsson
cbbc9a718e filter-chain: fix unmap indexing for LV2 plugins
The index returned to the LV2 plugin starts from 1, but the array
index starts from 0.
2024-11-06 10:59:14 +01:00
Pauli Virtanen
926d567c4c pulse-server: more specific error message when too many connections
This appears to be encountered often enough so a clearer message is
maybe useful.
2024-11-06 10:58:47 +01:00
Wim Taymans
00057d211f audioconvert: interchange the resampler loops
Iterate the channels in the inner loop instead of the outer loop. This
makes it handle with 0 channels better but also does the more
complicated phase increment code only once for all channels. Also the
filters might stay in the cache for each channel now.
2024-11-06 10:58:31 +01:00
Pauli Virtanen
77f71f2b58 proxy: invalidate proxy id when removed from map
Client-side bugs calling methods on destroyed proxies like

    pw_proxy_ref(p);
    pw_proxy_destroy(p);
    ...
    wait for server to ack the remove
    ...
    pw_core_destroy(p->core, p); /* p already removed & destroyed */

should not send messages with the stale proxy id to server.

Set id to SPA_ID_INVALID when removing a proxy from the id map, so that
such client bugs only result to ENOENT.
2024-11-06 10:56:45 +01:00
Wim Taymans
9697b67802 filter-chain: first create instances and then link port
First make instances of all the plugins and then try to link them up.

Otherwise, depending on the order the plugins are defined in the config,
a link will try to create port data and set it on the instance, which is
still NULL and we crash.
2024-11-06 10:55:46 +01:00
Wim Taymans
cdb3c64753 json: improve infinite checks
Avoid compiler errors like this:

/usr/include/spa-0.2/spa/utils/json.h:417:25: error: comparing floating-point with '==' or '!=' is unsafe [-Werror=float-equal]
|   417 |                 if (val == INFINITY)
|       |                         ^~
2024-11-06 10:52:05 +01:00
Arun Raghavan
41b5c50c86 spa: audiotestsrc: Validate loop and system before using them
Makes sure we don't crash if those are not available (like with
DataSystem under spa-inspect).

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4365
2024-11-06 10:49:51 +01:00