Skip to contentSkip to conversation

Add 'broadcasting' state

PATCH Superseded Vlad Pruteanu 3 participants 9 messages Jul 25, 2024 – Jul 30, 2024 Bluetooth drivers

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add 'broadcasting' state

This series adds a new 'broadcasting' state for transports created by the Broadcast Sink device as a result of scanning a Broadcast Source. Such transports will remain in the 'idle' state until the user selects them, at which point they will be moved to 'broadcasting'. PipeWire detects these transports and automatically acquires them.

The transport selection is done using the 'transport.select' method, that this series implements. The user can thus select the BIS that he wishes to sync to.

A PR has also been opened for PipeWire, I added Pauli to CC so that he is also aware of this change.

Vlad Pruteanu (5):
doc/media: Add 'broadcasting' state and 'Select' method
transport: Add 'broadcasting' state
transport: Add "select" method
client/player: Expose transport "select" method to the user
transport: Broadcast sink: wait for user to select transport

 client/player.c                  | 52 +++++++++++++++++++++++++++++++
 doc/org.bluez.MediaTransport.rst | 16 +++++++++-
 profiles/audio/transport.c       | 53 +++++++++++++++++++++++++++-----
 3 files changed, 112 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 1/5 doc/media: Add 'broadcasting' state and 'Select' method

This adds a new state for transports created by the Broadcast Sink. Such transports will remain in the 'idle' state until the user calls 'Select' on them, at which point they will be moved to 'broadcasting'. This allows the user to select the desired BIS as the audio server automatically acquires transports that are in this state.

---
 doc/org.bluez.MediaTransport.rst | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
doc/org.bluez.MediaTransport.rst +15 -1
index 6e95df8f2..47346d36b 100644
@@ -7,7 +7,7 @@ BlueZ D-Bus MediaTransport API documentation
 --------------------------------------------
 
 :Version: BlueZ
-:Date: September 2023
+:Date: July 2024
 :Manual section: 5
 :Manual group: Linux System Administration
 
@@ -51,6 +51,18 @@ void Release()
 
 	Releases file descriptor.
 
+void Select()
+``````````````
+
+	Applicable only for transports created by a broadcast sink. This moves
+	the transport from 'idle' to 'broadcasting'. Since the audio server
+	automatically acquires transports that are in this state, the user can
+	thus select which BISes he wishes to sync to.
+
+	Possible Errors:
+
+	:org.bluez.Error.NotAuthorized:
+
 Properties
 ----------
 
@@ -84,6 +96,8 @@ string State [readonly]
 
 	:"idle": not streaming
 	:"pending": streaming but not acquired
+	:"broadcasting": streaming but not acquired, applicable only for transports
+		created by a broadcast sink
 	:"active": streaming and acquired
 
 uint16 Delay [readwrite, optional]
Signature · 1 line
2.40.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=873820

---Test result---

Test Summary:

CheckPatch                    FAIL      1.78 seconds
GitLint                       PASS      1.47 seconds
BuildEll                      PASS      24.43 seconds
BluezMake                     PASS      1678.94 seconds
MakeCheck                     PASS      13.63 seconds
MakeDistcheck                 PASS      176.04 seconds
CheckValgrind                 PASS      249.84 seconds
CheckSmatch                   PASS      352.51 seconds
bluezmakeextell               PASS      118.54 seconds
IncrementalBuild              PASS      7869.54 seconds
ScanBuild                     PASS      986.14 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v2,3/5] transport: Add "select" method
ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#128: FILE: profiles/audio/transport.c:975:
+static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,

                    ^

ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#128: FILE: profiles/audio/transport.c:975:
+static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,

                                                     ^

ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#128: FILE: profiles/audio/transport.c:975:
+static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,

                                                                        ^

/github/workspace/src/src/13741852.patch total: 3 errors, 0 warnings, 42 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13741852.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#3 lore raw

Re: [PATCH BlueZ v2 1/5] doc/media: Add 'broadcasting' state and 'Select' method

In reply to Vlad Pruteanu

Hi,

to, 2024-07-25 kello 14:58 +0300, Vlad Pruteanu kirjoitti:

Quoted 28 lines

