Commit graph

772 commits

Author SHA1 Message Date
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
Pauli Virtanen
5d6f25e8f0 bluez5: implement BLE midi data writer 2023-01-24 08:27:56 +00:00
Pauli Virtanen
e3cf7f6d87 bluez5: implement BLE MIDI parser 2023-01-24 08:27:56 +00:00
Pauli Virtanen
931e8da3ea bluez5: implement Bluetooth MIDI device enumeration
Add monitor for enumerating connected Bluetooth MIDI devices.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
a07dfbbdb9 bluez5: add convenience helper for dbus pending calls 2023-01-24 08:27:56 +00:00
Pauli Virtanen
42e463f726 bluez5: add abstraction for remote DBus objects
Add framework for enumerating remote objects via DBus object manager
interfaces.
2023-01-24 08:27:56 +00:00
Pauli Virtanen
57956ad100 bluez5: add abstraction for local DBus object manager
Add framework for exposing local objects via DBus object manager
interfaces.
2023-01-24 08:27:56 +00:00
Wim Taymans
6207d98ff1 spa: add debug log context
Make a real debug context with a log function and move it to a new file.
This way we don't need to redefine a macro.
Make a new context for debugging to a log file. Make new functions to
debug to a log file.
Move the stringbuffer to string utils.
Integrate file/line/func and topics into the debug log.
We can remove some more things from the pipewire log_object function and
also add support for topics.
2023-01-18 17:51:16 +01:00
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