Commit graph

480 commits

Author SHA1 Message Date
Pauli Virtanen
fc2fe12794 bluez5: update a2dp-codecs.h from bluez with aptx-ll caps 2021-08-18 19:55:22 +00:00
Pauli Virtanen
672223d055 bluez5: avoid poll busy loop in a2dp-sink
Disable flush polling when we don't have data ready to write to the
socket (or socket send failed). This avoids entering into a poll busy
loop, which may result to rtkit killing the process.
2021-08-13 23:37:48 +03:00
Pauli Virtanen
5071589aea bluez5: enable SBC-XQ codec by default, if allowed by quirks
Enable SBC-XQ by default, and move it at the end of the codecs list, so
that bluez does not connect to it automatically except when it is the
codec used previously.

When the codec is disabled by quirks, it won't appear in the codecs
list, and so can't be selected by user (and so won't be connected
automatically).

However, since SelectConfiguration does not carry information which
device is in question, we cannot prevent BlueZ connecting to the codec
even if it's disabled for a specific device. If the "impossible" occurs
regardless, we won't reject the connection and the profile will be shown
as the generic "A2DP" one.  If the sound is garbled, the user can select
some other profile that works.
2021-08-13 18:45:16 +00:00
Zsombor Welker
f5850af4d8 bluez5: handle XAPL battery level per Apple Guidelines
Corrects the handling of AT+XAPL Apple extensions to send
`+XAPL=iPhone,2` instead of `+XAPL: iPhone,2` based on Apple's
documentation.

Replaces magic numbers with enum values.

[Accessory Design Guidelines](https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf)
2021-08-13 10:30:36 +02:00
Zsombor Welker
a1777d00e3 bluez5: correct parsing order for HF indicator 2 based battery status
Since "AT+BIND=" was before "AT+BIND=?", the seconds statement was never
matched.
2021-08-12 21:13:22 +02:00
Sanchayan Maity
be6824cb15 bluez5-device: Set device intended role for HFP 2021-08-12 18:54:46 +00:00
Zsombor Welker
f87942027f bluez5: report HF indicator 2 based battery status
HF indicator 2 (see [assigned-numbers], Hands-Free Profile) is able to
report battery percentage at 1% intervals (in range [0, 100]), contrary
to the `+XAPL` `+IPHONEACCEV` extension which only supports 10%
increments.  This does not guarantee increased granularity however, as
peers may still be limited to imprecise battery measurements internally
or round to coarser percentages.
Supporting both additionally broadens the range of devices for which PW
can report its battery level.

[assigned-numbers]:
https://www.bluetooth.com/specifications/assigned-numbers/
2021-08-12 18:45:44 +00:00
Wim Taymans
a9fecd50ed bluez5: improve debug
Log the errno when something is wrong.
2021-08-05 15:41:50 +02:00
Wim Taymans
e3a643bffe bluez5: remove useless pod_frame() call 2021-08-05 15:41:26 +02:00
Peter Hutterer
51a177eb6d tree-wide: replace strstr(a, b) == a with spa_strstartswith()
spa_strstartswith() is more immediately understandable.

Coccinelle spatch file:
	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) != E1
	+ !spa_strstartswith(E1, E2)

	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) == E1
	+ spa_strstartswith(E1, E2)

Applied to the tree except for alsa/acp/compat.h because it looks like
that header is still mostly as-is from PA.
2021-08-02 08:24:21 +00:00
Huang-Huang Bao
9f2d6d6d28 bluez5: fix rounding error on hardware volume conversion
Ensure the conversions between spa_bt_volume_linear_to_hw and spa_bt_volume_hw_to_linear are reversible when
operating on hardware volume.
2021-07-30 08:46:14 +00:00
Neal Gompa
1216371f8c bluez5: Use libfreeaptx instead of libopenaptx
libfreeaptx is a fork of libopenaptx prior to the dubious licensing
situation was introduced to the library.

As it's fully API compatible, let's use that instead for those who
want to use aptX support.

