Commit graph

13715 commits

Author SHA1 Message Date
Wim Taymans
549f3fc46f module-combine: use a better empty property string
The empty string fails to parse as a properties, use "{}" instead.
2025-06-12 16:35:49 +02:00
Wim Taymans
046fdad4ee modules: improve latency handling
Now that the stream remembers the latency for us, we can only care
about the other latency.

So, if we get (output) latency on an input port/stream, we add our
own latency and then set it on the output port/stream. We do the
same for input ports.
2025-06-12 15:20:18 +02:00
Wim Taymans
92243038c1 stream: handle Latency params better
LOCK the Latency param we get from the peer so that we don't remove it
when we update our own port latency. Also don't remove our port latency
when we get an update from the peer.

This essentially keeps the update/clear of the upstream and downstrem
latencies separate and makes it easier to implement the latency
logic in the pw-stream.

When a filter receives a Latency event on a port, it can simply update
the other port latency and none of the peer latencies are removed.
2025-06-12 15:02:17 +02:00
Wim Taymans
2393be4543 spa: add SPA_LATENCY_INFO_UNSET
Add a initializer for an unset latency info. Use this for combining
latency info.
2025-06-12 12:12:28 +02:00
Wim Taymans
5480a1382f modules: always update latency params
Even if the latency didn't change, the current pw-stream
implementation will have wiped all Latency params away and we want
to put them back in all cases.

See #4731
2025-06-11 16:26:03 +02:00
David Turner
3a0ffe21e6 libcamera: Default to auto-focus & auto-exposure
libcamera says that cameras should default to manual focus mode.  This
means that unless pipewire clients specifically change this control,
users with an autofocus-capable camera are left with an out-of-focus
image.  This patch sets the autofocus mode to continuous and enables
auto-exposure (as the default for this is unspecified).

Testing with an imx708 on Raspberry Pi OS on a Raspberry Pi 4, before
this patch the image was generally out of focus in Firefox/webrtc, after
this patch autofocus works correctly.
2025-06-11 13:56:26 +00:00
Wim Taymans
82229b3d87 modules: make sure we deactivate the graph safely
Use the loop lock to ensure the loop is not using the graph anymore when
the deactivate or reset it.
2025-06-11 15:21:26 +02:00
Wim Taymans
3fdcf0d34c alsa: reset alsa_sync when linked
When a linked node needs to be resynced we actually never clear the
flag or reset the dll. Move the code around so that it still does
the reset of the flag and dll without actually doing the resync in
the ringbuffer when it is a linked node.
2025-06-11 13:06:54 +02:00
Wim Taymans
524da5962d alsa: reset dll in prepare
When we do_prepare, always reset the dll. We already set the alsa_sync
field but that is only used by followers to resync in some cases.

When reseting the dll, we also reset the next_time and base_time values,
we however need to do this before calculating the error in update_time
when we are the driver in IRQ mode or else we get some crazy error
that distorts the rate estimation.
2025-06-11 13:03:18 +02:00
Wim Taymans
b0462cb5de filter-chain: do graph reconfigure in playback state change
Because we do the processing of the graph in the playback process
function, only do graph reset and reconfigure from the playback state
change so that we don't have process and state change at the same time
and crash.
2025-06-11 11:43:13 +02:00
Wim Taymans
c08ef84745 modules: initialize the latency params
Otherwise we get nonsense values for the direction.

See #4731
2025-06-11 10:17:32 +02:00
Wim Taymans
190d49d874 loop: add docs about the locking 2025-06-10 18:00:01 +02:00
Wim Taymans
a2f2bded0b modules: update latency handling in example filter 2025-06-10 16:48:49 +02:00
Wim Taymans
b6b61a956f modules: implement Latency according to docs
Make one function to update the Latencies on all streams. We need to do
this because if one of the process or latency params change, it
influences the latency params on all streams.
2025-06-10 16:48:49 +02:00
Martin Geier
4976ac7ef9 alsa-pcm: add dsd bit order parameter
Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:48 +02:00
Martin Geier
9afa0cd270 alsa-pcm: enable interrupts after alsa recovery
Interrupts are disabled in alsa_irq_wakeup_event -> playback_ready method
to not produce another wakeups when waiting for a new data. Interrupts are
enabled again when a new data arrives in a method spa_alsa_write.
In rare cases, when there is multiple streams providing data and one of
them is disconnected, a new data fails to be delivered and the spa_alsa_write
is not called. Not providing data produces underrun and alsa-pcm invokes
recovery process. Recovery process starts a new playback, but without interrupts
enabled is graph not triggered and new data are not delivered (to enable
interrupts). Recovery process keeps running in loop.
Now the interrupts are enabled again after the recovery and the starvation
should not occur.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:46 +02:00
Martin Geier
c2e539b780 module-combine-stream: flush data in paused state
When stream is paused, internal delay buffers were cleared, but some
data could stay in stream output queue. Without a flush, these data where
played in front of a new data.
Patch was inspired by 64d6ff4184 fixing the
same issue in a filter-chain module.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:43 +02:00
Martin Geier
ff3bc8818f module-combine-stream: update latency right before playback starts
Combine stream selects the biggest latency from all output streams and sent
the latency upstream. To select the biggest latency, each stream needs to have
the sample rate and the quantum size set.
The combine stream recalculates the latency in the latency changed callback
or during data processing.
Stream sets the sample rate and the quantum size in a copy_position call
which is normally called during processing the output data or when state
changes to streaming.
Before this change, it wasn't guarantee the copy_position was called for
each stream already and latency in the combine stream was selected from
random stream.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:40 +02:00
Wim Taymans
88963e9a9c Revert "loop: deprecate the hooks"
This reverts commit 550ec8c2a4.

