[PATCH BlueZ v3 04/10] bap: lock streams when used

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Indicate to lower layer when we are using the streams.

When setup is freed, make sure the corresponding stream is released
after unlocking.
---
 profiles/audio/bap.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index b420354cd..6be6ff8fd 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -861,6 +861,17 @@ static struct bap_setup *setup_new(struct bap_ep *ep)
 	return setup;
 }
 
+static void release_stream(struct bt_bap_stream *stream)
+{
+	switch (bt_bap_stream_get_state(stream)) {
+	case BT_BAP_STREAM_STATE_IDLE:
+	case BT_BAP_STREAM_STATE_RELEASING:
+		break;
+	default:
+		bt_bap_stream_release(stream, NULL, NULL);
+	}
+}
+
 static void setup_free(void *data)
 {
 	struct bap_setup *setup = data;
@@ -892,6 +903,10 @@ static void setup_free(void *data)
 	if (setup->destroy)
 		setup->destroy(setup);
 
+	bt_bap_stream_unlock(setup->stream);
+
+	release_stream(setup->stream);
+
 	free(setup);
 }
 
@@ -1015,6 +1030,7 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
 
 	setup->stream = bt_bap_stream_new(ep->data->bap, ep->lpac, ep->rpac,
 						&setup->qos, setup->caps);
+	bt_bap_stream_lock(setup->stream);
 	bt_bap_stream_set_user_data(setup->stream, ep->path);
 	setup->config_pending = true;
 	setup->id = bt_bap_stream_config(setup->stream, &setup->qos,
@@ -1107,6 +1123,7 @@ static void create_stream_for_bis(struct bap_data *bap_data,
 	/* Create and configure stream */
 	setup->stream = bt_bap_stream_new(bap_data->bap,
 			lpac, NULL, &setup->qos, caps);
+	bt_bap_stream_lock(setup->stream);
 
 	setup->sid = sid;
 	bt_bap_stream_set_user_data(setup->stream, path);
@@ -1430,10 +1447,12 @@ static void setup_config(void *data, void *user_data)
 	/* TODO: Check if stream capabilities match add support for Latency
 	 * and PHY.
 	 */
-	if (!setup->stream)
+	if (!setup->stream) {
 		setup->stream = bt_bap_stream_new(ep->data->bap, ep->lpac,
 						ep->rpac, &setup->qos,
 						setup->caps);
+		bt_bap_stream_lock(setup->stream);
+	}
 
 	setup->config_pending = true;
 	setup->id = bt_bap_stream_config(setup->stream, &setup->qos,
-- 
2.49.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux