From c7afbb8b74419330698c57f4edb1d2242b9a8951 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Wed, 24 Aug 2022 17:05:19 +0200 Subject: [PATCH] profiles: Allow linked transport to release the fd Multiple transports can be linked when using LE Audio BAP. In this case only one transport is used to Acquire the file descriptor which will be shared by all linked transports. In the same way, any transport can Release the file descriptor. Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- profiles/audio/transport.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 206947d..2a8347e 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -286,9 +286,26 @@ static void media_owner_free(struct media_owner *owner) g_free(owner); } +static void linked_transport_remove_owner(void *data, void *user_data) +{ + struct bt_bap_stream *stream = data; + struct media_owner *owner = user_data; + struct media_transport *transport; + + transport = find_transport_by_bap_stream(stream); + if (!transport) { + error("Unable to find transport"); + return; + } + + DBG("Transport %s Owner %s", transport->path, owner->name); + transport->owner = NULL; +} + static void media_transport_remove_owner(struct media_transport *transport) { struct media_owner *owner = transport->owner; + struct bap_transport *bap = transport->data; if (!transport->owner) return; @@ -300,6 +317,9 @@ static void media_transport_remove_owner(struct media_transport *transport) media_request_reply(owner->pending, EIO); transport->owner = NULL; + if (bap->linked) + queue_foreach(bt_bap_stream_io_get_links(bap->stream), + linked_transport_remove_owner, owner); if (owner->watch) g_dbus_remove_watch(btd_get_dbus_connection(), owner->watch); @@ -457,11 +477,34 @@ static void media_owner_exit(DBusConnection *connection, void *user_data) media_transport_remove_owner(owner->transport); } +static void linked_transport_set_owner(void *data, void *user_data) +{ + struct bt_bap_stream *stream = data; + struct media_owner *owner = user_data; + struct media_transport *transport; + + transport = find_transport_by_bap_stream(stream); + if (!transport) { + error("Unable to find transport"); + return; + } + + DBG("Transport %s Owner %s", transport->path, owner->name); + transport->owner = owner; +} + static void media_transport_set_owner(struct media_transport *transport, struct media_owner *owner) { + struct bap_transport *bap = transport->data; + DBG("Transport %s Owner %s", transport->path, owner->name); transport->owner = owner; + + if (bap->linked) + queue_foreach(bt_bap_stream_io_get_links(bap->stream), + linked_transport_set_owner, owner); + owner->transport = transport; owner->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(), owner->name, -- 2.7.4