diff mbox series

[RFC,BlueZ] shared/bap: Merge PAC records of the same type/codec

Message ID 20221021195743.490649-1-luiz.dentz@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC,BlueZ] shared/bap: Merge PAC records of the same type/codec | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS
tedd_an/setupell success Setup ELL PASS
tedd_an/buildprep success Build Prep PASS
tedd_an/build success Build Configuration PASS
tedd_an/makecheck success Make Check PASS
tedd_an/makecheckvalgrind success Make Check PASS
tedd_an/makedistcheck success Make Distcheck PASS
tedd_an/build_extell success Build External ELL PASS
tedd_an/build_extell_make success Build Make with External ELL PASS
tedd_an/incremental_build success Pass
tedd_an/scan_build success Pass

Commit Message

Luiz Augusto von Dentz Oct. 21, 2022, 7:57 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(+)

Comments

bluez.test.bot@gmail.com Oct. 21, 2022, 9:16 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=687658

---Test result---

Test Summary:
CheckPatch                    PASS      1.50 seconds
GitLint                       PASS      0.94 seconds
Prep - Setup ELL              PASS      28.28 seconds
Build - Prep                  PASS      0.83 seconds
Build - Configure             PASS      9.25 seconds
Build - Make                  PASS      1029.51 seconds
Make Check                    PASS      11.98 seconds
Make Check w/Valgrind         PASS      302.50 seconds
Make Distcheck                PASS      253.24 seconds
Build w/ext ELL - Configure   PASS      9.64 seconds
Build w/ext ELL - Make        PASS      89.76 seconds
Incremental Build w/ patches  PASS      107.48 seconds
Scan Build                    PASS      577.60 seconds



---
Regards,
Linux Bluetooth
diff mbox series

Patch

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;