From e9b78f1c31ac8ccf562a4827aab2801405f78417 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Sun, 24 Aug 2025 00:47:43 +0300 Subject: [PATCH] bluez5: media-source: add option to control the target latency of the decode-buffer On production systems, having a constant high latency is favored over dynamically adjusting it in order to optimize for low latency, because every time a dynamic adjustment happens, there's a glitch. This adds an option to let the user specify the exact amount of latency they want. --- doc/dox/config/pipewire-props.7.md | 5 +++++ spa/plugins/bluez5/media-source.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/doc/dox/config/pipewire-props.7.md b/doc/dox/config/pipewire-props.7.md index 6b854873c..1319297ff 100644 --- a/doc/dox/config/pipewire-props.7.md +++ b/doc/dox/config/pipewire-props.7.md @@ -1196,6 +1196,11 @@ this instance. Available values: - input: appear as source node. \endparblock +@PAR@ node-prop bluez5.decode-buffer.latency # integer +Applies on media source nodes and defines the target amount +of samples to be buffered on the output of the decoder. +Default: 0, which means it is automatically determined. + @PAR@ node-prop node.latency-offset-msec # string Applies only for BLE MIDI nodes. Latency adjustment to apply on the node. Larger values add a diff --git a/spa/plugins/bluez5/media-source.c b/spa/plugins/bluez5/media-source.c index 3394cb6c0..6d2833983 100644 --- a/spa/plugins/bluez5/media-source.c +++ b/spa/plugins/bluez5/media-source.c @@ -141,6 +141,8 @@ struct impl { unsigned int is_duplex:1; unsigned int is_internal:1; + unsigned int decode_buffer_target; + unsigned int node_latency; int fd; @@ -885,6 +887,8 @@ static int transport_start(struct impl *this) this->quantum_limit, this->quantum_limit)) < 0) return res; + spa_bt_decode_buffer_set_target_latency(&port->buffer, (int32_t) this->decode_buffer_target); + if (this->codec->kind == MEDIA_CODEC_HFP) { /* 40 ms max buffer (on top of duration) */ spa_bt_decode_buffer_set_max_extra_latency(&port->buffer, @@ -2057,6 +2061,9 @@ impl_init(const struct spa_handle_factory *factory, this->is_duplex = spa_atob(str); if ((str = spa_dict_lookup(info, "api.bluez5.internal")) != NULL) this->is_internal = spa_atob(str); + if ((str = spa_dict_lookup(info, "bluez5.decode-buffer.latency")) != NULL) { + spa_atou32(str, &this->decode_buffer_target, 0); + } } if (this->is_duplex) {