Commit graph

5495 commits

Author SHA1 Message Date
Wim Taymans
b09c8d79c5 filter-graph: sync_volume initializes the control ports
Setting the volume control ports with a volume param also initializes
the controls. This ensures the controls are not restored to their
default value when the graph is activated.

Fixes #5192
2026-05-20 11:39:54 +02:00
Wim Taymans
3563728e03 audioconvert: add dither noise even on empty input
When we are asked to add noise bits, don't call the clear function.

Make the passthrough and clear-on-empty flags available with a new flag
field to make it more extensible.

Fixes #5260
2026-05-18 17:38:46 +02:00
Wim Taymans
aae60d8db3 filter-graph: relax LADSPA plugin loading
Make a new library.filter-path for the filter-graph that will filter and
restrict the dlopen filenames (used for the LADSPA plugin only).

By default this is false and so filter-chain can load from absolute
paths without extra checks.

Enable the extra checks for the pulse LADSPA modules and the
audioconvert filter graphs because these allow loading LADSPA plugins
into other processes.

Fixes #5222
2026-05-18 17:31:51 +02:00
Wim Taymans
768895bdd5 alsa: fix warning about sign 2026-05-11 09:39:33 +02:00
Barnabás Pőcze
c6b5767c8a spa: alsa: pcm: spa_alsa_clear(): clear pointers
Use `spa_clear_ptr()` to ensure that all freed pointers are cleared.
2026-05-11 09:38:33 +02:00
Barnabás Pőcze
bf57911b83 spa: alsa: pcm: log_write(): return early if log level is disabled
If the "debug" log level is not enabled for the "spa.alsa" log topic,
then there is no point in going into the loop and splitting the data
into lines, so skip that.
2026-05-11 09:36:29 +02:00
Barnabás Pőcze
320fe9a6a0 spa: alsa: pcm: log_write(): don't use strcspn()
Do not use `strcspn()` because it assumes a null terminated string,
but the `fopencookie()` write callback receives a (ptr, length) pair.

So use `memchr()` instead to find the `\n`.
2026-05-11 09:36:20 +02:00
Barnabás Pőcze
892d2cb54e spa: alsa: pcm: log_write(): fix return value
The `fopencookie()` write callback should return the number of consumed
bytes, but it currently only ever returns 0, which signals an error
condition according to the documentation.

Fix that by not overwriting `size`.

Fixes: 73073eb33f ("alsa: redirect alsa output to log file")
2026-05-11 09:36:13 +02:00
Barnabás Pőcze
5ea19f5fca treewide: mark fopencookie() vtable const
`fopencookie()` takes the vtable by value, so it can be marked `const`, so do that.
2026-05-11 09:36:00 +02:00
Martin Geier
6affbf9cf2 audioconvert: update rate also for nodes with disabled resampler
When the graph rate changes it is possible that the follower node can
renegotiate to the new suggested audioconvert rate without requiring
resampling and so the extra check for the disabled resampler is not
required.

Fixes #4933
2026-05-08 15:53:17 +02:00
Wim Taymans
3730528419 bluez5: fix wrong use of F_GETFL and F_SETFL
The pattern is to F_GETFL the flags, then clear the NONBLOCK flag and
then F_SETFL the new flags.
2026-05-08 14:53:01 +02:00
Barnabás Pőcze
e5b741732d treewide: make more file descriptors cloexec
Avoid file descriptor leakage into child processes by marking them `O_CLOEXEC`.
2026-05-08 14:53:01 +02:00
Wim Taymans
2bfdc36954 filter-graph: guard against overflow of graph input/output 2026-05-08 14:52:54 +02:00
Wim Taymans
e8bf06ea56 security: add missing O_CLOEXEC flag to V4L2 device open
File and Resource Handling: Medium

The V4L2 device file descriptor was opened without the O_CLOEXEC flag.
If a child process is subsequently spawned (e.g., via fork+exec), the
video device fd would be inherited, potentially allowing the child
process unauthorized access to the camera device.

Fixed by adding O_CLOEXEC to the open() flags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 13:53:17 +02:00
Wim Taymans
4d7c448150 security: add missing O_CLOEXEC/SOCK_CLOEXEC flags
File and Resource Handling: Medium

Several file and socket operations were missing the close-on-exec flag,
which causes file descriptors to leak to child processes created via
fork+exec. This could allow child processes unintended access to
privileged resources.

- node-driver.c: SOCK_DGRAM socket for SIOCETHTOOL ioctl leaked to
  child processes
- pw-container.c: Unix domain listen socket leaked to spawned
  container processes
- compress-offload-api.c: ALSA compress-offload device fd leaked to
  child processes