Before hooks are still useful when integrating other fds in the pipewire
main loop.
2025-06-10 13:08:45 +02:00
Wim Taymans
550ec8c2a4 loop: deprecate the hooks
They were mostly useful for locking and unlocking but since that is
builtin right now, we should remove those eventually.
2025-06-10 12:01:20 +02:00
Wim Taymans
8e32afb863 loop: don't call the hooks around blocking wait
The hooks were previously used to unlock the loop but now that the
lock is handled inside the loop itself and we don't unlock before the
blocking read anymore, we should also not call the hooks.

The blocking invoke function is not meant to be called with any of the
loop context locks acquired in order to avoid a deadlock. Make this (and
other blocking risks) clear in the documentation.

See #4472
2025-06-10 11:57:38 +02:00
Wim Taymans
feba1fd260 meson: fix avfilter dependency 2025-06-10 11:23:15 +02:00
Wim Taymans
a78e97a53b filter-chain: document ffmpeg plugin 2025-06-10 10:55:45 +02:00
Wim Taymans
8c68537446 filter-graph: clean up descriptor memory 2025-06-10 10:55:45 +02:00
Wim Taymans
41cafb4d2f filter-graph: add avfilter multichannel support
Use the port name extension to set the channel layout on the ports.

Add latency measurement and reporting.
2025-06-10 10:55:45 +02:00
Wim Taymans
2f51b9a5d9 filter-graph: add multiple in/out support for avfilter
Make one buffersrc for each input and configure it to mono. Try to guess
the channel position from the port name or use the config option and
fall back to FC (MONO) if unspecified.

Make one buffersink for each output and place a format converter in
front of it. Configure the converter to produce 1 channel with a layout
guessed from the port name or from the config.

With this we can use channelsplit and amerge to create multichannel
streams for avfilter plugins.
2025-06-10 10:55:45 +02:00
Wim Taymans
94116901ce filter-graph: add an ffmpeg plugin
Allows for using an ffmpeg filter-graph as a filter-graph node.
2025-06-10 10:55:45 +02:00
Wim Taymans
9b36e576cb alsa: handle NULL io
It is possible that the port io is set to NULL when the node is
negotiating or destroying.

Fixes #4734
2025-06-10 10:54:36 +02:00
Jonas Holmberg
930f2f3e2d gst: deviceprovider: take a ref to devices
When _probe() is called, take a ref to the newly created devices instead
if sinking the floating ref, since gst_clear_object() is called when
core is disconnected. Otherwise the devices will be freed before the
caller gets them.

Fixes the following assert in the caller:

g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed

Or sometimes a segfault with the backtrace:

0  g_type_check_instance_is_fundamentally_a (type_instance=type_instance@entry=0x116c1b0, fundamental_type=fundamental_type@entry=80) at /usr/src/debug/glib-2.0/2.84.0/gobject/gtype.c:3918
1  0xb6d40cc6 in g_object_is_floating (_object=0x116c1b0) at /usr/src/debug/glib-2.0/2.84.0/gobject/gobject.c:3843
2  0xb6bc4c74 in gst_device_provider_get_devices (provider=0x109ba00) at /usr/src/debug/gstreamer1.0/1.24.12/gst/gstdeviceprovider.c:426
2025-06-09 16:50:18 +02:00
Wim Taymans
b51d3d7e8b filter-graph: ignore ports without descriptor
Ports without a descriptor are to be ignored. They also don't have
a node associated with them so don't try to get its latency.

