Commit graph

40 commits

Author SHA1 Message Date
Wim Taymans
f453b1545d audio: don't use SPA_AUDIO_MAX_CHANNELS in some places
When we know the max size of the array, just use this instead of the
SPA_AUDIO_MAX_CHANNELS constant.
2025-10-20 18:31:17 +02:00
Pauli Virtanen
ff81fc9f7b bluez5: fix ISO sequence numbering
Pass zero-length packets to the codec. BAP/ISO may use these to indicate
missing data.

Fix A2DP codecs to not parse input with spa_return_val_if_fail, that's
meant for assertions. Just return -EINVAL directly, it's normal that
input data may contain garbage.
2025-07-12 19:59:33 +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
Iulia Tanasescu
9a5b2d42f9 bluez5: Configure LC3 codec capabilities
Currently, the PipeWire daemon registers BlueZ LE Media Endpoints
with audio capabilities covering all settings defined in the BAP spec.
However, some scenarios might require the capabilities to be restricted
to specific configurations.

This adds a method to read LC3 codec specific capabilities from the
Wireplumber config file, and provide those settings when registering
Media Endpoint objects with BlueZ. If the values are not present in
the config file, all settings will be used by default.

Below is an example of how to set the LC3 capabilities in the config
file, to support the 16_2 setting from the BAP spec:

bluez5.bap-server-capabilities.rates = [16000]
bluez5.bap-server-capabilities.durations = [10]
bluez5.bap-server-capabilities.channels = [1, 2]
bluez5.bap-server-capabilities.framelen_min = 40
bluez5.bap-server-capabilities.framelen_max = 40
bluez5.bap-server-capabilities.max_frames = 2
2024-12-14 10:57:23 +00:00
Pauli Virtanen
2d30ab94c2 bluez5: account for codec internal delay in latency values
Encoders and some decoders have additional internal latency that needs
to be accounted for.

This mostly matters for AAC (~40ms), as the other BT codecs have much
lower delays (~5ms).
2024-12-07 18:28:17 +00:00
Pauli Virtanen
83050e647b bluez5: aptx-ll: produce 7.5ms packets
Put a bit more samples to packets to make it more robust.  The 7.5ms
interval may also fit better with other BT devices.
2024-02-05 19:34:47 +02:00
Wim Taymans
0333ddff45 pod-builder: move some code around to help gcc 13
Make sure to pop the frame before returning errors to stop gcc13
from complaining with -Wdangling-pointer

Fixes #3171
2023-04-20 17:52:27 +02: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
Frédéric Danis
00d51c3d31 bluez5: Rename codec API from *a2dp* to *media*
The BlueZ Media1 interface will not only be used for A2DP but also for
LE Audio and code related can be shared.
2022-09-15 11:17:20 +00:00
Pauli Virtanen
d29aafd857 bluez5: enable A2DP duplex volume boost only if codec asks for it
Make A2DP volume boost conditional on a flag the codec sets.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
a8eb146d39 bluez5: tell the codec whether endpoint is sink or source
Add a flag A2DP_CODEC_FLAG_SINK to incidate a sink endpoint.

Also enum_config and caps_preference_cmp may need to know whether the
codec is being configured for SRC or SNK. Also add the flags argument to
init_props.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
3d4eafcb0f bluez5: allow codecs to produce multiple packets from same data
Codecs may need to fragment a single encoder frame across multiple
packets that are sent consecutively.

Allow codec->encode() to set need_flush=NEED_FLUSH_FRAGMENT, so that
sink should immediately call start_encode + encode with NULL input data,
to produce the next packet.

Previously, other return values than need_flush=1 were unused, so no
need to bump codec ABI for this.
2022-04-30 23:43:10 +03:00
Pauli Virtanen
c3a8041e0f bluez5: fix aptx-ll max_frames handling 2022-03-11 18:09:55 +02:00
Pauli Virtanen
1e5f499ed3 bluez5: fix aptx-ll caps size
Ensure SEP exposed by Pipewire has the full aptx-LL caps also for duplex
profile.
2021-12-11 17:20:39 +02:00
Pauli Virtanen
59d572de09 bluez5: split A2DP codecs to separate SPA plugins
Make easier to package A2DP codecs separately, by splitting each to a
separate SPA plugin.  Adjust the code to not use a global variable for
the codec list.

The A2DP SPA interface API is in the bluez5 private headers, and not
exposed in installed SPA headers, as it's too close to the
implementation.
2021-09-03 20:40:30 +03:00
Pauli Virtanen
63ba9f98ba bluez5: don't create aptx-ll/faststream sink endpoints
We don't currently implement encoding for the duplex channel
for these codecs, so they are not fully functional as A2DP sinks,
and their main use is anyway with headphones.

Also, the number of endpoints in BlueZ appears to be limited, and
appears to be counted across all adapters.  Unclear whether this comes
from AVDTP limitation, but currently plugging in a second BT adapter
causes the second media application registration to fail.  This change
reduces the number of endpoints enough so that registration succeeds for
two adapters.
2021-08-25 20:58:15 +03:00
Pauli Virtanen
ab5fcf4a66 bluez5: boost A2DP duplex microphone volume by 20 dB
There doesn't seem to be a way to control the A2DP duplex microphone
HW volume gain, and devices sometimes have very low mic volumes.

