Commit graph

932 commits

Author SHA1 Message Date
Pauli Virtanen
397059017b bluez5: don't rely on bluez event ordering for acquire
Don't assume that transport State property update arrives after acquire
completion callback.

It currently does, but best to not rely on it.
2023-03-18 14:11:54 +02:00
Pauli Virtanen
eb12a3dfca bluez5: acquire all BAP transports in a CIG at the same time
We need to acquire and release all transports in the same CIG at the
same time.

Due to current kernel ISO socket limitations, this cannot be done one by
one.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
dfd30f37dc bluez5: parse BAP transport CIG/CIS properties 2023-03-17 16:56:31 +00:00
Pauli Virtanen
3236d706ba bluez5: hsphfpd: make transport acquire async
Now that sinks/sources can do transport acquire asynchronously, remove
the workaround that made it synchronous.  Do release still synchronously
however.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
4d844ee1c6 bluez5: backend-native: set state on synchronous acquire/release
Sinks/sources now expect transport state is set on acquire+release.
It doesn't need to be done async, so do it still synchronously.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
b69f3fc19e bluez5: ofono: set transport state on synchronous acquire/release
The sinks/sources now expect transport state is set in acquire and
release.  It does not need to be async, so we still do it synchronously.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
63118b130e bluez5: make A2DP/BAP transport acquire/release async
Change A2DP/BAP transport acquire and release to be async.

Since BlueZ acquiring ISO sockets blocks until all sockets in same CIG
are acquired, BAP transports must be acquired asynchronously.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
1d5c693d33 bluez5: change sink/source run state follow transport state
Allow asynchronous changes in transport state in the sinks/sources.

Also allow transport acquire to be actually synchronous, in this case it
must set transport state during acquire call.

Separate driver start/stop from transport start/stop.
2023-03-17 16:56:31 +00:00
Pauli Virtanen
fa3ee2e20b bluez5: allow disabling sink or source endpoints
Add option bluez5.roles that selects which endpoints (A2DP, BAP, HFP,
HSP) will be enabled.

This extends and deprecates bluez5.headset-roles.
2023-03-16 20:58:55 +02:00
Pauli Virtanen
a49d2d41af bluez5: ensure nodes are removed on disconnect
Emit any remove node events before resetting initial profile.  It
indicates to the session manager that nodes if any went away before
device disconnected.

Usually the profile is removed first which removes the nodes. This
depends on ordering of events from bluez, which apparently can be
different depending on how remote device disconnects.
2023-03-16 19:42:31 +02:00
Wim Taymans
98a214891d handle some uninitialized variables 2023-03-16 12:29:15 +01:00
Pauli Virtanen
1664df2c85 bluez5: guard against processing when errored or not started
Add some guards against doing processing when there has been an error or
the node is not started. Set error status to IO.  Continue driving on IO
errors.
2023-03-11 11:11:08 +00:00
Pauli Virtanen
04eb709619 bluez5: don't set unnecessary socket options
In media-sink, there's no need to set RCVBUF.

In media-source, we don't need to set NONBLOCK, as reads are done with
DONTWAIT. Don't set SNDBUF as it's not needed there. Don't set RCVBUF,
but use the (big) kernel default value: decode-buffer will handle any
overruns. Small values of RCVBUF might cause problems if kernel is
sending packets in a burst faster than we wake up.
2023-03-05 17:55:24 +00:00
Pauli Virtanen
34d8466c8c bluez5: sources should produce full buffer every cycle
On underflow in sources, pad with explicit silence.  This avoids the
audioadapter from getting off sync from the cycle. That causes problems
as driver when we want to produce a buffer only a the start of the
cycle.

In some cases, it's also possible that the io already has buffer at the
start of the cycle when rate matching as driver. Currently, we don't
produce buffer in this case, but we should.  Fix that by doing things in
the exact same way as ALSA sources do.
2023-03-02 16:18:27 +00:00
Pauli Virtanen
99d5436f15 bluez5: media-sink: write packets exactly on time
Delay output by one packet, so that we never need to wait for
node_process to supply more data when a packet is due out, and can write
audio packets at exactly equal intervals (up to timer/io accuracy).