The library source is available at https://github.com/iamthehorker/libfreeaptx
2021-07-29 15:22:04 +00:00
Pauli Virtanen
cb10d87bb8 bluez5: handle no data written to sco socket
If socket write results to EAGAIN/EWOULDBLOCK or rx data starts late,
spa_bt_sco_io_write may return 0, and we should give up and skip ahead
(and not loop in RT thread with very small timeout).
2021-07-23 07:58:39 +00:00
Peter Hutterer
257fd83f65 Replace Pipewire with PipeWire for consistency
And set up a CI job to check for that.
2021-07-14 16:56:54 +10:00
Pauli Virtanen
0c9f0210ed bluez5: sco-io: start writing only after the packet size is known
The kernel-provided SCO write MTU is currently never the correct packet
size for writing, so don't try to use it. Some adapter firmware (eg.
BCM20702A0 0b05:17cb) appears in practice sensitive to the alignment of
the msbc frames, and writes with wrong packet size break things but only
on certain headsets. For other adapters, this doesn't appear to matter.
2021-07-11 16:14:03 +00:00
lsde
579481ab70 Use correct RTP payload type for aptX, LDAC,SBC
According to the A2DP spec, the payload type should be
set to a number between 96 and 127.
This is fixed for AAC codec, but not the rest.

Original PulseAudio issue: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/591
2021-07-11 16:10:20 +00:00
Wim Taymans
d88e8edd11 avoid shadowing arguments 2021-07-06 17:55:16 +02:00
Konstantin Kharlamov
252816f757 bluez5: fix wrongly typed started field in spa_bt_sco_io
This is a bitfield, but it's unclear what it achieves since this is the
only member of a bitfield, so it may be more efficient to just make it a
bool.

Fixes a LGTM warning:

    Bit field started of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type.
2021-07-06 00:07:21 +03:00
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Barnabás Pőcze
48dbb4da3c spa: bluez: native: do not use spa_aprintf()
Instead of spa_aprintf(), convert `rfcomm_send_{cmd,query}`
to take a printf-style format string.

Furthermore, handle overflows and return errors from
`rfcomm_send_{cmd,reply}`. And make those functions
take an rfcomm as argument instead of any spa_source.
And match conversion specifiers to the actual types
in format strings.
2021-06-30 14:44:08 +02:00
Pauli Virtanen
2b515b5e50 dbus: keep a ref to DBusConnection if reconnecting is not handled
Several places in the code don't handle reconnecting DBus connections
yet. In those cases, a ref to the DBusConnection handle needs to be
kept, so that there's no use-after-free if it gets freed by spa_dbus
if the connection is broken.

Adjust spa_dbus so that others keeping additional refs is safe.
2021-06-26 16:11:40 +03:00
Pauli Virtanen
b98b9e0e77 bluez5: deal with old libusb versions 2021-06-22 10:58:50 +03:00
Pauli Virtanen
9d38d375d2 bluez5: add and use quirk for broken mic HW volume
Some headsets emit AT+VGM even though +VGM commands do not actually
adjust the recording volume.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
9422e76d89 bluez5: enable hw volume on all profiles, if device quirks permit it 2021-06-22 10:58:50 +03:00
Pauli Virtanen
5e0b63b149 bluez5: backend-native: use quirks + usb adapter caps for checking msbc
Use the quirks database to check whether to enable MSBC codec for each
device.

If quirks don't allow ALT1 mode for an USB adapter, check whether the
adapter has an usable ALT6 mode and disable MSBC if not.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
b57ae8c2a6 bluez5: add support for hardware quirk/feature database
Implement hardware quirk/feature database with pattern matching.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
2c9764da1d bluez5: parse bluez vendor/product ids
It seems few devices support the Device Id via bluez.

Try to figure out vendor/product ids for usb devices also via sysfs.
Also try to figure out the adapter bus type.
2021-06-22 10:58:50 +03:00
Huang-Huang Bao
ea28cb95c0 bluez5: don't autoconnect device if no profiles
Otherwise timers would be created for every bluetooth devices, even they don't have audio profiles.
2021-06-21 07:10:02 +00:00
Huang-Huang Bao
db6e73895f bluez5: clean up connection status handling
Also separate device info emitting into a new function.
2021-06-21 07:10:02 +00:00
Huang-Huang Bao
3433f40cd9 bluez5: fix device connection issue if profile(UUIDs) info is delayed
Keep all types of devices, only emit device info if device has audio profiles.
Heuristically add profiles based on bluez actions so device can still be connected
even without initial UUIDs info from signal InterfaceAdded for org.bluez.Device1.