Added O_CLOEXEC to open() calls and SOCK_CLOEXEC to socket() calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 13:52:53 +02:00
Wim Taymans
0b11792194 filter-graph: error when there are no valid nodes
The nodes might have failed to load or there was an empty array or the
array did not contain objects.
2026-05-08 13:28:28 +02:00
Wim Taymans
4a303edb9e spa: limit the number of buffer blocks
Unbounded values might overflow the stack.
2026-05-08 12:17:50 +02:00
Wim Taymans
3a503ea4b6 filter-graph: remove the pipe filter
It's a terrible idea, doesn't work so well (locks up the data-loop when
read is blocked) and a security mightmare. If you really need to pipe
samples through some program, do that somewhere else, like from the
command line with pw-cat and pw-record.
2026-05-08 12:03:37 +02:00
Wim Taymans
82dbfd558f acp: partially revert f76327e076
The Line Out mute seems to break things.

See #5246
2026-04-28 12:11:53 +02:00
Wim Taymans
8bf7ae5e74 audiomixer: rate limit the "out of buffers" debug
See #5249
2026-04-28 12:11:42 +02:00
zuozhiwei
e01ff7e67e audioconvert: fix tmp_datas[1] when scratch ports grow 2026-04-21 17:17:31 +02:00
Masum Reza
cf8a0b012f alsa: acp: don’t override user-selected port on availability changes
ACP was re-selecting the “best” port on every port availability event,
even when a port was already explicitly selected by the user. This
differs from PulseAudio’s behavior, where port switching decisions are
left to higher-level policy.

This caused issues on devices where Line Out (speakers) and Headphones
share the same analog interface: when headphones are plugged in, ACP
would immediately switch away from the user-selected Line Out, or end up
in a state where no sound is produced despite selecting speakers explicitly from
clients like pwvucontrol.

Fix this by only re-evaluating and switching ports when:
  - no active port is currently selected, or
  - the active port has become unavailable

This preserves manual user choices and prevents ACP from fighting client
port selections during route activation.

Additionally, adjust ALSA mixer paths to better separate Line Out and
Headphones behavior:
  - Disable Line Out controls in the headphones path
  - Add explicit Line Out and Auto-Mute Mode handling in the lineout path

Together, these changes align PipeWire’s behavior more closely with
PulseAudio and fix cases where selecting speakers while headphones are
plugged results in no audio output.

Signed-off-by: John Titor <masumrezarock100@gmail.com>
2026-04-21 17:15:05 +02:00
Pauli Virtanen
04af44d5c3 bluez5: more MT7925 quirks
The MT7925 chipset has several alternative USB ids recognized by kernel,
list them all.

(cherry picked from commit cee1bdfb5a)
2026-04-19 19:15:23 +03:00
Pauli Virtanen
bb6199214d bluez5: add quirk for LC3-24kHz for HFP
MT7925 fails to setup a SCO connection that results to working LC3-24kHz
audio. Other controllers (Intel etc) appear to work OK.

Add quirk for disabling this codec, and disable it for this Mediatek
controller.

(cherry picked from commit 84e6845aa6)
2026-04-19 19:15:23 +03:00
Pauli Virtanen
b2028a03f0 bluez5: fix disabling HFP codecs via bluez5.codecs
backend-native should not advertise disabled HFP codecs as available.

(cherry picked from commit 6e8e234e61)
2026-04-19 19:15:23 +03:00
Martin Geier
c148028f5a bluez5: iso-io: don't use streams without tx_latency enabled for fill level calculation
When there is a stream without tx_latency enabled, the fill_count ends
with MIN_FILL value. This causes one buffer of silence to be written to
every stream before the actual data in each iteration.
Consequently, more data is written than consumed in each iteration.
After several iterations, spa_bt_send fails, triggering a
group_latency_check failure in few next iterations and leading to
dropped data.

Skip streams without tx_latency enabled in fill level calculations
to prevent these audio glitches.

(cherry picked from commit 42415eadd9)
2026-04-19 19:15:23 +03:00
Alexander Sarmanow
78888a78c3 bluez5: bap: add support for manual BIS config
(cherry picked from commit 54a4515b09)
2026-04-19 19:15:23 +03:00
ValdikSS
5918e6f05d bluez5: aac: Use VBR encoding with Mode 5 by default
(cherry picked from commit ee1b429441)
2026-04-19 19:15:23 +03:00
ValdikSS
cb1d19e433 bluez5: aac: use higher band limit for CBR mode
FDK-AAC encoder uses band pass filter, which is automatically
applied at all bitrates.
For CBR encoding mode, its values are as follows (for stereo):