This adds a new state for transports created by the Broadcast Sink. Such transports will remain in the 'idle' state until the user calls 'Select' on them, at which point they will be moved to 'broadcasting'. This allows the user to select the desired BIS as the audio server automatically acquires transports that are in this state.

---
 doc/org.bluez.MediaTransport.rst | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
doc/org.bluez.MediaTransport.rst +2 -1
index 6e95df8f2..47346d36b 100644
@@ -7,7 +7,7 @@ BlueZ D-Bus MediaTransport API documentation
 --------------------------------------------
 
 :Version: BlueZ
-:Date: September 2023
+:Date: July 2024
 :Manual section: 5
 :Manual group: Linux System Administration
 
@@ -51,6 +51,18 @@ void Release()
 
 	Releases file descriptor.
 
+void Select()

doc/org.bluez.MediaTransport.rst void Release() · line 64

Quoted 10 lines
doc/org.bluez.MediaTransport.rst +10 -0
+``````````````
+
+	Applicable only for transports created by a broadcast sink. This moves
+	the transport from 'idle' to 'broadcasting'. Since the audio server
+	automatically acquires transports that are in this state, the user can
+	thus select which BISes he wishes to sync to.
+
+	Possible Errors:
+
+	:org.bluez.Error.NotAuthorized:

Should there also be Unselect() that forces the transport back to "idle"?

IIRC, BlueZ as A2DP Sink/ACP behaves like that --- when remote INT stops audio stream the transport goes back to "idle". So it would be similar, with the difference that a local application --- instead of the remote side --- is controlling whether the stream is "playing".

I guess the design question here is whether local apps shall to talk to BlueZ or the sound server to enable specific audio streams.

Having the "enable" flag either in BlueZ or on audio server side is possible, esp. if it is question of transport acquire.

As audio server, we could e.g. expose it as the device "on/off" profile state, which user can turn on/off e.g. in pavucontrol.

***

Note that the current Pipewire BAP Broadcast behavior I think is work in progress. Acquiring the transport on PENDING I think is maybe accidental --- it is using the BAP Unicast Server code path, and in one of the bcast sink patches from NXP I see there seems to be intent to use BAP Unicast Client like behavior, but probably it's not quite right if you see the acquire-on-pending behavior.

(As "server" Pipewire will expose audio streams similarly as application audio streams, and by default direct them to available audio speakers. As "client" Pipewire exposes the audio streams as virtual microphone devices, which the user can manually record from or link to speakers.)

Quoted 13 lines
doc/org.bluez.MediaTransport.rst +3 -0
+
 Properties
 ----------
 
@@ -84,6 +96,8 @@ string State [readonly]
 
 	:"idle": not streaming
 	:"pending": streaming but not acquired
+	:"broadcasting": streaming but not acquired, applicable only for transports
+		created by a broadcast sink
 	:"active": streaming and acquired
 
 uint16 Delay [readwrite, optional]
Signature · 1 line
Pauli Virtanen
#4 lore raw

RE: [EXT] Re: [PATCH BlueZ v2 1/5] doc/media: Add 'broadcasting' state and 'Select' method

Hello,

Quoted 47 lines

-----Original Message-----
From: Pauli Virtanen <[email protected]>
Sent: Thursday, July 25, 2024 7:46 PM
To: Vlad Pruteanu <[email protected]>; linux- [email protected]
Cc: Mihai-Octavian Urzica <[email protected]>; Iulia Tanasescu <[email protected]>; Andrei Istodorescu <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH BlueZ v2 1/5] doc/media: Add 'broadcasting' state and 'Select' method

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Hi,

to, 2024-07-25 kello 14:58 +0300, Vlad Pruteanu kirjoitti:

Review

Quoted 11 lines

This adds a new state for transports created by the Broadcast Sink. Such transports will remain in the 'idle' state until the user calls 'Select' on them, at which point they will be moved to 'broadcasting'. This allows the user to select the desired BIS as the audio server automatically acquires transports that are in this state.

---
 doc/org.bluez.MediaTransport.rst | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/doc/org.bluez.MediaTransport.rst

Quoted 16 lines

index 6e95df8f2..47346d36b 100644

