Commit graph

4111 commits

Author SHA1 Message Date
Barnabás Pőcze
f81f2f8d38 treewide: fix C++20 compilation error wrt. designated initializers
C++20 introduced designated initializers similar to the ones found
in C99, however, in C++ designated initializers cannot be mixed
with non-designated initializers. GCC rejects mixed initializers
with an error.
2025-02-14 16:30:23 +01:00
Wim Taymans
03e198a130 alsa: clean up followers and our driver link in _clear
When we are going to be freed, make sure we remove ourself from the
driver list and also remove all the followers that we might still have.

Fixes #4355
2024-10-22 10:23:28 +02:00
Pauli Virtanen
f5d544d996 bluez5: don't exit if system DBus goes down
Similarly as in spa_dbus, don't exit if bus goes down.  Neither the
audio or midi Bluetooth backend reconnects to DBus, but they shouldn't
exit the process.
2024-10-22 10:23:24 +02:00
Pauli Virtanen
bdae0b2ffa bluez5: add quirk for Phonak hearing aids 2024-10-22 10:23:09 +02:00
Wim Taymans
1782728eee adapter: increase max-retry to 64
When the follower doesn't produce enough data for this many attempts,
bail and cause an xrun to avoid an infinite loop.

The limit of 8 cause real-life problems and should be larger. It should
probably depend on the expected size per cycle (node.latency) and the
current quantum but we don't always have this information.

See #4334
2024-10-21 10:12:02 +02:00
Wim Taymans
773a3a338d spa: fix event pod type 2024-10-21 10:07:11 +02:00
Hans de Goede
c5da2e30dc spa: v4l2: Use systemd-logind to listen for access changes
There is a race between logind applying ACLs to allow the active session
of a locally present user access to devices with a udev uaccess tag
(like /dev/video# nodes) getting applied vs wireplumber/pipewire starting.

Wireplumber/pipewire are part of the (user) default.target, which gets
started as soon as a user logs in and systemd --user is started for that
user, where as logind only starts applying the ACLs after the gnome-shell
associated logind session has been created.

This race may cause pipewire to not see v4l2 video sources at login,
this can be reproduced with these steps:

1. sudo setfacl --remove-all /dev/video*
2. systemctl --user restart pipewire
3. Now wp-ctl status will not show any video devices
   (like if pipewire was started before the udev uaccess ACLs got applied)
4. Do a switch to another (test) user without logging out, e.g. in GNOME
   go to the top right system menu press the power on/off icon and select
   "Switch User..."
5. Switch back to your normal user. Run getfacl /dev/video0 this will show
   your user has access now.
6. wp-ctl status should show the camera now, but it does not.

Fix pipewire not seeing v4l2 sources in this case by making v4l2-udev
monitor systemd-logind session changes and redoing the access() checks
on /dev/video# nodes when the session changes.

Closes: #3539
Closes: #3960
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit 2a6ba61264)
2024-10-12 15:19:49 +02:00
Hans de Goede
f45926c38e spa: v4l2: Remove start_inotify() call from impl_on_fd_events()
The spa_loop_add_source() call for udev event monitoring which uses
impl_on_fd_events() is done from start_monitor() which also unconditionally
calls start_inotify().

Since start_monitor() already always calls start_inotify() there is no
scenario where start_inotify() has not been called yet when
impl_on_fd_events() gets called. So the start_inotify() call in
impl_on_fd_events() is redundant, remove it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit ab245947e5)
2024-10-12 15:19:49 +02:00
Hans de Goede
d679ea840f spa: v4l2: Remove start_watching_device() loop from start_inotify()
Now that start_monitor() (which calls start_inotify()) is called before
enum_devices() it no longer is necessary to call start_watching_device()
for devices which have been enumerated before start_inotify() gets
called (since there will not be any such devices anymore).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit 46f89d8009)
2024-10-12 15:19:49 +02:00
Hans de Goede
17e6d88a6e spa: v4l2: call start_monitor() before enum_devices()
This fixes 2 races wrt probing v4l2 devices:

1. Before this change there was a window where a new udev device can get
added between the udev_enumerate_scan_devices() call in enum_devices() and
the udev_monitor_enable_receiving(this->umonitor); call. If this window was
hit then enum_devices() would not see the device and no udev-event for it
would be received either causing the device to not be seen.