Fixes #1330
2021-06-21 07:10:02 +00:00
Pauli Virtanen
b44fdf5ebb bluez5: backend-native: don't send +BCS if no codec negotiation
Fix issue with sending +BCS for CVSD even though codec negotation is not
available for the RFCOMM.
2021-06-20 19:40:00 +03:00
Huang-Huang Bao
4c9ac08310 bluez5: always emit node object info for dynamic node
impl_add_listener() could be called more than one time, ensure that we always emit node info
so that session manager(bluez-monitor) can receives it.

Fixes #1308
2021-06-17 07:22:46 +00:00
Peter Hutterer
0054319d88 meson.build: add -D_GNU_SOURCE to the project arguments
This appends it to every compilation command so we can get rid of the c_args
for (almost all) executables.
2021-06-09 07:47:51 +00:00
Huang-Huang Bao
8c42e6aecb alsa,bluez5: handle SPA_PARAM_Latency in port_set_param
Simply return 0 instead of -ENOENT.

Fixes #1262
2021-06-05 17:52:40 +00:00
Huang-Huang Bao
d3fcc0a37a bluez5: correct parameter names in spa_bt_sco_io_create declaration
From its definition and parameters passed to its function call, the 3rd parameter
is read_mtu and the 4th is write_mtu.

Fixes #1256
2021-06-05 15:17:10 +00:00
Huang-Huang Bao
c7cac40e03 bluez5: init node soft volumes to 1.0f 2021-06-03 07:17:41 +00:00
Huang-Huang Bao
f92a5b3bbd bluez5: emit node volume and mute right after bluez5 node creating
bluez5 nodes will always be removed & created again during profile changing, hence
node volume & mute will always be reset. This is OK if profile did changed, because
session manager would carries volume & mute to bluez5 route param. But if profile
was not changed after setting profile (a2dp-sink-sbc -> a2dp-sink -> a2dp-sink-sbc),
session manager would think node volume & mute are not changed and no route
setting is performed, causing route volume out of sync with node volume.

To fix this, we emit node volume and mute right after bluez5 node is created.

Fixes #1254
2021-06-03 07:17:41 +00:00
Huang-Huang Bao
27433c4000 bluez5: clean up node volume emitting
The problem described in previous 'volume_changed()' has been fixed
in 5bf2144438, hence we don't need
that workaround anymore.
2021-06-03 07:17:41 +00:00
Huang-Huang Bao
38bcec9022
bluez5: add port latency reporting 2021-05-28 20:02:10 +08:00
Huang-Huang Bao
d8435cd5fd
bluez5: use definations to index node and port params 2021-05-28 19:40:19 +08:00
Wim Taymans
46ef88e520 spa: save the old change_mask and restore when emitting full
When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
2021-05-27 15:21:44 +02:00
Peter Hutterer
bc64b32798 bluez: fix a memleak on error
If the allocation failed, our strdup'ed path would leak.

Found by scan-build
2021-05-26 10:03:43 +02:00
Peter Hutterer
cdfd50e166 spa: add spa_atob() to convert a string to a boolean
This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
2021-05-18 22:18:56 +10:00
Peter Hutterer
92514d57e4 treewide: replace plain strcmp() calls with spa_streq 2021-05-18 22:10:27 +10:00
Peter Hutterer
522f87d5ea treewide: replace strcmp() != 0 with !spa_streq
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer
95a84e797a treewide: replace !strcmp() with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer
9bbe5c7517 bluez: add a helper function for checking the message signature
strcmp() is easier to get wrong (or lack consistency) so let's abstract all
these calls with a little helper.
2021-05-18 22:10:26 +10:00
Huang-Huang Bao
03cde9751b
bluez5: guard against device profile
Invalid device profile should not be set.
2021-05-11 19:22:42 +08:00
Peter Hutterer
2405f0942b spa/buffer: rename SPA_MEMBER to SPA_PTROFF
SPA_MEMBER is misleading, all we're doing here is pointer+offset and a
type-casting the result. Rename to SPA_PTROFF which is more expressive (and
has the same number of characters so we don't need to re-indent).
2021-05-06 09:39:39 +00:00