diff mbox series

[BlueZ,v3,5/7] shared/bap: Check state of all streams with same BIG ID

Message ID 20240215212356.310301-6-silviu.barbulescu@nxp.com
State New
Headers show
Series Add support for multiple BISes on the bcast source | expand

Commit Message

Silviu Florian Barbulescu Feb. 15, 2024, 9:23 p.m. UTC
The function is used to verify if all the streams from a BIG are in the
same state, and if so it returns the number of BISes in the BIG.
Else, return 0.

---
 src/shared/bap.c | 33 +++++++++++++++++++++++++++++++++
 src/shared/bap.h |  2 ++
 2 files changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 524bfa058..49d9838fb 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -6115,3 +6115,36 @@  struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream)
 
 	return base_iov;
 }
+
+/*
+ * Check the state of all streams with the same BIG ID.
+ * If all the streams are in the checked state, return
+ * number of this streams. Else, return 0.
+ */
+uint8_t bt_bap_get_streams_by_state(struct bt_bap_stream *stream,
+						uint8_t test_state)
+{
+	const struct queue_entry *entry;
+	struct bt_bap_stream *ent_stream;
+	uint8_t nb = 0;
+
+	for (entry = queue_get_entries(stream->bap->streams);
+				entry; entry = entry->next) {
+		ent_stream = entry->data;
+
+		if (ent_stream == stream) {
+			nb++;
+			continue;
+		}
+
+		if (ent_stream->qos.bcast.big != stream->qos.bcast.big)
+			continue;
+
+		if (ent_stream->bcast_state != test_state)
+			return 0;
+
+		nb++;
+	}
+
+	return nb;
+}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 2c3550921..a37e1528e 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -323,3 +323,5 @@  void bt_bap_update_bcast_source(struct bt_bap_pac *pac,
 bool bt_bap_pac_bcast_is_local(struct bt_bap *bap, struct bt_bap_pac *pac);
 
 struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream);
+uint8_t bt_bap_get_streams_by_state(struct bt_bap_stream *stream,
+						uint8_t test_state);