Enabling udev event monitoring before calling udev_enumerate_scan_devices()
fixes this. Note that the code is already prepared to deal with getting
multiple add/change events for the same udev device, so hitting the new
race window where PipeWire may receive both an add- or change-event and
also sees + probes the device from enum_devices() is not a problem.

2. Before this change devices added by enum_devices() would not have
inotify monitoring activated right away because notify.fd = -1 at this
time turning start_watching_device() into a no-op.

These devices without inotify monitoring would then have their access
checked by process_device() calling check_access().

Then after all devices have been enumerated start_monitor() would call
start_inotify() which calls start_watching_device() for all devices added
by enum_devices(). This leaves a window where the ACL can change without
there being an inotify watch for it.

Calling start_monitor() before enum_devices() puts start_inotify()
notify before enum_devices() so that the add_device() calls done
by enum_devices() will now successfully call start_watching_device()
closing this window.

PipeWire is somewhat likely to not notify ACL changes because of this
because PipeWire is part of the systemd user default.target, where as
logind only starts applying the ACLs after GNOME has created the seat
for the GNOME session. So on first login we have PipeWire starting
and logind applying the ACLs at the same time, which allows for the ACL
change to hit the small race window where PipeWire is not monitoring
for ACL changes. Fixing this second race should hopefully resolve
issue #3960.

Closes: #3960
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit 584168caab)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
9599e7e394 spa: alsa: react to "new" udev action as well
Previously, only "change" and "remove" were considered.

(cherry picked from commit 84699032be)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
062a1039e9 spa: alsa,v4l2: avoid double access check on inotify events
Previously both `impl_on_notify_events()` and `process_{device,card}()`
called `check_access()`. Avoid that by merging `ACTION_ADD` and
`ACTION_DISABLE` into a single `ACTION_CHANGE` and let `process_{device,card}()`
call `check_access()` and decide what to do.

(cherry picked from commit ad975c93ee)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
37031a21ea spa: v4l2: handle IN_IGNORED events from inotify
(cherry picked from commit 0158b5dcb6)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
e19d9784cf spa: alsa,v4l2: avoid double lookup on inotify events
Split up `process_{device,card}()` to have a separate function that does
the lookup based on the udev device, and only use that when there is
no available reference to the actual device/card object.

(cherry picked from commit 69f9e75458)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
d9fd1d4b28 spa: v4l2: use proper log topic in udev monitor
(cherry picked from commit 57a5417703)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
6aea34ff72 spa: alsa,v4l2: use proper enum for action
An enum provides better debugging experience
and makes the source code easier to grasp.

(cherry picked from commit 5fa34988fa)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
dd03036667 spa: alsa: handle IN_IGNORED instead of IN_DELETE_SELF
`IN_IGNORED` event is sent whenever the watch is removed,
which includes when the entity is deleted among other things,
so watch that instead of the more specific `IN_DELETE_SELF`.

(cherry picked from commit 04b8a0c215)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
98f2b18277 spa: alsa,v4l2: simplify inotify read loop exit condition
The removed condition is strictly a subset of the condition
that is checked one line below, so remove it.

(cherry picked from commit 18cfb808bd)
2024-10-12 15:19:49 +02:00
Barnabás Pőcze
2a02ef384d spa: v4l2: remove ignored flag
Nothing sets it.

(cherry picked from commit 66c7966b75)
2024-10-12 15:19:49 +02:00
Wim Taymans
5b6fae48d3 v4l2: include config.h to check for udev
(cherry picked from commit 1de71d96c6)
2024-10-12 15:19:49 +02:00
Wim Taymans
3a4374ec09 meson: fix build with missing libudev-devel
(cherry picked from commit b4c7973d49)
2024-10-12 15:19:49 +02:00
Wim Taymans
2e52930c16 spa: avoid C23 empty initializers in the headers
Patch by Petar Popovic to avoid using empty initializers in headers.

Fixes #4317
2024-09-27 15:06:56 +02:00
Alper Nebi Yasak
2767c65b06 acp: sync the mixer after selecting the port
Otherwise we might sync the wrong port and end up muted.

