From patchwork Mon Jul 22 20:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13739088 Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com [209.85.217.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A2DB28DC7 for ; Mon, 22 Jul 2024 20:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721681513; cv=none; b=IL+So9pcdo6vrJQvLFQ4gWsUxZ+6IjyfkpPjtDofTrYSDKGxFbzXAG9NwwSDYmL13liF4QAGb/1navev6CYOFb2zqCRmlixMoRvTDJu4jvqSXhei1ayT+Ffw8/PTkVw3byCMLXP3aSazUmPWoOVXz+pO3DeyFbQYeTEgR5mfL9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721681513; c=relaxed/simple; bh=/pHh7BHlMImsbYtPpQzfT+XgSptK3WKkKWt3sst1pTQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ipf4tLInn3MbqFm1kimA8Ogjk++X5mHzY4GqtLgZ7sUm6sCgRYoMvy+12KxPkY1F7IH2wY2zB29IXCyCGAVsCuAQRz4KKYVIRyNOWVjmZji71zX23bTUYssbVYgrwjq4eIi/EIsljom4riqvLVk7ys3oTvr+ypT+qR1ckQTCRQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HwxMP2CM; arc=none smtp.client-ip=209.85.217.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HwxMP2CM" Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-48c2d353b01so1643670137.2 for ; Mon, 22 Jul 2024 13:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721681510; x=1722286310; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=VOylXU3nEoFVhceX6cR2b0Tm705qNG+arenPHKSTtsM=; b=HwxMP2CMHryocRGoNjoar/X5ldIl+iDDfg331pEhDu4ZxdK3qLjI47xVPfa30pMb7j ILw+HgZ0LHHPlZ+O9dsteBrkMDzCMRIDMo65waTxgUYayz1YD9QjoOOgXZA/zX12J5/c or5NX3w9jBSnPlZEF40BgzTCWT1mWD4COK5MYFEGQBo+yQmJZsY2a20Yc68E3bVOmMLB Zn5N2t8WkKzSfyywjA7UgWMtZdqs9nVQbvjKTXRbU/ZfPf+DVWQDKuLWkFceYzL9ij9i 2gxatBkxTDzQkirz//DKVUTKMj+FL8+zX9MAotf4o/3CEOcpl+pS8Yjq4RCSGi3iAaGY NBsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721681510; x=1722286310; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VOylXU3nEoFVhceX6cR2b0Tm705qNG+arenPHKSTtsM=; b=RarklJVoMM7VC59+leFYJZbjhT4TqdRF26rajgFDWYjYtMglz77ct6DSiTfSIGiSfD 4S2U0DhyNWRqJDmSPcd8r0Ut588R8KuFRZz1Z9bk5cwhubHV+ERuo3JQRZiKIq7tIvCs OU7Ne/MEKDYQ7TnGToxkEWRy6+SLZqFY+025PFa1rlyEv3q9/tO4q3rj5kq4Y+yNayy9 QP6Ew6+6dcmUVnAH4g81xTdb7KQ4Fm7Jj65R9b7Q1t0a+/kHe1vhTWbJ5W4lVbNQ0e61 WBWCxsMmWdFEM8P99nXowxrnPLFpqugcepsqX8vJYDyC2GOL+ScanWHaG08X1yfcjg4C gL4g== X-Gm-Message-State: AOJu0YyanLLxbw6wDtRoyvYW26LrMrmb3TUDeL75grWytN+l0QvrxT6g OeEeDoZC5OR5GYHtXslwty17TnITSjF9mDtfvoIA20ve8TzqbRb2R/WcVg== X-Google-Smtp-Source: AGHT+IHMDQoKftMQer8NBcHndBFJVsPSAu3wEzhTo5xepzz3aSSRVFT3k4UcE+kXAzotnD/QSFfKRA== X-Received: by 2002:a05:6102:f87:b0:492:9d0b:1d58 with SMTP id ada2fe7eead31-4929d0b2040mr5737227137.5.1721681510513; Mon, 22 Jul 2024 13:51:50 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4927922bf52sm1946183137.8.2024.07.22.13.51.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:51:49 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 1/2] client/player: Set number of channels based on locations Date: Mon, 22 Jul 2024 16:51:47 -0400 Message-ID: <20240722205148.2273531-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This sets the number of channels based on the locations set rather than always hardcoding it to 3 which in certain case is incorrect and can lead for the same location to be configured multiple times. --- client/player.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/client/player.c b/client/player.c index 5b0b918fb8d7..486629a9add2 100644 --- a/client/player.c +++ b/client/player.c @@ -1140,10 +1140,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, .meta = _meta, \ } -#define LC3_DATA(_freq, _duration, _chan_count, _len_min, _len_max) \ +#define LC3_DATA(_freq, _duration, _len_min, _len_max) \ UTIL_IOV_INIT(0x03, LC3_FREQ, _freq, _freq >> 8, \ 0x02, LC3_DURATION, _duration, \ - 0x02, LC3_CHAN_COUNT, _chan_count, \ 0x05, LC3_FRAME_LEN, _len_min, _len_min >> 8, \ _len_max, _len_max >> 8) @@ -1182,11 +1181,10 @@ static const struct capabilities { * * Frequencies: 8Khz 11Khz 16Khz 22Khz 24Khz 32Khz 44.1Khz 48Khz * Duration: 7.5 ms 10 ms - * Channel count: 3 * Frame length: 26-240 */ CODEC_CAPABILITIES("pac_snk/lc3", PAC_SINK_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1198,7 +1196,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("pac_src/lc3", PAC_SOURCE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1210,7 +1208,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("bcaa/lc3", BCAA_SERVICE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1222,7 +1220,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("baa/lc3", BAA_SERVICE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), }; @@ -3220,6 +3218,7 @@ static void endpoint_locations(const char *input, void *user_data) struct endpoint *ep = user_data; char *endptr = NULL; int value; + uint8_t channels; value = strtol(input, &endptr, 0); @@ -3230,6 +3229,10 @@ static void endpoint_locations(const char *input, void *user_data) ep->locations = value; + /* Update LC3_CHAN_COUNT based on the locations */ + channels = __builtin_popcount(value); + util_ltv_push(ep->caps, sizeof(channels), LC3_CHAN_COUNT, &channels); + bt_shell_prompt_input(ep->path, "Supported Context (value):", endpoint_supported_context, ep); } @@ -4186,6 +4189,8 @@ static const struct bt_shell_menu endpoint_menu = { static void endpoint_init_bcast(struct endpoint *ep) { + uint8_t channels; + if (!strcmp(ep->uuid, BAA_SERVICE_UUID)) { ep->locations = EP_SNK_LOCATIONS; ep->supported_context = EP_SUPPORTED_SNK_CTXT; @@ -4193,6 +4198,10 @@ static void endpoint_init_bcast(struct endpoint *ep) ep->locations = EP_SRC_LOCATIONS; ep->supported_context = EP_SUPPORTED_SRC_CTXT; } + + /* Update LC3_CHAN_COUNT based on the locations */ + channels = __builtin_popcount(ep->locations); + util_ltv_push(ep->caps, sizeof(channels), LC3_CHAN_COUNT, &channels); } static void endpoint_init_ucast(struct endpoint *ep) From patchwork Mon Jul 22 20:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13739089 Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D88434CC4 for ; Mon, 22 Jul 2024 20:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721681515; cv=none; b=MRjS1WBCoD3iaOOr4wGuSGTzlyTeegtTTckO6jBjt3ShG+dl8UKFTJbleG4DhuA+gVPhABJXMooG1FV0obsau6pKTNUpcAq2yw95yrixIXfFLrrRssrXClxQWKHsMtnzqFUKEsHxBLawsHJAtxM2gQ58vO/mean12NBcNxIo32k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721681515; c=relaxed/simple; bh=LJ5/f2UMo4MaytBQxKKBIV05iIVcIQN7qgH3JfI8VqM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kNyswXxUWtfPpRXxBLA8b8XOUMwAmmwlGBrTDu81Bd5OMsj+1SM/2ZEZ4yzSeZ2G0SQLy+1XLB8Q5fU6L4HsIehpJhTXJdj7kv9UUbt14DTbRTyBdRxnY/RU5uDE7mpZ7WAiiO+hFtQGDn+HsgPGp4OeN8mB1ccftfJdvWnreH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QRH78Ljm; arc=none smtp.client-ip=209.85.217.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QRH78Ljm" Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-492959b906eso638756137.0 for ; Mon, 22 Jul 2024 13:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721681512; x=1722286312; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3ZmB/diYCDwSKTljthaaRIP6shijD5EXkmxWi90bHm0=; b=QRH78LjmQeqw41gnMmsK2KJXxTXjTOwqJR88A+g01BgUwZ92Knlh3t1j7rPgtbzdvD Hz33UE+NXZnvp2iS7OJgQoQNjSaLzpxEeXPvCTLXYW/v+xuIuPYUjLS6PCXDUZez7GgC Im3xsLnSeECmwfZ2YeCNJ1WVLOEdOzhVy543BvGCnMWV8sJSksl4bquGHgoNCnU5fqKL ujnS/x1EOU//fap9snhjHQ/YVQ4zLO2DUzVneTlNm0DVt4rZ74mYy6iFUAlbkmriWBjn 7+4om5vDWXwWl42I87tNxtXvthRM7+MbCLZhrGmOeGsgg5CuRtzzBNMBPFlfMClSGDsV Zx+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721681512; x=1722286312; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ZmB/diYCDwSKTljthaaRIP6shijD5EXkmxWi90bHm0=; b=BHcYFc/eopvqyPsZ6PIXspd6S2swFp+/4w6T7vtV9uR/MEazNV5pGRTZTlbfkZq2X7 76kcan6WJK114Ln0OFXtLV7a4MtgBubXvIWPNK7FAIbFVWyMZy4gRMgiPz9ggBRxGqDm VwvefJh5QW6QyEO9nPfcAAnCDtX7J48aeNyCS/HeIfKumsW3zHZ0Q6kT3PS7ojGf1/mY Zs3K2bKtnHM2eVPOANQQGE6/SfM5aFZ2caXwJCPYzIByAbU/S3RljjGHlDLIoCcMyBi8 W43CaijdpBy1TMb4SnFF1lXNZ17uG6fXkmG7lOjEemICTDRUsca1Wduff4uCoahTxFj+ zufg== X-Gm-Message-State: AOJu0YyBTxOF8ZoQU8FN8SuH6aU5hY0tMunM3L9g9GGtmShb6wcMNagG ns3LVD91EEM3j7XV5tmJ95/+gXOJUaXS8D9jMVtS1nwA8pZIxx4imQ8nyA== X-Google-Smtp-Source: AGHT+IHf5ng4TRPyZKvA06E9i34Zo3SOOPXNAvPR+x5kY5HnXTojsfHJ7qe5+8srIljTLa+xj9S1vQ== X-Received: by 2002:a05:6102:5e98:b0:48f:143a:d8e9 with SMTP id ada2fe7eead31-4928ba6cdabmr9051312137.20.1721681512184; Mon, 22 Jul 2024 13:51:52 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4927922bf52sm1946183137.8.2024.07.22.13.51.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:51:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 2/2] client/player: Add support to enter alternative preset Date: Mon, 22 Jul 2024 16:51:48 -0400 Message-ID: <20240722205148.2273531-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240722205148.2273531-1-luiz.dentz@gmail.com> References: <20240722205148.2273531-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds support for alternative preset to be entered so when auto accepting configuration a different preset can be selected following the order given to endpoint.presets. --- client/player.c | 74 ++++++++++++++++++++++++++++++++++++++++++++---- src/shared/bap.c | 2 +- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/client/player.c b/client/player.c index 486629a9add2..640bef92a7ae 100644 --- a/client/player.c +++ b/client/player.c @@ -1230,7 +1230,10 @@ struct codec_preset { const struct iovec data; struct bt_bap_qos qos; uint8_t target_latency; + uint32_t chan_alloc; bool custom; + bool alt; + struct codec_preset *alt_preset; }; #define SBC_PRESET(_name, _data) \ @@ -1969,12 +1972,18 @@ static int parse_chan_alloc(DBusMessageIter *iter, uint32_t *location, if (*channels) *channels = __builtin_popcount(*location); return 0; + } else if (!strcasecmp(key, "Locations")) { + if (var != DBUS_TYPE_UINT32) + return -EINVAL; + dbus_message_iter_get_basic(&value, location); + if (*channels) + *channels = __builtin_popcount(*location); } dbus_message_iter_next(iter); } - return -EINVAL; + return *location ? 0 : -EINVAL; } static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, @@ -2010,6 +2019,24 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, 0x05, LC3_CONFIG_CHAN_ALLOC, location & 0xff, location >> 8, location >> 16, location >> 24 }; + uint32_t chan_alloc = 0; + + if (preset->chan_alloc & location) + chan_alloc = preset->chan_alloc & location; + else if (preset->alt_preset && + preset->alt_preset->chan_alloc & + location) { + chan_alloc = preset->alt_preset->chan_alloc & location; + preset = preset->alt_preset; + + /* Copy alternate capabilities */ + util_iov_free(cfg->caps, 1); + cfg->caps = util_iov_dup(&preset->data, 1); + cfg->target_latency = preset->target_latency; + } + + if (chan_alloc) + put_le32(chan_alloc, &chan_alloc_ltv[2]); util_iov_append(cfg->caps, &chan_alloc_ltv, sizeof(chan_alloc_ltv)); @@ -2035,6 +2062,8 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, dbus_message_iter_init_append(reply, &iter); + bt_shell_printf("selecting %s...\n", preset->name); + append_properties(&iter, cfg); free(cfg); @@ -2098,8 +2127,6 @@ static DBusMessage *endpoint_select_properties(DBusConnection *conn, if (!reply) return NULL; - bt_shell_printf("Auto Accepting using %s...\n", p->name); - return reply; } @@ -4104,13 +4131,38 @@ static void print_presets(struct preset *preset) for (i = 0; i < preset->num_presets; i++) { p = &preset->presets[i]; - bt_shell_printf("%s%s\n", p == preset->default_preset ? - "*" : "", p->name); + + if (p == preset->default_preset) + bt_shell_printf("*%s\n", p->name); + else if (preset->default_preset && + p == preset->default_preset->alt_preset) + bt_shell_printf("**%s\n", p->name); + else + bt_shell_printf("%s\n", p->name); } queue_foreach(preset->custom, foreach_custom_preset_print, preset); } +static void custom_chan_alloc(const char *input, void *user_data) +{ + struct codec_preset *p = user_data; + char *endptr = NULL; + + p->chan_alloc = strtol(input, &endptr, 0); + if (!endptr || *endptr != '\0') { + bt_shell_printf("Invalid argument: %s\n", input); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if (p->alt_preset) + bt_shell_prompt_input(p->alt_preset->name, + "Enter Channel Allocation: ", + custom_chan_alloc, p->alt_preset); + else + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + static void cmd_presets_endpoint(int argc, char *argv[]) { struct preset *preset; @@ -4131,8 +4183,20 @@ static void cmd_presets_endpoint(int argc, char *argv[]) preset->default_preset = default_preset; if (argc > 4) { + struct codec_preset *alt_preset; struct iovec *iov = (void *)&default_preset->data; + /* Check if and alternative preset was given */ + alt_preset = preset_find_name(preset, argv[4]); + if (alt_preset) { + default_preset->alt_preset = alt_preset; + bt_shell_prompt_input(default_preset->name, + "Enter Channel Allocation: ", + custom_chan_alloc, + default_preset); + return; + } + iov->iov_base = str2bytearray(argv[4], &iov->iov_len); if (!iov->iov_base) { bt_shell_printf("Invalid configuration %s\n", diff --git a/src/shared/bap.c b/src/shared/bap.c index 0aa89c2781ba..4bec51011469 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -5420,7 +5420,7 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, selected++; /* Check if there are any channels left to select */ - map.count &= ~(map.count & rc->count); + map.count &= ~(map.count & rc->count); /* Check if there are any locations left to select */ map.location &= ~(map.location & rc->location);