diff mbox series

[BlueZ,v5,7/8] transport: Add 'Unselect' method

Message ID 20240731061713.435586-8-vlad.pruteanu@nxp.com
State New
Headers show
Series Add 'broadcasting' state | expand

Commit Message

Vlad Pruteanu July 31, 2024, 6:17 a.m. UTC
This adds a new method, exclusive to transports created by the Broadcast
Sink. It allows the user to terminate the sync to a BIS, via a 2 step
process. The first step is the call to this method, which changes the
transport's state to idle, with the second step being done by the audio
server which detects this change and releases the transport.
---
 profiles/audio/transport.c | 41 +++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index 80e4f564c..300145794 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -975,6 +975,9 @@  static gboolean get_endpoint(const GDBusPropertyTable *property,
 static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,
 					void *data);
 
+static DBusMessage *unselect_transport(DBusConnection *conn, DBusMessage *msg,
+					void *data);
+
 static const GDBusMethodTable transport_methods[] = {
 	{ GDBUS_ASYNC_METHOD("Acquire",
 			NULL,
@@ -989,6 +992,8 @@  static const GDBusMethodTable transport_methods[] = {
 	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, release) },
 	{ GDBUS_ASYNC_METHOD("Select",
 			NULL, NULL, select_transport) },
+	{ GDBUS_ASYNC_METHOD("Unselect",
+			NULL, NULL, unselect_transport) },
 	{ },
 };
 
@@ -1295,13 +1300,22 @@  static void transport_update_playing(struct media_transport *transport,
 					str_state[transport->state], playing);
 
 	if (playing == FALSE) {
-		if ((transport->state == TRANSPORT_STATE_PENDING) ||
-			(transport->state == TRANSPORT_STATE_BROADCASTING))
-			transport_set_state(transport, TRANSPORT_STATE_IDLE);
-		else if (transport->state == TRANSPORT_STATE_ACTIVE) {
-			/* Remove owner */
-			if (transport->owner != NULL)
-				media_transport_remove_owner(transport);
+		if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
+						BCAA_SERVICE_UUID)) {
+			if ((transport->state ==
+				TRANSPORT_STATE_BROADCASTING) ||
+				(transport->state == TRANSPORT_STATE_ACTIVE))
+				transport_set_state(transport,
+						TRANSPORT_STATE_IDLE);
+		} else {
+			if (transport->state == TRANSPORT_STATE_PENDING)
+				transport_set_state(transport,
+						TRANSPORT_STATE_IDLE);
+			else if (transport->state == TRANSPORT_STATE_ACTIVE) {
+				/* Remove owner */
+				if (transport->owner != NULL)
+					media_transport_remove_owner(transport);
+			}
 		}
 	} else if (transport->state == TRANSPORT_STATE_IDLE) {
 		if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
@@ -1332,6 +1346,19 @@  static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,
 	return NULL;
 }
 
+static DBusMessage *unselect_transport(DBusConnection *conn, DBusMessage *msg,
+					void *data)
+{
+	struct media_transport *transport = data;
+
+	if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
+						BAA_SERVICE_UUID)) {
+		transport_update_playing(transport, FALSE);
+	}
+
+	return NULL;
+}
+
 static void sink_state_changed(struct btd_service *service,
 						sink_state_t old_state,
 						sink_state_t new_state,