diff mbox series

[BlueZ,v1] transport: Fix not always being able to Acquire when linked

Message ID 20240605195610.534491-1-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,v1] transport: Fix not always being able to Acquire when linked | expand

Commit Message

Luiz Augusto von Dentz June 5, 2024, 7:56 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If a linked transport becomes ready and sets an fd it means it can be
acquired via Acquire/TryAcquire methods but that shall also be valid for
linked transports as well since they share the same fd/IO it can already
be transferred despite the state of the stream.

Fixes: https://github.com/bluez/bluez/issues/862
---
 profiles/audio/transport.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index 5b11bfeb6ab6..64d38ae669da 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -1492,11 +1492,20 @@  static guint transport_bap_resume(struct media_transport *transport,
 
 	if (!bap->stream)
 		return 0;
+
 	if (bap->resume_id)
-		return 0;
+		return bap->resume_id;
 
 	bap_update_links(transport);
 
+	/* If there is already an fd set consider it ready and proceed to
+	 * complete the resume process.
+	 */
+	if (transport->fd >= 0) {
+		bap->resume_id = g_idle_add(bap_resume_complete_cb, transport);
+		return bap->resume_id;
+	}
+
 	switch (bt_bap_stream_get_state(bap->stream)) {
 	case BT_BAP_STREAM_STATE_ENABLING:
 		bap_enable_complete(bap->stream, 0x00, 0x00, owner);
@@ -1671,6 +1680,22 @@  static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 	g_io_channel_unref(chan);
 
 	media_transport_set_fd(transport, fd, imtu, omtu);
+
+	/* If the transport is linked update the fd in the link as well as they
+	 * share the same io channel.
+	 */
+	if (bap->linked) {
+		struct bt_bap_stream *link = bt_bap_stream_io_get_link(stream);
+
+		if (link) {
+			struct media_transport *t;
+
+			t = find_transport_by_bap_stream(link);
+			if (t)
+				media_transport_set_fd(t, fd, imtu, omtu);
+		}
+	}
+
 	transport_update_playing(transport, TRUE);
 
 done: