Commit graph

1146 commits

Author SHA1 Message Date
Pauli Virtanen
592a97a7b0 bluez5: keep BAP endpoint properties in spa_bt_remote_endpoint
Make QoS, Context etc. always up to date in spa_bt_remote_endpoint.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
6e0970c14b bluez5: simplify codec switch code
Simplify codec switching code: determine what switch to perform
immediately in spa_bt_device_ensure_media_codec().

The previous code doing "fallback" switching to various codecs is not
useful, as A2DP generally disconnects on the first failure and all
remote endpoints disappear.

Add iteration over multiple endpoints, for reconfiguring both source and
sink directions at the same time.  This is in preparation of supporting
BAP reconfiguration (for A2DP there's usually only one direction
connected at a time).
2025-06-13 22:16:03 +00:00
Pauli Virtanen
a30d385636 bluez5: reduce debug spam 2025-06-13 22:16:03 +00:00
Pauli Virtanen
64f2f38ec4 bluez5: support LC3-24kHz HFP codec available on some Apple devices
Add support of HFP codec used on eg Apple AirPods 3+, transporting LC3
mono @ 24kHz
2025-06-13 22:15:29 +00:00
Pauli Virtanen
6982bb8c7f bluez5: backend-native: set best codec also when retrying on timeout
Try again setting best available codec, not MSBC, when retrying if no
response to previous +BCS: command.
2025-06-13 22:15:29 +00:00
Pauli Virtanen
7e135a5235 bluez5: fix compilation 2025-06-13 21:06:08 +03:00
Pauli Virtanen
df591638a5 bluez5: indicate codec support status for ofono/hsphfpd
Indicates codecs properly.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
52fc22a76b bluez5: make sure mandatory codecs are always enabled
It should not be possible to disable mandatory codecs: csvd, sbc, lc3
2025-06-13 17:51:16 +00:00
Pauli Virtanen
9f34e962a6 bluez5: backend-native: don't hardcode available HFP codecs
Remove most hardcoding of possible HFP codecs. Instead, get what is
available from codec lists.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
83f6d719b1 bluez5: remove HFP codec id from transports
Make HFP codec id backend/codec internal detail. Remove
spa_bt_transport::codec field which is now unused.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
3f9fb8d664 bluez5: bluez5-device: reduce special casing of HFP codec related things
Get most information items out from media_codec properties, avoid
referring to HFP codec ids.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
defcea02fa bluez5: convert sco-sink to media_codec API
Use codecs via media_codec in sco-sink instead of implementing the
encoding in-place.

In future, media-sink could replace sco-source to reduce code
duplication.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
1c5895f625 bluez5: convert sco-source to use media_codec API
Use codecs via media_codec in sco-source instead of implementing the
decoding in-place.

Also slightly adjust media-source decode semantics.

In future, media-source could replace sco-source to reduce code
duplication.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
123f937701 bluez5: backend-hsphfpd: set media_codec on created transports
Set media_codec on created transports.

Also avoid using the HFP codec id in spa_bt_transport::codec
2025-06-13 17:51:16 +00:00
Pauli Virtanen
61b0ea4589 bluez5: backend-ofono: set media_codec on created transports
Set media_codec on created transports.

Also avoid using the HFP codec id in spa_bt_transport::codec
2025-06-13 17:51:16 +00:00
Pauli Virtanen
13256e9083 bluez5: backend-native: set media_codec on created transports
Set media_codec on created transports.

Also avoid using the HFP codec id in spa_bt_transport::codec
2025-06-13 17:51:16 +00:00
Pauli Virtanen
62bec49c27 bluez5: add spa_bt_get_hfp_codec() / spa_bt_get_media_codecs()
These are for HFP backends to get media codecs.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
e6f5fb12a3 bluez5: add HFP codecs in the media codec API
Add copy of HFP codec implementations in the media codec API.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
4e0d0c5f0b bluez5: replace codec->bap/asha flags with codec->kind enum
Indicate codec type with enum instead of bool flags.  This is in
preparation of moving also HFP to media codecs.
2025-06-13 17:51:16 +00:00
Frédéric Danis
f6fc307638 bluez5: backend-native: Support legacy audio connection
This allows to connect the SCO link with old HFP AG devices which
doesn't support the codec negotiation.
The audio connection could be done even without an ongoing call.
2025-06-13 07:47:18 +00:00
ValdikSS
187df01b5e bluez5: aac: disable Perceptual Noise Substitution for MPEG-2 profile
When the Bluetooth earphones claim to support AAC `MPEG-2 AAC LC` type only,
PipeWire encodes audio using MPEG-4 FDK-AAC profile which enables unsupported
Perceptual Noise Substitution (PNS) encoder feature.

Use AOT_MP2_AAC_LC pseudo-profile which is AOT_AAC_LC with PNS disabled.
2025-06-03 09:38:28 +00:00
Sam James
2cec77e7df *: unify config.h handling
config.h needs to be consistently included before any standard headers
if we ever want to set feature test macros (like _GNU_SOURCE or whatever)
inside. It can lead to hard-to-debug issues without that.

It can also be problematic just for our own HAVE_* that it may define
if it's not consistently made available before our own headers. Just
always include it first, before everything.

We already did this in many files, just not consistently.
2025-05-30 10:24:13 +00:00
Wim Taymans
c45d667934 loop: spa_loop_invoke -> spa_loop_locked where possible
When we simply need to change some state for the code executed in the
loop, we can use locked() instead of invoke(). This is more efficient
and avoids some context switches in the normal case.
2025-05-30 11:59:35 +02:00
Sam James
b943c31fd8
*: don't include standard C headers inside of extern "C"
Including C headers inside of `extern "C"` breaks use from C++. Hoist
the includes of standard C headers above the block so we don't try
to mangle the stdlib.

I initially tried to scope this with a targeted change but it's too
hard to do correctly that way. This way, we avoid whack-a-mole.

Firefox is working around this in their e21461b7b8b39cc31ba53c47d4f6f310c673ff2f
commit.

Bug: https://bugzilla.mozilla.org/1953080
2025-05-30 09:48:28 +01:00
Wim Taymans
d9b742cfda bluez: avoid some compiler warnings 2025-05-28 15:15:25 +02:00
Wim Taymans
564c9b1ba5 Use "8 bit raw midi" for control ports again
There is no need to encode the potential format in the format.dsp of
control ports, this is just for legacy compatibility with JACK apps. The
actual format can be negotiated with the types field.

Fixes midi port visibility with apps compiled against 1.2, such as JACK
apps in flatpaks.
2025-05-23 16:46:13 +02:00
Arun Raghavan
9ff1c93ab1 media-sink: Set up ASHA source after setting transport state
We need to make sure the state is available when the source starts, so
that it does not assert in flush_data()
2025-05-17 10:25:37 -04:00
Pauli Virtanen
1e18cded75 bluez5: iso-io: improve latency logic
If kernel socket queues for different streams get out of sync, it will
mess up time alignment of different streams. If that happens, flush to
resync.

If total latency becomes too large, flush queue.

Get accurate queue sizes from tx timestamping.
2025-05-17 10:51:37 +00:00
Pauli Virtanen
489e4b6bd2 bluez5: latency tracking also for A2DP, use it for unsent size
Use TX timestamping to figure out the accurate amount of unsent data,
including controller buffers.  SIOCOUTQ does not report accurate data
size as it includes overheads.
2025-05-17 10:51:37 +00:00
Pauli Virtanen
897748759e bluez5: update timestamping code to match kernel & bluez
Update code to match the final version landed in mainline Linux 6.15
2025-05-17 10:51:37 +00:00
Pauli Virtanen
e375364c87 bluez5: fix device set profile/route enumerations
Now that we have ASHA & BAP, this->device_set now refers to the device
set of the active profile.  It cannot be used to produce
EnumProfile/EnumRoute.