Fixes #4084
2024-09-27 15:06:41 +02:00
Wim Taymans
b2ce24e20e v4l2: queue dropped first buffer again
When we drop the first buffer to avoid timestamp problems, queue it
again in the driver or else we will not be able to dequeue is again
later and we will be running with a buffer less.
2024-09-19 09:49:53 +02:00
Severin von Wnuck-Lipinski
55dc9c3c27 bluez5: backend-native: Handle AT+CCWA command
Claim that call waiting notifications are supported.
Required for some devices (e.g. Soundcore Motion 300),
as they stop sending commands if the reply to CCWA is not OK.
2024-09-17 11:35:54 +02:00
Wim Taymans
bc435dc6f3 audioadapter: recheck formats when EnumFormat changes
When the follower has new EnumFormat, make sure we recheck the formats
the next time the node is started.
2024-09-17 11:18:43 +02:00
Wim Taymans
29595ca7bf audioadapter: clear buffers when format is reconfigured
Always clear the Buffers when the format is reconfigured because they
depend on the Format.
2024-09-17 11:18:43 +02:00
Wim Taymans
0f08f54ef3 thread: make it possible to set a custom create function
Make a property to pass a custom function pointer to create threads
instead of pthread_create.

Use this in jack instead of bypassing the thread utils create function,
which gives the wrong thread rt priority with rtkit.

Fixes #4099
2024-08-07 10:46:52 +02:00
Wim Taymans
7114e9a31a v4l2: Improve format and control enumeration
Use dynamic pod builder so that we can also build complex formats.

Make sure we zero the format before we parse it or else we end up with
potentially uninitialized values.

When ENUM_FRAMESIZES or VIDIOC_ENUM_FRAMEINTERVALS return EINVAL for the
first index, make a dummy result and continue with that. This will
trigger an intersect withe filter so that we end up with something valid
instead of nothing.

Handle 0 framerates without crashing.

See #4063
2024-08-07 10:44:26 +02:00
Wim Taymans
bc9eb76a6e v4l2: use a dynamic pod builder to handle larger PropInfo
The labels from the vivid driver need more space so use a dynamic
builder to make sure we can handle them.

See #4063
2024-08-07 10:42:29 +02:00
Hans de Goede
b79f77b73d spa: libcamera: Increase devices_str[] buffer size
Some complex camera pipelines, like the IPU6 can involve many /dev/video#
nodes (32 in the IPU6 case) and the current size of 128 chars is not enough
to hold all /dev/video# nodes in this cases causing SPA_KEY_DEVICE_DEVIDS
to get truncated, which in turn breaks the filtering of V4L2 devices which
are used by a libcamera driven camera in wireplumber.

Fix this by increasing the size of devices_str[] to 256.

This fixes wireplumber adding a bunch of non-function V4L2 video sources,
e.g. before this "wpctl status" outputs the following video sources:

Video
 ├─ Devices:
...
 ├─ Sources:
 │      90. ov2740
 │  *  115. ipu6 (V4L2)
...
 │     135. ipu6 (V4L2)
 │
 ├─ Filters:

After this fix the output is:

Video
 ├─ Devices:
...
 ├─ Sources:
 │  *   92. ov2740
 │
 ├─ Filters:

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2024-08-07 10:40:55 +02:00
Wim Taymans
99dcf94ad3 meta: add explicit sync metadata and data type
Change the GenericFd data type to SyncObj. It's probably better to
explicitly state the data type than to make something generic. Otherwise
we would need to transfer the specific fd type somewhere else and there
is no room for that in the buffer and the the metadata is not a good idea
either because it can be modified and corrupted at runtime.

Add the SyncTimeline metadata. This contains 2 points on two timelines
(SyncObj datas in the buffer). The buffer can be accessed when the
acquire_point is signaled on the timeline and when the buffer
can be released, the release_point on the timeline should be signaled.
2024-08-07 10:05:02 +02:00
Wim Taymans
350416768e buffers: add support for mandatory metadata
Add a SPA_PARAM_BUFFERS_metaType in the Buffers object. This contains a
bitmask of the mandatory metadata items that should be included on a
buffer when using this Buffers param.

Make the buffer allocation logic skip over the Buffers params that
require unavailable metadata.