Fixes #4700
2025-06-09 11:44:06 +02:00
Wim Taymans
4f3a2d723b filter-graph: add a pipe filter 2025-06-06 13:00:29 +02:00
Arun Raghavan
420c510d47 spa: loop: Fix potential uninitialised result 2025-06-06 12:50:56 +05:30
Wim Taymans
e43324a186 filter-graph: remove a memcpy and some cleanups
We don't need to memcpy if we swap between 2 buffers for overlap.

Remove a duplicate variable.
2025-06-05 11:35:32 +02:00
Wim Taymans
7ef8dc4dee filter-graph: a 64 tap hilbert function is a better default
1024 taps for the default hilbert functions seems excessive, use 64
instead.
2025-06-05 11:21:56 +02:00
Wim Taymans
efb1208b97 filter-graph: use spa_memcpy to make it instrumentable 2025-06-05 11:21:28 +02:00
Christian Glombek
113e22cb72 raop: don't set improper media.format 2025-06-03 19:39:43 +02:00
Christian Glombek
6e64d5da47 raop: set mtu to 1448 by default 2025-06-03 19:39:41 +02:00
Wim Taymans
457b1c2e1e filter-graph: run when both in and out != NULL
The check got reverted in 8ee51cd88f
2025-06-03 17:54:06 +02:00
Arun Raghavan
56c6e19f99 Revert "spa: loop: Change get_time() timeout to unsigned"
This reverts commit c515f9bf8e. The PW
APIs use int64_t (partly because SPA_NSEC_PER_SEC is an LL), and we
don't want to change already public API.
2025-06-03 15:20:15 +05:30
Arun Raghavan
c515f9bf8e spa: loop: Change get_time() timeout to unsigned
A signed value doesn't really make sense in this context, so let's keep
it unsigned so the semantics are clear. This does break the interface,
but should be okay since it's not in a release yet.
2025-06-03 09:39:30 +00:00
ValdikSS
187df01b5e bluez5: aac: disable Perceptual Noise Substitution for MPEG-2 profile
When the Bluetooth earphones claim to support AAC `MPEG-2 AAC LC` type only,
PipeWire encodes audio using MPEG-4 FDK-AAC profile which enables unsupported
Perceptual Noise Substitution (PNS) encoder feature.

Use AOT_MP2_AAC_LC pseudo-profile which is AOT_AAC_LC with PNS disabled.
2025-06-03 09:38:28 +00:00
Wim Taymans
38a3ebdca1 adapter: use the right default when filtering default
We should prefer the value of the follower when fixating to the
PortConfig format.

To make this actually work we need to be able to check if the value is
within the configured ranges. Implement the check for all types by
simply comparing the memory. This should then work also for checking
arrays, such as channel positions.
2025-06-03 11:35:59 +02:00
Wim Taymans
a5e63102d9 alsa: unlock pending drain in drop
When we set activated=false, signal the thread because it might be
waiting in drain.

See #4728
2025-06-02 19:14:45 +02:00
Wim Taymans
f65f5cf866 stream: make ticks continuous on DISCONT
A discont of the clock does not mean a discont in the stream, so keep
the ticks continuous.
2025-06-02 12:23:53 +02:00
Carlos Rafael Giani
abb55697c1 spa: Add SPA_IO_CLOCK_FLAG_DISCONT 2025-06-02 10:04:13 +00:00
Carlos Rafael Giani
5dd65dccf3 spa: Improve spa_io_clock flags documentation 2025-06-02 10:04:13 +00:00
Wim Taymans
13105a8e64 pulse-server: Implement record PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND
Also implement the flag for record streams, where it is more usually
used, like in pavucontrol to disable starting a network source.
2025-06-02 11:48:01 +02:00
Arun Raghavan
60669920f0 pulse-server: Implement PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND
We do this by setting the node as passive.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4255
Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4726
2025-06-02 14:38:22 +05:30
Sam James
2cec77e7df *: unify config.h handling
config.h needs to be consistently included before any standard headers
if we ever want to set feature test macros (like _GNU_SOURCE or whatever)
inside. It can lead to hard-to-debug issues without that.

It can also be problematic just for our own HAVE_* that it may define
if it's not consistently made available before our own headers. Just
always include it first, before everything.

We already did this in many files, just not consistently.
2025-05-30 10:24:13 +00:00
Wim Taymans
50fe63ea76 examples: exit early when no longer running
When we are no longer running after the eventfd was signaled, stop
producing samples.
2025-05-30 12:17:41 +02:00