Commit graph

42 commits

Author SHA1 Message Date
Wim Taymans
06efc8ffb6 pulse-server: clear timer when stream is created
Make a function when the stream is created so that we can clear the
create_tag and the timer.
2025-09-18 14:22:00 +02:00
Wim Taymans
ca713c08ee pulse-server: use the new timer-queue for timeouts
Use the timer queue for scheduling stream and object data timeouts.

This avoids allocating timerfds for these timeouts and the timer queue
can handle many timeouts more efficiently.
2025-09-18 13:55:43 +02:00
Wim Taymans
361a0de85a pulse-server: make timer function static and fix formatting 2025-09-17 19:18:27 +02:00
Arun Raghavan
cfde4c1b17 pulse: Handle timed out streams
If we don't get a link on a stream, we might never send a create stream
reply. The client handles this fine by timing out after 30s and dropping
the stream, but the server holds on to the pw_stream forever (or until
the client quits).

Let's add a timer to clean up such streams on the server.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4901
2025-09-17 11:48:27 -04:00
Wim Taymans
370d190572 pulse: improve stream suspended state handling
Only send out SUSPENDED event when there is a change in the suspended
state. This avoids sending out unsuspend events when we simply uncork.

Implement the fail_on_suspend flag for capture and playback streams.
Instead of suspending those streams, we need to kill them.
2025-09-01 12:55:51 +02:00
Arun Raghavan
220b037683 pulse-server: Implement stream suspended callback 2025-06-23 09:19:10 +00:00
Wim Taymans
c45d667934 loop: spa_loop_invoke -> spa_loop_locked where possible
When we simply need to change some state for the code executed in the
loop, we can use locked() instead of invoke(). This is more efficient
and avoids some context switches in the normal case.
2025-05-30 11:59:35 +02:00
Wim Taymans
9e932ec671 pulse-server: set pulse.corked on streams
Set the corked state on streams so that we can use this in sink-input
and source-output info without guessing.

The problem is that when a stream starts un-corked, the state is less
than RUNNING and so before this patch, pulse-server reports a corked
stream, which is not what pulseaudio reports.
2024-09-30 15:02:08 +02:00
Wim Taymans
6d0613bc9a pulse-server: place stream media.* keys as Tag 2023-10-11 15:17:13 +02:00
Wim Taymans
846e732458 pulse-server: remove pending_streams list
We can simply use the pending flag and merge the handling of the new
stream with the stream move logic.
2023-09-14 12:08:48 +02:00
Wim Taymans
016d15e598 ratelimit: missed -> suppressed
To avoid confusing with missed samples.
2023-09-08 12:18:23 +02:00
Wim Taymans
dc07c2321b spa: add spa_ratelimit 2023-07-11 19:25:35 +02:00
Wim Taymans
004d3d900a pulse-server: improve debug 2023-05-24 18:01:19 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
164e343dbf remove pipewire/private.h includes when possible
In many places this is not needed.
Expose pw_impl_node_set_param() for adapter.
2023-01-20 16:08:38 +01:00
Wim Taymans
a0adb52124 pulse-server: add a pulse.idle.timeout option
When a client is not sending any data when it should be and causes an
underrun, mark it as idle and record the timestamp.

When a client is idle for pulse.idle.timeout seconds, set the stream
as inactive. When more data is received, set it back to active.

Add a pulse.idle.timeout option to set a global server default or
a per-stream value. Set the server default to 5 seconds. A value of 0
can be used to disable this feature.

With this change, badly behaving clients that are not sending any data
will be paused so that the sinks can suspend to save battery power.

Fixes #2839
2022-11-20 16:20:05 +01:00
Wim Taymans
fc159be9c6 pulse-server: make method to pause/resume stream
Make a method to pause and resume a stream and keep track of the paused
state of the stream. Use this function instead of setting the stream
inactive/active so that we get nice logging for each state change.
2022-11-20 16:19:24 +01:00
Wim Taymans
d5bc6aa2cb Revert "pulse-server: Handle clients that send more than requested"
This reverts commit a79b5c86ea.
2022-09-08 09:06:02 +02:00
Wim Taymans
a79b5c86ea pulse-server: Handle clients that send more than requested
A client can sometimes send more data than we requested. PulseAudio
keeps the extra data around, it just asks for more data when it consumed
some of it.

PipeWire however always tries to keep tlength worth of data, as
specified in the PulseAudio docs... Keep track of how much extra data
has been sent and keep this around as well. Make sure we flush this
extra data as well.

Fixes #2626
2022-09-07 13:07:28 +02:00
Wim Taymans
efe30d5075 pulse-server: send STREAM_MOVED messages
Keep track of the last known peer of a stream and send a moved message
when it changes.

Fixes #2407
2022-06-03 16:59:08 +02:00
Wim Taymans
ce03fc7c15 pulse-server: increase maxlength to match tlength
When we need to increase tlength because of a quantum change, increase
maxlength as well, but clamp it to MAXLENGTH.

See #2069
2022-01-28 16:23:42 +01:00
Wim Taymans
5ead4507cc pulse-server: ensure tlength <= maxlength
See #2069
2022-01-28 16:15:26 +01:00
Wim Taymans
1b0252c267 Revert "pulse-server: don't ask data when corked"
This reverts commit 3b14afe317.