This can be used to, for example, enforce specific metadata to describe
extra buffer memory (such as the meaning of generic file descriptors).

One such use is the explicit sync, where an extra buffer data is needed
for the sync fd along with metadata that contains the sync_point.
2024-08-07 10:05:02 +02:00
Wim Taymans
a3a2ac9d7c spa: fix compilation with -Werror=float-conversion 2024-06-18 12:29:10 +02:00
Wim Taymans
3c9bd37fa1 acp: handle some errors better
Handle allocation failure and size overflow.
2024-05-24 11:01:06 +02:00
Pauli Virtanen
6ee9e62787 spa: fix integer overflows etc. in spa_pod_compare_value
Add macro SPA_CMP to do 3-way comparisons safely, and use it to avoid
signed integer overflows.

Fix also float/double comparisons (previously 0.1 == 0.8 since cast to
return type int).

Fix Id/Bool comparisons so they can return negative value.
2024-05-24 11:01:06 +02:00
Pauli Virtanen
2335657343 bluez5: media-sink: keep one more buffer free
We delay the audio a bit to keep packet intervals equal, which keeps
some data in buffers.

In theory the calculation keeps one buffer free, but it doesn't
explicitly keep "extra" buffer space so in theory might flush too late
and next process() might not have free buffers.  However, as we encode
next packet right away this shouldn't really occur...

Try to keep one extra spare buffer free so that the flush time is
certainly early enough.
2024-05-06 18:21:33 +03:00
Pauli Virtanen
513495eaaa bluez5: drop queued data on node stop
Clear queued buffers when stopping consuming, to ensure that all buffers
are usable when we start again.

Do for A2DP as we already do for SCO.
2024-05-06 18:21:29 +03:00
Robert Mader
60deeb2555 spa: libcamera: fix RGB mappings
Libcamera formats are generally little-endian, matching DMA DRM
fourccs, while PW ones are big-endian. Thus we have to invert the
order.

Only RGB and BGR where tested, as these are the formats currently
supported by the software ISP. This fixes inverted red and blue in
Snapshot on the Librem5 and Pinephone (OG).

See also gstlibcamera-utils.cpp in libcamera.
2024-05-06 09:53:50 +02:00
Pauli Virtanen
bb54e32e8a json: fix high surrogate escapes
Surrogate escapes must add not or 0x10000, as the specified bits go up
0xfffff.
2024-05-06 09:53:08 +02:00
Barnabás Pőcze
f524271b81 treewide: fix errno assignments
Do not set `errno` to a negative value.
2024-05-03 12:12:05 +02:00
Lukas Rusak
1b115eaf31 alsa-pcm: don't force quantum for iec958 formats
This fixes an issue introduced in 771f71f622
where the quantum is forced and may break applications the specify their
own quantum.

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
2024-05-03 12:10:54 +02:00
Pauli Virtanen
d3980f7cef journal: prepend code location to messages at debug log levels
Debug and trace log messages are often written based on the stderr
logging, where code location is always visible.

journalctl does not show the code location without extra tricks,
which makes user-submitted debug logs from journal more cryptic.

Make journal log more similar to stderr logs by prepending the code
location and log level in the log message when the log topic
level is >= DEBUG.
2024-04-29 16:30:06 +02:00
Barnabás Pőcze
8a4ff447d9 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-29 16:19:15 +02:00
Wim Taymans
5066ea9a72 v4l2: fix printf format 2024-04-23 11:16:40 +02:00
Ashok Sidipotu
7728586601 spa: v4l2: encode device id into a json array 2024-04-23 11:16:40 +02:00
Ashok Sidipotu
4c19da1127 spa: libcamera: encode device ids into a json array 2024-04-23 11:16:40 +02:00
Wim Taymans
17a2c21573 audioconvert: also clamp monitor volume to min/max
When we set a min/max value, also clamp the monitor volume to it.

Fixes #3962
2024-04-16 09:56:48 +02:00
Wim Taymans
b5284791fc v4l2: handle empty properties gracefully
When a property is not found or is empty, go on to the next format
instead of failing.

See #3959
2024-04-10 11:10:20 +02:00
Adam Gensler
582dcf773d Update 90-pipewire-alsa.rules with support for Astro Mixamp Pro TR. 2024-04-02 13:30:02 +02:00