From patchwork Mon Dec 11 21:04:29 2023 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: 753614 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kZCUnhu2" Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1725DD2 for ; Mon, 11 Dec 2023 13:04:45 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3ba10647a19so752941b6e.3 for ; Mon, 11 Dec 2023 13:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702328683; x=1702933483; 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=pfJH2vBFvTk3Ec7zxskcSmGRALcmbhg3NKo1nMNN3hI=; b=kZCUnhu29RssESqN3L8NJJgPXAmgwPvEQOdsLRPz+uP8DuBOQLrunUgx5l5ttpsBCM +QdEfVTLlSoc/u2LRp0+/spv1SJgan9iTwXyyYijGfyHDEmsIOcffClmwyHPCAcxCQ+1 5873n6iw/yv30nHB2D8EcuHgnEqb6PbJznIuSStwpxK9818OYt+LGDwugvY0Z5Kr7cbH m686R/pNWQFtkdoyrGFuRkhh5Dv0Gp2+37bZ/18QHiZIVoFELoDBbV8uH6zayVnuJImX gTpzpPEsw4WxqdMj6uMQnc8s7Kyk6Ix/8j73XbmJZaVRxbVBoDQaQRNqWRjiXHIWrxL+ 9Dbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702328683; x=1702933483; 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=pfJH2vBFvTk3Ec7zxskcSmGRALcmbhg3NKo1nMNN3hI=; b=pHN3nv6CYI2ETYDOIB8Hd4AkaXpy/bRBGBmW3vp1gtlDXv3IQ8vK+YuD+rrIzIeXkX lPtZcMZfh4YZnHed0owgHj+/oYk6WdnStlnWhYbdwc2so9H5g9jT5N3e/btmFd7RVJyJ vbWQvNCOE3Jzsc+IohWo2teAn9Dv9T4G53GRdgCATTdtR39fXL9is4bgSQDlcI+AMwg4 jNAtUbin5Vba8Ub4Z4nL86hqx7jr2W6ybZeMku2D+5SJ3y5QIdKL9+a8VYFVWSZt6O1O Mnt8rYBPYcNkKSMGUx5Sll/R9BlK1RPTY1aiT4aQ0pVrWHW7kARfvXEcKCm37NT1E/QD Qasg== X-Gm-Message-State: AOJu0YwwzcVdm2oK1CXV92A9eWEJ9I4bDJtsPnWgEql1yMcaATOqg1o3 pVzPMwJ99D1Hvbi2StiKQ1uOimUg0jo= X-Google-Smtp-Source: AGHT+IEdime0O8jgS8dK8Elof5qaEZLKo9Em6yAKNLlyygcnR59o6k7HcfNqxS8GAqxWLOJsAoI6Uw== X-Received: by 2002:a05:6808:10c7:b0:3ba:fa:17ef with SMTP id s7-20020a05680810c700b003ba00fa17efmr5148336ois.91.1702328683168; Mon, 11 Dec 2023 13:04:43 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id k23-20020a05680808d700b003b85f47a3e1sm1996852oij.43.2023.12.11.13.04.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 13:04:41 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 6/6] client/player: Use ChannelAllocation given on SelectProperties Date: Mon, 11 Dec 2023 16:04:29 -0500 Message-ID: <20231211210429.530964-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231211210429.530964-1-luiz.dentz@gmail.com> References: <20231211210429.530964-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 makes use of ChannelAllocation when present on SelectProperties dictionary which is then passed on to bluetoothd and send over as part of Codec Configuration: < ACL Data TX: Handle 2048 flags 0x00 dlen 109 ATT: Write Command (0x52) len 104 Handle: 0x0098 Type: ASE Control Point (0x2bc6) Data: 0104050202060000000010020103020201030428000503010000000 6020206000000001002010302020103042800050302000000010202060000 0000100201030202010304280005030100000002020206000000001002010 302020103042800050302000000 Opcode: Codec Configuration (0x01) Number of ASE(s): 4 ASE: #0 ASE ID: 0x05 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000001 Front Left (0x00000001) ASE: #1 ASE ID: 0x06 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000002 Front Right (0x00000002) ASE: #2 ASE ID: 0x01 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000001 Front Left (0x00000001) ASE: #3 ASE ID: 0x02 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000002 Front Right (0x00000002) --- client/player.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/client/player.c b/client/player.c index 4d49602c70d7..92fc91f920f3 100644 --- a/client/player.c +++ b/client/player.c @@ -64,7 +64,7 @@ #define SEC_USEC(_t) (_t * 1000000L) #define TS_USEC(_ts) (SEC_USEC((_ts)->tv_sec) + NSEC_USEC((_ts)->tv_nsec)) -#define EP_SRC_LOCATIONS 0x00000001 +#define EP_SRC_LOCATIONS 0x00000003 #define EP_SNK_LOCATIONS 0x00000003 #define EP_SRC_CTXT 0x000f @@ -2104,13 +2104,42 @@ static struct iovec *iov_append(struct iovec **iov, const void *data, return *iov; } +static int parse_chan_alloc(DBusMessageIter *iter, uint32_t *location) +{ + while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) { + const char *key; + DBusMessageIter value, entry; + int var; + + dbus_message_iter_recurse(iter, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + var = dbus_message_iter_get_arg_type(&value); + + if (!strcasecmp(key, "ChannelAllocation")) { + if (var != DBUS_TYPE_UINT32) + return -EINVAL; + dbus_message_iter_get_basic(&value, location); + return 0; + } + + dbus_message_iter_next(iter); + } + + return -EINVAL; +} + static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, DBusMessage *msg, struct codec_preset *preset) { DBusMessage *reply; - DBusMessageIter iter; + DBusMessageIter iter, props; struct endpoint_config *cfg; + uint32_t location = 0; if (!preset) return NULL; @@ -2126,6 +2155,18 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, iov_append(&cfg->caps, preset->data.iov_base, preset->data.iov_len); cfg->target_latency = preset->target_latency; + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &props); + + if (!parse_chan_alloc(&props, &location)) { + uint8_t chan_alloc_ltv[] = { + 0x05, LC3_CONFIG_CHAN_ALLOC, location & 0xff, + location >> 8, location >> 16, location >> 24 + }; + + iov_append(&cfg->caps, &chan_alloc_ltv, sizeof(chan_alloc_ltv)); + } + /* Copy metadata */ if (ep->meta) iov_append(&cfg->meta, ep->meta->iov_base, ep->meta->iov_len);