doc/org.bluez.MediaTransport.rst +1 -1
@@ -7,7 +7,7 @@ BlueZ D-Bus MediaTransport API documentation
 --------------------------------------------
 
 :Version: BlueZ
-:Date: September 2023
+:Date: July 2024
 :Manual section: 5
 :Manual group: Linux System Administration
 
@@ -51,6 +51,18 @@ void Release()
 
      Releases file descriptor.
 
Quoted 15 lines

doc/org.bluez.MediaTransport.rst void Release() · line 64

Quoted 11 lines
doc/org.bluez.MediaTransport.rst +11 -0
+void Select()
+``````````````
+
+     Applicable only for transports created by a broadcast sink. This moves
+     the transport from 'idle' to 'broadcasting'. Since the audio server
+     automatically acquires transports that are in this state, the user can
+     thus select which BISes he wishes to sync to.
+
+     Possible Errors:
+
+     :org.bluez.Error.NotAuthorized:

Should there also be Unselect() that forces the transport back to "idle"?

Yes we also need this command. I will send an updated patch to also include this method.

Quoted 8 lines

IIRC, BlueZ as A2DP Sink/ACP behaves like that --- when remote INT stops audio stream the transport goes back to "idle". So it would be similar, with the difference that a local application --- instead of the remote side --- is controlling whether the stream is "playing".

I guess the design question here is whether local apps shall to talk to BlueZ or the sound server to enable specific audio streams.

I think that at least for discovering Broadcast Sources local apps should talk to BlueZ, since, after all, it's a matter of scanning for a Bluetooth device that is advertising and acting according to the profile specification. To me, the process is similar to A2DP, without the actual connection process, and since for A2DP the local apps first talk to BlueZ, I believe that this should be the case here as well.

Quoted 31 lines

Having the "enable" flag either in BlueZ or on audio server side is possible, esp. if it is question of transport acquire.

As audio server, we could e.g. expose it as the device "on/off" profile state, which user can turn on/off e.g. in pavucontrol.

***

Note that the current Pipewire BAP Broadcast behavior I think is work in progress. Acquiring the transport on PENDING I think is maybe accidental --- it is using the BAP Unicast Server code path, and in one of the bcast sink patches from NXP I see there seems to be intent to use BAP Unicast Client like behavior, but probably it's not quite right if you see the acquire-on-pending behavior.

(As "server" Pipewire will expose audio streams similarly as application audio streams, and by default direct them to available audio speakers. As "client" Pipewire exposes the audio streams as virtual microphone devices, which the user can manually record from or link to speakers.)

doc/org.bluez.MediaTransport.rst string State [readonly] · line 99

Quoted 9 lines
doc/org.bluez.MediaTransport.rst +2 -0
+
 Properties
 ----------
 
@@ -84,6 +96,8 @@ string State [readonly]
 
      :"idle": not streaming
      :"pending": streaming but not acquired
+     :"broadcasting": streaming but not acquired, applicable only for

transports

Quoted 7 lines

doc/org.bluez.MediaTransport.rst string State [readonly] · line 103

Quoted 4 lines
doc/org.bluez.MediaTransport.rst +1 -0
+             created by a broadcast sink
      :"active": streaming and acquired
 
 uint16 Delay [readwrite, optional]

--
Pauli Virtanen

Regards,
Vlad

#5 lore raw

PATCH v2 2/5 transport: Add 'broadcasting' state

In reply to Vlad Pruteanu

This adds a new state for transports created by the Broadcast Sink device as a result of scanning a Broadcast Source. Such transports will remain in the 'idle' state until the user selects them using 'transport.select', at which point they will be moved to 'broadcasting'.

---
 profiles/audio/transport.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
