Commit graph

1030 commits

Author SHA1 Message Date
Wim Taymans
1957d3fb00 pulse: avoid a compiler warning 2025-07-25 17:37:56 +02:00
Demi Marie Obenour
9e789c65c2 src: check that POD arrays have the correct size for their type
The parser does not check that POD arrays have the correct size for
their type, so the calling code must do that.

This also enumerates some of the code that cannot handle the size of the
values of an array not being the exact expected size for its type.
There is a lot of it.
2025-07-24 16:27:42 -04:00
Demi Marie Obenour
fb315b9050 *: Missing bounds checks in POD handling
There were missing bounds checks for ill-formed POD all over the place.
2025-07-15 10:13:17 +02:00
Demi Marie Obenour
9a66938283 pulse: don't ignore return value
If a function can fail don't pretend it succeeded.
2025-07-10 14:06:05 +00:00
Demi Marie Obenour
b3bf5be1f6 *: Avoid macros that use casts where possible
Use direct field access when the type is known, instead of a macro that
includes a cast.

These were missed in e4fcbef89a.
2025-07-10 14:02:55 +00:00
Wim Taymans
bd7ce5c7fa pulse-server: only react to state changes when not corked
When we are starting or corked we don't emit suspend/resume caused
by state changes.
2025-06-25 10:31:32 +02:00
Arun Raghavan
220b037683 pulse-server: Implement stream suspended callback 2025-06-23 09:19:10 +00:00
Wim Taymans
b51755bc8b pulse-server: add stream_properties for RTP streams 2025-06-18 12:29:39 +02:00
Wim Taymans
83c644fe09 pulse-server: mark empty buffers
This makes it use some more optimal paths in the mixer.
2025-06-13 18:07:55 +02: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
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
Sam James
b943c31fd8
*: don't include standard C headers inside of extern "C"
Including C headers inside of `extern "C"` breaks use from C++. Hoist
the includes of standard C headers above the block so we don't try
to mangle the stdlib.

I initially tried to scope this with a targeted change but it's too
hard to do correctly that way. This way, we avoid whack-a-mole.

Firefox is working around this in their e21461b7b8b39cc31ba53c47d4f6f310c673ff2f
commit.

Bug: https://bugzilla.mozilla.org/1953080
2025-05-30 09:48:28 +01:00
Pauli Virtanen
1445843ced modules: get also instance id for flatpak apps
Add "pipewire.access.portal.instance_id" property for distinguishing
Flatpak application instances from each other.
2025-05-12 09:40:32 +00:00
Wim Taymans
a9f12537d1 pulse: clamp channel numbers to right values
When converting between pipewire and pulse channelmaps, make sure we
clamp the channel numbers to the the right limit.
2025-04-04 15:46:03 +02:00
Wim Taymans
3905e3b3d3 stream: set errno to the current error
Make the state_changed event and _get_state() function set errno with
the current error value if the state is in error, so that application
can use this to give more detailed error reporting.

Use this in alsa, v4l2 and pulse to give some other error codes than
EIO.

Fixes #4574
2025-03-04 13:22:51 +01:00
Wim Taymans
546de65c67 pulse: sanitize the remote name
We use the remote name as a suffix for the default server address and so
it should not contain any slashes. Take everything after the last slash
if there is one.
2025-01-29 12:09:36 +01:00
Wim Taymans
c62905d911 pulse-server: clear old data when jumping forwards
When we write samples, check if we make a jump in the ringbuffer and
clear the samples we jumped over.

If we don't do this, the reader side might pick up old samples that we
didn't write or clear but that are now available for reading after we
made a jump in the ringbuffer.

This migh not be exactly what pulseaudio does but it is good for now.

Fixes #4464
2025-01-16 16:21:22 +01:00
Wim Taymans
cf7e917024 pulse-server: make a function to silence a buffer 2025-01-16 16:16:39 +01:00
Wim Taymans
feaa36560d pulse-server: increase max rate to 768000
Fixes #4482
2025-01-08 17:23:15 +01:00
Pauli Virtanen
371781e214 pulse-server: fix pulse.cmd load-module not loading multiple overrides
pw_context_conf_section_for_each() stops iterating on nonzero return
value, so make sure 0 is returned on success.
2024-11-28 19:34:22 +00:00
Wim Taymans
188d920733 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-20 10:17:37 +01:00
Pauli Virtanen
e393e57a26 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-19 22:07:09 +02:00
Wim Taymans
c8c89f7517 pulse: also set channels in the map
When converting a position to a channel-map, copy the number of channels
as well.

This broke with commit e2991f6398
2024-11-12 11:55:14 +01:00
Pauli Virtanen
8d019c5689 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-10-30 19:55:39 +02:00
Wim Taymans
9243ed0cbd pulse-server: add condition support in pulse.cmd
So that a config override can disable the execution of the command by
setting the property to false in the pulse.properties config override.

