Commit graph

725 commits

Author SHA1 Message Date
Wim Taymans
3c67821c4a spa: add context to debug functions
Add new spa_debugc_ funnctions that take a context. The user should also
redefine the spa_debugc macro to handle the context.

Use this to let some plugins log the pod and format to the log without
using the global logger.

Also use this to remove our custom pod logger function by reusing the
spa one with a custom context.
2023-01-18 13:12:16 +01:00
Pauli Virtanen
4b408e2978 bluez5: fix reported BAP profile index 2023-01-17 20:14:14 +02:00
Pauli Virtanen
37d78ce29e bluez5: disable LE Audio if using legacy bluez API 2023-01-17 19:58:42 +02:00
Pauli Virtanen
a372c89544 bluez5: lc3: handle multiple PACs in capabilities
BlueZ may send multiple PACs in the capabilities delimited by zero LTV.
Handle this case by selecting the "best" one.

The configuration size may also for BAP generally be different from PAC
size.
2023-01-17 19:58:42 +02:00
Wim Taymans
97aafe2234 fix use_buffers checks
We can set 0 buffers even if there is no format.
Return -ENOSPC when too many buffers are set.
2023-01-10 12:30:25 +01:00
Pauli Virtanen
b0853ad34a bluez5: media-sink: set initial latency after getting transport
The call to set_latency doesn't do anything, before transport has been
set.
2022-12-21 16:42:04 +02:00
Pauli Virtanen
c7b3ef0d9f bluez5: backend-native: fix missing brace in CIND reply
It should look like ...,("battchg,(0-5)) not ...,"battchg",(0-5))
2022-12-21 12:55:20 +02:00
Wim Taymans
7758240c79 bluez: fix compilation without ldac_abr
The define for this constant was removed but it was LDACBT_EQMID_MQ
before.
2022-12-15 12:20:40 +01:00
Wim Taymans
f44d55f6c2 handle read from timerfd correctly
When reading the timerfd gives an error, we should return right away
because the timeout did not happen.

If we change the timerfd timeout before reading it, we can get -EAGAIN.
Don't log an error in that case but wait for the new timeout.
2022-12-09 17:30:31 +01:00
Frédéric Danis
90d00551b7 bluez5: sco-sink: Remove unused variable 2022-12-02 11:11:47 +01:00
Pauli Virtanen
9496078be5 bluez5: add bluetoothOffloadActive device prop for acquiring transports
Add a device prop that causes transports to be acquired.
2022-12-02 11:11:47 +01:00
Bart Ribbers
c939a9edf7
spa/bluez: remove unused import fixing Musl builds with lc3
The include defines things like __uint16_t but these are unused here and glibc-specific anyway
2022-11-23 13:47:14 +01:00
Barnabás Pőcze
14e044a92c spa: bluez: backend-native: fix filtered number memory leak
The `number_filtered` variable was dynamically allocated but never freed.
2022-11-14 16:15:21 +00:00
Dmitry Sharshakov
e0c9f87d78 bluez5: backend-native: prevent string overflow
Fixes -Wfortify-source when building
2022-11-13 15:13:33 +03:00
Pauli Virtanen
e381a26de9 bluez5: don't put side effects into spa_log_* arguments
spa_log_* are macros such that their arguments don't get executed if the
log topic is not enabled.
2022-11-07 20:22:45 +02:00
Dmitry Sharshakov
02a4758043 bluez5: aac, lc3plus: report bitpool changes
Behavior similar to SBC. This makes return value useful for media-sink logger.
2022-11-07 16:32:53 +00:00
Dmitry Sharshakov
1bea58c20b bluez5: media-sink: fix bitpool increase
The free buffer check must happen before writing to check for leftover data in buffers. In case data is left over from previous submission, bitpool mustn't be increased.
Also improved logging by adding bitpool to the log message.
2022-11-07 16:32:53 +00:00
Dmitry Sharshakov
79b95e083a bluez5: backend-native: report HFP AG battery indicator to UPower 2022-11-07 16:32:17 +00:00
Wim Taymans
74447acedb Add some more format checks
The format parse functions don't really check if the parsed values
make any sense so we need to to this ourselves.
2022-11-03 13:10:32 +01:00
Pauli Virtanen
cc4e5a89b4 bluez5: fix BAP codec sink flag usage
MEDIA_CODEC_FLAG_SINK means the local endpoint is sink. Have this the
same way for BAP, no need to invert it.
2022-10-26 20:14:34 +03:00
Pauli Virtanen
d0d783541d bluez5: reduce the number of registered Opus endpoints
The different source modes can share the same endpoint.
2022-10-26 18:59:26 +03:00
Pauli Virtanen
d94832942e bluez5: allow codecs to share endpoints
AVDTP in principle allows 62 endpoints, but in practice it appears some
devices (Samsung Galaxy Buds2 Pro, Redmi Buds 3 Lite, probably others)
fail to connect A2DP when the number is somewhere above 24.  A2DP
connection works when initiated from the Central, but not when the
device itself does it, so these devices are not fully broken.  We should
reduce the number of registered A2DP endpoints to avoid running into
problems with such broken devices.

Some of our source codecs are the same actual codec with the same
configuration, and don't need separate source endpoints.

Allow codecs to not have a registered endpoint (fill_caps == NULL), and
tolerate codecs with the same endpoint name.  In codec switch, keep
track separately which of the codecs with the same endpoint name the
local endpoint is currently associated with.
2022-10-26 18:59:26 +03:00
Pauli Virtanen
99406aefea bluez5: deal with missing endpoint path in selectproperties 2022-10-26 18:59:26 +03:00
Pauli Virtanen
2fa3120486 bluez5: driver should produce buffers before ready
The graph cycle goes: driver timeout -> process output nodes -> process
driver node.  Hence, driver should produce buffers in the timeout,
otherwise there's one quantum extra latency.

Make the bluez5 media/sco sources as drivers put a buffer to io before
indicating ready, and as follower do it in process. Also make checks if
io == NULL, and don't set io->status to HAVE_DATA unless there really is
a buffer ready.
2022-10-22 15:23:06 +03:00
Barnabás Pőcze
95eeb7c2ec spa: bluez: dbus: add endpoint (un)registration helpers
Introduce `unregister_media_endpoint()` to unregister the specified
media endpoint object from dbus. Moreover, move the logic that decides
whether or not a particular codec should be registered for a given
direction into `endpoint_should_be_registered()` and use that in
both `(un)register_media_endpoint()`.
2022-10-21 13:39:31 +00:00
Pauli Virtanen
d388c206ef bluez5: reset timers when reassigning followers
Driver timeouts need to be started/stopped when we switch from follower
to driver or vice versa.

The BT sources fail to do this, so fix it. Sinks already do it right.
2022-10-21 07:09:36 +00:00
Wim Taymans
c0fc29494f bluez5: stop before freeing things
Make sure all timers are stopped before we clear our state.

See #2764
2022-10-20 21:52:49 +02:00
Pauli Virtanen
9c4aab7508 bluez5: sco-sink: implement flushing the same way as in a2dp-sink
Use separate timers for driving graph and for flushing, since they don't
have the same period.

Flushing is done based on the time positions of the next sample to be
written, so it will stay in sync with the graph.  Because writing too
much data to SCO sockets generally only causes the device to skip ahead,
we don't need to handle the case where the writing has been lagging.

This fixes simultaneous playback to both ALSA and SCO sinks from the
same graph, with SCO as driver, which previously produces broken sound
(e.g. with pw-play --latency 512, linked to the two sinks) ALSA nodes
require regular driver intervals, which was not true previously.
2022-10-18 14:42:14 +00:00
Pauli Virtanen
9cfa66baa2 bluez5: media-sink: flush packets at time of first sample
Send encoded data packets at the time corresponding to their first
sample. This is simpler than what we did previously.

Use this scheme also for BAP.
2022-10-18 14:42:14 +00:00
Pauli Virtanen
d231e2a1b1 bluez5: media-sink: bigger socket buffer
Bigger buffer allows for more fluctuation in transmission rate without
sound glitches.

It doesn't matter much for latency, as under normal conditions we are
not producing data faster than the BT adapter can transmit, so the
buffer generally is almost always empty or full, and in the latter case
we have to reduce the bitrate.
2022-10-18 14:42:14 +00:00
Niklāvs Koļesņikovs
cba334f028 treewide: fix some strict-prototypes Clang warnings/errors
Clang 15 at least with my build configuration emits warnings about
function prototypes that lack argument types. Most notably this
happens with functions that take no arguments which in compiler view
equates to the void type i.e. void f(void) instead of void f(). As I
understand, this will become an error in some future Clang release,
so might as well fix it now.

Since these were discovered not by a linter but by the actual compiler
for my particular build configuration, some f() may have escaped for
now. But at least it's enough to build PipeWire with most optional
features enabled even when -Werror=strict-prototypes is enabled.

For anyone else wanting to have a go at this, these can be upgraded
from warnings to errors by adding -Werror=strict-prototypes to the
custom CFLAGS which probably works with GCC, too, but has only been
done with Clang 15.0.2.

Finally my editor automatically stripped trailing spaces upon saving
the modified files. I assume it's probably not worth keeping those
invisible bytes around but this may have slightly dubious implications
as it did also turn indented empty lines of JACK license header into
regular empty lines.

Signed-off-by: Niklāvs Koļesņikovs <89q1r14hd@relay.firefox.com>
2022-10-12 07:32:47 +00:00
Pauli Virtanen
7066aa7e15 bluez5: fix build_profile index handling
The codec profiles come at profile indices after the no-codec profiles.
Make the codec clearer by not using magic numbers here.
2022-10-12 07:26:00 +00:00
Pauli Virtanen
9846e0cb7a bluez5: in SelectProperties, parse QoS values and pass to get_qos
The codec may need to take into account endpoint preferred QoS values,
so parse this information and pass it to the codec's get_qos.

All the QoS struct values need to be set, as otherwise BlueZ may pass
uninitialized zero values over the air, which devices can reject.  This
does not apply to CIG/CIS ids, which are automatically allocated by
default.

Fixes connecting to nrf5340 devkit, which requires a valid TargetLatency
value.
2022-10-12 07:26:00 +00:00
Barnabás Pőcze
61453b91bd spa: bluez: dbus: emit added devices when adding new listener
Previously, when a new listener was registered,
it was not made aware of the already added devices.
2022-10-08 18:16:25 +02:00
Barnabás Pőcze
52af41850d spa: bluez: dbus: harmonize label indentation 2022-10-08 18:05:11 +02:00
Barnabás Pőcze
fd979a3cf7 spa: bluez: dbus: use tabs for indentation 2022-10-08 18:05:11 +02:00
Barnabás Pőcze
253c8b48fc spa: bluez: dbus: use spa_strstartswith() 2022-10-08 18:05:11 +02:00
Barnabás Pőcze
8ca5c0f15b spa: bluez: dbus: do not use NameHasOwner()
Commit 947ee152d3 ("bluez: check dbus service before enumerating objects")
introduced a check that would esure that GetManagedObjects()
is not called if the "org.bluez" name has no owner. This
was done to avoid auto-starting the bluez daemon.

However, this is not needed because it is possible to set on
a per-message basis whether or not the destination service
should be automatically started by the dbus daemon.
2022-10-08 17:59:41 +02:00
Barnabás Pőcze
1d3497b0cd spa: bluez: dbus: do not call GetManagedObjects() if there is a pending call 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
bf18d948b3 spa: bluez: dbus: immediately unref pending call after retrieving reply 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
58d9fbff88 spa: bluez: dbus: keep a reference to the GetManagedObjects() call 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
008d836608 spa: bluez: dbus: do not call GetManagedObjects() again
If a reply to a previous GetManagedObjects() call have been
received, and there is no reason to call it again, do not do it.
2022-10-08 17:59:41 +02:00
Frédéric Danis
fd508d395b bluez5: backend-native: Add a property to select the modem to use
By default no modem is allowed.
Property "bluez5.hfphsp-backend-native-modem" can be 'none', 'any' or the
modem device string has found in 'Device' property of
org.freedesktop.ModemManager1.Modem interface, e.g. for PinePhone
"/sys/devices/platform/soc/1c1b000.usb/usb2/2-1".
2022-10-05 19:31:50 +00:00
Frédéric Danis
c4addb102b bluez5: backend-native: Only use first modem found
Some device may have multiple modems, we should only used one, the first
found and manage changes only for this one.
2022-10-05 19:31:50 +00:00
Frédéric Danis
47700a2214 bluez5: backend-native: Add battery level indicator support
This connect to the UPower service and update the +CIND battchg indicator
2022-10-05 19:31:50 +00:00
Frédéric Danis
a37aeac273 bluez5: backend-native: Add AT+VTS support
This allows to send a DTMF key on an active call.
2022-10-05 19:31:50 +00:00
Frédéric Danis
7c05574072 bluez5: backend-native: Add AT+CNUM support
This only support the first subscriber number.
2022-10-05 19:31:50 +00:00
Frédéric Danis
3566b0739b bluez5: backend-native: Add ATDdd...dd; support
This allows to dial a number.

Memory dialing (ATD>nnn...;) is not supported as it requests access to
the contact application.
2022-10-05 19:31:50 +00:00
Frédéric Danis
20572a1789 bluez5: backend-native: Add AT+CLCC support
This allows the HFP HF to retrieve the list of calls with their index,
state and remote number (if available).

This commit shared the list of calls between modemmanager.c and
backend-native.c, and switches call state storage from ModemManager
states to CLCC states
2022-10-05 19:31:50 +00:00
Frédéric Danis
55075915ec bluez5: backend-native: Add AT+CLIP support
This allows to send the caller number of an incoming call with the RING
event.
2022-10-05 19:31:50 +00:00