Breaks mpv..
2022-01-25 13:23:58 +01:00
Wim Taymans
3b14afe317 pulse-server: don't ask data when corked
Don't ask for data when we are corked. Some clients like telegram
don't send data when corked.

See #2041
2022-01-25 13:18:56 +01:00
Wim Taymans
4f57f3cdae pulse-server: allow per-application latency quirks
Make it possible to set latency and buffer parameters in the matching
rules.

Add a rule for speech-dispatcher and force it to some larger latency.
2022-01-22 16:17:09 +01:00
Wim Taymans
6394537dbd pulse-server: remove unused field
And it's not quite useful to debug the value either.
2022-01-14 10:41:11 +01:00
Wim Taymans
982758ffed pulse-server: calculate missing bytes differently
Based on patch from Barnabás Pőcze <pobrn@protonmail.com>

Instead of trying to keep track of the missing bytes ourselves, use the
simple tlength - avail - requested formula to request more bytes from
the client.

Fixes #1981
2022-01-10 15:08:52 +01:00
Barnabás Pőcze
6f412236d5 pulse-server: stream: only remove from list if pending
Only call `spa_list_remove()` in `stream_free()` if the
stream is pending. `spa_list_remove()` does not reinitialize
the list node, therefore calling `spa_list_remove()` again
after the stream has been removed from the pending list
will corrupt the pending list of the client.
2021-12-26 19:37:41 +00:00
Barnabás Pőcze
cc12188763 pulse-server: move parts of stream creation
Move some portions of the client creation logic into stream.c
so that it is easier to keep it in sync with `stream_free()`, etc.
2021-12-26 19:37:41 +00:00
Wim Taymans
3c66d46007 pulse-server: recalculate tlength on quantum change
Always reevaluate the tlength or total buffered samples when the
quantum changes, even for the first sample because it is possible that
we completely miscalculated the length when we started, like when the
quantum is force high and the requested latency is low.

Also only increase the calculated tlength, for smaller sizes we don't
need to do anything, we can keep the latency as is it.

See #1930
2021-12-20 17:33:55 +01:00
Wim Taymans
c8fc79bad2 Revert "pulse-server: only try to increase the tlength"
This reverts commit 7f0255f4ce.

Doesn't work with small quant for some reason.
2021-12-16 17:10:38 +01:00
Wim Taymans
7f0255f4ce pulse-server: only try to increase the tlength
PulseAudio only tries to increase tlength, never decrease so let's
do the same.
2021-12-16 17:08:23 +01:00
Wim Taymans
1f4254b344 pulse-server: track quantum and update tlength
Keep track of the current quantum and recalculate the tlength in the
same way that pulseaudio does.

Send a bufferattr changed message to a client when we change the
parameters.

This fixes the case where the quantum is increased and there needs to be
more buffering to keep the stream going.
2021-12-14 15:48:54 +01:00
Wim Taymans
6b81be5ac3 pulse-server: update the in_prebuf state
Move out of prebuf when we reach the prebuf amount of data. Go back to
prebuf when we run empty.
2021-12-14 15:47:19 +01:00
Wim Taymans
a8139b7acf pulse-server: handle prebuf state better
When we have a prebuf value, we start in the prebuf state.
We go back to prebuf when we have a prebuf value and an empty
ringbuffer.
2021-12-03 17:49:59 +01:00
Wim Taymans
743f699193 pulse-server: try to not put pointers in info messages
It's not very helpful, prefer to use human readable strings and move the
more techincal stuff in debug messages.
2021-11-05 16:22:22 +01:00
Peter Hutterer
52a96bb602 modules: add log topics to module-protocol-pulse
This ends up using a nested namespace: mod.protocol-pulse for the module
itself, mod.protocol-pulse.foo for the various submodules and
extensions.
2021-09-28 09:35:39 +02:00
Julian Bouzas
b136bb8ca5 pipewire-pulse: delay create stream reply if the peer is not found
When the client adapter is configured in passthrough mode, the stream param
changed event in pipewire-pulse is emitted before the session manager creates
the link, and not after. Therfore, the peer can never be found when replying
create stream, and the pulseaudio application receives a stream error.

This patch delays the create stream reply until the link is added if the peer
cannot be found, fixing the above race conditon to allow passthrough mode to
work with pulseaudio applications.
2021-08-30 08:01:52 +00:00
Torkel Niklasson
eff67c3c03 Add log level argument to ratelimit_test function
If a log message is rate limited, we only need to know about it if we
are actually interested in that log level. We therefore add an argument
to the ratelimit_test function to set the log level of the message
printed if a message is skipped

Change-Id: I5ccd4a78bf7e972fe8b0e7133cd7e08c1e38835f
2021-08-12 18:59:31 +00:00
Wim Taymans
9f6890e10e pulse-server: improve stream cleanup
First disconnect the stream this ensures no more process events are
called. Then flush out the pending events, then destroy the stream.

Fixes #1451
2021-07-26 11:48:00 +02:00
Wim Taymans
d14c383811 pulse-server: silence UNDERFLOW warning to info
Creating underflows is standard behaviour for many clients. PulseAudio
does not warn about this so we should not either.

Fixes #910
2021-07-03 21:14:48 +02:00
Barnabás Pőcze
49d31ea0af pulse-server: split out reply, operation, client, stream
Part of !776.
2021-06-25 03:23:27 +02:00