Work around this by boosting the software volume scale by +20 dB.  If it
causes clipping, the user can just reduce the volume to bring SW gain
below 1.0.
2021-08-23 08:17:46 +00:00
Pauli Virtanen
dedc08cdf8 bluez5: enable duplex for aptx-ll
aptX-LL sink devices may send back mSBC encoded data corresponding to
microphone input.  It appears to be enabled when the bidirectional link
is set in the caps, and the device also supports this.

Implement mSBC decoding in the duplex channel.

Tested to be working on Avantree Aria Pro.
2021-08-22 17:41:50 +03:00
Pauli Virtanen
90b62ba2b3 bluez5: add aptx-LL codec
Support the low-latency variant of the aptx codec.

The magic mostly seems to be on the device side, since the stream is the
same as standard aptx, but latency is smaller even if stream/packet
sizes are the same.

Sound output latency is noticeably less than with the standard aptx.
Tested on Sennheiser HD 250 / Avantree Aria Pro.

The codec in principle also supports bidirectional duplex streams,
but that is not implemented here.
2021-08-18 19:55:22 +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
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
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
Huang-Huang Bao
9384ba5500 bluez5: add properties for A2DP codec sample rate & channel mode configuration
Those properties are set as reference sample rate and channels number for A2DP configuration selecting.
2021-05-03 10:07:42 +00:00
Huang-Huang Bao
5c93f780cf a2dp: improve a2dp sink codec data flushing
Let codec decides when rtp packet need to be sent (terminated by MTU size in most case).
LDAC encoding loop can now be terminated by reading if frame_num is written, no 'frame_count' updating is needed.
RTP payload fragmentation can now be implemented more easily based on this.
2021-03-31 11:14:58 +00:00
Pauli Virtanen
a552655edc bluez5: add bluetoothAudioCodec property to device
Also make the "codecless" profiles to automatically switch to the codec
profiles.
2021-03-26 16:59:07 +00:00
Huang-Huang Bao
1d390addb1 a2dp: allow codec to hold Props params
Initial Props value are parsed from device settings, further changes are triggered by 'set_param' on a2dp node.
Codec can then use props to tweak its transcoder.
2021-03-20 09:16:20 +00:00
Pauli Virtanen
0908588d0c bluez5: add codec check_caps + check vendor codec id for ldac & aptx 2021-02-02 09:56:29 +00:00
Huang-Huang
c778bd734c
a2dp: improve codec specific transport socket send buffer size setting 2021-01-31 09:01:40 +08:00
Wim Taymans
5bb7a0f573 a2dp-codecs: add settings to codec init function
To make it possible to add extra config options in init.
Also add a method to update settings in a codec.
2021-01-07 17:39:39 +01:00
Wim Taymans
ece8a95c29 bluez5: improve a2dp codec api
Pass dict to select_config to influence the selection
Make a method to validate a config.
Add spa_dict to the codec to pass more info around.
2021-01-07 17:28:49 +01:00
Huang-Huang Bao
4621792354
a2dp: add missing function abr_process in a2dp_codec_aptx
Signed-off-by: Huang-Huang Bao <eh5@sokka.cn>
2020-12-20 04:53:21 +08:00
Huang-Huang Bao
16f5058af9
a2dp: add ldac ABR support
Signed-off-by: Huang-Huang Bao <eh5@sokka.cn>
2020-12-19 19:17:15 +08:00
Huang-Huang Bao
161c05d737 a2dp: fix aptx hd codec negotiation
Signed-off-by: Huang-Huang Bao <eh5@sokka.cn>
2020-12-17 14:17:37 +00:00
Wim Taymans
90bdab8414 bluez5: improve param enumeration
Return -EIO when we can't enumerate the params
Don't check for end-of-params in a2dp-sink, we do that in the codec.
2020-12-17 11:43:53 +01:00
Wim Taymans
6bc8ab18dc bluez5: aptx wants S24 input sample format 2020-12-11 15:13:59 +01:00
Wim Taymans
8b52e44836 bluez5: support other ldac bit depth
Make the format_info const in codec_init, we just need to read the
final negotiated format in some cases.
Add some more ldac bit depths we support.
2020-12-11 13:30:11 +01:00
Wim Taymans
34a9b1dc1a a2dp: set channel map 2020-12-09 18:08:24 +01:00
Wim Taymans
29fe356fdf a2dp: copy aptx config in configure 2020-12-09 18:00:42 +01:00
Kamil Sołtysik
0a8a854721 Fix codec names in comments 2020-12-05 19:23:27 +01:00
Wim Taymans
106d597305 bluez5: add aptX and aptX HD codecs
They need the libopenaptx libraries from
https://github.com/pali/libopenaptx
2020-12-04 11:34:38 +01:00