Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3206502rwi; Fri, 21 Oct 2022 13:05:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BA90IkLFNp8xoB3yxaF95IBanfnwzdYp/rpsejk/1hk+ksspSJ61OmRpDqJamBiyCbE4X X-Received: by 2002:a17:907:96a6:b0:78d:b6f6:3886 with SMTP id hd38-20020a17090796a600b0078db6f63886mr17694024ejc.106.1666382739535; Fri, 21 Oct 2022 13:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666382739; cv=none; d=google.com; s=arc-20160816; b=iW9AkSkOKCHJ/pQAfGj0G+TwfW+D06in+/RLodyzAb7TjELDhtZ5/neTXhyK28kbF/ bQXGybob3YCxMOxe0SGaLTw1pW2JJVaETosoGwF0Gph5gtoo8pDtDQWFVrZPOhcDLmhE U25OZcFxTsbh5yjFc5UkVdQgYtB00I3OADB+Ef9CdcIwLuDr9TI3Mo70rS/hk19rk1Qt VHKwhnofBpRmp90VyJfypQdzU/ABibTNKVQU3hdSKlN26dszklheCZsycu1w1QhXDOlo vT4OTmiuhbqaVtR9c7adrabIWs9b1cCxydGcwErEfqEFQVpKi5OTAqrvy+uMFc8ZDQwQ 6aAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=WOq7eMmCKWR1anbCxSOfEtznn/rAq3lwaVUhOxv12Mg=; b=frO6fEROEqedPGUhWEDy/PIKN1YadWM3b4Lu+4V7N4yld1ZYjzhy8yMpAvW+MYjomf EzlUpVLSKfsoZrBiLvZaI5nOapCl+rlMcvGk8fvQ4dH14rh8BNnVRbtyTN4W6fcaYDHP zvMz+dGYt+LeHw7yVSFYJW8c71rtmhRQTLnW/DNZWiCJPrLbE99DPvIIzmrRTXFVFkDq ygkbe4cPgRo5tx+YEOrXM5jt0dnE2bWd/TElylxkkTpetny1sgM1LZkWapo2J8fi6BZy /CfPXqRUUe96oH2fUxIc0IMd2bwkzXBmGU70A3hAGNUwmfgxvMiaFukAKVW4ZaeD3Q+z qHvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zonji7vr; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a508e02000000b00460ce6c3a1asi4860601edw.454.2022.10.21.13.04.59; Fri, 21 Oct 2022 13:05:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zonji7vr; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230238AbiJUT6J (ORCPT + 99 others); Fri, 21 Oct 2022 15:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230310AbiJUT5s (ORCPT ); Fri, 21 Oct 2022 15:57:48 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE6329B8B4 for ; Fri, 21 Oct 2022 12:57:47 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d10so3554281pfh.6 for ; Fri, 21 Oct 2022 12:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=WOq7eMmCKWR1anbCxSOfEtznn/rAq3lwaVUhOxv12Mg=; b=Zonji7vrON+bNuQLJfjYqXi/TJz58WnwPbQcxOqpN7VslpIAzpl4ypanl67TV7nwJr nCxltNsl2/0oDS4TwlNjd975BCs1u3Yf3kMYIikVMjRpFSiCN2Q9QKKO3IiS9kfikMit Gr42N6FNkLRgmGRP8IfmzBZA9E0dHk2vGO1N7yslG0+Ljm5avpA4Yrhwy/u/+q7k2AYL 2x6zGy+a2OGXq0yHxamn/63v1xj4BBRF7yjjQ2oZzN3jpuMAZ5vUVbtE/M9Pm4x3GbLj 0lbE3I8znHTSkMaDCJi4xOY+5CG1gBsl9KgU40Rp4wpgNx0ek7tLUNTMxWQTlsCSVFfy Fl3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=WOq7eMmCKWR1anbCxSOfEtznn/rAq3lwaVUhOxv12Mg=; b=VsgOwmjfMDtfDW/3zMglqZJLaY7qav6inFDMIqfyLqLvvFmLcSpVsFdbkWFO5HS1ld arUXJETSbVV9xuu4/ihz8ZFbuEGHLLR2l+J92ll590+C6jfQcduuVwaorqyMu+0rbSCm mzMBEOTDtTNscW5qJ2IbN0nWm4cpdNmr8I6dW2pT+T97XYAdBoRU+ut9b3l92vfuygez /TShMuXG1KGl/7yhwXqWGRVjM8ywxQVhz99PmjmNs4/bWZJlCvDQim0qXM+D74mHPVRG WJTAv766Wl78s1p+YMGxzdehZknbs3R4qn/IYKHyQuS/lrCxwpmvdiyFQPBNQAyo+RFL iiow== X-Gm-Message-State: ACrzQf3Vaevha/ObqN2mOiqV+8Ors1vYR8obL+5bK3Txmgxy1oUk51gW zlMTsrOmscHHIngIEYSOm2j86bvlbz4= X-Received: by 2002:a63:fd58:0:b0:46b:41d:9d33 with SMTP id m24-20020a63fd58000000b0046b041d9d33mr17770552pgj.399.1666382265994; Fri, 21 Oct 2022 12:57:45 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id a8-20020a1709027d8800b001743ba85d39sm15099665plm.110.2022.10.21.12.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 12:57:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [RFC BlueZ] shared/bap: Merge PAC records of the same type/codec Date: Fri, 21 Oct 2022 12:57:43 -0700 Message-Id: <20221021195743.490649-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This attempts to merge PAC records which contain the same type and codec to simplify the matching with client endpoints so all capabilities and metadata are match at once instead of for each PAC record. --- src/shared/bap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/shared/bap.c b/src/shared/bap.c index c3c0d596fe91..109a5d28b1b4 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -284,6 +284,12 @@ static void *iov_add_mem(struct iovec *iov, size_t len, const void *d) return data; } +static void *iov_append(struct iovec *iov, size_t len, const void *d) +{ + iov->iov_base = realloc(iov->iov_base, iov->iov_len + len); + return iov_add_mem(iov, len, d); +} + static void iov_free(void *data) { struct iovec *iov = data; @@ -2319,6 +2325,52 @@ static struct bt_ascs *bap_get_ascs(struct bt_bap *bap) return bap->rdb->ascs; } +static bool match_codec(const void *data, const void *user_data) +{ + const struct bt_bap_pac *pac = data; + const struct bt_bap_codec *codec = user_data; + + return bap_codec_equal(&pac->codec, codec); +} + +static struct bt_bap_pac *bap_pac_find(struct bt_bap_db *bdb, uint8_t type, + struct bt_bap_codec *codec) +{ + switch (type) { + case BT_BAP_SOURCE: + return queue_find(bdb->sources, match_codec, codec); + case BT_BAP_SINK: + return queue_find(bdb->sinks, match_codec, codec); + } + + return NULL; +} + +static void *ltv_merge(struct iovec *data, struct iovec *cont) +{ + uint8_t delimiter = 0; + + iov_append(data, sizeof(delimiter), &delimiter); + + return iov_append(data, cont->iov_len, cont->iov_base); +} + +static void bap_pac_merge(struct bt_bap_pac *pac, struct iovec *data, + struct iovec *metadata) +{ + /* Merge data into existing record */ + if (pac->data) + ltv_merge(pac->data, data); + else + pac->data = iov_dup(data, 1); + + /* Merge metadata into existing record */ + if (pac->metadata) + ltv_merge(pac->metadata, metadata); + else + pac->metadata = iov_dup(metadata, 1); +} + static struct bt_bap_pac *bap_pac_new(struct bt_bap_db *bdb, const char *name, uint8_t type, struct bt_bap_codec *codec, @@ -2328,6 +2380,15 @@ static struct bt_bap_pac *bap_pac_new(struct bt_bap_db *bdb, const char *name, { struct bt_bap_pac *pac; + if (!qos) { + /* Check if there is already a PAC record for the codec */ + pac = bap_pac_find(bdb, type, codec); + if (pac) { + bap_pac_merge(pac, data, metadata); + return pac; + } + } + pac = new0(struct bt_bap_pac, 1); pac->bdb = bdb; pac->name = name ? strdup(name) : NULL; -- 2.37.3