From 6dfb164cabf09efe646eb92c7e80d5e80a8d6863 Mon Sep 17 00:00:00 2001 From: Vinit Mehta Date: Mon, 3 Mar 2025 15:25:48 +0530 Subject: [PATCH] bluez5: Add support to configure & select BAP QoS config The current BAP unicast QoS configuration allows to register a sampling frequency based on the configuration done using wireplumber configuration. However, for a scenario were the user need to use a specific SDU framelength it cannot be done as the select_bap_qos function selects the QoS based on priority and hence it will use the best possible config rather than the user configured. This PR adds option to select the QoS set based on user configured value. If the remote device doesn't have the user configured capabilities it will always use the best priority config. Further, this change also allows the user to set RTN, Latency, Delay QoS config for certain use case to have controller use optimum bandwidth usage. Below is the example for the options that can be configured & selected in config file: bluez5.bap.set_name = "48_2_1" bluez5.bap.rtn = 5 bluez5.bap.latency = 20 bluez5.bap.delay = 40000 bluez5.framing = false --- spa/plugins/bluez5/bap-codec-lc3.c | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/bap-codec-lc3.c b/spa/plugins/bluez5/bap-codec-lc3.c index e9b772325..93b241796 100644 --- a/spa/plugins/bluez5/bap-codec-lc3.c +++ b/spa/plugins/bluez5/bap-codec-lc3.c @@ -111,7 +111,7 @@ static const struct { .framelen = (framelen_), .retransmission = (rtn_), .latency = (latency_), \ .delay = (delay_), .priority = (priority_) }) -static const struct bap_qos bap_qos_configs[] = { +static struct bap_qos bap_qos_configs[] = { /* Priority: low-latency > high-reliability, 7.5ms > 10ms, * bigger frequency and sdu better */ @@ -789,8 +789,10 @@ static int codec_select_config(const struct media_codec *codec, uint32_t flags, uint32_t locations = 0; uint32_t channel_allocation = 0; bool sink = false, duplex = false; + uint32_t value = 0; struct spa_debug_log_ctx debug_ctx = SPA_LOG_DEBUG_INIT(log_, SPA_LOG_LEVEL_TRACE); int i; + const char *str; if (caps == NULL) return -EINVAL; @@ -811,8 +813,41 @@ static int codec_select_config(const struct media_codec *codec, uint32_t flags, /* Is remote endpoint duplex */ duplex = spa_atob(spa_dict_lookup(settings, "bluez5.bap.duplex")); + + + if ((str = spa_dict_lookup(settings, "bluez5.bap.set_name"))) { + + SPA_FOR_EACH_ELEMENT_VAR(bap_qos_configs, qos_sets) { + + if (spa_streq(str, qos_sets->name)) { + + spa_log_debug(log_, "Found Forced QoS For Set: %s\n", qos_sets->name); + + if (settings && (str = spa_dict_lookup(settings, "bluez5.bap.rtn"))) + if (spa_atou32(str, &value, 0)) + qos_sets->retransmission = value; + + if (settings && (str = spa_dict_lookup(settings, "bluez5.bap.latency"))) + if (spa_atou32(str, &value, 0)) + qos_sets->latency = value; + + if (settings && (str = spa_dict_lookup(settings, "bluez5.bap.delay"))) + if (spa_atou32(str, &value, 0)) + qos_sets->delay = value; + + if (settings && (str = spa_dict_lookup(settings, "bluez5.framing"))) + qos_sets->framing = spa_atob(str); + + /* We set highest priority for the forced configuration. This allows the + * config to be used when LC3 QoS is selected at the time of CIS creation*/ + qos_sets->priority = 0xFF; + break; + } + } + } } + /* Select best conf from those possible */ npacs = parse_bluez_pacs(caps, caps_size, pacs, &debug_ctx.ctx); if (npacs < 0) {