Commit graph

6048 commits

Author SHA1 Message Date
Wim Taymans
74831aa967 support: add support for checking loop context
Add check for running the the loop context and thread.

Add checks in filter and stream to avoid doing things when not run from
the context main-loop because this can crash things when doing IPC from
concurrent threads.
2023-04-04 16:19:41 +02:00
Wim Taymans
a6497839bb stream: move some code around
So that we don't have to call public API internally. We might want to
add some checks there later that don't need to happen when called
internally.
2023-04-04 16:16:47 +02:00
Wim Taymans
f2be2923e6 thread: use pthread_equal to compare thread ids 2023-04-04 12:43:25 +02:00
Wim Taymans
edbfd180d0 thread-loop: only restore recurse on error
Only restore the previous recurse state when we fail to unlock.
2023-04-04 12:20:56 +02:00
Wim Taymans
aa2ea737c7 thread-loop: add some additional check
Check for errors from pthread_ functions and log an error.
Check the recursion count to check if locks were correctly taken.
2023-04-04 11:34:03 +02:00
Wim Taymans
796a0d2cfe thread-loop: small cleanup
Use named fields for the event, prefix function.
2023-04-04 11:12:13 +02:00
Wim Taymans
8b1902c825 echo-cancel: reset buffers in suspend
Or else some stay samples from the previous run might be played when
resuming.
2023-04-04 10:17:44 +02:00
Wim Taymans
9664787cff context: Only activate runnable nodes
Rework the runnable state calculation. It works in 2 steps now:

1. Collect all nodes linked to a driver in some way. Mark nodes that
   are reachable with a non-passive link as runnable.
2, Go through all runnable nodes and set all linked nodes to the
   runnable state as well, up to the driver.

Step 2 is new. Previously if there was just one runnable node, *all*
nodes would be set to runnable. With the addition of step 2, some nodes
might remain idle when they are not used.

This has the effect that virtual sinks without inputs stay idle when
the driver is otherwise running. Grouped nodes (like the RTP session)
will now also only run the linked nodes.
2023-04-04 10:17:44 +02:00
Wim Taymans
35d2bce24b context: also follow link-groups
Nodes from the same link-group also need to be linked together to the
same driver.
2023-04-03 16:59:17 +02:00
Wim Taymans
147674c5dd Revert "context: handle link-group nodes"
This reverts commit 2bfe772bb4.

This does not take into account nodes recursively becomming runnable and
so does not set the runnable state on all nodes correctly, like for
combine-stream.

Revert for now, it probably requires a new algorithm to make this work.

See #3128
2023-04-03 10:25:58 +02:00
Wim Taymans
0873c6942a stream: don't crash when _set_control is given 0 values 2023-03-31 11:28:55 +02:00
Wim Taymans
bed961a4b2 keys: update comment 2023-03-31 10:33:20 +02:00
Wim Taymans
9485b2819a impl-node: add support for node.force-rate=0
If you set node.force-rate=0, the rate will be forced to the node.rate
denominator.

This makes it possible to autiomatically make the graph switch to the
native rate of the stream by setting this as the default property on
streams.

See #3026
2023-03-31 10:30:36 +02:00
Wim Taymans
7372a078b4 context: don't try to restore rate on !runnable nodes
There is no point in trying to restore a node to the default rate when
it's not going to run.

This avoids loops when rate switching from one forced rate to another.
2023-03-31 10:14:36 +02:00
Wim Taymans
917d865ea8 stream: invoke RequestProcess in the main loop
pw_stream_trigger_process() can be called from any thread but the
RequestProcess event always needs to be scheduled in the main-loop.
2023-03-30 16:39:32 +02:00
Wim Taymans
d3bd687bc2 buffers: add new ASYNC flag
Make sure we allocate at least 2 buffers when we are dealing with an
ASYNC node. This ensures that an adapter without a converter will at
least negotiate to 2 buffers when the follower stream is async (such as
is the case with pw-cat).
2023-03-30 15:03:29 +02:00
Wim Taymans
a163f29a43 improve logging 2023-03-30 15:03:21 +02:00
Wim Taymans
7bddb80c93 pulse-server: improve Buffer param
We need to be able to fill up one quantum of data when the stream
requests it so suggest a quantum_limit buffer size. Normally, the
converter will further improve the buffer size parameters when
resampling is involved but this is a good default for when working in
passthrough mode.

We don't actually use the stream buffering features so we're happy with
just 1 or 2 buffers.
2023-03-30 10:13:43 +02:00
Wim Taymans
f28c30d526 impl-link: only make passive links with suspendable peers
Only make a passive link when one of the peers is passive and the other
one can be suspended or when both are explicitly passive.

This avoid making passive links between a sink/source pair.

