Commit graph

3631 commits

Author SHA1 Message Date
Wim Taymans
14b265f646 v4l2: fix format enum with unsupported framerate
Actually count the number of frame fractions we add. If we added 0, we
don't have any supported framerate that intersects with the filter and we
try the next frame size.

See #1793
2024-01-17 09:55:47 +01:00
Pauli Virtanen
cee92e08a9 bluez5: lc3: fix wrong enum_config
The rate is not a bitmask.
2024-01-16 23:48:34 +02:00
Wim Taymans
dd8e2def4f audioconvert: remove unnecessary casts 2024-01-16 15:33:13 +01:00
Pauli Virtanen
89cdf4f6eb bluez5: move no-HFP fast connect checks to better place
Not waiting for HFP when no HFP backend should be checked via
adapter_connectable_profiles in spa_bt_device_check_profiles where the
relevant logic is.

Cleanup by moving the checks there.
2024-01-16 14:29:01 +00:00
Dmitry Sharshakov
e2844e4421 audioconvert: fix rare unaligned load exceptions
Supposed causes described in the issue. Also improve float semantics.

Fixes #3790
2024-01-16 14:22:52 +00:00
Wim Taymans
627f148665 audioconvert: also place resample output in rate_io
We can also place the estimated size that the resampler will produce in
the rate_io for output streams.

See #3750
2024-01-16 13:29:57 +01:00
Wim Taymans
05c969381d audioconvert: implement resample_out_len() 2024-01-16 13:28:37 +01:00
Wim Taymans
63e283f377 audioconvert: update initial resampler rate match
When starting the converter, calculate the initial size needed by
the resampler to fill one quantum.

This makes it possible to get the requested amount of samples before
the first process call is made.
2024-01-15 15:03:54 +01:00
Pauli Virtanen
7c9b96c606 bluez5: add quirk for SoundCore mini2
AVRCP volume doesn't work properly with this device.

Closes #2927
2024-01-14 13:21:34 +02:00
Pauli Virtanen
ea5ff6b3c1 bluez5: more informative warning with unknown transports
Unknown transports visible in DBus usually belong to a different
sound server instance that is talking to BlueZ.

Explain this in the warning message that we log, so that people can more
easily understand why things are not working.
2024-01-14 10:57:56 +00:00
Pauli Virtanen
89d86c73c4 bluez5: add quirk for Rockbox Brick 2024-01-13 12:37:57 +02:00
Barnabás Pőcze
4b145ad444 spa: libcamera: bump minimum supported version to 0.2.0 2024-01-11 12:04:27 +00:00
Barnabás Pőcze
268f4856f8 spa: libcamera: use CameraConfiguration::orientation
libcamera commit cc65629b68d49d ("libcamera: camera: Introduce Orientation") [0]
introduced to the `CameraConfiguration::orientation` member to describe the
orientation of the image in the received memory buffers.

Then c65e40b8480ffb ("libcamera: Use CameraConfiguration::orientation") [1]
removed `CameraConfiguration::transform`, which broke the libcamera plugin.

Fix that by using the new `orientation` member.

[0]: https://git.linuxtv.org/libcamera.git/commit/?id=cc65629b68d49d5f2a4d61537584c56ba510a335
[1]: https://git.linuxtv.org/libcamera.git/commit/?id=c65e40b8480ffb5f50e01a4e6713164c7194a937
2024-01-11 12:04:27 +00:00
Wim Taymans
d0a2e6316b spa: small cleanups
Initialize result variable.
Use strncpy to avoid warnings about using non-NULL terminaded strings.
2024-01-10 15:51:01 +01:00
Wim Taymans
15908328d1 support: fix freewheel timeout in node-driver
When freewheeling we will immediately schedule a new graph cycle when we
get a process call because the graph completed.

When the process call is not done, because of some xrun or
because some node was removed that causes the graph to fail completion,
The next cycle will happen after a timeout.

This timeout was calculated as the ideal wakeup time (after a quantum of
time) and would accumulate for each timeout. The result is that the
timeout ended up far in the future and would stall the freewheel driver
for a long time.

Fix this by always setting the next timeout to wakeup time + freewheel.timeout
seconds. Also add a config property for the timeout (10 seconds, like
jack2 by default).
2024-01-10 11:59:10 +01:00
Wim Taymans
c7519c73ac spa: small cleanups
Use snprint to ensure null terminated strings.
Initialize res, it would be uninitialized when setting a NULL Latency
param.
2024-01-10 11:35:54 +01:00
Pauli Virtanen
70ffbaed74 bluez5: fix node initialization to init all nodes
Now that we can have more than 4 nodes, so should init them all.
2024-01-09 08:07:33 +00:00
Pauli Virtanen
f341dfed54 bluez5: lc3: prefer 7.5 ms frame duration
According to Intel people this is better for their hardware.