Expose some conf.c method for this purpose.
2024-10-23 09:08:50 +02:00
Wim Taymans
0dfd6d997f protocol-pulse: implement readiness notification
Write a newline to the fd in the PIPEWIRE_PULSE_NOTIFICATION_FD env
variable when set.

This is to implement readiness notification as suggested in
https://skarnet.org/software/s6/notifywhenup.html

Fixes #4347
2024-10-22 09:50:27 +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
ca488a5dcc pulse-server: add quirk to block record and playback streams
Add aquirk to block any record or playback stream.
2024-09-23 10:56:40 +02:00
Barnabás Pőcze
27b76ae686 pulse-server: calculate event mask from facility and type
Make `client_queue_subscribe_event()` take the facility and type
separately, and calculate the mask itself, so that the caller
does not need to be concerned with that.
2024-09-18 19:35:08 +02:00
Wim Taymans
e2991f6398 json: add helper function to parse channel positions
Use the helper instead of duplicating the same code.

Also add some helpers to parse a json array of uint32_t

Move some functions to convert between type name and id.
2024-09-18 09:54:34 +02:00
Wim Taymans
b5cccdb382 json: add and use spa_json_str_object_find()
Parse a string as a json object and copy the value with key as a string.
2024-09-16 13:12:05 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +02:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Wim Taymans
feccb882b6 spa: add spa_json_begin
That combines spa_json_init() and spa_json_next, a common thing to do.
2024-09-16 09:50:31 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Barnabás Pőcze
b3bd026699 pipewire: remove cleanup.h
Since `spa/utils/cleanup.h` is not a private header anymore, there is
no need for a separate `pipewire/cleanup.h` since the definitions of
the cleanup routines can now be moved into the respective headers.
2024-05-16 17:35:58 +02:00
Barnabás Pőcze
46e4a33f27 pulse-server: message: use union to store event data
Store subscription event data in a union instead of
just an array for better readability.
2024-05-15 08:31:40 +00:00
Barnabás Pőcze
d467f6fdc6 pulse-server: client_queue_subscribe_event(): check message allocation 2024-05-15 08:31:40 +00:00
Wim Taymans
a30c27dce0 pulse-server: add pulse.allow-module-loading option
Add an option to disable loading and unloading of modules with the
native protocol.

Document some more options.
2024-05-06 15:28:43 +02:00
Wim Taymans
a3ccbd00b4 pulse-server: implement describe-module with core message
Implement the old pacmd describe-module command with a core message:

pactl send-message /core pipewire-pulse:describe-module
module-echo-cancel
2024-05-06 11:39:52 +02:00
Pauli Virtanen
44d958d397 pulse-server: show warning about snap kernel features only once
Don't spam the warning about kernel missing features required for snap
on every pulseaudio connection, but instead show it only once, as the
situation is not going to improve.
2024-05-01 13:17:31 +03:00
Barnabás Pőcze
6a26e6dd3f treewide: fix some format string issues
Use the proper specifier, and cast to a known type where the type
is not guaranteed by any standard.

See #3975
2024-04-25 07:24:10 +00:00
Barnabás Pőcze
4cea8eb01f pulse-server: use memcpy() to write string into message
The length of the string is already known, so use `memcpy()`
instead of `strcpy()` to copy the string into the message buffer.
2024-04-16 07:37:12 +00:00
Barnabás Pőcze
150211a3f8 pulse-server: message_dump(): fix format_info memory leak 2024-04-16 07:37:12 +00:00
Barnabás Pőcze
3fa92bbd15 pulse-server: ignore unsaveable values when deserializing property list
PulseAudio's property list can store arbitrary data, but
pw_properties can only store null-terminated strings.
So for the time being, ignore those values that don't
have null-terminators or have zero bytes inside.
2024-04-16 07:37:12 +00:00
Barnabás Pőcze
12bddf6521 pulse-server: stricter length checking when deserializing property list
The length of the value for each value in a property list is serialized
twice. Both the reference implementation and pipewire-pulse send
the same length, so be stricter and only accept a property list
if both lengths are the same.
2024-04-16 07:37:12 +00:00
Wim Taymans
c534acac46 spa: handle empty values better
Make sure the properties are not empty before trying to access them.
2024-04-10 11:08:40 +02:00
Wim Taymans
7e9e261fa6 conf: support property rules
Add pw_conf_section_update_props_rules() that will not only update the
properties of a section but wil also apply rules in section.rules and
match against the context properties.

Use this by default when using pw_context_conf_update_props().

Add a new method to get a string name of the VM type. Place the
cpu.vm.name in the context properties.

This makes it possible to deprecate the vm.overrides with something more
flexible based on rules. Update the conf files and docs to refect this.
2024-03-15 12:10:41 +01:00