It also avoid making passive links between two streams if they are not
explicitly marked as passive.

It does allow making passive links between a passive stream and a
sink/source or between two passive streams.
2023-03-28 18:14:19 +02:00
Wim Taymans
c84ef9e29a Revert "impl-link: make passive link if both ports are passive"
This reverts commit 6a64b4461e.

Now that sinks and sources are no longer passive by default, we need
just one part of the link to be passive to make things passive.

This breaks the stream recording from a passive stream case but we can
find a different fix for that later.
2023-03-28 17:32:02 +02:00
Wim Taymans
0f27432f8c Revert "impl-node: assume Sink/Source nodes are passive"
This reverts commit 67999f0f9c.

This breaks direct links between two devices because all ports are
passive. This needs some more thinking.
2023-03-28 17:32:02 +02:00
Harri Nieminen
4323a8ad4a module-pipe-tunnel: remove extra whitespace 2023-03-28 13:36:16 +00:00
Wim Taymans
2bfe772bb4 context: handle link-group nodes
Nodes with the same link-group should be added to the same driver.

Also the runnable state of the nodes in the same link group is
shared between eachother. This makes it look like the linked nodes are
really just one big node.

With this change we correctly calculate the state of all nodes and we
can then only set the running state on the runnable nodes.

If you have 2 loopback sinks in front of a driver, this change will
only make the used loopback sink running and keep the other one
idle. It also works for grouped nodes, where only the active nodes
will now be running (such as rtp-session nodes).
2023-03-28 15:19:16 +02:00
Wim Taymans
93e6e98a17 module-link-factory: ignore link.passive by default
Make an option to allow link.passive properties and set it to false by
default.

This effectively ignores the link.passive properties from the session
manager, jack clients and pw-link when set. This is a good idea because
the logic for making passive links is better handled in the core.
2023-03-28 15:19:16 +02:00
Wim Taymans
67999f0f9c impl-node: assume Sink/Source nodes are passive
If not otherwise stated, assume the Sink and Source nodes
are passive.
2023-03-28 15:18:50 +02:00
Wim Taymans
6a64b4461e impl-link: make passive link if both ports are passive
Only make a passive link when both ports are passive.
Otherwise, adding a monitor stream on the loopback output stream will
make a passive link.
2023-03-28 11:58:32 +02:00
Wim Taymans
c8bfa69320 context: init flags before starting recalculate
Init the node flags before recalculating the graph state. There is no
reason to do this later.
2023-03-28 11:52:36 +02:00
Wim Taymans
8fca3808d8 impl-node: only update the trigger node state once
Don't increment the required activation count every time we change the
node prorties with a TRIGGER property. Only increment/decrement when the
value actually changed.
2023-03-28 09:48:21 +02:00
Wim Taymans
08642adddc module-rtp: free the avahi client as well 2023-03-27 16:01:50 +02:00
Wim Taymans
f6e25c239f module-pulse-tunnel: don't unload module from pulse thread
We are not allowed to call pipewire methods from any other thread than
the main thread so use invoke to schedule a module unload from the
pulseaudio thread.

Fixes some infinite loops when the work-queue list gets corrupted.
2023-03-27 11:10:12 +02:00
Wim Taymans
6363bbd1b9 stream: we should not update clock automatically
A driver node should update the clock before it starts the graph
cycle.
2023-03-27 09:52:15 +02:00
Niklāvs Koļesņikovs
265f7dd09f src/daemon: move the optional drop-ins to conf.avail
These drop-ins are not meant to be enabled by default, so let's move
them to fontconfig style *.conf.avail/ subfolders from which they can
be copied or symlinked to a location that will get merged into the
corresponding configuration file.

Signed-off-by: Niklāvs Koļesņikovs <89q1r14hd@relay.firefox.com>
2023-03-27 07:19:27 +00:00
Volker Rümelin
92a41ba21f pipewire-pulse: generate silence on underflow correctly
Filling a buffer with zeros to produce silence is wrong for
unsigned sample formats and compressed sample formats. This is
silence with an offset. A silent stream with unsigned or
compressed samples mixed with another stream produces a clipped
stream. To hear the problem start QEMU with

qemu-system-x86_64 -accel kvm -smp 4 -m 4096 \
 -audiodev pa,id=audio0,out.mixing-engine=off \
 -machine pc,pcspk-audiodev=audio0 \
 -device ich9-intel-hda -device hda-duplex,audiodev=audio0 \
 -boot d -cdrom Fedora-Workstation-Live-x86_64-37-1.7.iso

on a host configured to use PipeWire and start audio playback on
the guest HDA device.