profiles/audio/transport.c +12 -2
index 922911cf3..0a890c0ac 100644
@@ -51,6 +51,10 @@
 typedef enum {
 	TRANSPORT_STATE_IDLE,		/* Not acquired and suspended */
 	TRANSPORT_STATE_PENDING,	/* Playing but not acquired */
+	/* Playing but not acquired, applicable only for transports
+	 * created by a broadcast sink
+	 */
+	TRANSPORT_STATE_BROADCASTING,
 	TRANSPORT_STATE_REQUESTING,	/* Acquire in progress */
 	TRANSPORT_STATE_ACTIVE,		/* Acquired and playing */
 	TRANSPORT_STATE_SUSPENDING,     /* Release in progress */
@@ -59,6 +63,7 @@ typedef enum {
 static const char *str_state[] = {
 	"TRANSPORT_STATE_IDLE",
 	"TRANSPORT_STATE_PENDING",
+	"TRANSPORT_STATE_BROADCASTING",
 	"TRANSPORT_STATE_REQUESTING",
 	"TRANSPORT_STATE_ACTIVE",
 	"TRANSPORT_STATE_SUSPENDING",
@@ -139,6 +144,8 @@ static const char *state2str(transport_state_t state)
 		return "idle";
 	case TRANSPORT_STATE_PENDING:
 		return "pending";
+	case TRANSPORT_STATE_BROADCASTING:
+		return "broadcasting";
 	case TRANSPORT_STATE_ACTIVE:
 	case TRANSPORT_STATE_SUSPENDING:
 		return "active";
@@ -152,6 +159,7 @@ static gboolean state_in_use(transport_state_t state)
 	switch (state) {
 	case TRANSPORT_STATE_IDLE:
 	case TRANSPORT_STATE_PENDING:
+	case TRANSPORT_STATE_BROADCASTING:
 		return FALSE;
 	case TRANSPORT_STATE_REQUESTING:
 	case TRANSPORT_STATE_ACTIVE:
@@ -679,7 +687,8 @@ static DBusMessage *try_acquire(DBusConnection *conn, DBusMessage *msg,
 	if (transport->state >= TRANSPORT_STATE_REQUESTING)
 		return btd_error_not_authorized(msg);
 
-	if (transport->state != TRANSPORT_STATE_PENDING)
+	if ((transport->state != TRANSPORT_STATE_PENDING) &&
+		(transport->state != TRANSPORT_STATE_BROADCASTING))
 		return btd_error_not_available(msg);
 
 	owner = media_owner_create(msg);
@@ -1281,7 +1290,8 @@ static void transport_update_playing(struct media_transport *transport,
 					str_state[transport->state], playing);
 
 	if (playing == FALSE) {
-		if (transport->state == TRANSPORT_STATE_PENDING)
+		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 */
Signature · 1 line
2.40.1
#6 lore raw

PATCH v2 3/5 transport: Add "select" method

In reply to Vlad Pruteanu

This adds the "select" method for Broadcast transports. It's role is to change the transport's state from idle to broadcasting. This allows the user to select the desired stream when running the setup with PipeWire since it acquires any transport that is broadcasting.

---
 profiles/audio/transport.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
profiles/audio/transport.c +24 -0
index 0a890c0ac..bf2215a0f 100644
@@ -972,6 +972,9 @@ static gboolean get_endpoint(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,
+					void *data);
+
 static const GDBusMethodTable transport_methods[] = {
 	{ GDBUS_ASYNC_METHOD("Acquire",
 			NULL,
@@ -984,6 +987,8 @@ static const GDBusMethodTable transport_methods[] = {
 							{ "mtu_w", "q" }),
 			try_acquire) },
 	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, release) },
+	{ GDBUS_ASYNC_METHOD("Select",
+			NULL, NULL, select_transport) },
 	{ },
 };
 
@@ -1302,6 +1307,25 @@ static void transport_update_playing(struct media_transport *transport,
 		transport_set_state(transport, TRANSPORT_STATE_PENDING);
 }
 
+static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,
+					void *data)
+{
+	struct media_transport *transport = data;
+
+	if (transport->owner != NULL)
+		return btd_error_not_authorized(msg);
+
+	if (transport->state >= TRANSPORT_STATE_REQUESTING)
+		return btd_error_not_authorized(msg);
+
+	if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
+						BAA_SERVICE_UUID)) {
+		transport_update_playing(transport, TRUE);
+	}
+
+	return NULL;
+}
+
 static void sink_state_changed(struct btd_service *service,
 						sink_state_t old_state,
 						sink_state_t new_state,
Signature · 1 line
2.40.1
#7 lore raw

PATCH v2 4/5 client/player: Expose transport "select" method to the user

In reply to Vlad Pruteanu

This exposes the "select" method for Broadcast transports. This allows the user to select the desired stream when running the setup with PipeWire since it acquires any transport that is broadcasting.

---
 client/player.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
client/player.c +52 -0
index 2480ed64b..30b73c9cd 100644
@@ -4634,6 +4634,23 @@ static void acquire_reply(DBusMessage *message, void *user_data)
 	return bt_shell_noninteractive_quit(EXIT_FAILURE);
 }
 
+static void select_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		bt_shell_printf("Failed to select: %s\n", error.name);
+		dbus_error_free(&error);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	bt_shell_printf("Select successful");
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void prompt_acquire(const char *input, void *user_data)
 {
 	GDBusProxy *proxy = user_data;
@@ -4855,6 +4872,38 @@ static void cmd_acquire_transport(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void transport_select(GDBusProxy *proxy, bool prompt)
+{
+	if (!g_dbus_proxy_method_call(proxy, "Select", NULL,
+					select_reply, proxy, NULL)) {
+		bt_shell_printf("Failed select transport\n");
+		return;
+	}
+}
+
+static void cmd_select_transport(int argc, char *argv[])
+{
+	GDBusProxy *proxy;
+	int i;
+
+	for (i = 1; i < argc; i++) {
+		proxy = g_dbus_proxy_lookup(transports, NULL, argv[i],
+					BLUEZ_MEDIA_TRANSPORT_INTERFACE);
+		if (!proxy) {
+			bt_shell_printf("Transport %s not found\n", argv[i]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		if (find_transport(proxy)) {
+			bt_shell_printf("Transport %s already acquired\n",
+					argv[i]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		transport_select(proxy, false);
+	}
+}
+
 static void release_reply(DBusMessage *message, void *user_data)
 {
 	struct transport *transport = user_data;
@@ -5283,6 +5332,9 @@ static const struct bt_shell_menu transport_menu = {
 	{ "volume",      "<transport> [value]",	cmd_volume_transport,
 						"Get/Set transport volume",
 						transport_generator },
+	{ "select",     "<transport>", cmd_select_transport,
+						"Select Transport",
+						transport_generator },
 	{} },
 };
 
Signature · 1 line
2.40.1
#8 lore raw

PATCH v2 5/5 transport: Broadcast sink: wait for user to select transport

In reply to Vlad Pruteanu

This changes the flow for transports created on broadcast sink side. Transports are not automatically changed to pending anymore, instead the user must first run transport.select on them which updates the state to 'broadcasting'. This allows for the selection of the desired stream when running the setup with PipeWire, which acquires any transport that is broadcasting.

---
 profiles/audio/transport.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
profiles/audio/transport.c +9 -6
index bf2215a0f..54d0ca1f7 100644
@@ -1303,8 +1303,14 @@ static void transport_update_playing(struct media_transport *transport,
 			if (transport->owner != NULL)
 				media_transport_remove_owner(transport);
 		}
-	} else if (transport->state == TRANSPORT_STATE_IDLE)
-		transport_set_state(transport, TRANSPORT_STATE_PENDING);
+	} else if (transport->state == TRANSPORT_STATE_IDLE) {
+		if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
+						BCAA_SERVICE_UUID))
+			transport_set_state(transport,
+						TRANSPORT_STATE_BROADCASTING);
+		else
+			transport_set_state(transport, TRANSPORT_STATE_PENDING);
+	}
 }
 
 static DBusMessage *select_transport(DBusConnection *conn, DBusMessage *msg,
@@ -1686,10 +1692,7 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 			bap_update_qos(transport);
 		else if (bt_bap_stream_io_dir(stream) != BT_BAP_BCAST_SOURCE)
 			bap_update_bcast_qos(transport);
-		if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SOURCE)
-			transport_update_playing(transport, TRUE);
-		else
-			transport_update_playing(transport, FALSE);
+		transport_update_playing(transport, FALSE);
 		return;
 	case BT_BAP_STREAM_STATE_DISABLING:
 		return;
Signature · 1 line
2.40.1