In principle, this should not be necessary. However, enable it for now,
in case this improves the various stutter/etc. bug reports.
2023-02-25 01:10:20 +00:00
Pauli Virtanen
f05e68e4d4 bluez5: media-sink: encode next packet as soon as possible
After flushing a packet, encode the next one immediately if we already
have the data.  This makes the flush timing more accurate (std ~4x
smaller) as we don't need to wait for the encode.
2023-02-25 01:10:20 +00:00
Pauli Virtanen
da21cfa93c bluez5: backend-native: implement AT+BCC
Implement HF-initiated connection establishment command AT+BCC
for HFP AG.
2023-02-23 18:42:53 +02:00
Pauli Virtanen
15e4b3d500 bluez5: media-source: allow using bigger A2DP receive buffers
The maximum receive buffer target of 6 packets may be too small when
there's huge jitter in reception.  Increase it so that we may use all
buffer available if needed (2*quantum_limit = 370 ms @ 44100).

For SCO, explicitly set maximum buffer to 40 ms, so that latency cannot
grow too large there.  For A2DP duplex, set it to 80 ms for same reason.
These are close to the old 6*packet limit.
2023-02-22 20:20:07 +02:00
Pauli Virtanen
b9d7ecb5b2 bluez5: handle BAP presentation delay and transport latency
For BAP server audio sink, set buffering target so that we try to match
the target presentation delay.  Also adjust requested node latency to be
smaller than the delay.

Also fix BAP transport presentation delay value parsing, and parse also
the other BAP transport properties. Of these, transport latency value
needs to be taken into account in the total sink latency.
2023-02-19 22:44:23 +02:00
Pauli Virtanen
192044f1d9 bluez5: dup transport fd, in case media-sink is using it
For bidirectional links, both media-sink and media-source are polling
the same fd.  This won't work, so dup the fd in media-source to avoid
problems.
2023-02-17 20:40:46 +02:00
Barnabás Pőcze
d77ef4b05e spa: bluez: include gio/gunixfdlist.h
Apparently before glib 2.73 including only gio/gio.h
does not include gio/gunixfdlist.h. So do that explicitly.
2023-02-16 20:55:55 +01:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Pauli Virtanen
b94cb5d99d bluez5: fix BAP current profile
Fix BAP profiles again: make sure the current profile is indicated
properly.
2023-02-07 22:54:37 +02:00
Pauli Virtanen
987b772b97 bluez5: don't claim sbc is supported when there's no A2DP at all
Handle failure to register legacy A2DP endpoints.
2023-02-06 06:35:40 +00:00
Pauli Virtanen
cfee662f0b bluez5: fix BAP profiles for source/duplex cases
Codec switching does not currently work properly for source/duplex.
With BAP it's also possible only when we're BAP client.

When we can't codec switch, emit the "codecless" BAP profile.
2023-02-06 06:35:40 +00:00
Pauli Virtanen
417f1dc02a bluez5: fix dependency checking
Don't do subdir_done() in bluez5/meson.build, since the presence of
dependencies is supposed to be checked in spa/meson.build.
2023-02-05 09:36:45 +00:00
Pauli Virtanen
1ed9daa8c5 bluez5: fix supported codecs when as BAP Server
BAP Clients do not have endpoints associated with them, and we only know
that codecs on currently configured transports are supported.

Handle this case in spa_bt_device_supports_media_codec
2023-01-29 17:38:21 +02:00
Pauli Virtanen
fb43a71543 bluez5: SupportedUUIDs is an adapter-specific property
The DBus adapter objects has both .Adapter1 and .Media1 interfaces.

Change handling of this so that we wait for both properties to appear.
2023-01-27 19:25:16 +02:00
Pauli Virtanen
7b54a891b4 bluez5: separate object manager for A2DP and BAP
BlueZ fails registering object managers containing A2DP endpoints if
controller is in LE-only mode.

Make the A2DP and BAP object managers separate, so that failure to
register one does not prevent registering the other.