Link: https://github.com/bluez/bluez/issues/713
2024-01-09 08:07:33 +00:00
Pauli Virtanen
a154169942 bluez5: support multiple BAP transports per device
In multi-ASE configurations there can be multiple transports per device,
each corresponding to different channels.

Emit sink/source nodes for each BAP transport present.

Combine them into a single sink/source in the same way as we do for
device sets.
2024-01-08 10:09:13 +00:00
Pauli Virtanen
d487dc0fc6 bluez5: bap: support ChannelAllocation parameter from BlueZ
For multi-ASE configurations, BlueZ does the channel allocation itself,
and passes us the result in the ChannelAllocation parameter.

If it is present, don't do the allocation ourselves but use that value
instead.
2024-01-08 10:09:13 +00:00
Pauli Virtanen
caebeaa9b3 bluez5: lc3: workaround bad Supported_Max_Codec_Frames_Per_SDU
If Supported_Max_Codec_Frames_Per_SDU is less than what is required by
Supported_Audio_Channel_Counts, override its value assuming the device
actually supports at least that. Needed for Creative Zen Hybrid Pro.

Fix default value for channel count bitmask.
2024-01-08 10:09:13 +00:00
Pauli Virtanen
b533b06b51 bluez5: backend-native: handle multiple commands in RFCOMM input
Do relaxed parsing of RFCOMM commands for AG & HF roles, allowing
multiple commands in same buffer.

Use same parser code for all HFP/HSP AG/HF. Parse input in relaxed way,
as some devices emit spurious \n
2024-01-06 15:42:20 +02:00
Wim Taymans
e088dd2d2f journal: copy log level to chained logger
Make sure the log level on the chained logger is the same as ours.

Makes PIPEWIRE_DEBUG=3 make run print debug again.

This used to work because the log level was parsed and set before the
loggers were created and chained, and so they all got the same level.

Now that the level can be changed with metadata at runtime, we can't
really update all past loggers so let the journal logger copy the
level itself.
2024-01-04 13:57:26 +01:00
Pauli Virtanen
53ba3d0e4c spa: support: remove log pattern support
The log patterns are now handled by plugin host.
2024-01-04 10:02:55 +00:00
Pauli Virtanen
1197b581d9 spa: use only static log topics 2024-01-04 10:02:55 +00:00
Pauli Virtanen
eaea03c26c spa: export log topic enumerations 2024-01-04 10:02:55 +00:00
Mauro Carvalho Chehab
d26916828d bluez5: update bluez-hardware.conf to ignore sbc-mq on Primark earbud
Primark True Wireless earbud doesn't support sbc-xq. Having it
enabled causes bluez to enter into a loop enabling/disabling
the device dozens of times per minute, making it unusable.
2023-12-26 16:02:22 +00:00
Dmitry Sharshakov
5edd3f240b node-driver: open PHC as readonly
RW access is usually denied to a user unit. RO might be as well but it's more safe to make /dev/ptpX just user-readable
2023-12-20 09:35:22 +00:00
Dimitrios Katsaros
1d3013f0f9 ALSA: Remove alsa timer from IRQ scheduling
As part of the setup for IRQ based scheduling, a period event
was installed. Not only is a timer based polling unecessary for
IRQ scheduling, depending on the state of the system, the timer
could fire far enough from the IRQ, causing alsa wakeup events
with no data in the ring buffer. Pipewire would identify these
events as an "early wakeup", adding an extra quantum of time
to the next_time estimate, skewing the clock and causing issues
with apps that depend on precise timing.
2023-12-13 20:56:50 +01:00
Wim Taymans
ad784ca5e6 audioadapter: improve state check
Update the started and ready state after we suspend/pause the node so
that we don't complain if scheduling happens between setting the fields
and actually stopping the follower.

Also only complain when the scheduling happens when the node is not
ready. It is possible that the node is scheduled before we manage to set
the started field.
2023-12-13 12:26:26 +01:00
Wim Taymans
27bed62e66 audioconvert: avoid bitfield data races
Move the driver and warned bits after the int field in the struct so
that they are placed in separate memory.

Otherwise, a write from the data thread might race with a write from the
main thread and leave the bits in the wrong state.
2023-12-13 12:15:11 +01:00
Wim Taymans
5980f6988a Revert "alsa: also use interpolated time as nsec in IRQ mode"
This reverts commit 49cdb468c2.

We should not do this, the nsec field should be relatable to the clock
monotonic time. If we use the estimated time, without actually using it
as a timer, we might end up with a wakeup time in the future compared to
the MONOTONIC clock time.

