diff mbox series

[BlueZ,1/9] bap: Add helper function get_bis_from_stream

Message ID 20241004123523.1012743-2-vlad.pruteanu@nxp.com
State New
Headers show
Series Allow syncing to multiple BISes from the same BIG | expand

Commit Message

Vlad Pruteanu Oct. 4, 2024, 12:35 p.m. UTC
This function receives a bt_bap_stream as a parameter and returns
a number, representing the index of the BIS for which the stream
was created.
---
 profiles/audio/bap.c | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 100acca57..b48fe2c2f 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -994,6 +994,30 @@  static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
 	return NULL;
 }
 
+static int get_bis_from_stream(struct bt_bap_stream *stream)
+{
+	char *path;
+	int bis_index = 1;
+	int s_err;
+	const char *strbis = NULL;
+
+	path = bt_bap_stream_get_user_data(stream);
+
+	strbis = strstr(path, "/bis");
+	if (strbis == NULL) {
+		DBG("bis index cannot be found");
+		return 0;
+	}
+
+	s_err = sscanf(strbis, "/bis%d", &bis_index);
+	if (s_err == -1) {
+		DBG("sscanf error");
+		return 0;
+	}
+
+	return bis_index;
+}
+
 static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)
 {
 	struct bap_bcast_pa_req *req = user_data;
@@ -3055,10 +3079,7 @@  static void iso_do_big_sync(GIOChannel *io, void *user_data)
 	struct bap_data *data = btd_service_get_user_data(btd_service);
 	struct sockaddr_iso_bc iso_bc_addr;
 	struct bt_iso_qos qos;
-	char *path;
-	int bis_index = 1;
-	int s_err;
-	const char *strbis = NULL;
+	int bis_index = get_bis_from_stream(setup->stream);
 
 	DBG("PA Sync done");
 
@@ -3078,19 +3099,6 @@  static void iso_do_big_sync(GIOChannel *io, void *user_data)
 	 * transports in the same BIG to be acquired or tell when to do the
 	 * bt_io_bcast_accept by other means
 	 */
-	path = bt_bap_stream_get_user_data(setup->stream);
-
-	strbis = strstr(path, "/bis");
-	if (strbis == NULL) {
-		DBG("bis index cannot be found");
-		return;
-	}
-
-	s_err = sscanf(strbis, "/bis%d", &bis_index);
-	if (s_err == -1) {
-		DBG("sscanf error");
-		return;
-	}
 
 	DBG("Do BIG Sync with BIS %d", bis_index);