Also rename some functions to indicate which ones deal with the legacy
BlueZ API.
2023-01-27 19:25:16 +02:00
Wim Taymans
1efb43b897 bluez5: fix uninitialized value warning 2023-01-26 09:54:30 +01:00
Pauli Virtanen
17049abd04 bluez5: backend-native: fixup HFP command handling
Strip initial \n from commands: some devices (Sennheiser HD 350BT) send
them.

Only reply OK to empty command with terminated command line;
non-terminated lines are invalid.

Add some debug in case the RFCOMM reply contains non-printable
characters.
2023-01-25 22:22:37 +02:00
Pauli Virtanen
effc1974e3 bluez5: backend-native: HFP should reply OK to no commands
HFP 1.8 -> 3GPP 27.007 -> ITU-T Rec. V.250 Sec. 5.6, which indicates to
reply OK to no commands on command line, not ERROR.
2023-01-25 19:35:26 +02:00
Niklāvs Koļesņikovs
b0fccf87d7
bluez5: a few more -Werror=strict-prototypes fixes
The Bluetooth Low Energy MIDI code added a few legacy function declarations
that fail when building with -Werror=strict-prototypes. The fix is same as
before: add a void to the empty function argument list.

Signed-off-by: Niklāvs Koļesņikovs <89q1r14hd@relay.firefox.com>
2023-01-24 11:14:27 +02:00
Pauli Virtanen
f292818961 bluez5: dbus-monitor: call remove hooks always
Call remove hooks always. We don't rely on this currently, but may be
clearer like this.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
039759ceaf bluez5: use spa_debug_log_mem, not spa_log_hexdump 2023-01-24 08:27:56 +00:00
Pauli Virtanen
fef0981488 bluez5: fixup BLE MIDI selinux README
The SELinux configuration should allow passing sockets also from PW to
bluetoothd.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
25f36e4334 bluez5: add info key indicating glib mainloop is usable 2023-01-24 08:27:56 +00:00
Pauli Virtanen
93a473eff6 bluez5: prevent unloading spa-bluez5.so
GObject is not compatible with unloading shared libraries using it, so
add linker flags preventing that.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
661569febc bluez5: use GDBus in midi-node 2023-01-24 08:27:56 +00:00
Pauli Virtanen
89542289ac bluez5: use GDBus in midi-server 2023-01-24 08:27:56 +00:00
Pauli Virtanen
f1b5575ec3 bluez5: use GDBus in midi-enum 2023-01-24 08:27:56 +00:00
Pauli Virtanen
de595a78ff bluez5: add GDBus-based object monitor framework 2023-01-24 08:27:56 +00:00
Pauli Virtanen
8d438d26ab bluez5: remove libdbus object manager wrappers 2023-01-24 08:27:56 +00:00
Pauli Virtanen
bd45f846fc bluez5: midi: refcounting and other correctness fixes
Use stdalign.h instead of union.
Fix some refcounting and return values.
Fail early in add_filters.
Minor style cleanups.
Less magical spa_dbus_async_call.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
2f8691b64f bluez5: add comments on possible SELinux + BLE MIDI issues 2023-01-24 08:27:56 +00:00
Pauli Virtanen
e13fed1a80 bluez5: midi: put node nick in GATT Characteristic User Description
As server, put node nick in GATT Characteristic User Description, so
that clients have some information which endpoint is which in case we
have multiple.  This is not in BLE MIDI standard, but cannot hurt.

As client, make use of that information, if present.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
2ef126885a bluez5: midi-node: implement server role 2023-01-24 08:27:56 +00:00
Pauli Virtanen
d30a0c5ee6 bluez5: add MIDI server/peripheral implementation dbus part 2023-01-24 08:27:56 +00:00
Pauli Virtanen
fe11bfdba0 bluez5: implement Bluetooth MIDI nodes
Implement BLE MIDI node, providing an input and output port.  MIDI data
received is normalized and produced on output port.  Data from input
port is converted to BLE MIDI and sent to the device.

Event timestamps come from device clock, whose offset to wall clock we
determine by correlating packet reception times with their timestamps.
The jitter in packet reception is likely much larger than device clock
error, so we average over that.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
fe3ca50818 bluez5: Add BLE MIDI parser/writer tests 2023-01-24 08:27:56 +00:00