Instead, you can use the estimated current time simply by subtracting
the rate corrected duration from the next_nsec. This is really only
useful for some selected use cases (like in the JACK library).

This fixes some issues where in pro-audio mode, a client would try to
compare the current MONOTONIC time to nsec and find that it is in the
past.

This commit was done in an attempt to fix #3657 but it turned out the
real problem was something else.
2023-12-12 13:09:30 +01:00
Pauli Virtanen
7f2dd3531c bluez5: use only one input route
Don't have separate input route for A2DP and HFP, as it is generally not
necessary.

When in A2DP mode when there's also HFP possible, emit the input route
in SPA_PARAM_Route, even though there is no corresponding input node
emitted.

The host may then emit a loopback microphone node, and switch profiles
according to its status. Having the input route available at all times
allows to retain changes to volume settings made when there is no real
input node.
2023-12-09 14:05:50 +02:00
Kiran K
44df080482 bluez5: Add support for 32KHz for lc3 codec
Fixes: b69e089648 ("bluez5: Add support for 32KHz sampling frequency")
2023-12-08 19:15:50 +05:30
kirankrishnappa-intel
b69e089648 bluez5: Add support for 32KHz sampling frequency 2023-12-08 08:34:09 +00:00
Pauli Virtanen
92f0815e4d 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.
2023-12-05 18:37:36 +02:00
Pauli Virtanen
a9ff282501 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.
2023-12-05 18:37:36 +02:00
Pauli Virtanen
81aaf0e204 bluez5: set io status properly when sink is not going to consume
When sink is not ready to consume buffers, set io and status to indicate
it already has data.
2023-12-05 18:37:36 +02:00
Wim Taymans
758805d65d alsa: fix rate matching in the sequencer
The alsa sequencer rate matching was not actually working correctly.
It would compare the previous queue time with the current time and
compare that to the quantum. This would include uncorrected errors from
jitter and would result in the timeouts being scaled in the wrong
direction forever.

Instead, calculate an ideal queue time and compare our current queue
time against that. We then use the correction to scale the timeout or
the next queue time prediction.

Also use the predicted time as the base time for the event timestamps.
this results in less jitter.

Fixes #3657
2023-12-05 15:12:27 +01:00
Wim Taymans
c153f39720 alsa: reset dll when we reprogram the timers 2023-12-05 15:11:01 +01:00
Alper Nebi Yasak
7d2e824e97 acp: Disable active UCM profile before enabling Pro Audio profile
While switching to the Pro Audio profile from a UCM profile, the active
UCM profile is not disabled because the devices may need a UCM verb to
be set before being used. Then, switching away from the Pro profile to a
UCM profile is done by passing the Off profile as the old profile,
instead of the actually-still-enabled UCM profile.

This means the devices from the old UCM profile are kept enabled when we
try to switch to another UCM profile. And the devices to enable may be
conflicting with the still-enabled devices, which will cause failures.

To avoid this, we need to tell the UCM code to disable the profile when
switching away from it. Doing so disables UCM devices and the UCM verb.
Existing code sets the highest priority UCM verb before probing the Pro
profile, so manually enable the same one here as well, instead of
relying on unclean state from whatever profile that was last active.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
9b9ce21b1d acp: Don't sync hardware volumes while UCM device is disabled
The hardware controls we track for volume and mute state can change as
part of enabling or disabling the UCM device. This then triggers a
re-sync of our state with the hardware controls, which can e.g. set our
volume to an unwanted value as the result of enabling the device, or set
a hardware control to a wrong value based on our volume while disabling
the device. So these UCM-triggered changes to enable/disable the device
will at best show up on user interfaces and cause confusion, but maybe
even will push the hardware into an unexpected state.

The volume and mute state we set from user interfaces only make sense
when the devices are enabled. They should not be kept in sync with
hardware for inactive UCM devices [1]. Skip the callbacks for reading
and changing volume and mute state if the UCM device is disabled. This
way, the volume/mute controls for sinks/sources are essentially detached
from the hardware controls until the UCM device is re-enabled.

[1] https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772#note_1872757

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
0bdad320cd alsa-ucm: Replace port device UCM context assertion with an error
The pa_alsa_ucm_set_port() function is passed both a mapping context and
a device port, and both of these refer to their respective UCM device.
While switching over to having one port per mapping per UCM device, I
expected both of these to be the same device struct, so added an assert
checking so.

This assertion gets triggered when we have multiple UCM verbs declaring
the same UCM device name. The root cause here is that the ports' UCM
device references are set once while creating the ports for the card, so
they happen to be those of a specific verb and may not match those from
a different UCM verb's profiles' mappings.