PA_SAMPLE_U8 is the only unsigned PulseAudio sample format.
There is no need to care about unsigned multi-byte formats.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
2023-03-24 19:53:26 +01:00
Wim Taymans
7b6680ba57 plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
2023-03-24 11:36:15 +01:00
Wim Taymans
f309543810 context: update the duration/rate directly when node idle
When the node is not running, update the duration/rate directly
so that followers can see the current duration/rate when they start.
2023-03-23 18:50:24 +01:00
Wim Taymans
6e8625cf96 node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and
rate with the new targets.
2023-03-23 18:39:27 +01:00
Wim Taymans
2adf8d38d5 node: add target_rate and target_duration in io_clock
Place the target rate and duration in the io clock area.

The driver is meant to read these new values at the start of the cycle
and update the position rate and duration.

This used to be done by the pipewire server when it received the ready
callback from the driver but this is in fact too late. Most driver would
start processing and set the next timeout based on the old rate/duration
instead of the new pending ones.

There is still a fallback for the old behaviour (with a warning) when
the driver doesn't yet update the position.
2023-03-23 17:57:16 +01:00
Wim Taymans
87d64f5cad context: rename current_quantum/rate to target_*
They are really the target rate and quantum that we would like to
have and are only current after target_pending is false.
2023-03-23 17:20:01 +01:00
Wim Taymans
d78bea5e32 module-combine-stream: improve docs 2023-03-23 11:47:27 +01:00
Wim Taymans
d3cd900d06 context: restore driver rate when no longer forced
Keep track of when a rate was forced on a driver and restore the
best rate again when no longer forced.

This handles:

- paplay playing a file at 44100Hz
  --> driver openeing the device at 44100
- PIPEWIRE_PROPS='{ node.force-rate=48000 }' jack_simple_client
  --> driver being forced to a new rate of 48000
- Stop jack_simple_client
  --> Driver reverting back to 44100

Previously the driver would stay in 48000Hz until it idles.

This also works with pw-metadata -n settings 0 clock.force-rate 0.

Fixes #2133
2023-03-23 11:35:50 +01:00
Wim Taymans
8ddb6d711f context: don't reconfigure when already pending
When we already have a pending rate/quantum change, don't reconfigure
the driver.

This avoids going into an endless loop when:

1- paplay plays with 44100Hz on device1
2- jack_simple_client starts and attaches to device1
3- jack_simple_client links to device2
4- jack_simple_client is moved from device1 to device2, rate from
   device1 is moved to device2 (44100Hz)
5- device2 becomes schedulable and sees the rate should be 48000Hz (the
   default) it does a rate switch to 48KHz
6- jack_simple_client is suspended, links are back to init
7- jack_simple_client is moved back to device1
8- jack_simple_client links are activated and cycle restarts at 4

The cycle is broken because at 6 we avoid doing the suspend.
2023-03-23 10:26:21 +01:00
Wim Taymans
07e6f44e58 modules: clean up USAGE arguments
use () to mark optional arguments to avoid confusion with arrays.
Add some more optional arguments.
2023-03-22 16:35:55 +01:00
Wim Taymans
d07e1b5641 audioconvert: disable upmix by default again
But instead ship config override files to enable it again.

The idea is that distros can make extra packages that can than be
installed to enable the upmixing.

Also ship a config file to enable more samplerates.

Fixes #3081
2023-03-22 15:21:55 +01:00
jdavidsson
0d0af4c9d8 module-echo-cancel: null check playback stream
Protect against segfault when monitor.mode = true and playback stream
isn't created.
2023-03-22 11:07:17 +00:00
Wim Taymans
943f40fd3a filter-chain: add docs
Add docs for sofa and improve docs for the convolver.
2023-03-22 11:52:02 +01:00
Wim Taymans
5af265ed22 protocol-native: emit bound_id and bound_props from protocol
Emit both the bound_id and bound_props events from the protocol on
the core_resource.

Doing the dispatching of the bound_id/bound_props in the core to the
proxy doesn't handle the case where the client has a listener directly
on the core_resource.

Fixes #3109
2023-03-22 10:20:14 +01:00
Wim Taymans
fb8709716c core: add bound_props event
this event extends the bound_id event and sends the global properties as
well.

This can be used to get the object.serial, for example.

It can also be used in the future to let the server generate unique
property values, like the node.name, and let the client know about the
new property value.
2023-03-21 17:22:27 +01:00
Wim Taymans
59cd5670d7 impl-core: store hello version in core resource
So that we can later get the client core version from the resource.
2023-03-21 17:20:18 +01:00
Wim Taymans
60718c4b4f stream: don't allow _connect twice
Check if we already are connected and return -EBUSY to avoid
crashing.

Fixes #3091
2023-03-17 11:02:36 +01:00
Wim Taymans
8a9e7dc1c7 module-filter-chain: use pw_split_walk correctly 2023-03-16 16:27:12 +01:00