* 0-12 kb/s:   5   kHz
* 12-20 kb/s:  6.4 kHz
* 20-28 kb/s:  9.6 kHz
* 40-56 kb/s:  13  kHz
* 56-72 kb/s:  16  kHz
* 72-576 kb/s: 17  kHz

VBR uses the following table (stereo):

* Mode 1: 13   kHz
* Mode 2: 13   kHz
* Mode 3: 15.7 kHz
* Mode 4: 16.5 kHz
* Mode 5: 19.3 kHz

17 kHz for CBR is a limiting value for high bitrate.

Assume >110 kbit/s as a "high bitrate" CBR and increase the
band pass cutout up to 19.3 kHz (as in mode 5 VBR).

Link: d8e6b1a3aa/libAACenc/src/bandwidth.cpp (L114-L160)
(cherry picked from commit a35b6b0c4b)
2026-04-19 19:15:23 +03:00
ValdikSS
cc71d011e0 bluez5: aac: use maximum possible peak bitrate according to MTU
Android 11 and newer, in both CBR and VBR modes,
* Sets bitrate (AACENC_BITRATE) to the max_bitrate value of A2DP
* Sets peak bitrate (AACENC_PEAK_BITRATE) according to the maximum data
   which could fit into single audio packet based on MTU

AACENC_BITRATE is used only in CBR mode. For VBR mode, the only limiting
factor is AACENC_PEAK_BITRATE.

Do the same in Pipewire.

Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/work_items/1482#note_2949680
Link: https://cs.android.com/android/platform/superproject/+/android16-qpr2-release:packages/modules/Bluetooth/system/stack/a2dp/a2dp_aac_encoder.cc;drc=37d7b4549f7b8740df1a290f04c20c591a2d3391;l=269
(cherry picked from commit 49d5f4f236)
2026-04-19 19:15:23 +03:00
Wim Taymans
e0697f52c3 alsa-seq: add : between client and port name
The separator is important for applications to find the client name and
group ports.

Fixes #5229
2026-04-16 10:19:05 +02:00
zuozhiwei
b0f719edd4 alsa: fix inverted port validity check in port_reuse_buffer
The CHECK_PORT condition in impl_node_port_reuse_buffer was inverted with a negation operator, causing the function to reject valid output ports and accept invalid ones.

Fixes the logic so that valid ports proceed to buffer recycling and invalid ports are properly rejected.
2026-04-16 10:18:58 +02:00
Wim Taymans
db0fa4b419 filter-graph: allow negative Gain in mixer
To allow for polarity changes.

Fixes #5228
2026-04-16 10:18:47 +02:00
Wim Taymans
d9b6153123 alsa-seq: remove port from mix_list on destroy
When the port is destroyed we need to remove it from the mix_list or
else the process function will keep trying to use the invalid memory.

This is because the port logic does not want to call any functions on
the port (like clearing the IO or Format) after it emitted the destroy
signal and we need to clean up ourselves.

Fixes #5221
2026-04-16 10:18:30 +02:00
Wim Taymans
8be0d7534b dlopen: support search path ending in /
When the search path is /usr/lib/, /usr/lib/foo.so fails to load because
there is no / after the search path. Fix this by requiring that either
the search path end with / or the following char is a /.
2026-04-16 10:18:03 +02:00
Wim Taymans
d6adf944df filter-graph: return current control value correctly
The control values are only set in the port control_data after the
filter has been activated and the instances are created.

Property enumerations might happen before that and then we can either
return the current_value (when set in a control section or later with a
param property) or the default value.
2026-04-08 17:55:33 +02:00
Wim Taymans
821b62dac5 dlopen: improve prefix check some more
If we pass a path /usr/libevil/mycode.so, it might have a prefix of
/usr/lib but we should still reject it. Do thi by checking that after
the prefix match, we start a new directory.
2026-04-08 16:22:04 +02:00
Wim Taymans
fd867cf655 mixer: handle control.ump property
Add a control.ump port property. When true, the port wants UMP and the
mixer will convert to it. When false, the port supports both UMP and
Midi1 and no conversions will happen. When unset, the mixer will always
convert UMP to midi1.

Remove the CONTROL_types property from the filter. This causes problems
because this is the format negotiated with peers, which might not
support the types but can still be linked because the mixer will
convert.

The control.ump port property is supposed to be a temporary fix until we
can negotiate the mixer ports properly with the CONTROL_types.

Remove UMP handling from bluetooth midi, just use the raw Midi1 events
now that the mixer will give those and we are supposed to output our
unconverted format.

Fix midi events in-place in netjack because we can.