Fix this by computing the device set for given profile(s) as needed.
2025-05-17 10:50:15 +00:00
Pauli Virtanen
e5d0dd2020 bluez5: enable asha device set only if there's a device set
Now that ASHA uses device set, no need to special case here.
2025-05-11 16:14:40 +03:00
Sanchayan Maity
a5a6973472 bluez5-dbus: Fix another build failure on 32-bit system 2025-05-09 07:09:26 +00:00
Sanchayan Maity
42b9b0eb4c bluez5-dbus: Fix the audio channel position for ASHA
For stereo to work, we need to advertise the channel position based on
whether the side is left or right.
2025-05-07 18:29:01 +05:30
Frédéric Danis
27fecd3c56 bluez5: backend-native: Fix hangup of waiting call
3-way incoming calls are created in waiting state. When those calls are
hang-up before being active, the +CIEV: (callsetup = 0) should also be
managed for waiting calls.
2025-05-07 07:41:28 +00:00
Sanchayan Maity
afa7ebc032 media-sink: Drop packet if send fails for ASHA
One of the ideas behind retrying the sending of a failed packet with the
poll callback was to make sure that we do not end up with missing seqnums
by missing received credit due to some jitter.

However, the rate matching behaviour for ASHA is not clear and we do not
seem to face problems in local testing by just dropping the packet.
2025-05-07 07:39:46 +00:00
Sanchayan Maity
e68111b4aa media-sink: Fix sequence number sync for ASHA
The two sides of a ASHA pair rarely if ever start together and the
sequence number was always a bit off due to the stateful nature of
reset_buffer and ASHA needing the sequence number to be matched to
the other side.

Simplify this by setting the sequence number for ASHA just before
flushing.
2025-05-07 07:39:46 +00:00
Sanchayan Maity
a419f69bbb bluez5-device: Refactor device_set_update for ASHA & BAP 2025-05-07 07:39:46 +00:00
Wim Taymans
445ca819ce bluez: fix format specifier
zu is for size_t, PRIu64 is for uint64_t
2025-05-07 09:38:24 +02:00
Sanchayan Maity
d96485190d bluez5: media-sink: Fix format specifier for log
This should fix the build on 32-bit systems.
2025-05-07 13:02:10 +05:30
Pauli Virtanen
584ea400c3 bluez5: fix spelling "Headphone" -> "Headphones"
"Headphone" is usually plural
2025-05-05 07:45:24 +00:00
Pauli Virtanen
270eda63a9 bluez5: different icon for A2DP & HFP output routes
Set different icons for A2DP & HFP output routes, so that they look
different (in Gnome).

Don't call the non-HFP output route as "headset" or "handsfree" in this
case, to be less ambiguous about microphone availability.

Also set device.icon-name for the device too.
2025-05-05 07:45:24 +00:00
Sanchayan Maity
9586ef891e bluez5: Use device set for ASHA
While ASHA does not really use the D-Bus device set interface
but since ASHA has a device-wide HiSyncId and needs to handle
left and right side via a combine sink, use the device set
notion for ASHA as well.
2025-05-05 07:43:34 +00:00
Sanchayan Maity
1b6830f68f bluez5: media-sink: Improvements for ASHA
Clean up as per feedback from Pauli and Barnabás.
2025-05-05 07:43:34 +00:00
Arun Raghavan
b02b69b271 bluez5: media-sink: Drop a redundant ASHA state variable 2025-05-05 07:43:34 +00:00
Arun Raghavan
ce8abfc5cc bluez5: media-sink: Refine ASHA other-side timer setup further
Let's just directly use the next timer value from the other side
directly, and the reference time as well to calculate the expected next
sample position we want to send from on this side.
2025-05-05 07:43:34 +00:00
Arun Raghavan
c5b5476aa4 bluez5: media-sink: Skip samples to align audio data for ASHA
For ASHA, we want the media sinks to send packets where the ASHA packet
sequence number corresponds to time position of audio in that packet.
2025-05-05 07:43:34 +00:00
Arun Raghavan
efb4a1df25 bluez5: media-sink: Snap timer to ASHA connection interval
For ASHA stereo, the timer for flushing packets on both sides of a
pair should be as closed to each other as possible.

Also set seqnum before first flush so other side sends the correct
packets at the start.
2025-05-05 07:43:34 +00:00
Arun Raghavan
4d22296d3a bluez5: media-sink: Use reference time for ASHA sequence numbers
This improves the sequence number generation by tying it to
get_reference_time.
2025-05-05 07:43:34 +00:00
Sanchayan Maity
24843a73c0 bluez5: media-sink: Support for ASHA stereo 2025-05-05 07:43:34 +00:00