Solving the root cause necessitates a larger refactor. What we actually
assume here is that name of the UCM device is same for both the port and
the UCM context, which ends up always true in practice. For now, replace
the assert with a check and error.

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/802
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
5b3dea6319 alsa-ucm: Check UCM verb before working with device status
Some versions of the ALSA libraries run into a segmentation fault when
we query a UCM device/modifier status without first setting a UCM verb.
It's not a reasonable thing to do anyway, so check for this case and
return an error. Also do the check in other helpers.

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/801
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
a7e9f79cd0 alsa-ucm: Fix more instances of profile-verb conflation
The ucm_get_device_property() function adds to each UCM device's
playback_volumes (or capture_volumes) hash map an associated volume
mixer keyed with the UCM verb. These key-value pairs are then iterated
over in various places which assume the key is a profile name. This
assumption is no longer true since we can generate multiple profiles to
use conflicting devices.

A previous commit 45278904167f ("alsa-ucm: Stop conflating profile name
with UCM verb name") fixes some instances of this assumption, but misses
the relation explained above. Fix more instances of misleading
"profile"s where the UCM verb name is actually meant.

Link: 7005eafee3
Fixes: 57295beee1a6 ("alsa-ucm: Stop conflating profile name with UCM verb name")
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
d2046adcd1 alsa-ucm: Consider devices using the same PCM as incompatible
Although it's a valid UCM configuration to have multiple devices using
the same PlaybackPCM or CapturePCM, it's unclear how PulseAudio should
handle the cases where multiple of these devices are enabled. Some
options I can think of are:

- Merge all devices sharing the same PCM into the same mapping, open
  only one PCM substream for this mapping, and add 'combination ports'
  that enable combinations of the devices. This has been the case until
  recently, although the combination port logic was broken. A problem
  with this is that we can't independently control device volumes. We
  most likely cannot use hardware volumes either.

- Have one mapping for each device in the same profile, and open one PCM
  substream for each mapping. This is the current state, and it fails
  when there are fewer substreams than devices. Otherwise it works, but
  it's still confusing, as sound directed to a device-specific mapping
  might end up playing at multiple devices.

- Make multiple profiles each with combinations of upto-substream-count
  devices, and have one mapping/substream per device. This still causes
  the confusion mentioned above. And it's likely that the substream
  count will almost always be one, where this case degenerates into the
  last one.

- Have one mapping for each device in the same profile, but open only
  one PCM substream. I assume this is possible with software mixing, but
  it is still confusing like the above, and probably less performant.

- Generate multiple profiles each with one of the shared-PCM devices,
  again with one mapping/substream for that one device. The trade-off
  with this is that we can't use multiple of these devices at the same
  time. However, this doesn't have the output device confusion,
  combination port's volume problems, or the substream count limitation.

This patch takes a short-cut to achieve the last option, by considering
shared-PCM devices implicitly conflicting with each other.

Link: 45509ff9bc
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
cff0ef13c1 alsa-ucm: Disable old modifiers when switching profiles of same verb
While switching profiles of the same UCM verb, existing code first
disables devices that are only on the first profile to avoid conflicts.
However, it only disables devices, not modifiers. Even worse, modifiers
which have PlaybackPCM/CapturePCM are incorrectly treated as devices and
result in a segmentation fault.

Check what we are disabling, and call the appropriate disable function
for both devices and modifiers. Modifiers are disabled before devices,
because _dismod calls fail when the modifier's supported devices are
disabled.

Link: b74269016c
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
905241c4a1 alsa-ucm: Add enable, disable, status helpers for modifiers
These are mostly the same as the device helpers added in c83b34516929
("alsa-ucm: Add enable, disable, status helpers for devices"), but for
modifiers instead.

Link: b382a00f8b
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
d99e0586b0 alsa-ucm: Create multiple profiles per verb for conflicting devices
Right now we try to add all UCM devices of a verb to a single profile.
But if some devices using different PCMs are configured as conflicting
with one another, we will only be able to utilize one of them, chosen
seemingly based on the order in the UCM config file.

This is not a problem with conflicting devices sharing a PCM, as they
are assigned to the same mapping and the ports mechanism only enables
one of them to be active at a time.

To utilize all devices in a UCM verb even when there are conflicting
devices using different PCMs, calculate subsets of devices which
can be simultaneously used and create a profile for each such set.

Link: 5dd411190d
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
63a44038d2 alsa-ucm: Disable old devices when switching profiles of same verb
While switching profiles, it was enough to switch UCM verbs since that
disables all enabled UCM devices and every profile had a distinct verb.
However, switching to the current verb does not disable any devices.

To support multiple profiles for a verb we need to explicitly disable
the old profile's devices, since they might be conflicting with the new
profile's devices and will prevent them from being enabled. Compare both
profiles' mappings, and disable the devices not in the new mappings.

Link: e49da7bcd6
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00