Update docs and pw-mididump to note that we are back to midi1 as the
default format.

With this, most of the midi<->UMP conversion should be gone again and we
should be able to avoid conversion problems in ALSA and PipeWire.

Fixes #5183
2026-04-07 10:08:14 +02:00
Wim Taymans
6a8bf93768 midi: don't convert Midi in nodes
Avoid doing conversions in the nodes between Midi formats, just assume
the imput is what we expect and output what we naturally produce.

For ALSA this means we produce and consume Midi1 or Midi2 depending on the
configurtation.

All of the other modules (ffado, RTP, netjack and VBAN) really only
produce and consume MIDI1.

Set the default MIDI format to MIDI1 in ALSA.

Whith this change, almost everything now produces and consumes MIDI1
again (previously the buffer format was forced to MIDI2).

The problem is that MIDI2 to and from MIDI1 conversion has problems in
some cases in PipeWire and ALSA and breaks compatibility with some
hardware.

The idea is to let elements produce their prefered format and that the
control mixer also negotiates and converts to the node prefered format.
There is then a mix of MIDI2 and MIDI1 on ports but with the control
port adapting, this should not be a problem.

There is one remaining problem to make this work, the port format is
taken from the node port and not the mixer port, which would then expose
the prefered format on the port and force negotiation to it with the
peer instead of in the mixer.

See #5183
2026-04-07 10:07:00 +02:00
Wim Taymans
a0c3c2d9e4 mixer: only add input ports to mixer 2026-04-07 10:05:20 +02:00
Wim Taymans
6bc07dfe0e only dlopen from the defined search paths
Don't accept absolute library paths that are not in the search path,
skip the ../ in paths to avoid opening arbitrary libraries from
unexpected places.
2026-04-07 09:51:47 +02:00
George Kiagiadakis
dcb86450c8 bluez5: parse the broadcast adapter value from the correct iterator
(cherry picked from commit 0d1280a5b2)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
35e3608d0e bluez5: media-source: don't crash if BAP streams doesn't have iso_io
Don't crash in update_target_latency() if a BAP stream doesn't have
iso_io for some reason.

(cherry picked from commit 3dff64364f)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
fb4567232d bluez5: cleanup get_codec_profile()
Check codec kinds for each direction properly when mapping to profiles
corresponding to it. Being sloppy here masked another bug, so best fix
it.

(cherry picked from commit 22a5fad902)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
99f901de06 bluez5: fix spa_bt_device_supports_media_codec() for HFP codecs
HFP codecs don't have a direction dependent "target" profile, and this
function was returning false if A2DP is disabled.

Don't check target profile for HFP, leave checks to backend.

Fixes HFP-only configurations, which were missing profiles.

(cherry picked from commit 75c3d3ecf8)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
929be3252f bluez5: sbc: clean up codec_enum_config
Non-spec compliant devices may set multiple bits in code config, which
we currently reject in validate_config().

enum_config() does work to deal with multiple bits set, but this is
never used, so write the code in a simpler way to return a single
configuration.

(cherry picked from commit d42646e91f)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
535d2f159e bluez5: aac: for multiple bits in aot, normalize to mandatory
Non-spec compliant devices may set multiple bits in AAC AOT, which is
invalid.

In this case, we should normalize to MPEG-2 AAC LC which is the
mandatory value in spec, not to MPEG-4 AAC LC. In select_config() we
also prefer MPEG-2 over MPEG-4.

(cherry picked from commit 67b4732c26)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
97865f8550 bluez5: aac: coerce non-spec compliant freq/channels to single choice
Some non-spec compliant devices (Sony XB100) set multiple bits
in all AAC field, including the frequency & channels.

Although they set multiple bits, these devices appear to intend that the
sender picks some specific format and uses it, and don't work correctly
with the others.

validate_config() already picks one configuration, so use the result in
enum_config(), instead of allowing also other settings.

Assume devices generally want preferably 44.1 kHz stereo.

Note we cannot reject the configuration, as BlueZ does not necessarily
retry, leaving the device connected but with no audio.

(cherry picked from commit 5f8ece7017)
2026-03-30 07:44:33 +00:00
Pauli Virtanen
6b2a207fd9 bluez5: backend-native: don't crash without dbus session bus
When there is no DBus session bus, creation of the telephony backend
fails, and we later crash on null ptr deref.

In this case, avoid crash trying to create telephony_ag or iterate its
call list.

(cherry picked from commit f9e2b1d8b9)
2026-03-30 07:44:33 +00:00
Frédéric Danis
93dfae0ddf bluez5: bap: Fix typos
(cherry picked from commit ee18160c4e)
2026-03-30 07:44:33 +00:00